Compare commits

..

2 Commits

Author SHA1 Message Date
9c3792718c Kernel: Remove waitpid() debug messages and add more checks 2022-10-30 19:24:56 +01:00
e244c150c2 Kernel, libc: Add ECHILD 2022-10-30 19:24:26 +01:00
4 changed files with 12 additions and 4 deletions

View File

@ -7,6 +7,7 @@
#define E2BIG 7
#define ENOEXEC 8
#define EBADF 9
#define ECHILD 10
#define EAGAIN 11
#define ENOMEM 12
#define EACCES 13

View File

@ -510,10 +510,16 @@ void sys_waitpid(Context* context, long pid, int* wstatus,
child = Scheduler::find_by_pid(pid);
if (!child)
{
context->rax = -ESRCH;
context->rax = -ECHILD;
return;
}
}
if (child->ppid != sched_current_task->id)
{
// We are trying to call waitpid() on a task that isn't a child of ours. This is not allowed.
context->rax = -ECHILD;
return;
}
if (child->state != child->Dying)
{
if (options & WNOHANG)
@ -531,7 +537,6 @@ void sys_waitpid(Context* context, long pid, int* wstatus,
return;
}
}
kdbgln("blocking wait on pid %ld", pid);
sched_current_task->state = sched_current_task->Blocking;
sched_current_task->block_reason = BlockReason::Waiting;
sched_current_task->blocking_wait_info.wait_pid = pid;
@ -583,6 +588,8 @@ bool Task::is_wait_still_blocking()
else
{
child = Scheduler::find_by_pid(blocking_wait_info.wait_pid);
ASSERT(child); // since sys_waitpid should have validated this child, and the only way for it to disappear from
// the process list is for someone to wait for it, this should be pretty safe.
if (child->state != child->Dying) return true;
else
return false;
@ -596,8 +603,6 @@ void Task::resume_wait()
Task* child = Scheduler::find_by_pid(blocking_wait_info.wait_pid);
ASSERT(child); // This should also already have been validated.
kdbgln("resuming wait on child %ld", child->id);
if (blocking_wait_info.wstatus)
{
*blocking_wait_info.wstatus = (int)(child->exit_status & 0xff);

View File

@ -12,6 +12,7 @@ extern int errno;
#define E2BIG 7 // Argument list too long
#define ENOEXEC 8 // Exec format error
#define EBADF 9 // Bad file descriptor
#define ECHILD 10 // No child processes
#define EAGAIN 11 // Resource temporarily unavailable
#define ENOMEM 12 // Cannot allocate memory
#define EACCES 13 // Permission denied

View File

@ -265,6 +265,7 @@ extern "C"
case E2BIG: return "Argument list too long";
case ENOEXEC: return "Exec format error";
case EBADF: return "Bad file descriptor";
case ECHILD: return "No child processes";
case EAGAIN: return "Resource temporarily unavailable";
case ENOMEM: return "Cannot allocate memory";
case EACCES: return "Permission denied";