mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +00:00

This change lays the foundation for making the require_promise return an error hand handling the process abort outside of the syscall implementations, to avoid cases where we would leak resources. It also has the advantage that it makes removes a gs pointer read to look up the current thread, then process for every syscall. We can instead go through the Process this pointer in most cases.
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/Process.h>
|
|
|
|
namespace Kernel {
|
|
|
|
ErrorOr<FlatPtr> Process::sys$gethostname(Userspace<char*> buffer, size_t size)
|
|
{
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this)
|
|
require_promise(Pledge::stdio);
|
|
if (size > NumericLimits<ssize_t>::max())
|
|
return EINVAL;
|
|
return hostname().with_shared([&](const auto& name) -> ErrorOr<FlatPtr> {
|
|
if (size < (name.length() + 1))
|
|
return ENAMETOOLONG;
|
|
TRY(copy_to_user(buffer, name.characters(), name.length() + 1));
|
|
return 0;
|
|
});
|
|
}
|
|
|
|
ErrorOr<FlatPtr> Process::sys$sethostname(Userspace<const char*> buffer, size_t length)
|
|
{
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this)
|
|
REQUIRE_NO_PROMISES;
|
|
if (!is_superuser())
|
|
return EPERM;
|
|
if (length > 64)
|
|
return ENAMETOOLONG;
|
|
auto new_name = TRY(try_copy_kstring_from_user(buffer, length));
|
|
return hostname().with_exclusive([&](auto& name) -> ErrorOr<FlatPtr> {
|
|
// FIXME: Use KString instead of String here.
|
|
name = new_name->view();
|
|
return 0;
|
|
});
|
|
}
|
|
|
|
}
|