xref: /openbmc/linux/tools/perf/trace/beauty/mmap.c (revision 5d0e4d78)
1 #include <uapi/linux/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 	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 
32 static 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 #define	P_MMAP_FLAG(n) \
38 	if (flags & MAP_##n) { \
39 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
40 		flags &= ~MAP_##n; \
41 	}
42 
43 	P_MMAP_FLAG(SHARED);
44 	P_MMAP_FLAG(PRIVATE);
45 #ifdef MAP_32BIT
46 	P_MMAP_FLAG(32BIT);
47 #endif
48 	P_MMAP_FLAG(ANONYMOUS);
49 	P_MMAP_FLAG(DENYWRITE);
50 	P_MMAP_FLAG(EXECUTABLE);
51 	P_MMAP_FLAG(FILE);
52 	P_MMAP_FLAG(FIXED);
53 	P_MMAP_FLAG(GROWSDOWN);
54 	P_MMAP_FLAG(HUGETLB);
55 	P_MMAP_FLAG(LOCKED);
56 	P_MMAP_FLAG(NONBLOCK);
57 	P_MMAP_FLAG(NORESERVE);
58 	P_MMAP_FLAG(POPULATE);
59 	P_MMAP_FLAG(STACK);
60 	P_MMAP_FLAG(UNINITIALIZED);
61 #undef P_MMAP_FLAG
62 
63 	if (flags)
64 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
65 
66 	return printed;
67 }
68 
69 #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags
70 
71 static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size,
72 						  struct syscall_arg *arg)
73 {
74 	int printed = 0, flags = arg->val;
75 
76 #define P_MREMAP_FLAG(n) \
77 	if (flags & MREMAP_##n) { \
78 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
79 		flags &= ~MREMAP_##n; \
80 	}
81 
82 	P_MREMAP_FLAG(MAYMOVE);
83 	P_MREMAP_FLAG(FIXED);
84 #undef P_MREMAP_FLAG
85 
86 	if (flags)
87 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
88 
89 	return printed;
90 }
91 
92 #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags
93 
94 static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,
95 						      struct syscall_arg *arg)
96 {
97 	int behavior = arg->val;
98 
99 	switch (behavior) {
100 #define	P_MADV_BHV(n) case MADV_##n: return scnprintf(bf, size, #n)
101 	P_MADV_BHV(NORMAL);
102 	P_MADV_BHV(RANDOM);
103 	P_MADV_BHV(SEQUENTIAL);
104 	P_MADV_BHV(WILLNEED);
105 	P_MADV_BHV(DONTNEED);
106 	P_MADV_BHV(FREE);
107 	P_MADV_BHV(REMOVE);
108 	P_MADV_BHV(DONTFORK);
109 	P_MADV_BHV(DOFORK);
110 	P_MADV_BHV(HWPOISON);
111 	P_MADV_BHV(SOFT_OFFLINE);
112 	P_MADV_BHV(MERGEABLE);
113 	P_MADV_BHV(UNMERGEABLE);
114 	P_MADV_BHV(HUGEPAGE);
115 	P_MADV_BHV(NOHUGEPAGE);
116 	P_MADV_BHV(DONTDUMP);
117 	P_MADV_BHV(DODUMP);
118 #undef P_MADV_BHV
119 	default: break;
120 	}
121 
122 	return scnprintf(bf, size, "%#x", behavior);
123 }
124 
125 #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior
126