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