| 1 | /* |
| 2 | * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 3 | * Copyright 2011 - Julien Desfossez <julien.desfossez@polymtl.ca> |
| 4 | * |
| 5 | * Dump syscall metadata to console. |
| 6 | * |
| 7 | * GPLv2 license. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/kallsyms.h> |
| 17 | #include <linux/dcache.h> |
| 18 | #include <linux/ftrace_event.h> |
| 19 | #include <trace/syscall.h> |
| 20 | |
| 21 | #ifndef CONFIG_FTRACE_SYSCALLS |
| 22 | #error "You need to set CONFIG_FTRACE_SYSCALLS=y" |
| 23 | #endif |
| 24 | |
| 25 | #ifndef CONFIG_KALLSYMS_ALL |
| 26 | #error "You need to set CONFIG_KALLSYMS_ALL=y" |
| 27 | #endif |
| 28 | |
| 29 | static struct syscall_metadata **__start_syscalls_metadata; |
| 30 | static struct syscall_metadata **__stop_syscalls_metadata; |
| 31 | |
| 32 | static __init |
| 33 | struct syscall_metadata *find_syscall_meta(unsigned long syscall) |
| 34 | { |
| 35 | struct syscall_metadata **iter; |
| 36 | |
| 37 | for (iter = __start_syscalls_metadata; |
| 38 | iter < __stop_syscalls_metadata; iter++) { |
| 39 | if ((*iter)->syscall_nr == syscall) |
| 40 | return (*iter); |
| 41 | } |
| 42 | return NULL; |
| 43 | } |
| 44 | |
| 45 | int init_module(void) |
| 46 | { |
| 47 | struct syscall_metadata *meta; |
| 48 | int i; |
| 49 | |
| 50 | __start_syscalls_metadata = (void *) kallsyms_lookup_name("__start_syscalls_metadata"); |
| 51 | __stop_syscalls_metadata = (void *) kallsyms_lookup_name("__stop_syscalls_metadata"); |
| 52 | |
| 53 | for (i = 0; i < NR_syscalls; i++) { |
| 54 | int j; |
| 55 | |
| 56 | meta = find_syscall_meta(i); |
| 57 | if (!meta) |
| 58 | continue; |
| 59 | printk("syscall %s nr %d nbargs %d ", |
| 60 | meta->name, meta->syscall_nr, meta->nb_args); |
| 61 | printk("types: ("); |
| 62 | for (j = 0; j < meta->nb_args; j++) { |
| 63 | if (j > 0) |
| 64 | printk(", "); |
| 65 | printk("%s", meta->types[j]); |
| 66 | } |
| 67 | printk(") "); |
| 68 | printk("args: ("); |
| 69 | for (j = 0; j < meta->nb_args; j++) { |
| 70 | if (j > 0) |
| 71 | printk(", "); |
| 72 | printk("%s", meta->args[j]); |
| 73 | } |
| 74 | printk(")\n"); |
| 75 | } |
| 76 | printk("SUCCESS\n"); |
| 77 | |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | void cleanup_module(void) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | MODULE_LICENSE("GPL"); |