int fd = open(file, O_RDONLY);
size_t size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
uint8_t *buffer = mmap(NULL, VM_PAGE_COUNT(size) * VM_PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
while(size > 0)
{
size_t bytes = read(fd, buffer, size);
size -= bytes;
buffer += bytes;
}
read()andwrite()are done in the kernel, which maps the buffer passed over into the kernel space losing all information about the page's protection. Example: