[kernel] Fix current thread deletion bug

Defer from calling process::thread_exited() in scheduler::prune() if the
thread in question is the currently-executing thread, so that we don't
blow away the stack we're executing on. The next call to prune will pick
up the exited thread.
This commit is contained in:
2020-09-06 15:01:24 -07:00
parent 42455873ff
commit 53a4682418
2 changed files with 7 additions and 1 deletions

View File

@@ -45,6 +45,8 @@ inline uintptr_t end(frame_block *node) { return node->address + node->count * f
void void
frame_allocator::free(uintptr_t address, size_t count) frame_allocator::free(uintptr_t address, size_t count)
{ {
kassert(address % frame_size == 0, "Trying to free a non page-aligned frame!");
frame_block_node *node = frame_block_node *node =
reinterpret_cast<frame_block_node*>(address + page_offset); reinterpret_cast<frame_block_node*>(address + page_offset);

View File

@@ -241,6 +241,7 @@ void scheduler::prune(uint64_t now)
bool ready = th->has_state(thread::state::ready); bool ready = th->has_state(thread::state::ready);
bool exited = th->has_state(thread::state::exited); bool exited = th->has_state(thread::state::exited);
bool constant = th->has_state(thread::state::constant); bool constant = th->has_state(thread::state::constant);
bool current = tcb == m_current;
ready |= th->wake_on_time(now); ready |= th->wake_on_time(now);
@@ -253,7 +254,10 @@ void scheduler::prune(uint64_t now)
if (exited) { if (exited) {
process &p = th->parent(); process &p = th->parent();
if(p.thread_exited(th))
// If the current thread has exited, wait until the next call
// to prune() to delete it.
if(!current && p.thread_exited(th))
delete &p; delete &p;
} else { } else {
log::debug(logs::task, "Prune: readying unblocked thread %llx", th->koid()); log::debug(logs::task, "Prune: readying unblocked thread %llx", th->koid());