Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
886d51a3 MD |
3 | * lttng-syscalls-extractor.c |
4 | * | |
5 | * Dump syscall metadata to console. | |
6 | * | |
e709527c MJ |
7 | * Copyright 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
8 | * Copyright 2011 Julien Desfossez <julien.desfossez@polymtl.ca> | |
5fee13fd MD |
9 | */ |
10 | ||
11 | #include <linux/module.h> | |
12 | #include <linux/kernel.h> | |
13 | #include <linux/types.h> | |
14 | #include <linux/list.h> | |
15 | #include <linux/err.h> | |
16 | #include <linux/slab.h> | |
17 | #include <linux/kallsyms.h> | |
18 | #include <linux/dcache.h> | |
e709527c | 19 | #include <linux/trace_events.h> |
5fee13fd | 20 | #include <trace/syscall.h> |
7801e9f4 | 21 | #include <asm/syscall.h> |
5fee13fd MD |
22 | |
23 | #ifndef CONFIG_FTRACE_SYSCALLS | |
24 | #error "You need to set CONFIG_FTRACE_SYSCALLS=y" | |
25 | #endif | |
26 | ||
bc55cda3 MD |
27 | #ifndef CONFIG_KALLSYMS_ALL |
28 | #error "You need to set CONFIG_KALLSYMS_ALL=y" | |
29 | #endif | |
30 | ||
e709527c MJ |
31 | /* |
32 | * The 'ident' parameter is prepended to each printk line to help | |
33 | * extract the proper lines from dmesg. | |
34 | */ | |
35 | static char *ident = ""; | |
36 | module_param(ident, charp, 0); | |
37 | ||
5fee13fd MD |
38 | static struct syscall_metadata **__start_syscalls_metadata; |
39 | static struct syscall_metadata **__stop_syscalls_metadata; | |
40 | ||
41 | static __init | |
42 | struct syscall_metadata *find_syscall_meta(unsigned long syscall) | |
43 | { | |
44 | struct syscall_metadata **iter; | |
45 | ||
46 | for (iter = __start_syscalls_metadata; | |
47 | iter < __stop_syscalls_metadata; iter++) { | |
48 | if ((*iter)->syscall_nr == syscall) | |
49 | return (*iter); | |
50 | } | |
51 | return NULL; | |
52 | } | |
53 | ||
54 | int init_module(void) | |
55 | { | |
56 | struct syscall_metadata *meta; | |
57 | int i; | |
58 | ||
59 | __start_syscalls_metadata = (void *) kallsyms_lookup_name("__start_syscalls_metadata"); | |
60 | __stop_syscalls_metadata = (void *) kallsyms_lookup_name("__stop_syscalls_metadata"); | |
61 | ||
e709527c | 62 | printk("%s---START---\n", ident); |
5fee13fd MD |
63 | for (i = 0; i < NR_syscalls; i++) { |
64 | int j; | |
65 | ||
66 | meta = find_syscall_meta(i); | |
67 | if (!meta) | |
68 | continue; | |
e709527c MJ |
69 | printk("%ssyscall %s nr %d nbargs %d ", |
70 | ident, meta->name, meta->syscall_nr, meta->nb_args); | |
71 | printk(KERN_CONT "types: ("); | |
5fee13fd MD |
72 | for (j = 0; j < meta->nb_args; j++) { |
73 | if (j > 0) | |
e709527c MJ |
74 | printk(KERN_CONT ", "); |
75 | printk(KERN_CONT "%s", meta->types[j]); | |
5fee13fd | 76 | } |
e709527c MJ |
77 | printk(KERN_CONT ") "); |
78 | printk(KERN_CONT "args: ("); | |
5fee13fd MD |
79 | for (j = 0; j < meta->nb_args; j++) { |
80 | if (j > 0) | |
e709527c MJ |
81 | printk(KERN_CONT ", "); |
82 | printk(KERN_CONT "%s", meta->args[j]); | |
5fee13fd | 83 | } |
e709527c | 84 | printk(KERN_CONT ")\n"); |
5fee13fd | 85 | } |
e709527c | 86 | printk("%s---END---\n", ident); |
5fee13fd | 87 | |
e709527c MJ |
88 | /* |
89 | * This module always fails to load. | |
90 | */ | |
5fee13fd MD |
91 | return -1; |
92 | } | |
93 | ||
94 | void cleanup_module(void) | |
95 | { | |
1e543e7c | 96 | } |
5fee13fd MD |
97 | |
98 | MODULE_LICENSE("GPL"); |