So, I am on x86-64 linux, and when I try mmap
one byte, I get more than one page. Here is my thinking: when I allocate one byte, I should have access to the PAGE_SIZE
bytes after that. How does paging work? I confirmed that it PAGE_SIZE
is 4096 on my system. But still, the following code does not execute segfault:
#include <sys/mman.h>
#include <stdio.h>
int main()
{
char *p = mmap(0, 1, PROT_READ|PROT_WRITE, MAP_PRIVATE
|MAP_ANONYMOUS, -1, 0);
p[5000] = 3;
}
5000 there is some arbitrary value greater than PAGE_SIZE
. I understand that the line p[5000] = 3
should generate a page error, and the page error handler should understand that the page does not belong to me. But this does not happen. The code is working. So mmap
giving me more than one page?
source
share