mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
Kernel: Use FixedStringBuffer for fixed-length strings in syscalls
Using the kernel stack is preferable, especially when the examined strings should be limited to a reasonable length. This is a small improvement, because if we don't actually move these strings then we don't need to own heap allocations for them during the syscall handler function scope. In addition to that, some kernel strings are known to be limited, like the hostname string, for these strings we also can use FixedStringBuffer to store and copy to and from these buffers, without using any heap allocations at all.
This commit is contained in:
parent
3fd4997fc2
commit
d8b514873f
13 changed files with 100 additions and 46 deletions
|
@ -53,9 +53,9 @@ static Atomic<pid_t> next_pid;
|
|||
static Singleton<SpinlockProtected<Process::AllProcessesList, LockRank::None>> s_all_instances;
|
||||
READONLY_AFTER_INIT Memory::Region* g_signal_trampoline_region;
|
||||
|
||||
static Singleton<MutexProtected<OwnPtr<KString>>> s_hostname;
|
||||
static Singleton<MutexProtected<FixedStringBuffer<UTSNAME_ENTRY_LEN - 1>>> s_hostname;
|
||||
|
||||
MutexProtected<OwnPtr<KString>>& hostname()
|
||||
MutexProtected<FixedStringBuffer<UTSNAME_ENTRY_LEN - 1>>& hostname()
|
||||
{
|
||||
return *s_hostname;
|
||||
}
|
||||
|
@ -161,7 +161,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<OwnPtr<KString>&>(hostname()) = KString::must_create("courage"sv);
|
||||
reinterpret_cast<FixedStringBuffer<UTSNAME_ENTRY_LEN - 1>&>(hostname()).store_characters("courage"sv);
|
||||
|
||||
create_signal_trampoline();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue