diff options
-rw-r--r-- | Kernel/Bus/USB/UHCI/UHCIController.cpp | 6 | ||||
-rw-r--r-- | Kernel/FileSystem/Plan9FileSystem.cpp | 5 | ||||
-rw-r--r-- | Kernel/Net/NetworkTask.cpp | 5 | ||||
-rw-r--r-- | Kernel/Process.cpp | 13 | ||||
-rw-r--r-- | Kernel/Process.h | 12 | ||||
-rw-r--r-- | Kernel/Scheduler.cpp | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/execve.cpp | 6 | ||||
-rw-r--r-- | Kernel/Syscalls/fork.cpp | 3 | ||||
-rw-r--r-- | Kernel/Syscalls/process.cpp | 7 | ||||
-rw-r--r-- | Kernel/Syscalls/thread.cpp | 2 | ||||
-rw-r--r-- | Kernel/Tasks/FinalizerTask.cpp | 2 | ||||
-rw-r--r-- | Kernel/Tasks/SyncTask.cpp | 2 | ||||
-rw-r--r-- | Kernel/WorkQueue.cpp | 7 | ||||
-rw-r--r-- | Kernel/WorkQueue.h | 4 | ||||
-rw-r--r-- | Kernel/init.cpp | 2 |
15 files changed, 46 insertions, 32 deletions
diff --git a/Kernel/Bus/USB/UHCI/UHCIController.cpp b/Kernel/Bus/USB/UHCI/UHCIController.cpp index 9f8aa6a5e6..532925cdd0 100644 --- a/Kernel/Bus/USB/UHCI/UHCIController.cpp +++ b/Kernel/Bus/USB/UHCI/UHCIController.cpp @@ -472,7 +472,11 @@ void UHCIController::spawn_port_proc() { RefPtr<Thread> usb_hotplug_thread; - Process::create_kernel_process(usb_hotplug_thread, "UHCIHotplug", [&] { + auto process_name = KString::try_create("UHCI hotplug"); + if (process_name.is_error()) + TODO(); + + Process::create_kernel_process(usb_hotplug_thread, process_name.release_value(), [&] { for (;;) { if (m_root_hub) m_root_hub->check_for_port_updates(); diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp index 40e5f47936..4f27c1cf28 100644 --- a/Kernel/FileSystem/Plan9FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FileSystem.cpp @@ -655,7 +655,10 @@ void Plan9FS::ensure_thread() { SpinlockLocker lock(m_thread_lock); if (!m_thread_running.exchange(true, AK::MemoryOrder::memory_order_acq_rel)) { - Process::create_kernel_process(m_thread, "Plan9FS", [&]() { + auto process_name = KString::try_create("Plan9FS"); + if (process_name.is_error()) + TODO(); + Process::create_kernel_process(m_thread, process_name.release_value(), [&]() { thread_main(); m_thread_running.store(false, AK::MemoryOrder::memory_order_release); }); diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 42b68f72de..66c2d8785b 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -43,7 +43,10 @@ static HashTable<RefPtr<TCPSocket>>* delayed_ack_sockets; void NetworkTask::spawn() { RefPtr<Thread> thread; - Process::create_kernel_process(thread, "NetworkTask", NetworkTask_main, nullptr); + auto name = KString::try_create("NetworkTask"); + if (name.is_error()) + TODO(); + Process::create_kernel_process(thread, name.release_value(), NetworkTask_main, nullptr); network_task = thread; } diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index e1c75f3ad2..537ea28624 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -145,12 +145,13 @@ void Process::register_new(Process& process) KResultOr<NonnullRefPtr<Process>> Process::try_create_user_process(RefPtr<Thread>& first_thread, String const& path, UserID uid, GroupID gid, Vector<String> arguments, Vector<String> environment, TTY* tty) { - auto parts = path.split('/'); + auto parts = path.split_view('/'); if (arguments.is_empty()) { arguments.append(parts.last()); } - auto process = TRY(Process::try_create(first_thread, parts.take_last(), uid, gid, ProcessID(0), false, VirtualFileSystem::the().root_custody(), nullptr, tty)); + auto name = TRY(KString::try_create(parts.last())); + auto process = TRY(Process::try_create(first_thread, move(name), uid, gid, ProcessID(0), false, VirtualFileSystem::the().root_custody(), nullptr, tty)); if (!process->m_fds.try_resize(process->m_fds.max_open())) { first_thread = nullptr; @@ -180,7 +181,7 @@ KResultOr<NonnullRefPtr<Process>> Process::try_create_user_process(RefPtr<Thread return process; } -RefPtr<Process> Process::create_kernel_process(RefPtr<Thread>& first_thread, String&& name, void (*entry)(void*), void* entry_data, u32 affinity, RegisterProcess do_register) +RefPtr<Process> Process::create_kernel_process(RefPtr<Thread>& first_thread, NonnullOwnPtr<KString> name, void (*entry)(void*), void* entry_data, u32 affinity, RegisterProcess do_register) { auto process_or_error = Process::try_create(first_thread, move(name), UserID(0), GroupID(0), ProcessID(0), true); if (process_or_error.is_error()) @@ -217,15 +218,15 @@ void Process::unprotect_data() }); } -KResultOr<NonnullRefPtr<Process>> Process::try_create(RefPtr<Thread>& first_thread, String const& name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty, Process* fork_parent) +KResultOr<NonnullRefPtr<Process>> Process::try_create(RefPtr<Thread>& first_thread, NonnullOwnPtr<KString> name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty, Process* fork_parent) { auto space = TRY(Memory::AddressSpace::try_create(fork_parent ? &fork_parent->address_space() : nullptr)); - auto process = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Process(name, uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty))); + auto process = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Process(move(name), uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty))); TRY(process->attach_resources(move(space), first_thread, fork_parent)); return process; } -Process::Process(const String& name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty) +Process::Process(NonnullOwnPtr<KString> name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty) : m_name(move(name)) , m_is_kernel_process(is_kernel_process) , m_executable(move(executable)) diff --git a/Kernel/Process.h b/Kernel/Process.h index 5aed32eeb3..93a0f9674e 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -172,13 +172,13 @@ public: }; template<typename EntryFunction> - static RefPtr<Process> create_kernel_process(RefPtr<Thread>& first_thread, String&& name, EntryFunction entry, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes) + static RefPtr<Process> create_kernel_process(RefPtr<Thread>& first_thread, NonnullOwnPtr<KString> name, EntryFunction entry, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes) { auto* entry_func = new EntryFunction(move(entry)); return create_kernel_process(first_thread, move(name), &Process::kernel_process_trampoline<EntryFunction>, entry_func, affinity, do_register); } - static RefPtr<Process> create_kernel_process(RefPtr<Thread>& first_thread, String&& name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes); + static RefPtr<Process> create_kernel_process(RefPtr<Thread>& first_thread, NonnullOwnPtr<KString> name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes); static KResultOr<NonnullRefPtr<Process>> try_create_user_process(RefPtr<Thread>& first_thread, String const& path, UserID, GroupID, Vector<String> arguments, Vector<String> environment, TTY*); static void register_new(Process&); @@ -207,7 +207,7 @@ public: static RefPtr<Process> from_pid(ProcessID); static SessionID get_sid_from_pgid(ProcessGroupID pgid); - const String& name() const { return m_name; } + StringView name() const { return m_name->view(); } ProcessID pid() const { return m_protected_values.pid; } SessionID sid() const { return m_protected_values.sid; } bool is_session_leader() const { return sid().value() == pid().value(); } @@ -521,8 +521,8 @@ private: bool add_thread(Thread&); bool remove_thread(Thread&); - Process(const String& name, UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty); - static KResultOr<NonnullRefPtr<Process>> try_create(RefPtr<Thread>& first_thread, String const& name, UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd = nullptr, RefPtr<Custody> executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr); + Process(NonnullOwnPtr<KString> name, UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty); + static KResultOr<NonnullRefPtr<Process>> try_create(RefPtr<Thread>& first_thread, NonnullOwnPtr<KString> name, UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd = nullptr, RefPtr<Custody> executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr); KResult attach_resources(NonnullOwnPtr<Memory::AddressSpace>&&, RefPtr<Thread>& first_thread, Process* fork_parent); static ProcessID allocate_pid(); @@ -586,7 +586,7 @@ private: mutable IntrusiveListNode<Process> m_list_node; - String m_name; + NonnullOwnPtr<KString> m_name; OwnPtr<Memory::AddressSpace> m_space; diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 40110d1c7c..a17d135171 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -413,7 +413,7 @@ UNMAP_AFTER_INIT void Scheduler::initialize() g_finalizer_wait_queue = new WaitQueue; g_finalizer_has_work.store(false, AK::MemoryOrder::memory_order_release); - s_colonel_process = Process::create_kernel_process(idle_thread, "colonel", idle_loop, nullptr, 1, Process::RegisterProcess::No).leak_ref(); + s_colonel_process = Process::create_kernel_process(idle_thread, KString::must_create("colonel"), idle_loop, nullptr, 1, Process::RegisterProcess::No).leak_ref(); VERIFY(s_colonel_process); VERIFY(idle_thread); idle_thread->set_priority(THREAD_PRIORITY_MIN); diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 5dbe3dfc5e..46cd482046 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -446,12 +446,12 @@ KResult Process::do_exec(NonnullRefPtr<FileDescription> main_program_description if (!validate_stack_size(arguments, environment)) return E2BIG; - auto parts = path.split('/'); + auto parts = path.split_view('/'); if (parts.is_empty()) return ENOENT; - auto new_process_name = parts.take_last(); - auto new_main_thread_name = TRY(KString::try_create(new_process_name)); + auto new_process_name = TRY(KString::try_create(parts.last())); + auto new_main_thread_name = TRY(new_process_name->try_clone()); auto main_program_metadata = main_program_description->metadata(); diff --git a/Kernel/Syscalls/fork.cpp b/Kernel/Syscalls/fork.cpp index 0483325d67..a21a2e42b6 100644 --- a/Kernel/Syscalls/fork.cpp +++ b/Kernel/Syscalls/fork.cpp @@ -18,7 +18,8 @@ KResultOr<FlatPtr> Process::sys$fork(RegisterState& regs) VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(proc); RefPtr<Thread> child_first_thread; - auto child = TRY(Process::try_create(child_first_thread, m_name, uid(), gid(), pid(), m_is_kernel_process, m_cwd, m_executable, m_tty, this)); + auto child_name = TRY(m_name->try_clone()); + auto child = TRY(Process::try_create(child_first_thread, move(child_name), uid(), gid(), pid(), m_is_kernel_process, m_cwd, m_executable, m_tty, this)); child->m_veil_state = m_veil_state; child->m_unveiled_paths = m_unveiled_paths.deep_copy(); diff --git a/Kernel/Syscalls/process.cpp b/Kernel/Syscalls/process.cpp index ea0a660a31..f2301b4129 100644 --- a/Kernel/Syscalls/process.cpp +++ b/Kernel/Syscalls/process.cpp @@ -27,10 +27,10 @@ KResultOr<FlatPtr> Process::sys$get_process_name(Userspace<char*> buffer, size_t { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(stdio); - if (m_name.length() + 1 > buffer_size) + if (m_name->length() + 1 > buffer_size) return ENAMETOOLONG; - return copy_to_user(buffer, m_name.characters(), m_name.length() + 1); + return copy_to_user(buffer, m_name->characters(), m_name->length() + 1); } KResultOr<FlatPtr> Process::sys$set_process_name(Userspace<const char*> user_name, size_t user_name_length) @@ -43,8 +43,7 @@ KResultOr<FlatPtr> Process::sys$set_process_name(Userspace<const char*> user_nam // Empty and whitespace-only names only exist to confuse users. if (name->view().is_whitespace()) return EINVAL; - // FIXME: There's a String copy here. Process::m_name should be a KString. - m_name = name->view(); + m_name = move(name); return 0; } diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp index e110b5c44f..baf8be9e50 100644 --- a/Kernel/Syscalls/thread.cpp +++ b/Kernel/Syscalls/thread.cpp @@ -49,7 +49,7 @@ KResultOr<FlatPtr> Process::sys$create_thread(void* (*entry)(void*), Userspace<c // We know this thread is not the main_thread, // So give it a unique name until the user calls $set_thread_name on it // length + 4 to give space for our extra junk at the end - StringBuilder builder(m_name.length() + 4); + StringBuilder builder(m_name->length() + 4); thread->set_name(move(new_thread_name)); if (!is_thread_joinable) diff --git a/Kernel/Tasks/FinalizerTask.cpp b/Kernel/Tasks/FinalizerTask.cpp index ffdfb09ef3..a8283f4826 100644 --- a/Kernel/Tasks/FinalizerTask.cpp +++ b/Kernel/Tasks/FinalizerTask.cpp @@ -24,7 +24,7 @@ static void finalizer_task(void*) UNMAP_AFTER_INIT void FinalizerTask::spawn() { RefPtr<Thread> finalizer_thread; - auto finalizer_process = Process::create_kernel_process(finalizer_thread, "FinalizerTask", finalizer_task, nullptr); + auto finalizer_process = Process::create_kernel_process(finalizer_thread, KString::must_create("FinalizerTask"), finalizer_task, nullptr); VERIFY(finalizer_process); g_finalizer = finalizer_thread; } diff --git a/Kernel/Tasks/SyncTask.cpp b/Kernel/Tasks/SyncTask.cpp index a5b44aa6f7..c6e544afa8 100644 --- a/Kernel/Tasks/SyncTask.cpp +++ b/Kernel/Tasks/SyncTask.cpp @@ -15,7 +15,7 @@ namespace Kernel { UNMAP_AFTER_INIT void SyncTask::spawn() { RefPtr<Thread> syncd_thread; - Process::create_kernel_process(syncd_thread, "SyncTask", [] { + Process::create_kernel_process(syncd_thread, KString::must_create("SyncTask"), [] { dbgln("SyncTask is running"); for (;;) { VirtualFileSystem::sync(); diff --git a/Kernel/WorkQueue.cpp b/Kernel/WorkQueue.cpp index 4fa8c735a0..e3cea7b22b 100644 --- a/Kernel/WorkQueue.cpp +++ b/Kernel/WorkQueue.cpp @@ -19,10 +19,13 @@ UNMAP_AFTER_INIT void WorkQueue::initialize() g_io_work = new WorkQueue("IO WorkQueue"); } -UNMAP_AFTER_INIT WorkQueue::WorkQueue(const char* name) +UNMAP_AFTER_INIT WorkQueue::WorkQueue(StringView name) { RefPtr<Thread> thread; - Process::create_kernel_process(thread, name, [this] { + auto name_kstring = KString::try_create(name); + if (name_kstring.is_error()) + TODO(); + Process::create_kernel_process(thread, name_kstring.release_value(), [this] { for (;;) { WorkItem* item; bool have_more; diff --git a/Kernel/WorkQueue.h b/Kernel/WorkQueue.h index 21e45f8f49..90756998d6 100644 --- a/Kernel/WorkQueue.h +++ b/Kernel/WorkQueue.h @@ -20,8 +20,6 @@ class WorkQueue { public: static void initialize(); - WorkQueue(const char*); - void queue(void (*function)(void*), void* data = nullptr, void (*free_data)(void*) = nullptr) { auto* item = new WorkItem; // TODO: use a pool @@ -42,6 +40,8 @@ public: } private: + explicit WorkQueue(StringView); + struct WorkItem { IntrusiveListNode<WorkItem> m_node; Function<void()> function; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index b4d7821fb3..abc57179b0 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -215,7 +215,7 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) { RefPtr<Thread> init_stage2_thread; - Process::create_kernel_process(init_stage2_thread, "init_stage2", init_stage2, nullptr, THREAD_AFFINITY_DEFAULT, Process::RegisterProcess::No); + Process::create_kernel_process(init_stage2_thread, KString::must_create("init_stage2"), init_stage2, nullptr, THREAD_AFFINITY_DEFAULT, Process::RegisterProcess::No); // We need to make sure we drop the reference for init_stage2_thread // before calling into Scheduler::start, otherwise we will have a // dangling Thread that never gets cleaned up |