aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/syscalls.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/syscalls.h')
-rw-r--r--include/linux/syscalls.h156
1 files changed, 50 insertions, 106 deletions
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 313a8e0a6553..4147d700a293 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -78,49 +78,34 @@ struct sigaltstack;
78#include <linux/key.h> 78#include <linux/key.h>
79#include <trace/syscall.h> 79#include <trace/syscall.h>
80 80
81#define __SC_DECL1(t1, a1) t1 a1 81/*
82#define __SC_DECL2(t2, a2, ...) t2 a2, __SC_DECL1(__VA_ARGS__) 82 * __MAP - apply a macro to syscall arguments
83#define __SC_DECL3(t3, a3, ...) t3 a3, __SC_DECL2(__VA_ARGS__) 83 * __MAP(n, m, t1, a1, t2, a2, ..., tn, an) will expand to
84#define __SC_DECL4(t4, a4, ...) t4 a4, __SC_DECL3(__VA_ARGS__) 84 * m(t1, a1), m(t2, a2), ..., m(tn, an)
85#define __SC_DECL5(t5, a5, ...) t5 a5, __SC_DECL4(__VA_ARGS__) 85 * The first argument must be equal to the amount of type/name
86#define __SC_DECL6(t6, a6, ...) t6 a6, __SC_DECL5(__VA_ARGS__) 86 * pairs given. Note that this list of pairs (i.e. the arguments
87 87 * of __MAP starting at the third one) is in the same format as
88#define __SC_LONG1(t1, a1) long a1 88 * for SYSCALL_DEFINE<n>/COMPAT_SYSCALL_DEFINE<n>
89#define __SC_LONG2(t2, a2, ...) long a2, __SC_LONG1(__VA_ARGS__) 89 */
90#define __SC_LONG3(t3, a3, ...) long a3, __SC_LONG2(__VA_ARGS__) 90#define __MAP0(m,...)
91#define __SC_LONG4(t4, a4, ...) long a4, __SC_LONG3(__VA_ARGS__) 91#define __MAP1(m,t,a) m(t,a)
92#define __SC_LONG5(t5, a5, ...) long a5, __SC_LONG4(__VA_ARGS__) 92#define __MAP2(m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)
93#define __SC_LONG6(t6, a6, ...) long a6, __SC_LONG5(__VA_ARGS__) 93#define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
94 94#define __MAP4(m,t,a,...) m(t,a), __MAP3(m,__VA_ARGS__)
95#define __SC_CAST1(t1, a1) (t1) a1 95#define __MAP5(m,t,a,...) m(t,a), __MAP4(m,__VA_ARGS__)
96#define __SC_CAST2(t2, a2, ...) (t2) a2, __SC_CAST1(__VA_ARGS__) 96#define __MAP6(m,t,a,...) m(t,a), __MAP5(m,__VA_ARGS__)
97#define __SC_CAST3(t3, a3, ...) (t3) a3, __SC_CAST2(__VA_ARGS__) 97#define __MAP(n,...) __MAP##n(__VA_ARGS__)
98#define __SC_CAST4(t4, a4, ...) (t4) a4, __SC_CAST3(__VA_ARGS__) 98
99#define __SC_CAST5(t5, a5, ...) (t5) a5, __SC_CAST4(__VA_ARGS__) 99#define __SC_DECL(t, a) t a
100#define __SC_CAST6(t6, a6, ...) (t6) a6, __SC_CAST5(__VA_ARGS__) 100#define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
101 101#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
102#define __SC_TEST(type) BUILD_BUG_ON(sizeof(type) > sizeof(long)) 102#define __SC_CAST(t, a) (t) a
103#define __SC_TEST1(t1, a1) __SC_TEST(t1) 103#define __SC_ARGS(t, a) a
104#define __SC_TEST2(t2, a2, ...) __SC_TEST(t2); __SC_TEST1(__VA_ARGS__) 104#define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
105#define __SC_TEST3(t3, a3, ...) __SC_TEST(t3); __SC_TEST2(__VA_ARGS__)
106#define __SC_TEST4(t4, a4, ...) __SC_TEST(t4); __SC_TEST3(__VA_ARGS__)
107#define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__)
108#define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__)
109 105
110#ifdef CONFIG_FTRACE_SYSCALLS 106#ifdef CONFIG_FTRACE_SYSCALLS
111#define __SC_STR_ADECL1(t, a) #a 107#define __SC_STR_ADECL(t, a) #a
112#define __SC_STR_ADECL2(t, a, ...) #a, __SC_STR_ADECL1(__VA_ARGS__) 108#define __SC_STR_TDECL(t, a) #t
113#define __SC_STR_ADECL3(t, a, ...) #a, __SC_STR_ADECL2(__VA_ARGS__)
114#define __SC_STR_ADECL4(t, a, ...) #a, __SC_STR_ADECL3(__VA_ARGS__)
115#define __SC_STR_ADECL5(t, a, ...) #a, __SC_STR_ADECL4(__VA_ARGS__)
116#define __SC_STR_ADECL6(t, a, ...) #a, __SC_STR_ADECL5(__VA_ARGS__)
117
118#define __SC_STR_TDECL1(t, a) #t
119#define __SC_STR_TDECL2(t, a, ...) #t, __SC_STR_TDECL1(__VA_ARGS__)
120#define __SC_STR_TDECL3(t, a, ...) #t, __SC_STR_TDECL2(__VA_ARGS__)
121#define __SC_STR_TDECL4(t, a, ...) #t, __SC_STR_TDECL3(__VA_ARGS__)
122#define __SC_STR_TDECL5(t, a, ...) #t, __SC_STR_TDECL4(__VA_ARGS__)
123#define __SC_STR_TDECL6(t, a, ...) #t, __SC_STR_TDECL5(__VA_ARGS__)
124 109
125extern struct ftrace_event_class event_class_syscall_enter; 110extern struct ftrace_event_class event_class_syscall_enter;
126extern struct ftrace_event_class event_class_syscall_exit; 111extern struct ftrace_event_class event_class_syscall_exit;
@@ -155,7 +140,13 @@ extern struct trace_event_functions exit_syscall_print_funcs;
155 __attribute__((section("_ftrace_events"))) \ 140 __attribute__((section("_ftrace_events"))) \
156 *__event_exit_##sname = &event_exit_##sname; 141 *__event_exit_##sname = &event_exit_##sname;
157 142
158#define SYSCALL_METADATA(sname, nb) \ 143#define SYSCALL_METADATA(sname, nb, ...) \
144 static const char *types_##sname[] = { \
145 __MAP(nb,__SC_STR_TDECL,__VA_ARGS__) \
146 }; \
147 static const char *args_##sname[] = { \
148 __MAP(nb,__SC_STR_ADECL,__VA_ARGS__) \
149 }; \
159 SYSCALL_TRACE_ENTER_EVENT(sname); \ 150 SYSCALL_TRACE_ENTER_EVENT(sname); \
160 SYSCALL_TRACE_EXIT_EVENT(sname); \ 151 SYSCALL_TRACE_EXIT_EVENT(sname); \
161 static struct syscall_metadata __used \ 152 static struct syscall_metadata __used \
@@ -163,8 +154,8 @@ extern struct trace_event_functions exit_syscall_print_funcs;
163 .name = "sys"#sname, \ 154 .name = "sys"#sname, \
164 .syscall_nr = -1, /* Filled in at boot */ \ 155 .syscall_nr = -1, /* Filled in at boot */ \
165 .nb_args = nb, \ 156 .nb_args = nb, \
166 .types = types_##sname, \ 157 .types = nb ? types_##sname : NULL, \
167 .args = args_##sname, \ 158 .args = nb ? args_##sname : NULL, \
168 .enter_event = &event_enter_##sname, \ 159 .enter_event = &event_enter_##sname, \
169 .exit_event = &event_exit_##sname, \ 160 .exit_event = &event_exit_##sname, \
170 .enter_fields = LIST_HEAD_INIT(__syscall_meta_##sname.enter_fields), \ 161 .enter_fields = LIST_HEAD_INIT(__syscall_meta_##sname.enter_fields), \
@@ -172,26 +163,13 @@ extern struct trace_event_functions exit_syscall_print_funcs;
172 static struct syscall_metadata __used \ 163 static struct syscall_metadata __used \
173 __attribute__((section("__syscalls_metadata"))) \ 164 __attribute__((section("__syscalls_metadata"))) \
174 *__p_syscall_meta_##sname = &__syscall_meta_##sname; 165 *__p_syscall_meta_##sname = &__syscall_meta_##sname;
166#else
167#define SYSCALL_METADATA(sname, nb, ...)
168#endif
175 169
176#define SYSCALL_DEFINE0(sname) \ 170#define SYSCALL_DEFINE0(sname) \
177 SYSCALL_TRACE_ENTER_EVENT(_##sname); \ 171 SYSCALL_METADATA(_##sname, 0); \
178 SYSCALL_TRACE_EXIT_EVENT(_##sname); \
179 static struct syscall_metadata __used \
180 __syscall_meta__##sname = { \
181 .name = "sys_"#sname, \
182 .syscall_nr = -1, /* Filled in at boot */ \
183 .nb_args = 0, \
184 .enter_event = &event_enter__##sname, \
185 .exit_event = &event_exit__##sname, \
186 .enter_fields = LIST_HEAD_INIT(__syscall_meta__##sname.enter_fields), \
187 }; \
188 static struct syscall_metadata __used \
189 __attribute__((section("__syscalls_metadata"))) \
190 *__p_syscall_meta_##sname = &__syscall_meta__##sname; \
191 asmlinkage long sys_##sname(void) 172 asmlinkage long sys_##sname(void)
192#else
193#define SYSCALL_DEFINE0(name) asmlinkage long sys_##name(void)
194#endif
195 173
196#define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__) 174#define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
197#define SYSCALL_DEFINE2(name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__) 175#define SYSCALL_DEFINE2(name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
@@ -200,57 +178,23 @@ extern struct trace_event_functions exit_syscall_print_funcs;
200#define SYSCALL_DEFINE5(name, ...) SYSCALL_DEFINEx(5, _##name, __VA_ARGS__) 178#define SYSCALL_DEFINE5(name, ...) SYSCALL_DEFINEx(5, _##name, __VA_ARGS__)
201#define SYSCALL_DEFINE6(name, ...) SYSCALL_DEFINEx(6, _##name, __VA_ARGS__) 179#define SYSCALL_DEFINE6(name, ...) SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
202 180
203#ifdef CONFIG_PPC64
204#define SYSCALL_ALIAS(alias, name) \
205 asm ("\t.globl " #alias "\n\t.set " #alias ", " #name "\n" \
206 "\t.globl ." #alias "\n\t.set ." #alias ", ." #name)
207#else
208#if defined(CONFIG_ALPHA) || defined(CONFIG_MIPS)
209#define SYSCALL_ALIAS(alias, name) \
210 asm ( #alias " = " #name "\n\t.globl " #alias)
211#else
212#define SYSCALL_ALIAS(alias, name) \
213 asm ("\t.globl " #alias "\n\t.set " #alias ", " #name)
214#endif
215#endif
216
217#ifdef CONFIG_FTRACE_SYSCALLS
218#define SYSCALL_DEFINEx(x, sname, ...) \ 181#define SYSCALL_DEFINEx(x, sname, ...) \
219 static const char *types_##sname[] = { \ 182 SYSCALL_METADATA(sname, x, __VA_ARGS__) \
220 __SC_STR_TDECL##x(__VA_ARGS__) \
221 }; \
222 static const char *args_##sname[] = { \
223 __SC_STR_ADECL##x(__VA_ARGS__) \
224 }; \
225 SYSCALL_METADATA(sname, x); \
226 __SYSCALL_DEFINEx(x, sname, __VA_ARGS__) 183 __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
227#else
228#define SYSCALL_DEFINEx(x, sname, ...) \
229 __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
230#endif
231
232#ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
233
234#define SYSCALL_DEFINE(name) static inline long SYSC_##name
235 184
185#define __PROTECT(...) asmlinkage_protect(__VA_ARGS__)
236#define __SYSCALL_DEFINEx(x, name, ...) \ 186#define __SYSCALL_DEFINEx(x, name, ...) \
237 asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__)); \ 187 asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
238 static inline long SYSC##name(__SC_DECL##x(__VA_ARGS__)); \ 188 static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
239 asmlinkage long SyS##name(__SC_LONG##x(__VA_ARGS__)) \ 189 asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
240 { \ 190 { \
241 __SC_TEST##x(__VA_ARGS__); \ 191 long ret = SYSC##name(__MAP(x,__SC_CAST,__VA_ARGS__)); \
242 return (long) SYSC##name(__SC_CAST##x(__VA_ARGS__)); \ 192 __MAP(x,__SC_TEST,__VA_ARGS__); \
193 __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \
194 return ret; \
243 } \ 195 } \
244 SYSCALL_ALIAS(sys##name, SyS##name); \ 196 SYSCALL_ALIAS(sys##name, SyS##name); \
245 static inline long SYSC##name(__SC_DECL##x(__VA_ARGS__)) 197 static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
246
247#else /* CONFIG_HAVE_SYSCALL_WRAPPERS */
248
249#define SYSCALL_DEFINE(name) asmlinkage long sys_##name
250#define __SYSCALL_DEFINEx(x, name, ...) \
251 asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__))
252
253#endif /* CONFIG_HAVE_SYSCALL_WRAPPERS */
254 198
255asmlinkage long sys_time(time_t __user *tloc); 199asmlinkage long sys_time(time_t __user *tloc);
256asmlinkage long sys_stime(time_t __user *tptr); 200asmlinkage long sys_stime(time_t __user *tptr);
@@ -694,7 +638,7 @@ asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf);
694asmlinkage long sys_semget(key_t key, int nsems, int semflg); 638asmlinkage long sys_semget(key_t key, int nsems, int semflg);
695asmlinkage long sys_semop(int semid, struct sembuf __user *sops, 639asmlinkage long sys_semop(int semid, struct sembuf __user *sops,
696 unsigned nsops); 640 unsigned nsops);
697asmlinkage long sys_semctl(int semid, int semnum, int cmd, union semun arg); 641asmlinkage long sys_semctl(int semid, int semnum, int cmd, unsigned long arg);
698asmlinkage long sys_semtimedop(int semid, struct sembuf __user *sops, 642asmlinkage long sys_semtimedop(int semid, struct sembuf __user *sops,
699 unsigned nsops, 643 unsigned nsops,
700 const struct timespec __user *timeout); 644 const struct timespec __user *timeout);