diff --git a/kernel/src/arch/x86_64/CPU.cpp b/kernel/src/arch/x86_64/CPU.cpp index 2a8ed6a1..54dd934c 100644 --- a/kernel/src/arch/x86_64/CPU.cpp +++ b/kernel/src/arch/x86_64/CPU.cpp @@ -219,7 +219,8 @@ namespace CPU void platform_finish_init() { - Scheduler::new_kernel_thread(io_thread).expect_value("Could not create the IO background thread!"); + Scheduler::new_kernel_thread(io_thread, "[x86_64-io]") + .expect_value("Could not create the IO background thread!"); remap_pic(); } diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index cd158592..477f8ad2 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -68,7 +68,7 @@ static Result try_init_userspace() { auto init = TRY(VFS::resolve_path("/bin/init")); - TRY(Scheduler::new_userspace_thread(init)); + TRY(Scheduler::new_userspace_thread(init, "/bin/init")); return {}; } @@ -80,7 +80,7 @@ static void init_userspace() static void create_reaper() { - Scheduler::new_kernel_thread(reap_thread).release_value(); + Scheduler::new_kernel_thread(reap_thread, "[reap]").release_value(); } static void scan_pci() diff --git a/kernel/src/sys/exec.cpp b/kernel/src/sys/exec.cpp index 656eb8d0..a65a503b 100644 --- a/kernel/src/sys/exec.cpp +++ b/kernel/src/sys/exec.cpp @@ -81,6 +81,8 @@ Result sys_exec(Registers* regs, SyscallArgs args) MMU::delete_userspace_page_directory(current->directory); + current->name = argv[0].chars(); + image->apply(current); MMU::switch_page_directory(current->directory); diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 21ba8b5b..41865055 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -24,6 +24,7 @@ namespace Scheduler g_idle.state = ThreadState::Idle; g_idle.is_kernel = true; g_idle.parent_id = 0; + g_idle.name = "[idle]"; g_idle.ticks_left = 1; @@ -51,7 +52,7 @@ namespace Scheduler return &g_idle; } - Result new_kernel_thread_impl(Thread* thread) + Result new_kernel_thread_impl(Thread* thread, const char* name) { // If anything fails, make sure to clean up. auto guard = make_scope_guard([&] { delete thread; }); @@ -67,6 +68,8 @@ namespace Scheduler thread->parent_id = 0; + thread->name = name; + thread->is_kernel = true; g_threads.append(thread); @@ -76,39 +79,40 @@ namespace Scheduler return {}; } - Result new_kernel_thread(u64 address) + Result new_kernel_thread(u64 address, const char* name) { Thread* const thread = TRY(new_thread()); thread->init_regs_kernel(); thread->set_ip(address); - return new_kernel_thread_impl(thread); + return new_kernel_thread_impl(thread, name); } - Result new_kernel_thread(void (*func)(void)) + Result new_kernel_thread(void (*func)(void), const char* name) { Thread* const thread = TRY(new_thread()); thread->init_regs_kernel(); thread->set_ip((u64)func); - return new_kernel_thread_impl(thread); + return new_kernel_thread_impl(thread, name); } - Result new_kernel_thread(void (*func)(void*), void* arg) + Result new_kernel_thread(void (*func)(void*), void* arg, const char* name) { Thread* const thread = TRY(new_thread()); thread->init_regs_kernel(); thread->set_ip((u64)func); thread->set_arguments((u64)arg, 0, 0, 0); - return new_kernel_thread_impl(thread); + return new_kernel_thread_impl(thread, name); } - Result new_userspace_thread(SharedPtr inode) + Result new_userspace_thread(SharedPtr inode, const char* name) { Thread* const thread = TRY(new_thread()); thread->is_kernel = false; + thread->name = name; thread->parent_id = 0; auto guard = make_scope_guard([&] { delete thread; }); diff --git a/kernel/src/thread/Scheduler.h b/kernel/src/thread/Scheduler.h index 67bf8707..f0ced1d1 100644 --- a/kernel/src/thread/Scheduler.h +++ b/kernel/src/thread/Scheduler.h @@ -9,11 +9,11 @@ namespace Scheduler Thread* current(); Thread* idle(); - Result new_kernel_thread(u64 address); - Result new_kernel_thread(void (*func)(void)); - Result new_kernel_thread(void (*func)(void*), void* arg); + Result new_kernel_thread(u64 address, const char* name); + Result new_kernel_thread(void (*func)(void), const char* name); + Result new_kernel_thread(void (*func)(void*), void* arg, const char* name); - Result new_userspace_thread(SharedPtr inode); + Result new_userspace_thread(SharedPtr inode, const char* name); void add_thread(Thread* thread); diff --git a/kernel/src/thread/Thread.h b/kernel/src/thread/Thread.h index 1e4a8d21..cd34dd27 100644 --- a/kernel/src/thread/Thread.h +++ b/kernel/src/thread/Thread.h @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef ARCH_X86_64 #include "arch/x86_64/CPU.h" @@ -68,6 +69,8 @@ struct Thread : public LinkedListNode u8 status { 0 }; + StaticString<128> name; + PageDirectory* directory; bool is_idle()