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); \
24 P_MMAP_PROT(GROWSDOWN
);
29 printed
+= scnprintf(bf
+ printed
, size
- printed
, "%s%#x", printed
? "|" : "", prot
);
34 #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot
36 static size_t mmap__scnprintf_flags(unsigned long flags
, char *bf
, size_t size
, bool show_prefix
)
38 #include "trace/beauty/generated/mmap_flags_array.c"
39 static DEFINE_STRARRAY(mmap_flags
, "MAP_");
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
);
75 printed
+= scnprintf(bf
+ printed
, size
- printed
, "%s%#x", printed
? "|" : "", flags
);
80 #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags
82 static size_t madvise__scnprintf_behavior(int behavior
, char *bf
, size_t size
)
84 #include "trace/beauty/generated/madvise_behavior_array.c"
85 static DEFINE_STRARRAY(madvise_advices
, "MADV_");
87 if (behavior
< strarray__madvise_advices
.nr_entries
&& strarray__madvise_advices
.entries
[behavior
] != NULL
)
88 return scnprintf(bf
, size
, "MADV_%s", strarray__madvise_advices
.entries
[behavior
]);
90 return scnprintf(bf
, size
, "%#", behavior
);
93 static size_t syscall_arg__scnprintf_madvise_behavior(char *bf
, size_t size
,
94 struct syscall_arg
*arg
)
96 return madvise__scnprintf_behavior(arg
->val
, bf
, size
);
99 #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior