4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Dual LGPL v2.1/GPL v2 license.
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <asm/ptrace.h>
14 #include <asm/syscall.h>
16 #include "ltt-events.h"
18 static void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
);
21 * Take care of NOARGS not supported by mainline.
23 #define DECLARE_EVENT_CLASS_NOARGS(name, tstruct, assign, print)
24 #define DEFINE_EVENT_NOARGS(template, name)
25 #define TRACE_EVENT_NOARGS(name, struct, assign, print)
28 * Create LTTng tracepoint probes.
30 #define LTTNG_PACKAGE_BUILD
31 #define CREATE_TRACE_POINTS
33 /* Hijack probe callback for system calls */
34 #define TP_PROBE_CB(_template) &syscall_entry_probe
35 #define TP_MODULE_OVERRIDE
37 #define TRACE_INCLUDE_PATH ../instrumentation/syscalls/headers
38 #include "instrumentation/syscalls/headers/syscalls_integers.h"
39 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
40 #include "instrumentation/syscalls/headers/syscalls_unknown.h"
42 #undef TP_MODULE_OVERRIDE
44 #undef LTTNG_PACKAGE_BUILD
45 #undef CREATE_TRACE_POINTS
47 struct trace_syscall_entry
{
49 const struct lttng_event_desc
*desc
;
50 const struct lttng_event_field
*fields
;
54 #define CREATE_SYSCALL_TABLE
56 #undef TRACE_SYSCALL_TABLE
57 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
59 .func = __event_probe__##_template, \
60 .nrargs = (_nrargs), \
61 .fields = __event_fields___##_template, \
62 .desc = &__event_desc___##_name, \
65 static struct trace_syscall_entry sc_table
[] = {
66 #include "instrumentation/syscalls/headers/syscalls_integers.h"
67 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
70 static int sc_table_filled
;
72 #undef CREATE_SYSCALL_TABLE
74 static void syscall_entry_unknown(struct ltt_channel
*chan
,
75 struct pt_regs
*regs
, unsigned int id
)
77 unsigned long args
[UNKNOWN_SYSCALL_NRARGS
];
78 struct ltt_event
*event
;
80 event
= chan
->sc_unknown
;
81 syscall_get_arguments(current
, regs
, 0, UNKNOWN_SYSCALL_NRARGS
, args
);
82 __event_probe__sys_unknown(event
, id
, args
);
85 static void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
)
87 struct trace_syscall_entry
*entry
;
88 struct ltt_channel
*chan
= __data
;
89 struct ltt_event
*event
;
91 if (unlikely(id
>= ARRAY_SIZE(sc_table
))) {
92 syscall_entry_unknown(chan
, regs
, id
);
95 event
= chan
->sc_table
[id
];
96 if (unlikely(!event
)) {
97 syscall_entry_unknown(chan
, regs
, id
);
100 entry
= &sc_table
[id
];
101 WARN_ON_ONCE(!entry
);
103 switch (entry
->nrargs
) {
106 void (*fptr
)(void *__data
) = entry
->func
;
113 void (*fptr
)(void *__data
, unsigned long arg0
) = entry
->func
;
114 unsigned long args
[1];
116 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
117 fptr(event
, args
[0]);
122 void (*fptr
)(void *__data
,
124 unsigned long arg1
) = entry
->func
;
125 unsigned long args
[2];
127 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
128 fptr(event
, args
[0], args
[1]);
133 void (*fptr
)(void *__data
,
136 unsigned long arg2
) = entry
->func
;
137 unsigned long args
[3];
139 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
140 fptr(event
, args
[0], args
[1], args
[2]);
145 void (*fptr
)(void *__data
,
149 unsigned long arg3
) = entry
->func
;
150 unsigned long args
[4];
152 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
153 fptr(event
, args
[0], args
[1], args
[2], args
[3]);
158 void (*fptr
)(void *__data
,
163 unsigned long arg4
) = entry
->func
;
164 unsigned long args
[5];
166 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
167 fptr(event
, args
[0], args
[1], args
[2], args
[3], args
[4]);
172 void (*fptr
)(void *__data
,
178 unsigned long arg5
) = entry
->func
;
179 unsigned long args
[6];
181 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
182 fptr(event
, args
[0], args
[1], args
[2],
183 args
[3], args
[4], args
[5]);
191 int lttng_syscalls_register(struct ltt_channel
*chan
, void *filter
)
196 wrapper_vmalloc_sync_all();
198 if (!chan
->sc_table
) {
199 /* create syscall table mapping syscall to events */
200 chan
->sc_table
= kzalloc(sizeof(struct ltt_event
*)
201 * ARRAY_SIZE(sc_table
), GFP_KERNEL
);
206 if (!chan
->sc_unknown
) {
207 struct lttng_kernel_event ev
;
209 const struct lttng_event_desc
*desc
=
210 &__event_desc___sys_unknown
;
211 memset(&ev
, 0, sizeof(ev
));
212 strncpy(ev
.name
, desc
->name
, LTTNG_SYM_NAME_LEN
);
213 ev
.name
[LTTNG_SYM_NAME_LEN
- 1] = '\0';
214 ev
.instrumentation
= LTTNG_KERNEL_NOOP
;
215 chan
->sc_unknown
= ltt_event_create(chan
, &ev
, filter
,
217 if (!chan
->sc_unknown
) {
222 /* Allocate events for each syscall, insert into table */
223 for (i
= 0; i
< ARRAY_SIZE(sc_table
); i
++) {
224 struct lttng_kernel_event ev
;
225 const struct lttng_event_desc
*desc
= sc_table
[i
].desc
;
228 /* Unknown syscall */
232 * Skip those already populated by previous failed
233 * register for this channel.
235 if (chan
->sc_table
[i
])
237 memset(&ev
, 0, sizeof(ev
));
238 strncpy(ev
.name
, desc
->name
, LTTNG_SYM_NAME_LEN
);
239 ev
.name
[LTTNG_SYM_NAME_LEN
- 1] = '\0';
240 ev
.instrumentation
= LTTNG_KERNEL_NOOP
;
241 chan
->sc_table
[i
] = ltt_event_create(chan
, &ev
, filter
,
243 if (!chan
->sc_table
[i
]) {
245 * If something goes wrong in event registration
246 * after the first one, we have no choice but to
247 * leave the previous events in there, until
248 * deleted by session teardown.
253 ret
= tracepoint_probe_register("sys_enter",
254 (void *) syscall_entry_probe
, chan
);
258 * We change the name of sys_exit tracepoint due to namespace
259 * conflict with sys_exit syscall entry.
261 ret
= tracepoint_probe_register("sys_exit",
262 (void *) __event_probe__exit_syscall
, chan
);
264 WARN_ON_ONCE(tracepoint_probe_unregister("sys_enter",
265 (void *) syscall_entry_probe
, chan
));
271 * Only called at session destruction.
273 int lttng_syscalls_unregister(struct ltt_channel
*chan
)
279 ret
= tracepoint_probe_unregister("sys_exit",
280 (void *) __event_probe__exit_syscall
, chan
);
283 ret
= tracepoint_probe_unregister("sys_enter",
284 (void *) syscall_entry_probe
, chan
);
287 /* ltt_event destroy will be performed by ltt_session_destroy() */
288 kfree(chan
->sc_table
);