1 #include <sys/mman.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <kernel/OS.h>
5
6 #define SPACE_SIZE (B_PAGE_SIZE * 9)
7
8 int
main()9 main()
10 {
11 void* space = NULL;
12 area_id area = create_area("mlock test area", &space, B_EXACT_ADDRESS,
13 SPACE_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
14
15 /* --------- */
16 int result = mlock(space + B_PAGE_SIZE, B_PAGE_SIZE * 7);
17 /* -xxxxxxx- */
18 assert(result == 0);
19 result = munlock(space + 2 * B_PAGE_SIZE, B_PAGE_SIZE * 5);
20 /* -x-----x- */
21 assert(result == 0);
22 result = mlock(space + 2 * B_PAGE_SIZE, B_PAGE_SIZE * 3);
23 /* -xxxx--x- */
24 assert(result == 0);
25 result = mlock(space, B_PAGE_SIZE * 9);
26 /* xxxxxxxxx */
27 assert(result == 0);
28 result = munlock(space + 4 * B_PAGE_SIZE, B_PAGE_SIZE * 5);
29 /* xxxx----- */
30 assert(result == 0);
31 result = munlock(space, B_PAGE_SIZE * 9);
32 assert(result == 0);
33
34 delete_area(area);
35 return 0;
36 }
37