]> git.corax.cc Git - corax/commitdiff
Add syscall stubs for some POSIX process management syscalls (fork, vfork, exit,...
authorMatthias Kruk <m@m10k.eu>
Mon, 28 Oct 2019 09:33:46 +0000 (18:33 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 28 Oct 2019 09:34:35 +0000 (18:34 +0900)
include/corax/syscall.h
kernel/arch/interrupt.c
kernel/core/Makefile
kernel/core/posixcall.c [new file with mode: 0644]
libc/posixcall.S [new file with mode: 0644]

index 24f2c1f39f83c6bc947d85f99e101680f4c1ce59..083258adf4a7abfe7e891c0623e61dc5fa236dad 100644 (file)
 #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
index 7cee95f04ed59434c94c280701f482f1adc2c14e..346e404d0b58b57a1e50aa22ebf80e09455dd1a4 100644 (file)
@@ -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) */
 
index e1c8b78675f5c29b10342952340ba25262259d05..298be61d60d2479d1a3bc836662764893f27b02f 100644 (file)
@@ -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 (file)
index 0000000..7223ed3
--- /dev/null
@@ -0,0 +1,82 @@
+#include <config.h>
+
+#if FEATURE(POSIX)
+
+#include <corax/errno.h>
+#include <corax/syscall.h>
+#include <corax/types.h>
+
+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 (file)
index 0000000..6aecef1
--- /dev/null
@@ -0,0 +1,85 @@
+#define __ASSEMBLY_SOURCE
+
+#include <config.h>
+#include <corax/syscall.h>
+
+/* 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