From 409b874514995286fd3cfc3f397cd97e4e74a551 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 26 Jun 2021 04:09:25 +0200 Subject: [PATCH] Kernel: Ensure that the ProcessBase class is properly laid out on x86_64 Without this the ProcessBase class is placed into the padding for the ProtectedProcessBase class which then causes the members of the RefCounted class to end up without the first 4096 bytes of the Process class: BP 1, Kernel::Process::protect_data (this=this@entry=0xc063b000) 205 { (gdb) p &m_ref_count $1 = (AK::Atomic *) 0xc063bffc Note how the difference between 'this' and &m_ref_count is less than 4096. --- Kernel/Process.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Kernel/Process.h b/Kernel/Process.h index cd18698ea9..f14fc87b98 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -109,7 +109,10 @@ protected: class ProcessBase : public ProtectedProcessBase { protected: - u8 m_process_base_padding[PAGE_SIZE - sizeof(ProtectedProcessBase)]; + // Without the alignas specifier here the compiler places this class into + // the parent class' padding which then causes the members for the RefCounted + // class to be placed within the first page of the Process class. + alignas(ProtectedProcessBase) u8 m_process_base_padding[PAGE_SIZE - sizeof(ProtectedProcessBase)]; }; static_assert(sizeof(ProcessBase) == PAGE_SIZE);