1 #include <sys/resource.h>
2 #include <stdio.h>
3 
bpf_rlimit_ctor(void)4 static  __attribute__((constructor)) void bpf_rlimit_ctor(void)
5 {
6 	struct rlimit rlim_old, rlim_new = {
7 		.rlim_cur	= RLIM_INFINITY,
8 		.rlim_max	= RLIM_INFINITY,
9 	};
10 
11 	getrlimit(RLIMIT_MEMLOCK, &rlim_old);
12 	/* For the sake of running the test cases, we temporarily
13 	 * set rlimit to infinity in order for kernel to focus on
14 	 * errors from actual test cases and not getting noise
15 	 * from hitting memlock limits. The limit is on per-process
16 	 * basis and not a global one, hence destructor not really
17 	 * needed here.
18 	 */
19 	if (setrlimit(RLIMIT_MEMLOCK, &rlim_new) < 0) {
20 		perror("Unable to lift memlock rlimit");
21 		/* Trying out lower limit, but expect potential test
22 		 * case failures from this!
23 		 */
24 		rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
25 		rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
26 		setrlimit(RLIMIT_MEMLOCK, &rlim_new);
27 	}
28 }
29