From: Matthias Kruk Date: Mon, 28 Oct 2019 09:33:46 +0000 (+0900) Subject: Add syscall stubs for some POSIX process management syscalls (fork, vfork, exit,... X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=6969da8ac87299d9112601711731f752c398a124;p=corax Add syscall stubs for some POSIX process management syscalls (fork, vfork, exit, ...) --- diff --git a/include/corax/syscall.h b/include/corax/syscall.h index 24f2c1f..083258a 100644 --- a/include/corax/syscall.h +++ b/include/corax/syscall.h @@ -15,6 +15,14 @@ #define SYS_POLL 11 #define SYS_BIND 12 +#define SYS_EXIT 0 +#define SYS_FORK 1 +#define SYS_VFORK 2 +#define SYS_WAIT 3 +#define SYS_WAITPID 4 +#define SYS_WAITID 5 +#define SYS_SETSID 6 + #define IPC_SEND 0 #define IPC_RECV 1 #define IPC_SENDRECV 2 diff --git a/kernel/arch/interrupt.c b/kernel/arch/interrupt.c index 7cee95f..346e404 100644 --- a/kernel/arch/interrupt.c +++ b/kernel/arch/interrupt.c @@ -27,6 +27,9 @@ void sched_tick(void); extern int sys_cxnet(long, long, long, long, long, long, long); extern int sys_cxipc(long, long, long); +#if FEATURE(POSIX) +extern int sys_posixcall(long, long, long, long, long, long, long); +#endif /* FEATURE(POSIX) */ static const char *_exc_name[] = { "#DE", "#DB", "NMI", "#BP", "#OF", "#BR", "#UD", "#NM", "#DF", "#MF", @@ -166,7 +169,7 @@ void _sys_handle(stack_frame_t ctx) #if FEATURE(POSIX) case SYS_VECTOR_POSIX: - dbg_printf("_posix_call(0x%x, 0x%x, 0x%x);\n", ctx.eax, ctx.ebx, ctx.ecx); + ret_val = sys_posixcall(ctx.eax, ctx.ebx, ctx.ecx, ctx.edx, ctx.esi, ctx.edi, ctx.ebp); break; #endif /* FEATURE(POSIX) */ diff --git a/kernel/core/Makefile b/kernel/core/Makefile index e1c8b78..298be61 100644 --- a/kernel/core/Makefile +++ b/kernel/core/Makefile @@ -1,4 +1,4 @@ -OBJECTS = main.o process.o sched.o cxnet.o socket.o cxipc.o syscall.o +OBJECTS = main.o process.o sched.o cxnet.o socket.o cxipc.o syscall.o posixcall.o OUTPUT = core.o INCLUDES = -I../include -I../../include -I../.. CFLAGS += $(INCLUDES) diff --git a/kernel/core/posixcall.c b/kernel/core/posixcall.c new file mode 100644 index 0000000..7223ed3 --- /dev/null +++ b/kernel/core/posixcall.c @@ -0,0 +1,82 @@ +#include + +#if FEATURE(POSIX) + +#include +#include +#include + +int sys_exit(int status) +{ + return(-ENOSYS); +} + +int sys_fork(void) +{ + return(-ENOSYS); +} + +int sys_vfork(void) +{ + return(-ENOSYS); +} + +int sys_wait(int *status) +{ + return(-ENOSYS); +} + +int sys_waitpid(pid_t pid, int *status, int options) +{ + return(-ENOSYS); +} + +int sys_setsid(void) +{ + return(-ENOSYS); +} + +int sys_posixcall(long vec, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6) +{ + int ret_val; + + ret_val = -EFAULT; + + switch(vec) { + case SYS_EXIT: + ret_val = sys_exit((int)arg1); + break; + + case SYS_FORK: + ret_val = sys_fork(); + break; + + case SYS_VFORK: + ret_val = sys_vfork(); + break; + + case SYS_WAIT: + ret_val = sys_wait((int*)arg1); + break; + + case SYS_WAITPID: + ret_val = sys_waitpid((pid_t)arg1, (int*)arg2, (int)arg3); + break; + + case SYS_WAITID: + ret_val = -ENOSYS; + break; + + case SYS_SETSID: + ret_val = sys_setsid(); + break; + + default: + ret_val = -EOPNOTSUPP; + break; + } + + return(ret_val); +} + +#endif /* FEATURE(POSIX) */ diff --git a/libc/posixcall.S b/libc/posixcall.S new file mode 100644 index 0000000..6aecef1 --- /dev/null +++ b/libc/posixcall.S @@ -0,0 +1,85 @@ +#define __ASSEMBLY_SOURCE + +#include +#include + +/* FIXME: Add syscall stubs for amd64/Intel64 */ + +.global fork +fork: + pushl %ebx + + movl $SYS_FORK, %eax + int $SYSCALL_POSIX + + popl %ebx + ret + +.global vfork +vfork: + pushl %ebx + + movl $SYS_VFORK, %eax + int $SYSCALL_POSIX + + popl %ebx + ret + +.global exit +exit: + pushl %ebx + + movl $SYS_EXIT, %eax + movl 8(%esp), %ebx + int $SYSCALL_POSIX + + popl %ebx + ret + +.global wait +wait: + pushl %ebx + + movl $SYS_WAIT, %eax + movl 8(%esp), %ebx + int $SYSCALL_POSIX + + popl %ebx + ret + +.global waitpid +waitpid: + pushl %ebx + + movl $SYS_WAITPID, %eax + movl 8(%esp), %ebx + movl 12(%esp), %ecx + movl 16(%esp), %edx + int $SYSCALL_POSIX + + popl %ebx + ret + +.global waitid +waitid: + pushl %ebx + + movl $SYS_WAITID, %eax + movl 8(%esp), %ebx + movl 12(%esp), %ecx + movl 16(%esp), %edx + movl 20(%esp), %esi + int $SYSCALL_POSIX + + popl %ebx + ret + +.global setsid +setsid: + pushl %ebx + + movl $SYS_SETSID, %eax + int $SYSCALL_POSIX + + popl %ebx + ret