From 1007f634fb22945694d51b64991747bb6329716d Mon Sep 17 00:00:00 2001 From: flysand7 Date: Tue, 25 Jul 2023 16:24:19 +1100 Subject: [PATCH] Add program api to tinyrt --- include/cia_definitions.h | 1 + src/linux/syscall.c | 5 +++-- src/linux/tinyrt.c | 4 ++++ src/linux/tinyrt.mf | 2 ++ src/tinyrt.h | 10 ++++++++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/cia_definitions.h b/include/cia_definitions.h index 02312c8..85c972c 100644 --- a/include/cia_definitions.h +++ b/include/cia_definitions.h @@ -3,6 +3,7 @@ // Pre-C23 keyword macros and stddef #define static_assert _Static_assert +#define noreturn _Noreturn #define NULL ((void *)0) // Platform macros diff --git a/src/linux/syscall.c b/src/linux/syscall.c index d5a5da9..8335853 100644 --- a/src/linux/syscall.c +++ b/src/linux/syscall.c @@ -167,8 +167,9 @@ static inline i64 syscall_close(u32 fd) { return __syscall1(SYS_close, fd); } -static inline i64 syscall_exit(int code) { - return __syscall1(SYS_exit, (i64)code); +static inline noreturn void syscall_exit(int code) { + __syscall1(SYS_exit, (i64)code); + __builtin_unreachable(); } static inline i64 syscall_arch_prctl_set(int code, u64 value) { diff --git a/src/linux/tinyrt.c b/src/linux/tinyrt.c index aed3827..2073aa5 100644 --- a/src/linux/tinyrt.c +++ b/src/linux/tinyrt.c @@ -55,3 +55,7 @@ static RT_Status rt_file_close(RT_File *file) { } return RT_STATUS_OK; } + +static noreturn void rt_program_exit(int code) { + syscall_exit(code); +} diff --git a/src/linux/tinyrt.mf b/src/linux/tinyrt.mf index b8e93ee..88541ea 100644 --- a/src/linux/tinyrt.mf +++ b/src/linux/tinyrt.mf @@ -11,3 +11,5 @@ # #define RT_API_FILE file = 1 +program = 1 +shell = 0 diff --git a/src/tinyrt.h b/src/tinyrt.h index 3dac071..7a2dd1f 100644 --- a/src/tinyrt.h +++ b/src/tinyrt.h @@ -41,6 +41,16 @@ static bool _rt_api_tmpfile; static RT_Status rt_init(); static RT_Status rt_deinit(); +// Program API +#if RT_API_PROGRAM == 1 + static noreturn void rt_program_exit(int code); +#endif + +#if RT_API_ENVIRONMENT == 1 + static RT_Status rt_shell_exec(char const *cmd); + static RT_Status rt_env_get(char const *name); +#endif + // File API #if RT_API_FILE == 1 struct RT_File typedef RT_File;