ENOMEM with mmap in IA64



Hi,
I am calling mmap for certain binaries in a loop (inside the same
process), and I am getting ENOMEM while mapping the 2nd or 3rd binary
(not the first one).. Here is the sample scenerio -

foo(char *fname)
{
struct stat sbuf;
fd = open(fname, O_RDONLY);
/* exit if fail */

stat(fname, &sbuf);
/* exit if fail */

file_size = sbuf.st_size;

buffer = mmap(0, file_size, PROT_READ, MAP_SHARED, fd, 0);
if (buffer == MAP_FAIL) {
/* Exit */
}

/* DO SOMETHINGS with buffer */

munmap(buffer, file_size);
}

I am calling this function for various binaries (system binaries) in a
loop, and I get ENOMEM after successfully crossing 2-3 binaries
......... I didnt understand the reason.
I also tried with MAP_PRIVATE, surprisingly I didnt get ENOMEM after
processing some 15-20 binaries... (didnt check after that).. But why
should it matter if I am not writing to the region ?

Is there something which I am missing ?

Thanks

.