Implement syscall listing
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 12 Sep 2014 18:12:43 +0000 (14:12 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 26 Sep 2014 16:10:00 +0000 (12:10 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lttng-abi.c
lttng-abi.h
lttng-events.h
lttng-syscalls.c

index 6dc59aed5c58465380c49980646236de03a2f94d..ab0a11286c7ba75f423e430085b616c0df4e76b0 100644 (file)
@@ -143,6 +143,43 @@ fd_error:
        return ret;
 }
 
+static
+int lttng_abi_syscall_list(void)
+{
+       struct file *syscall_list_file;
+       int file_fd, ret;
+
+       file_fd = 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;
+}
+
 static
 void lttng_abi_tracer_version(struct lttng_kernel_tracer_version *v)
 {
@@ -249,6 +286,8 @@ long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case LTTNG_KERNEL_OLD_TRACEPOINT_LIST:
        case LTTNG_KERNEL_TRACEPOINT_LIST:
                return lttng_abi_tracepoint_list();
+       case LTTNG_KERNEL_SYSCALL_LIST:
+               return lttng_abi_syscall_list();
        case LTTNG_KERNEL_OLD_WAIT_QUIESCENT:
        case LTTNG_KERNEL_WAIT_QUIESCENT:
                synchronize_trace();
index b626b88e2c6b2b5eee0a49fd6b93133b8665175c..279435792fa0a50e4b944caeda3c3a8af1a146aa 100644 (file)
@@ -157,6 +157,7 @@ struct lttng_kernel_context {
 #define LTTNG_KERNEL_WAIT_QUIESCENT            _IO(0xF6, 0x48)
 #define LTTNG_KERNEL_CALIBRATE                 \
        _IOWR(0xF6, 0x49, struct lttng_kernel_calibrate)
+#define LTTNG_KERNEL_SYSCALL_LIST              _IO(0xF6, 0x49)
 
 /* Session FD ioctl */
 #define LTTNG_KERNEL_METADATA                  \
index cf5acafab8348d7937623bb1376f118ed7827589..92a61789af6a15e320147ebd37683759e59dc53c 100644 (file)
@@ -556,6 +556,7 @@ void lttng_ftrace_destroy_private(struct lttng_event *event)
 int lttng_calibrate(struct lttng_kernel_calibrate *calibrate);
 
 extern const struct file_operations lttng_tracepoint_list_fops;
+extern const struct file_operations lttng_syscall_list_fops;
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
 #define TRACEPOINT_HAS_DATA_ARG
index c23f1d9e7e5b07c7533e14f2fdf404763152ea8c..25b8431a7c1ed3fa64141959ac2f015ba56a8879 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/bitmap.h>
 #include <linux/in.h>
 #include <linux/in6.h>
+#include <linux/seq_file.h>
 #include <asm/ptrace.h>
 #include <asm/syscall.h>
 
@@ -1070,3 +1071,86 @@ error:
                kfree(filter);
        return ret;
 }
+
+static
+const struct trace_syscall_entry *syscall_list_get_entry(loff_t *pos)
+{
+       const struct trace_syscall_entry *entry;
+       int iter = 0;
+
+       for (entry = sc_table;
+                       entry < sc_table + ARRAY_SIZE(sc_table);
+                        entry++) {
+               if (iter++ >= *pos)
+                       return entry;
+       }
+       for (entry = compat_sc_table;
+                       entry < compat_sc_table + ARRAY_SIZE(compat_sc_table);
+                        entry++) {
+               if (iter++ >= *pos)
+                       return entry;
+       }
+       /* End of list */
+       return NULL;
+}
+
+static
+void *syscall_list_start(struct seq_file *m, loff_t *pos)
+{
+       return (void *) syscall_list_get_entry(pos);
+}
+
+static
+void *syscall_list_next(struct seq_file *m, void *p, loff_t *ppos)
+{
+       (*ppos)++;
+       return (void *) syscall_list_get_entry(ppos);
+}
+
+static
+void syscall_list_stop(struct seq_file *m, void *p)
+{
+}
+
+static
+int syscall_list_show(struct seq_file *m, void *p)
+{
+       const struct trace_syscall_entry *table, *entry = p;
+       unsigned int bitness;
+
+       if (entry >= sc_table && entry < sc_table + ARRAY_SIZE(sc_table)) {
+               bitness = BITS_PER_LONG;
+               table = sc_table;
+       } else {
+               bitness = 32;
+               table = compat_sc_table;
+               WARN_ON_ONCE(!(entry >= compat_sc_table
+                       && entry < compat_sc_table + ARRAY_SIZE(compat_sc_table)));
+       }
+       seq_printf(m,   "syscall { name = %s; bitness = %u; };\n",
+               entry->desc->name,
+               bitness);
+       return 0;
+}
+
+static
+const struct seq_operations lttng_syscall_list_seq_ops = {
+       .start = syscall_list_start,
+       .next = syscall_list_next,
+       .stop = syscall_list_stop,
+       .show = syscall_list_show,
+};
+
+static
+int lttng_syscall_list_open(struct inode *inode, struct file *file)
+{
+       return seq_open(file, &lttng_syscall_list_seq_ops);
+}
+
+const struct file_operations lttng_syscall_list_fops = {
+       .owner = THIS_MODULE,
+       .open = lttng_syscall_list_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = seq_release,
+};
This page took 0.028877 seconds and 4 git commands to generate.