pkey_alloc.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * trace/beauty/pkey_alloc.c
  3. *
  4. * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
  5. *
  6. * Released under the GPL v2. (and only v2, not any later version)
  7. */
  8. #include "trace/beauty/beauty.h"
  9. #include <linux/kernel.h>
  10. #include <linux/log2.h>
  11. static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size)
  12. {
  13. int i, printed = 0;
  14. #include "trace/beauty/generated/pkey_alloc_access_rights_array.c"
  15. static DEFINE_STRARRAY(pkey_alloc_access_rights);
  16. if (access_rights == 0) {
  17. const char *s = strarray__pkey_alloc_access_rights.entries[0];
  18. if (s)
  19. return scnprintf(bf, size, "%s", s);
  20. return scnprintf(bf, size, "%d", 0);
  21. }
  22. for (i = 1; i < strarray__pkey_alloc_access_rights.nr_entries; ++i) {
  23. int bit = 1 << (i - 1);
  24. if (!(access_rights & bit))
  25. continue;
  26. if (printed != 0)
  27. printed += scnprintf(bf + printed, size - printed, "|");
  28. if (strarray__pkey_alloc_access_rights.entries[i] != NULL)
  29. printed += scnprintf(bf + printed, size - printed, "%s", strarray__pkey_alloc_access_rights.entries[i]);
  30. else
  31. printed += scnprintf(bf + printed, size - printed, "0x%#", bit);
  32. }
  33. return printed;
  34. }
  35. size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg)
  36. {
  37. unsigned long cmd = arg->val;
  38. return pkey_alloc__scnprintf_access_rights(cmd, bf, size);
  39. }