mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 01:41:59 -05: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
|
@ -85,7 +85,6 @@ enum class NeedsBigProcessLock {
|
|||
S(ftruncate, NeedsBigProcessLock::No) \
|
||||
S(futex, NeedsBigProcessLock::Yes) \
|
||||
S(get_dir_entries, NeedsBigProcessLock::Yes) \
|
||||
S(get_process_name, NeedsBigProcessLock::No) \
|
||||
S(get_root_session_id, NeedsBigProcessLock::No) \
|
||||
S(get_stack_bounds, NeedsBigProcessLock::No) \
|
||||
S(get_thread_name, NeedsBigProcessLock::No) \
|
||||
|
@ -159,7 +158,6 @@ enum class NeedsBigProcessLock {
|
|||
S(sendfd, NeedsBigProcessLock::No) \
|
||||
S(sendmsg, NeedsBigProcessLock::Yes) \
|
||||
S(set_mmap_name, NeedsBigProcessLock::Yes) \
|
||||
S(set_process_name, NeedsBigProcessLock::No) \
|
||||
S(set_thread_name, NeedsBigProcessLock::No) \
|
||||
S(setegid, NeedsBigProcessLock::No) \
|
||||
S(seteuid, NeedsBigProcessLock::No) \
|
||||
|
|
|
@ -11,3 +11,5 @@
|
|||
#define PR_SET_NO_NEW_SYSCALL_REGION_ANNOTATIONS 3
|
||||
#define PR_GET_NO_NEW_SYSCALL_REGION_ANNOTATIONS 4
|
||||
#define PR_SET_COREDUMP_METADATA_VALUE 5
|
||||
#define PR_SET_PROCESS_NAME 6
|
||||
#define PR_GET_PROCESS_NAME 7
|
||||
|
|
|
@ -293,8 +293,6 @@ public:
|
|||
ErrorOr<FlatPtr> sys$yield();
|
||||
ErrorOr<FlatPtr> sys$sync();
|
||||
ErrorOr<FlatPtr> sys$beep(int tone);
|
||||
ErrorOr<FlatPtr> sys$get_process_name(Userspace<char*> buffer, size_t buffer_size);
|
||||
ErrorOr<FlatPtr> sys$set_process_name(Userspace<char const*> user_name, size_t user_name_length);
|
||||
ErrorOr<FlatPtr> sys$create_inode_watcher(u32 flags);
|
||||
ErrorOr<FlatPtr> sys$inode_watcher_add_watch(Userspace<Syscall::SC_inode_watcher_add_watch_params const*> user_params);
|
||||
ErrorOr<FlatPtr> sys$inode_watcher_remove_watch(int fd, int wd);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -23,33 +23,4 @@ ErrorOr<FlatPtr> Process::sys$getppid()
|
|||
return ppid().value();
|
||||
}
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$get_process_name(Userspace<char*> buffer, size_t buffer_size)
|
||||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
TRY(require_promise(Pledge::stdio));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$set_process_name(Userspace<char const*> user_name, size_t user_name_length)
|
||||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
TRY(require_promise(Pledge::proc));
|
||||
if (user_name_length > 256)
|
||||
return ENAMETOOLONG;
|
||||
auto name = TRY(try_copy_kstring_from_user(user_name, user_name_length));
|
||||
// Empty and whitespace-only names only exist to confuse users.
|
||||
if (name->view().is_whitespace())
|
||||
return EINVAL;
|
||||
set_name(move(name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -171,7 +171,6 @@ private:
|
|||
int virt$ftruncate(int fd, FlatPtr length_addr);
|
||||
int virt$futex(FlatPtr);
|
||||
int virt$get_dir_entries(int fd, FlatPtr buffer, ssize_t);
|
||||
int virt$get_process_name(FlatPtr buffer, int size);
|
||||
int virt$get_stack_bounds(FlatPtr, FlatPtr);
|
||||
int virt$getcwd(FlatPtr buffer, size_t buffer_size);
|
||||
gid_t virt$getegid();
|
||||
|
|
|
@ -100,8 +100,6 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
|
|||
return virt$futex(arg1);
|
||||
case SC_get_dir_entries:
|
||||
return virt$get_dir_entries(arg1, arg2, arg3);
|
||||
case SC_get_process_name:
|
||||
return virt$get_process_name(arg1, arg2);
|
||||
case SC_get_stack_bounds:
|
||||
return virt$get_stack_bounds(arg1, arg2);
|
||||
case SC_getcwd:
|
||||
|
@ -210,8 +208,6 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
|
|||
return virt$sendmsg(arg1, arg2, arg3);
|
||||
case SC_set_mmap_name:
|
||||
return virt$set_mmap_name(arg1);
|
||||
case SC_set_process_name:
|
||||
return virt$set_process_name(arg1, arg2);
|
||||
case SC_set_thread_name:
|
||||
return virt$set_thread_name(arg1, arg2, arg3);
|
||||
case SC_setgid:
|
||||
|
@ -571,28 +567,6 @@ int Emulator::virt$set_mmap_name(FlatPtr params_addr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Emulator::virt$get_process_name(FlatPtr buffer, int size)
|
||||
{
|
||||
if (size < 0)
|
||||
return -EINVAL;
|
||||
auto host_buffer_result = ByteBuffer::create_zeroed((size_t)size);
|
||||
if (host_buffer_result.is_error())
|
||||
return -ENOMEM;
|
||||
auto& host_buffer = host_buffer_result.value();
|
||||
int rc = syscall(SC_get_process_name, host_buffer.data(), host_buffer.size());
|
||||
mmu().copy_to_vm(buffer, host_buffer.data(), host_buffer.size());
|
||||
return rc;
|
||||
}
|
||||
|
||||
int Emulator::virt$set_process_name(FlatPtr user_buffer, int size)
|
||||
{
|
||||
if (size < 0)
|
||||
return -EINVAL;
|
||||
auto host_buffer = mmu().copy_buffer_from_vm(user_buffer, size);
|
||||
auto name = DeprecatedString::formatted("(UE) {}", StringView { host_buffer.data(), host_buffer.size() });
|
||||
return syscall(SC_set_process_name, name.characters(), name.length());
|
||||
}
|
||||
|
||||
int Emulator::virt$lseek(int fd, FlatPtr offset_addr, int whence)
|
||||
{
|
||||
off_t offset;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -969,13 +970,13 @@ void dump_backtrace()
|
|||
|
||||
int get_process_name(char* buffer, int buffer_size)
|
||||
{
|
||||
int rc = syscall(SC_get_process_name, buffer, buffer_size);
|
||||
int rc = syscall(SC_prctl, PR_GET_PROCESS_NAME, buffer, buffer_size);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int set_process_name(char const* name, size_t name_length)
|
||||
{
|
||||
int rc = syscall(SC_set_process_name, name, name_length);
|
||||
int rc = syscall(SC_prctl, PR_SET_PROCESS_NAME, name, name_length);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
|
|
|
@ -690,11 +690,6 @@ static void format_dbgputstr(FormattedSyscallBuilder& builder, char* characters,
|
|||
builder.add_argument(StringArgument { { characters, size }, "\0\n"sv });
|
||||
}
|
||||
|
||||
static void format_get_process_name(FormattedSyscallBuilder& builder, char* buffer, size_t buffer_size)
|
||||
{
|
||||
builder.add_argument(StringArgument { { buffer, buffer_size }, "\0"sv });
|
||||
}
|
||||
|
||||
static ErrorOr<void> format_syscall(FormattedSyscallBuilder& builder, Syscall::Function syscall_function, syscall_arg_t arg1, syscall_arg_t arg2, syscall_arg_t arg3, syscall_arg_t res)
|
||||
{
|
||||
enum ResultType {
|
||||
|
@ -730,9 +725,6 @@ static ErrorOr<void> format_syscall(FormattedSyscallBuilder& builder, Syscall::F
|
|||
format_chdir(builder, (char const*)arg1, (size_t)arg2);
|
||||
result_type = Int;
|
||||
break;
|
||||
case SC_get_process_name:
|
||||
format_get_process_name(builder, (char*)arg1, (size_t)arg2);
|
||||
break;
|
||||
case SC_getrandom:
|
||||
format_getrandom(builder, (void*)arg1, (size_t)arg2, (unsigned)arg3);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue