diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-13 00:27:33 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-01-13 00:20:08 -0800 |
commit | 50d6a6a1864301e82cf8d563742c392ee1b2feb4 (patch) | |
tree | 9cd416bfa9f7494a0dbd2a190c3fe9962128755d | |
parent | 640284067008e8f7bf8edd79c9d25b771b429f49 (diff) | |
download | serenity-50d6a6a1864301e82cf8d563742c392ee1b2feb4.zip |
Kernel: Convert hostname to KString
-rw-r--r-- | Kernel/Process.cpp | 6 | ||||
-rw-r--r-- | Kernel/Process.h | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/hostname.cpp | 6 | ||||
-rw-r--r-- | Kernel/Syscalls/uname.cpp | 2 |
4 files changed, 8 insertions, 8 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index b9002a7057..e99682714a 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -45,9 +45,9 @@ static Atomic<pid_t> next_pid; static Singleton<SpinlockProtected<Process::List>> s_all_instances; READONLY_AFTER_INIT Memory::Region* g_signal_trampoline_region; -static Singleton<MutexProtected<String>> s_hostname; +static Singleton<MutexProtected<OwnPtr<KString>>> s_hostname; -MutexProtected<String>& hostname() +MutexProtected<OwnPtr<KString>>& hostname() { return *s_hostname; } @@ -73,7 +73,7 @@ UNMAP_AFTER_INIT void Process::initialize() // Note: This is called before scheduling is initialized, and before APs are booted. // So we can "safely" bypass the lock here. - reinterpret_cast<String&>(hostname()) = "courage"; + reinterpret_cast<OwnPtr<KString>&>(hostname()) = KString::must_create("courage"sv); create_signal_trampoline(); } diff --git a/Kernel/Process.h b/Kernel/Process.h index 416da472d5..090a7d9da9 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -39,7 +39,7 @@ namespace Kernel { -MutexProtected<String>& hostname(); +MutexProtected<OwnPtr<KString>>& hostname(); Time kgettimeofday(); #define ENUMERATE_PLEDGE_PROMISES \ diff --git a/Kernel/Syscalls/hostname.cpp b/Kernel/Syscalls/hostname.cpp index da30c4d2bc..8c96a39a44 100644 --- a/Kernel/Syscalls/hostname.cpp +++ b/Kernel/Syscalls/hostname.cpp @@ -15,9 +15,9 @@ ErrorOr<FlatPtr> Process::sys$gethostname(Userspace<char*> buffer, size_t size) if (size > NumericLimits<ssize_t>::max()) return EINVAL; return hostname().with_shared([&](const auto& name) -> ErrorOr<FlatPtr> { - if (size < (name.length() + 1)) + if (size < (name->length() + 1)) return ENAMETOOLONG; - TRY(copy_to_user(buffer, name.characters(), name.length() + 1)); + TRY(copy_to_user(buffer, name->characters(), name->length() + 1)); return 0; }); } @@ -33,7 +33,7 @@ ErrorOr<FlatPtr> Process::sys$sethostname(Userspace<const char*> buffer, size_t return ENAMETOOLONG; auto new_name = TRY(try_copy_kstring_from_user(buffer, length)); hostname().with_exclusive([&](auto& name) { - name = new_name->view(); + name = move(new_name); }); return 0; } diff --git a/Kernel/Syscalls/uname.cpp b/Kernel/Syscalls/uname.cpp index ab6ac949ef..b652630bb8 100644 --- a/Kernel/Syscalls/uname.cpp +++ b/Kernel/Syscalls/uname.cpp @@ -24,7 +24,7 @@ ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf) #endif hostname().with_shared([&](const auto& name) { - memcpy(buf.nodename, name.characters(), name.length() + 1); + memcpy(buf.nodename, name->characters(), name->length() + 1); }); TRY(copy_to_user(user_buf, &buf)); |