Mmap highlighting more than one page

So, I am on x86-64 linux, and when I try mmapone byte, I get more than one page. Here is my thinking: when I allocate one byte, I should have access to the PAGE_SIZEbytes after that. How does paging work? I confirmed that it PAGE_SIZEis 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] = 3should 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 mmapgiving me more than one page?

+4
source share
1

, p [5000] = 3

, p , , - undefined: , segfault.

, p[5000] - , , segfault.

. mmap ?

, , segfault, , .

mmap :

length .

+3

Source: https://habr.com/ru/post/1685862/


All Articles