mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
process removal: remove a few bugs and race conditions
This commit is contained in:
@@ -362,13 +362,6 @@ void sched_dequeue(){
|
||||
|
||||
timer_resume();
|
||||
|
||||
thread_t* curthread = arch_getcls()->thread;
|
||||
|
||||
// context and thread destruction will happen in the waitpid()
|
||||
// the pointer to this thread will reside in proc->threads
|
||||
|
||||
curthread->proc->threads = curthread;
|
||||
|
||||
// for safety
|
||||
|
||||
|
||||
|
||||
+10
-2
@@ -4,6 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <kernel/event.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <arch/interrupt.h>
|
||||
|
||||
void syscall_exit(int status){
|
||||
proc_t* proc = arch_getcls()->thread->proc;
|
||||
@@ -44,10 +45,17 @@ void syscall_exit(int status){
|
||||
}
|
||||
|
||||
spinlock_release(&init->lock);
|
||||
spinlock_release(&proc->lock);
|
||||
|
||||
event_signal(&proc->parent->childevent, true);
|
||||
|
||||
// context and thread destruction will happen in the waitpid()
|
||||
// the pointer to this thread will reside in proc->threads
|
||||
|
||||
proc->threads = arch_getcls()->thread;
|
||||
|
||||
arch_interrupt_disable();
|
||||
|
||||
spinlock_release(&proc->lock);
|
||||
|
||||
sched_dequeue();
|
||||
|
||||
__builtin_unreachable();
|
||||
|
||||
@@ -38,25 +38,24 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
||||
proc_t* proc = arch_getcls()->thread->proc;
|
||||
|
||||
bool loop = true;
|
||||
|
||||
|
||||
|
||||
proc_t* child;
|
||||
proc_t* sibling;
|
||||
|
||||
while(1){
|
||||
|
||||
child = proc->child;
|
||||
sibling = NULL;
|
||||
|
||||
// now find the child
|
||||
|
||||
spinlock_acquire(&proc->lock);
|
||||
|
||||
child = proc->child;
|
||||
sibling = NULL;
|
||||
|
||||
while(child){
|
||||
if(pid > 0 && child->pid != pid)
|
||||
continue;
|
||||
|
||||
if(child->state == PROC_STATE_ZOMBIE){
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -90,6 +89,9 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
||||
sibling->sibling = child->sibling;
|
||||
spinlock_release(&sibling->lock);
|
||||
}
|
||||
else{
|
||||
proc->child = child->sibling;
|
||||
}
|
||||
|
||||
*status = child->status; // XXX safer way of doing this
|
||||
|
||||
@@ -98,7 +100,6 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
||||
thread_t* thread = child->threads;
|
||||
|
||||
// TODO free ctx
|
||||
|
||||
free(thread->regs);
|
||||
free(thread->kernelstackbase);
|
||||
free(thread);
|
||||
@@ -106,7 +107,6 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
||||
|
||||
retv.ret = child->pid;
|
||||
retv.errno = 0;
|
||||
|
||||
return retv;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user