seccomp.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0
  2. #ifndef SECCOMP_SET_MODE_STRICT
  3. #define SECCOMP_SET_MODE_STRICT 0
  4. #endif
  5. #ifndef SECCOMP_SET_MODE_FILTER
  6. #define SECCOMP_SET_MODE_FILTER 1
  7. #endif
  8. static size_t syscall_arg__scnprintf_seccomp_op(char *bf, size_t size, struct syscall_arg *arg)
  9. {
  10. int op = arg->val;
  11. size_t printed = 0;
  12. switch (op) {
  13. #define P_SECCOMP_SET_MODE_OP(n) case SECCOMP_SET_MODE_##n: printed = scnprintf(bf, size, #n); break
  14. P_SECCOMP_SET_MODE_OP(STRICT);
  15. P_SECCOMP_SET_MODE_OP(FILTER);
  16. #undef P_SECCOMP_SET_MODE_OP
  17. default: printed = scnprintf(bf, size, "%#x", op); break;
  18. }
  19. return printed;
  20. }
  21. #define SCA_SECCOMP_OP syscall_arg__scnprintf_seccomp_op
  22. #ifndef SECCOMP_FILTER_FLAG_TSYNC
  23. #define SECCOMP_FILTER_FLAG_TSYNC 1
  24. #endif
  25. static size_t syscall_arg__scnprintf_seccomp_flags(char *bf, size_t size,
  26. struct syscall_arg *arg)
  27. {
  28. int printed = 0, flags = arg->val;
  29. #define P_FLAG(n) \
  30. if (flags & SECCOMP_FILTER_FLAG_##n) { \
  31. printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
  32. flags &= ~SECCOMP_FILTER_FLAG_##n; \
  33. }
  34. P_FLAG(TSYNC);
  35. #undef P_FLAG
  36. if (flags)
  37. printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
  38. return printed;
  39. }
  40. #define SCA_SECCOMP_FLAGS syscall_arg__scnprintf_seccomp_flags