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
39 #include "instrumentation/syscalls/headers/syscalls.h"
41 #undef TP_MODULE_OVERRIDE
43 #undef LTTNG_PACKAGE_BUILD
44 #undef CREATE_TRACE_POINTS
46 struct trace_syscall_entry
{
48 const struct lttng_event_desc
*desc
;
49 const struct lttng_event_field
*fields
;
53 static int sc_table_desc_filled
;
55 #define CREATE_SYSCALL_TABLE
57 #undef TRACE_SYSCALL_TABLE
58 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
60 .func = __event_probe__##_template, \
61 .nrargs = (_nrargs), \
62 .fields = __event_fields___##_template, \
63 .desc = &__event_desc___##_name, \
66 static struct trace_syscall_entry sc_table
[] = {
67 #include "instrumentation/syscalls/headers/syscalls.h"
70 #undef CREATE_SYSCALL_TABLE
72 static void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
)
74 struct trace_syscall_entry
*entry
;
75 struct ltt_channel
*chan
= __data
;
76 struct ltt_event
*event
;
78 if (unlikely(id
>= ARRAY_SIZE(sc_table
)))
80 entry
= &sc_table
[id
];
81 if (unlikely(!entry
->func
))
83 event
= chan
->sc_table
[id
];
86 switch (entry
->nrargs
) {
89 void (*fptr
)(void *__data
) = entry
->func
;
96 void (*fptr
)(void *__data
, unsigned long arg0
) = entry
->func
;
97 unsigned long args
[1];
99 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
100 fptr(event
, args
[0]);
105 void (*fptr
)(void *__data
,
107 unsigned long arg1
) = entry
->func
;
108 unsigned long args
[2];
110 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
111 fptr(event
, args
[0], args
[1]);
116 void (*fptr
)(void *__data
,
119 unsigned long arg2
) = entry
->func
;
120 unsigned long args
[3];
122 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
123 fptr(event
, args
[0], args
[1], args
[2]);
128 void (*fptr
)(void *__data
,
132 unsigned long arg3
) = entry
->func
;
133 unsigned long args
[4];
135 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
136 fptr(event
, args
[0], args
[1], args
[2], args
[3]);
141 void (*fptr
)(void *__data
,
146 unsigned long arg4
) = entry
->func
;
147 unsigned long args
[5];
149 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
150 fptr(event
, args
[0], args
[1], args
[2], args
[3], args
[4]);
155 void (*fptr
)(void *__data
,
161 unsigned long arg5
) = entry
->func
;
162 unsigned long args
[6];
164 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
165 fptr(event
, args
[0], args
[1], args
[2],
166 args
[3], args
[4], args
[5]);
174 int lttng_syscalls_register(struct ltt_channel
*chan
, void *filter
)
179 wrapper_vmalloc_sync_all();
181 if (!chan
->sc_table
) {
182 /* create syscall table mapping syscall to events */
183 chan
->sc_table
= kzalloc(sizeof(struct ltt_event
*)
184 * ARRAY_SIZE(sc_table
), GFP_KERNEL
);
189 /* Allocate events for each syscall, insert into table */
190 for (i
= 0; i
< ARRAY_SIZE(sc_table
); i
++) {
191 struct lttng_kernel_event ev
;
192 const struct lttng_event_desc
*desc
= sc_table
[i
].desc
;
197 * Skip those already populated by previous failed
198 * register for this channel.
200 if (chan
->sc_table
[i
])
202 memset(&ev
, 0, sizeof(ev
));
203 strncpy(ev
.name
, desc
->name
, LTTNG_SYM_NAME_LEN
);
204 ev
.name
[LTTNG_SYM_NAME_LEN
- 1] = '\0';
205 ev
.instrumentation
= LTTNG_KERNEL_NOOP
;
206 chan
->sc_table
[i
] = ltt_event_create(chan
, &ev
, filter
,
208 if (!chan
->sc_table
[i
]) {
210 * If something goes wrong in event registration
211 * after the first one, we have no choice but to
212 * leave the previous events in there, until
213 * deleted by session teardown.
218 ret
= tracepoint_probe_register("sys_enter",
219 (void *) syscall_entry_probe
, chan
);
224 * Only called at session destruction.
226 int lttng_syscalls_unregister(struct ltt_channel
*chan
)
232 ret
= tracepoint_probe_unregister("sys_enter",
233 (void *) syscall_entry_probe
, chan
);
236 /* ltt_event destroy will be performed by ltt_session_destroy() */
237 kfree(chan
->sc_table
);