18c2ecf20Sopenharmony_ci#include <sys/resource.h> 28c2ecf20Sopenharmony_ci#include <stdio.h> 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_cistatic __attribute__((constructor)) void bpf_rlimit_ctor(void) 58c2ecf20Sopenharmony_ci{ 68c2ecf20Sopenharmony_ci struct rlimit rlim_old, rlim_new = { 78c2ecf20Sopenharmony_ci .rlim_cur = RLIM_INFINITY, 88c2ecf20Sopenharmony_ci .rlim_max = RLIM_INFINITY, 98c2ecf20Sopenharmony_ci }; 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci getrlimit(RLIMIT_MEMLOCK, &rlim_old); 128c2ecf20Sopenharmony_ci /* For the sake of running the test cases, we temporarily 138c2ecf20Sopenharmony_ci * set rlimit to infinity in order for kernel to focus on 148c2ecf20Sopenharmony_ci * errors from actual test cases and not getting noise 158c2ecf20Sopenharmony_ci * from hitting memlock limits. The limit is on per-process 168c2ecf20Sopenharmony_ci * basis and not a global one, hence destructor not really 178c2ecf20Sopenharmony_ci * needed here. 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci if (setrlimit(RLIMIT_MEMLOCK, &rlim_new) < 0) { 208c2ecf20Sopenharmony_ci perror("Unable to lift memlock rlimit"); 218c2ecf20Sopenharmony_ci /* Trying out lower limit, but expect potential test 228c2ecf20Sopenharmony_ci * case failures from this! 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20); 258c2ecf20Sopenharmony_ci rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20); 268c2ecf20Sopenharmony_ci setrlimit(RLIMIT_MEMLOCK, &rlim_new); 278c2ecf20Sopenharmony_ci } 288c2ecf20Sopenharmony_ci} 29