From: Guido Reina on 2 Sep 2009 11:45 Hi all, I am having problems trying to run an application with valgrind v3.4.1. The application mmap()s a big file (around 200 MB) with the flag MAP_FIXED and some fixed address, the size is multiple of 4096. map fails with the error EINVAL when I run it with valgrind. If I run it with gdb, it works fine. Is there something I can change to make it work? Thanks in advance, Guido
From: Noob on 3 Sep 2009 03:57 Guido Reina wrote: > I am having problems trying to run an application with valgrind > v3.4.1. The application mmap()s a big file (around 200 MB) with the > flag MAP_FIXED and some fixed address, the size is multiple of 4096. > map fails with the error EINVAL when I run it with valgrind. If I run > it with gdb, it works fine. Is there something I can change to make it > work? It always helps to provide a small compilable example to demonstrate your problem, so that others may reproduce it on their system. You should also state OS and kernel revision.
From: David Schwartz on 3 Sep 2009 05:59 On Sep 2, 8:45 am, Guido Reina <gra.te...(a)googlemail.com> wrote: > I am having problems trying to run an application with valgrind > v3.4.1. The application mmap()s a big file (around 200 MB) with the > flag MAP_FIXED and some fixed address, the size is multiple of 4096. > map fails with the error EINVAL when I run it with valgrind. If I run > it with gdb, it works fine. Is there something I can change to make it > work? MAP_FIXED is supposed to return EINVAL if you specify an address that cannot be mapped. It *IS* working. You are asking the wrong question. The right question is "why does this application fail when its mmap fails, since the mmap failing is perfectly routine and ordinary". DS
From: guidoreina on 3 Sep 2009 10:48 Thank you for the answers. The thing is that it works when I run it "normally" and it also works when I run it with gdb, but not when I run it valgrind. I have just read the subject of my post... I don't want to mean that valgrind is not working. I am having this problem and I want to understand why this particular call to mmap is failing when I run it with valgrind. Finding memory leaks without valgrind is too difficult, that's why I have started this post. I want to do what Noob suggested and write a test program to see where the problem is. The original program is using POST++ to mmap a file and it fails in the file::open method. The base address for mmap is: 0x62500000, and the size: 200000000. POST++ converts the size to a multiple of 4096. So, the call is something like: void* p = mmap(base, mapped_size, PROT_READ|PROT_WRITE, MAP_VARIABLE| MAP_SHARED|MAP_FILE, fd, 0) where base = 0x62500000 and mapped_size is a bit bigger than 200000000, so it is multiple of 4096 I thought that the base address could be in use when running it with valgrind, so I checked: /proc/<pid>/maps and chose another address, but this didn't work either. Guido On Sep 3, 9:59 am, David Schwartz <dav...(a)webmaster.com> wrote: > On Sep 2, 8:45 am, Guido Reina <gra.te...(a)googlemail.com> wrote: > > > I am having problems trying to run an application with valgrind > > v3.4.1. The application mmap()s a big file (around 200 MB) with the > > flag MAP_FIXED and some fixed address, the size is multiple of 4096. > > map fails with the error EINVAL when I run it with valgrind. If I run > > it with gdb, it works fine. Is there something I can change to make it > > work? > > MAP_FIXED is supposed to return EINVAL if you specify an address that > cannot be mapped. It *IS* working. > > You are asking the wrong question. The right question is "why does > this application fail when its mmap fails, since the mmap failing is > perfectly routine and ordinary". > > DS
From: Moi on 3 Sep 2009 14:03
On Thu, 03 Sep 2009 07:48:23 -0700, guidoreina wrote: > Thank you for the answers. > > The thing is that it works when I run it "normally" and it also works > when I run it with gdb, but not when I run it valgrind. > > I have just read the subject of my post... I don't want to mean that > valgrind is not working. I am having this problem and I want to > understand why this particular call to mmap is failing when I run it > with valgrind. Finding memory leaks without valgrind is too difficult, > that's why I have started this post. Well, if mmap() returns without an error without valgrind, it probably means that mmap() succeeded. When it fails with valgrind it might be valgrind-related. Maybe it trips a guard page ? Maybe valgrind is confused by mmap()? It seems you use a c++ wrapper around mmap. Maybe it hits a (memory related) bug, and errno is not updated accordingly. (not all erros change errno) Maybe your fixed mapped address range overlaps with memory addresses in use (such as the heap) which trips valgrind ? For testing: 1) mmap only half of the file (if the application permits) 2) mmap at another address (if the application permits) HTH, YMMV, AvK |