diff options
-rw-r--r-- | src/cmd/init/init.c | 4 | ||||
-rw-r--r-- | src/kernel/proc.c | 9 | ||||
-rw-r--r-- | src/kernel/proc.h | 2 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 16 | ||||
-rw-r--r-- | src/kernel/vfs/procfs.c | 4 | ||||
-rw-r--r-- | src/libc/syscall.c | 4 | ||||
-rw-r--r-- | src/libk/include/camellia/syscalls.h | 2 | ||||
-rw-r--r-- | src/libk/include/limits.h | 1 |
8 files changed, 31 insertions, 11 deletions
diff --git a/src/cmd/init/init.c b/src/cmd/init/init.c index 7f26f1b..5c49281 100644 --- a/src/cmd/init/init.c +++ b/src/cmd/init/init.c @@ -34,7 +34,7 @@ void redirect(const char *exe, const char *out, const char *in) { exit(1); } _sys_await(); - _sys_intr(); + _sys_intr(NULL, 0); _sys_sleep(1000); } } @@ -42,7 +42,7 @@ void redirect(const char *exe, const char *out, const char *in) { void shutdown(void) { printf("[init] intr\n"); - _sys_intr(); + _sys_intr(NULL, 0); _sys_sleep(1000); printf("[init] filicide\n"); _sys_filicide(); diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 0ce0f50..dc17af2 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -382,7 +382,14 @@ void proc_tryintr(Proc *p) { } } -void proc_intr(Proc *p) { +void proc_intr(Proc *p, const char *buf, size_t len) { + assert(buf != NULL || len == 0); + + if (4 <= len && memcmp(buf, "kill", 4) == 0) { + proc_kill(p, EINTR); + return; + } + if (!p->intr_fn) return; proc_tryintr(p); diff --git a/src/kernel/proc.h b/src/kernel/proc.h index d437b8c..2261f85 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -123,7 +123,7 @@ void proc_tryreap(Proc *dead); void proc_tryintr(Proc *p); /** Send an interupt to a process. */ -void proc_intr(Proc *proc); +void proc_intr(Proc *p, const char *buf, size_t len); /** Switches execution to any running process. */ _Noreturn void proc_switch_any(void); diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 8ff5112..edc74bb 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -356,10 +356,20 @@ void _sys_filicide(void) { } } -void _sys_intr(void) { +int _sys_intr(const char __user *msg, size_t len) { + char buf[INTR_MAX]; + int count = 0; + if (INTR_MAX < len) { + SYSCALL_RETURN(-EINVAL); + } + if (pcpy_from(proc_cur, buf, msg, len) < len) { + SYSCALL_RETURN(-EFAULT); + } for (Proc *p = proc_cur->child; p; p = proc_next(p, proc_cur)) { - proc_intr(p); + proc_intr(p, buf, len); + count++; } + SYSCALL_RETURN(count); } void _sys_intr_set(void __user *ip) { @@ -481,7 +491,7 @@ long _syscall(long num, long a, long b, long c, long d, long e) { break; case _SYS_PIPE: _sys_pipe((userptr_t)a, b); break; case _SYS_SLEEP: _sys_sleep(a); break; case _SYS_FILICIDE: _sys_filicide(); - break; case _SYS_INTR: _sys_intr(); + break; case _SYS_INTR: _sys_intr((userptr_t)a, b); break; case _SYS_INTR_SET: _sys_intr_set((userptr_t)a); break; case _SYS_GETPID: _sys_getpid(); break; case _SYS_GETPPID: _sys_getppid(); diff --git a/src/kernel/vfs/procfs.c b/src/kernel/vfs/procfs.c index 7ba43d8..5031840 100644 --- a/src/kernel/vfs/procfs.c +++ b/src/kernel/vfs/procfs.c @@ -146,7 +146,9 @@ procfs_accept(VfsReq *req) ); vfsreq_finish_short(req, res); } else if (req->type == VFSOP_WRITE && h->type == PhIntr) { - proc_intr(p); + size_t len = min(sizeof buf, req->input.len); + len = pcpy_from(req->caller, buf, req->input.buf, len); + proc_intr(p, buf, len); vfsreq_finish_short(req, req->input.len); } else { vfsreq_finish_short(req, -ENOSYS); diff --git a/src/libc/syscall.c b/src/libc/syscall.c index 4cdbe6c..782b2fe 100644 --- a/src/libc/syscall.c +++ b/src/libc/syscall.c @@ -70,8 +70,8 @@ void _sys_filicide(void) { return (void)_syscall(_SYS_FILICIDE, 0, 0, 0, 0, 0); } -void _sys_intr(void) { - return (void)_syscall(_SYS_INTR, 0, 0, 0, 0, 0); +int _sys_intr(const char __user *msg, size_t len) { + return (int)_syscall(_SYS_INTR, (long)msg, (long)len, 0, 0, 0); } void _sys_intr_set(void __user *ip) { diff --git a/src/libk/include/camellia/syscalls.h b/src/libk/include/camellia/syscalls.h index d27ae0c..c7e2f10 100644 --- a/src/libk/include/camellia/syscalls.h +++ b/src/libk/include/camellia/syscalls.h @@ -75,7 +75,7 @@ long _sys_pipe(hid_t __user user_ends[2], int flags); void _sys_sleep(long ms); void _sys_filicide(void); -void _sys_intr(void); +int _sys_intr(const char __user *msg, size_t len); void _sys_intr_set(void __user *ip); uint32_t _sys_getpid(void); diff --git a/src/libk/include/limits.h b/src/libk/include/limits.h index 4cb972d..f0f028c 100644 --- a/src/libk/include/limits.h +++ b/src/libk/include/limits.h @@ -3,3 +3,4 @@ #define NAME_MAX 255 #define PATH_MAX 512 #define _POSIX2_RE_DUP_MAX 255 +#define INTR_MAX 64 |