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