]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - tools/testing/selftests/vm/on-fault-limit.c
Merge tag 'pm-extra-4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[mirror_ubuntu-zesty-kernel.git] / tools / testing / selftests / vm / on-fault-limit.c
1 #include <sys/mman.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <sys/time.h>
6 #include <sys/resource.h>
7
8 #ifndef MCL_ONFAULT
9 #define MCL_ONFAULT (MCL_FUTURE << 1)
10 #endif
11
12 static int test_limit(void)
13 {
14 int ret = 1;
15 struct rlimit lims;
16 void *map;
17
18 if (getrlimit(RLIMIT_MEMLOCK, &lims)) {
19 perror("getrlimit");
20 return ret;
21 }
22
23 if (mlockall(MCL_ONFAULT | MCL_FUTURE)) {
24 perror("mlockall");
25 return ret;
26 }
27
28 map = mmap(NULL, 2 * lims.rlim_max, PROT_READ | PROT_WRITE,
29 MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, 0, 0);
30 if (map != MAP_FAILED)
31 printf("mmap should have failed, but didn't\n");
32 else {
33 ret = 0;
34 munmap(map, 2 * lims.rlim_max);
35 }
36
37 munlockall();
38 return ret;
39 }
40
41 int main(int argc, char **argv)
42 {
43 int ret = 0;
44
45 ret += test_limit();
46 return ret;
47 }