From 8fd0a145947011f113abaab245e35f1adfb6eb48 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 4 Feb 2022 06:16:18 -0500 Subject: Allow `builtins.c` to inject constants into program, use for syscalls We can now directly expose the `syscallN()` APIs to the program and define the `open()`, `write()` etc syscalls in the stdlib. This simplifies the implementation a decent bunch :^) --- src/utils.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 939021a..050c654 100644 --- a/src/utils.c +++ b/src/utils.c @@ -29,6 +29,15 @@ void _die_location(char *file, int line, Location loc, const char *fmt, ...) i64 i64max(i64 a, i64 b) { return a > b ? a : b; } i64 i64min(i64 a, i64 b) { return a < b ? a : b; } + +i64 get_syscall_num(i64 orig_syscall) { +#if __APPLE__ + return orig_syscall + 0x2000000; +#else + return orig_syscall; +#endif +} + i64 align_up(i64 val, i64 align) { return (val + align - 1) & ~(align - 1); -- cgit v1.2.3