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)
49 /* in_compat_syscall appears in kernel 4.6. */
50 #ifndef in_compat_syscall
51 #define in_compat_syscall() is_compat_task()
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_
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)
72 void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
);
74 void syscall_exit_probe(void *__data
, struct pt_regs
*regs
, long ret
);
77 * Forward declarations for old kernels.
81 struct oldold_utsname
;
83 struct sel_arg_struct
;
84 struct mmap_arg_struct
;
88 #ifdef IA32_NR_syscalls
89 #define NR_compat_syscalls IA32_NR_syscalls
91 #define NR_compat_syscalls NR_syscalls
95 * Create LTTng tracepoint probes.
97 #define LTTNG_PACKAGE_BUILD
98 #define CREATE_TRACE_POINTS
99 #define TP_MODULE_NOINIT
100 #define TRACE_INCLUDE_PATH instrumentation/syscalls/headers
102 #define PARAMS(args...) args
104 /* Handle unknown syscalls */
106 #define TRACE_SYSTEM syscalls_unknown
107 #include <instrumentation/syscalls/headers/syscalls_unknown.h>
115 #define sc_in(...) __VA_ARGS__
119 #define sc_inout(...) __VA_ARGS__
121 /* Hijack probe callback for system call enter */
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), \
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))
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
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
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
155 #undef _TRACE_SYSCALLS_INTEGERS_H
156 #undef _TRACE_SYSCALLS_POINTERS_H
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), \
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
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
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
189 #undef _TRACE_SYSCALLS_INTEGERS_H
190 #undef _TRACE_SYSCALLS_POINTERS_H
197 #define sc_exit(...) __VA_ARGS__
201 #define sc_out(...) __VA_ARGS__
203 #define sc_inout(...) __VA_ARGS__
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), \
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
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
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
236 #undef _TRACE_SYSCALLS_INTEGERS_H
237 #undef _TRACE_SYSCALLS_POINTERS_H
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), \
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
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
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
271 #undef _TRACE_SYSCALLS_INTEGERS_H
272 #undef _TRACE_SYSCALLS_POINTERS_H
276 #undef TP_MODULE_NOINIT
277 #undef LTTNG_PACKAGE_BUILD
278 #undef CREATE_TRACE_POINTS
280 struct trace_syscall_entry
{
282 const struct lttng_event_desc
*desc
;
283 const struct lttng_event_field
*fields
;
287 #define CREATE_SYSCALL_TABLE
294 #undef TRACE_SYSCALL_TABLE
295 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
297 .func = __event_probe__syscall_entry_##_template, \
298 .nrargs = (_nrargs), \
299 .fields = __event_fields___syscall_entry_##_template, \
300 .desc = &__event_desc___syscall_entry_##_name, \
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>
309 #undef TRACE_SYSCALL_TABLE
310 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
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, \
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>
329 #define sc_exit(...) __VA_ARGS__
331 #undef TRACE_SYSCALL_TABLE
332 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
334 .func = __event_probe__syscall_exit_##_template, \
335 .nrargs = (_nrargs), \
336 .fields = __event_fields___syscall_exit_##_template, \
337 .desc = &__event_desc___syscall_exit_##_name, \
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>
346 #undef TRACE_SYSCALL_TABLE
347 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
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, \
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>
363 #undef CREATE_SYSCALL_TABLE
365 struct lttng_syscall_filter
{
366 DECLARE_BITMAP(sc
, NR_syscalls
);
367 DECLARE_BITMAP(sc_compat
, NR_compat_syscalls
);
370 static void syscall_entry_unknown(struct lttng_event
*event
,
371 struct pt_regs
*regs
, unsigned int id
)
373 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
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
);
379 __event_probe__syscall_entry_unknown(event
, id
, args
);
382 void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
)
384 struct lttng_channel
*chan
= __data
;
385 struct lttng_event
*event
, *unknown_event
;
386 const struct trace_syscall_entry
*table
, *entry
;
389 if (unlikely(in_compat_syscall())) {
390 struct lttng_syscall_filter
*filter
;
392 filter
= lttng_rcu_dereference(chan
->sc_filter
);
394 if (id
< 0 || id
>= NR_compat_syscalls
395 || !test_bit(id
, filter
->sc_compat
)) {
396 /* System call filtered out. */
400 table
= compat_sc_table
;
401 table_len
= ARRAY_SIZE(compat_sc_table
);
402 unknown_event
= chan
->sc_compat_unknown
;
404 struct lttng_syscall_filter
*filter
;
406 filter
= lttng_rcu_dereference(chan
->sc_filter
);
408 if (id
< 0 || id
>= NR_syscalls
409 || !test_bit(id
, filter
->sc
)) {
410 /* System call filtered out. */
415 table_len
= ARRAY_SIZE(sc_table
);
416 unknown_event
= chan
->sc_unknown
;
418 if (unlikely(id
< 0 || id
>= table_len
)) {
419 syscall_entry_unknown(unknown_event
, regs
, id
);
422 if (unlikely(in_compat_syscall()))
423 event
= chan
->compat_sc_table
[id
];
425 event
= chan
->sc_table
[id
];
426 if (unlikely(!event
)) {
427 syscall_entry_unknown(unknown_event
, regs
, id
);
431 WARN_ON_ONCE(!entry
);
433 switch (entry
->nrargs
) {
436 void (*fptr
)(void *__data
) = entry
->func
;
443 void (*fptr
)(void *__data
, unsigned long arg0
) = entry
->func
;
444 unsigned long args
[1];
446 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
447 fptr(event
, args
[0]);
452 void (*fptr
)(void *__data
,
454 unsigned long arg1
) = entry
->func
;
455 unsigned long args
[2];
457 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
458 fptr(event
, args
[0], args
[1]);
463 void (*fptr
)(void *__data
,
466 unsigned long arg2
) = entry
->func
;
467 unsigned long args
[3];
469 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
470 fptr(event
, args
[0], args
[1], args
[2]);
475 void (*fptr
)(void *__data
,
479 unsigned long arg3
) = entry
->func
;
480 unsigned long args
[4];
482 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
483 fptr(event
, args
[0], args
[1], args
[2], args
[3]);
488 void (*fptr
)(void *__data
,
493 unsigned long arg4
) = entry
->func
;
494 unsigned long args
[5];
496 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
497 fptr(event
, args
[0], args
[1], args
[2], args
[3], args
[4]);
502 void (*fptr
)(void *__data
,
508 unsigned long arg5
) = entry
->func
;
509 unsigned long args
[6];
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]);
521 static void syscall_exit_unknown(struct lttng_event
*event
,
522 struct pt_regs
*regs
, int id
, long ret
)
524 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
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
,
531 __event_probe__syscall_exit_unknown(event
, id
, ret
, args
);
534 void syscall_exit_probe(void *__data
, struct pt_regs
*regs
, long ret
)
536 struct lttng_channel
*chan
= __data
;
537 struct lttng_event
*event
, *unknown_event
;
538 const struct trace_syscall_entry
*table
, *entry
;
542 id
= syscall_get_nr(current
, regs
);
543 if (unlikely(in_compat_syscall())) {
544 struct lttng_syscall_filter
*filter
;
546 filter
= lttng_rcu_dereference(chan
->sc_filter
);
548 if (id
< 0 || id
>= NR_compat_syscalls
549 || !test_bit(id
, filter
->sc_compat
)) {
550 /* System call filtered out. */
554 table
= compat_sc_exit_table
;
555 table_len
= ARRAY_SIZE(compat_sc_exit_table
);
556 unknown_event
= chan
->compat_sc_exit_unknown
;
558 struct lttng_syscall_filter
*filter
;
560 filter
= lttng_rcu_dereference(chan
->sc_filter
);
562 if (id
< 0 || id
>= NR_syscalls
563 || !test_bit(id
, filter
->sc
)) {
564 /* System call filtered out. */
568 table
= sc_exit_table
;
569 table_len
= ARRAY_SIZE(sc_exit_table
);
570 unknown_event
= chan
->sc_exit_unknown
;
572 if (unlikely(id
< 0 || id
>= table_len
)) {
573 syscall_exit_unknown(unknown_event
, regs
, id
, ret
);
576 if (unlikely(in_compat_syscall()))
577 event
= chan
->compat_sc_exit_table
[id
];
579 event
= chan
->sc_exit_table
[id
];
580 if (unlikely(!event
)) {
581 syscall_exit_unknown(unknown_event
, regs
, id
, ret
);
585 WARN_ON_ONCE(!entry
);
587 switch (entry
->nrargs
) {
590 void (*fptr
)(void *__data
, long ret
) = entry
->func
;
597 void (*fptr
)(void *__data
,
599 unsigned long arg0
) = entry
->func
;
600 unsigned long args
[1];
602 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
603 fptr(event
, ret
, args
[0]);
608 void (*fptr
)(void *__data
,
611 unsigned long arg1
) = entry
->func
;
612 unsigned long args
[2];
614 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
615 fptr(event
, ret
, args
[0], args
[1]);
620 void (*fptr
)(void *__data
,
624 unsigned long arg2
) = entry
->func
;
625 unsigned long args
[3];
627 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
628 fptr(event
, ret
, args
[0], args
[1], args
[2]);
633 void (*fptr
)(void *__data
,
638 unsigned long arg3
) = entry
->func
;
639 unsigned long args
[4];
641 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
642 fptr(event
, ret
, args
[0], args
[1], args
[2], args
[3]);
647 void (*fptr
)(void *__data
,
653 unsigned long arg4
) = entry
->func
;
654 unsigned long args
[5];
656 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
657 fptr(event
, ret
, args
[0], args
[1], args
[2], args
[3], args
[4]);
662 void (*fptr
)(void *__data
,
669 unsigned long arg5
) = entry
->func
;
670 unsigned long args
[6];
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]);
683 * noinline to diminish caller stack size.
684 * Should be called with sessions lock held.
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
)
691 const struct lttng_event_desc
*desc
;
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
;
700 /* Unknown syscall */
704 * Skip those already populated by previous failed
705 * register for this channel.
709 memset(&ev
, 0, sizeof(ev
));
712 strncpy(ev
.name
, SYSCALL_ENTRY_STR
,
713 LTTNG_KERNEL_SYM_NAME_LEN
);
716 strncpy(ev
.name
, SYSCALL_EXIT_STR
,
717 LTTNG_KERNEL_SYM_NAME_LEN
);
719 case SC_TYPE_COMPAT_ENTRY
:
720 strncpy(ev
.name
, COMPAT_SYSCALL_ENTRY_STR
,
721 LTTNG_KERNEL_SYM_NAME_LEN
);
723 case SC_TYPE_COMPAT_EXIT
:
724 strncpy(ev
.name
, COMPAT_SYSCALL_EXIT_STR
,
725 LTTNG_KERNEL_SYM_NAME_LEN
);
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
])) {
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.
745 return PTR_ERR(chan_table
[i
]);
752 * Should be called with sessions lock held.
754 int lttng_syscalls_register(struct lttng_channel
*chan
, void *filter
)
756 struct lttng_kernel_event ev
;
759 wrapper_vmalloc_sync_all();
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
);
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
)
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
)
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
)
794 if (!chan
->sc_unknown
) {
795 const struct lttng_event_desc
*desc
=
796 &__event_desc___syscall_entry_unknown
;
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
,
805 WARN_ON_ONCE(!chan
->sc_unknown
);
806 if (IS_ERR(chan
->sc_unknown
)) {
807 return PTR_ERR(chan
->sc_unknown
);
811 if (!chan
->sc_compat_unknown
) {
812 const struct lttng_event_desc
*desc
=
813 &__event_desc___compat_syscall_entry_unknown
;
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
,
822 WARN_ON_ONCE(!chan
->sc_unknown
);
823 if (IS_ERR(chan
->sc_compat_unknown
)) {
824 return PTR_ERR(chan
->sc_compat_unknown
);
828 if (!chan
->compat_sc_exit_unknown
) {
829 const struct lttng_event_desc
*desc
=
830 &__event_desc___compat_syscall_exit_unknown
;
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
,
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
);
845 if (!chan
->sc_exit_unknown
) {
846 const struct lttng_event_desc
*desc
=
847 &__event_desc___syscall_exit_unknown
;
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
);
861 ret
= fill_table(sc_table
, ARRAY_SIZE(sc_table
),
862 chan
->sc_table
, chan
, filter
, SC_TYPE_ENTRY
);
865 ret
= fill_table(sc_exit_table
, ARRAY_SIZE(sc_exit_table
),
866 chan
->sc_exit_table
, chan
, filter
, SC_TYPE_EXIT
);
871 ret
= fill_table(compat_sc_table
, ARRAY_SIZE(compat_sc_table
),
872 chan
->compat_sc_table
, chan
, filter
,
873 SC_TYPE_COMPAT_ENTRY
);
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
);
882 if (!chan
->sys_enter_registered
) {
883 ret
= lttng_wrapper_tracepoint_probe_register("sys_enter",
884 (void *) syscall_entry_probe
, chan
);
887 chan
->sys_enter_registered
= 1;
890 * We change the name of sys_exit tracepoint due to namespace
891 * conflict with sys_exit syscall entry.
893 if (!chan
->sys_exit_registered
) {
894 ret
= lttng_wrapper_tracepoint_probe_register("sys_exit",
895 (void *) syscall_exit_probe
, chan
);
897 WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter",
898 (void *) syscall_entry_probe
, chan
));
901 chan
->sys_exit_registered
= 1;
907 * Only called at session destruction.
909 int lttng_syscalls_unregister(struct lttng_channel
*chan
)
915 if (chan
->sys_enter_registered
) {
916 ret
= lttng_wrapper_tracepoint_probe_unregister("sys_exit",
917 (void *) syscall_exit_probe
, chan
);
920 chan
->sys_enter_registered
= 0;
922 if (chan
->sys_exit_registered
) {
923 ret
= lttng_wrapper_tracepoint_probe_unregister("sys_enter",
924 (void *) syscall_entry_probe
, chan
);
927 chan
->sys_exit_registered
= 0;
929 /* lttng_event destroy will be performed by lttng_session_destroy() */
930 kfree(chan
->sc_table
);
931 kfree(chan
->sc_exit_table
);
933 kfree(chan
->compat_sc_table
);
934 kfree(chan
->compat_sc_exit_table
);
936 kfree(chan
->sc_filter
);
941 int get_syscall_nr(const char *syscall_name
)
946 for (i
= 0; i
< ARRAY_SIZE(sc_table
); i
++) {
947 const struct trace_syscall_entry
*entry
;
950 entry
= &sc_table
[i
];
953 it_name
= entry
->desc
->name
;
954 it_name
+= strlen(SYSCALL_ENTRY_STR
);
955 if (!strcmp(syscall_name
, it_name
)) {
964 int get_compat_syscall_nr(const char *syscall_name
)
969 for (i
= 0; i
< ARRAY_SIZE(compat_sc_table
); i
++) {
970 const struct trace_syscall_entry
*entry
;
973 entry
= &compat_sc_table
[i
];
976 it_name
= entry
->desc
->name
;
977 it_name
+= strlen(COMPAT_SYSCALL_ENTRY_STR
);
978 if (!strcmp(syscall_name
, it_name
)) {
987 uint32_t get_sc_tables_len(void)
989 return ARRAY_SIZE(sc_table
) + ARRAY_SIZE(compat_sc_table
);
992 int lttng_syscall_filter_enable(struct lttng_channel
*chan
,
995 int syscall_nr
, compat_syscall_nr
, ret
;
996 struct lttng_syscall_filter
*filter
;
998 WARN_ON_ONCE(!chan
->sc_table
);
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();
1008 chan
->syscall_all
= 1;
1012 if (!chan
->sc_filter
) {
1013 if (chan
->syscall_all
) {
1015 * All syscalls are already enabled.
1019 filter
= kzalloc(sizeof(struct lttng_syscall_filter
),
1024 filter
= chan
->sc_filter
;
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) {
1032 if (syscall_nr
>= 0) {
1033 if (test_bit(syscall_nr
, filter
->sc
)) {
1037 bitmap_set(filter
->sc
, syscall_nr
, 1);
1039 if (compat_syscall_nr
>= 0) {
1040 if (test_bit(compat_syscall_nr
, filter
->sc_compat
)) {
1044 bitmap_set(filter
->sc_compat
, compat_syscall_nr
, 1);
1046 if (!chan
->sc_filter
)
1047 rcu_assign_pointer(chan
->sc_filter
, filter
);
1051 if (!chan
->sc_filter
)
1056 int lttng_syscall_filter_disable(struct lttng_channel
*chan
,
1059 int syscall_nr
, compat_syscall_nr
, ret
;
1060 struct lttng_syscall_filter
*filter
;
1062 WARN_ON_ONCE(!chan
->sc_table
);
1064 if (!chan
->sc_filter
) {
1065 if (!chan
->syscall_all
)
1067 filter
= kzalloc(sizeof(struct lttng_syscall_filter
),
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
);
1075 filter
= chan
->sc_filter
;
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
)) {
1087 /* Disable all system calls */
1088 bitmap_clear(filter
->sc
, 0, NR_syscalls
);
1089 bitmap_clear(filter
->sc_compat
, 0, NR_compat_syscalls
);
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) {
1098 if (syscall_nr
>= 0) {
1099 if (!test_bit(syscall_nr
, filter
->sc
)) {
1103 bitmap_clear(filter
->sc
, syscall_nr
, 1);
1105 if (compat_syscall_nr
>= 0) {
1106 if (!test_bit(compat_syscall_nr
, filter
->sc_compat
)) {
1110 bitmap_clear(filter
->sc_compat
, compat_syscall_nr
, 1);
1113 if (!chan
->sc_filter
)
1114 rcu_assign_pointer(chan
->sc_filter
, filter
);
1115 chan
->syscall_all
= 0;
1119 if (!chan
->sc_filter
)
1125 const struct trace_syscall_entry
*syscall_list_get_entry(loff_t
*pos
)
1127 const struct trace_syscall_entry
*entry
;
1130 for (entry
= sc_table
;
1131 entry
< sc_table
+ ARRAY_SIZE(sc_table
);
1136 for (entry
= compat_sc_table
;
1137 entry
< compat_sc_table
+ ARRAY_SIZE(compat_sc_table
);
1147 void *syscall_list_start(struct seq_file
*m
, loff_t
*pos
)
1149 return (void *) syscall_list_get_entry(pos
);
1153 void *syscall_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
1156 return (void *) syscall_list_get_entry(ppos
);
1160 void syscall_list_stop(struct seq_file
*m
, void *p
)
1165 int get_sc_table(const struct trace_syscall_entry
*entry
,
1166 const struct trace_syscall_entry
**table
,
1167 unsigned int *bitness
)
1169 if (entry
>= sc_table
&& entry
< sc_table
+ ARRAY_SIZE(sc_table
)) {
1171 *bitness
= BITS_PER_LONG
;
1176 if (!(entry
>= compat_sc_table
1177 && entry
< compat_sc_table
+ ARRAY_SIZE(compat_sc_table
))) {
1183 *table
= compat_sc_table
;
1188 int syscall_list_show(struct seq_file
*m
, void *p
)
1190 const struct trace_syscall_entry
*table
, *entry
= p
;
1191 unsigned int bitness
;
1192 unsigned long index
;
1196 ret
= get_sc_table(entry
, &table
, &bitness
);
1201 if (table
== sc_table
) {
1202 index
= entry
- table
;
1203 name
= &entry
->desc
->name
[strlen(SYSCALL_ENTRY_STR
)];
1205 index
= (entry
- table
) + ARRAY_SIZE(sc_table
);
1206 name
= &entry
->desc
->name
[strlen(COMPAT_SYSCALL_ENTRY_STR
)];
1208 seq_printf(m
, "syscall { index = %lu; name = %s; bitness = %u; };\n",
1209 index
, name
, bitness
);
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
,
1222 int lttng_syscall_list_open(struct inode
*inode
, struct file
*file
)
1224 return seq_open(file
, <tng_syscall_list_seq_ops
);
1227 const struct file_operations lttng_syscall_list_fops
= {
1228 .owner
= THIS_MODULE
,
1229 .open
= lttng_syscall_list_open
,
1231 .llseek
= seq_lseek
,
1232 .release
= seq_release
,
1235 long lttng_channel_syscall_mask(struct lttng_channel
*channel
,
1236 struct lttng_kernel_syscall_mask __user
*usyscall_mask
)
1238 uint32_t len
, sc_tables_len
, bitmask_len
;
1241 struct lttng_syscall_filter
*filter
;
1243 ret
= get_user(len
, &usyscall_mask
->len
);
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
);
1251 /* Array is large enough, we can copy array to user-space. */
1252 tmp_mask
= kzalloc(bitmask_len
, GFP_KERNEL
);
1255 filter
= channel
->sc_filter
;
1257 for (bit
= 0; bit
< ARRAY_SIZE(sc_table
); bit
++) {
1260 if (channel
->sc_table
) {
1262 state
= test_bit(bit
, filter
->sc
);
1268 bt_bitfield_write_be(tmp_mask
, char, bit
, 1, state
);
1270 for (; bit
< sc_tables_len
; bit
++) {
1273 if (channel
->compat_sc_table
) {
1275 state
= test_bit(bit
- ARRAY_SIZE(sc_table
),
1282 bt_bitfield_write_be(tmp_mask
, char, bit
, 1, state
);
1284 if (copy_to_user(usyscall_mask
->mask
, tmp_mask
, bitmask_len
))
1290 int lttng_abi_syscall_list(void)
1292 struct file
*syscall_list_file
;
1295 file_fd
= lttng_get_unused_fd();
1301 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
1302 <tng_syscall_list_fops
,
1304 if (IS_ERR(syscall_list_file
)) {
1305 ret
= PTR_ERR(syscall_list_file
);
1308 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
1311 fd_install(file_fd
, syscall_list_file
);
1315 fput(syscall_list_file
);
1317 put_unused_fd(file_fd
);