6 static void test_anonymous(void)
8 int pagesize
= getpagesize();
12 page
= mmap(NULL
, pagesize
, PROT_READ
, MAP_ANONYMOUS
| MAP_PRIVATE
, -1, 0);
13 assert(page
!= MAP_FAILED
);
15 /* Check that mprotect() does not interfere with MADV_DONTNEED. */
16 ret
= mprotect(page
, pagesize
, PROT_READ
| PROT_WRITE
);
19 /* Check that MADV_DONTNEED clears the page. */
21 ret
= madvise(page
, pagesize
, MADV_DONTNEED
);
25 ret
= munmap(page
, pagesize
);
29 static void test_file(void)
31 char tempname
[] = "/tmp/.cmadviseXXXXXX";
32 int pagesize
= getpagesize();
39 fd
= mkstemp(tempname
);
41 ret
= unlink(tempname
);
43 written
= write(fd
, &c
, sizeof(c
));
44 assert(written
== sizeof(c
));
45 page
= mmap(NULL
, pagesize
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
46 assert(page
!= MAP_FAILED
);
48 /* Check that mprotect() does not interfere with MADV_DONTNEED. */
49 ret
= mprotect(page
, pagesize
, PROT_READ
| PROT_WRITE
);
52 /* Check that MADV_DONTNEED resets the page. */
54 ret
= madvise(page
, pagesize
, MADV_DONTNEED
);
58 ret
= munmap(page
, pagesize
);