1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +00:00

Kernel: Make all syscall functions return KResultOr<T>

This makes it a lot easier to return errors since we no longer have to
worry about negating EFOO errors and can just return them flat.
This commit is contained in:
Andreas Kling 2021-03-01 13:49:16 +01:00
parent 9af1e1a3bf
commit ac71775de5
70 changed files with 747 additions and 742 deletions

View file

@ -29,61 +29,61 @@
namespace Kernel {
pid_t Process::sys$getpid()
KResultOr<pid_t> Process::sys$getpid()
{
REQUIRE_PROMISE(stdio);
return m_pid.value();
}
pid_t Process::sys$getppid()
KResultOr<pid_t> Process::sys$getppid()
{
REQUIRE_PROMISE(stdio);
return m_ppid.value();
}
int Process::sys$get_process_name(Userspace<char*> buffer, size_t buffer_size)
KResultOr<int> Process::sys$get_process_name(Userspace<char*> buffer, size_t buffer_size)
{
REQUIRE_PROMISE(stdio);
if (m_name.length() + 1 > buffer_size)
return -ENAMETOOLONG;
return ENAMETOOLONG;
if (!copy_to_user(buffer, m_name.characters(), m_name.length() + 1))
return -EFAULT;
return EFAULT;
return 0;
}
int Process::sys$set_process_name(Userspace<const char*> user_name, size_t user_name_length)
KResultOr<int> Process::sys$set_process_name(Userspace<const char*> user_name, size_t user_name_length)
{
REQUIRE_PROMISE(proc);
if (user_name_length > 256)
return -ENAMETOOLONG;
return ENAMETOOLONG;
auto name = copy_string_from_user(user_name, user_name_length);
if (name.is_null())
return -EFAULT;
return EFAULT;
// Empty and whitespace-only names only exist to confuse users.
if (name.is_whitespace())
return -EINVAL;
return EINVAL;
m_name = move(name);
return 0;
}
int Process::sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*> user_params)
KResultOr<int> Process::sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*> user_params)
{
Syscall::SC_set_coredump_metadata_params params;
if (!copy_from_user(&params, user_params))
return -EFAULT;
return EFAULT;
if (params.key.length == 0 || params.key.length > 16 * KiB)
return -EINVAL;
return EINVAL;
if (params.value.length > 16 * KiB)
return -EINVAL;
return EINVAL;
auto copied_key = copy_string_from_user(params.key.characters, params.key.length);
if (copied_key.is_null())
return -EFAULT;
return EFAULT;
auto copied_value = copy_string_from_user(params.value.characters, params.value.length);
if (copied_value.is_null())
return -EFAULT;
return EFAULT;
if (!m_coredump_metadata.contains(copied_key) && m_coredump_metadata.size() >= 16)
return -EFAULT;
return EFAULT;
m_coredump_metadata.set(move(copied_key), move(copied_value));
return 0;
}