1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:37:42 +00:00

Kernel: Migrate hostname locking to ProtectedValue

This commit is contained in:
Jean-Baptiste Boric 2021-07-18 15:00:48 +02:00 committed by Andreas Kling
parent 9517100672
commit 626b99ce1c
4 changed files with 32 additions and 28 deletions

View file

@ -11,15 +11,8 @@ namespace Kernel {
KResultOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
{
VERIFY_NO_PROCESS_BIG_LOCK(this)
extern String* g_hostname;
extern Mutex* g_hostname_lock;
REQUIRE_PROMISE(stdio);
MutexLocker locker(*g_hostname_lock, Mutex::Mode::Shared);
if (g_hostname->length() + 1 > sizeof(utsname::nodename))
return ENAMETOOLONG;
utsname buf {};
memcpy(buf.sysname, "SerenityOS", 11);
memcpy(buf.release, "1.0-dev", 8);
@ -30,7 +23,9 @@ KResultOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
memcpy(buf.machine, "x86_64", 7);
#endif
memcpy(buf.nodename, g_hostname->characters(), g_hostname->length() + 1);
hostname().with_shared([&](const auto& name) {
memcpy(buf.nodename, name.characters(), name.length() + 1);
});
if (!copy_to_user(user_buf, &buf))
return EFAULT;