4 * LTTng syscall probes.
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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
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>
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>
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>
44 # ifndef is_compat_task
45 # define is_compat_task() (0)
56 #define SYSCALL_ENTRY_TOK syscall_entry_
57 #define COMPAT_SYSCALL_ENTRY_TOK compat_syscall_entry_
58 #define SYSCALL_EXIT_TOK syscall_exit_
59 #define COMPAT_SYSCALL_EXIT_TOK compat_syscall_exit_
61 #define SYSCALL_ENTRY_STR __stringify(SYSCALL_ENTRY_TOK)
62 #define COMPAT_SYSCALL_ENTRY_STR __stringify(COMPAT_SYSCALL_ENTRY_TOK)
63 #define SYSCALL_EXIT_STR __stringify(SYSCALL_EXIT_TOK)
64 #define COMPAT_SYSCALL_EXIT_STR __stringify(COMPAT_SYSCALL_EXIT_TOK)
67 void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
);
69 void syscall_exit_probe(void *__data
, struct pt_regs
*regs
, long ret
);
72 * Forward declarations for old kernels.
76 struct oldold_utsname
;
78 struct sel_arg_struct
;
79 struct mmap_arg_struct
;
83 #ifdef IA32_NR_syscalls
84 #define NR_compat_syscalls IA32_NR_syscalls
86 #define NR_compat_syscalls NR_syscalls
90 * Create LTTng tracepoint probes.
92 #define LTTNG_PACKAGE_BUILD
93 #define CREATE_TRACE_POINTS
94 #define TP_MODULE_NOINIT
95 #define TRACE_INCLUDE_PATH instrumentation/syscalls/headers
97 #define PARAMS(args...) args
99 /* Handle unknown syscalls */
101 #define TRACE_SYSTEM syscalls_unknown
102 #include <instrumentation/syscalls/headers/syscalls_unknown.h>
110 #define sc_in(...) __VA_ARGS__
114 #define sc_inout(...) __VA_ARGS__
116 /* Hijack probe callback for system call enter */
118 #define TP_PROBE_CB(_template) &syscall_entry_probe
119 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
120 LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
122 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
123 LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
124 PARAMS(_locvar), PARAMS(_code_pre), \
125 PARAMS(_fields), PARAMS(_code_post))
126 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
127 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields))
128 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
129 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name)
131 #define TRACE_SYSTEM syscall_entry_integers
132 #define TRACE_INCLUDE_FILE syscalls_integers
133 #include <instrumentation/syscalls/headers/syscalls_integers.h>
134 #undef TRACE_INCLUDE_FILE
136 #define TRACE_SYSTEM syscall_entry_pointers
137 #define TRACE_INCLUDE_FILE syscalls_pointers
138 #include <instrumentation/syscalls/headers/syscalls_pointers.h>
139 #undef TRACE_INCLUDE_FILE
141 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
142 #undef SC_LTTNG_TRACEPOINT_EVENT
143 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
144 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
146 #undef _TRACE_SYSCALLS_INTEGERS_H
147 #undef _TRACE_SYSCALLS_POINTERS_H
149 /* Hijack probe callback for compat system call enter */
150 #define TP_PROBE_CB(_template) &syscall_entry_probe
151 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
152 LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
154 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
155 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
156 PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
157 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
158 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields))
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
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
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
177 #undef _TRACE_SYSCALLS_INTEGERS_H
178 #undef _TRACE_SYSCALLS_POINTERS_H
185 #define sc_exit(...) __VA_ARGS__
189 #define sc_out(...) __VA_ARGS__
191 #define sc_inout(...) __VA_ARGS__
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, _fields) \
196 LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
198 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
199 LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
200 PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
201 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
202 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields))
203 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
204 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, \
205 syscall_exit_##_name)
206 #define TRACE_SYSTEM syscall_exit_integers
207 #define TRACE_INCLUDE_FILE syscalls_integers
208 #include <instrumentation/syscalls/headers/syscalls_integers.h>
209 #undef TRACE_INCLUDE_FILE
211 #define TRACE_SYSTEM syscall_exit_pointers
212 #define TRACE_INCLUDE_FILE syscalls_pointers
213 #include <instrumentation/syscalls/headers/syscalls_pointers.h>
214 #undef TRACE_INCLUDE_FILE
216 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
217 #undef SC_LTTNG_TRACEPOINT_EVENT
218 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
219 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
221 #undef _TRACE_SYSCALLS_INTEGERS_H
222 #undef _TRACE_SYSCALLS_POINTERS_H
225 /* Hijack probe callback for compat system call exit */
226 #define TP_PROBE_CB(_template) &syscall_exit_probe
227 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
228 LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
230 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
231 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
232 PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
233 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
234 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields))
235 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
236 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, \
237 compat_syscall_exit_##_name)
238 #define TRACE_SYSTEM compat_syscall_exit_integers
239 #define TRACE_INCLUDE_FILE compat_syscalls_integers
240 #include <instrumentation/syscalls/headers/compat_syscalls_integers.h>
241 #undef TRACE_INCLUDE_FILE
243 #define TRACE_SYSTEM compat_syscall_exit_pointers
244 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
245 #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h>
246 #undef TRACE_INCLUDE_FILE
248 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
249 #undef SC_LTTNG_TRACEPOINT_EVENT
250 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
251 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
253 #undef _TRACE_SYSCALLS_INTEGERS_H
254 #undef _TRACE_SYSCALLS_POINTERS_H
258 #undef TP_MODULE_NOINIT
259 #undef LTTNG_PACKAGE_BUILD
260 #undef CREATE_TRACE_POINTS
262 struct trace_syscall_entry
{
264 const struct lttng_event_desc
*desc
;
265 const struct lttng_event_field
*fields
;
269 #define CREATE_SYSCALL_TABLE
276 #undef TRACE_SYSCALL_TABLE
277 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
279 .func = __event_probe__syscall_entry_##_template, \
280 .nrargs = (_nrargs), \
281 .fields = __event_fields___syscall_entry_##_template, \
282 .desc = &__event_desc___syscall_entry_##_name, \
285 /* Syscall enter tracing table */
286 static const struct trace_syscall_entry sc_table
[] = {
287 #include <instrumentation/syscalls/headers/syscalls_integers.h>
288 #include <instrumentation/syscalls/headers/syscalls_pointers.h>
291 #undef TRACE_SYSCALL_TABLE
292 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
294 .func = __event_probe__compat_syscall_entry_##_template, \
295 .nrargs = (_nrargs), \
296 .fields = __event_fields___compat_syscall_entry_##_template, \
297 .desc = &__event_desc___compat_syscall_entry_##_name, \
300 /* Compat syscall enter table */
301 const struct trace_syscall_entry compat_sc_table
[] = {
302 #include <instrumentation/syscalls/headers/compat_syscalls_integers.h>
303 #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h>
311 #define sc_exit(...) __VA_ARGS__
313 #undef TRACE_SYSCALL_TABLE
314 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
316 .func = __event_probe__syscall_exit_##_template, \
317 .nrargs = (_nrargs), \
318 .fields = __event_fields___syscall_exit_##_template, \
319 .desc = &__event_desc___syscall_exit_##_name, \
322 /* Syscall exit table */
323 static const struct trace_syscall_entry sc_exit_table
[] = {
324 #include <instrumentation/syscalls/headers/syscalls_integers.h>
325 #include <instrumentation/syscalls/headers/syscalls_pointers.h>
328 #undef TRACE_SYSCALL_TABLE
329 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
331 .func = __event_probe__compat_syscall_exit_##_template, \
332 .nrargs = (_nrargs), \
333 .fields = __event_fields___compat_syscall_exit_##_template, \
334 .desc = &__event_desc___compat_syscall_exit_##_name, \
337 /* Compat syscall exit table */
338 const struct trace_syscall_entry compat_sc_exit_table
[] = {
339 #include <instrumentation/syscalls/headers/compat_syscalls_integers.h>
340 #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h>
345 #undef CREATE_SYSCALL_TABLE
347 struct lttng_syscall_filter
{
348 DECLARE_BITMAP(sc
, NR_syscalls
);
349 DECLARE_BITMAP(sc_compat
, NR_compat_syscalls
);
352 static void syscall_entry_unknown(struct lttng_event
*event
,
353 struct pt_regs
*regs
, unsigned int id
)
355 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
357 syscall_get_arguments(current
, regs
, 0, UNKNOWN_SYSCALL_NRARGS
, args
);
358 if (unlikely(is_compat_task()))
359 __event_probe__compat_syscall_entry_unknown(event
, id
, args
);
361 __event_probe__syscall_entry_unknown(event
, id
, args
);
364 void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
)
366 struct lttng_channel
*chan
= __data
;
367 struct lttng_event
*event
, *unknown_event
;
368 const struct trace_syscall_entry
*table
, *entry
;
371 if (unlikely(is_compat_task())) {
372 struct lttng_syscall_filter
*filter
;
374 filter
= lttng_rcu_dereference(chan
->sc_filter
);
376 if (id
< 0 || id
>= NR_compat_syscalls
377 || !test_bit(id
, filter
->sc_compat
)) {
378 /* System call filtered out. */
382 table
= compat_sc_table
;
383 table_len
= ARRAY_SIZE(compat_sc_table
);
384 unknown_event
= chan
->sc_compat_unknown
;
386 struct lttng_syscall_filter
*filter
;
388 filter
= lttng_rcu_dereference(chan
->sc_filter
);
390 if (id
< 0 || id
>= NR_syscalls
391 || !test_bit(id
, filter
->sc
)) {
392 /* System call filtered out. */
397 table_len
= ARRAY_SIZE(sc_table
);
398 unknown_event
= chan
->sc_unknown
;
400 if (unlikely(id
< 0 || id
>= table_len
)) {
401 syscall_entry_unknown(unknown_event
, regs
, id
);
404 if (unlikely(is_compat_task()))
405 event
= chan
->compat_sc_table
[id
];
407 event
= chan
->sc_table
[id
];
408 if (unlikely(!event
)) {
409 syscall_entry_unknown(unknown_event
, regs
, id
);
413 WARN_ON_ONCE(!entry
);
415 switch (entry
->nrargs
) {
418 void (*fptr
)(void *__data
) = entry
->func
;
425 void (*fptr
)(void *__data
, unsigned long arg0
) = entry
->func
;
426 unsigned long args
[1];
428 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
429 fptr(event
, args
[0]);
434 void (*fptr
)(void *__data
,
436 unsigned long arg1
) = entry
->func
;
437 unsigned long args
[2];
439 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
440 fptr(event
, args
[0], args
[1]);
445 void (*fptr
)(void *__data
,
448 unsigned long arg2
) = entry
->func
;
449 unsigned long args
[3];
451 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
452 fptr(event
, args
[0], args
[1], args
[2]);
457 void (*fptr
)(void *__data
,
461 unsigned long arg3
) = entry
->func
;
462 unsigned long args
[4];
464 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
465 fptr(event
, args
[0], args
[1], args
[2], args
[3]);
470 void (*fptr
)(void *__data
,
475 unsigned long arg4
) = entry
->func
;
476 unsigned long args
[5];
478 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
479 fptr(event
, args
[0], args
[1], args
[2], args
[3], args
[4]);
484 void (*fptr
)(void *__data
,
490 unsigned long arg5
) = entry
->func
;
491 unsigned long args
[6];
493 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
494 fptr(event
, args
[0], args
[1], args
[2],
495 args
[3], args
[4], args
[5]);
503 static void syscall_exit_unknown(struct lttng_event
*event
,
504 struct pt_regs
*regs
, int id
, long ret
)
506 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
508 syscall_get_arguments(current
, regs
, 0, UNKNOWN_SYSCALL_NRARGS
, args
);
509 if (unlikely(is_compat_task()))
510 __event_probe__compat_syscall_exit_unknown(event
, id
, ret
,
513 __event_probe__syscall_exit_unknown(event
, id
, ret
, args
);
516 void syscall_exit_probe(void *__data
, struct pt_regs
*regs
, long ret
)
518 struct lttng_channel
*chan
= __data
;
519 struct lttng_event
*event
, *unknown_event
;
520 const struct trace_syscall_entry
*table
, *entry
;
524 id
= syscall_get_nr(current
, regs
);
525 if (unlikely(is_compat_task())) {
526 struct lttng_syscall_filter
*filter
;
528 filter
= lttng_rcu_dereference(chan
->sc_filter
);
530 if (id
< 0 || id
>= NR_compat_syscalls
531 || !test_bit(id
, filter
->sc_compat
)) {
532 /* System call filtered out. */
536 table
= compat_sc_exit_table
;
537 table_len
= ARRAY_SIZE(compat_sc_exit_table
);
538 unknown_event
= chan
->compat_sc_exit_unknown
;
540 struct lttng_syscall_filter
*filter
;
542 filter
= lttng_rcu_dereference(chan
->sc_filter
);
544 if (id
< 0 || id
>= NR_syscalls
545 || !test_bit(id
, filter
->sc
)) {
546 /* System call filtered out. */
550 table
= sc_exit_table
;
551 table_len
= ARRAY_SIZE(sc_exit_table
);
552 unknown_event
= chan
->sc_exit_unknown
;
554 if (unlikely(id
< 0 || id
>= table_len
)) {
555 syscall_exit_unknown(unknown_event
, regs
, id
, ret
);
558 if (unlikely(is_compat_task()))
559 event
= chan
->compat_sc_exit_table
[id
];
561 event
= chan
->sc_exit_table
[id
];
562 if (unlikely(!event
)) {
563 syscall_exit_unknown(unknown_event
, regs
, id
, ret
);
567 WARN_ON_ONCE(!entry
);
569 switch (entry
->nrargs
) {
572 void (*fptr
)(void *__data
, long ret
) = entry
->func
;
579 void (*fptr
)(void *__data
,
581 unsigned long arg0
) = entry
->func
;
582 unsigned long args
[1];
584 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
585 fptr(event
, ret
, args
[0]);
590 void (*fptr
)(void *__data
,
593 unsigned long arg1
) = entry
->func
;
594 unsigned long args
[2];
596 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
597 fptr(event
, ret
, args
[0], args
[1]);
602 void (*fptr
)(void *__data
,
606 unsigned long arg2
) = entry
->func
;
607 unsigned long args
[3];
609 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
610 fptr(event
, ret
, args
[0], args
[1], args
[2]);
615 void (*fptr
)(void *__data
,
620 unsigned long arg3
) = entry
->func
;
621 unsigned long args
[4];
623 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
624 fptr(event
, ret
, args
[0], args
[1], args
[2], args
[3]);
629 void (*fptr
)(void *__data
,
635 unsigned long arg4
) = entry
->func
;
636 unsigned long args
[5];
638 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
639 fptr(event
, ret
, args
[0], args
[1], args
[2], args
[3], args
[4]);
644 void (*fptr
)(void *__data
,
651 unsigned long arg5
) = entry
->func
;
652 unsigned long args
[6];
654 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
655 fptr(event
, ret
, args
[0], args
[1], args
[2],
656 args
[3], args
[4], args
[5]);
665 * noinline to diminish caller stack size.
666 * Should be called with sessions lock held.
669 int fill_table(const struct trace_syscall_entry
*table
, size_t table_len
,
670 struct lttng_event
**chan_table
, struct lttng_channel
*chan
,
671 void *filter
, enum sc_type type
)
673 const struct lttng_event_desc
*desc
;
676 /* Allocate events for each syscall, insert into table */
677 for (i
= 0; i
< table_len
; i
++) {
678 struct lttng_kernel_event ev
;
679 desc
= table
[i
].desc
;
682 /* Unknown syscall */
686 * Skip those already populated by previous failed
687 * register for this channel.
691 memset(&ev
, 0, sizeof(ev
));
694 strncpy(ev
.name
, SYSCALL_ENTRY_STR
,
695 LTTNG_KERNEL_SYM_NAME_LEN
);
698 strncpy(ev
.name
, SYSCALL_EXIT_STR
,
699 LTTNG_KERNEL_SYM_NAME_LEN
);
701 case SC_TYPE_COMPAT_ENTRY
:
702 strncpy(ev
.name
, COMPAT_SYSCALL_ENTRY_STR
,
703 LTTNG_KERNEL_SYM_NAME_LEN
);
705 case SC_TYPE_COMPAT_EXIT
:
706 strncpy(ev
.name
, COMPAT_SYSCALL_EXIT_STR
,
707 LTTNG_KERNEL_SYM_NAME_LEN
);
713 strncat(ev
.name
, desc
->name
,
714 LTTNG_KERNEL_SYM_NAME_LEN
- strlen(ev
.name
) - 1);
715 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
716 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
717 chan_table
[i
] = _lttng_event_create(chan
, &ev
, filter
,
718 desc
, ev
.instrumentation
);
719 WARN_ON_ONCE(!chan_table
[i
]);
720 if (IS_ERR(chan_table
[i
])) {
722 * If something goes wrong in event registration
723 * after the first one, we have no choice but to
724 * leave the previous events in there, until
725 * deleted by session teardown.
727 return PTR_ERR(chan_table
[i
]);
734 * Should be called with sessions lock held.
736 int lttng_syscalls_register(struct lttng_channel
*chan
, void *filter
)
738 struct lttng_kernel_event ev
;
741 wrapper_vmalloc_sync_all();
743 if (!chan
->sc_table
) {
744 /* create syscall table mapping syscall to events */
745 chan
->sc_table
= kzalloc(sizeof(struct lttng_event
*)
746 * ARRAY_SIZE(sc_table
), GFP_KERNEL
);
750 if (!chan
->sc_exit_table
) {
751 /* create syscall table mapping syscall to events */
752 chan
->sc_exit_table
= kzalloc(sizeof(struct lttng_event
*)
753 * ARRAY_SIZE(sc_exit_table
), GFP_KERNEL
);
754 if (!chan
->sc_exit_table
)
760 if (!chan
->compat_sc_table
) {
761 /* create syscall table mapping compat syscall to events */
762 chan
->compat_sc_table
= kzalloc(sizeof(struct lttng_event
*)
763 * ARRAY_SIZE(compat_sc_table
), GFP_KERNEL
);
764 if (!chan
->compat_sc_table
)
768 if (!chan
->compat_sc_exit_table
) {
769 /* create syscall table mapping compat syscall to events */
770 chan
->compat_sc_exit_table
= kzalloc(sizeof(struct lttng_event
*)
771 * ARRAY_SIZE(compat_sc_exit_table
), GFP_KERNEL
);
772 if (!chan
->compat_sc_exit_table
)
776 if (!chan
->sc_unknown
) {
777 const struct lttng_event_desc
*desc
=
778 &__event_desc___syscall_entry_unknown
;
780 memset(&ev
, 0, sizeof(ev
));
781 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
782 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
783 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
784 chan
->sc_unknown
= _lttng_event_create(chan
, &ev
, filter
,
787 WARN_ON_ONCE(!chan
->sc_unknown
);
788 if (IS_ERR(chan
->sc_unknown
)) {
789 return PTR_ERR(chan
->sc_unknown
);
793 if (!chan
->sc_compat_unknown
) {
794 const struct lttng_event_desc
*desc
=
795 &__event_desc___compat_syscall_entry_unknown
;
797 memset(&ev
, 0, sizeof(ev
));
798 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
799 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
800 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
801 chan
->sc_compat_unknown
= _lttng_event_create(chan
, &ev
, filter
,
804 WARN_ON_ONCE(!chan
->sc_unknown
);
805 if (IS_ERR(chan
->sc_compat_unknown
)) {
806 return PTR_ERR(chan
->sc_compat_unknown
);
810 if (!chan
->compat_sc_exit_unknown
) {
811 const struct lttng_event_desc
*desc
=
812 &__event_desc___compat_syscall_exit_unknown
;
814 memset(&ev
, 0, sizeof(ev
));
815 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
816 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
817 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
818 chan
->compat_sc_exit_unknown
= _lttng_event_create(chan
, &ev
,
821 WARN_ON_ONCE(!chan
->compat_sc_exit_unknown
);
822 if (IS_ERR(chan
->compat_sc_exit_unknown
)) {
823 return PTR_ERR(chan
->compat_sc_exit_unknown
);
827 if (!chan
->sc_exit_unknown
) {
828 const struct lttng_event_desc
*desc
=
829 &__event_desc___syscall_exit_unknown
;
831 memset(&ev
, 0, sizeof(ev
));
832 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
833 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
834 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
835 chan
->sc_exit_unknown
= _lttng_event_create(chan
, &ev
, filter
,
836 desc
, ev
.instrumentation
);
837 WARN_ON_ONCE(!chan
->sc_exit_unknown
);
838 if (IS_ERR(chan
->sc_exit_unknown
)) {
839 return PTR_ERR(chan
->sc_exit_unknown
);
843 ret
= fill_table(sc_table
, ARRAY_SIZE(sc_table
),
844 chan
->sc_table
, chan
, filter
, SC_TYPE_ENTRY
);
847 ret
= fill_table(sc_exit_table
, ARRAY_SIZE(sc_exit_table
),
848 chan
->sc_exit_table
, chan
, filter
, SC_TYPE_EXIT
);
853 ret
= fill_table(compat_sc_table
, ARRAY_SIZE(compat_sc_table
),
854 chan
->compat_sc_table
, chan
, filter
,
855 SC_TYPE_COMPAT_ENTRY
);
858 ret
= fill_table(compat_sc_exit_table
, ARRAY_SIZE(compat_sc_exit_table
),
859 chan
->compat_sc_exit_table
, chan
, filter
,
860 SC_TYPE_COMPAT_EXIT
);
864 if (!chan
->sys_enter_registered
) {
865 ret
= lttng_wrapper_tracepoint_probe_register("sys_enter",
866 (void *) syscall_entry_probe
, chan
);
869 chan
->sys_enter_registered
= 1;
872 * We change the name of sys_exit tracepoint due to namespace
873 * conflict with sys_exit syscall entry.
875 if (!chan
->sys_exit_registered
) {
876 ret
= lttng_wrapper_tracepoint_probe_register("sys_exit",
877 (void *) syscall_exit_probe
, chan
);
879 WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter",
880 (void *) syscall_entry_probe
, chan
));
883 chan
->sys_exit_registered
= 1;
889 * Only called at session destruction.
891 int lttng_syscalls_unregister(struct lttng_channel
*chan
)
897 if (chan
->sys_enter_registered
) {
898 ret
= lttng_wrapper_tracepoint_probe_unregister("sys_exit",
899 (void *) syscall_exit_probe
, chan
);
902 chan
->sys_enter_registered
= 0;
904 if (chan
->sys_exit_registered
) {
905 ret
= lttng_wrapper_tracepoint_probe_unregister("sys_enter",
906 (void *) syscall_entry_probe
, chan
);
909 chan
->sys_exit_registered
= 0;
911 /* lttng_event destroy will be performed by lttng_session_destroy() */
912 kfree(chan
->sc_table
);
913 kfree(chan
->sc_exit_table
);
915 kfree(chan
->compat_sc_table
);
916 kfree(chan
->compat_sc_exit_table
);
918 kfree(chan
->sc_filter
);
923 int get_syscall_nr(const char *syscall_name
)
928 for (i
= 0; i
< ARRAY_SIZE(sc_table
); i
++) {
929 const struct trace_syscall_entry
*entry
;
932 entry
= &sc_table
[i
];
935 it_name
= entry
->desc
->name
;
936 it_name
+= strlen(SYSCALL_ENTRY_STR
);
937 if (!strcmp(syscall_name
, it_name
)) {
946 int get_compat_syscall_nr(const char *syscall_name
)
951 for (i
= 0; i
< ARRAY_SIZE(compat_sc_table
); i
++) {
952 const struct trace_syscall_entry
*entry
;
955 entry
= &compat_sc_table
[i
];
958 it_name
= entry
->desc
->name
;
959 it_name
+= strlen(COMPAT_SYSCALL_ENTRY_STR
);
960 if (!strcmp(syscall_name
, it_name
)) {
969 uint32_t get_sc_tables_len(void)
971 return ARRAY_SIZE(sc_table
) + ARRAY_SIZE(compat_sc_table
);
974 int lttng_syscall_filter_enable(struct lttng_channel
*chan
,
977 int syscall_nr
, compat_syscall_nr
, ret
;
978 struct lttng_syscall_filter
*filter
;
980 WARN_ON_ONCE(!chan
->sc_table
);
983 /* Enable all system calls by removing filter */
984 if (chan
->sc_filter
) {
985 filter
= chan
->sc_filter
;
986 rcu_assign_pointer(chan
->sc_filter
, NULL
);
990 chan
->syscall_all
= 1;
994 if (!chan
->sc_filter
) {
995 if (chan
->syscall_all
) {
997 * All syscalls are already enabled.
1001 filter
= kzalloc(sizeof(struct lttng_syscall_filter
),
1006 filter
= chan
->sc_filter
;
1008 syscall_nr
= get_syscall_nr(name
);
1009 compat_syscall_nr
= get_compat_syscall_nr(name
);
1010 if (syscall_nr
< 0 && compat_syscall_nr
< 0) {
1014 if (syscall_nr
>= 0) {
1015 if (test_bit(syscall_nr
, filter
->sc
)) {
1019 bitmap_set(filter
->sc
, syscall_nr
, 1);
1021 if (compat_syscall_nr
>= 0) {
1022 if (test_bit(compat_syscall_nr
, filter
->sc_compat
)) {
1026 bitmap_set(filter
->sc_compat
, compat_syscall_nr
, 1);
1028 if (!chan
->sc_filter
)
1029 rcu_assign_pointer(chan
->sc_filter
, filter
);
1033 if (!chan
->sc_filter
)
1038 int lttng_syscall_filter_disable(struct lttng_channel
*chan
,
1041 int syscall_nr
, compat_syscall_nr
, ret
;
1042 struct lttng_syscall_filter
*filter
;
1044 WARN_ON_ONCE(!chan
->sc_table
);
1046 if (!chan
->sc_filter
) {
1047 if (!chan
->syscall_all
)
1049 filter
= kzalloc(sizeof(struct lttng_syscall_filter
),
1053 /* Trace all system calls, then apply disable. */
1054 bitmap_set(filter
->sc
, 0, NR_syscalls
);
1055 bitmap_set(filter
->sc_compat
, 0, NR_compat_syscalls
);
1057 filter
= chan
->sc_filter
;
1061 /* Fail if all syscalls are already disabled. */
1062 if (bitmap_empty(filter
->sc
, NR_syscalls
)
1063 && bitmap_empty(filter
->sc_compat
,
1064 NR_compat_syscalls
)) {
1069 /* Disable all system calls */
1070 bitmap_clear(filter
->sc
, 0, NR_syscalls
);
1071 bitmap_clear(filter
->sc_compat
, 0, NR_compat_syscalls
);
1074 syscall_nr
= get_syscall_nr(name
);
1075 compat_syscall_nr
= get_compat_syscall_nr(name
);
1076 if (syscall_nr
< 0 && compat_syscall_nr
< 0) {
1080 if (syscall_nr
>= 0) {
1081 if (!test_bit(syscall_nr
, filter
->sc
)) {
1085 bitmap_clear(filter
->sc
, syscall_nr
, 1);
1087 if (compat_syscall_nr
>= 0) {
1088 if (!test_bit(compat_syscall_nr
, filter
->sc_compat
)) {
1092 bitmap_clear(filter
->sc_compat
, compat_syscall_nr
, 1);
1095 if (!chan
->sc_filter
)
1096 rcu_assign_pointer(chan
->sc_filter
, filter
);
1097 chan
->syscall_all
= 0;
1101 if (!chan
->sc_filter
)
1107 const struct trace_syscall_entry
*syscall_list_get_entry(loff_t
*pos
)
1109 const struct trace_syscall_entry
*entry
;
1112 for (entry
= sc_table
;
1113 entry
< sc_table
+ ARRAY_SIZE(sc_table
);
1118 for (entry
= compat_sc_table
;
1119 entry
< compat_sc_table
+ ARRAY_SIZE(compat_sc_table
);
1129 void *syscall_list_start(struct seq_file
*m
, loff_t
*pos
)
1131 return (void *) syscall_list_get_entry(pos
);
1135 void *syscall_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
1138 return (void *) syscall_list_get_entry(ppos
);
1142 void syscall_list_stop(struct seq_file
*m
, void *p
)
1147 int get_sc_table(const struct trace_syscall_entry
*entry
,
1148 const struct trace_syscall_entry
**table
,
1149 unsigned int *bitness
)
1151 if (entry
>= sc_table
&& entry
< sc_table
+ ARRAY_SIZE(sc_table
)) {
1153 *bitness
= BITS_PER_LONG
;
1158 if (!(entry
>= compat_sc_table
1159 && entry
< compat_sc_table
+ ARRAY_SIZE(compat_sc_table
))) {
1165 *table
= compat_sc_table
;
1170 int syscall_list_show(struct seq_file
*m
, void *p
)
1172 const struct trace_syscall_entry
*table
, *entry
= p
;
1173 unsigned int bitness
;
1174 unsigned long index
;
1178 ret
= get_sc_table(entry
, &table
, &bitness
);
1183 if (table
== sc_table
) {
1184 index
= entry
- table
;
1185 name
= &entry
->desc
->name
[strlen(SYSCALL_ENTRY_STR
)];
1187 index
= (entry
- table
) + ARRAY_SIZE(sc_table
);
1188 name
= &entry
->desc
->name
[strlen(COMPAT_SYSCALL_ENTRY_STR
)];
1190 seq_printf(m
, "syscall { index = %lu; name = %s; bitness = %u; };\n",
1191 index
, name
, bitness
);
1196 const struct seq_operations lttng_syscall_list_seq_ops
= {
1197 .start
= syscall_list_start
,
1198 .next
= syscall_list_next
,
1199 .stop
= syscall_list_stop
,
1200 .show
= syscall_list_show
,
1204 int lttng_syscall_list_open(struct inode
*inode
, struct file
*file
)
1206 return seq_open(file
, <tng_syscall_list_seq_ops
);
1209 const struct file_operations lttng_syscall_list_fops
= {
1210 .owner
= THIS_MODULE
,
1211 .open
= lttng_syscall_list_open
,
1213 .llseek
= seq_lseek
,
1214 .release
= seq_release
,
1217 long lttng_channel_syscall_mask(struct lttng_channel
*channel
,
1218 struct lttng_kernel_syscall_mask __user
*usyscall_mask
)
1220 uint32_t len
, sc_tables_len
, bitmask_len
;
1223 struct lttng_syscall_filter
*filter
;
1225 ret
= get_user(len
, &usyscall_mask
->len
);
1228 sc_tables_len
= get_sc_tables_len();
1229 bitmask_len
= ALIGN(sc_tables_len
, 8) >> 3;
1230 if (len
< sc_tables_len
) {
1231 return put_user(sc_tables_len
, &usyscall_mask
->len
);
1233 /* Array is large enough, we can copy array to user-space. */
1234 tmp_mask
= kzalloc(bitmask_len
, GFP_KERNEL
);
1237 filter
= channel
->sc_filter
;
1239 for (bit
= 0; bit
< ARRAY_SIZE(sc_table
); bit
++) {
1242 if (channel
->sc_table
) {
1244 state
= test_bit(bit
, filter
->sc
);
1250 bt_bitfield_write_be(tmp_mask
, char, bit
, 1, state
);
1252 for (; bit
< sc_tables_len
; bit
++) {
1255 if (channel
->compat_sc_table
) {
1257 state
= test_bit(bit
- ARRAY_SIZE(sc_table
),
1264 bt_bitfield_write_be(tmp_mask
, char, bit
, 1, state
);
1266 if (copy_to_user(usyscall_mask
->mask
, tmp_mask
, bitmask_len
))
1272 int lttng_abi_syscall_list(void)
1274 struct file
*syscall_list_file
;
1277 file_fd
= lttng_get_unused_fd();
1283 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
1284 <tng_syscall_list_fops
,
1286 if (IS_ERR(syscall_list_file
)) {
1287 ret
= PTR_ERR(syscall_list_file
);
1290 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
1293 fd_install(file_fd
, syscall_list_file
);
1297 fput(syscall_list_file
);
1299 put_unused_fd(file_fd
);