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