xref: /openbmc/linux/tools/perf/trace/beauty/mmap.c (revision 0edbfea5)
1 #include <sys/mman.h>
2 
3 static 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 #ifdef PROT_SEM
20 	P_MMAP_PROT(SEM);
21 #endif
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 #ifndef MAP_STACK
35 # define MAP_STACK		0x20000
36 #endif
37 
38 static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,
39 						struct syscall_arg *arg)
40 {
41 	int printed = 0, flags = arg->val;
42 
43 #define	P_MMAP_FLAG(n) \
44 	if (flags & MAP_##n) { \
45 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
46 		flags &= ~MAP_##n; \
47 	}
48 
49 	P_MMAP_FLAG(SHARED);
50 	P_MMAP_FLAG(PRIVATE);
51 #ifdef MAP_32BIT
52 	P_MMAP_FLAG(32BIT);
53 #endif
54 	P_MMAP_FLAG(ANONYMOUS);
55 	P_MMAP_FLAG(DENYWRITE);
56 	P_MMAP_FLAG(EXECUTABLE);
57 	P_MMAP_FLAG(FILE);
58 	P_MMAP_FLAG(FIXED);
59 	P_MMAP_FLAG(GROWSDOWN);
60 #ifdef MAP_HUGETLB
61 	P_MMAP_FLAG(HUGETLB);
62 #endif
63 	P_MMAP_FLAG(LOCKED);
64 	P_MMAP_FLAG(NONBLOCK);
65 	P_MMAP_FLAG(NORESERVE);
66 	P_MMAP_FLAG(POPULATE);
67 	P_MMAP_FLAG(STACK);
68 #ifdef MAP_UNINITIALIZED
69 	P_MMAP_FLAG(UNINITIALIZED);
70 #endif
71 #undef P_MMAP_FLAG
72 
73 	if (flags)
74 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
75 
76 	return printed;
77 }
78 
79 #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags
80 
81 static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
82 						  struct syscall_arg *arg)
83 {
84 	int printed = 0, flags = arg->val;
85 
86 #define P_MREMAP_FLAG(n) \
87 	if (flags & MREMAP_##n) { \
88 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
89 		flags &= ~MREMAP_##n; \
90 	}
91 
92 	P_MREMAP_FLAG(MAYMOVE);
93 #ifdef MREMAP_FIXED
94 	P_MREMAP_FLAG(FIXED);
95 #endif
96 #undef P_MREMAP_FLAG
97 
98 	if (flags)
99 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
100 
101 	return printed;
102 }
103 
104 #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags
105 
106 #ifndef MADV_HWPOISON
107 #define MADV_HWPOISON		100
108 #endif
109 
110 #ifndef MADV_MERGEABLE
111 #define MADV_MERGEABLE		 12
112 #endif
113 
114 #ifndef MADV_UNMERGEABLE
115 #define MADV_UNMERGEABLE	 13
116 #endif
117 
118 static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
119 						      struct syscall_arg *arg)
120 {
121 	int behavior = arg->val;
122 
123 	switch (behavior) {
124 #define	P_MADV_BHV(n) case MADV_##n: return scnprintf(bf, size, #n)
125 	P_MADV_BHV(NORMAL);
126 	P_MADV_BHV(RANDOM);
127 	P_MADV_BHV(SEQUENTIAL);
128 	P_MADV_BHV(WILLNEED);
129 	P_MADV_BHV(DONTNEED);
130 	P_MADV_BHV(REMOVE);
131 	P_MADV_BHV(DONTFORK);
132 	P_MADV_BHV(DOFORK);
133 	P_MADV_BHV(HWPOISON);
134 #ifdef MADV_SOFT_OFFLINE
135 	P_MADV_BHV(SOFT_OFFLINE);
136 #endif
137 	P_MADV_BHV(MERGEABLE);
138 	P_MADV_BHV(UNMERGEABLE);
139 #ifdef MADV_HUGEPAGE
140 	P_MADV_BHV(HUGEPAGE);
141 #endif
142 #ifdef MADV_NOHUGEPAGE
143 	P_MADV_BHV(NOHUGEPAGE);
144 #endif
145 #ifdef MADV_DONTDUMP
146 	P_MADV_BHV(DONTDUMP);
147 #endif
148 #ifdef MADV_DODUMP
149 	P_MADV_BHV(DODUMP);
150 #endif
151 #undef P_MADV_PHV
152 	default: break;
153 	}
154 
155 	return scnprintf(bf, size, "%#x", behavior);
156 }
157 
158 #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior
159