Kernel: Fix Process::exit() and where it is called from

cksum doesn't seem to work anymore on big files. I have to look
into this. It locks up after couple of seconds...
This commit is contained in:
Bananymous 2023-04-19 12:51:20 +03:00
parent 67e0c21e0f
commit 6f65453fd4
2 changed files with 16 additions and 4 deletions

View File

@ -1,5 +1,4 @@
#include <BAN/StringView.h> #include <BAN/StringView.h>
#include <kernel/CriticalScope.h>
#include <kernel/FS/VirtualFileSystem.h> #include <kernel/FS/VirtualFileSystem.h>
#include <kernel/LockGuard.h> #include <kernel/LockGuard.h>
#include <kernel/Memory/MMU.h> #include <kernel/Memory/MMU.h>
@ -61,7 +60,8 @@ namespace Kernel
Process::~Process() Process::~Process()
{ {
exit(); if (!m_threads.empty())
exit();
} }
BAN::ErrorOr<Thread*> Process::add_thread(entry_t entry, void* data) BAN::ErrorOr<Thread*> Process::add_thread(entry_t entry, void* data)
@ -85,14 +85,24 @@ namespace Kernel
for (size_t i = 0; i < m_threads.size(); i++) for (size_t i = 0; i < m_threads.size(); i++)
if (m_threads[i] == &thread) if (m_threads[i] == &thread)
m_threads.remove(i); m_threads.remove(i);
if (m_threads.empty())
exit();
} }
void Process::exit() void Process::exit()
{ {
CriticalScope _; m_lock.lock();
m_threads.clear(); m_threads.clear();
for (auto& open_fd : m_open_files) for (auto& open_fd : m_open_files)
open_fd.inode = nullptr; open_fd.inode = nullptr;
dprintln("process {} exit", pid());
s_process_lock.lock();
for (size_t i = 0; i < s_processes.size(); i++)
if (s_processes[i] == this)
s_processes.remove(i);
s_process_lock.unlock();
Scheduler::get().set_current_process_done(); Scheduler::get().set_current_process_done();
} }

View File

@ -245,7 +245,8 @@ namespace Kernel
void Scheduler::set_current_process_done() void Scheduler::set_current_process_done()
{ {
VERIFY_CLI(); VERIFY_STI();
DISABLE_INTERRUPTS();
pid_t pid = m_current_thread->thread->process().pid(); pid_t pid = m_current_thread->thread->process().pid();
@ -253,6 +254,7 @@ namespace Kernel
remove_threads(m_sleeping_threads, it->thread->process().pid() == pid); remove_threads(m_sleeping_threads, it->thread->process().pid() == pid);
remove_threads(m_active_threads, it != m_current_thread && it->thread->process().pid() == pid); remove_threads(m_active_threads, it != m_current_thread && it->thread->process().pid() == pid);
delete &m_current_thread->thread->process();
delete m_current_thread->thread; delete m_current_thread->thread;
remove_and_advance_current_thread(); remove_and_advance_current_thread();
execute_current_thread(); execute_current_thread();