From 7ef9c703d205249e87a67da7b777d133ee46e4ac Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 15 Nov 2019 12:47:18 +0100 Subject: [PATCH] Kernel: Unbreak SlabAllocator after startup-time constructors Now that the kernel supports startup-time constructors, we were first doing slab_alloc_init(), and then the constructors ran later on, zeroing out the freelist pointers. This meant that all slab allocators thought they were completelty exhausted and forwarded all requests to kmalloc() instead. --- Kernel/Heap/SlabAllocator.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Kernel/Heap/SlabAllocator.cpp b/Kernel/Heap/SlabAllocator.cpp index 39b346b3768..c7a9c0b495b 100644 --- a/Kernel/Heap/SlabAllocator.cpp +++ b/Kernel/Heap/SlabAllocator.cpp @@ -61,11 +61,12 @@ private: char padding[templated_slab_size - sizeof(FreeSlab*)]; }; - FreeSlab* m_freelist { nullptr }; - size_t m_num_allocated { 0 }; - size_t m_num_free { 0 }; - void* m_base { nullptr }; - void* m_end { nullptr }; + // NOTE: These are not default-initialized to prevent an init-time constructor from overwriting them + FreeSlab* m_freelist; + size_t m_num_allocated; + size_t m_num_free; + void* m_base; + void* m_end; static_assert(sizeof(FreeSlab) == templated_slab_size); };