mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
waitpid: implement WSTOPPED and WCONTINUED
This commit is contained in:
@@ -55,6 +55,7 @@ typedef struct thread_t {
|
|||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
sigset_t pending;
|
sigset_t pending;
|
||||||
sigset_t urgent;
|
sigset_t urgent;
|
||||||
|
bool stopped;
|
||||||
} signals;
|
} signals;
|
||||||
} thread_t;
|
} thread_t;
|
||||||
|
|
||||||
@@ -108,6 +109,8 @@ typedef struct proc_t {
|
|||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
sigaction_t actions[NSIG];
|
sigaction_t actions[NSIG];
|
||||||
sigset_t pending;
|
sigset_t pending;
|
||||||
|
bool stopunwaited;
|
||||||
|
bool continueunwaited;
|
||||||
} signals;
|
} signals;
|
||||||
} proc_t;
|
} proc_t;
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO address check
|
// TODO address check
|
||||||
// TODO implement these
|
|
||||||
__assert((options & ~KNOWN_FLAGS) == 0);
|
__assert((options & ~KNOWN_FLAGS) == 0);
|
||||||
|
// TODO implement these
|
||||||
__assert(pid == -1 || pid > 0);
|
__assert(pid == -1 || pid > 0);
|
||||||
|
|
||||||
thread_t *thread = _cpu()->thread;
|
thread_t *thread = _cpu()->thread;
|
||||||
@@ -33,6 +33,10 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool continued = false;
|
||||||
|
bool stopped = false;
|
||||||
|
bool zombie = false;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (iterator == NULL) {
|
if (iterator == NULL) {
|
||||||
if (pid > 0 && desired == NULL) {
|
if (pid > 0 && desired == NULL) {
|
||||||
@@ -59,28 +63,46 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
|
|||||||
if (pid > 0 && iterator->pid == pid)
|
if (pid > 0 && iterator->pid == pid)
|
||||||
desired = iterator;
|
desired = iterator;
|
||||||
|
|
||||||
if (iterator->state == SCHED_PROC_STATE_ZOMBIE)
|
bool intstatus = interrupt_set(false);
|
||||||
|
spinlock_acquire(&iterator->signals.lock);
|
||||||
|
if (iterator->signals.continueunwaited && (options & WCONTINUED)) {
|
||||||
|
iterator->signals.continueunwaited = false;
|
||||||
|
continued = true;
|
||||||
|
}
|
||||||
|
if (iterator->signals.stopunwaited && (options & WSTOPPED)) {
|
||||||
|
iterator->signals.stopunwaited = false;
|
||||||
|
stopped = true;
|
||||||
|
}
|
||||||
|
spinlock_release(&iterator->signals.lock);
|
||||||
|
interrupt_set(intstatus);
|
||||||
|
|
||||||
|
zombie = iterator->state == SCHED_PROC_STATE_ZOMBIE;
|
||||||
|
|
||||||
|
if (zombie || continued || stopped)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
prev = iterator;
|
prev = iterator;
|
||||||
iterator = iterator->sibling;
|
iterator = iterator->sibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterator has the zombie child
|
// iterator has the waited child
|
||||||
|
if (zombie) {
|
||||||
if (prev)
|
// remove process from child list if zombie
|
||||||
prev->sibling = iterator->sibling;
|
if (prev)
|
||||||
else
|
prev->sibling = iterator->sibling;
|
||||||
proc->child = iterator->sibling;
|
else
|
||||||
|
proc->child = iterator->sibling;
|
||||||
MUTEX_RELEASE(&proc->mutex);
|
}
|
||||||
|
|
||||||
// TODO memory safe operation
|
// TODO memory safe operation
|
||||||
if (status) {
|
if (status) {
|
||||||
*status = iterator->status;
|
int statustmp = iterator->status;
|
||||||
|
*status = statustmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < iterator->threadtablesize; ++i) {
|
MUTEX_RELEASE(&proc->mutex);
|
||||||
|
|
||||||
|
for (int i = 0; i < iterator->threadtablesize && zombie; ++i) {
|
||||||
if (iterator->threads[i] == NULL)
|
if (iterator->threads[i] == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -97,6 +119,9 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
|
|||||||
|
|
||||||
__assert(iterator);
|
__assert(iterator);
|
||||||
// process will no longer be referenced by the child list
|
// process will no longer be referenced by the child list
|
||||||
PROC_RELEASE(iterator);
|
if (zombie) {
|
||||||
|
PROC_RELEASE(iterator);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user