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-03-01 15:49:16 +03:00
|
|
|
KResultOr<pid_t> Process::sys$getpid()
|
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-03-01 15:49:16 +03:00
|
|
|
KResultOr<pid_t> Process::sys$getppid()
|
2020-07-31 00:38:15 +03:00
|
|
|
{
|
|
|
|
REQUIRE_PROMISE(stdio);
|
2021-03-11 15:13:05 +03:00
|
|
|
return m_ppid.value();
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|
|
|
|
|
2021-03-01 15:49:16 +03:00
|
|
|
KResultOr<int> Process::sys$get_process_name(Userspace<char*> buffer, size_t buffer_size)
|
2020-07-31 00:38:15 +03:00
|
|
|
{
|
|
|
|
REQUIRE_PROMISE(stdio);
|
2020-08-01 12:37:40 +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
|
|
|
|
2020-09-12 06:11:07 +03:00
|
|
|
if (!copy_to_user(buffer, m_name.characters(), m_name.length() + 1))
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2020-07-31 00:38:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-01 15:49:16 +03:00
|
|
|
KResultOr<int> Process::sys$set_process_name(Userspace<const char*> user_name, size_t user_name_length)
|
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;
|
2020-09-12 06:11:07 +03:00
|
|
|
auto name = copy_string_from_user(user_name, user_name_length);
|
2020-07-31 00:38:15 +03:00
|
|
|
if (name.is_null())
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2021-02-11 22:11:05 +03:00
|
|
|
// Empty and whitespace-only names only exist to confuse users.
|
|
|
|
if (name.is_whitespace())
|
2021-03-01 15:49:16 +03:00
|
|
|
return EINVAL;
|
2020-07-31 00:38:15 +03:00
|
|
|
m_name = move(name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-01 15:49:16 +03:00
|
|
|
KResultOr<int> Process::sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*> user_params)
|
2020-12-30 17:19:57 +03:00
|
|
|
{
|
|
|
|
Syscall::SC_set_coredump_metadata_params params;
|
|
|
|
if (!copy_from_user(¶ms, user_params))
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
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;
|
2020-12-30 17:19:57 +03:00
|
|
|
auto copied_key = copy_string_from_user(params.key.characters, params.key.length);
|
|
|
|
if (copied_key.is_null())
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2020-12-30 17:19:57 +03:00
|
|
|
auto copied_value = copy_string_from_user(params.value.characters, params.value.length);
|
|
|
|
if (copied_value.is_null())
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2020-12-30 17:19:57 +03:00
|
|
|
if (!m_coredump_metadata.contains(copied_key) && m_coredump_metadata.size() >= 16)
|
2021-03-01 15:49:16 +03:00
|
|
|
return EFAULT;
|
2020-12-30 17:19:57 +03:00
|
|
|
m_coredump_metadata.set(move(copied_key), move(copied_value));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-31 00:38:15 +03:00
|
|
|
}
|