mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 06:28: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();
|
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
|
// for safety
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -4,6 +4,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <kernel/event.h>
|
#include <kernel/event.h>
|
||||||
#include <kernel/alloc.h>
|
#include <kernel/alloc.h>
|
||||||
|
#include <arch/interrupt.h>
|
||||||
|
|
||||||
void syscall_exit(int status){
|
void syscall_exit(int status){
|
||||||
proc_t* proc = arch_getcls()->thread->proc;
|
proc_t* proc = arch_getcls()->thread->proc;
|
||||||
@@ -44,10 +45,17 @@ void syscall_exit(int status){
|
|||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&init->lock);
|
spinlock_release(&init->lock);
|
||||||
spinlock_release(&proc->lock);
|
|
||||||
|
|
||||||
event_signal(&proc->parent->childevent, true);
|
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();
|
sched_dequeue();
|
||||||
|
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
|
|||||||
@@ -38,25 +38,24 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
|||||||
proc_t* proc = arch_getcls()->thread->proc;
|
proc_t* proc = arch_getcls()->thread->proc;
|
||||||
|
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
|
|
||||||
|
|
||||||
proc_t* child;
|
proc_t* child;
|
||||||
proc_t* sibling;
|
proc_t* sibling;
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
|
|
||||||
child = proc->child;
|
|
||||||
sibling = NULL;
|
|
||||||
|
|
||||||
// now find the child
|
// now find the child
|
||||||
|
|
||||||
spinlock_acquire(&proc->lock);
|
spinlock_acquire(&proc->lock);
|
||||||
|
child = proc->child;
|
||||||
|
sibling = NULL;
|
||||||
|
|
||||||
while(child){
|
while(child){
|
||||||
if(pid > 0 && child->pid != pid)
|
if(pid > 0 && child->pid != pid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(child->state == PROC_STATE_ZOMBIE){
|
if(child->state == PROC_STATE_ZOMBIE){
|
||||||
|
loop = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +89,9 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
|||||||
sibling->sibling = child->sibling;
|
sibling->sibling = child->sibling;
|
||||||
spinlock_release(&sibling->lock);
|
spinlock_release(&sibling->lock);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
proc->child = child->sibling;
|
||||||
|
}
|
||||||
|
|
||||||
*status = child->status; // XXX safer way of doing this
|
*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;
|
thread_t* thread = child->threads;
|
||||||
|
|
||||||
// TODO free ctx
|
// TODO free ctx
|
||||||
|
|
||||||
free(thread->regs);
|
free(thread->regs);
|
||||||
free(thread->kernelstackbase);
|
free(thread->kernelstackbase);
|
||||||
free(thread);
|
free(thread);
|
||||||
@@ -106,7 +107,6 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
|
|||||||
|
|
||||||
retv.ret = child->pid;
|
retv.ret = child->pid;
|
||||||
retv.errno = 0;
|
retv.errno = 0;
|
||||||
|
|
||||||
return retv;
|
return retv;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user