2 * It tests the duplicate mlock result:
3 * - the ulimit of lock page is 64k
4 * - allocate address area 64k starting from p
5 * - mlock [p -- p + 30k]
6 * - Then mlock address [ p -- p + 40k ]
8 * It should succeed since totally we locked
9 * 40k < 64k limitation.
11 * It should not be run with CAP_IPC_LOCK.
16 #include <sys/resource.h>
17 #include <sys/capability.h>
21 int main(int argc, char **argv)
25 cap_t cap = cap_init();
28 /* drop capabilities including CAP_IPC_LOCK */
29 if (cap_set_proc(cap))
32 /* set mlock limits to 64k */
35 setrlimit(RLIMIT_MEMLOCK, &new);
38 p = malloc(1024 * 64);
39 if (mlock(p, 1024 * 30)) {
40 printf("mlock() 30k return failure.\n");
43 for (i = 0; i < 10; i++) {
44 if (mlock(p, 1024 * 40)) {
45 printf("mlock() #%d 40k returns failure.\n", i);
49 for (i = 0; i < 10; i++) {
50 if (mlock2_(p, 1024 * 40, MLOCK_ONFAULT)) {
51 printf("mlock2_() #%d 40k returns failure.\n", i);
57 /* Test VM_LOCKONFAULT */
58 p = malloc(1024 * 64);
59 if (mlock2_(p, 1024 * 30, MLOCK_ONFAULT)) {
60 printf("mlock2_() 30k return failure.\n");
63 for (i = 0; i < 10; i++) {
64 if (mlock2_(p, 1024 * 40, MLOCK_ONFAULT)) {
65 printf("mlock2_() #%d 40k returns failure.\n", i);
69 for (i = 0; i < 10; i++) {
70 if (mlock(p, 1024 * 40)) {
71 printf("mlock() #%d 40k returns failure.\n", i);