syscalls: Make mmap()'s fields `prot` and `flags` enums
[lttng-modules.git] / include / instrumentation / syscalls / headers / syscalls_integers_override.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) */
2
3 #ifndef CREATE_SYSCALL_TABLE
4
5 /*
6 * The `flags` argument of the mmap syscall is split in two parts:
7 * - The type of mapping is described by the four least significant bits of the 4
8 * bytes integer,
9 * - The options on the mapping are described by the remaining 28 most
10 * significant bits.
11 */
12 #define MAPPING_TYPE_RESERVED_BITS 4
13 #define LTTNG_MMAP_FLAGS_TO_CTF(x) ((x) >> MAPPING_TYPE_RESERVED_BITS)
14
15 /*
16 * Enumeration of the mmap flags, as described in the 'mmap'
17 * system call man page.
18 */
19 SC_LTTNG_TRACEPOINT_ENUM(lttng_mmap_protection,
20 TP_ENUM_VALUES(
21 ctf_enum_value("PROT_EXEC", PROT_EXEC)
22 ctf_enum_value("PROT_READ", PROT_READ)
23 ctf_enum_value("PROT_WRITE", PROT_WRITE)
24 ctf_enum_value("PROT_NONE", PROT_NONE)
25 )
26 )
27
28 SC_LTTNG_TRACEPOINT_ENUM(lttng_mmap_flags_mapping_type,
29 TP_ENUM_VALUES(
30 ctf_enum_value("MAP_SHARED", MAP_SHARED)
31 ctf_enum_value("MAP_PRIVATE", MAP_PRIVATE)
32 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0))
33 ctf_enum_value("MAP_SHARED_VALIDATE", MAP_SHARED_VALIDATE)
34 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0)) */
35 )
36 )
37
38 /*
39 * Shift the values of the options so we can read them from the `flags` integer
40 * directly.
41 */
42 SC_LTTNG_TRACEPOINT_ENUM(lttng_mmap_flags_options,
43 TP_ENUM_VALUES(
44 ctf_enum_value("<none>", 0)
45 ctf_enum_value("MAP_32BIT", LTTNG_MMAP_FLAGS_TO_CTF(MAP_32BIT))
46 ctf_enum_value("MAP_ANONYMOUS", LTTNG_MMAP_FLAGS_TO_CTF(MAP_ANONYMOUS))
47 ctf_enum_value("MAP_DENYWRITE", LTTNG_MMAP_FLAGS_TO_CTF(MAP_DENYWRITE))
48 ctf_enum_value("MAP_EXECUTABLE", LTTNG_MMAP_FLAGS_TO_CTF(MAP_EXECUTABLE))
49 ctf_enum_value("MAP_FIXED", LTTNG_MMAP_FLAGS_TO_CTF(MAP_FIXED))
50 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0))
51 ctf_enum_value("MAP_FIXED_NOREPLACE", LTTNG_MMAP_FLAGS_TO_CTF(MAP_FIXED_NOREPLACE))
52 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0)) */
53 ctf_enum_value("MAP_GROWSDOWN", LTTNG_MMAP_FLAGS_TO_CTF(MAP_GROWSDOWN))
54 ctf_enum_value("MAP_HUGETLB", LTTNG_MMAP_FLAGS_TO_CTF(MAP_HUGETLB))
55 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
56 ctf_enum_value("MAP_HUGETLB_2MB", LTTNG_MMAP_FLAGS_TO_CTF(MAP_HUGE_2MB))
57 ctf_enum_value("MAP_HUGETLB_1GB", LTTNG_MMAP_FLAGS_TO_CTF(MAP_HUGE_1GB))
58 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)) */
59 ctf_enum_value("MAP_LOCKED", LTTNG_MMAP_FLAGS_TO_CTF(MAP_LOCKED))
60 ctf_enum_value("MAP_NONBLOCK", LTTNG_MMAP_FLAGS_TO_CTF(MAP_NONBLOCK))
61 ctf_enum_value("MAP_NORESERVE", LTTNG_MMAP_FLAGS_TO_CTF(MAP_NORESERVE))
62 ctf_enum_value("MAP_POPULATE", LTTNG_MMAP_FLAGS_TO_CTF(MAP_POPULATE))
63 ctf_enum_value("MAP_STACK", LTTNG_MMAP_FLAGS_TO_CTF(MAP_STACK))
64 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0))
65 ctf_enum_value("MAP_SYNC", LTTNG_MMAP_FLAGS_TO_CTF(MAP_SYNC))
66 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0)) */
67 ctf_enum_value("MAP_UNINITIALIZED", LTTNG_MMAP_FLAGS_TO_CTF(MAP_UNINITIALIZED))
68 )
69 )
70
71 #define LTTNG_MMAP_FLAGS_TYPE \
72 { \
73 .name = "type", \
74 .type = { \
75 .atype = atype_enum_nestable, \
76 .u = { \
77 .enum_nestable = { \
78 .desc = &__enum_lttng_mmap_flags_mapping_type, \
79 .container_type = __LTTNG_COMPOUND_LITERAL( \
80 struct lttng_type, __type_integer(uint32_t, \
81 4, 1, -1, __BYTE_ORDER, 16, none)), \
82 }, \
83 }, \
84 }, \
85 }
86
87 #define LTTNG_MMAP_FLAGS_OPTIONS \
88 { \
89 .name = "options", \
90 .type = { \
91 .atype = atype_enum_nestable, \
92 .u = { \
93 .enum_nestable = { \
94 .desc = &__enum_lttng_mmap_flags_options, \
95 .container_type = __LTTNG_COMPOUND_LITERAL( \
96 struct lttng_type, __type_integer(uint32_t, \
97 28, 1, -1, __BYTE_ORDER, 16, none)),\
98 }, \
99 }, \
100 }, \
101 }
102
103 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
104 #define LTTNG_MMAP_FLAGS \
105 [0] = LTTNG_MMAP_FLAGS_TYPE, \
106 [1] = LTTNG_MMAP_FLAGS_OPTIONS,
107
108 #else
109 #define LTTNG_MMAP_FLAGS \
110 [0] = LTTNG_MMAP_FLAGS_OPTIONS, \
111 [1] = LTTNG_MMAP_FLAGS_TYPE,
112 #endif
113
114 /*
115 * Use a custom field here so that tracer writes a single integer and the
116 * work of splitting it up in two fields is left to the trace reader.
117 */
118 #define OVERRIDE_32_mmap
119 #define OVERRIDE_64_mmap
120 SC_LTTNG_TRACEPOINT_EVENT(mmap,
121 TP_PROTO(sc_exit(unsigned long ret,)
122 unsigned long addr, unsigned long len,
123 unsigned long prot, unsigned long flags,
124 unsigned long fd, unsigned long off),
125 TP_ARGS(sc_exit(ret,) addr, len, prot, flags, fd, off),
126 TP_FIELDS(sc_exit(ctf_integer_hex(unsigned long, ret, ret))
127 sc_in(ctf_integer_hex(unsigned long, addr, addr))
128 sc_in(ctf_integer(size_t, len, len))
129 sc_in(ctf_enum(lttng_mmap_protection, int, prot, prot))
130 sc_in(
131 ctf_custom_field(
132 ctf_custom_type(
133 {
134 .atype = atype_struct_nestable,
135 .u.struct_nestable.nr_fields = 2,
136 .u.struct_nestable.fields =
137 __LTTNG_COMPOUND_LITERAL(struct lttng_event_field,
138 LTTNG_MMAP_FLAGS
139 ),
140 .u.struct_nestable.alignment = lttng_alignof(uint32_t) * CHAR_BIT,
141 }
142 ),
143 flags,
144 ctf_custom_code(
145 ctf_integer_type(uint32_t, flags)
146 )
147 )
148 )
149 sc_in(ctf_integer(int, fd, fd))
150 sc_in(ctf_integer(off_t, offset, off))
151 )
152 )
153
154 /*
155 * Enumeration of the open flags, as described in the 'open'
156 * system call man page.
157 */
158 SC_LTTNG_TRACEPOINT_ENUM(lttng_fcntl_cmd_flags,
159 TP_ENUM_VALUES(
160 ctf_enum_value("F_DUPFD", F_DUPFD)
161 ctf_enum_value("F_GETFD", F_GETFD)
162 ctf_enum_value("F_SETFD", F_SETFD)
163 ctf_enum_value("F_GETFL", F_GETFL)
164 ctf_enum_value("F_SETFL", F_SETFL)
165 ctf_enum_value("F_GETLK", F_GETLK)
166 ctf_enum_value("F_SETLK", F_SETLK)
167 ctf_enum_value("F_SETLKW", F_SETLKW)
168 ctf_enum_value("F_SETOWN", F_SETOWN)
169 ctf_enum_value("F_GETOWN", F_GETOWN)
170 ctf_enum_value("F_SETSIG", F_SETSIG)
171 ctf_enum_value("F_GETSIG", F_GETSIG)
172 #if !defined(CONFIG_64BIT) || defined(CONFIG_COMPAT)
173 ctf_enum_value("F_GETLK64", F_GETLK64)
174 ctf_enum_value("F_SETLK64", F_SETLK64)
175 ctf_enum_value("F_SETLKW64", F_SETLKW64)
176 #endif /* #if !defined(CONFIG_64BIT) || defined(CONFIG_COMPAT) */
177 ctf_enum_value("F_SETOWN_EX", F_SETOWN_EX)
178 ctf_enum_value("F_GETOWN_EX", F_GETOWN_EX)
179 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
180 ctf_enum_value("F_GETOWNER_UIDS", F_GETOWNER_UIDS)
181 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */
182 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0))
183 ctf_enum_value("F_OFD_GETLK", F_OFD_GETLK)
184 ctf_enum_value("F_OFD_SETLK", F_OFD_SETLK)
185 ctf_enum_value("F_OFD_SETLKW", F_OFD_SETLKW)
186 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) */
187 ctf_enum_value("F_SETLEASE", F_SETLEASE)
188 ctf_enum_value("F_GETLEASE", F_GETLEASE)
189 ctf_enum_value("F_NOTIFY", F_NOTIFY)
190 ctf_enum_value("F_CANCELLK", F_CANCELLK)
191 ctf_enum_value("F_DUPFD_CLOEXEC", F_DUPFD_CLOEXEC)
192 ctf_enum_value("F_SETPIPE_SZ", F_SETPIPE_SZ)
193 ctf_enum_value("F_GETPIPE_SZ", F_GETPIPE_SZ)
194 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0))
195 ctf_enum_value("F_ADD_SEALS", F_ADD_SEALS)
196 ctf_enum_value("F_GET_SEALS", F_GET_SEALS)
197 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)) */
198 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0))
199 ctf_enum_value("F_GET_RW_HINT", F_GET_RW_HINT)
200 ctf_enum_value("F_SET_RW_HINT", F_SET_RW_HINT)
201 ctf_enum_value("F_GET_FILE_RW_HINT", F_GET_FILE_RW_HINT)
202 ctf_enum_value("F_SET_FILE_RW_HINT", F_SET_FILE_RW_HINT)
203 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)) */
204 )
205 )
206
207 #define OVERRIDE_32_fcntl
208 #define OVERRIDE_64_fcntl
209 SC_LTTNG_TRACEPOINT_EVENT(fcntl,
210 TP_PROTO(sc_exit(long ret,) unsigned int fd, unsigned int cmd, unsigned long arg),
211 TP_ARGS(sc_exit(ret,) fd, cmd, arg),
212 TP_FIELDS(
213 sc_exit(ctf_integer(long, ret, ret))
214 sc_in(ctf_integer(unsigned int, fd, fd))
215 sc_in(ctf_enum(lttng_fcntl_cmd_flags, unsigned int, cmd, cmd))
216 sc_inout(ctf_integer(unsigned long, arg, arg)))
217 )
218
219 #endif /* CREATE_SYSCALL_TABLE */
This page took 0.03501 seconds and 4 git commands to generate.