1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

Kernel+Userland: Remove the {get,set}_thread_name syscalls

These syscalls are not necessary on their own, and they give the false
impression that a caller could set or get the thread name of any process
in the system, which is not true.

Therefore, move the functionality of these syscalls to be options in the
prctl syscall, which makes it abundantly clear that these operations
could only occur from a running thread in a process that sees other
threads in that process only.
This commit is contained in:
Liav A 2023-08-19 21:10:25 +03:00 committed by Tim Schumacher
parent 1458849850
commit 1c0aa51684
14 changed files with 54 additions and 63 deletions

View file

@ -9,7 +9,7 @@
namespace Kernel {
ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, FlatPtr arg2)
ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, FlatPtr arg2, FlatPtr arg3)
{
VERIFY_NO_PROCESS_BIG_LOCK(this);
return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr<FlatPtr> {
@ -71,6 +71,31 @@ ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, FlatPtr arg2)
}));
return 0;
}
case PR_SET_THREAD_NAME: {
TRY(require_promise(Pledge::stdio));
int thread_id = static_cast<int>(arg1);
Userspace<char const*> buffer = arg2;
size_t buffer_size = static_cast<size_t>(arg3);
Thread::Name thread_name {};
TRY(try_copy_name_from_user_into_fixed_string_buffer(buffer, thread_name, buffer_size));
auto thread = TRY(get_thread_from_thread_list(thread_id));
thread->set_name(thread_name.representable_view());
return 0;
}
case PR_GET_THREAD_NAME: {
TRY(require_promise(Pledge::thread));
int thread_id = static_cast<int>(arg1);
Userspace<char*> buffer = arg2;
size_t buffer_size = static_cast<size_t>(arg3);
auto thread = TRY(get_thread_from_thread_list(thread_id));
TRY(thread->name().with([&](auto& thread_name) -> ErrorOr<void> {
VERIFY(!thread_name.representable_view().is_null());
return copy_fixed_string_buffer_including_null_char_to_user(buffer, buffer_size, thread_name);
}));
return 0;
}
}
return EINVAL;