From f44b80c3f0004418c4953f0a2f32f7bec2e26e36 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 8 Sep 2021 19:45:50 +0200 Subject: process struct: replace the generic saved_addr with an union --- src/kernel/proc.h | 12 +++++++----- src/kernel/syscalls.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/proc.h b/src/kernel/proc.h index 0efccde..5d9e7eb 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -24,11 +24,13 @@ struct process { uint32_t id; // only for debugging, don't expose to userland - // meaning changes depending on the state - // PS_DEAD - death message - // PS_WAITS4CHILDDEATH - buffer for said message - user_ptr saved_addr; - size_t saved_len; + // saved value, meaning depends on .state + union { + struct { // PS_DEAD, PS_WAITS4CHILDDEATH + user_ptr buf; + size_t len; + } death_msg; + }; struct vfs_mount *mount; diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index ddc3d4b..124333a 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -17,11 +17,11 @@ _Noreturn static void await_finish(struct process *dead, struct process *listene dead->state = PS_DEADER; listener->state = PS_RUNNING; - len = listener->saved_len < dead->saved_len - ? listener->saved_len : dead->saved_len; + len = listener->death_msg.len < dead->death_msg.len + ? listener->death_msg.len : dead->death_msg.len; res = virt_cpy( - listener->pages, listener->saved_addr, - dead->pages, dead->saved_addr, len); + listener->pages, listener->death_msg.buf, + dead->pages, dead->death_msg.buf, len); regs_savereturn(&listener->regs, res ? len : -1); process_switch(listener); } @@ -29,8 +29,8 @@ _Noreturn static void await_finish(struct process *dead, struct process *listene _Noreturn void _syscall_exit(const user_ptr msg, size_t len) { process_current->state = PS_DEAD; - process_current->saved_addr = msg; - process_current->saved_len = len; + process_current->death_msg.buf = msg; + process_current->death_msg.len = len; if (process_current->parent->state == PS_WAITS4CHILDDEATH) await_finish(process_current, process_current->parent); @@ -44,8 +44,8 @@ _Noreturn void _syscall_exit(const user_ptr msg, size_t len) { int _syscall_await(user_ptr buf, int len) { process_current->state = PS_WAITS4CHILDDEATH; - process_current->saved_addr = buf; - process_current->saved_len = len; + process_current->death_msg.buf = buf; + process_current->death_msg.len = len; // find any already dead children for (struct process *iter = process_current->child; -- cgit v1.2.3