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 #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.h"
68 #undef CREATE_SYSCALL_TABLE
70 static void syscall_entry_probe(void *__data
, struct pt_regs
*regs
, long id
)
72 struct trace_syscall_entry
*entry
;
73 struct ltt_channel
*chan
= __data
;
74 struct ltt_event
*event
;
76 if (unlikely(id
>= ARRAY_SIZE(sc_table
)))
78 entry
= &sc_table
[id
];
79 if (unlikely(!entry
->func
))
81 event
= chan
->sc_table
[id
];
84 switch (entry
->nrargs
) {
87 void (*fptr
)(void *__data
) = entry
->func
;
94 void (*fptr
)(void *__data
, unsigned long arg0
) = entry
->func
;
95 unsigned long args
[1];
97 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
103 void (*fptr
)(void *__data
,
105 unsigned long arg1
) = entry
->func
;
106 unsigned long args
[2];
108 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
109 fptr(event
, args
[0], args
[1]);
114 void (*fptr
)(void *__data
,
117 unsigned long arg2
) = entry
->func
;
118 unsigned long args
[3];
120 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
121 fptr(event
, args
[0], args
[1], args
[2]);
126 void (*fptr
)(void *__data
,
130 unsigned long arg3
) = entry
->func
;
131 unsigned long args
[4];
133 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
134 fptr(event
, args
[0], args
[1], args
[2], args
[3]);
139 void (*fptr
)(void *__data
,
144 unsigned long arg4
) = entry
->func
;
145 unsigned long args
[5];
147 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
148 fptr(event
, args
[0], args
[1], args
[2], args
[3], args
[4]);
153 void (*fptr
)(void *__data
,
159 unsigned long arg5
) = entry
->func
;
160 unsigned long args
[6];
162 syscall_get_arguments(current
, regs
, 0, entry
->nrargs
, args
);
163 fptr(event
, args
[0], args
[1], args
[2],
164 args
[3], args
[4], args
[5]);
172 int lttng_syscalls_register(struct ltt_channel
*chan
, void *filter
)
177 wrapper_vmalloc_sync_all();
179 if (!chan
->sc_table
) {
180 /* create syscall table mapping syscall to events */
181 chan
->sc_table
= kzalloc(sizeof(struct ltt_event
*)
182 * ARRAY_SIZE(sc_table
), GFP_KERNEL
);
187 /* Allocate events for each syscall, insert into table */
188 for (i
= 0; i
< ARRAY_SIZE(sc_table
); i
++) {
189 struct lttng_kernel_event ev
;
190 const struct lttng_event_desc
*desc
= sc_table
[i
].desc
;
195 * Skip those already populated by previous failed
196 * register for this channel.
198 if (chan
->sc_table
[i
])
200 memset(&ev
, 0, sizeof(ev
));
201 strncpy(ev
.name
, desc
->name
, LTTNG_SYM_NAME_LEN
);
202 ev
.name
[LTTNG_SYM_NAME_LEN
- 1] = '\0';
203 ev
.instrumentation
= LTTNG_KERNEL_NOOP
;
204 chan
->sc_table
[i
] = ltt_event_create(chan
, &ev
, filter
,
206 if (!chan
->sc_table
[i
]) {
208 * If something goes wrong in event registration
209 * after the first one, we have no choice but to
210 * leave the previous events in there, until
211 * deleted by session teardown.
216 ret
= tracepoint_probe_register("sys_enter",
217 (void *) syscall_entry_probe
, chan
);
222 * Only called at session destruction.
224 int lttng_syscalls_unregister(struct ltt_channel
*chan
)
230 ret
= tracepoint_probe_unregister("sys_enter",
231 (void *) syscall_entry_probe
, chan
);
234 /* ltt_event destroy will be performed by ltt_session_destroy() */
235 kfree(chan
->sc_table
);