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
;
82 #ifdef IA32_NR_syscalls
83 #define NR_compat_syscalls IA32_NR_syscalls
85 #define NR_compat_syscalls NR_syscalls
89 * Create LTTng tracepoint probes.
91 #define LTTNG_PACKAGE_BUILD
92 #define CREATE_TRACE_POINTS
93 #define TP_MODULE_NOINIT
94 #define TRACE_INCLUDE_PATH ../instrumentation/syscalls/headers
96 #define PARAMS(args...) args
98 /* Handle unknown syscalls */
100 #define TRACE_SYSTEM syscalls_unknown
101 #include "instrumentation/syscalls/headers/syscalls_unknown.h"
109 #define sc_in(...) __VA_ARGS__
113 #define sc_inout(...) __VA_ARGS__
115 /* Hijack probe callback for system call enter */
117 #define TP_PROBE_CB(_template) &syscall_entry_probe
118 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
119 LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
121 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
122 LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
123 PARAMS(_locvar), PARAMS(_code), \
125 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
126 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields))
127 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
128 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name)
130 #define TRACE_SYSTEM syscall_entry_integers
131 #define TRACE_INCLUDE_FILE syscalls_integers
132 #include "instrumentation/syscalls/headers/syscalls_integers.h"
133 #undef TRACE_INCLUDE_FILE
135 #define TRACE_SYSTEM syscall_entry_pointers
136 #define TRACE_INCLUDE_FILE syscalls_pointers
137 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
138 #undef TRACE_INCLUDE_FILE
140 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
141 #undef SC_LTTNG_TRACEPOINT_EVENT
142 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
143 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
145 #undef _TRACE_SYSCALLS_INTEGERS_H
146 #undef _TRACE_SYSCALLS_POINTERS_H
148 /* Hijack probe callback for compat system call enter */
149 #define TP_PROBE_CB(_template) &syscall_entry_probe
150 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
151 LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
153 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
154 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
155 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
156 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
157 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields))
158 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
159 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_entry_##_template, \
160 compat_syscall_entry_##_name)
161 #define TRACE_SYSTEM compat_syscall_entry_integers
162 #define TRACE_INCLUDE_FILE compat_syscalls_integers
163 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
164 #undef TRACE_INCLUDE_FILE
166 #define TRACE_SYSTEM compat_syscall_entry_pointers
167 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
168 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
169 #undef TRACE_INCLUDE_FILE
171 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
172 #undef SC_LTTNG_TRACEPOINT_EVENT
173 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
174 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
176 #undef _TRACE_SYSCALLS_INTEGERS_H
177 #undef _TRACE_SYSCALLS_POINTERS_H
184 #define sc_exit(...) __VA_ARGS__
188 #define sc_out(...) __VA_ARGS__
190 #define sc_inout(...) __VA_ARGS__
192 /* Hijack probe callback for system call exit */
193 #define TP_PROBE_CB(_template) &syscall_exit_probe
194 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
195 LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
197 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
198 LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
199 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
200 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
201 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields))
202 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
203 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, \
204 syscall_exit_##_name)
205 #define TRACE_SYSTEM syscall_exit_integers
206 #define TRACE_INCLUDE_FILE syscalls_integers
207 #include "instrumentation/syscalls/headers/syscalls_integers.h"
208 #undef TRACE_INCLUDE_FILE
210 #define TRACE_SYSTEM syscall_exit_pointers
211 #define TRACE_INCLUDE_FILE syscalls_pointers
212 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
213 #undef TRACE_INCLUDE_FILE
215 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
216 #undef SC_LTTNG_TRACEPOINT_EVENT
217 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
218 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
220 #undef _TRACE_SYSCALLS_INTEGERS_H
221 #undef _TRACE_SYSCALLS_POINTERS_H
224 /* Hijack probe callback for compat system call exit */
225 #define TP_PROBE_CB(_template) &syscall_exit_probe
226 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
227 LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
229 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
230 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
231 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
232 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
233 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields))
234 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
235 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, \
236 compat_syscall_exit_##_name)
237 #define TRACE_SYSTEM compat_syscall_exit_integers
238 #define TRACE_INCLUDE_FILE compat_syscalls_integers
239 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
240 #undef TRACE_INCLUDE_FILE
242 #define TRACE_SYSTEM compat_syscall_exit_pointers
243 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
244 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
245 #undef TRACE_INCLUDE_FILE
247 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
248 #undef SC_LTTNG_TRACEPOINT_EVENT
249 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
250 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
252 #undef _TRACE_SYSCALLS_INTEGERS_H
253 #undef _TRACE_SYSCALLS_POINTERS_H
257 #undef TP_MODULE_NOINIT
258 #undef LTTNG_PACKAGE_BUILD
259 #undef CREATE_TRACE_POINTS
261 struct trace_syscall_entry
{
263 const struct lttng_event_desc
*desc
;
264 const struct lttng_event_field
*fields
;
268 #define CREATE_SYSCALL_TABLE
275 #undef TRACE_SYSCALL_TABLE
276 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
278 .func = __event_probe__syscall_entry_##_template, \
279 .nrargs = (_nrargs), \
280 .fields = __event_fields___syscall_entry_##_template, \
281 .desc = &__event_desc___syscall_entry_##_name, \
284 /* Syscall enter tracing table */
285 static const struct trace_syscall_entry sc_table
[] = {
286 #include "instrumentation/syscalls/headers/syscalls_integers.h"
287 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
290 #undef TRACE_SYSCALL_TABLE
291 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
293 .func = __event_probe__compat_syscall_entry_##_template, \
294 .nrargs = (_nrargs), \
295 .fields = __event_fields___compat_syscall_entry_##_template, \
296 .desc = &__event_desc___compat_syscall_entry_##_name, \
299 /* Compat syscall enter table */
300 const struct trace_syscall_entry compat_sc_table
[] = {
301 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
302 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
310 #define sc_exit(...) __VA_ARGS__
312 #undef TRACE_SYSCALL_TABLE
313 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
315 .func = __event_probe__syscall_exit_##_template, \
316 .nrargs = (_nrargs), \
317 .fields = __event_fields___syscall_exit_##_template, \
318 .desc = &__event_desc___syscall_exit_##_name, \
321 /* Syscall exit table */
322 static const struct trace_syscall_entry sc_exit_table
[] = {
323 #include "instrumentation/syscalls/headers/syscalls_integers.h"
324 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
327 #undef TRACE_SYSCALL_TABLE
328 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
330 .func = __event_probe__compat_syscall_exit_##_template, \
331 .nrargs = (_nrargs), \
332 .fields = __event_fields___compat_syscall_exit_##_template, \
333 .desc = &__event_desc___compat_syscall_exit_##_name, \
336 /* Compat syscall exit table */
337 const struct trace_syscall_entry compat_sc_exit_table
[] = {
338 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
339 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
344 #undef CREATE_SYSCALL_TABLE
346 struct lttng_syscall_filter
{
347 DECLARE_BITMAP(sc
, NR_syscalls
);
348 DECLARE_BITMAP(sc_compat
, NR_compat_syscalls
);
351 static void syscall_entry_unknown(struct lttng_event
*event
,
352 struct pt_regs
*regs
, unsigned int id
)
354 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
356 syscall_get_arguments(current
, regs
, 0, UNKNOWN_SYSCALL_NRARGS
, args
);
357 if (unlikely(is_compat_task()))
358 __event_probe__compat_syscall_entry_unknown(event
, id
, args
);
360 __event_probe__syscall_entry_unknown(event
, id
, args
);
363 void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
)
365 struct lttng_channel
*chan
= __data
;
366 struct lttng_event
*event
, *unknown_event
;
367 const struct trace_syscall_entry
*table
, *entry
;
370 if (unlikely(is_compat_task())) {
371 struct lttng_syscall_filter
*filter
;
373 filter
= lttng_rcu_dereference(chan
->sc_filter
);
375 if (id
< 0 || id
>= NR_compat_syscalls
376 || !test_bit(id
, filter
->sc_compat
)) {
377 /* System call filtered out. */
381 table
= compat_sc_table
;
382 table_len
= ARRAY_SIZE(compat_sc_table
);
383 unknown_event
= chan
->sc_compat_unknown
;
385 struct lttng_syscall_filter
*filter
;
387 filter
= lttng_rcu_dereference(chan
->sc_filter
);
389 if (id
< 0 || id
>= NR_syscalls
390 || !test_bit(id
, filter
->sc
)) {
391 /* System call filtered out. */
396 table_len
= ARRAY_SIZE(sc_table
);
397 unknown_event
= chan
->sc_unknown
;
399 if (unlikely(id
< 0 || id
>= table_len
)) {
400 syscall_entry_unknown(unknown_event
, regs
, id
);
403 if (unlikely(is_compat_task()))
404 event
= chan
->compat_sc_table
[id
];
406 event
= chan
->sc_table
[id
];
407 if (unlikely(!event
)) {
408 syscall_entry_unknown(unknown_event
, regs
, id
);
412 WARN_ON_ONCE(!entry
);
414 switch (entry
->nrargs
) {
417 void (*fptr
)(void *__data
) = entry
->func
;
424 void (*fptr
)(void *__data
, unsigned long arg0
) = entry
->func
;
425 unsigned long args
[1];
427 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
428 fptr(event
, args
[0]);
433 void (*fptr
)(void *__data
,
435 unsigned long arg1
) = entry
->func
;
436 unsigned long args
[2];
438 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
439 fptr(event
, args
[0], args
[1]);
444 void (*fptr
)(void *__data
,
447 unsigned long arg2
) = entry
->func
;
448 unsigned long args
[3];
450 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
451 fptr(event
, args
[0], args
[1], args
[2]);
456 void (*fptr
)(void *__data
,
460 unsigned long arg3
) = entry
->func
;
461 unsigned long args
[4];
463 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
464 fptr(event
, args
[0], args
[1], args
[2], args
[3]);
469 void (*fptr
)(void *__data
,
474 unsigned long arg4
) = entry
->func
;
475 unsigned long args
[5];
477 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
478 fptr(event
, args
[0], args
[1], args
[2], args
[3], args
[4]);
483 void (*fptr
)(void *__data
,
489 unsigned long arg5
) = entry
->func
;
490 unsigned long args
[6];
492 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
493 fptr(event
, args
[0], args
[1], args
[2],
494 args
[3], args
[4], args
[5]);
502 static void syscall_exit_unknown(struct lttng_event
*event
,
503 struct pt_regs
*regs
, int id
, long ret
)
505 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
507 syscall_get_arguments(current
, regs
, 0, UNKNOWN_SYSCALL_NRARGS
, args
);
508 if (unlikely(is_compat_task()))
509 __event_probe__compat_syscall_exit_unknown(event
, id
, ret
,
512 __event_probe__syscall_exit_unknown(event
, id
, ret
, args
);
515 void syscall_exit_probe(void *__data
, struct pt_regs
*regs
, long ret
)
517 struct lttng_channel
*chan
= __data
;
518 struct lttng_event
*event
, *unknown_event
;
519 const struct trace_syscall_entry
*table
, *entry
;
523 id
= syscall_get_nr(current
, regs
);
524 if (unlikely(is_compat_task())) {
525 struct lttng_syscall_filter
*filter
;
527 filter
= lttng_rcu_dereference(chan
->sc_filter
);
529 if (id
< 0 || id
>= NR_compat_syscalls
530 || !test_bit(id
, filter
->sc_compat
)) {
531 /* System call filtered out. */
535 table
= compat_sc_exit_table
;
536 table_len
= ARRAY_SIZE(compat_sc_exit_table
);
537 unknown_event
= chan
->compat_sc_exit_unknown
;
539 struct lttng_syscall_filter
*filter
;
541 filter
= lttng_rcu_dereference(chan
->sc_filter
);
543 if (id
< 0 || id
>= NR_syscalls
544 || !test_bit(id
, filter
->sc
)) {
545 /* System call filtered out. */
549 table
= sc_exit_table
;
550 table_len
= ARRAY_SIZE(sc_exit_table
);
551 unknown_event
= chan
->sc_exit_unknown
;
553 if (unlikely(id
< 0 || id
>= table_len
)) {
554 syscall_exit_unknown(unknown_event
, regs
, id
, ret
);
557 if (unlikely(is_compat_task()))
558 event
= chan
->compat_sc_exit_table
[id
];
560 event
= chan
->sc_exit_table
[id
];
561 if (unlikely(!event
)) {
562 syscall_exit_unknown(unknown_event
, regs
, id
, ret
);
566 WARN_ON_ONCE(!entry
);
568 switch (entry
->nrargs
) {
571 void (*fptr
)(void *__data
, long ret
) = entry
->func
;
578 void (*fptr
)(void *__data
,
580 unsigned long arg0
) = entry
->func
;
581 unsigned long args
[1];
583 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
584 fptr(event
, ret
, args
[0]);
589 void (*fptr
)(void *__data
,
592 unsigned long arg1
) = entry
->func
;
593 unsigned long args
[2];
595 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
596 fptr(event
, ret
, args
[0], args
[1]);
601 void (*fptr
)(void *__data
,
605 unsigned long arg2
) = entry
->func
;
606 unsigned long args
[3];
608 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
609 fptr(event
, ret
, args
[0], args
[1], args
[2]);
614 void (*fptr
)(void *__data
,
619 unsigned long arg3
) = entry
->func
;
620 unsigned long args
[4];
622 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
623 fptr(event
, ret
, args
[0], args
[1], args
[2], args
[3]);
628 void (*fptr
)(void *__data
,
634 unsigned long arg4
) = entry
->func
;
635 unsigned long args
[5];
637 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
638 fptr(event
, ret
, args
[0], args
[1], args
[2], args
[3], args
[4]);
643 void (*fptr
)(void *__data
,
650 unsigned long arg5
) = entry
->func
;
651 unsigned long args
[6];
653 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
654 fptr(event
, ret
, args
[0], args
[1], args
[2],
655 args
[3], args
[4], args
[5]);
664 * noinline to diminish caller stack size.
665 * Should be called with sessions lock held.
668 int fill_table(const struct trace_syscall_entry
*table
, size_t table_len
,
669 struct lttng_event
**chan_table
, struct lttng_channel
*chan
,
670 void *filter
, enum sc_type type
)
672 const struct lttng_event_desc
*desc
;
675 /* Allocate events for each syscall, insert into table */
676 for (i
= 0; i
< table_len
; i
++) {
677 struct lttng_kernel_event ev
;
678 desc
= table
[i
].desc
;
681 /* Unknown syscall */
685 * Skip those already populated by previous failed
686 * register for this channel.
690 memset(&ev
, 0, sizeof(ev
));
693 strncpy(ev
.name
, SYSCALL_ENTRY_STR
,
694 LTTNG_KERNEL_SYM_NAME_LEN
);
697 strncpy(ev
.name
, SYSCALL_EXIT_STR
,
698 LTTNG_KERNEL_SYM_NAME_LEN
);
700 case SC_TYPE_COMPAT_ENTRY
:
701 strncpy(ev
.name
, COMPAT_SYSCALL_ENTRY_STR
,
702 LTTNG_KERNEL_SYM_NAME_LEN
);
704 case SC_TYPE_COMPAT_EXIT
:
705 strncpy(ev
.name
, COMPAT_SYSCALL_EXIT_STR
,
706 LTTNG_KERNEL_SYM_NAME_LEN
);
712 strncat(ev
.name
, desc
->name
,
713 LTTNG_KERNEL_SYM_NAME_LEN
- strlen(ev
.name
) - 1);
714 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
715 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
716 chan_table
[i
] = _lttng_event_create(chan
, &ev
, filter
,
717 desc
, ev
.instrumentation
);
718 WARN_ON_ONCE(!chan_table
[i
]);
719 if (IS_ERR(chan_table
[i
])) {
721 * If something goes wrong in event registration
722 * after the first one, we have no choice but to
723 * leave the previous events in there, until
724 * deleted by session teardown.
726 return PTR_ERR(chan_table
[i
]);
733 * Should be called with sessions lock held.
735 int lttng_syscalls_register(struct lttng_channel
*chan
, void *filter
)
737 struct lttng_kernel_event ev
;
740 wrapper_vmalloc_sync_all();
742 if (!chan
->sc_table
) {
743 /* create syscall table mapping syscall to events */
744 chan
->sc_table
= kzalloc(sizeof(struct lttng_event
*)
745 * ARRAY_SIZE(sc_table
), GFP_KERNEL
);
749 if (!chan
->sc_exit_table
) {
750 /* create syscall table mapping syscall to events */
751 chan
->sc_exit_table
= kzalloc(sizeof(struct lttng_event
*)
752 * ARRAY_SIZE(sc_exit_table
), GFP_KERNEL
);
753 if (!chan
->sc_exit_table
)
759 if (!chan
->compat_sc_table
) {
760 /* create syscall table mapping compat syscall to events */
761 chan
->compat_sc_table
= kzalloc(sizeof(struct lttng_event
*)
762 * ARRAY_SIZE(compat_sc_table
), GFP_KERNEL
);
763 if (!chan
->compat_sc_table
)
767 if (!chan
->compat_sc_exit_table
) {
768 /* create syscall table mapping compat syscall to events */
769 chan
->compat_sc_exit_table
= kzalloc(sizeof(struct lttng_event
*)
770 * ARRAY_SIZE(compat_sc_exit_table
), GFP_KERNEL
);
771 if (!chan
->compat_sc_exit_table
)
775 if (!chan
->sc_unknown
) {
776 const struct lttng_event_desc
*desc
=
777 &__event_desc___syscall_entry_unknown
;
779 memset(&ev
, 0, sizeof(ev
));
780 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
781 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
782 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
783 chan
->sc_unknown
= _lttng_event_create(chan
, &ev
, filter
,
786 WARN_ON_ONCE(!chan
->sc_unknown
);
787 if (IS_ERR(chan
->sc_unknown
)) {
788 return PTR_ERR(chan
->sc_unknown
);
792 if (!chan
->sc_compat_unknown
) {
793 const struct lttng_event_desc
*desc
=
794 &__event_desc___compat_syscall_entry_unknown
;
796 memset(&ev
, 0, sizeof(ev
));
797 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
798 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
799 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
800 chan
->sc_compat_unknown
= _lttng_event_create(chan
, &ev
, filter
,
803 WARN_ON_ONCE(!chan
->sc_unknown
);
804 if (IS_ERR(chan
->sc_compat_unknown
)) {
805 return PTR_ERR(chan
->sc_compat_unknown
);
809 if (!chan
->compat_sc_exit_unknown
) {
810 const struct lttng_event_desc
*desc
=
811 &__event_desc___compat_syscall_exit_unknown
;
813 memset(&ev
, 0, sizeof(ev
));
814 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
815 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
816 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
817 chan
->compat_sc_exit_unknown
= _lttng_event_create(chan
, &ev
,
820 WARN_ON_ONCE(!chan
->compat_sc_exit_unknown
);
821 if (IS_ERR(chan
->compat_sc_exit_unknown
)) {
822 return PTR_ERR(chan
->compat_sc_exit_unknown
);
826 if (!chan
->sc_exit_unknown
) {
827 const struct lttng_event_desc
*desc
=
828 &__event_desc___syscall_exit_unknown
;
830 memset(&ev
, 0, sizeof(ev
));
831 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
832 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
833 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
834 chan
->sc_exit_unknown
= _lttng_event_create(chan
, &ev
, filter
,
835 desc
, ev
.instrumentation
);
836 WARN_ON_ONCE(!chan
->sc_exit_unknown
);
837 if (IS_ERR(chan
->sc_exit_unknown
)) {
838 return PTR_ERR(chan
->sc_exit_unknown
);
842 ret
= fill_table(sc_table
, ARRAY_SIZE(sc_table
),
843 chan
->sc_table
, chan
, filter
, SC_TYPE_ENTRY
);
846 ret
= fill_table(sc_exit_table
, ARRAY_SIZE(sc_exit_table
),
847 chan
->sc_exit_table
, chan
, filter
, SC_TYPE_EXIT
);
852 ret
= fill_table(compat_sc_table
, ARRAY_SIZE(compat_sc_table
),
853 chan
->compat_sc_table
, chan
, filter
,
854 SC_TYPE_COMPAT_ENTRY
);
857 ret
= fill_table(compat_sc_exit_table
, ARRAY_SIZE(compat_sc_exit_table
),
858 chan
->compat_sc_exit_table
, chan
, filter
,
859 SC_TYPE_COMPAT_EXIT
);
863 if (!chan
->sys_enter_registered
) {
864 ret
= lttng_wrapper_tracepoint_probe_register("sys_enter",
865 (void *) syscall_entry_probe
, chan
);
868 chan
->sys_enter_registered
= 1;
871 * We change the name of sys_exit tracepoint due to namespace
872 * conflict with sys_exit syscall entry.
874 if (!chan
->sys_exit_registered
) {
875 ret
= lttng_wrapper_tracepoint_probe_register("sys_exit",
876 (void *) syscall_exit_probe
, chan
);
878 WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter",
879 (void *) syscall_entry_probe
, chan
));
882 chan
->sys_exit_registered
= 1;
888 * Only called at session destruction.
890 int lttng_syscalls_unregister(struct lttng_channel
*chan
)
896 if (chan
->sys_enter_registered
) {
897 ret
= lttng_wrapper_tracepoint_probe_unregister("sys_exit",
898 (void *) syscall_exit_probe
, chan
);
901 chan
->sys_enter_registered
= 0;
903 if (chan
->sys_exit_registered
) {
904 ret
= lttng_wrapper_tracepoint_probe_unregister("sys_enter",
905 (void *) syscall_entry_probe
, chan
);
908 chan
->sys_exit_registered
= 0;
910 /* lttng_event destroy will be performed by lttng_session_destroy() */
911 kfree(chan
->sc_table
);
912 kfree(chan
->sc_exit_table
);
914 kfree(chan
->compat_sc_table
);
915 kfree(chan
->compat_sc_exit_table
);
917 kfree(chan
->sc_filter
);
922 int get_syscall_nr(const char *syscall_name
)
927 for (i
= 0; i
< ARRAY_SIZE(sc_table
); i
++) {
928 const struct trace_syscall_entry
*entry
;
931 entry
= &sc_table
[i
];
934 it_name
= entry
->desc
->name
;
935 it_name
+= strlen(SYSCALL_ENTRY_STR
);
936 if (!strcmp(syscall_name
, it_name
)) {
945 int get_compat_syscall_nr(const char *syscall_name
)
950 for (i
= 0; i
< ARRAY_SIZE(compat_sc_table
); i
++) {
951 const struct trace_syscall_entry
*entry
;
954 entry
= &compat_sc_table
[i
];
957 it_name
= entry
->desc
->name
;
958 it_name
+= strlen(COMPAT_SYSCALL_ENTRY_STR
);
959 if (!strcmp(syscall_name
, it_name
)) {
968 uint32_t get_sc_tables_len(void)
970 return ARRAY_SIZE(sc_table
) + ARRAY_SIZE(compat_sc_table
);
973 int lttng_syscall_filter_enable(struct lttng_channel
*chan
,
976 int syscall_nr
, compat_syscall_nr
, ret
;
977 struct lttng_syscall_filter
*filter
;
979 WARN_ON_ONCE(!chan
->sc_table
);
982 /* Enable all system calls by removing filter */
983 if (chan
->sc_filter
) {
984 filter
= chan
->sc_filter
;
985 rcu_assign_pointer(chan
->sc_filter
, NULL
);
989 chan
->syscall_all
= 1;
993 if (!chan
->sc_filter
) {
994 if (chan
->syscall_all
) {
996 * All syscalls are already enabled.
1000 filter
= kzalloc(sizeof(struct lttng_syscall_filter
),
1005 filter
= chan
->sc_filter
;
1007 syscall_nr
= get_syscall_nr(name
);
1008 compat_syscall_nr
= get_compat_syscall_nr(name
);
1009 if (syscall_nr
< 0 && compat_syscall_nr
< 0) {
1013 if (syscall_nr
>= 0) {
1014 if (test_bit(syscall_nr
, filter
->sc
)) {
1018 bitmap_set(filter
->sc
, syscall_nr
, 1);
1020 if (compat_syscall_nr
>= 0) {
1021 if (test_bit(compat_syscall_nr
, filter
->sc_compat
)) {
1025 bitmap_set(filter
->sc_compat
, compat_syscall_nr
, 1);
1027 if (!chan
->sc_filter
)
1028 rcu_assign_pointer(chan
->sc_filter
, filter
);
1032 if (!chan
->sc_filter
)
1037 int lttng_syscall_filter_disable(struct lttng_channel
*chan
,
1040 int syscall_nr
, compat_syscall_nr
, ret
;
1041 struct lttng_syscall_filter
*filter
;
1043 WARN_ON_ONCE(!chan
->sc_table
);
1045 if (!chan
->sc_filter
) {
1046 if (!chan
->syscall_all
)
1048 filter
= kzalloc(sizeof(struct lttng_syscall_filter
),
1052 /* Trace all system calls, then apply disable. */
1053 bitmap_set(filter
->sc
, 0, NR_syscalls
);
1054 bitmap_set(filter
->sc_compat
, 0, NR_compat_syscalls
);
1056 filter
= chan
->sc_filter
;
1060 /* Fail if all syscalls are already disabled. */
1061 if (bitmap_empty(filter
->sc
, NR_syscalls
)
1062 && bitmap_empty(filter
->sc_compat
,
1063 NR_compat_syscalls
)) {
1068 /* Disable all system calls */
1069 bitmap_clear(filter
->sc
, 0, NR_syscalls
);
1070 bitmap_clear(filter
->sc_compat
, 0, NR_compat_syscalls
);
1073 syscall_nr
= get_syscall_nr(name
);
1074 compat_syscall_nr
= get_compat_syscall_nr(name
);
1075 if (syscall_nr
< 0 && compat_syscall_nr
< 0) {
1079 if (syscall_nr
>= 0) {
1080 if (!test_bit(syscall_nr
, filter
->sc
)) {
1084 bitmap_clear(filter
->sc
, syscall_nr
, 1);
1086 if (compat_syscall_nr
>= 0) {
1087 if (!test_bit(compat_syscall_nr
, filter
->sc_compat
)) {
1091 bitmap_clear(filter
->sc_compat
, compat_syscall_nr
, 1);
1094 if (!chan
->sc_filter
)
1095 rcu_assign_pointer(chan
->sc_filter
, filter
);
1096 chan
->syscall_all
= 0;
1100 if (!chan
->sc_filter
)
1106 const struct trace_syscall_entry
*syscall_list_get_entry(loff_t
*pos
)
1108 const struct trace_syscall_entry
*entry
;
1111 for (entry
= sc_table
;
1112 entry
< sc_table
+ ARRAY_SIZE(sc_table
);
1117 for (entry
= compat_sc_table
;
1118 entry
< compat_sc_table
+ ARRAY_SIZE(compat_sc_table
);
1128 void *syscall_list_start(struct seq_file
*m
, loff_t
*pos
)
1130 return (void *) syscall_list_get_entry(pos
);
1134 void *syscall_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
1137 return (void *) syscall_list_get_entry(ppos
);
1141 void syscall_list_stop(struct seq_file
*m
, void *p
)
1146 int get_sc_table(const struct trace_syscall_entry
*entry
,
1147 const struct trace_syscall_entry
**table
,
1148 unsigned int *bitness
)
1150 if (entry
>= sc_table
&& entry
< sc_table
+ ARRAY_SIZE(sc_table
)) {
1152 *bitness
= BITS_PER_LONG
;
1157 if (!(entry
>= compat_sc_table
1158 && entry
< compat_sc_table
+ ARRAY_SIZE(compat_sc_table
))) {
1164 *table
= compat_sc_table
;
1169 int syscall_list_show(struct seq_file
*m
, void *p
)
1171 const struct trace_syscall_entry
*table
, *entry
= p
;
1172 unsigned int bitness
;
1173 unsigned long index
;
1177 ret
= get_sc_table(entry
, &table
, &bitness
);
1182 if (table
== sc_table
) {
1183 index
= entry
- table
;
1184 name
= &entry
->desc
->name
[strlen(SYSCALL_ENTRY_STR
)];
1186 index
= (entry
- table
) + ARRAY_SIZE(sc_table
);
1187 name
= &entry
->desc
->name
[strlen(COMPAT_SYSCALL_ENTRY_STR
)];
1189 seq_printf(m
, "syscall { index = %lu; name = %s; bitness = %u; };\n",
1190 index
, name
, bitness
);
1195 const struct seq_operations lttng_syscall_list_seq_ops
= {
1196 .start
= syscall_list_start
,
1197 .next
= syscall_list_next
,
1198 .stop
= syscall_list_stop
,
1199 .show
= syscall_list_show
,
1203 int lttng_syscall_list_open(struct inode
*inode
, struct file
*file
)
1205 return seq_open(file
, <tng_syscall_list_seq_ops
);
1208 const struct file_operations lttng_syscall_list_fops
= {
1209 .owner
= THIS_MODULE
,
1210 .open
= lttng_syscall_list_open
,
1212 .llseek
= seq_lseek
,
1213 .release
= seq_release
,
1216 long lttng_channel_syscall_mask(struct lttng_channel
*channel
,
1217 struct lttng_kernel_syscall_mask __user
*usyscall_mask
)
1219 uint32_t len
, sc_tables_len
, bitmask_len
;
1222 struct lttng_syscall_filter
*filter
;
1224 ret
= get_user(len
, &usyscall_mask
->len
);
1227 sc_tables_len
= get_sc_tables_len();
1228 bitmask_len
= ALIGN(sc_tables_len
, 8) >> 3;
1229 if (len
< sc_tables_len
) {
1230 return put_user(sc_tables_len
, &usyscall_mask
->len
);
1232 /* Array is large enough, we can copy array to user-space. */
1233 tmp_mask
= kzalloc(bitmask_len
, GFP_KERNEL
);
1236 filter
= channel
->sc_filter
;
1238 for (bit
= 0; bit
< ARRAY_SIZE(sc_table
); bit
++) {
1241 if (channel
->sc_table
) {
1243 state
= test_bit(bit
, filter
->sc
);
1249 bt_bitfield_write_be(tmp_mask
, char, bit
, 1, state
);
1251 for (; bit
< sc_tables_len
; bit
++) {
1254 if (channel
->compat_sc_table
) {
1256 state
= test_bit(bit
- ARRAY_SIZE(sc_table
),
1263 bt_bitfield_write_be(tmp_mask
, char, bit
, 1, state
);
1265 if (copy_to_user(usyscall_mask
->mask
, tmp_mask
, bitmask_len
))
1271 int lttng_abi_syscall_list(void)
1273 struct file
*syscall_list_file
;
1276 file_fd
= lttng_get_unused_fd();
1282 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
1283 <tng_syscall_list_fops
,
1285 if (IS_ERR(syscall_list_file
)) {
1286 ret
= PTR_ERR(syscall_list_file
);
1289 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
1292 fd_install(file_fd
, syscall_list_file
);
1300 fput(syscall_list_file
);
1302 put_unused_fd(file_fd
);