From 476f17b3f18234f9d66ba112df77e248a17e2f6f Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 5 Sep 2020 15:52:14 -0600 Subject: Kernel: Merge PurgeableVMObject into AnonymousVMObject This implements memory commitments and lazy-allocation of committed memory. --- Kernel/Thread.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Kernel/Thread.cpp') diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index e1b1bd5e5a..2b7e1b7ea6 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -86,7 +86,12 @@ Thread::Thread(NonnullRefPtr process) m_tss.cr3 = m_process->page_directory().cr3(); - m_kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, String::format("Kernel Stack (Thread %d)", m_tid.value()), Region::Access::Read | Region::Access::Write, false, true); + m_kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, String::format("Kernel Stack (Thread %d)", m_tid.value()), Region::Access::Read | Region::Access::Write, false, AllocationStrategy::AllocateNow); + if (!m_kernel_stack_region) { + // Abort creating this thread, was_created() will return false + return; + } + m_kernel_stack_region->set_stack(true); m_kernel_stack_base = m_kernel_stack_region->vaddr().get(); m_kernel_stack_top = m_kernel_stack_region->vaddr().offset(default_kernel_stack_size).get() & 0xfffffff8u; @@ -858,6 +863,10 @@ RegisterState& Thread::get_register_dump_from_stack() RefPtr Thread::clone(Process& process) { auto clone = adopt(*new Thread(process)); + if (!clone->was_created()) { + // We failed to clone this thread + return {}; + } memcpy(clone->m_signal_action_data, m_signal_action_data, sizeof(m_signal_action_data)); clone->m_signal_mask = m_signal_mask; memcpy(clone->m_fpu_state, m_fpu_state, sizeof(FPUState)); @@ -1052,7 +1061,7 @@ KResult Thread::make_thread_specific_region(Badge) if (!process().m_master_tls_region) return KSuccess; - auto* region = process().allocate_region({}, thread_specific_region_size(), "Thread-specific", PROT_READ | PROT_WRITE, true); + auto* region = process().allocate_region({}, thread_specific_region_size(), "Thread-specific", PROT_READ | PROT_WRITE); if (!region) return KResult(-ENOMEM); -- cgit v1.2.3