Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
259b6cb3 MD |
3 | * lttng-syscalls.c |
4 | * | |
2faf7d1b | 5 | * LTTng syscall probes. |
259b6cb3 | 6 | * |
886d51a3 | 7 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
259b6cb3 MD |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/slab.h> | |
6333ace3 | 12 | #include <linux/compat.h> |
abc0446a | 13 | #include <linux/err.h> |
80f87dd2 | 14 | #include <linux/bitmap.h> |
7ca580f8 MD |
15 | #include <linux/in.h> |
16 | #include <linux/in6.h> | |
2d2464bd | 17 | #include <linux/seq_file.h> |
d4291869 | 18 | #include <linux/stringify.h> |
082d4946 MD |
19 | #include <linux/file.h> |
20 | #include <linux/anon_inodes.h> | |
259b6cb3 MD |
21 | #include <asm/ptrace.h> |
22 | #include <asm/syscall.h> | |
23 | ||
241ae9a8 MD |
24 | #include <lib/bitfield.h> |
25 | #include <wrapper/tracepoint.h> | |
26 | #include <wrapper/file.h> | |
27 | #include <wrapper/rcu.h> | |
1b7b9c65 | 28 | #include <wrapper/syscall.h> |
241ae9a8 | 29 | #include <lttng-events.h> |
259b6cb3 | 30 | |
6333ace3 | 31 | #ifndef CONFIG_COMPAT |
bfa949bf MD |
32 | # ifndef is_compat_task |
33 | # define is_compat_task() (0) | |
34 | # endif | |
6333ace3 MD |
35 | #endif |
36 | ||
1aa3298b MD |
37 | /* in_compat_syscall appears in kernel 4.6. */ |
38 | #ifndef in_compat_syscall | |
39 | #define in_compat_syscall() is_compat_task() | |
40 | #endif | |
41 | ||
5b7ac358 MD |
42 | enum sc_type { |
43 | SC_TYPE_ENTRY, | |
44 | SC_TYPE_EXIT, | |
45 | SC_TYPE_COMPAT_ENTRY, | |
46 | SC_TYPE_COMPAT_EXIT, | |
47 | }; | |
48 | ||
d4291869 MD |
49 | #define SYSCALL_ENTRY_TOK syscall_entry_ |
50 | #define COMPAT_SYSCALL_ENTRY_TOK compat_syscall_entry_ | |
51 | #define SYSCALL_EXIT_TOK syscall_exit_ | |
52 | #define COMPAT_SYSCALL_EXIT_TOK compat_syscall_exit_ | |
53 | ||
54 | #define SYSCALL_ENTRY_STR __stringify(SYSCALL_ENTRY_TOK) | |
55 | #define COMPAT_SYSCALL_ENTRY_STR __stringify(COMPAT_SYSCALL_ENTRY_TOK) | |
56 | #define SYSCALL_EXIT_STR __stringify(SYSCALL_EXIT_TOK) | |
57 | #define COMPAT_SYSCALL_EXIT_STR __stringify(COMPAT_SYSCALL_EXIT_TOK) | |
5b7ac358 | 58 | |
a93244f8 | 59 | static |
2faf7d1b | 60 | void syscall_entry_probe(void *__data, struct pt_regs *regs, long id); |
5b7ac358 MD |
61 | static |
62 | void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret); | |
259b6cb3 | 63 | |
3a523f5b MD |
64 | /* |
65 | * Forward declarations for old kernels. | |
66 | */ | |
67 | struct mmsghdr; | |
68 | struct rlimit64; | |
69 | struct oldold_utsname; | |
70 | struct old_utsname; | |
71 | struct sel_arg_struct; | |
72 | struct mmap_arg_struct; | |
c0b71117 | 73 | struct file_handle; |
a292e6f1 | 74 | struct user_msghdr; |
3a523f5b | 75 | |
393f0993 MJ |
76 | /* |
77 | * Forward declaration for kernels >= 5.6 | |
78 | */ | |
79 | struct timex; | |
80 | ||
80f87dd2 MD |
81 | #ifdef IA32_NR_syscalls |
82 | #define NR_compat_syscalls IA32_NR_syscalls | |
83 | #else | |
84 | #define NR_compat_syscalls NR_syscalls | |
85 | #endif | |
86 | ||
259b6cb3 MD |
87 | /* |
88 | * Create LTTng tracepoint probes. | |
89 | */ | |
90 | #define LTTNG_PACKAGE_BUILD | |
91 | #define CREATE_TRACE_POINTS | |
2655f9ad | 92 | #define TP_MODULE_NOINIT |
c075712b | 93 | #define TRACE_INCLUDE_PATH instrumentation/syscalls/headers |
259b6cb3 | 94 | |
a93244f8 MD |
95 | #define PARAMS(args...) args |
96 | ||
5b7ac358 | 97 | /* Handle unknown syscalls */ |
72a52753 | 98 | #undef TRACE_SYSTEM |
5b7ac358 | 99 | #define TRACE_SYSTEM syscalls_unknown |
241ae9a8 | 100 | #include <instrumentation/syscalls/headers/syscalls_unknown.h> |
5b7ac358 MD |
101 | #undef TRACE_SYSTEM |
102 | ||
fc4f7161 MD |
103 | #define SC_ENTER |
104 | ||
fc4f7161 MD |
105 | #undef sc_exit |
106 | #define sc_exit(...) | |
b75d00c4 MD |
107 | #undef sc_in |
108 | #define sc_in(...) __VA_ARGS__ | |
109 | #undef sc_out | |
110 | #define sc_out(...) | |
111 | #undef sc_inout | |
112 | #define sc_inout(...) __VA_ARGS__ | |
5b7ac358 MD |
113 | |
114 | /* Hijack probe callback for system call enter */ | |
a93244f8 | 115 | #undef TP_PROBE_CB |
259b6cb3 | 116 | #define TP_PROBE_CB(_template) &syscall_entry_probe |
57ede728 | 117 | #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ |
d4291869 | 118 | LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ |
57ede728 | 119 | PARAMS(_fields)) |
265822ae | 120 | #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
d4291869 | 121 | LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ |
265822ae MD |
122 | PARAMS(_locvar), PARAMS(_code_pre), \ |
123 | PARAMS(_fields), PARAMS(_code_post)) | |
57ede728 MD |
124 | #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
125 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields)) | |
cb3ef14c | 126 | #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ |
d4291869 | 127 | LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name) |
141ddf28 MD |
128 | /* Enumerations only defined at first inclusion. */ |
129 | #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \ | |
130 | LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values)) | |
a93244f8 | 131 | #undef TRACE_SYSTEM |
d4291869 | 132 | #define TRACE_SYSTEM syscall_entry_integers |
5b7ac358 | 133 | #define TRACE_INCLUDE_FILE syscalls_integers |
241ae9a8 | 134 | #include <instrumentation/syscalls/headers/syscalls_integers.h> |
5b7ac358 | 135 | #undef TRACE_INCLUDE_FILE |
a93244f8 | 136 | #undef TRACE_SYSTEM |
d4291869 | 137 | #define TRACE_SYSTEM syscall_entry_pointers |
5b7ac358 | 138 | #define TRACE_INCLUDE_FILE syscalls_pointers |
241ae9a8 | 139 | #include <instrumentation/syscalls/headers/syscalls_pointers.h> |
5b7ac358 | 140 | #undef TRACE_INCLUDE_FILE |
a93244f8 | 141 | #undef TRACE_SYSTEM |
141ddf28 | 142 | #undef SC_LTTNG_TRACEPOINT_ENUM |
cb3ef14c MD |
143 | #undef SC_LTTNG_TRACEPOINT_EVENT_CODE |
144 | #undef SC_LTTNG_TRACEPOINT_EVENT | |
145 | #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS | |
146 | #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS | |
5b7ac358 | 147 | #undef TP_PROBE_CB |
3bc29f0a MD |
148 | #undef _TRACE_SYSCALLS_INTEGERS_H |
149 | #undef _TRACE_SYSCALLS_POINTERS_H | |
5b7ac358 MD |
150 | |
151 | /* Hijack probe callback for compat system call enter */ | |
a93244f8 | 152 | #define TP_PROBE_CB(_template) &syscall_entry_probe |
771af27e | 153 | #define LTTNG_SC_COMPAT |
57ede728 | 154 | #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ |
d4291869 | 155 | LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ |
57ede728 | 156 | PARAMS(_fields)) |
265822ae | 157 | #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
d4291869 | 158 | LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ |
265822ae | 159 | PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) |
57ede728 MD |
160 | #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
161 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields)) | |
cb3ef14c | 162 | #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ |
d4291869 MD |
163 | LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_entry_##_template, \ |
164 | compat_syscall_entry_##_name) | |
141ddf28 MD |
165 | /* Enumerations only defined at inital inclusion (not here). */ |
166 | #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) | |
d4291869 | 167 | #define TRACE_SYSTEM compat_syscall_entry_integers |
5b7ac358 | 168 | #define TRACE_INCLUDE_FILE compat_syscalls_integers |
241ae9a8 | 169 | #include <instrumentation/syscalls/headers/compat_syscalls_integers.h> |
5b7ac358 MD |
170 | #undef TRACE_INCLUDE_FILE |
171 | #undef TRACE_SYSTEM | |
d4291869 | 172 | #define TRACE_SYSTEM compat_syscall_entry_pointers |
5b7ac358 | 173 | #define TRACE_INCLUDE_FILE compat_syscalls_pointers |
241ae9a8 | 174 | #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h> |
5b7ac358 MD |
175 | #undef TRACE_INCLUDE_FILE |
176 | #undef TRACE_SYSTEM | |
141ddf28 | 177 | #undef SC_LTTNG_TRACEPOINT_ENUM |
cb3ef14c MD |
178 | #undef SC_LTTNG_TRACEPOINT_EVENT_CODE |
179 | #undef SC_LTTNG_TRACEPOINT_EVENT | |
180 | #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS | |
181 | #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS | |
5b7ac358 | 182 | #undef TP_PROBE_CB |
3bc29f0a MD |
183 | #undef _TRACE_SYSCALLS_INTEGERS_H |
184 | #undef _TRACE_SYSCALLS_POINTERS_H | |
771af27e | 185 | #undef LTTNG_SC_COMPAT |
5b7ac358 | 186 | |
fc4f7161 MD |
187 | #undef SC_ENTER |
188 | ||
189 | #define SC_EXIT | |
190 | ||
fc4f7161 MD |
191 | #undef sc_exit |
192 | #define sc_exit(...) __VA_ARGS__ | |
b75d00c4 MD |
193 | #undef sc_in |
194 | #define sc_in(...) | |
195 | #undef sc_out | |
196 | #define sc_out(...) __VA_ARGS__ | |
197 | #undef sc_inout | |
198 | #define sc_inout(...) __VA_ARGS__ | |
5b7ac358 MD |
199 | |
200 | /* Hijack probe callback for system call exit */ | |
201 | #define TP_PROBE_CB(_template) &syscall_exit_probe | |
57ede728 | 202 | #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ |
3bc29f0a | 203 | LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ |
57ede728 | 204 | PARAMS(_fields)) |
265822ae | 205 | #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
3bc29f0a | 206 | LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ |
265822ae | 207 | PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) |
57ede728 MD |
208 | #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
209 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields)) | |
cb3ef14c MD |
210 | #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ |
211 | LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, \ | |
5b7ac358 | 212 | syscall_exit_##_name) |
141ddf28 MD |
213 | /* Enumerations only defined at inital inclusion (not here). */ |
214 | #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) | |
5b7ac358 MD |
215 | #define TRACE_SYSTEM syscall_exit_integers |
216 | #define TRACE_INCLUDE_FILE syscalls_integers | |
241ae9a8 | 217 | #include <instrumentation/syscalls/headers/syscalls_integers.h> |
5b7ac358 MD |
218 | #undef TRACE_INCLUDE_FILE |
219 | #undef TRACE_SYSTEM | |
220 | #define TRACE_SYSTEM syscall_exit_pointers | |
221 | #define TRACE_INCLUDE_FILE syscalls_pointers | |
241ae9a8 | 222 | #include <instrumentation/syscalls/headers/syscalls_pointers.h> |
5b7ac358 MD |
223 | #undef TRACE_INCLUDE_FILE |
224 | #undef TRACE_SYSTEM | |
141ddf28 | 225 | #undef SC_LTTNG_TRACEPOINT_ENUM |
cb3ef14c MD |
226 | #undef SC_LTTNG_TRACEPOINT_EVENT_CODE |
227 | #undef SC_LTTNG_TRACEPOINT_EVENT | |
228 | #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS | |
229 | #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS | |
5b7ac358 | 230 | #undef TP_PROBE_CB |
3bc29f0a MD |
231 | #undef _TRACE_SYSCALLS_INTEGERS_H |
232 | #undef _TRACE_SYSCALLS_POINTERS_H | |
5b7ac358 MD |
233 | |
234 | ||
235 | /* Hijack probe callback for compat system call exit */ | |
236 | #define TP_PROBE_CB(_template) &syscall_exit_probe | |
771af27e | 237 | #define LTTNG_SC_COMPAT |
57ede728 | 238 | #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ |
3bc29f0a | 239 | LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ |
57ede728 | 240 | PARAMS(_fields)) |
265822ae | 241 | #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
3bc29f0a | 242 | LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ |
265822ae | 243 | PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) |
57ede728 MD |
244 | #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
245 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields)) | |
cb3ef14c | 246 | #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ |
3bc29f0a | 247 | LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, \ |
5b7ac358 | 248 | compat_syscall_exit_##_name) |
141ddf28 MD |
249 | /* Enumerations only defined at inital inclusion (not here). */ |
250 | #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) | |
5b7ac358 MD |
251 | #define TRACE_SYSTEM compat_syscall_exit_integers |
252 | #define TRACE_INCLUDE_FILE compat_syscalls_integers | |
241ae9a8 | 253 | #include <instrumentation/syscalls/headers/compat_syscalls_integers.h> |
5b7ac358 | 254 | #undef TRACE_INCLUDE_FILE |
a93244f8 | 255 | #undef TRACE_SYSTEM |
5b7ac358 MD |
256 | #define TRACE_SYSTEM compat_syscall_exit_pointers |
257 | #define TRACE_INCLUDE_FILE compat_syscalls_pointers | |
241ae9a8 | 258 | #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h> |
5b7ac358 | 259 | #undef TRACE_INCLUDE_FILE |
a93244f8 | 260 | #undef TRACE_SYSTEM |
141ddf28 | 261 | #undef SC_LTTNG_TRACEPOINT_ENUM |
cb3ef14c MD |
262 | #undef SC_LTTNG_TRACEPOINT_EVENT_CODE |
263 | #undef SC_LTTNG_TRACEPOINT_EVENT | |
264 | #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS | |
265 | #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS | |
a93244f8 | 266 | #undef TP_PROBE_CB |
3bc29f0a MD |
267 | #undef _TRACE_SYSCALLS_INTEGERS_H |
268 | #undef _TRACE_SYSCALLS_POINTERS_H | |
771af27e | 269 | #undef LTTNG_SC_COMPAT |
5b7ac358 | 270 | |
fc4f7161 | 271 | #undef SC_EXIT |
259b6cb3 | 272 | |
2655f9ad | 273 | #undef TP_MODULE_NOINIT |
259b6cb3 MD |
274 | #undef LTTNG_PACKAGE_BUILD |
275 | #undef CREATE_TRACE_POINTS | |
276 | ||
a93244f8 MD |
277 | struct trace_syscall_entry { |
278 | void *func; | |
279 | const struct lttng_event_desc *desc; | |
280 | const struct lttng_event_field *fields; | |
281 | unsigned int nrargs; | |
282 | }; | |
283 | ||
284 | #define CREATE_SYSCALL_TABLE | |
285 | ||
fc4f7161 MD |
286 | #define SC_ENTER |
287 | ||
288 | #undef sc_exit | |
289 | #define sc_exit(...) | |
290 | ||
259b6cb3 | 291 | #undef TRACE_SYSCALL_TABLE |
f7bdf4db | 292 | #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ |
259b6cb3 | 293 | [ _nr ] = { \ |
d4291869 | 294 | .func = __event_probe__syscall_entry_##_template, \ |
259b6cb3 | 295 | .nrargs = (_nrargs), \ |
d4291869 MD |
296 | .fields = __event_fields___syscall_entry_##_template, \ |
297 | .desc = &__event_desc___syscall_entry_##_name, \ | |
259b6cb3 MD |
298 | }, |
299 | ||
5b7ac358 | 300 | /* Syscall enter tracing table */ |
49c50022 | 301 | static const struct trace_syscall_entry sc_table[] = { |
241ae9a8 MD |
302 | #include <instrumentation/syscalls/headers/syscalls_integers.h> |
303 | #include <instrumentation/syscalls/headers/syscalls_pointers.h> | |
259b6cb3 MD |
304 | }; |
305 | ||
a93244f8 MD |
306 | #undef TRACE_SYSCALL_TABLE |
307 | #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ | |
308 | [ _nr ] = { \ | |
d4291869 | 309 | .func = __event_probe__compat_syscall_entry_##_template, \ |
a93244f8 | 310 | .nrargs = (_nrargs), \ |
d4291869 MD |
311 | .fields = __event_fields___compat_syscall_entry_##_template, \ |
312 | .desc = &__event_desc___compat_syscall_entry_##_name, \ | |
a93244f8 MD |
313 | }, |
314 | ||
5b7ac358 | 315 | /* Compat syscall enter table */ |
a93244f8 | 316 | const struct trace_syscall_entry compat_sc_table[] = { |
241ae9a8 MD |
317 | #include <instrumentation/syscalls/headers/compat_syscalls_integers.h> |
318 | #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h> | |
a93244f8 | 319 | }; |
259b6cb3 | 320 | |
fc4f7161 MD |
321 | #undef SC_ENTER |
322 | ||
323 | #define SC_EXIT | |
324 | ||
325 | #undef sc_exit | |
326 | #define sc_exit(...) __VA_ARGS__ | |
327 | ||
5b7ac358 MD |
328 | #undef TRACE_SYSCALL_TABLE |
329 | #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ | |
330 | [ _nr ] = { \ | |
331 | .func = __event_probe__syscall_exit_##_template, \ | |
332 | .nrargs = (_nrargs), \ | |
333 | .fields = __event_fields___syscall_exit_##_template, \ | |
334 | .desc = &__event_desc___syscall_exit_##_name, \ | |
335 | }, | |
336 | ||
337 | /* Syscall exit table */ | |
338 | static const struct trace_syscall_entry sc_exit_table[] = { | |
241ae9a8 MD |
339 | #include <instrumentation/syscalls/headers/syscalls_integers.h> |
340 | #include <instrumentation/syscalls/headers/syscalls_pointers.h> | |
5b7ac358 MD |
341 | }; |
342 | ||
343 | #undef TRACE_SYSCALL_TABLE | |
344 | #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ | |
345 | [ _nr ] = { \ | |
346 | .func = __event_probe__compat_syscall_exit_##_template, \ | |
347 | .nrargs = (_nrargs), \ | |
348 | .fields = __event_fields___compat_syscall_exit_##_template, \ | |
349 | .desc = &__event_desc___compat_syscall_exit_##_name, \ | |
350 | }, | |
351 | ||
352 | /* Compat syscall exit table */ | |
353 | const struct trace_syscall_entry compat_sc_exit_table[] = { | |
241ae9a8 MD |
354 | #include <instrumentation/syscalls/headers/compat_syscalls_integers.h> |
355 | #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h> | |
5b7ac358 MD |
356 | }; |
357 | ||
fc4f7161 MD |
358 | #undef SC_EXIT |
359 | ||
a93244f8 | 360 | #undef CREATE_SYSCALL_TABLE |
2faf7d1b | 361 | |
80f87dd2 MD |
362 | struct lttng_syscall_filter { |
363 | DECLARE_BITMAP(sc, NR_syscalls); | |
364 | DECLARE_BITMAP(sc_compat, NR_compat_syscalls); | |
365 | }; | |
366 | ||
a90917c3 | 367 | static void syscall_entry_unknown(struct lttng_event *event, |
f405cfce MD |
368 | struct pt_regs *regs, unsigned int id) |
369 | { | |
1b7b9c65 | 370 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
f405cfce | 371 | |
1b7b9c65 | 372 | lttng_syscall_get_arguments(current, regs, args); |
1aa3298b | 373 | if (unlikely(in_compat_syscall())) |
d4291869 | 374 | __event_probe__compat_syscall_entry_unknown(event, id, args); |
a93244f8 | 375 | else |
d4291869 | 376 | __event_probe__syscall_entry_unknown(event, id, args); |
f405cfce MD |
377 | } |
378 | ||
2faf7d1b | 379 | void syscall_entry_probe(void *__data, struct pt_regs *regs, long id) |
259b6cb3 | 380 | { |
a90917c3 MD |
381 | struct lttng_channel *chan = __data; |
382 | struct lttng_event *event, *unknown_event; | |
49c50022 MD |
383 | const struct trace_syscall_entry *table, *entry; |
384 | size_t table_len; | |
259b6cb3 | 385 | |
1aa3298b | 386 | if (unlikely(in_compat_syscall())) { |
80f87dd2 MD |
387 | struct lttng_syscall_filter *filter; |
388 | ||
49e2f4c4 | 389 | filter = lttng_rcu_dereference(chan->sc_filter); |
80f87dd2 | 390 | if (filter) { |
74f7b56a | 391 | if (id < 0 || id >= NR_compat_syscalls |
80f87dd2 MD |
392 | || !test_bit(id, filter->sc_compat)) { |
393 | /* System call filtered out. */ | |
394 | return; | |
395 | } | |
396 | } | |
49c50022 | 397 | table = compat_sc_table; |
a93244f8 | 398 | table_len = ARRAY_SIZE(compat_sc_table); |
49c50022 MD |
399 | unknown_event = chan->sc_compat_unknown; |
400 | } else { | |
80f87dd2 MD |
401 | struct lttng_syscall_filter *filter; |
402 | ||
49e2f4c4 | 403 | filter = lttng_rcu_dereference(chan->sc_filter); |
80f87dd2 | 404 | if (filter) { |
74f7b56a | 405 | if (id < 0 || id >= NR_syscalls |
80f87dd2 MD |
406 | || !test_bit(id, filter->sc)) { |
407 | /* System call filtered out. */ | |
408 | return; | |
409 | } | |
410 | } | |
49c50022 MD |
411 | table = sc_table; |
412 | table_len = ARRAY_SIZE(sc_table); | |
413 | unknown_event = chan->sc_unknown; | |
b76dc1a0 | 414 | } |
74f7b56a | 415 | if (unlikely(id < 0 || id >= table_len)) { |
49c50022 | 416 | syscall_entry_unknown(unknown_event, regs, id); |
259b6cb3 | 417 | return; |
f405cfce | 418 | } |
1aa3298b | 419 | if (unlikely(in_compat_syscall())) |
49c50022 MD |
420 | event = chan->compat_sc_table[id]; |
421 | else | |
422 | event = chan->sc_table[id]; | |
f405cfce | 423 | if (unlikely(!event)) { |
49c50022 | 424 | syscall_entry_unknown(unknown_event, regs, id); |
f405cfce MD |
425 | return; |
426 | } | |
49c50022 | 427 | entry = &table[id]; |
f405cfce | 428 | WARN_ON_ONCE(!entry); |
259b6cb3 MD |
429 | |
430 | switch (entry->nrargs) { | |
431 | case 0: | |
432 | { | |
433 | void (*fptr)(void *__data) = entry->func; | |
434 | ||
435 | fptr(event); | |
436 | break; | |
437 | } | |
438 | case 1: | |
439 | { | |
440 | void (*fptr)(void *__data, unsigned long arg0) = entry->func; | |
1b7b9c65 | 441 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
259b6cb3 | 442 | |
1b7b9c65 | 443 | lttng_syscall_get_arguments(current, regs, args); |
259b6cb3 MD |
444 | fptr(event, args[0]); |
445 | break; | |
446 | } | |
447 | case 2: | |
448 | { | |
449 | void (*fptr)(void *__data, | |
450 | unsigned long arg0, | |
451 | unsigned long arg1) = entry->func; | |
1b7b9c65 | 452 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
259b6cb3 | 453 | |
1b7b9c65 | 454 | lttng_syscall_get_arguments(current, regs, args); |
259b6cb3 MD |
455 | fptr(event, args[0], args[1]); |
456 | break; | |
457 | } | |
458 | case 3: | |
459 | { | |
460 | void (*fptr)(void *__data, | |
461 | unsigned long arg0, | |
462 | unsigned long arg1, | |
463 | unsigned long arg2) = entry->func; | |
1b7b9c65 | 464 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
259b6cb3 | 465 | |
1b7b9c65 | 466 | lttng_syscall_get_arguments(current, regs, args); |
259b6cb3 MD |
467 | fptr(event, args[0], args[1], args[2]); |
468 | break; | |
469 | } | |
470 | case 4: | |
471 | { | |
472 | void (*fptr)(void *__data, | |
473 | unsigned long arg0, | |
474 | unsigned long arg1, | |
475 | unsigned long arg2, | |
476 | unsigned long arg3) = entry->func; | |
1b7b9c65 | 477 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
259b6cb3 | 478 | |
1b7b9c65 | 479 | lttng_syscall_get_arguments(current, regs, args); |
259b6cb3 MD |
480 | fptr(event, args[0], args[1], args[2], args[3]); |
481 | break; | |
482 | } | |
483 | case 5: | |
484 | { | |
485 | void (*fptr)(void *__data, | |
486 | unsigned long arg0, | |
487 | unsigned long arg1, | |
488 | unsigned long arg2, | |
489 | unsigned long arg3, | |
490 | unsigned long arg4) = entry->func; | |
1b7b9c65 | 491 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
259b6cb3 | 492 | |
1b7b9c65 | 493 | lttng_syscall_get_arguments(current, regs, args); |
259b6cb3 MD |
494 | fptr(event, args[0], args[1], args[2], args[3], args[4]); |
495 | break; | |
496 | } | |
497 | case 6: | |
498 | { | |
499 | void (*fptr)(void *__data, | |
500 | unsigned long arg0, | |
501 | unsigned long arg1, | |
502 | unsigned long arg2, | |
503 | unsigned long arg3, | |
504 | unsigned long arg4, | |
505 | unsigned long arg5) = entry->func; | |
1b7b9c65 | 506 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
259b6cb3 | 507 | |
1b7b9c65 | 508 | lttng_syscall_get_arguments(current, regs, args); |
259b6cb3 MD |
509 | fptr(event, args[0], args[1], args[2], |
510 | args[3], args[4], args[5]); | |
511 | break; | |
512 | } | |
513 | default: | |
514 | break; | |
515 | } | |
516 | } | |
517 | ||
5b7ac358 | 518 | static void syscall_exit_unknown(struct lttng_event *event, |
74f7b56a | 519 | struct pt_regs *regs, int id, long ret) |
5b7ac358 | 520 | { |
1b7b9c65 | 521 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
5b7ac358 | 522 | |
1b7b9c65 | 523 | lttng_syscall_get_arguments(current, regs, args); |
1aa3298b | 524 | if (unlikely(in_compat_syscall())) |
5b7ac358 MD |
525 | __event_probe__compat_syscall_exit_unknown(event, id, ret, |
526 | args); | |
527 | else | |
528 | __event_probe__syscall_exit_unknown(event, id, ret, args); | |
529 | } | |
530 | ||
531 | void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret) | |
532 | { | |
533 | struct lttng_channel *chan = __data; | |
534 | struct lttng_event *event, *unknown_event; | |
535 | const struct trace_syscall_entry *table, *entry; | |
536 | size_t table_len; | |
537 | long id; | |
538 | ||
539 | id = syscall_get_nr(current, regs); | |
1aa3298b | 540 | if (unlikely(in_compat_syscall())) { |
5b7ac358 MD |
541 | struct lttng_syscall_filter *filter; |
542 | ||
49e2f4c4 | 543 | filter = lttng_rcu_dereference(chan->sc_filter); |
5b7ac358 | 544 | if (filter) { |
74f7b56a | 545 | if (id < 0 || id >= NR_compat_syscalls |
5b7ac358 MD |
546 | || !test_bit(id, filter->sc_compat)) { |
547 | /* System call filtered out. */ | |
548 | return; | |
549 | } | |
550 | } | |
551 | table = compat_sc_exit_table; | |
552 | table_len = ARRAY_SIZE(compat_sc_exit_table); | |
553 | unknown_event = chan->compat_sc_exit_unknown; | |
554 | } else { | |
555 | struct lttng_syscall_filter *filter; | |
556 | ||
49e2f4c4 | 557 | filter = lttng_rcu_dereference(chan->sc_filter); |
5b7ac358 | 558 | if (filter) { |
74f7b56a | 559 | if (id < 0 || id >= NR_syscalls |
5b7ac358 MD |
560 | || !test_bit(id, filter->sc)) { |
561 | /* System call filtered out. */ | |
562 | return; | |
563 | } | |
564 | } | |
565 | table = sc_exit_table; | |
566 | table_len = ARRAY_SIZE(sc_exit_table); | |
567 | unknown_event = chan->sc_exit_unknown; | |
568 | } | |
74f7b56a | 569 | if (unlikely(id < 0 || id >= table_len)) { |
5b7ac358 MD |
570 | syscall_exit_unknown(unknown_event, regs, id, ret); |
571 | return; | |
572 | } | |
1aa3298b | 573 | if (unlikely(in_compat_syscall())) |
5b7ac358 MD |
574 | event = chan->compat_sc_exit_table[id]; |
575 | else | |
576 | event = chan->sc_exit_table[id]; | |
577 | if (unlikely(!event)) { | |
578 | syscall_exit_unknown(unknown_event, regs, id, ret); | |
579 | return; | |
580 | } | |
581 | entry = &table[id]; | |
582 | WARN_ON_ONCE(!entry); | |
583 | ||
584 | switch (entry->nrargs) { | |
585 | case 0: | |
586 | { | |
fc4f7161 | 587 | void (*fptr)(void *__data, long ret) = entry->func; |
5b7ac358 | 588 | |
fc4f7161 | 589 | fptr(event, ret); |
5b7ac358 MD |
590 | break; |
591 | } | |
592 | case 1: | |
593 | { | |
594 | void (*fptr)(void *__data, | |
fc4f7161 | 595 | long ret, |
5b7ac358 | 596 | unsigned long arg0) = entry->func; |
1b7b9c65 | 597 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
5b7ac358 | 598 | |
1b7b9c65 | 599 | lttng_syscall_get_arguments(current, regs, args); |
fc4f7161 | 600 | fptr(event, ret, args[0]); |
5b7ac358 MD |
601 | break; |
602 | } | |
603 | case 2: | |
604 | { | |
605 | void (*fptr)(void *__data, | |
fc4f7161 | 606 | long ret, |
5b7ac358 MD |
607 | unsigned long arg0, |
608 | unsigned long arg1) = entry->func; | |
1b7b9c65 | 609 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
5b7ac358 | 610 | |
1b7b9c65 | 611 | lttng_syscall_get_arguments(current, regs, args); |
fc4f7161 | 612 | fptr(event, ret, args[0], args[1]); |
5b7ac358 MD |
613 | break; |
614 | } | |
615 | case 3: | |
616 | { | |
617 | void (*fptr)(void *__data, | |
fc4f7161 | 618 | long ret, |
5b7ac358 MD |
619 | unsigned long arg0, |
620 | unsigned long arg1, | |
621 | unsigned long arg2) = entry->func; | |
1b7b9c65 | 622 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
5b7ac358 | 623 | |
1b7b9c65 | 624 | lttng_syscall_get_arguments(current, regs, args); |
fc4f7161 | 625 | fptr(event, ret, args[0], args[1], args[2]); |
5b7ac358 MD |
626 | break; |
627 | } | |
628 | case 4: | |
629 | { | |
630 | void (*fptr)(void *__data, | |
fc4f7161 | 631 | long ret, |
5b7ac358 MD |
632 | unsigned long arg0, |
633 | unsigned long arg1, | |
634 | unsigned long arg2, | |
635 | unsigned long arg3) = entry->func; | |
1b7b9c65 | 636 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
5b7ac358 | 637 | |
1b7b9c65 | 638 | lttng_syscall_get_arguments(current, regs, args); |
fc4f7161 | 639 | fptr(event, ret, args[0], args[1], args[2], args[3]); |
5b7ac358 MD |
640 | break; |
641 | } | |
642 | case 5: | |
643 | { | |
644 | void (*fptr)(void *__data, | |
fc4f7161 | 645 | long ret, |
5b7ac358 MD |
646 | unsigned long arg0, |
647 | unsigned long arg1, | |
648 | unsigned long arg2, | |
649 | unsigned long arg3, | |
650 | unsigned long arg4) = entry->func; | |
1b7b9c65 | 651 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
5b7ac358 | 652 | |
1b7b9c65 | 653 | lttng_syscall_get_arguments(current, regs, args); |
fc4f7161 | 654 | fptr(event, ret, args[0], args[1], args[2], args[3], args[4]); |
5b7ac358 MD |
655 | break; |
656 | } | |
657 | case 6: | |
658 | { | |
659 | void (*fptr)(void *__data, | |
fc4f7161 | 660 | long ret, |
5b7ac358 MD |
661 | unsigned long arg0, |
662 | unsigned long arg1, | |
663 | unsigned long arg2, | |
664 | unsigned long arg3, | |
665 | unsigned long arg4, | |
666 | unsigned long arg5) = entry->func; | |
1b7b9c65 | 667 | unsigned long args[LTTNG_SYSCALL_NR_ARGS]; |
5b7ac358 | 668 | |
1b7b9c65 | 669 | lttng_syscall_get_arguments(current, regs, args); |
fc4f7161 | 670 | fptr(event, ret, args[0], args[1], args[2], |
5b7ac358 MD |
671 | args[3], args[4], args[5]); |
672 | break; | |
673 | } | |
674 | default: | |
675 | break; | |
676 | } | |
677 | } | |
678 | ||
33a39a3c MD |
679 | /* |
680 | * noinline to diminish caller stack size. | |
681 | * Should be called with sessions lock held. | |
682 | */ | |
49c50022 MD |
683 | static |
684 | int fill_table(const struct trace_syscall_entry *table, size_t table_len, | |
5b7ac358 MD |
685 | struct lttng_event **chan_table, struct lttng_channel *chan, |
686 | void *filter, enum sc_type type) | |
259b6cb3 | 687 | { |
2a0c4816 | 688 | const struct lttng_event_desc *desc; |
259b6cb3 | 689 | unsigned int i; |
49c50022 MD |
690 | |
691 | /* Allocate events for each syscall, insert into table */ | |
692 | for (i = 0; i < table_len; i++) { | |
693 | struct lttng_kernel_event ev; | |
2a0c4816 | 694 | desc = table[i].desc; |
49c50022 MD |
695 | |
696 | if (!desc) { | |
697 | /* Unknown syscall */ | |
698 | continue; | |
699 | } | |
700 | /* | |
701 | * Skip those already populated by previous failed | |
702 | * register for this channel. | |
703 | */ | |
704 | if (chan_table[i]) | |
705 | continue; | |
706 | memset(&ev, 0, sizeof(ev)); | |
5b7ac358 MD |
707 | switch (type) { |
708 | case SC_TYPE_ENTRY: | |
709 | strncpy(ev.name, SYSCALL_ENTRY_STR, | |
710 | LTTNG_KERNEL_SYM_NAME_LEN); | |
711 | break; | |
712 | case SC_TYPE_EXIT: | |
713 | strncpy(ev.name, SYSCALL_EXIT_STR, | |
714 | LTTNG_KERNEL_SYM_NAME_LEN); | |
715 | break; | |
716 | case SC_TYPE_COMPAT_ENTRY: | |
717 | strncpy(ev.name, COMPAT_SYSCALL_ENTRY_STR, | |
718 | LTTNG_KERNEL_SYM_NAME_LEN); | |
719 | break; | |
720 | case SC_TYPE_COMPAT_EXIT: | |
721 | strncpy(ev.name, COMPAT_SYSCALL_EXIT_STR, | |
722 | LTTNG_KERNEL_SYM_NAME_LEN); | |
723 | break; | |
724 | default: | |
725 | BUG_ON(1); | |
726 | break; | |
727 | } | |
728 | strncat(ev.name, desc->name, | |
729 | LTTNG_KERNEL_SYM_NAME_LEN - strlen(ev.name) - 1); | |
f8695253 | 730 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; |
33a39a3c MD |
731 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
732 | chan_table[i] = _lttng_event_create(chan, &ev, filter, | |
3c997079 | 733 | desc, ev.instrumentation); |
abc0446a MD |
734 | WARN_ON_ONCE(!chan_table[i]); |
735 | if (IS_ERR(chan_table[i])) { | |
49c50022 MD |
736 | /* |
737 | * If something goes wrong in event registration | |
738 | * after the first one, we have no choice but to | |
739 | * leave the previous events in there, until | |
740 | * deleted by session teardown. | |
741 | */ | |
abc0446a | 742 | return PTR_ERR(chan_table[i]); |
49c50022 MD |
743 | } |
744 | } | |
745 | return 0; | |
746 | } | |
747 | ||
33a39a3c MD |
748 | /* |
749 | * Should be called with sessions lock held. | |
750 | */ | |
a90917c3 | 751 | int lttng_syscalls_register(struct lttng_channel *chan, void *filter) |
49c50022 | 752 | { |
2a0c4816 | 753 | struct lttng_kernel_event ev; |
259b6cb3 MD |
754 | int ret; |
755 | ||
756 | wrapper_vmalloc_sync_all(); | |
259b6cb3 MD |
757 | |
758 | if (!chan->sc_table) { | |
759 | /* create syscall table mapping syscall to events */ | |
a90917c3 | 760 | chan->sc_table = kzalloc(sizeof(struct lttng_event *) |
259b6cb3 MD |
761 | * ARRAY_SIZE(sc_table), GFP_KERNEL); |
762 | if (!chan->sc_table) | |
763 | return -ENOMEM; | |
764 | } | |
5b7ac358 MD |
765 | if (!chan->sc_exit_table) { |
766 | /* create syscall table mapping syscall to events */ | |
767 | chan->sc_exit_table = kzalloc(sizeof(struct lttng_event *) | |
768 | * ARRAY_SIZE(sc_exit_table), GFP_KERNEL); | |
769 | if (!chan->sc_exit_table) | |
770 | return -ENOMEM; | |
771 | } | |
772 | ||
259b6cb3 | 773 | |
49c50022 MD |
774 | #ifdef CONFIG_COMPAT |
775 | if (!chan->compat_sc_table) { | |
776 | /* create syscall table mapping compat syscall to events */ | |
a90917c3 | 777 | chan->compat_sc_table = kzalloc(sizeof(struct lttng_event *) |
a93244f8 | 778 | * ARRAY_SIZE(compat_sc_table), GFP_KERNEL); |
49c50022 MD |
779 | if (!chan->compat_sc_table) |
780 | return -ENOMEM; | |
781 | } | |
5b7ac358 MD |
782 | |
783 | if (!chan->compat_sc_exit_table) { | |
784 | /* create syscall table mapping compat syscall to events */ | |
785 | chan->compat_sc_exit_table = kzalloc(sizeof(struct lttng_event *) | |
786 | * ARRAY_SIZE(compat_sc_exit_table), GFP_KERNEL); | |
787 | if (!chan->compat_sc_exit_table) | |
788 | return -ENOMEM; | |
789 | } | |
49c50022 | 790 | #endif |
f405cfce | 791 | if (!chan->sc_unknown) { |
f405cfce | 792 | const struct lttng_event_desc *desc = |
d4291869 | 793 | &__event_desc___syscall_entry_unknown; |
2f804c0a | 794 | |
f405cfce | 795 | memset(&ev, 0, sizeof(ev)); |
f8695253 MD |
796 | strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN); |
797 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
33a39a3c MD |
798 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
799 | chan->sc_unknown = _lttng_event_create(chan, &ev, filter, | |
3c997079 MD |
800 | desc, |
801 | ev.instrumentation); | |
abc0446a MD |
802 | WARN_ON_ONCE(!chan->sc_unknown); |
803 | if (IS_ERR(chan->sc_unknown)) { | |
804 | return PTR_ERR(chan->sc_unknown); | |
f405cfce MD |
805 | } |
806 | } | |
807 | ||
b76dc1a0 | 808 | if (!chan->sc_compat_unknown) { |
b76dc1a0 | 809 | const struct lttng_event_desc *desc = |
d4291869 | 810 | &__event_desc___compat_syscall_entry_unknown; |
b76dc1a0 MD |
811 | |
812 | memset(&ev, 0, sizeof(ev)); | |
f8695253 MD |
813 | strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN); |
814 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
33a39a3c MD |
815 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
816 | chan->sc_compat_unknown = _lttng_event_create(chan, &ev, filter, | |
3c997079 MD |
817 | desc, |
818 | ev.instrumentation); | |
abc0446a MD |
819 | WARN_ON_ONCE(!chan->sc_unknown); |
820 | if (IS_ERR(chan->sc_compat_unknown)) { | |
821 | return PTR_ERR(chan->sc_compat_unknown); | |
b76dc1a0 MD |
822 | } |
823 | } | |
824 | ||
5b7ac358 | 825 | if (!chan->compat_sc_exit_unknown) { |
2f804c0a | 826 | const struct lttng_event_desc *desc = |
5b7ac358 | 827 | &__event_desc___compat_syscall_exit_unknown; |
2f804c0a MD |
828 | |
829 | memset(&ev, 0, sizeof(ev)); | |
f8695253 MD |
830 | strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN); |
831 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
33a39a3c MD |
832 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
833 | chan->compat_sc_exit_unknown = _lttng_event_create(chan, &ev, | |
3c997079 MD |
834 | filter, desc, |
835 | ev.instrumentation); | |
5b7ac358 MD |
836 | WARN_ON_ONCE(!chan->compat_sc_exit_unknown); |
837 | if (IS_ERR(chan->compat_sc_exit_unknown)) { | |
838 | return PTR_ERR(chan->compat_sc_exit_unknown); | |
839 | } | |
840 | } | |
841 | ||
842 | if (!chan->sc_exit_unknown) { | |
843 | const struct lttng_event_desc *desc = | |
844 | &__event_desc___syscall_exit_unknown; | |
845 | ||
846 | memset(&ev, 0, sizeof(ev)); | |
847 | strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN); | |
848 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
33a39a3c MD |
849 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
850 | chan->sc_exit_unknown = _lttng_event_create(chan, &ev, filter, | |
3c997079 | 851 | desc, ev.instrumentation); |
5b7ac358 MD |
852 | WARN_ON_ONCE(!chan->sc_exit_unknown); |
853 | if (IS_ERR(chan->sc_exit_unknown)) { | |
854 | return PTR_ERR(chan->sc_exit_unknown); | |
2f804c0a MD |
855 | } |
856 | } | |
857 | ||
49c50022 | 858 | ret = fill_table(sc_table, ARRAY_SIZE(sc_table), |
5b7ac358 MD |
859 | chan->sc_table, chan, filter, SC_TYPE_ENTRY); |
860 | if (ret) | |
861 | return ret; | |
862 | ret = fill_table(sc_exit_table, ARRAY_SIZE(sc_exit_table), | |
863 | chan->sc_exit_table, chan, filter, SC_TYPE_EXIT); | |
49c50022 MD |
864 | if (ret) |
865 | return ret; | |
5b7ac358 | 866 | |
49c50022 | 867 | #ifdef CONFIG_COMPAT |
a93244f8 | 868 | ret = fill_table(compat_sc_table, ARRAY_SIZE(compat_sc_table), |
5b7ac358 MD |
869 | chan->compat_sc_table, chan, filter, |
870 | SC_TYPE_COMPAT_ENTRY); | |
871 | if (ret) | |
872 | return ret; | |
873 | ret = fill_table(compat_sc_exit_table, ARRAY_SIZE(compat_sc_exit_table), | |
874 | chan->compat_sc_exit_table, chan, filter, | |
875 | SC_TYPE_COMPAT_EXIT); | |
49c50022 MD |
876 | if (ret) |
877 | return ret; | |
878 | #endif | |
80f87dd2 MD |
879 | if (!chan->sys_enter_registered) { |
880 | ret = lttng_wrapper_tracepoint_probe_register("sys_enter", | |
881 | (void *) syscall_entry_probe, chan); | |
882 | if (ret) | |
883 | return ret; | |
884 | chan->sys_enter_registered = 1; | |
885 | } | |
63728b02 MD |
886 | /* |
887 | * We change the name of sys_exit tracepoint due to namespace | |
888 | * conflict with sys_exit syscall entry. | |
889 | */ | |
80f87dd2 MD |
890 | if (!chan->sys_exit_registered) { |
891 | ret = lttng_wrapper_tracepoint_probe_register("sys_exit", | |
5b7ac358 | 892 | (void *) syscall_exit_probe, chan); |
80f87dd2 MD |
893 | if (ret) { |
894 | WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter", | |
895 | (void *) syscall_entry_probe, chan)); | |
896 | return ret; | |
897 | } | |
898 | chan->sys_exit_registered = 1; | |
63728b02 | 899 | } |
259b6cb3 MD |
900 | return ret; |
901 | } | |
902 | ||
903 | /* | |
904 | * Only called at session destruction. | |
905 | */ | |
a90917c3 | 906 | int lttng_syscalls_unregister(struct lttng_channel *chan) |
259b6cb3 MD |
907 | { |
908 | int ret; | |
909 | ||
910 | if (!chan->sc_table) | |
911 | return 0; | |
80f87dd2 | 912 | if (chan->sys_enter_registered) { |
2d9cd7f3 FD |
913 | ret = lttng_wrapper_tracepoint_probe_unregister("sys_enter", |
914 | (void *) syscall_entry_probe, chan); | |
80f87dd2 MD |
915 | if (ret) |
916 | return ret; | |
917 | chan->sys_enter_registered = 0; | |
918 | } | |
919 | if (chan->sys_exit_registered) { | |
2d9cd7f3 FD |
920 | ret = lttng_wrapper_tracepoint_probe_unregister("sys_exit", |
921 | (void *) syscall_exit_probe, chan); | |
80f87dd2 MD |
922 | if (ret) |
923 | return ret; | |
924 | chan->sys_exit_registered = 0; | |
925 | } | |
a90917c3 | 926 | /* lttng_event destroy will be performed by lttng_session_destroy() */ |
259b6cb3 | 927 | kfree(chan->sc_table); |
5b7ac358 | 928 | kfree(chan->sc_exit_table); |
49c50022 MD |
929 | #ifdef CONFIG_COMPAT |
930 | kfree(chan->compat_sc_table); | |
5b7ac358 | 931 | kfree(chan->compat_sc_exit_table); |
49c50022 | 932 | #endif |
80f87dd2 MD |
933 | kfree(chan->sc_filter); |
934 | return 0; | |
935 | } | |
936 | ||
937 | static | |
938 | int get_syscall_nr(const char *syscall_name) | |
939 | { | |
940 | int syscall_nr = -1; | |
941 | int i; | |
942 | ||
943 | for (i = 0; i < ARRAY_SIZE(sc_table); i++) { | |
944 | const struct trace_syscall_entry *entry; | |
5b7ac358 | 945 | const char *it_name; |
80f87dd2 MD |
946 | |
947 | entry = &sc_table[i]; | |
948 | if (!entry->desc) | |
949 | continue; | |
5b7ac358 MD |
950 | it_name = entry->desc->name; |
951 | it_name += strlen(SYSCALL_ENTRY_STR); | |
952 | if (!strcmp(syscall_name, it_name)) { | |
80f87dd2 MD |
953 | syscall_nr = i; |
954 | break; | |
955 | } | |
956 | } | |
957 | return syscall_nr; | |
958 | } | |
959 | ||
960 | static | |
961 | int get_compat_syscall_nr(const char *syscall_name) | |
962 | { | |
963 | int syscall_nr = -1; | |
964 | int i; | |
965 | ||
966 | for (i = 0; i < ARRAY_SIZE(compat_sc_table); i++) { | |
967 | const struct trace_syscall_entry *entry; | |
5b7ac358 | 968 | const char *it_name; |
80f87dd2 MD |
969 | |
970 | entry = &compat_sc_table[i]; | |
971 | if (!entry->desc) | |
972 | continue; | |
5b7ac358 MD |
973 | it_name = entry->desc->name; |
974 | it_name += strlen(COMPAT_SYSCALL_ENTRY_STR); | |
975 | if (!strcmp(syscall_name, it_name)) { | |
80f87dd2 MD |
976 | syscall_nr = i; |
977 | break; | |
978 | } | |
979 | } | |
980 | return syscall_nr; | |
981 | } | |
982 | ||
12e579db MD |
983 | static |
984 | uint32_t get_sc_tables_len(void) | |
985 | { | |
986 | return ARRAY_SIZE(sc_table) + ARRAY_SIZE(compat_sc_table); | |
987 | } | |
988 | ||
80f87dd2 MD |
989 | int lttng_syscall_filter_enable(struct lttng_channel *chan, |
990 | const char *name) | |
991 | { | |
992 | int syscall_nr, compat_syscall_nr, ret; | |
993 | struct lttng_syscall_filter *filter; | |
994 | ||
995 | WARN_ON_ONCE(!chan->sc_table); | |
996 | ||
997 | if (!name) { | |
998 | /* Enable all system calls by removing filter */ | |
999 | if (chan->sc_filter) { | |
1000 | filter = chan->sc_filter; | |
1001 | rcu_assign_pointer(chan->sc_filter, NULL); | |
1002 | synchronize_trace(); | |
1003 | kfree(filter); | |
1004 | } | |
1005 | chan->syscall_all = 1; | |
1006 | return 0; | |
1007 | } | |
1008 | ||
1009 | if (!chan->sc_filter) { | |
1010 | if (chan->syscall_all) { | |
1011 | /* | |
1012 | * All syscalls are already enabled. | |
1013 | */ | |
1014 | return -EEXIST; | |
1015 | } | |
1016 | filter = kzalloc(sizeof(struct lttng_syscall_filter), | |
1017 | GFP_KERNEL); | |
1018 | if (!filter) | |
1019 | return -ENOMEM; | |
1020 | } else { | |
1021 | filter = chan->sc_filter; | |
1022 | } | |
1023 | syscall_nr = get_syscall_nr(name); | |
1024 | compat_syscall_nr = get_compat_syscall_nr(name); | |
1025 | if (syscall_nr < 0 && compat_syscall_nr < 0) { | |
1026 | ret = -ENOENT; | |
1027 | goto error; | |
1028 | } | |
1029 | if (syscall_nr >= 0) { | |
1030 | if (test_bit(syscall_nr, filter->sc)) { | |
1031 | ret = -EEXIST; | |
1032 | goto error; | |
1033 | } | |
1034 | bitmap_set(filter->sc, syscall_nr, 1); | |
1035 | } | |
1036 | if (compat_syscall_nr >= 0) { | |
1037 | if (test_bit(compat_syscall_nr, filter->sc_compat)) { | |
1038 | ret = -EEXIST; | |
1039 | goto error; | |
1040 | } | |
1041 | bitmap_set(filter->sc_compat, compat_syscall_nr, 1); | |
1042 | } | |
1043 | if (!chan->sc_filter) | |
1044 | rcu_assign_pointer(chan->sc_filter, filter); | |
1045 | return 0; | |
1046 | ||
1047 | error: | |
1048 | if (!chan->sc_filter) | |
1049 | kfree(filter); | |
1050 | return ret; | |
1051 | } | |
1052 | ||
1053 | int lttng_syscall_filter_disable(struct lttng_channel *chan, | |
1054 | const char *name) | |
1055 | { | |
1056 | int syscall_nr, compat_syscall_nr, ret; | |
1057 | struct lttng_syscall_filter *filter; | |
1058 | ||
1059 | WARN_ON_ONCE(!chan->sc_table); | |
1060 | ||
1061 | if (!chan->sc_filter) { | |
bcde0d5b MD |
1062 | if (!chan->syscall_all) |
1063 | return -EEXIST; | |
80f87dd2 MD |
1064 | filter = kzalloc(sizeof(struct lttng_syscall_filter), |
1065 | GFP_KERNEL); | |
1066 | if (!filter) | |
1067 | return -ENOMEM; | |
1068 | /* Trace all system calls, then apply disable. */ | |
1069 | bitmap_set(filter->sc, 0, NR_syscalls); | |
1070 | bitmap_set(filter->sc_compat, 0, NR_compat_syscalls); | |
1071 | } else { | |
1072 | filter = chan->sc_filter; | |
1073 | } | |
1074 | ||
72814741 | 1075 | if (!name) { |
404e87bf MD |
1076 | /* Fail if all syscalls are already disabled. */ |
1077 | if (bitmap_empty(filter->sc, NR_syscalls) | |
1078 | && bitmap_empty(filter->sc_compat, | |
1079 | NR_compat_syscalls)) { | |
1080 | ret = -EEXIST; | |
1081 | goto error; | |
1082 | } | |
1083 | ||
72814741 MD |
1084 | /* Disable all system calls */ |
1085 | bitmap_clear(filter->sc, 0, NR_syscalls); | |
1086 | bitmap_clear(filter->sc_compat, 0, NR_compat_syscalls); | |
1087 | goto apply_filter; | |
1088 | } | |
80f87dd2 MD |
1089 | syscall_nr = get_syscall_nr(name); |
1090 | compat_syscall_nr = get_compat_syscall_nr(name); | |
1091 | if (syscall_nr < 0 && compat_syscall_nr < 0) { | |
1092 | ret = -ENOENT; | |
1093 | goto error; | |
1094 | } | |
1095 | if (syscall_nr >= 0) { | |
cecef7f8 | 1096 | if (!test_bit(syscall_nr, filter->sc)) { |
80f87dd2 MD |
1097 | ret = -EEXIST; |
1098 | goto error; | |
1099 | } | |
cecef7f8 | 1100 | bitmap_clear(filter->sc, syscall_nr, 1); |
80f87dd2 MD |
1101 | } |
1102 | if (compat_syscall_nr >= 0) { | |
cecef7f8 | 1103 | if (!test_bit(compat_syscall_nr, filter->sc_compat)) { |
80f87dd2 MD |
1104 | ret = -EEXIST; |
1105 | goto error; | |
1106 | } | |
cecef7f8 | 1107 | bitmap_clear(filter->sc_compat, compat_syscall_nr, 1); |
80f87dd2 | 1108 | } |
72814741 | 1109 | apply_filter: |
80f87dd2 MD |
1110 | if (!chan->sc_filter) |
1111 | rcu_assign_pointer(chan->sc_filter, filter); | |
1112 | chan->syscall_all = 0; | |
259b6cb3 | 1113 | return 0; |
80f87dd2 MD |
1114 | |
1115 | error: | |
1116 | if (!chan->sc_filter) | |
1117 | kfree(filter); | |
1118 | return ret; | |
259b6cb3 | 1119 | } |
2d2464bd MD |
1120 | |
1121 | static | |
1122 | const struct trace_syscall_entry *syscall_list_get_entry(loff_t *pos) | |
1123 | { | |
1124 | const struct trace_syscall_entry *entry; | |
1125 | int iter = 0; | |
1126 | ||
1127 | for (entry = sc_table; | |
1128 | entry < sc_table + ARRAY_SIZE(sc_table); | |
1129 | entry++) { | |
1130 | if (iter++ >= *pos) | |
1131 | return entry; | |
1132 | } | |
1133 | for (entry = compat_sc_table; | |
1134 | entry < compat_sc_table + ARRAY_SIZE(compat_sc_table); | |
1135 | entry++) { | |
1136 | if (iter++ >= *pos) | |
1137 | return entry; | |
1138 | } | |
1139 | /* End of list */ | |
1140 | return NULL; | |
1141 | } | |
1142 | ||
1143 | static | |
1144 | void *syscall_list_start(struct seq_file *m, loff_t *pos) | |
1145 | { | |
1146 | return (void *) syscall_list_get_entry(pos); | |
1147 | } | |
1148 | ||
1149 | static | |
1150 | void *syscall_list_next(struct seq_file *m, void *p, loff_t *ppos) | |
1151 | { | |
1152 | (*ppos)++; | |
1153 | return (void *) syscall_list_get_entry(ppos); | |
1154 | } | |
1155 | ||
1156 | static | |
1157 | void syscall_list_stop(struct seq_file *m, void *p) | |
1158 | { | |
1159 | } | |
1160 | ||
12e579db MD |
1161 | static |
1162 | int get_sc_table(const struct trace_syscall_entry *entry, | |
1163 | const struct trace_syscall_entry **table, | |
1164 | unsigned int *bitness) | |
1165 | { | |
1166 | if (entry >= sc_table && entry < sc_table + ARRAY_SIZE(sc_table)) { | |
1167 | if (bitness) | |
1168 | *bitness = BITS_PER_LONG; | |
1169 | if (table) | |
1170 | *table = sc_table; | |
1171 | return 0; | |
1172 | } | |
1173 | if (!(entry >= compat_sc_table | |
1174 | && entry < compat_sc_table + ARRAY_SIZE(compat_sc_table))) { | |
1175 | return -EINVAL; | |
1176 | } | |
1177 | if (bitness) | |
1178 | *bitness = 32; | |
1179 | if (table) | |
1180 | *table = compat_sc_table; | |
1181 | return 0; | |
1182 | } | |
1183 | ||
2d2464bd MD |
1184 | static |
1185 | int syscall_list_show(struct seq_file *m, void *p) | |
1186 | { | |
1187 | const struct trace_syscall_entry *table, *entry = p; | |
1188 | unsigned int bitness; | |
d4291869 | 1189 | unsigned long index; |
12e579db | 1190 | int ret; |
d4291869 | 1191 | const char *name; |
2d2464bd | 1192 | |
12e579db MD |
1193 | ret = get_sc_table(entry, &table, &bitness); |
1194 | if (ret) | |
1195 | return ret; | |
f4855b46 MD |
1196 | if (!entry->desc) |
1197 | return 0; | |
d4291869 MD |
1198 | if (table == sc_table) { |
1199 | index = entry - table; | |
1200 | name = &entry->desc->name[strlen(SYSCALL_ENTRY_STR)]; | |
1201 | } else { | |
1202 | index = (entry - table) + ARRAY_SIZE(sc_table); | |
1203 | name = &entry->desc->name[strlen(COMPAT_SYSCALL_ENTRY_STR)]; | |
1204 | } | |
12e579db | 1205 | seq_printf(m, "syscall { index = %lu; name = %s; bitness = %u; };\n", |
d4291869 | 1206 | index, name, bitness); |
2d2464bd MD |
1207 | return 0; |
1208 | } | |
1209 | ||
1210 | static | |
1211 | const struct seq_operations lttng_syscall_list_seq_ops = { | |
1212 | .start = syscall_list_start, | |
1213 | .next = syscall_list_next, | |
1214 | .stop = syscall_list_stop, | |
1215 | .show = syscall_list_show, | |
1216 | }; | |
1217 | ||
1218 | static | |
1219 | int lttng_syscall_list_open(struct inode *inode, struct file *file) | |
1220 | { | |
1221 | return seq_open(file, <tng_syscall_list_seq_ops); | |
1222 | } | |
1223 | ||
1224 | const struct file_operations lttng_syscall_list_fops = { | |
1225 | .owner = THIS_MODULE, | |
1226 | .open = lttng_syscall_list_open, | |
1227 | .read = seq_read, | |
1228 | .llseek = seq_lseek, | |
1229 | .release = seq_release, | |
1230 | }; | |
12e579db MD |
1231 | |
1232 | long lttng_channel_syscall_mask(struct lttng_channel *channel, | |
1233 | struct lttng_kernel_syscall_mask __user *usyscall_mask) | |
1234 | { | |
1235 | uint32_t len, sc_tables_len, bitmask_len; | |
1236 | int ret = 0, bit; | |
1237 | char *tmp_mask; | |
1238 | struct lttng_syscall_filter *filter; | |
1239 | ||
1240 | ret = get_user(len, &usyscall_mask->len); | |
1241 | if (ret) | |
1242 | return ret; | |
1243 | sc_tables_len = get_sc_tables_len(); | |
1244 | bitmask_len = ALIGN(sc_tables_len, 8) >> 3; | |
1245 | if (len < sc_tables_len) { | |
1246 | return put_user(sc_tables_len, &usyscall_mask->len); | |
1247 | } | |
1248 | /* Array is large enough, we can copy array to user-space. */ | |
1249 | tmp_mask = kzalloc(bitmask_len, GFP_KERNEL); | |
1250 | if (!tmp_mask) | |
1251 | return -ENOMEM; | |
1252 | filter = channel->sc_filter; | |
1253 | ||
1254 | for (bit = 0; bit < ARRAY_SIZE(sc_table); bit++) { | |
e2129868 | 1255 | char state; |
2f25059d MD |
1256 | |
1257 | if (channel->sc_table) { | |
1258 | if (filter) | |
1259 | state = test_bit(bit, filter->sc); | |
1260 | else | |
1261 | state = 1; | |
1262 | } else { | |
1263 | state = 0; | |
1264 | } | |
1265 | bt_bitfield_write_be(tmp_mask, char, bit, 1, state); | |
12e579db MD |
1266 | } |
1267 | for (; bit < sc_tables_len; bit++) { | |
e2129868 | 1268 | char state; |
2f25059d MD |
1269 | |
1270 | if (channel->compat_sc_table) { | |
1271 | if (filter) | |
1272 | state = test_bit(bit - ARRAY_SIZE(sc_table), | |
1273 | filter->sc_compat); | |
1274 | else | |
1275 | state = 1; | |
1276 | } else { | |
1277 | state = 0; | |
1278 | } | |
1279 | bt_bitfield_write_be(tmp_mask, char, bit, 1, state); | |
12e579db MD |
1280 | } |
1281 | if (copy_to_user(usyscall_mask->mask, tmp_mask, bitmask_len)) | |
1282 | ret = -EFAULT; | |
1283 | kfree(tmp_mask); | |
1284 | return ret; | |
1285 | } | |
082d4946 MD |
1286 | |
1287 | int lttng_abi_syscall_list(void) | |
1288 | { | |
1289 | struct file *syscall_list_file; | |
1290 | int file_fd, ret; | |
1291 | ||
4ac10b76 | 1292 | file_fd = lttng_get_unused_fd(); |
082d4946 MD |
1293 | if (file_fd < 0) { |
1294 | ret = file_fd; | |
1295 | goto fd_error; | |
1296 | } | |
1297 | ||
1298 | syscall_list_file = anon_inode_getfile("[lttng_syscall_list]", | |
1299 | <tng_syscall_list_fops, | |
1300 | NULL, O_RDWR); | |
1301 | if (IS_ERR(syscall_list_file)) { | |
1302 | ret = PTR_ERR(syscall_list_file); | |
1303 | goto file_error; | |
1304 | } | |
1305 | ret = lttng_syscall_list_fops.open(NULL, syscall_list_file); | |
1306 | if (ret < 0) | |
1307 | goto open_error; | |
1308 | fd_install(file_fd, syscall_list_file); | |
082d4946 MD |
1309 | return file_fd; |
1310 | ||
1311 | open_error: | |
1312 | fput(syscall_list_file); | |
1313 | file_error: | |
1314 | put_unused_fd(file_fd); | |
1315 | fd_error: | |
1316 | return ret; | |
1317 | } |