Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / trace / beauty / mmap.c
blob862c8331dded677cd9e1fb0563fa272472b4e42b
1 // SPDX-License-Identifier: LGPL-2.1
2 #include <uapi/linux/mman.h>
3 #include <linux/log2.h>
5 static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
6 struct syscall_arg *arg)
8 const char *prot_prefix = "PROT_";
9 int printed = 0, prot = arg->val;
10 bool show_prefix = arg->show_string_prefix;
12 if (prot == PROT_NONE)
13 return scnprintf(bf, size, "%sNONE", show_prefix ? prot_prefix : "");
14 #define P_MMAP_PROT(n) \
15 if (prot & PROT_##n) { \
16 printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prot_prefix :"", #n); \
17 prot &= ~PROT_##n; \
20 P_MMAP_PROT(READ);
21 P_MMAP_PROT(WRITE);
22 P_MMAP_PROT(EXEC);
23 P_MMAP_PROT(SEM);
24 P_MMAP_PROT(GROWSDOWN);
25 P_MMAP_PROT(GROWSUP);
26 #undef P_MMAP_PROT
28 if (prot)
29 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", prot);
31 return printed;
34 #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot
36 #include "trace/beauty/generated/mmap_flags_array.c"
37 static DEFINE_STRARRAY(mmap_flags, "MAP_");
39 static size_t mmap__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
41 return strarray__scnprintf_flags(&strarray__mmap_flags, bf, size, show_prefix, flags);
44 static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,
45 struct syscall_arg *arg)
47 unsigned long flags = arg->val;
49 if (flags & MAP_ANONYMOUS)
50 arg->mask |= (1 << 4) | (1 << 5); /* Mask 4th ('fd') and 5th ('offset') args, ignored */
52 return mmap__scnprintf_flags(flags, bf, size, arg->show_string_prefix);
55 #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags
57 static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
58 struct syscall_arg *arg)
60 const char *flags_prefix = "MREMAP_";
61 bool show_prefix = arg->show_string_prefix;
62 int printed = 0, flags = arg->val;
64 #define P_MREMAP_FLAG(n) \
65 if (flags & MREMAP_##n) { \
66 printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? flags_prefix : "", #n); \
67 flags &= ~MREMAP_##n; \
70 P_MREMAP_FLAG(MAYMOVE);
71 P_MREMAP_FLAG(FIXED);
72 P_MREMAP_FLAG(DONTUNMAP);
73 #undef P_MREMAP_FLAG
75 if (flags)
76 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
78 return printed;
81 #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags
83 static size_t madvise__scnprintf_behavior(int behavior, char *bf, size_t size)
85 #include "trace/beauty/generated/madvise_behavior_array.c"
86 static DEFINE_STRARRAY(madvise_advices, "MADV_");
88 if (behavior < strarray__madvise_advices.nr_entries && strarray__madvise_advices.entries[behavior] != NULL)
89 return scnprintf(bf, size, "MADV_%s", strarray__madvise_advices.entries[behavior]);
91 return scnprintf(bf, size, "%#", behavior);
94 static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
95 struct syscall_arg *arg)
97 return madvise__scnprintf_behavior(arg->val, bf, size);
100 #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior