diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-02-04 14:11:35 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-06 20:36:53 +0100 |
commit | 1014aefe649aa50d69aa10aba647872e2ff99a93 (patch) | |
tree | 323d31d45de5bda44dad6cc5e3215ba910467877 /Kernel/Syscalls | |
parent | fe7b08dad7a41251469840ab15ab90bc9b31caa8 (diff) | |
download | serenity-1014aefe649aa50d69aa10aba647872e2ff99a93.zip |
Kernel: Protect Thread::m_name with a spinlock
This replaces manually grabbing the thread's main lock.
This lets us remove the `get_thread_name` and `set_thread_name` syscalls
from the big lock. :^)
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r-- | Kernel/Syscalls/thread.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp index 1093f48fca..46e120a74a 100644 --- a/Kernel/Syscalls/thread.cpp +++ b/Kernel/Syscalls/thread.cpp @@ -180,7 +180,7 @@ ErrorOr<FlatPtr> Process::sys$kill_thread(pid_t tid, int signal) ErrorOr<FlatPtr> Process::sys$set_thread_name(pid_t tid, Userspace<char const*> user_name, size_t user_name_length) { - VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); + VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); auto name = TRY(try_copy_kstring_from_user(user_name, user_name_length)); @@ -199,7 +199,7 @@ ErrorOr<FlatPtr> Process::sys$set_thread_name(pid_t tid, Userspace<char const*> ErrorOr<FlatPtr> Process::sys$get_thread_name(pid_t tid, Userspace<char*> buffer, size_t buffer_size) { - VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); + VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::thread)); if (buffer_size == 0) return EINVAL; @@ -208,19 +208,19 @@ ErrorOr<FlatPtr> Process::sys$get_thread_name(pid_t tid, Userspace<char*> buffer if (!thread || thread->pid() != pid()) return ESRCH; - SpinlockLocker locker(thread->get_lock()); - auto thread_name = thread->name(); + TRY(thread->name().with([&](auto& thread_name) -> ErrorOr<void> { + if (thread_name->view().is_null()) { + char null_terminator = '\0'; + TRY(copy_to_user(buffer, &null_terminator, sizeof(null_terminator))); + return {}; + } - if (thread_name.is_null()) { - char null_terminator = '\0'; - TRY(copy_to_user(buffer, &null_terminator, sizeof(null_terminator))); - return 0; - } + if (thread_name->length() + 1 > buffer_size) + return ENAMETOOLONG; - if (thread_name.length() + 1 > buffer_size) - return ENAMETOOLONG; + return copy_to_user(buffer, thread_name->characters(), thread_name->length() + 1); + })); - TRY(copy_to_user(buffer, thread_name.characters_without_null_termination(), thread_name.length() + 1)); return 0; } |