mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
Kernel: Merge {get,set}_process_name syscalls to the prctl syscall
It makes much more sense to have these actions being performed via the prctl syscall, as they both require 2 plain arguments to be passed to the syscall layer, and in contrast to most syscalls, we don't get in these removed syscalls an automatic representation of Userspace<T>, but two FlatPtr(s) to perform casting on them in the prctl syscall which is suited to what has been done in the removed syscalls. Also, it makes sense to have these actions in the prctl syscall, because they are strongly related to the process control concept of the prctl syscall.
This commit is contained in:
parent
1e36d54493
commit
d16d805d96
9 changed files with 36 additions and 71 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, [[maybe_unused]] FlatPtr arg2)
|
||||
ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, FlatPtr arg2)
|
||||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr<FlatPtr> {
|
||||
|
@ -49,6 +49,36 @@ ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, [[maybe_unused]] F
|
|||
TRY(set_coredump_property(move(key), move(value)));
|
||||
return 0;
|
||||
}
|
||||
case PR_SET_PROCESS_NAME: {
|
||||
TRY(require_promise(Pledge::proc));
|
||||
Userspace<char const*> buffer = arg1;
|
||||
int user_buffer_size = static_cast<int>(arg2);
|
||||
if (user_buffer_size < 0)
|
||||
return EINVAL;
|
||||
if (user_buffer_size > 256)
|
||||
return ENAMETOOLONG;
|
||||
size_t buffer_size = static_cast<size_t>(user_buffer_size);
|
||||
auto name = TRY(try_copy_kstring_from_user(buffer, buffer_size));
|
||||
// NOTE: Reject empty and whitespace-only names, as they only confuse users.
|
||||
if (name->view().is_whitespace())
|
||||
return EINVAL;
|
||||
set_name(move(name));
|
||||
return 0;
|
||||
}
|
||||
case PR_GET_PROCESS_NAME: {
|
||||
TRY(require_promise(Pledge::stdio));
|
||||
Userspace<char*> buffer = arg1;
|
||||
int user_buffer_size = arg2;
|
||||
if (user_buffer_size < 0)
|
||||
return EINVAL;
|
||||
size_t buffer_size = static_cast<size_t>(arg2);
|
||||
TRY(m_name.with([&buffer, buffer_size](auto& name) -> ErrorOr<void> {
|
||||
if (name->length() + 1 > buffer_size)
|
||||
return ENAMETOOLONG;
|
||||
return copy_to_user(buffer, name->characters(), name->length() + 1);
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return EINVAL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue