pkey_alloc.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: LGPL-2.1
  2. /*
  3. * trace/beauty/pkey_alloc.c
  4. *
  5. * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
  6. */
  7. #include "trace/beauty/beauty.h"
  8. #include <linux/kernel.h>
  9. #include <linux/log2.h>
  10. size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, bool show_prefix, unsigned long flags)
  11. {
  12. int i, printed = 0;
  13. if (flags == 0) {
  14. const char *s = sa->entries[0];
  15. if (s)
  16. return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", s);
  17. return scnprintf(bf, size, "%d", 0);
  18. }
  19. for (i = 1; i < sa->nr_entries; ++i) {
  20. unsigned long bit = 1UL << (i - 1);
  21. if (!(flags & bit))
  22. continue;
  23. if (printed != 0)
  24. printed += scnprintf(bf + printed, size - printed, "|");
  25. if (sa->entries[i] != NULL)
  26. printed += scnprintf(bf + printed, size - printed, "%s%s", show_prefix ? sa->prefix : "", sa->entries[i]);
  27. else
  28. printed += scnprintf(bf + printed, size - printed, "0x%#", bit);
  29. }
  30. return printed;
  31. }
  32. static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size, bool show_prefix)
  33. {
  34. #include "trace/beauty/generated/pkey_alloc_access_rights_array.c"
  35. static DEFINE_STRARRAY(pkey_alloc_access_rights, "PKEY_");
  36. return strarray__scnprintf_flags(&strarray__pkey_alloc_access_rights, bf, size, show_prefix, access_rights);
  37. }
  38. size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg)
  39. {
  40. unsigned long cmd = arg->val;
  41. return pkey_alloc__scnprintf_access_rights(cmd, bf, size, arg->show_string_prefix);
  42. }