Hi,


I have used below program  for testing. Below are the steps I have followed.

Compile: gcc -g3 test_shm.c -o test_shm

Create shared memory: ./test_shm –c

Get shared memory without valgrind: ./test_shm –g  ( this works fine)

Get with valgrind: /usr/bin/valgrind --tool=memcheck --leak-check=full 
--track-origins=yes --log-file=/tmp/val_log /home/rtp99/test_shm –g

With valgrind shmat command fails.





Total shared memory segments  active on the my system is 320.

My process will attach to 40 shared memory segments.  Shmat will fails when 
tested with 14 shared memory attach also.

Total RAM available on my system is 124GB. I am using HP C7000 blade hardware 
with RHEL6.2 OS.

I am using 64bit binary. 'file test_shm' command output is

test_shm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically 
linked (uses shared libs), for GNU/Linux 2.6.18, not stripped



        #include  

        #include  

        #include  

        #include 

        #include 

        



        struct shm_details

        {

                key_t key;

                size_t size;

                int shmid;

                void *shm;



        };

        

        main(int argc,char **argv) { 

        

        int i;

        struct shm_details test_shm[] = 

        {

                {0xe300626d,2147456,-1,NULL  },

                {0xe300626c ,144271608  ,-1,NULL},

                {0xe300626e,115604     ,-1,NULL},

                {0xe300626f ,118376704 ,-1,NULL},

                {0xe300653d ,574592     ,-1,NULL},

                {0xe300653c ,22578504   ,-1,NULL},

                {0xe300653e ,18092      ,-1,NULL},

                {0xe300653f ,208416960  ,-1,NULL},

                {0xe30066b9 ,2147456    ,-1,NULL},

                {0xe30066b8 ,120870984  ,-1,NULL},

                {0xe30066ba ,484260     ,-1,NULL},

                {0xe30066bb ,9793648960 ,-1,NULL},

                {0xe30068ad ,8438912,-1,NULL },

                {0xe30068ac,553973472,-1,NULL}

        };

        

        int list = (sizeof(test_shm)/sizeof(test_shm[0]));

        int shmflg;

        int delete=0;

         struct shmid_ds buf;

        if(argc != 2)

        {

                printf("Usage: ./test_shm -c|-g|-d\n -c for create shared 
memory\n -g for get shared memory\n -d delete the shared memory\n");

                return(0);

                

        }

        if(strcmp(argv[1],"-c") == 0)

        {

                shmflg = IPC_CREAT | 0666;

        }else if(strcmp(argv[1],"-g") == 0)

        {

                shmflg = 0666;

        }else if(strcmp(argv[1],"-d") == 0)

        {

                shmflg = 0666;

                delete = 1;

        }else{

        

                printf("Usage: ./test_shm -c|-g|-d\n -c for create\n -g for get 
shared memory\n -d delete the shared memory\n");

                return(0);

        }

        for (i=0;i 'uname -a' output is



> Linux mercury05 2.6.32-220.17.1.el6.x86_64 #1 SMP Thu Apr 26 13:37:13 EDT 
> 2012 x86_64 x86_64 x86_64 GNU/Linux



> 



> using valgrind version 3.8.0 also shmat is failing with errno 22.







Thank you for that information. Is the process running in "native" 64-bit mode,



or is this a 32-bit [only] process whose environment is being "emulated"



by the x86_64 system?







Now, please try to construct a small test case which fails in the same way:



The test app calls shmat() and works without valgrind, but gets EINVAL



when run under valgrind-3.8.0. Post the actual code to this mailing list;



the code should be no more than a few dozen lines.







Here are some situations which might affect the results:







 How many shared memory segments are attached by the app,



 and how many other shared memory segments are active



 at the same time in the whole system?







 What is the mix of access permissions (ReadOnly, ReadWrite, ...)?







 Were the shared memory segments created by the same process,



 or did the segments exist already before the process began?







 Is each shared memory segment being attached only once



 by any particular process, or are there multiple mappings?







 Is there any case which succeeds when (0!=shmaddr) ?



 Attach using shmat(shmid, 0, 0); Remember the address;



 Detach the segment; try to re-attach using shmat(shmid, old_addr, 0)



 where old_addr is the address which was returned for the first



 (successful) attach.







-- 









------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to