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 "lttng-events.h"
43 # ifndef is_compat_task
44 # define is_compat_task() (0)
55 #define SYSCALL_ENTRY_TOK syscall_entry_
56 #define COMPAT_SYSCALL_ENTRY_TOK compat_syscall_entry_
57 #define SYSCALL_EXIT_TOK syscall_exit_
58 #define COMPAT_SYSCALL_EXIT_TOK compat_syscall_exit_
60 #define SYSCALL_ENTRY_STR __stringify(SYSCALL_ENTRY_TOK)
61 #define COMPAT_SYSCALL_ENTRY_STR __stringify(COMPAT_SYSCALL_ENTRY_TOK)
62 #define SYSCALL_EXIT_STR __stringify(SYSCALL_EXIT_TOK)
63 #define COMPAT_SYSCALL_EXIT_STR __stringify(COMPAT_SYSCALL_EXIT_TOK)
66 void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
);
68 void syscall_exit_probe(void *__data
, struct pt_regs
*regs
, long ret
);
71 * Forward declarations for old kernels.
75 struct oldold_utsname
;
77 struct sel_arg_struct
;
78 struct mmap_arg_struct
;
80 #ifdef IA32_NR_syscalls
81 #define NR_compat_syscalls IA32_NR_syscalls
83 #define NR_compat_syscalls NR_syscalls
87 * Create LTTng tracepoint probes.
89 #define LTTNG_PACKAGE_BUILD
90 #define CREATE_TRACE_POINTS
91 #define TP_MODULE_NOINIT
92 #define TRACE_INCLUDE_PATH ../instrumentation/syscalls/headers
94 #define PARAMS(args...) args
96 /* Handle unknown syscalls */
98 #define TRACE_SYSTEM syscalls_unknown
99 #include "instrumentation/syscalls/headers/syscalls_unknown.h"
107 #define sc_in(...) __VA_ARGS__
111 #define sc_inout(...) __VA_ARGS__
113 /* Hijack probe callback for system call enter */
115 #define TP_PROBE_CB(_template) &syscall_entry_probe
116 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
117 LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
119 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
120 LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
121 PARAMS(_locvar), PARAMS(_code), \
123 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
124 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields))
125 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
126 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name)
128 #define TRACE_SYSTEM syscall_entry_integers
129 #define TRACE_INCLUDE_FILE syscalls_integers
130 #include "instrumentation/syscalls/headers/syscalls_integers.h"
131 #undef TRACE_INCLUDE_FILE
133 #define TRACE_SYSTEM syscall_entry_pointers
134 #define TRACE_INCLUDE_FILE syscalls_pointers
135 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
136 #undef TRACE_INCLUDE_FILE
138 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
139 #undef SC_LTTNG_TRACEPOINT_EVENT
140 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
141 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
143 #undef _TRACE_SYSCALLS_INTEGERS_H
144 #undef _TRACE_SYSCALLS_POINTERS_H
146 /* Hijack probe callback for compat system call enter */
147 #define TP_PROBE_CB(_template) &syscall_entry_probe
148 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
149 LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
151 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
152 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
153 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
154 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
155 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields))
156 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
157 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_entry_##_template, \
158 compat_syscall_entry_##_name)
159 #define TRACE_SYSTEM compat_syscall_entry_integers
160 #define TRACE_INCLUDE_FILE compat_syscalls_integers
161 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
162 #undef TRACE_INCLUDE_FILE
164 #define TRACE_SYSTEM compat_syscall_entry_pointers
165 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
166 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
167 #undef TRACE_INCLUDE_FILE
169 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
170 #undef SC_LTTNG_TRACEPOINT_EVENT
171 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
172 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
174 #undef _TRACE_SYSCALLS_INTEGERS_H
175 #undef _TRACE_SYSCALLS_POINTERS_H
182 #define sc_exit(...) __VA_ARGS__
186 #define sc_out(...) __VA_ARGS__
188 #define sc_inout(...) __VA_ARGS__
190 /* Hijack probe callback for system call exit */
191 #define TP_PROBE_CB(_template) &syscall_exit_probe
192 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
193 LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
195 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
196 LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
197 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
198 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
199 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields))
200 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
201 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, \
202 syscall_exit_##_name)
203 #define TRACE_SYSTEM syscall_exit_integers
204 #define TRACE_INCLUDE_FILE syscalls_integers
205 #include "instrumentation/syscalls/headers/syscalls_integers.h"
206 #undef TRACE_INCLUDE_FILE
208 #define TRACE_SYSTEM syscall_exit_pointers
209 #define TRACE_INCLUDE_FILE syscalls_pointers
210 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
211 #undef TRACE_INCLUDE_FILE
213 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
214 #undef SC_LTTNG_TRACEPOINT_EVENT
215 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
216 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
218 #undef _TRACE_SYSCALLS_INTEGERS_H
219 #undef _TRACE_SYSCALLS_POINTERS_H
222 /* Hijack probe callback for compat system call exit */
223 #define TP_PROBE_CB(_template) &syscall_exit_probe
224 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
225 LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
227 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
228 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
229 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
230 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
231 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields))
232 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
233 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, \
234 compat_syscall_exit_##_name)
235 #define TRACE_SYSTEM compat_syscall_exit_integers
236 #define TRACE_INCLUDE_FILE compat_syscalls_integers
237 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
238 #undef TRACE_INCLUDE_FILE
240 #define TRACE_SYSTEM compat_syscall_exit_pointers
241 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
242 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
243 #undef TRACE_INCLUDE_FILE
245 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
246 #undef SC_LTTNG_TRACEPOINT_EVENT
247 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
248 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
250 #undef _TRACE_SYSCALLS_INTEGERS_H
251 #undef _TRACE_SYSCALLS_POINTERS_H
255 #undef TP_MODULE_NOINIT
256 #undef LTTNG_PACKAGE_BUILD
257 #undef CREATE_TRACE_POINTS
259 struct trace_syscall_entry
{
261 const struct lttng_event_desc
*desc
;
262 const struct lttng_event_field
*fields
;
266 #define CREATE_SYSCALL_TABLE
273 #undef TRACE_SYSCALL_TABLE
274 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
276 .func = __event_probe__syscall_entry_##_template, \
277 .nrargs = (_nrargs), \
278 .fields = __event_fields___syscall_entry_##_template, \
279 .desc = &__event_desc___syscall_entry_##_name, \
282 /* Syscall enter tracing table */
283 static const struct trace_syscall_entry sc_table
[] = {
284 #include "instrumentation/syscalls/headers/syscalls_integers.h"
285 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
288 #undef TRACE_SYSCALL_TABLE
289 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
291 .func = __event_probe__compat_syscall_entry_##_template, \
292 .nrargs = (_nrargs), \
293 .fields = __event_fields___compat_syscall_entry_##_template, \
294 .desc = &__event_desc___compat_syscall_entry_##_name, \
297 /* Compat syscall enter table */
298 const struct trace_syscall_entry compat_sc_table
[] = {
299 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
300 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
308 #define sc_exit(...) __VA_ARGS__
310 #undef TRACE_SYSCALL_TABLE
311 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
313 .func = __event_probe__syscall_exit_##_template, \
314 .nrargs = (_nrargs), \
315 .fields = __event_fields___syscall_exit_##_template, \
316 .desc = &__event_desc___syscall_exit_##_name, \
319 /* Syscall exit table */
320 static const struct trace_syscall_entry sc_exit_table
[] = {
321 #include "instrumentation/syscalls/headers/syscalls_integers.h"
322 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
325 #undef TRACE_SYSCALL_TABLE
326 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
328 .func = __event_probe__compat_syscall_exit_##_template, \
329 .nrargs = (_nrargs), \
330 .fields = __event_fields___compat_syscall_exit_##_template, \
331 .desc = &__event_desc___compat_syscall_exit_##_name, \
334 /* Compat syscall exit table */
335 const struct trace_syscall_entry compat_sc_exit_table
[] = {
336 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
337 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
342 #undef CREATE_SYSCALL_TABLE
344 struct lttng_syscall_filter
{
345 DECLARE_BITMAP(sc
, NR_syscalls
);
346 DECLARE_BITMAP(sc_compat
, NR_compat_syscalls
);
349 static void syscall_entry_unknown(struct lttng_event
*event
,
350 struct pt_regs
*regs
, unsigned int id
)
352 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
354 syscall_get_arguments(current
, regs
, 0, UNKNOWN_SYSCALL_NRARGS
, args
);
355 if (unlikely(is_compat_task()))
356 __event_probe__compat_syscall_entry_unknown(event
, id
, args
);
358 __event_probe__syscall_entry_unknown(event
, id
, args
);
361 void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
)
363 struct lttng_channel
*chan
= __data
;
364 struct lttng_event
*event
, *unknown_event
;
365 const struct trace_syscall_entry
*table
, *entry
;
368 if (unlikely(is_compat_task())) {
369 struct lttng_syscall_filter
*filter
;
371 filter
= rcu_dereference(chan
->sc_filter
);
373 if (id
< 0 || id
>= NR_compat_syscalls
374 || !test_bit(id
, filter
->sc_compat
)) {
375 /* System call filtered out. */
379 table
= compat_sc_table
;
380 table_len
= ARRAY_SIZE(compat_sc_table
);
381 unknown_event
= chan
->sc_compat_unknown
;
383 struct lttng_syscall_filter
*filter
;
385 filter
= rcu_dereference(chan
->sc_filter
);
387 if (id
< 0 || id
>= NR_syscalls
388 || !test_bit(id
, filter
->sc
)) {
389 /* System call filtered out. */
394 table_len
= ARRAY_SIZE(sc_table
);
395 unknown_event
= chan
->sc_unknown
;
397 if (unlikely(id
< 0 || id
>= table_len
)) {
398 syscall_entry_unknown(unknown_event
, regs
, id
);
401 if (unlikely(is_compat_task()))
402 event
= chan
->compat_sc_table
[id
];
404 event
= chan
->sc_table
[id
];
405 if (unlikely(!event
)) {
406 syscall_entry_unknown(unknown_event
, regs
, id
);
410 WARN_ON_ONCE(!entry
);
412 switch (entry
->nrargs
) {
415 void (*fptr
)(void *__data
) = entry
->func
;
422 void (*fptr
)(void *__data
, unsigned long arg0
) = entry
->func
;
423 unsigned long args
[1];
425 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
426 fptr(event
, args
[0]);
431 void (*fptr
)(void *__data
,
433 unsigned long arg1
) = entry
->func
;
434 unsigned long args
[2];
436 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
437 fptr(event
, args
[0], args
[1]);
442 void (*fptr
)(void *__data
,
445 unsigned long arg2
) = entry
->func
;
446 unsigned long args
[3];
448 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
449 fptr(event
, args
[0], args
[1], args
[2]);
454 void (*fptr
)(void *__data
,
458 unsigned long arg3
) = entry
->func
;
459 unsigned long args
[4];
461 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
462 fptr(event
, args
[0], args
[1], args
[2], args
[3]);
467 void (*fptr
)(void *__data
,
472 unsigned long arg4
) = entry
->func
;
473 unsigned long args
[5];
475 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
476 fptr(event
, args
[0], args
[1], args
[2], args
[3], args
[4]);
481 void (*fptr
)(void *__data
,
487 unsigned long arg5
) = entry
->func
;
488 unsigned long args
[6];
490 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
491 fptr(event
, args
[0], args
[1], args
[2],
492 args
[3], args
[4], args
[5]);
500 static void syscall_exit_unknown(struct lttng_event
*event
,
501 struct pt_regs
*regs
, int id
, long ret
)
503 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
505 syscall_get_arguments(current
, regs
, 0, UNKNOWN_SYSCALL_NRARGS
, args
);
506 if (unlikely(is_compat_task()))
507 __event_probe__compat_syscall_exit_unknown(event
, id
, ret
,
510 __event_probe__syscall_exit_unknown(event
, id
, ret
, args
);
513 void syscall_exit_probe(void *__data
, struct pt_regs
*regs
, long ret
)
515 struct lttng_channel
*chan
= __data
;
516 struct lttng_event
*event
, *unknown_event
;
517 const struct trace_syscall_entry
*table
, *entry
;
521 id
= syscall_get_nr(current
, regs
);
522 if (unlikely(is_compat_task())) {
523 struct lttng_syscall_filter
*filter
;
525 filter
= rcu_dereference(chan
->sc_filter
);
527 if (id
< 0 || id
>= NR_compat_syscalls
528 || !test_bit(id
, filter
->sc_compat
)) {
529 /* System call filtered out. */
533 table
= compat_sc_exit_table
;
534 table_len
= ARRAY_SIZE(compat_sc_exit_table
);
535 unknown_event
= chan
->compat_sc_exit_unknown
;
537 struct lttng_syscall_filter
*filter
;
539 filter
= rcu_dereference(chan
->sc_filter
);
541 if (id
< 0 || id
>= NR_syscalls
542 || !test_bit(id
, filter
->sc
)) {
543 /* System call filtered out. */
547 table
= sc_exit_table
;
548 table_len
= ARRAY_SIZE(sc_exit_table
);
549 unknown_event
= chan
->sc_exit_unknown
;
551 if (unlikely(id
< 0 || id
>= table_len
)) {
552 syscall_exit_unknown(unknown_event
, regs
, id
, ret
);
555 if (unlikely(is_compat_task()))
556 event
= chan
->compat_sc_exit_table
[id
];
558 event
= chan
->sc_exit_table
[id
];
559 if (unlikely(!event
)) {
560 syscall_exit_unknown(unknown_event
, regs
, id
, ret
);
564 WARN_ON_ONCE(!entry
);
566 switch (entry
->nrargs
) {
569 void (*fptr
)(void *__data
, long ret
) = entry
->func
;
576 void (*fptr
)(void *__data
,
578 unsigned long arg0
) = entry
->func
;
579 unsigned long args
[1];
581 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
582 fptr(event
, ret
, args
[0]);
587 void (*fptr
)(void *__data
,
590 unsigned long arg1
) = entry
->func
;
591 unsigned long args
[2];
593 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
594 fptr(event
, ret
, args
[0], args
[1]);
599 void (*fptr
)(void *__data
,
603 unsigned long arg2
) = entry
->func
;
604 unsigned long args
[3];
606 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
607 fptr(event
, ret
, args
[0], args
[1], args
[2]);
612 void (*fptr
)(void *__data
,
617 unsigned long arg3
) = entry
->func
;
618 unsigned long args
[4];
620 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
621 fptr(event
, ret
, args
[0], args
[1], args
[2], args
[3]);
626 void (*fptr
)(void *__data
,
632 unsigned long arg4
) = entry
->func
;
633 unsigned long args
[5];
635 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
636 fptr(event
, ret
, args
[0], args
[1], args
[2], args
[3], args
[4]);
641 void (*fptr
)(void *__data
,
648 unsigned long arg5
) = entry
->func
;
649 unsigned long args
[6];
651 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
652 fptr(event
, ret
, args
[0], args
[1], args
[2],
653 args
[3], args
[4], args
[5]);
662 * noinline to diminish caller stack size.
663 * Should be called with sessions lock held.
666 int fill_table(const struct trace_syscall_entry
*table
, size_t table_len
,
667 struct lttng_event
**chan_table
, struct lttng_channel
*chan
,
668 void *filter
, enum sc_type type
)
670 const struct lttng_event_desc
*desc
;
673 /* Allocate events for each syscall, insert into table */
674 for (i
= 0; i
< table_len
; i
++) {
675 struct lttng_kernel_event ev
;
676 desc
= table
[i
].desc
;
679 /* Unknown syscall */
683 * Skip those already populated by previous failed
684 * register for this channel.
688 memset(&ev
, 0, sizeof(ev
));
691 strncpy(ev
.name
, SYSCALL_ENTRY_STR
,
692 LTTNG_KERNEL_SYM_NAME_LEN
);
695 strncpy(ev
.name
, SYSCALL_EXIT_STR
,
696 LTTNG_KERNEL_SYM_NAME_LEN
);
698 case SC_TYPE_COMPAT_ENTRY
:
699 strncpy(ev
.name
, COMPAT_SYSCALL_ENTRY_STR
,
700 LTTNG_KERNEL_SYM_NAME_LEN
);
702 case SC_TYPE_COMPAT_EXIT
:
703 strncpy(ev
.name
, COMPAT_SYSCALL_EXIT_STR
,
704 LTTNG_KERNEL_SYM_NAME_LEN
);
710 strncat(ev
.name
, desc
->name
,
711 LTTNG_KERNEL_SYM_NAME_LEN
- strlen(ev
.name
) - 1);
712 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
713 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
714 chan_table
[i
] = _lttng_event_create(chan
, &ev
, filter
,
715 desc
, ev
.instrumentation
);
716 WARN_ON_ONCE(!chan_table
[i
]);
717 if (IS_ERR(chan_table
[i
])) {
719 * If something goes wrong in event registration
720 * after the first one, we have no choice but to
721 * leave the previous events in there, until
722 * deleted by session teardown.
724 return PTR_ERR(chan_table
[i
]);
731 * Should be called with sessions lock held.
733 int lttng_syscalls_register(struct lttng_channel
*chan
, void *filter
)
735 struct lttng_kernel_event ev
;
738 wrapper_vmalloc_sync_all();
740 if (!chan
->sc_table
) {
741 /* create syscall table mapping syscall to events */
742 chan
->sc_table
= kzalloc(sizeof(struct lttng_event
*)
743 * ARRAY_SIZE(sc_table
), GFP_KERNEL
);
747 if (!chan
->sc_exit_table
) {
748 /* create syscall table mapping syscall to events */
749 chan
->sc_exit_table
= kzalloc(sizeof(struct lttng_event
*)
750 * ARRAY_SIZE(sc_exit_table
), GFP_KERNEL
);
751 if (!chan
->sc_exit_table
)
757 if (!chan
->compat_sc_table
) {
758 /* create syscall table mapping compat syscall to events */
759 chan
->compat_sc_table
= kzalloc(sizeof(struct lttng_event
*)
760 * ARRAY_SIZE(compat_sc_table
), GFP_KERNEL
);
761 if (!chan
->compat_sc_table
)
765 if (!chan
->compat_sc_exit_table
) {
766 /* create syscall table mapping compat syscall to events */
767 chan
->compat_sc_exit_table
= kzalloc(sizeof(struct lttng_event
*)
768 * ARRAY_SIZE(compat_sc_exit_table
), GFP_KERNEL
);
769 if (!chan
->compat_sc_exit_table
)
773 if (!chan
->sc_unknown
) {
774 const struct lttng_event_desc
*desc
=
775 &__event_desc___syscall_entry_unknown
;
777 memset(&ev
, 0, sizeof(ev
));
778 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
779 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
780 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
781 chan
->sc_unknown
= _lttng_event_create(chan
, &ev
, filter
,
784 WARN_ON_ONCE(!chan
->sc_unknown
);
785 if (IS_ERR(chan
->sc_unknown
)) {
786 return PTR_ERR(chan
->sc_unknown
);
790 if (!chan
->sc_compat_unknown
) {
791 const struct lttng_event_desc
*desc
=
792 &__event_desc___compat_syscall_entry_unknown
;
794 memset(&ev
, 0, sizeof(ev
));
795 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
796 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
797 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
798 chan
->sc_compat_unknown
= _lttng_event_create(chan
, &ev
, filter
,
801 WARN_ON_ONCE(!chan
->sc_unknown
);
802 if (IS_ERR(chan
->sc_compat_unknown
)) {
803 return PTR_ERR(chan
->sc_compat_unknown
);
807 if (!chan
->compat_sc_exit_unknown
) {
808 const struct lttng_event_desc
*desc
=
809 &__event_desc___compat_syscall_exit_unknown
;
811 memset(&ev
, 0, sizeof(ev
));
812 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
813 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
814 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
815 chan
->compat_sc_exit_unknown
= _lttng_event_create(chan
, &ev
,
818 WARN_ON_ONCE(!chan
->compat_sc_exit_unknown
);
819 if (IS_ERR(chan
->compat_sc_exit_unknown
)) {
820 return PTR_ERR(chan
->compat_sc_exit_unknown
);
824 if (!chan
->sc_exit_unknown
) {
825 const struct lttng_event_desc
*desc
=
826 &__event_desc___syscall_exit_unknown
;
828 memset(&ev
, 0, sizeof(ev
));
829 strncpy(ev
.name
, desc
->name
, LTTNG_KERNEL_SYM_NAME_LEN
);
830 ev
.name
[LTTNG_KERNEL_SYM_NAME_LEN
- 1] = '\0';
831 ev
.instrumentation
= LTTNG_KERNEL_SYSCALL
;
832 chan
->sc_exit_unknown
= _lttng_event_create(chan
, &ev
, filter
,
833 desc
, ev
.instrumentation
);
834 WARN_ON_ONCE(!chan
->sc_exit_unknown
);
835 if (IS_ERR(chan
->sc_exit_unknown
)) {
836 return PTR_ERR(chan
->sc_exit_unknown
);
840 ret
= fill_table(sc_table
, ARRAY_SIZE(sc_table
),
841 chan
->sc_table
, chan
, filter
, SC_TYPE_ENTRY
);
844 ret
= fill_table(sc_exit_table
, ARRAY_SIZE(sc_exit_table
),
845 chan
->sc_exit_table
, chan
, filter
, SC_TYPE_EXIT
);
850 ret
= fill_table(compat_sc_table
, ARRAY_SIZE(compat_sc_table
),
851 chan
->compat_sc_table
, chan
, filter
,
852 SC_TYPE_COMPAT_ENTRY
);
855 ret
= fill_table(compat_sc_exit_table
, ARRAY_SIZE(compat_sc_exit_table
),
856 chan
->compat_sc_exit_table
, chan
, filter
,
857 SC_TYPE_COMPAT_EXIT
);
861 if (!chan
->sys_enter_registered
) {
862 ret
= lttng_wrapper_tracepoint_probe_register("sys_enter",
863 (void *) syscall_entry_probe
, chan
);
866 chan
->sys_enter_registered
= 1;
869 * We change the name of sys_exit tracepoint due to namespace
870 * conflict with sys_exit syscall entry.
872 if (!chan
->sys_exit_registered
) {
873 ret
= lttng_wrapper_tracepoint_probe_register("sys_exit",
874 (void *) syscall_exit_probe
, chan
);
876 WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter",
877 (void *) syscall_entry_probe
, chan
));
880 chan
->sys_exit_registered
= 1;
886 * Only called at session destruction.
888 int lttng_syscalls_unregister(struct lttng_channel
*chan
)
894 if (chan
->sys_enter_registered
) {
895 ret
= lttng_wrapper_tracepoint_probe_unregister("sys_exit",
896 (void *) syscall_exit_probe
, chan
);
899 chan
->sys_enter_registered
= 0;
901 if (chan
->sys_exit_registered
) {
902 ret
= lttng_wrapper_tracepoint_probe_unregister("sys_enter",
903 (void *) syscall_entry_probe
, chan
);
906 chan
->sys_exit_registered
= 0;
908 /* lttng_event destroy will be performed by lttng_session_destroy() */
909 kfree(chan
->sc_table
);
910 kfree(chan
->sc_exit_table
);
912 kfree(chan
->compat_sc_table
);
913 kfree(chan
->compat_sc_exit_table
);
915 kfree(chan
->sc_filter
);
920 int get_syscall_nr(const char *syscall_name
)
925 for (i
= 0; i
< ARRAY_SIZE(sc_table
); i
++) {
926 const struct trace_syscall_entry
*entry
;
929 entry
= &sc_table
[i
];
932 it_name
= entry
->desc
->name
;
933 it_name
+= strlen(SYSCALL_ENTRY_STR
);
934 if (!strcmp(syscall_name
, it_name
)) {
943 int get_compat_syscall_nr(const char *syscall_name
)
948 for (i
= 0; i
< ARRAY_SIZE(compat_sc_table
); i
++) {
949 const struct trace_syscall_entry
*entry
;
952 entry
= &compat_sc_table
[i
];
955 it_name
= entry
->desc
->name
;
956 it_name
+= strlen(COMPAT_SYSCALL_ENTRY_STR
);
957 if (!strcmp(syscall_name
, it_name
)) {
966 uint32_t get_sc_tables_len(void)
968 return ARRAY_SIZE(sc_table
) + ARRAY_SIZE(compat_sc_table
);
971 int lttng_syscall_filter_enable(struct lttng_channel
*chan
,
974 int syscall_nr
, compat_syscall_nr
, ret
;
975 struct lttng_syscall_filter
*filter
;
977 WARN_ON_ONCE(!chan
->sc_table
);
980 /* Enable all system calls by removing filter */
981 if (chan
->sc_filter
) {
982 filter
= chan
->sc_filter
;
983 rcu_assign_pointer(chan
->sc_filter
, NULL
);
987 chan
->syscall_all
= 1;
991 if (!chan
->sc_filter
) {
992 if (chan
->syscall_all
) {
994 * All syscalls are already enabled.
998 filter
= kzalloc(sizeof(struct lttng_syscall_filter
),
1003 filter
= chan
->sc_filter
;
1005 syscall_nr
= get_syscall_nr(name
);
1006 compat_syscall_nr
= get_compat_syscall_nr(name
);
1007 if (syscall_nr
< 0 && compat_syscall_nr
< 0) {
1011 if (syscall_nr
>= 0) {
1012 if (test_bit(syscall_nr
, filter
->sc
)) {
1016 bitmap_set(filter
->sc
, syscall_nr
, 1);
1018 if (compat_syscall_nr
>= 0) {
1019 if (test_bit(compat_syscall_nr
, filter
->sc_compat
)) {
1023 bitmap_set(filter
->sc_compat
, compat_syscall_nr
, 1);
1025 if (!chan
->sc_filter
)
1026 rcu_assign_pointer(chan
->sc_filter
, filter
);
1030 if (!chan
->sc_filter
)
1035 int lttng_syscall_filter_disable(struct lttng_channel
*chan
,
1038 int syscall_nr
, compat_syscall_nr
, ret
;
1039 struct lttng_syscall_filter
*filter
;
1041 WARN_ON_ONCE(!chan
->sc_table
);
1043 if (!chan
->sc_filter
) {
1044 if (!chan
->syscall_all
)
1046 filter
= kzalloc(sizeof(struct lttng_syscall_filter
),
1050 /* Trace all system calls, then apply disable. */
1051 bitmap_set(filter
->sc
, 0, NR_syscalls
);
1052 bitmap_set(filter
->sc_compat
, 0, NR_compat_syscalls
);
1054 filter
= chan
->sc_filter
;
1058 /* Fail if all syscalls are already disabled. */
1059 if (bitmap_empty(filter
->sc
, NR_syscalls
)
1060 && bitmap_empty(filter
->sc_compat
,
1061 NR_compat_syscalls
)) {
1066 /* Disable all system calls */
1067 bitmap_clear(filter
->sc
, 0, NR_syscalls
);
1068 bitmap_clear(filter
->sc_compat
, 0, NR_compat_syscalls
);
1071 syscall_nr
= get_syscall_nr(name
);
1072 compat_syscall_nr
= get_compat_syscall_nr(name
);
1073 if (syscall_nr
< 0 && compat_syscall_nr
< 0) {
1077 if (syscall_nr
>= 0) {
1078 if (!test_bit(syscall_nr
, filter
->sc
)) {
1082 bitmap_clear(filter
->sc
, syscall_nr
, 1);
1084 if (compat_syscall_nr
>= 0) {
1085 if (!test_bit(compat_syscall_nr
, filter
->sc_compat
)) {
1089 bitmap_clear(filter
->sc_compat
, compat_syscall_nr
, 1);
1092 if (!chan
->sc_filter
)
1093 rcu_assign_pointer(chan
->sc_filter
, filter
);
1094 chan
->syscall_all
= 0;
1098 if (!chan
->sc_filter
)
1104 const struct trace_syscall_entry
*syscall_list_get_entry(loff_t
*pos
)
1106 const struct trace_syscall_entry
*entry
;
1109 for (entry
= sc_table
;
1110 entry
< sc_table
+ ARRAY_SIZE(sc_table
);
1115 for (entry
= compat_sc_table
;
1116 entry
< compat_sc_table
+ ARRAY_SIZE(compat_sc_table
);
1126 void *syscall_list_start(struct seq_file
*m
, loff_t
*pos
)
1128 return (void *) syscall_list_get_entry(pos
);
1132 void *syscall_list_next(struct seq_file
*m
, void *p
, loff_t
*ppos
)
1135 return (void *) syscall_list_get_entry(ppos
);
1139 void syscall_list_stop(struct seq_file
*m
, void *p
)
1144 int get_sc_table(const struct trace_syscall_entry
*entry
,
1145 const struct trace_syscall_entry
**table
,
1146 unsigned int *bitness
)
1148 if (entry
>= sc_table
&& entry
< sc_table
+ ARRAY_SIZE(sc_table
)) {
1150 *bitness
= BITS_PER_LONG
;
1155 if (!(entry
>= compat_sc_table
1156 && entry
< compat_sc_table
+ ARRAY_SIZE(compat_sc_table
))) {
1162 *table
= compat_sc_table
;
1167 int syscall_list_show(struct seq_file
*m
, void *p
)
1169 const struct trace_syscall_entry
*table
, *entry
= p
;
1170 unsigned int bitness
;
1171 unsigned long index
;
1175 ret
= get_sc_table(entry
, &table
, &bitness
);
1180 if (table
== sc_table
) {
1181 index
= entry
- table
;
1182 name
= &entry
->desc
->name
[strlen(SYSCALL_ENTRY_STR
)];
1184 index
= (entry
- table
) + ARRAY_SIZE(sc_table
);
1185 name
= &entry
->desc
->name
[strlen(COMPAT_SYSCALL_ENTRY_STR
)];
1187 seq_printf(m
, "syscall { index = %lu; name = %s; bitness = %u; };\n",
1188 index
, name
, bitness
);
1193 const struct seq_operations lttng_syscall_list_seq_ops
= {
1194 .start
= syscall_list_start
,
1195 .next
= syscall_list_next
,
1196 .stop
= syscall_list_stop
,
1197 .show
= syscall_list_show
,
1201 int lttng_syscall_list_open(struct inode
*inode
, struct file
*file
)
1203 return seq_open(file
, <tng_syscall_list_seq_ops
);
1206 const struct file_operations lttng_syscall_list_fops
= {
1207 .owner
= THIS_MODULE
,
1208 .open
= lttng_syscall_list_open
,
1210 .llseek
= seq_lseek
,
1211 .release
= seq_release
,
1214 long lttng_channel_syscall_mask(struct lttng_channel
*channel
,
1215 struct lttng_kernel_syscall_mask __user
*usyscall_mask
)
1217 uint32_t len
, sc_tables_len
, bitmask_len
;
1220 struct lttng_syscall_filter
*filter
;
1222 ret
= get_user(len
, &usyscall_mask
->len
);
1225 sc_tables_len
= get_sc_tables_len();
1226 bitmask_len
= ALIGN(sc_tables_len
, 8) >> 3;
1227 if (len
< sc_tables_len
) {
1228 return put_user(sc_tables_len
, &usyscall_mask
->len
);
1230 /* Array is large enough, we can copy array to user-space. */
1231 tmp_mask
= kzalloc(bitmask_len
, GFP_KERNEL
);
1234 filter
= channel
->sc_filter
;
1236 for (bit
= 0; bit
< ARRAY_SIZE(sc_table
); bit
++) {
1239 if (channel
->sc_table
) {
1241 state
= test_bit(bit
, filter
->sc
);
1247 bt_bitfield_write_be(tmp_mask
, char, bit
, 1, state
);
1249 for (; bit
< sc_tables_len
; bit
++) {
1252 if (channel
->compat_sc_table
) {
1254 state
= test_bit(bit
- ARRAY_SIZE(sc_table
),
1261 bt_bitfield_write_be(tmp_mask
, char, bit
, 1, state
);
1263 if (copy_to_user(usyscall_mask
->mask
, tmp_mask
, bitmask_len
))
1269 int lttng_abi_syscall_list(void)
1271 struct file
*syscall_list_file
;
1274 file_fd
= lttng_get_unused_fd();
1280 syscall_list_file
= anon_inode_getfile("[lttng_syscall_list]",
1281 <tng_syscall_list_fops
,
1283 if (IS_ERR(syscall_list_file
)) {
1284 ret
= PTR_ERR(syscall_list_file
);
1287 ret
= lttng_syscall_list_fops
.open(NULL
, syscall_list_file
);
1290 fd_install(file_fd
, syscall_list_file
);
1298 fput(syscall_list_file
);
1300 put_unused_fd(file_fd
);