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-06-28 20:59:35 +02:00
|
|
|
KResultOr<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)
|
2020-07-30 23:38:15 +02:00
|
|
|
REQUIRE_PROMISE(stdio);
|
2021-03-10 19:59:46 +01:00
|
|
|
return pid().value();
|
2020-07-30 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
2021-06-28 20:59:35 +02:00
|
|
|
KResultOr<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)
|
2020-07-30 23:38:15 +02:00
|
|
|
REQUIRE_PROMISE(stdio);
|
2021-08-07 22:30:06 +03:00
|
|
|
return m_protected_values.ppid.value();
|
2020-07-30 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
2021-06-28 20:59:35 +02:00
|
|
|
KResultOr<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)
|
2020-07-30 23:38:15 +02:00
|
|
|
REQUIRE_PROMISE(stdio);
|
2020-08-01 11:37:40 +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-09-05 17:38:37 +02:00
|
|
|
return copy_to_user(buffer, m_name.characters(), m_name.length() + 1);
|
2020-07-30 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
2021-06-28 20:59:35 +02:00
|
|
|
KResultOr<FlatPtr> Process::sys$set_process_name(Userspace<const char*> 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)
|
2020-07-30 23:38:15 +02:00
|
|
|
REQUIRE_PROMISE(proc);
|
|
|
|
if (user_name_length > 256)
|
2021-03-01 13:49:16 +01:00
|
|
|
return ENAMETOOLONG;
|
2021-08-14 23:00:06 +02:00
|
|
|
auto name_or_error = try_copy_kstring_from_user(user_name, user_name_length);
|
|
|
|
if (name_or_error.is_error())
|
|
|
|
return name_or_error.error();
|
2021-02-11 20:11:05 +01:00
|
|
|
// Empty and whitespace-only names only exist to confuse users.
|
2021-08-14 23:00:06 +02:00
|
|
|
if (name_or_error.value()->view().is_whitespace())
|
2021-03-01 13:49:16 +01:00
|
|
|
return EINVAL;
|
2021-08-14 23:00:06 +02:00
|
|
|
// FIXME: There's a String copy here. Process::m_name should be a KString.
|
|
|
|
m_name = name_or_error.value()->view();
|
2020-07-30 23:38:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-28 20:59:35 +02:00
|
|
|
KResultOr<FlatPtr> Process::sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*> user_params)
|
2020-12-30 15:19:57 +01:00
|
|
|
{
|
2021-07-18 11:20:12 -07:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(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-08-05 23:43:10 +02:00
|
|
|
return set_coredump_property(move(key), move(value));
|
2020-12-30 15:19:57 +01:00
|
|
|
}
|
|
|
|
|
2020-07-30 23:38:15 +02:00
|
|
|
}
|