From 9d05f6b7a797ed3424bc5d0024d21e496bb4c87b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Nov 2018 00:11:08 +0100 Subject: Make bash-2.05b build with minimal changes. This is really neat. :^) --- Kernel/Process.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'Kernel/Process.cpp') diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 29a63cb669..3a7b2b5655 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -24,7 +24,7 @@ #define SIGNAL_DEBUG #define MAX_PROCESS_GIDS 32 -static const DWORD defaultStackSize = 16384; +static const dword defaultStackSize = 16384; static pid_t next_pid; InlineLinkedList* g_processes; @@ -663,7 +663,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring if (isRing3()) { // Ring3 processes need a separate stack for Ring0. m_kernelStack = kmalloc(defaultStackSize); - m_stackTop0 = ((DWORD)m_kernelStack + defaultStackSize) & 0xffffff8; + m_stackTop0 = ((dword)m_kernelStack + defaultStackSize) & 0xffffff8; m_tss.ss0 = 0x10; m_tss.esp0 = m_stackTop0; } @@ -1414,7 +1414,7 @@ void Process::reap(Process& process) pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) { - //kprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options); + dbgprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options); // FIXME: Respect options (void) options; if (wstatus) @@ -1426,6 +1426,31 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) if (waitee != -1 && !Process::from_pid(waitee)) return -ECHILD; } + + if (options & WNOHANG) { + if (waitee == -1) { + pid_t reaped_pid = 0; + InterruptDisabler disabler; + for_each_child([&reaped_pid] (Process& process) { + if (process.state() == Dead) { + reaped_pid = process.pid(); + reap(process); + } + return true; + }); + return reaped_pid; + } else { + auto* waitee_process = Process::from_pid(waitee); + if (!waitee_process) + return -ECHILD; + if (waitee_process->state() == Dead) { + reap(*waitee_process); + return waitee; + } + return 0; + } + } + m_waitee = waitee; m_waitee_status = 0; block(BlockedWait); @@ -1470,7 +1495,7 @@ void block(Process::State state) sched_yield(); } -void sleep(DWORD ticks) +void sleep(dword ticks) { ASSERT(current->state() == Process::Running); current->setWakeupTime(system.uptime + ticks); -- cgit v1.2.3