mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-05 16:14:38 +00:00
Kernel: Don't allocate memory for names of processes and threads
Instead, use the FixedCharBuffer class to ensure we always use a static buffer storage for these names. This ensures that if a Process or a Thread were created, there's a guarantee that setting a new name will never fail, as only copying of strings should be done to that static storage. The limits which are set are 32 characters for processes' names and 64 characters for thread names - this is because threads' names could be more verbose than processes' names.
This commit is contained in:
@@ -26,8 +26,6 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static constexpr StringView power_state_switch_task_name_view = "Power State Switch Task"sv;
|
||||
|
||||
Thread* g_power_state_switch_task;
|
||||
bool g_in_system_shutdown { false };
|
||||
|
||||
@@ -53,12 +51,9 @@ void PowerStateSwitchTask::power_state_switch_task(void* raw_entry_data)
|
||||
|
||||
void PowerStateSwitchTask::spawn(PowerStateCommand command)
|
||||
{
|
||||
// FIXME: If we switch power states during memory pressure, don't let the system crash just because of our task name.
|
||||
NonnullOwnPtr<KString> power_state_switch_task_name = MUST(KString::try_create(power_state_switch_task_name_view));
|
||||
|
||||
VERIFY(g_power_state_switch_task == nullptr);
|
||||
auto [_, power_state_switch_task_thread] = MUST(Process::create_kernel_process(
|
||||
move(power_state_switch_task_name), power_state_switch_task, bit_cast<void*>(command)));
|
||||
"Power State Switch Task"sv, power_state_switch_task, bit_cast<void*>(command)));
|
||||
g_power_state_switch_task = move(power_state_switch_task_thread);
|
||||
}
|
||||
|
||||
@@ -189,7 +184,7 @@ ErrorOr<void> PowerStateSwitchTask::kill_processes(ProcessKind kind, ProcessID f
|
||||
if (process.pid() != Process::current().pid() && !process.is_dead() && process.pid() != finalizer_pid && process.is_kernel_process() == kill_kernel_processes) {
|
||||
dbgln("Process {:2} kernel={} dead={} dying={} ({})",
|
||||
process.pid(), process.is_kernel_process(), process.is_dead(), process.is_dying(),
|
||||
process.name().with([](auto& name) { return name->view(); }));
|
||||
process.name().with([](auto& name) { return name.representable_view(); }));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user