From cef4c8d98221b3f423a9662cdf8602e1943351cc Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 1 Oct 2014 19:17:49 +0200 Subject: [PATCH] Fix waitpid status copying to user-space. --- kernel/process.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kernel/process.cpp b/kernel/process.cpp index 6cf05463..6031e674 100644 --- a/kernel/process.cpp +++ b/kernel/process.cpp @@ -457,10 +457,11 @@ void Process::NotifyNewZombies() kthread_cond_broadcast(&zombiecond); } -pid_t Process::Wait(pid_t thepid, int* user_status, int options) +pid_t Process::Wait(pid_t thepid, int* status_ptr, int options) { // TODO: Process groups are not supported yet. - if ( thepid < -1 || thepid == 0 ) { errno = ENOSYS; return -1; } + if ( thepid < -1 || thepid == 0 ) + return errno = ENOSYS, -1; ScopedLock lock(&childlock); @@ -530,15 +531,19 @@ pid_t Process::Wait(pid_t thepid, int* user_status, int options) if ( !in_limbo ) delete zombie; - if ( user_status && !CopyToUser(user_status, &status, sizeof(status)) ) - return -1; + if ( status_ptr ) + *status_ptr = status; return thepid; } static pid_t sys_waitpid(pid_t pid, int* user_status, int options) { - return CurrentProcess()->Wait(pid, user_status, options); + int status = 0; + pid_t ret = CurrentProcess()->Wait(pid, &status, options); + if ( 0 < ret && !CopyToUser(user_status, &status, sizeof(status)) ) + return -1; + return ret; } void Process::ExitThroughSignal(int signal)