B
bite me if you can...
The prototype of mmap() is:
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t
offset);
The second argument len is used to tell mmap() how many bytes I want to
map.
My question is: If len that i give to mmap() is larger than the size of
mapping file, and some data are wrote to these exceeding speces, where
are these data to be wrote to?
In Freebsd, this program section below will be executed without core
dump:
fd=open("mem.tmp", O_RDWR | O_CREAT | O_TRUNC | O_SHLOCK, S_IRWXU);
if(fd<0) {
printf("error at open() (errno: %d).\n", errno);
goto quit;
}
write(fd, empty, 8);
ptr=(char *)mmap((void *)NULL, 9, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
if(fd==MAP_FAILED) {
printf("error at mmap() (errno: %d).\n", errno);
goto quit;
}
ptr[0]='a';
ptr[1]='b';
ptr[2]='b';
ptr[3]='a';
ptr[4]='b';
ptr[5]='b';
ptr[6]='b';
ptr[7]='b';
ptr[8]='z';
But, where is 'z' to be wrote to?
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t
offset);
The second argument len is used to tell mmap() how many bytes I want to
map.
My question is: If len that i give to mmap() is larger than the size of
mapping file, and some data are wrote to these exceeding speces, where
are these data to be wrote to?
In Freebsd, this program section below will be executed without core
dump:
fd=open("mem.tmp", O_RDWR | O_CREAT | O_TRUNC | O_SHLOCK, S_IRWXU);
if(fd<0) {
printf("error at open() (errno: %d).\n", errno);
goto quit;
}
write(fd, empty, 8);
ptr=(char *)mmap((void *)NULL, 9, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
if(fd==MAP_FAILED) {
printf("error at mmap() (errno: %d).\n", errno);
goto quit;
}
ptr[0]='a';
ptr[1]='b';
ptr[2]='b';
ptr[3]='a';
ptr[4]='b';
ptr[5]='b';
ptr[6]='b';
ptr[7]='b';
ptr[8]='z';
But, where is 'z' to be wrote to?