fix: 'struct timex' removed upstream (v5.6)
[lttng-modules.git] / lttng-syscalls.c
1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
3 * lttng-syscalls.c
4 *
5 * LTTng syscall probes.
6 *
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/compat.h>
13 #include <linux/err.h>
14 #include <linux/bitmap.h>
15 #include <linux/in.h>
16 #include <linux/in6.h>
17 #include <linux/seq_file.h>
18 #include <linux/stringify.h>
19 #include <linux/file.h>
20 #include <linux/anon_inodes.h>
21 #include <asm/ptrace.h>
22 #include <asm/syscall.h>
23
24 #include <lib/bitfield.h>
25 #include <wrapper/tracepoint.h>
26 #include <wrapper/file.h>
27 #include <wrapper/rcu.h>
28 #include <wrapper/syscall.h>
29 #include <lttng-events.h>
30
31 #ifndef CONFIG_COMPAT
32 # ifndef is_compat_task
33 # define is_compat_task() (0)
34 # endif
35 #endif
36
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
42 enum sc_type {
43 SC_TYPE_ENTRY,
44 SC_TYPE_EXIT,
45 SC_TYPE_COMPAT_ENTRY,
46 SC_TYPE_COMPAT_EXIT,
47 };
48
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)
58
59 static
60 void syscall_entry_probe(void *__data, struct pt_regs *regs, long id);
61 static
62 void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret);
63
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;
73 struct file_handle;
74 struct user_msghdr;
75
76 /*
77 * Forward declaration for kernels >= 5.6
78 */
79 struct timex;
80
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
87 /*
88 * Create LTTng tracepoint probes.
89 */
90 #define LTTNG_PACKAGE_BUILD
91 #define CREATE_TRACE_POINTS
92 #define TP_MODULE_NOINIT
93 #define TRACE_INCLUDE_PATH instrumentation/syscalls/headers
94
95 #define PARAMS(args...) args
96
97 /* Handle unknown syscalls */
98 #undef TRACE_SYSTEM
99 #define TRACE_SYSTEM syscalls_unknown
100 #include <instrumentation/syscalls/headers/syscalls_unknown.h>
101 #undef TRACE_SYSTEM
102
103 #define SC_ENTER
104
105 #undef sc_exit
106 #define sc_exit(...)
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__
113
114 /* Hijack probe callback for system call enter */
115 #undef TP_PROBE_CB
116 #define TP_PROBE_CB(_template) &syscall_entry_probe
117 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
118 LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
119 PARAMS(_fields))
120 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
121 LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
122 PARAMS(_locvar), PARAMS(_code_pre), \
123 PARAMS(_fields), PARAMS(_code_post))
124 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
125 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields))
126 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
127 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name)
128 /* Enumerations only defined at first inclusion. */
129 #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \
130 LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values))
131 #undef TRACE_SYSTEM
132 #define TRACE_SYSTEM syscall_entry_integers
133 #define TRACE_INCLUDE_FILE syscalls_integers
134 #include <instrumentation/syscalls/headers/syscalls_integers.h>
135 #undef TRACE_INCLUDE_FILE
136 #undef TRACE_SYSTEM
137 #define TRACE_SYSTEM syscall_entry_pointers
138 #define TRACE_INCLUDE_FILE syscalls_pointers
139 #include <instrumentation/syscalls/headers/syscalls_pointers.h>
140 #undef TRACE_INCLUDE_FILE
141 #undef TRACE_SYSTEM
142 #undef SC_LTTNG_TRACEPOINT_ENUM
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
147 #undef TP_PROBE_CB
148 #undef _TRACE_SYSCALLS_INTEGERS_H
149 #undef _TRACE_SYSCALLS_POINTERS_H
150
151 /* Hijack probe callback for compat system call enter */
152 #define TP_PROBE_CB(_template) &syscall_entry_probe
153 #define LTTNG_SC_COMPAT
154 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
155 LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
156 PARAMS(_fields))
157 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
158 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
159 PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
160 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
161 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields))
162 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
163 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_entry_##_template, \
164 compat_syscall_entry_##_name)
165 /* Enumerations only defined at inital inclusion (not here). */
166 #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values)
167 #define TRACE_SYSTEM compat_syscall_entry_integers
168 #define TRACE_INCLUDE_FILE compat_syscalls_integers
169 #include <instrumentation/syscalls/headers/compat_syscalls_integers.h>
170 #undef TRACE_INCLUDE_FILE
171 #undef TRACE_SYSTEM
172 #define TRACE_SYSTEM compat_syscall_entry_pointers
173 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
174 #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h>
175 #undef TRACE_INCLUDE_FILE
176 #undef TRACE_SYSTEM
177 #undef SC_LTTNG_TRACEPOINT_ENUM
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
182 #undef TP_PROBE_CB
183 #undef _TRACE_SYSCALLS_INTEGERS_H
184 #undef _TRACE_SYSCALLS_POINTERS_H
185 #undef LTTNG_SC_COMPAT
186
187 #undef SC_ENTER
188
189 #define SC_EXIT
190
191 #undef sc_exit
192 #define sc_exit(...) __VA_ARGS__
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__
199
200 /* Hijack probe callback for system call exit */
201 #define TP_PROBE_CB(_template) &syscall_exit_probe
202 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
203 LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
204 PARAMS(_fields))
205 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
206 LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
207 PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
208 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
209 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields))
210 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
211 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, \
212 syscall_exit_##_name)
213 /* Enumerations only defined at inital inclusion (not here). */
214 #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values)
215 #define TRACE_SYSTEM syscall_exit_integers
216 #define TRACE_INCLUDE_FILE syscalls_integers
217 #include <instrumentation/syscalls/headers/syscalls_integers.h>
218 #undef TRACE_INCLUDE_FILE
219 #undef TRACE_SYSTEM
220 #define TRACE_SYSTEM syscall_exit_pointers
221 #define TRACE_INCLUDE_FILE syscalls_pointers
222 #include <instrumentation/syscalls/headers/syscalls_pointers.h>
223 #undef TRACE_INCLUDE_FILE
224 #undef TRACE_SYSTEM
225 #undef SC_LTTNG_TRACEPOINT_ENUM
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
230 #undef TP_PROBE_CB
231 #undef _TRACE_SYSCALLS_INTEGERS_H
232 #undef _TRACE_SYSCALLS_POINTERS_H
233
234
235 /* Hijack probe callback for compat system call exit */
236 #define TP_PROBE_CB(_template) &syscall_exit_probe
237 #define LTTNG_SC_COMPAT
238 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
239 LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
240 PARAMS(_fields))
241 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
242 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
243 PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
244 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
245 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields))
246 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
247 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, \
248 compat_syscall_exit_##_name)
249 /* Enumerations only defined at inital inclusion (not here). */
250 #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values)
251 #define TRACE_SYSTEM compat_syscall_exit_integers
252 #define TRACE_INCLUDE_FILE compat_syscalls_integers
253 #include <instrumentation/syscalls/headers/compat_syscalls_integers.h>
254 #undef TRACE_INCLUDE_FILE
255 #undef TRACE_SYSTEM
256 #define TRACE_SYSTEM compat_syscall_exit_pointers
257 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
258 #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h>
259 #undef TRACE_INCLUDE_FILE
260 #undef TRACE_SYSTEM
261 #undef SC_LTTNG_TRACEPOINT_ENUM
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
266 #undef TP_PROBE_CB
267 #undef _TRACE_SYSCALLS_INTEGERS_H
268 #undef _TRACE_SYSCALLS_POINTERS_H
269 #undef LTTNG_SC_COMPAT
270
271 #undef SC_EXIT
272
273 #undef TP_MODULE_NOINIT
274 #undef LTTNG_PACKAGE_BUILD
275 #undef CREATE_TRACE_POINTS
276
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
286 #define SC_ENTER
287
288 #undef sc_exit
289 #define sc_exit(...)
290
291 #undef TRACE_SYSCALL_TABLE
292 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
293 [ _nr ] = { \
294 .func = __event_probe__syscall_entry_##_template, \
295 .nrargs = (_nrargs), \
296 .fields = __event_fields___syscall_entry_##_template, \
297 .desc = &__event_desc___syscall_entry_##_name, \
298 },
299
300 /* Syscall enter tracing table */
301 static const struct trace_syscall_entry sc_table[] = {
302 #include <instrumentation/syscalls/headers/syscalls_integers.h>
303 #include <instrumentation/syscalls/headers/syscalls_pointers.h>
304 };
305
306 #undef TRACE_SYSCALL_TABLE
307 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
308 [ _nr ] = { \
309 .func = __event_probe__compat_syscall_entry_##_template, \
310 .nrargs = (_nrargs), \
311 .fields = __event_fields___compat_syscall_entry_##_template, \
312 .desc = &__event_desc___compat_syscall_entry_##_name, \
313 },
314
315 /* Compat syscall enter table */
316 const struct trace_syscall_entry compat_sc_table[] = {
317 #include <instrumentation/syscalls/headers/compat_syscalls_integers.h>
318 #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h>
319 };
320
321 #undef SC_ENTER
322
323 #define SC_EXIT
324
325 #undef sc_exit
326 #define sc_exit(...) __VA_ARGS__
327
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[] = {
339 #include <instrumentation/syscalls/headers/syscalls_integers.h>
340 #include <instrumentation/syscalls/headers/syscalls_pointers.h>
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[] = {
354 #include <instrumentation/syscalls/headers/compat_syscalls_integers.h>
355 #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h>
356 };
357
358 #undef SC_EXIT
359
360 #undef CREATE_SYSCALL_TABLE
361
362 struct lttng_syscall_filter {
363 DECLARE_BITMAP(sc, NR_syscalls);
364 DECLARE_BITMAP(sc_compat, NR_compat_syscalls);
365 };
366
367 static void syscall_entry_unknown(struct lttng_event *event,
368 struct pt_regs *regs, unsigned int id)
369 {
370 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
371
372 lttng_syscall_get_arguments(current, regs, args);
373 if (unlikely(in_compat_syscall()))
374 __event_probe__compat_syscall_entry_unknown(event, id, args);
375 else
376 __event_probe__syscall_entry_unknown(event, id, args);
377 }
378
379 void syscall_entry_probe(void *__data, struct pt_regs *regs, long id)
380 {
381 struct lttng_channel *chan = __data;
382 struct lttng_event *event, *unknown_event;
383 const struct trace_syscall_entry *table, *entry;
384 size_t table_len;
385
386 if (unlikely(in_compat_syscall())) {
387 struct lttng_syscall_filter *filter;
388
389 filter = lttng_rcu_dereference(chan->sc_filter);
390 if (filter) {
391 if (id < 0 || id >= NR_compat_syscalls
392 || !test_bit(id, filter->sc_compat)) {
393 /* System call filtered out. */
394 return;
395 }
396 }
397 table = compat_sc_table;
398 table_len = ARRAY_SIZE(compat_sc_table);
399 unknown_event = chan->sc_compat_unknown;
400 } else {
401 struct lttng_syscall_filter *filter;
402
403 filter = lttng_rcu_dereference(chan->sc_filter);
404 if (filter) {
405 if (id < 0 || id >= NR_syscalls
406 || !test_bit(id, filter->sc)) {
407 /* System call filtered out. */
408 return;
409 }
410 }
411 table = sc_table;
412 table_len = ARRAY_SIZE(sc_table);
413 unknown_event = chan->sc_unknown;
414 }
415 if (unlikely(id < 0 || id >= table_len)) {
416 syscall_entry_unknown(unknown_event, regs, id);
417 return;
418 }
419 if (unlikely(in_compat_syscall()))
420 event = chan->compat_sc_table[id];
421 else
422 event = chan->sc_table[id];
423 if (unlikely(!event)) {
424 syscall_entry_unknown(unknown_event, regs, id);
425 return;
426 }
427 entry = &table[id];
428 WARN_ON_ONCE(!entry);
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;
441 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
442
443 lttng_syscall_get_arguments(current, regs, args);
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;
452 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
453
454 lttng_syscall_get_arguments(current, regs, args);
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;
464 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
465
466 lttng_syscall_get_arguments(current, regs, args);
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;
477 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
478
479 lttng_syscall_get_arguments(current, regs, args);
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;
491 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
492
493 lttng_syscall_get_arguments(current, regs, args);
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;
506 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
507
508 lttng_syscall_get_arguments(current, regs, args);
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
518 static void syscall_exit_unknown(struct lttng_event *event,
519 struct pt_regs *regs, int id, long ret)
520 {
521 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
522
523 lttng_syscall_get_arguments(current, regs, args);
524 if (unlikely(in_compat_syscall()))
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);
540 if (unlikely(in_compat_syscall())) {
541 struct lttng_syscall_filter *filter;
542
543 filter = lttng_rcu_dereference(chan->sc_filter);
544 if (filter) {
545 if (id < 0 || id >= NR_compat_syscalls
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
557 filter = lttng_rcu_dereference(chan->sc_filter);
558 if (filter) {
559 if (id < 0 || id >= NR_syscalls
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 }
569 if (unlikely(id < 0 || id >= table_len)) {
570 syscall_exit_unknown(unknown_event, regs, id, ret);
571 return;
572 }
573 if (unlikely(in_compat_syscall()))
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 {
587 void (*fptr)(void *__data, long ret) = entry->func;
588
589 fptr(event, ret);
590 break;
591 }
592 case 1:
593 {
594 void (*fptr)(void *__data,
595 long ret,
596 unsigned long arg0) = entry->func;
597 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
598
599 lttng_syscall_get_arguments(current, regs, args);
600 fptr(event, ret, args[0]);
601 break;
602 }
603 case 2:
604 {
605 void (*fptr)(void *__data,
606 long ret,
607 unsigned long arg0,
608 unsigned long arg1) = entry->func;
609 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
610
611 lttng_syscall_get_arguments(current, regs, args);
612 fptr(event, ret, args[0], args[1]);
613 break;
614 }
615 case 3:
616 {
617 void (*fptr)(void *__data,
618 long ret,
619 unsigned long arg0,
620 unsigned long arg1,
621 unsigned long arg2) = entry->func;
622 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
623
624 lttng_syscall_get_arguments(current, regs, args);
625 fptr(event, ret, args[0], args[1], args[2]);
626 break;
627 }
628 case 4:
629 {
630 void (*fptr)(void *__data,
631 long ret,
632 unsigned long arg0,
633 unsigned long arg1,
634 unsigned long arg2,
635 unsigned long arg3) = entry->func;
636 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
637
638 lttng_syscall_get_arguments(current, regs, args);
639 fptr(event, ret, args[0], args[1], args[2], args[3]);
640 break;
641 }
642 case 5:
643 {
644 void (*fptr)(void *__data,
645 long ret,
646 unsigned long arg0,
647 unsigned long arg1,
648 unsigned long arg2,
649 unsigned long arg3,
650 unsigned long arg4) = entry->func;
651 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
652
653 lttng_syscall_get_arguments(current, regs, args);
654 fptr(event, ret, args[0], args[1], args[2], args[3], args[4]);
655 break;
656 }
657 case 6:
658 {
659 void (*fptr)(void *__data,
660 long ret,
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;
667 unsigned long args[LTTNG_SYSCALL_NR_ARGS];
668
669 lttng_syscall_get_arguments(current, regs, args);
670 fptr(event, ret, args[0], args[1], args[2],
671 args[3], args[4], args[5]);
672 break;
673 }
674 default:
675 break;
676 }
677 }
678
679 /*
680 * noinline to diminish caller stack size.
681 * Should be called with sessions lock held.
682 */
683 static
684 int fill_table(const struct trace_syscall_entry *table, size_t table_len,
685 struct lttng_event **chan_table, struct lttng_channel *chan,
686 void *filter, enum sc_type type)
687 {
688 const struct lttng_event_desc *desc;
689 unsigned int i;
690
691 /* Allocate events for each syscall, insert into table */
692 for (i = 0; i < table_len; i++) {
693 struct lttng_kernel_event ev;
694 desc = table[i].desc;
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));
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);
730 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
731 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
732 chan_table[i] = _lttng_event_create(chan, &ev, filter,
733 desc, ev.instrumentation);
734 WARN_ON_ONCE(!chan_table[i]);
735 if (IS_ERR(chan_table[i])) {
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 */
742 return PTR_ERR(chan_table[i]);
743 }
744 }
745 return 0;
746 }
747
748 /*
749 * Should be called with sessions lock held.
750 */
751 int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
752 {
753 struct lttng_kernel_event ev;
754 int ret;
755
756 wrapper_vmalloc_sync_all();
757
758 if (!chan->sc_table) {
759 /* create syscall table mapping syscall to events */
760 chan->sc_table = kzalloc(sizeof(struct lttng_event *)
761 * ARRAY_SIZE(sc_table), GFP_KERNEL);
762 if (!chan->sc_table)
763 return -ENOMEM;
764 }
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
773
774 #ifdef CONFIG_COMPAT
775 if (!chan->compat_sc_table) {
776 /* create syscall table mapping compat syscall to events */
777 chan->compat_sc_table = kzalloc(sizeof(struct lttng_event *)
778 * ARRAY_SIZE(compat_sc_table), GFP_KERNEL);
779 if (!chan->compat_sc_table)
780 return -ENOMEM;
781 }
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 }
790 #endif
791 if (!chan->sc_unknown) {
792 const struct lttng_event_desc *desc =
793 &__event_desc___syscall_entry_unknown;
794
795 memset(&ev, 0, sizeof(ev));
796 strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
797 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
798 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
799 chan->sc_unknown = _lttng_event_create(chan, &ev, filter,
800 desc,
801 ev.instrumentation);
802 WARN_ON_ONCE(!chan->sc_unknown);
803 if (IS_ERR(chan->sc_unknown)) {
804 return PTR_ERR(chan->sc_unknown);
805 }
806 }
807
808 if (!chan->sc_compat_unknown) {
809 const struct lttng_event_desc *desc =
810 &__event_desc___compat_syscall_entry_unknown;
811
812 memset(&ev, 0, sizeof(ev));
813 strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
814 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
815 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
816 chan->sc_compat_unknown = _lttng_event_create(chan, &ev, filter,
817 desc,
818 ev.instrumentation);
819 WARN_ON_ONCE(!chan->sc_unknown);
820 if (IS_ERR(chan->sc_compat_unknown)) {
821 return PTR_ERR(chan->sc_compat_unknown);
822 }
823 }
824
825 if (!chan->compat_sc_exit_unknown) {
826 const struct lttng_event_desc *desc =
827 &__event_desc___compat_syscall_exit_unknown;
828
829 memset(&ev, 0, sizeof(ev));
830 strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
831 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
832 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
833 chan->compat_sc_exit_unknown = _lttng_event_create(chan, &ev,
834 filter, desc,
835 ev.instrumentation);
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';
849 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
850 chan->sc_exit_unknown = _lttng_event_create(chan, &ev, filter,
851 desc, ev.instrumentation);
852 WARN_ON_ONCE(!chan->sc_exit_unknown);
853 if (IS_ERR(chan->sc_exit_unknown)) {
854 return PTR_ERR(chan->sc_exit_unknown);
855 }
856 }
857
858 ret = fill_table(sc_table, ARRAY_SIZE(sc_table),
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);
864 if (ret)
865 return ret;
866
867 #ifdef CONFIG_COMPAT
868 ret = fill_table(compat_sc_table, ARRAY_SIZE(compat_sc_table),
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);
876 if (ret)
877 return ret;
878 #endif
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 }
886 /*
887 * We change the name of sys_exit tracepoint due to namespace
888 * conflict with sys_exit syscall entry.
889 */
890 if (!chan->sys_exit_registered) {
891 ret = lttng_wrapper_tracepoint_probe_register("sys_exit",
892 (void *) syscall_exit_probe, chan);
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;
899 }
900 return ret;
901 }
902
903 /*
904 * Only called at session destruction.
905 */
906 int lttng_syscalls_unregister(struct lttng_channel *chan)
907 {
908 int ret;
909
910 if (!chan->sc_table)
911 return 0;
912 if (chan->sys_enter_registered) {
913 ret = lttng_wrapper_tracepoint_probe_unregister("sys_enter",
914 (void *) syscall_entry_probe, chan);
915 if (ret)
916 return ret;
917 chan->sys_enter_registered = 0;
918 }
919 if (chan->sys_exit_registered) {
920 ret = lttng_wrapper_tracepoint_probe_unregister("sys_exit",
921 (void *) syscall_exit_probe, chan);
922 if (ret)
923 return ret;
924 chan->sys_exit_registered = 0;
925 }
926 /* lttng_event destroy will be performed by lttng_session_destroy() */
927 kfree(chan->sc_table);
928 kfree(chan->sc_exit_table);
929 #ifdef CONFIG_COMPAT
930 kfree(chan->compat_sc_table);
931 kfree(chan->compat_sc_exit_table);
932 #endif
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;
945 const char *it_name;
946
947 entry = &sc_table[i];
948 if (!entry->desc)
949 continue;
950 it_name = entry->desc->name;
951 it_name += strlen(SYSCALL_ENTRY_STR);
952 if (!strcmp(syscall_name, it_name)) {
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;
968 const char *it_name;
969
970 entry = &compat_sc_table[i];
971 if (!entry->desc)
972 continue;
973 it_name = entry->desc->name;
974 it_name += strlen(COMPAT_SYSCALL_ENTRY_STR);
975 if (!strcmp(syscall_name, it_name)) {
976 syscall_nr = i;
977 break;
978 }
979 }
980 return syscall_nr;
981 }
982
983 static
984 uint32_t get_sc_tables_len(void)
985 {
986 return ARRAY_SIZE(sc_table) + ARRAY_SIZE(compat_sc_table);
987 }
988
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) {
1062 if (!chan->syscall_all)
1063 return -EEXIST;
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
1075 if (!name) {
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
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 }
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) {
1096 if (!test_bit(syscall_nr, filter->sc)) {
1097 ret = -EEXIST;
1098 goto error;
1099 }
1100 bitmap_clear(filter->sc, syscall_nr, 1);
1101 }
1102 if (compat_syscall_nr >= 0) {
1103 if (!test_bit(compat_syscall_nr, filter->sc_compat)) {
1104 ret = -EEXIST;
1105 goto error;
1106 }
1107 bitmap_clear(filter->sc_compat, compat_syscall_nr, 1);
1108 }
1109 apply_filter:
1110 if (!chan->sc_filter)
1111 rcu_assign_pointer(chan->sc_filter, filter);
1112 chan->syscall_all = 0;
1113 return 0;
1114
1115 error:
1116 if (!chan->sc_filter)
1117 kfree(filter);
1118 return ret;
1119 }
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
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
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;
1189 unsigned long index;
1190 int ret;
1191 const char *name;
1192
1193 ret = get_sc_table(entry, &table, &bitness);
1194 if (ret)
1195 return ret;
1196 if (!entry->desc)
1197 return 0;
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 }
1205 seq_printf(m, "syscall { index = %lu; name = %s; bitness = %u; };\n",
1206 index, name, bitness);
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, &lttng_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 };
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++) {
1255 char state;
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);
1266 }
1267 for (; bit < sc_tables_len; bit++) {
1268 char state;
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);
1280 }
1281 if (copy_to_user(usyscall_mask->mask, tmp_mask, bitmask_len))
1282 ret = -EFAULT;
1283 kfree(tmp_mask);
1284 return ret;
1285 }
1286
1287 int lttng_abi_syscall_list(void)
1288 {
1289 struct file *syscall_list_file;
1290 int file_fd, ret;
1291
1292 file_fd = lttng_get_unused_fd();
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 &lttng_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);
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 }
This page took 0.060352 seconds and 5 git commands to generate.