1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +00:00

Kernel: Migrate hostname locking to ProtectedValue

This commit is contained in:
Jean-Baptiste Boric 2021-07-18 15:00:48 +02:00 committed by Andreas Kling
parent 9517100672
commit 626b99ce1c
4 changed files with 32 additions and 28 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Singleton.h>
#include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h>
#include <AK/Time.h>
@ -45,11 +46,16 @@ static void create_signal_trampoline();
RecursiveSpinLock g_processes_lock;
static Atomic<pid_t> next_pid;
READONLY_AFTER_INIT Process::List* g_processes;
READONLY_AFTER_INIT String* g_hostname;
READONLY_AFTER_INIT Mutex* g_hostname_lock;
READONLY_AFTER_INIT HashMap<String, OwnPtr<Module>>* g_modules;
READONLY_AFTER_INIT Memory::Region* g_signal_trampoline_region;
static AK::Singleton<ProtectedValue<String>> s_hostname;
ProtectedValue<String>& hostname()
{
return *s_hostname;
}
ProcessID Process::allocate_pid()
{
// Overflow is UB, and negative PIDs wreck havoc.
@ -67,8 +73,10 @@ UNMAP_AFTER_INIT void Process::initialize()
next_pid.store(0, AK::MemoryOrder::memory_order_release);
g_processes = new Process::List();
g_process_groups = new ProcessGroup::List();
g_hostname = new String("courage");
g_hostname_lock = new Mutex;
hostname().with_exclusive([&](auto& name) {
name = "courage";
});
create_signal_trampoline();
}