Ticket #17556: Mmap.cpp

File Mmap.cpp, 560 bytes (added by X512, 3 years ago)
Line 
1#include <stdio.h>
2#include <string.h>
3#include <fcntl.h>
4#include <sys/mman.h>
5#include <OS.h>
6
7
8int main()
9{
10 int fd = open("/boot/system/lib/libroot.so", O_CLOEXEC | O_RDONLY);
11
12 uint8 *ptr1 = (uint8*)mmap(NULL, 16*B_PAGE_SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
13 printf("(1) %#x, %#x\n", ptr1[0], ptr1[3*B_PAGE_SIZE]);
14 uint8 *ptr2 = (uint8*)mmap(&ptr1[B_PAGE_SIZE], B_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0);
15 printf("(2) %#x, %#x\n", ptr1[0], ptr1[3*B_PAGE_SIZE]); // expected to print the same as in (1)
16
17 return 0;
18}