diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 9d82a61c..dc8a367b 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -1,7 +1,6 @@ #include "Log.h" #include "arch/CPU.h" #include "arch/MMU.h" -#include "arch/Serial.h" #include "arch/Timer.h" #include "boot/Init.h" #include "boot/bootboot.h" @@ -10,6 +9,7 @@ #include "memory/KernelVM.h" #include "memory/MemoryManager.h" #include "thread/Scheduler.h" +#include #include #include #include @@ -54,11 +54,7 @@ void reap_thread() while (thread_to_reap) { next_thread = dying_threads.next(thread_to_reap).value_or(nullptr); - kinfoln("reap: reaping thread with id %zu", thread_to_reap->id); - auto stack = thread_to_reap->stack; - kinfoln("deleting thread stack @ %#lx, has %zu bytes of stack", stack.bottom(), stack.bytes()); - MemoryManager::unmap_owned_and_free_vm(stack.bottom(), stack.bytes() / ARCH_PAGE_SIZE).release_value(); - delete thread_to_reap; + Scheduler::reap_thread(thread_to_reap); thread_to_reap = next_thread; } } @@ -87,8 +83,17 @@ Result init() while (TRY(stream.read_next_entry().try_set_value_with_specific_error(entry, 0))) { if (entry.type == TarStream::EntryType::RegularFile) + { kinfoln("Found file %s in initial ramdisk, of size %s", entry.name, to_dynamic_unit(entry.size).release_value().chars()); + + if (!strcmp(entry.name, "sys/config")) + { + auto contents = TRY(stream.read_contents_as_string(entry, 0, entry.size)); + + kinfoln("%s", contents.chars()); + } + } } Thread::init(); diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index fc43f6c1..31e556ed 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -95,6 +95,16 @@ namespace Scheduler return new_kernel_thread_impl(thread); } + void reap_thread(Thread* thread) + { + kinfoln("reap: reaping thread with id %zu", thread->id); + auto stack = thread->stack; + kinfoln("deleting thread stack @ %#lx, has %zu bytes of stack", stack.bottom(), stack.bytes()); + // FIXME: Propagate errors I guess? + MemoryManager::unmap_owned_and_free_vm(stack.bottom(), stack.bytes() / ARCH_PAGE_SIZE).release_value(); + delete thread; + } + Thread* pick_task() { Thread* old = g_current; diff --git a/kernel/src/thread/Scheduler.h b/kernel/src/thread/Scheduler.h index e0f71973..b0c686ac 100644 --- a/kernel/src/thread/Scheduler.h +++ b/kernel/src/thread/Scheduler.h @@ -14,6 +14,8 @@ namespace Scheduler Thread* pick_task(); + void reap_thread(Thread* thread); + void switch_task(Registers* regs); void invoke(Registers* regs);