Kernel: Allocate version string in the Process::initialize() method
Instead of allocating a KString on each uname syscall, just allocate during boot so we never have to worry about heap allocation in that syscall.
This commit is contained in:
parent
d8b514873f
commit
58b509584a
Notes:
sideshowbarker
2024-07-17 07:38:17 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/58b509584a Pull-request: https://github.com/SerenityOS/serenity/pull/20037 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/kleinesfilmroellchen ✅
2 changed files with 9 additions and 2 deletions
Kernel
|
@ -19,6 +19,8 @@ namespace Kernel {
|
|||
# error Unknown architecture
|
||||
#endif
|
||||
|
||||
KString* g_version_string { nullptr };
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
|
||||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
|
@ -32,8 +34,8 @@ ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
|
|||
UNAME_MACHINE
|
||||
};
|
||||
|
||||
auto version_string = TRY(KString::formatted("{}.{}-dev", SERENITY_MAJOR_REVISION, SERENITY_MINOR_REVISION));
|
||||
AK::TypedTransfer<u8>::copy(reinterpret_cast<u8*>(buf.release), version_string->bytes().data(), min(version_string->length(), UTSNAME_ENTRY_LEN - 1));
|
||||
VERIFY(g_version_string);
|
||||
AK::TypedTransfer<u8>::copy(reinterpret_cast<u8*>(buf.release), g_version_string->bytes().data(), min(g_version_string->length(), UTSNAME_ENTRY_LEN - 1));
|
||||
|
||||
AK::TypedTransfer<u8>::copy(reinterpret_cast<u8*>(buf.version), SERENITY_VERSION.bytes().data(), min(SERENITY_VERSION.length(), UTSNAME_ENTRY_LEN - 1));
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <Kernel/Tasks/Thread.h>
|
||||
#include <Kernel/Tasks/ThreadTracer.h>
|
||||
#include <Kernel/Time/TimerQueue.h>
|
||||
#include <Kernel/Version.h>
|
||||
|
||||
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<LockRank::None> g_profiling_lock {};
|
||||
static Atomic<pid_t> 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<FixedStringBuffer<UTSNAME_ENTRY_LEN - 1>&>(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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue