mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
Kernel: Process destruction should destroy all child threads.
We were only destroying the main thread when a process died, leaving any secondary threads around. They couldn't run, but because they were still in the global thread list, strange things could happen since they had some now-stale pointers to their old process.
This commit is contained in:
parent
e2cd572e60
commit
c5c4e54a67
2 changed files with 19 additions and 2 deletions
|
@ -278,7 +278,16 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
|||
|
||||
dbgprintf("%s(%d) do_exec: thread_count() = %d\n", m_name.characters(), m_pid, thread_count());
|
||||
// FIXME(Thread): Kill any threads the moment we commit to the exec().
|
||||
if (thread_count() != 1) {
|
||||
dbgprintf("Gonna die because I have many threads! These are the threads:\n");
|
||||
for_each_thread([] (Thread& thread) {
|
||||
dbgprintf("Thread{%p}: TID=%d, PID=%d\n", &thread, thread.tid(), thread.pid());
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
ASSERT(thread_count() == 1);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
|
||||
auto parts = path.split('/');
|
||||
if (parts.is_empty())
|
||||
|
@ -605,6 +614,14 @@ Process::~Process()
|
|||
dbgprintf("~Process{%p} name=%s pid=%d, m_fds=%d\n", this, m_name.characters(), pid(), m_fds.size());
|
||||
delete m_main_thread;
|
||||
m_main_thread = nullptr;
|
||||
|
||||
Vector<Thread*, 16> my_threads;
|
||||
for_each_thread([&my_threads] (auto& thread) {
|
||||
my_threads.append(&thread);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
for (auto* thread : my_threads)
|
||||
delete thread;
|
||||
}
|
||||
|
||||
void Process::dump_regions()
|
||||
|
|
|
@ -12,7 +12,7 @@ Thread::Thread(Process& process)
|
|||
: m_process(process)
|
||||
, m_tid(process.m_next_tid++)
|
||||
{
|
||||
dbgprintf("Thread: New thread TID=%u in %s(%u)\n", m_tid, process.name().characters(), process.pid());
|
||||
dbgprintf("Thread{%p}: New thread TID=%u in %s(%u)\n", this, m_tid, process.name().characters(), process.pid());
|
||||
set_default_signal_dispositions();
|
||||
m_fpu_state = (FPUState*)kmalloc_aligned(sizeof(FPUState), 16);
|
||||
memset(&m_tss, 0, sizeof(m_tss));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue