1 // SPDX-License-Identifier: GPL-2.0 2 #include <uapi/linux/mman.h> 3 4 static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, 5 struct syscall_arg *arg) 6 { 7 int printed = 0, prot = arg->val; 8 9 if (prot == PROT_NONE) 10 return scnprintf(bf, size, "NONE"); 11 #define P_MMAP_PROT(n) \ 12 if (prot & PROT_##n) { \ 13 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ 14 prot &= ~PROT_##n; \ 15 } 16 17 P_MMAP_PROT(EXEC); 18 P_MMAP_PROT(READ); 19 P_MMAP_PROT(WRITE); 20 P_MMAP_PROT(SEM); 21 P_MMAP_PROT(GROWSDOWN); 22 P_MMAP_PROT(GROWSUP); 23 #undef P_MMAP_PROT 24 25 if (prot) 26 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", prot); 27 28 return printed; 29 } 30 31 #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot 32 33 static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, 34 struct syscall_arg *arg) 35 { 36 int printed = 0, flags = arg->val; 37 38 if (flags & MAP_ANONYMOUS) 39 arg->mask |= (1 << 4) | (1 << 5); /* Mask 4th ('fd') and 5th ('offset') args, ignored */ 40 41 #define P_MMAP_FLAG(n) \ 42 if (flags & MAP_##n) { \ 43 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ 44 flags &= ~MAP_##n; \ 45 } 46 47 P_MMAP_FLAG(SHARED); 48 P_MMAP_FLAG(PRIVATE); 49 #ifdef MAP_32BIT 50 P_MMAP_FLAG(32BIT); 51 #endif 52 P_MMAP_FLAG(ANONYMOUS); 53 P_MMAP_FLAG(DENYWRITE); 54 P_MMAP_FLAG(EXECUTABLE); 55 P_MMAP_FLAG(FILE); 56 P_MMAP_FLAG(FIXED); 57 P_MMAP_FLAG(GROWSDOWN); 58 P_MMAP_FLAG(HUGETLB); 59 P_MMAP_FLAG(LOCKED); 60 P_MMAP_FLAG(NONBLOCK); 61 P_MMAP_FLAG(NORESERVE); 62 P_MMAP_FLAG(POPULATE); 63 P_MMAP_FLAG(STACK); 64 P_MMAP_FLAG(UNINITIALIZED); 65 #undef P_MMAP_FLAG 66 67 if (flags) 68 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); 69 70 return printed; 71 } 72 73 #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags 74 75 static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size, 76 struct syscall_arg *arg) 77 { 78 int printed = 0, flags = arg->val; 79 80 #define P_MREMAP_FLAG(n) \ 81 if (flags & MREMAP_##n) { \ 82 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ 83 flags &= ~MREMAP_##n; \ 84 } 85 86 P_MREMAP_FLAG(MAYMOVE); 87 P_MREMAP_FLAG(FIXED); 88 #undef P_MREMAP_FLAG 89 90 if (flags) 91 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); 92 93 return printed; 94 } 95 96 #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags 97 98 static size_t madvise__scnprintf_behavior(int behavior, char *bf, size_t size) 99 { 100 #include "trace/beauty/generated/madvise_behavior_array.c" 101 static DEFINE_STRARRAY(madvise_advices); 102 103 if (behavior < strarray__madvise_advices.nr_entries && strarray__madvise_advices.entries[behavior] != NULL) 104 return scnprintf(bf, size, "MADV_%s", strarray__madvise_advices.entries[behavior]); 105 106 return scnprintf(bf, size, "%#", behavior); 107 } 108 109 static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, 110 struct syscall_arg *arg) 111 { 112 return madvise__scnprintf_behavior(arg->val, bf, size); 113 } 114 115 #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior 116