Debian Codegraph @

src/syscalls.perf.template

raw
1 %{
2 /**
3 * Copyright (c) 2012 Red Hat <[email protected]>
4 * Copyright (c) 2020 Red Hat <[email protected]>
5 * Copyright (c) 2022 Microsoft Corporation. <[email protected]>
6 *
7 * Authors: Paul Moore <[email protected]>
8 * Giuseppe Scrivano <[email protected]>
9 */
10
11 /*
12 * This library is free software; you can redistribute it and/or modify it
13 * under the terms of version 2.1 of the GNU Lesser General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This library is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library; if not, see <http://www.gnu.org/licenses>.
23 */
24
25 #include <seccomp.h>
26 #include <string.h>
27 #include "syscalls.h"
28
29 %}
30 struct arch_syscall_table;
31
32 %%
33 @@SYSCALLS_TABLE@@
34 %%
35
36 static int __syscall_offset_value(const struct arch_syscall_table *s,
37 int offset)
38 {
39 return *(int *)((char *)s + offset);
40 }
41
42 static const struct arch_syscall_table *__syscall_lookup_name(const char *name)
43 {
44 return in_word_set(name, strlen(name));
45 }
46
47 static const struct arch_syscall_table *__syscall_lookup_num(int num,
48 int offset_arch)
49 {
50 unsigned int i;
51
52 for (i = 0; i < sizeof(wordlist)/sizeof(wordlist[0]); i++) {
53 if (__syscall_offset_value(&wordlist[i], offset_arch) == num)
54 return &wordlist[i];
55 }
56
57 return NULL;
58 }
59
60 int syscall_resolve_name(const char *name, int offset_arch)
61 {
62 const struct arch_syscall_table *entry;
63
64 entry = __syscall_lookup_name(name);
65 if (!entry)
66 return __NR_SCMP_ERROR;
67
68 return __syscall_offset_value(entry, offset_arch);
69 }
70
71 const char *syscall_resolve_num(int num, int offset_arch)
72 {
73 const struct arch_syscall_table *entry;
74
75 entry = __syscall_lookup_num(num, offset_arch);
76 if (!entry)
77 return NULL;
78
79 return (stringpool + entry->name);
80 }
81
82 enum scmp_kver syscall_resolve_name_kver(const char *name, int offset_kver)
83 {
84 const struct arch_syscall_table *entry;
85
86 entry = __syscall_lookup_name(name);
87 if (!entry)
88 return __SCMP_KV_NULL;
89
90 return __syscall_offset_value(entry, offset_kver);
91 }
92
93 enum scmp_kver syscall_resolve_num_kver(int num,
94 int offset_arch, int offset_kver)
95 {
96 const struct arch_syscall_table *entry;
97
98 entry = __syscall_lookup_num(num, offset_arch);
99 if (!entry)
100 return __SCMP_KV_NULL;
101
102 return __syscall_offset_value(entry, offset_kver);
103 }
104
105 /* DANGER: this is NOT THREAD-SAFE, use only for testing */
106 const struct arch_syscall_def *syscall_iterate(unsigned int spot, int offset)
107 {
108 unsigned int iter;
109 static struct arch_syscall_def arch_def;
110
111 /* DANGER: see the note above, NOT THREAD-SAFE, use only for testing */
112
113 arch_def.name = NULL;
114 arch_def.num = __NR_SCMP_ERROR;
115
116 for (iter = 0; iter < sizeof(wordlist)/sizeof(wordlist[0]); iter++) {
117 if (wordlist[iter].index == spot) {
118 arch_def.name = stringpool + wordlist[iter].name;
119 arch_def.num = __syscall_offset_value(&wordlist[iter],
120 offset);
121 return &arch_def;
122 }
123 }
124
125 return &arch_def;
126 }