• Siddhesh Poyarekar's avatar
    procfs: mark thread stack correctly in proc/<pid>/maps · b7643757
    Siddhesh Poyarekar authored
    Stack for a new thread is mapped by userspace code and passed via
    sys_clone.  This memory is currently seen as anonymous in
    /proc/<pid>/maps, which makes it difficult to ascertain which mappings
    are being used for thread stacks.  This patch uses the individual task
    stack pointers to determine which vmas are actually thread stacks.
    
    For a multithreaded program like the following:
    
    	#include <pthread.h>
    
    	void *thread_main(void *foo)
    	{
    		while(1);
    	}
    
    	int main()
    	{
    		pthread_t t;
    		pthread_create(&t, NULL, thread_main, NULL);
    		pthread_join(t, NULL);
    	}
    
    proc/PID/maps looks like the following:
    
        00400000-00401000 r-xp 00000000 fd:0a 3671804                            /home/siddhesh/a.out
        00600000-00601000 rw-p 00000000 fd:0a 3671804                            /home/siddhesh/a.out
        019ef000-01a10000 rw-p 00000000 00:00 0                                  [heap]
        7f8a44491000-7f8a44492000 ---p 00000000 00:00 0
        7f8a44492000-7f8a44c92000 r...
    b7643757
util.c 8.15 KB