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-06-28 21:59:35 +03:00
|
|
|
KResultOr<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)
|
2020-07-31 00:38:15 +03:00
|
|
|
REQUIRE_PROMISE(stdio);
|
2021-03-10 21:59:46 +03:00
|
|
|
return pid().value();
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|
|
|
|
|
2021-06-28 21:59:35 +03:00
|
|
|
KResultOr<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)
|
2020-07-31 00:38:15 +03:00
|
|
|
REQUIRE_PROMISE(stdio);
|
2021-08-07 22:30:06 +03:00
|
|
|
return m_protected_values.ppid.value();
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|
|
|
|
|
2021-06-28 21:59:35 +03:00
|
|
|
KResultOr<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)
|
2020-07-31 00:38:15 +03:00
|
|
|
REQUIRE_PROMISE(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-09-07 13:53:28 +03:00
|
|
|
return copy_to_user(buffer, m_name->characters(), m_name->length() + 1);
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|
|
|
|
|
2021-06-28 21:59:35 +03:00
|
|
|
KResultOr<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)
|
2020-07-31 00:38:15 +03:00
|
|
|
REQUIRE_PROMISE(proc);
|
|
|
|
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-06-28 21:59:35 +03:00
|
|
|
KResultOr<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-08-06 00:43:10 +03:00
|
|
|
return set_coredump_property(move(key), move(value));
|
2020-12-30 17:19:57 +03:00
|
|
|
}
|
|
|
|
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|