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