Fix syscall exit tracing
[lttng-modules.git] / lttng-syscalls.c
index 1872f161faa22955587c609bbc8eb7013edebcde..682a38759ff787802ff5370b6dace643e64e85f2 100644 (file)
@@ -67,23 +67,36 @@ static struct trace_syscall_entry sc_table[] = {
 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
 };
 
-static int sc_table_filled;
-
 #undef CREATE_SYSCALL_TABLE
 
+static void syscall_entry_unknown(struct ltt_channel *chan,
+       struct pt_regs *regs, unsigned int id)
+{
+       unsigned long args[UNKNOWN_SYSCALL_NRARGS];
+       struct ltt_event *event;
+
+       event = chan->sc_unknown;
+       syscall_get_arguments(current, regs, 0, UNKNOWN_SYSCALL_NRARGS, args);
+       __event_probe__sys_unknown(event, id, args);
+}
+
 static void syscall_entry_probe(void *__data, struct pt_regs *regs, long id)
 {
        struct trace_syscall_entry *entry;
        struct ltt_channel *chan = __data;
        struct ltt_event *event;
 
-       if (unlikely(id >= ARRAY_SIZE(sc_table)))
-               return;
-       entry = &sc_table[id];
-       if (unlikely(!entry->func))
+       if (unlikely(id >= ARRAY_SIZE(sc_table))) {
+               syscall_entry_unknown(chan, regs, id);
                return;
+       }
        event = chan->sc_table[id];
-       WARN_ON_ONCE(!event);
+       if (unlikely(!event)) {
+               syscall_entry_unknown(chan, regs, id);
+               return;
+       }
+       entry = &sc_table[id];
+       WARN_ON_ONCE(!entry);
 
        switch (entry->nrargs) {
        case 0:
@@ -173,27 +186,6 @@ static void syscall_entry_probe(void *__data, struct pt_regs *regs, long id)
        }
 }
 
-static void fill_sc_table(void)
-{
-       int i;
-
-       if (sc_table_filled) {
-               smp_rmb();      /* read flag before table */
-               return;
-       }
-
-       for (i = 0; i < ARRAY_SIZE(sc_table); i++) {
-               if (sc_table[i].func)
-                       continue;
-               sc_table[i].func = __event_probe__sys_unknown;
-               sc_table[i].nrargs = UNKNOWN_SYSCALL_NRARGS;
-               sc_table[i].fields = __event_fields___sys_unknown;
-               sc_table[i].desc = &__event_desc___sys_unknown;
-       }
-       smp_wmb();      /* Fill sc table before set flag to 1 */
-       sc_table_filled = 1;
-}
-
 int lttng_syscalls_register(struct ltt_channel *chan, void *filter)
 {
        unsigned int i;
@@ -201,8 +193,6 @@ int lttng_syscalls_register(struct ltt_channel *chan, void *filter)
 
        wrapper_vmalloc_sync_all();
 
-       fill_sc_table();
-
        if (!chan->sc_table) {
                /* create syscall table mapping syscall to events */
                chan->sc_table = kzalloc(sizeof(struct ltt_event *)
@@ -211,12 +201,31 @@ int lttng_syscalls_register(struct ltt_channel *chan, void *filter)
                        return -ENOMEM;
        }
 
+       if (!chan->sc_unknown) {
+               struct lttng_kernel_event ev;
+
+               const struct lttng_event_desc *desc =
+                       &__event_desc___sys_unknown;
+               memset(&ev, 0, sizeof(ev));
+               strncpy(ev.name, desc->name, LTTNG_SYM_NAME_LEN);
+               ev.name[LTTNG_SYM_NAME_LEN - 1] = '\0';
+               ev.instrumentation = LTTNG_KERNEL_NOOP;
+               chan->sc_unknown = ltt_event_create(chan, &ev, filter,
+                                                   desc);
+               if (!chan->sc_unknown) {
+                       return -EINVAL;
+               }
+       }
+
        /* Allocate events for each syscall, insert into table */
        for (i = 0; i < ARRAY_SIZE(sc_table); i++) {
                struct lttng_kernel_event ev;
                const struct lttng_event_desc *desc = sc_table[i].desc;
 
-               WARN_ON_ONCE(!desc);
+               if (!desc) {
+                       /* Unknown syscall */
+                       continue;
+               }
                /*
                 * Skip those already populated by previous failed
                 * register for this channel.
@@ -248,7 +257,8 @@ int lttng_syscalls_register(struct ltt_channel *chan, void *filter)
         * conflict with sys_exit syscall entry.
         */
        ret = tracepoint_probe_register("sys_exit",
-                       (void *) __event_probe__exit_syscall, chan);
+                       (void *) __event_probe__exit_syscall,
+                       chan->sc_unknown);
        if (ret) {
                WARN_ON_ONCE(tracepoint_probe_unregister("sys_enter",
                        (void *) syscall_entry_probe, chan));
@@ -266,7 +276,8 @@ int lttng_syscalls_unregister(struct ltt_channel *chan)
        if (!chan->sc_table)
                return 0;
        ret = tracepoint_probe_unregister("sys_exit",
-                       (void *) __event_probe__exit_syscall, chan);
+                       (void *) __event_probe__exit_syscall,
+                       chan->sc_unknown);
        if (ret)
                return ret;
        ret = tracepoint_probe_unregister("sys_enter",
This page took 0.024659 seconds and 4 git commands to generate.