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"
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 #define CREATE_SYSCALL_TABLE
55 #undef TRACE_SYSCALL_TABLE
56 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
58 .func = __event_probe__##_template, \
59 .nrargs = (_nrargs), \
60 .fields = __event_fields___##_template, \
61 .desc = &__event_desc___##_name, \
64 static struct trace_syscall_entry sc_table
[] = {
65 #include "instrumentation/syscalls/headers/syscalls_integers.h"
66 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
69 #undef CREATE_SYSCALL_TABLE
71 static void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
)
73 struct trace_syscall_entry
*entry
;
74 struct ltt_channel
*chan
= __data
;
75 struct ltt_event
*event
;
77 if (unlikely(id
>= ARRAY_SIZE(sc_table
)))
79 entry
= &sc_table
[id
];
80 if (unlikely(!entry
->func
))
82 event
= chan
->sc_table
[id
];
85 switch (entry
->nrargs
) {
88 void (*fptr
)(void *__data
) = entry
->func
;
95 void (*fptr
)(void *__data
, unsigned long arg0
) = entry
->func
;
96 unsigned long args
[1];
98 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
104 void (*fptr
)(void *__data
,
106 unsigned long arg1
) = entry
->func
;
107 unsigned long args
[2];
109 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
110 fptr(event
, args
[0], args
[1]);
115 void (*fptr
)(void *__data
,
118 unsigned long arg2
) = entry
->func
;
119 unsigned long args
[3];
121 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
122 fptr(event
, args
[0], args
[1], args
[2]);
127 void (*fptr
)(void *__data
,
131 unsigned long arg3
) = entry
->func
;
132 unsigned long args
[4];
134 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
135 fptr(event
, args
[0], args
[1], args
[2], args
[3]);
140 void (*fptr
)(void *__data
,
145 unsigned long arg4
) = entry
->func
;
146 unsigned long args
[5];
148 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
149 fptr(event
, args
[0], args
[1], args
[2], args
[3], args
[4]);
154 void (*fptr
)(void *__data
,
160 unsigned long arg5
) = entry
->func
;
161 unsigned long args
[6];
163 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
164 fptr(event
, args
[0], args
[1], args
[2],
165 args
[3], args
[4], args
[5]);
173 int lttng_syscalls_register(struct ltt_channel
*chan
, void *filter
)
178 wrapper_vmalloc_sync_all();
180 if (!chan
->sc_table
) {
181 /* create syscall table mapping syscall to events */
182 chan
->sc_table
= kzalloc(sizeof(struct ltt_event
*)
183 * ARRAY_SIZE(sc_table
), GFP_KERNEL
);
188 /* Allocate events for each syscall, insert into table */
189 for (i
= 0; i
< ARRAY_SIZE(sc_table
); i
++) {
190 struct lttng_kernel_event ev
;
191 const struct lttng_event_desc
*desc
= sc_table
[i
].desc
;
196 * Skip those already populated by previous failed
197 * register for this channel.
199 if (chan
->sc_table
[i
])
201 memset(&ev
, 0, sizeof(ev
));
202 strncpy(ev
.name
, desc
->name
, LTTNG_SYM_NAME_LEN
);
203 ev
.name
[LTTNG_SYM_NAME_LEN
- 1] = '\0';
204 ev
.instrumentation
= LTTNG_KERNEL_NOOP
;
205 chan
->sc_table
[i
] = ltt_event_create(chan
, &ev
, filter
,
207 if (!chan
->sc_table
[i
]) {
209 * If something goes wrong in event registration
210 * after the first one, we have no choice but to
211 * leave the previous events in there, until
212 * deleted by session teardown.
217 ret
= tracepoint_probe_register("sys_enter",
218 (void *) syscall_entry_probe
, chan
);
223 * Only called at session destruction.
225 int lttng_syscalls_unregister(struct ltt_channel
*chan
)
231 ret
= tracepoint_probe_unregister("sys_enter",
232 (void *) syscall_entry_probe
, chan
);
235 /* ltt_event destroy will be performed by ltt_session_destroy() */
236 kfree(chan
->sc_table
);