Implement tracepoint wildcard support
[lttng-modules.git] / lttng-syscalls.c
index 1489934f3319bbad05de08d3c404f155bd2feac7..ee09a0419498a07f0dc06a0bb0f56afcc8a3771a 100644 (file)
 #include <linux/in6.h>
 #include <linux/seq_file.h>
 #include <linux/stringify.h>
+#include <linux/file.h>
+#include <linux/anon_inodes.h>
 #include <asm/ptrace.h>
 #include <asm/syscall.h>
 
 #include "lib/bitfield.h"
 #include "wrapper/tracepoint.h"
+#include "wrapper/file.h"
 #include "lttng-events.h"
 
 #ifndef CONFIG_COMPAT
@@ -91,6 +94,7 @@ struct mmap_arg_struct;
 #define PARAMS(args...)        args
 
 /* Handle unknown syscalls */
+#undef TRACE_SYSTEM
 #define TRACE_SYSTEM syscalls_unknown
 #include "instrumentation/syscalls/headers/syscalls_unknown.h"
 #undef TRACE_SYSTEM
@@ -374,7 +378,7 @@ void syscall_entry_probe(void *__data, struct pt_regs *regs, long id)
 
                filter = rcu_dereference(chan->sc_filter);
                if (filter) {
-                       if (id >= NR_compat_syscalls
+                       if (id < 0 || id >= NR_compat_syscalls
                                || !test_bit(id, filter->sc_compat)) {
                                /* System call filtered out. */
                                return;
@@ -388,7 +392,7 @@ void syscall_entry_probe(void *__data, struct pt_regs *regs, long id)
 
                filter = rcu_dereference(chan->sc_filter);
                if (filter) {
-                       if (id >= NR_syscalls
+                       if (id < 0 || id >= NR_syscalls
                                || !test_bit(id, filter->sc)) {
                                /* System call filtered out. */
                                return;
@@ -398,7 +402,7 @@ void syscall_entry_probe(void *__data, struct pt_regs *regs, long id)
                table_len = ARRAY_SIZE(sc_table);
                unknown_event = chan->sc_unknown;
        }
-       if (unlikely(id >= table_len)) {
+       if (unlikely(id < 0 || id >= table_len)) {
                syscall_entry_unknown(unknown_event, regs, id);
                return;
        }
@@ -502,7 +506,7 @@ void syscall_entry_probe(void *__data, struct pt_regs *regs, long id)
 }
 
 static void syscall_exit_unknown(struct lttng_event *event,
-       struct pt_regs *regs, unsigned int id, long ret)
+       struct pt_regs *regs, int id, long ret)
 {
        unsigned long args[UNKNOWN_SYSCALL_NRARGS];
 
@@ -528,7 +532,7 @@ void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret)
 
                filter = rcu_dereference(chan->sc_filter);
                if (filter) {
-                       if (id >= NR_compat_syscalls
+                       if (id < 0 || id >= NR_compat_syscalls
                                || !test_bit(id, filter->sc_compat)) {
                                /* System call filtered out. */
                                return;
@@ -542,7 +546,7 @@ void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret)
 
                filter = rcu_dereference(chan->sc_filter);
                if (filter) {
-                       if (id >= NR_syscalls
+                       if (id < 0 || id >= NR_syscalls
                                || !test_bit(id, filter->sc)) {
                                /* System call filtered out. */
                                return;
@@ -552,7 +556,7 @@ void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret)
                table_len = ARRAY_SIZE(sc_exit_table);
                unknown_event = chan->sc_exit_unknown;
        }
-       if (unlikely(id >= table_len)) {
+       if (unlikely(id < 0 || id >= table_len)) {
                syscall_exit_unknown(unknown_event, regs, id, ret);
                return;
        }
@@ -713,7 +717,7 @@ int fill_table(const struct trace_syscall_entry *table, size_t table_len,
                ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                ev.instrumentation = LTTNG_KERNEL_NOOP;
                chan_table[i] = lttng_event_create(chan, &ev, filter,
-                                               desc);
+                                               desc, ev.instrumentation);
                WARN_ON_ONCE(!chan_table[i]);
                if (IS_ERR(chan_table[i])) {
                        /*
@@ -777,7 +781,8 @@ int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
                ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                ev.instrumentation = LTTNG_KERNEL_NOOP;
                chan->sc_unknown = lttng_event_create(chan, &ev, filter,
-                                                   desc);
+                                               desc,
+                                               ev.instrumentation);
                WARN_ON_ONCE(!chan->sc_unknown);
                if (IS_ERR(chan->sc_unknown)) {
                        return PTR_ERR(chan->sc_unknown);
@@ -793,7 +798,8 @@ int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
                ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                ev.instrumentation = LTTNG_KERNEL_NOOP;
                chan->sc_compat_unknown = lttng_event_create(chan, &ev, filter,
-                                                          desc);
+                                               desc,
+                                               ev.instrumentation);
                WARN_ON_ONCE(!chan->sc_unknown);
                if (IS_ERR(chan->sc_compat_unknown)) {
                        return PTR_ERR(chan->sc_compat_unknown);
@@ -809,7 +815,8 @@ int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
                ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                ev.instrumentation = LTTNG_KERNEL_NOOP;
                chan->compat_sc_exit_unknown = lttng_event_create(chan, &ev,
-                                               filter, desc);
+                                               filter, desc,
+                                               ev.instrumentation);
                WARN_ON_ONCE(!chan->compat_sc_exit_unknown);
                if (IS_ERR(chan->compat_sc_exit_unknown)) {
                        return PTR_ERR(chan->compat_sc_exit_unknown);
@@ -825,7 +832,7 @@ int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
                ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                ev.instrumentation = LTTNG_KERNEL_NOOP;
                chan->sc_exit_unknown = lttng_event_create(chan, &ev, filter,
-                                                desc);
+                                               desc, ev.instrumentation);
                WARN_ON_ONCE(!chan->sc_exit_unknown);
                if (IS_ERR(chan->sc_exit_unknown)) {
                        return PTR_ERR(chan->sc_exit_unknown);
@@ -1036,6 +1043,8 @@ int lttng_syscall_filter_disable(struct lttng_channel *chan,
        WARN_ON_ONCE(!chan->sc_table);
 
        if (!chan->sc_filter) {
+               if (!chan->syscall_all)
+                       return -EEXIST;
                filter = kzalloc(sizeof(struct lttng_syscall_filter),
                                GFP_KERNEL);
                if (!filter)
@@ -1048,6 +1057,14 @@ int lttng_syscall_filter_disable(struct lttng_channel *chan,
        }
 
        if (!name) {
+               /* Fail if all syscalls are already disabled. */
+               if (bitmap_empty(filter->sc, NR_syscalls)
+                       && bitmap_empty(filter->sc_compat,
+                               NR_compat_syscalls)) {
+                       ret = -EEXIST;
+                       goto error;
+               }
+
                /* Disable all system calls */
                bitmap_clear(filter->sc, 0, NR_syscalls);
                bitmap_clear(filter->sc_compat, 0, NR_compat_syscalls);
@@ -1219,16 +1236,70 @@ long lttng_channel_syscall_mask(struct lttng_channel *channel,
        filter = channel->sc_filter;
 
        for (bit = 0; bit < ARRAY_SIZE(sc_table); bit++) {
-               bt_bitfield_write_be(tmp_mask, char, bit, 1,
-                       test_bit(bit, filter->sc));
+               bool state;
+
+               if (channel->sc_table) {
+                       if (filter)
+                               state = test_bit(bit, filter->sc);
+                       else
+                               state = 1;
+               } else {
+                       state = 0;
+               }
+               bt_bitfield_write_be(tmp_mask, char, bit, 1, state);
        }
        for (; bit < sc_tables_len; bit++) {
-               bt_bitfield_write_be(tmp_mask, char, bit, 1,
-                       test_bit(bit - ARRAY_SIZE(sc_table),
-                               filter->sc_compat));
+               bool state;
+
+               if (channel->compat_sc_table) {
+                       if (filter)
+                               state = test_bit(bit - ARRAY_SIZE(sc_table),
+                                               filter->sc_compat);
+                       else
+                               state = 1;
+               } else {
+                       state = 0;
+               }
+               bt_bitfield_write_be(tmp_mask, char, bit, 1, state);
        }
        if (copy_to_user(usyscall_mask->mask, tmp_mask, bitmask_len))
                ret = -EFAULT;
        kfree(tmp_mask);
        return ret;
 }
+
+int lttng_abi_syscall_list(void)
+{
+       struct file *syscall_list_file;
+       int file_fd, ret;
+
+       file_fd = lttng_get_unused_fd();
+       if (file_fd < 0) {
+               ret = file_fd;
+               goto fd_error;
+       }
+
+       syscall_list_file = anon_inode_getfile("[lttng_syscall_list]",
+                                         &lttng_syscall_list_fops,
+                                         NULL, O_RDWR);
+       if (IS_ERR(syscall_list_file)) {
+               ret = PTR_ERR(syscall_list_file);
+               goto file_error;
+       }
+       ret = lttng_syscall_list_fops.open(NULL, syscall_list_file);
+       if (ret < 0)
+               goto open_error;
+       fd_install(file_fd, syscall_list_file);
+       if (file_fd < 0) {
+               ret = file_fd;
+               goto fd_error;
+       }
+       return file_fd;
+
+open_error:
+       fput(syscall_list_file);
+file_error:
+       put_unused_fd(file_fd);
+fd_error:
+       return ret;
+}
This page took 0.028259 seconds and 4 git commands to generate.