1 /* Maps several pages with or without MAP_NORESEVE.
2 Mappings with MAP_NORESEVE do not show in /proc/self/xmap
3 (only in /proc/self/rmap) until they actually materialize.
4 Very nice from Solaris kernel :-(
13 #include <sys/param.h>
15 static void *do_map(int flags
)
17 flags
|= MAP_PRIVATE
| MAP_ANON
;
18 void *addr
= mmap(0, PAGESIZE
, PROT_READ
| PROT_WRITE
, flags
, -1, 0);
27 static void *do_dlopen(const char *pathname
)
29 int mode
= RTLD_LAZY
| RTLD_LOCAL
;
30 void *handle
= dlopen(pathname
, mode
);
32 fprintf(stderr
, "dlopen failed for %s: %s",
40 int main(int argc
, const char *argv
[])
42 do_map(MAP_NORESERVE
);
46 do_map(MAP_NORESERVE
);
48 do_map(MAP_NORESERVE
);
51 do_map(MAP_NORESERVE
);
52 do_map(MAP_NORESERVE
);
54 do_map(MAP_NORESERVE
);
55 do_map(MAP_NORESERVE
);
65 do_map(MAP_NORESERVE
);
70 do_map(MAP_NORESERVE
);
71 do_map(MAP_NORESERVE
);
73 printf("CHILD: PASSED\n");
79 if (waitpid(pid
, &status
, 0) != pid
) {
81 } else if ((WIFEXITED(status
) != 0) && (WEXITSTATUS(status
) == 0)) {
84 fprintf(stderr
, "FAILED: child exited with unexpected status %s %d\n",
85 WIFEXITED(status
) ? "exit" : "signal",
86 WIFEXITED(status
) ? WEXITSTATUS(status
) : WTERMSIG(status
));