diff --git a/Kernel/Syscalls/uname.cpp b/Kernel/Syscalls/uname.cpp index 7cf1e5087c..7eb0828a41 100644 --- a/Kernel/Syscalls/uname.cpp +++ b/Kernel/Syscalls/uname.cpp @@ -19,6 +19,8 @@ namespace Kernel { # error Unknown architecture #endif +KString* g_version_string { nullptr }; + ErrorOr Process::sys$uname(Userspace user_buf) { VERIFY_NO_PROCESS_BIG_LOCK(this); @@ -32,8 +34,8 @@ ErrorOr Process::sys$uname(Userspace user_buf) UNAME_MACHINE }; - auto version_string = TRY(KString::formatted("{}.{}-dev", SERENITY_MAJOR_REVISION, SERENITY_MINOR_REVISION)); - AK::TypedTransfer::copy(reinterpret_cast(buf.release), version_string->bytes().data(), min(version_string->length(), UTSNAME_ENTRY_LEN - 1)); + VERIFY(g_version_string); + AK::TypedTransfer::copy(reinterpret_cast(buf.release), g_version_string->bytes().data(), min(g_version_string->length(), UTSNAME_ENTRY_LEN - 1)); AK::TypedTransfer::copy(reinterpret_cast(buf.version), SERENITY_VERSION.bytes().data(), min(SERENITY_VERSION.length(), UTSNAME_ENTRY_LEN - 1)); diff --git a/Kernel/Tasks/Process.cpp b/Kernel/Tasks/Process.cpp index db41cab486..597b073e54 100644 --- a/Kernel/Tasks/Process.cpp +++ b/Kernel/Tasks/Process.cpp @@ -40,6 +40,7 @@ #include #include #include +#include namespace Kernel { @@ -47,6 +48,7 @@ static void create_signal_trampoline(); extern ProcessID g_init_pid; extern bool g_in_system_shutdown; +extern KString* g_version_string; RecursiveSpinlock g_profiling_lock {}; static Atomic next_pid; @@ -162,6 +164,9 @@ 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&>(hostname()).store_characters("courage"sv); + // NOTE: Just allocate the kernel version string here so we never have to worry + // about OOM conditions in the uname syscall. + g_version_string = MUST(KString::formatted("{}.{}-dev", SERENITY_MAJOR_REVISION, SERENITY_MINOR_REVISION)).leak_ptr(); create_signal_trampoline(); }