1 // SPDX-License-Identifier: LGPL-2.1 2 #include <uapi/linux/mman.h> 3 #include <linux/log2.h> 4 5 static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, 6 struct syscall_arg *arg) 7 { 8 int printed = 0, prot = arg->val; 9 10 if (prot == PROT_NONE) 11 return scnprintf(bf, size, "NONE"); 12 #define P_MMAP_PROT(n) \ 13 if (prot & PROT_##n) { \ 14 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ 15 prot &= ~PROT_##n; \ 16 } 17 18 P_MMAP_PROT(EXEC); 19 P_MMAP_PROT(READ); 20 P_MMAP_PROT(WRITE); 21 P_MMAP_PROT(SEM); 22 P_MMAP_PROT(GROWSDOWN); 23 P_MMAP_PROT(GROWSUP); 24 #undef P_MMAP_PROT 25 26 if (prot) 27 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", prot); 28 29 return printed; 30 } 31 32 #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot 33 34 static size_t mmap__scnprintf_flags(unsigned long flags, char *bf, size_t size) 35 { 36 #include "trace/beauty/generated/mmap_flags_array.c" 37 static DEFINE_STRARRAY(mmap_flags); 38 39 return strarray__scnprintf_flags(&strarray__mmap_flags, bf, size, flags); 40 } 41 42 static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, 43 struct syscall_arg *arg) 44 { 45 unsigned long flags = arg->val; 46 47 if (flags & MAP_ANONYMOUS) 48 arg->mask |= (1 << 4) | (1 << 5); /* Mask 4th ('fd') and 5th ('offset') args, ignored */ 49 50 return mmap__scnprintf_flags(flags, bf, size); 51 } 52 53 #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags 54 55 static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size, 56 struct syscall_arg *arg) 57 { 58 int printed = 0, flags = arg->val; 59 60 #define P_MREMAP_FLAG(n) \ 61 if (flags & MREMAP_##n) { \ 62 printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ 63 flags &= ~MREMAP_##n; \ 64 } 65 66 P_MREMAP_FLAG(MAYMOVE); 67 P_MREMAP_FLAG(FIXED); 68 #undef P_MREMAP_FLAG 69 70 if (flags) 71 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); 72 73 return printed; 74 } 75 76 #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags 77 78 static size_t madvise__scnprintf_behavior(int behavior, char *bf, size_t size) 79 { 80 #include "trace/beauty/generated/madvise_behavior_array.c" 81 static DEFINE_STRARRAY(madvise_advices); 82 83 if (behavior < strarray__madvise_advices.nr_entries && strarray__madvise_advices.entries[behavior] != NULL) 84 return scnprintf(bf, size, "MADV_%s", strarray__madvise_advices.entries[behavior]); 85 86 return scnprintf(bf, size, "%#", behavior); 87 } 88 89 static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, 90 struct syscall_arg *arg) 91 { 92 return madvise__scnprintf_behavior(arg->val, bf, size); 93 } 94 95 #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior 96