1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:17:44 +00:00

Kernel: Store process names as KString

This commit is contained in:
Andreas Kling 2021-09-07 12:53:28 +02:00
parent db2e67fd53
commit 55b0b06897
15 changed files with 46 additions and 32 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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;
}

View file

@ -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)