diff options
| author | hachem <im@hachem.wtf> | 2026-10-17 12:24:17 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-10-17 12:24:17 +0200 |
| commit | 20a921db8bd8d5e99c0e9dcc72f22ac00a5e5222 (patch) | |
| tree | 3454816f3642fe468f806aac495c04e55993b102 /sysroot | |
| parent | 6a5543bb8f1f535ca49737bcd7be0cafca3b2a08 (diff) | |
feat: fork/exec & wait
Diffstat (limited to 'sysroot')
| -rw-r--r-- | sysroot/usr/include/sys/syscall.h | 15 | ||||
| -rw-r--r-- | sysroot/usr/include/unistd.h | 5 | ||||
| -rw-r--r-- | sysroot/usr/lib/libc/syscalls.c | 20 |
3 files changed, 38 insertions, 2 deletions
diff --git a/sysroot/usr/include/sys/syscall.h b/sysroot/usr/include/sys/syscall.h index 4a23a53..eecd257 100644 --- a/sysroot/usr/include/sys/syscall.h +++ b/sysroot/usr/include/sys/syscall.h @@ -7,8 +7,19 @@ #define SYS_open 7 #define SYS_close 8 #define SYS_lseek 9 -#define SYS_brk 10 -#define SYS_sbrk 11 +#define SYS_brk 10 +#define SYS_sbrk 11 +#define SYS_fork 12 +#define SYS_exec 13 +#define SYS_wait 14 +#define SYS_getpid 15 + +static inline long __syscall0(long number) +{ + long result; + __asm__ volatile("int $0x80" : "=a"(result) : "a"(number) : "memory"); + return result; +} static inline long __syscall1(long number, long a1) { diff --git a/sysroot/usr/include/unistd.h b/sysroot/usr/include/unistd.h index f5a67ab..65414d5 100644 --- a/sysroot/usr/include/unistd.h +++ b/sysroot/usr/include/unistd.h @@ -15,4 +15,9 @@ long lseek(int fd, long offset, int whence); void* sbrk(long increment); int brk(void* address); +int fork(void); +int exec(const char* path, const char* arg); +int wait(int* status); +int getpid(void); + #endif diff --git a/sysroot/usr/lib/libc/syscalls.c b/sysroot/usr/lib/libc/syscalls.c index ad959b9..33bbb12 100644 --- a/sysroot/usr/lib/libc/syscalls.c +++ b/sysroot/usr/lib/libc/syscalls.c @@ -36,3 +36,23 @@ int brk(void* address) { return (int)__syscall1(SYS_brk, (long)address); } + +int fork(void) +{ + return (int)__syscall0(SYS_fork); +} + +int exec(const char* path, const char* arg) +{ + return (int)__syscall2(SYS_exec, (long)path, (long)arg); +} + +int wait(int* status) +{ + return (int)__syscall1(SYS_wait, (long)status); +} + +int getpid(void) +{ + return (int)__syscall0(SYS_getpid); +} |
