Kernel/LibC: Rework userspace syscall interface
Kernel syscall API no longer zeros all unused argument registers and libc now uses inlined syscall macro internally. This significantly cleans up generated code for basic syscall wrapper functions.
This commit is contained in:
@@ -74,7 +74,7 @@ set(LIBC_SOURCES
|
||||
)
|
||||
|
||||
add_library(objlibc OBJECT ${LIBC_SOURCES})
|
||||
target_compile_definitions(objlibc PRIVATE __arch=${BANAN_ARCH})
|
||||
target_compile_definitions(objlibc PRIVATE __arch=${BANAN_ARCH} __is_libc)
|
||||
|
||||
target_compile_options(objlibc PRIVATE -O2 -g -Wstack-usage=512 -fno-exceptions -fno-rtti -fpic)
|
||||
target_compile_options(objlibc PUBLIC -Wall -Wextra -Werror -Wno-error=stack-usage=)
|
||||
|
||||
@@ -608,6 +608,22 @@ char* getpass(const char* prompt);
|
||||
|
||||
long syscall(long syscall, ...);
|
||||
|
||||
#ifdef __is_libc
|
||||
#include <kernel/API/Syscall.h>
|
||||
#include <errno.h>
|
||||
#define _syscall(...) ({ \
|
||||
long _ret = -ERESTART; \
|
||||
while (_ret == -ERESTART) \
|
||||
_ret = _kas_syscall(__VA_ARGS__); \
|
||||
if (_ret < 0) { \
|
||||
errno = -_ret; \
|
||||
_ret = -1; \
|
||||
} \
|
||||
_ret; \
|
||||
})
|
||||
#define syscall _syscall
|
||||
#endif
|
||||
|
||||
extern char** environ;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
@@ -254,32 +254,21 @@ void _exit(int status)
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
#undef syscall
|
||||
long syscall(long syscall, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, syscall);
|
||||
|
||||
uintptr_t arg1 = va_arg(args, uintptr_t);
|
||||
uintptr_t arg2 = va_arg(args, uintptr_t);
|
||||
uintptr_t arg3 = va_arg(args, uintptr_t);
|
||||
uintptr_t arg4 = va_arg(args, uintptr_t);
|
||||
uintptr_t arg5 = va_arg(args, uintptr_t);
|
||||
|
||||
va_end(args);
|
||||
|
||||
long ret;
|
||||
do
|
||||
ret = Kernel::syscall(syscall, arg1, arg2, arg3, arg4, arg5);
|
||||
while (ret == -ERESTART);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
errno = -ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return _syscall(syscall, arg1, arg2, arg3, arg4, arg5);
|
||||
}
|
||||
#define syscall _syscall
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user