2020-07-31 00:38:15 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-31 00:38:15 +03:00
|
|
|
*/
|
|
|
|
|
2020-12-30 17:19:57 +03:00
|
|
|
#include <AK/Types.h>
|
2020-07-31 00:38:15 +03:00
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getpid()
|
2020-07-31 00:38:15 +03:00
|
|
|
{
|
2021-07-18 21:33:13 +03:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this)
|
2021-12-29 12:11:45 +03:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-03-10 21:59:46 +03:00
|
|
|
return pid().value();
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getppid()
|
2020-07-31 00:38:15 +03:00
|
|
|
{
|
2021-07-18 21:20:12 +03:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
2021-12-29 12:11:45 +03:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-08-07 22:30:06 +03:00
|
|
|
return m_protected_values.ppid.value();
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
ErrorOr<FlatPtr> Process::sys$get_process_name(Userspace<char*> buffer, size_t buffer_size)
|
2020-07-31 00:38:15 +03:00
|
|
|
{
|
2021-07-18 21:20:12 +03:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
2021-12-29 12:11:45 +03:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-09-07 13:53:28 +03:00
|
|
|
if (m_name->length() + 1 > buffer_size)
|
2021-03-01 15:49:16 +03:00
|
|
|
return ENAMETOOLONG;
|
2020-07-31 00:38:15 +03:00
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
TRY(copy_to_user(buffer, m_name->characters(), m_name->length() + 1));
|
|
|
|
return 0;
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
ErrorOr<FlatPtr> Process::sys$set_process_name(Userspace<const char*> user_name, size_t user_name_length)
|
2020-07-31 00:38:15 +03:00
|
|
|
{
|
2021-07-18 21:20:12 +03:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
2021-12-29 12:11:45 +03:00
|
|
|
TRY(require_promise(Pledge::proc));
|
2020-07-31 00:38:15 +03:00
|
|
|
if (user_name_length > 256)
|
2021-03-01 15:49:16 +03:00
|
|
|
return ENAMETOOLONG;
|
2021-09-05 19:17:06 +03:00
|
|
|
auto name = TRY(try_copy_kstring_from_user(user_name, user_name_length));
|
2021-02-11 22:11:05 +03:00
|
|
|
// Empty and whitespace-only names only exist to confuse users.
|
2021-09-05 19:17:06 +03:00
|
|
|
if (name->view().is_whitespace())
|
2021-03-01 15:49:16 +03:00
|
|
|
return EINVAL;
|
2021-09-07 13:53:28 +03:00
|
|
|
m_name = move(name);
|
2020-07-31 00:38:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-08 02:51:39 +03:00
|
|
|
ErrorOr<FlatPtr> Process::sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*> user_params)
|
2020-12-30 17:19:57 +03:00
|
|
|
{
|
2021-07-18 21:20:12 +03:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
2021-09-05 18:51:37 +03:00
|
|
|
auto params = TRY(copy_typed_from_user(user_params));
|
|
|
|
|
2020-12-30 17:19:57 +03:00
|
|
|
if (params.key.length == 0 || params.key.length > 16 * KiB)
|
2021-03-01 15:49:16 +03:00
|
|
|
return EINVAL;
|
2020-12-30 17:19:57 +03:00
|
|
|
if (params.value.length > 16 * KiB)
|
2021-03-01 15:49:16 +03:00
|
|
|
return EINVAL;
|
2021-09-05 19:15:42 +03:00
|
|
|
auto key = TRY(try_copy_kstring_from_user(params.key));
|
|
|
|
auto value = TRY(try_copy_kstring_from_user(params.value));
|
2021-11-08 02:51:39 +03:00
|
|
|
TRY(set_coredump_property(move(key), move(value)));
|
|
|
|
return 0;
|
2020-12-30 17:19:57 +03:00
|
|
|
}
|
|
|
|
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|