From 191c47396747e54457510c7e126b6ba098fefbbd Mon Sep 17 00:00:00 2001 From: Minep Date: Mon, 20 Jun 2022 17:19:11 +0100 Subject: [PATCH] feat: pause(2) support --- lunaix-os/includes/lunaix/lunistd.h | 2 ++ lunaix-os/includes/lunaix/process.h | 3 +++ lunaix-os/includes/lunaix/status.h | 2 ++ lunaix-os/includes/lunaix/syscall.h | 15 ++++++++++----- lunaix-os/kernel/asm/x86/syscall.S | 1 + lunaix-os/kernel/lxinit.c | 1 + lunaix-os/kernel/signal.c | 15 +++++++++++++++ 7 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lunaix-os/includes/lunaix/lunistd.h b/lunaix-os/includes/lunaix/lunistd.h index 42c4320..7a1c368 100644 --- a/lunaix-os/includes/lunaix/lunistd.h +++ b/lunaix-os/includes/lunaix/lunistd.h @@ -18,4 +18,6 @@ __LXSYSCALL1(void, _exit, int, status) __LXSYSCALL1(unsigned int, sleep, unsigned int, seconds) +__LXSYSCALL(int, pause) + #endif /* __LUNAIX_UNISTD_H */ diff --git a/lunaix-os/includes/lunaix/process.h b/lunaix-os/includes/lunaix/process.h index 7a5d502..2cd4330 100644 --- a/lunaix-os/includes/lunaix/process.h +++ b/lunaix-os/includes/lunaix/process.h @@ -21,6 +21,8 @@ #define PROC_TERMMASK 0x6 +#define PROC_FINPAUSE 1 + struct proc_mm { heap_context_t u_heap; @@ -64,6 +66,7 @@ struct proc_info int32_t k_status; sigset_t sig_pending; sigset_t sig_mask; + int flags; void* sig_handler[_SIG_NUM]; pid_t pgid; struct lx_timer* timer; diff --git a/lunaix-os/includes/lunaix/status.h b/lunaix-os/includes/lunaix/status.h index f3309ab..aeef93e 100644 --- a/lunaix-os/includes/lunaix/status.h +++ b/lunaix-os/includes/lunaix/status.h @@ -9,4 +9,6 @@ #define LXSEGFAULT -(5) #define LXINVL -(6) +#define EINTR -(7) + #endif /* __LUNAIX_CODE_H */ diff --git a/lunaix-os/includes/lunaix/syscall.h b/lunaix-os/includes/lunaix/syscall.h index 3a6e2eb..f695cf7 100644 --- a/lunaix-os/includes/lunaix/syscall.h +++ b/lunaix-os/includes/lunaix/syscall.h @@ -33,11 +33,6 @@ syscall_install(); #define __PARAM_MAP5(t1, p1, ...) t1 p1, __PARAM_MAP4(__VA_ARGS__) #define __PARAM_MAP6(t1, p1, ...) t1 p1, __PARAM_MAP5(__VA_ARGS__) -#define ___DOINT33(callcode, rettype) \ - int v; \ - asm volatile("int %1\n" : "=a"(v) : "i"(LUNAIX_SYS_CALL), "a"(callcode)); \ - return (rettype)v; - #define __DEFINE_LXSYSCALL(rettype, name) asmlinkage rettype __lxsys_##name() #define __DEFINE_LXSYSCALL1(rettype, name, t1, p1) \ @@ -53,6 +48,16 @@ syscall_install(); asmlinkage rettype __lxsys_##name( \ __PARAM_MAP4(t1, p1, t2, p2, t3, p3, t4, p4)) +#define __SYSCALL_INTERRUPTIBLE(code) \ + asm("sti"); \ + { code }; \ + asm("cli"); + +#define ___DOINT33(callcode, rettype) \ + int v; \ + asm volatile("int %1\n" : "=a"(v) : "i"(LUNAIX_SYS_CALL), "a"(callcode)); \ + return (rettype)v; + #define __LXSYSCALL(rettype, name) \ static rettype name() \ { \ diff --git a/lunaix-os/kernel/asm/x86/syscall.S b/lunaix-os/kernel/asm/x86/syscall.S index e97cc6f..0922a96 100644 --- a/lunaix-os/kernel/asm/x86/syscall.S +++ b/lunaix-os/kernel/asm/x86/syscall.S @@ -21,6 +21,7 @@ .long __lxsys_sigreturn .long __lxsys_sigprocmask .long __lxsys_signal + .long __lxsys_pause 2: .rept __SYSCALL_MAX - (2b - 1b)/4 .long 0 diff --git a/lunaix-os/kernel/lxinit.c b/lunaix-os/kernel/lxinit.c index 1485c34..2de87c5 100644 --- a/lunaix-os/kernel/lxinit.c +++ b/lunaix-os/kernel/lxinit.c @@ -50,6 +50,7 @@ _lxinit_main() kprintf("I am child, I am about to terminated\n"); _exit(1); } + pause(); pid_t child = wait(&status); kprintf("I am parent, my child (%d) terminated normally with code: %d.\n", child, diff --git a/lunaix-os/kernel/signal.c b/lunaix-os/kernel/signal.c index 49f1e53..80a7098 100644 --- a/lunaix-os/kernel/signal.c +++ b/lunaix-os/kernel/signal.c @@ -1,6 +1,7 @@ #include #include #include +#include #include extern struct scheduler sched_ctx; /* kernel/sched.c */ @@ -62,6 +63,7 @@ __DEFINE_LXSYSCALL1(int, sigreturn, struct proc_sig, *sig_ctx) { __current->intr_ctx = sig_ctx->prev_context; __current->sig_mask &= ~__SIGNAL(sig_ctx->sig_num); + __current->flags &= ~PROC_FINPAUSE; schedule(); } @@ -101,4 +103,17 @@ __DEFINE_LXSYSCALL2(int, signal, int, signum, sighandler_t, handler) __current->sig_handler[signum] = (void*)handler; return 0; +} + +__DEFINE_LXSYSCALL(int, pause) +{ + __current->flags |= PROC_FINPAUSE; + + __SYSCALL_INTERRUPTIBLE({ + while ((__current->flags & PROC_FINPAUSE)) { + sched_yield(); + } + }) + __current->k_status = EINTR; + return -1; } \ No newline at end of file -- 2.27.0