1 /*
2  * Copyright (c) 2013, Google, Inc. All rights reserved
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files
6  * (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify, merge,
8  * publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 /* System call table definition
25  * ============================
26  *
27  * The user of this library must:
28  *
29  * - define WITH_SYSCALL_TABLE
30  * - provide a file named syscall_table.h in the include path
31  * - provide DEF_SYSCALL macros in syscall_table.h with
32  *   number, name, #args followed by argument type defintions.
33  */
34 #include <compiler.h>
35 #include <debug.h>
36 #include <err.h>
37 #include <kernel/thread.h>
38 
sys_undefined(int num)39 long sys_undefined(int num) {
40     dprintf(SPEW, "%p invalid syscall %d requested\n", get_current_thread(),
41             num);
42     return ERR_NOT_SUPPORTED;
43 }
44 
45 #ifdef WITH_SYSCALL_TABLE
46 
47 /* Generate fake function prototypes */
48 #define DEF_SYSCALL(nr, fn, rtype, nr_args, ...) rtype sys_##fn(void);
49 #include <syscall_table.h>
50 #undef DEF_SYSCALL
51 
52 #endif
53 
54 #define DEF_SYSCALL(nr, fn, rtype, nr_args, ...) \
55     [(nr)] = (unsigned long)(sys_##fn),
56 const unsigned long syscall_table[] = {
57 
58 #ifdef WITH_SYSCALL_TABLE
59 #include <syscall_table.h>
60 #endif
61 
62 };
63 #undef DEF_SYSCALL
64 
65 unsigned long nr_syscalls = countof(syscall_table);
66