Bläddra i källkod

Kernel: Convert hostname to KString

Idan Horowitz 3 år sedan
förälder
incheckning
50d6a6a186
4 ändrade filer med 8 tillägg och 8 borttagningar
  1. 3 3
      Kernel/Process.cpp
  2. 1 1
      Kernel/Process.h
  3. 3 3
      Kernel/Syscalls/hostname.cpp
  4. 1 1
      Kernel/Syscalls/uname.cpp

+ 3 - 3
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();
 }

+ 1 - 1
Kernel/Process.h

@@ -39,7 +39,7 @@
 
 namespace Kernel {
 
-MutexProtected<String>& hostname();
+MutexProtected<OwnPtr<KString>>& hostname();
 Time kgettimeofday();
 
 #define ENUMERATE_PLEDGE_PROMISES         \

+ 3 - 3
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;
 }

+ 1 - 1
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));