diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | src/init/syscalls.c | 33 | ||||
-rw-r--r-- | src/shared/syscalls.h | 8 | ||||
-rw-r--r-- | tools/syscall_wrappers.awk | 44 |
4 files changed, 70 insertions, 18 deletions
@@ -85,3 +85,6 @@ out/obj/%.s.o: src/%.s out/obj/%.c.o: src/%.c @mkdir -p $(@D) @$(CC) $(CFLAGS) -c $^ -o $@ + +src/init/syscalls.c: tools/syscall_wrappers.awk src/shared/syscalls.h + awk -f $^ > $@ diff --git a/src/init/syscalls.c b/src/init/syscalls.c index a374976..daddde9 100644 --- a/src/init/syscalls.c +++ b/src/init/syscalls.c @@ -1,37 +1,41 @@ -// this file could probably just get generated by a script +/* generated by tools/syscall_wrappers.awk + * don't modify manually, instead run: + * make src/init/syscalls.c + */ #include <shared/syscalls.h> + _Noreturn void _syscall_exit(int ret) { _syscall(_SYSCALL_EXIT, ret, 0, 0, 0); __builtin_unreachable(); } -int _syscall_fork(int flags) { - return _syscall(_SYSCALL_FORK, flags, 0, 0, 0); -} - int _syscall_await(void) { return _syscall(_SYSCALL_AWAIT, 0, 0, 0, 0); } +int _syscall_fork(int flags) { + return _syscall(_SYSCALL_FORK, flags, 0, 0, 0); +} + handle_t _syscall_open(const char __user *path, int len) { return _syscall(_SYSCALL_OPEN, (int)path, len, 0, 0); } -int _syscall_mount(handle_t handle, const char __user *path, int len) { - return _syscall(_SYSCALL_MOUNT, handle, (int)path, len, 0); +int _syscall_mount(handle_t h, const char __user *path, int len) { + return _syscall(_SYSCALL_MOUNT, (int)h, (int)path, len, 0); } -int _syscall_read(handle_t handle, void __user *buf, size_t len, int offset) { - return _syscall(_SYSCALL_READ, handle, (int)buf, (int)len, offset); +int _syscall_read(handle_t h, void __user *buf, size_t len, int offset) { + return _syscall(_SYSCALL_READ, (int)h, (int)buf, (int)len, offset); } -int _syscall_write(handle_t handle, const void __user *buf, size_t len, int offset) { - return _syscall(_SYSCALL_WRITE, handle, (int)buf, (int)len, offset); +int _syscall_write(handle_t h, const void __user *buf, size_t len, int offset) { + return _syscall(_SYSCALL_WRITE, (int)h, (int)buf, (int)len, offset); } -int _syscall_close(handle_t handle) { - return _syscall(_SYSCALL_CLOSE, handle, 0, 0, 0); +int _syscall_close(handle_t h) { + return _syscall(_SYSCALL_CLOSE, (int)h, 0, 0, 0); } handle_t _syscall_fs_fork2(void) { @@ -47,5 +51,6 @@ int _syscall_fs_respond(char __user *buf, int ret) { } int _syscall_memflag(void __user *addr, size_t len, int flags) { - return _syscall(_SYSCALL_MEMFLAG, (int)addr, len, flags, 0); + return _syscall(_SYSCALL_MEMFLAG, (int)addr, (int)len, flags, 0); } + diff --git a/src/shared/syscalls.h b/src/shared/syscalls.h index 5773190..d986d11 100644 --- a/src/shared/syscalls.h +++ b/src/shared/syscalls.h @@ -44,10 +44,10 @@ int _syscall_fork(int flags); handle_t _syscall_open(const char __user *path, int len); -int _syscall_mount(handle_t, const char __user *path, int len); -int _syscall_read(handle_t, void __user *buf, size_t len, int offset); -int _syscall_write(handle_t, const void __user *buf, size_t len, int offset); -int _syscall_close(handle_t); +int _syscall_mount(handle_t h, const char __user *path, int len); +int _syscall_read(handle_t h, void __user *buf, size_t len, int offset); +int _syscall_write(handle_t h, const void __user *buf, size_t len, int offset); +int _syscall_close(handle_t h); handle_t _syscall_fs_fork2(void); diff --git a/tools/syscall_wrappers.awk b/tools/syscall_wrappers.awk new file mode 100644 index 0000000..c1f980e --- /dev/null +++ b/tools/syscall_wrappers.awk @@ -0,0 +1,44 @@ +BEGIN { + print "\ +/* generated by tools/syscall_wrappers.awk\n\ + * don't modify manually, instead run:\n\ + * make src/init/syscalls.c\n\ + */\n\ +#include <shared/syscalls.h>\n\ +\n"; +} + +/_syscall\(/ { next; } # skipping _syscall(), it's implemented elsewhere + +/\);/ { + sub(/;/, " {"); + print $0; + + name = substr($0, match($0, /_syscall_[^(]+/), RLENGTH); + params = substr($0, match($0, /\(.+\)/) + 1, RLENGTH - 2); + if (params == "void") params = "" + + split(params, p, /,/); + for (i = 0; i <= 4; i += 1) { + if (p[i]) { + # p[i] is a parameter, convert it into an expression to pass to _syscall() + sub(/^ */, "", p[i]); # strip + split(p[i], words, / /); + if (length(words) != 1) { + var = words[length(words)]; + sub(/\*/, "", var); + if (words[1] != "int") var = "(int)" var; + } + p[i] = var; + } else { + p[i] = 0; + } + } + + printf "\t"; + if (!index($0, "_Noreturn")) printf "return "; + printf "_syscall(%s, %s, %s, %s, %s);\n", toupper(name), p[1], p[2], p[3], p[4]; + if (index($0, "_Noreturn")) print "\t__builtin_unreachable();"; + + print "}\n"; +} |