bpf_rlimit.h 907 B

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