Mmap allocating more than one page

Viewed 1173

So I'm on x86-64 linux, and when I try to mmap one byte, I get way more than one page. Here's my thinking: When I allocate one byte, I should be able to access PAGE_SIZE bytes after that. That's how paging works, right? I confirmed that PAGE_SIZE on my system is 4096. But still, the following code doesn't 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. My understanding is, the line p[5000] = 3 should generate a page fault, and the page fault handler should realize that the page doesn't belong to me. But it doesn't happen. The code works. So is mmap giving me more than one page?

1 Answers
Related