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<unsigned int, (AK::MemoryOrder)5> *) 0xc063bffc

Note how the difference between 'this' and &m_ref_count is less than
4096.
This commit is contained in:
Gunnar Beutner 2021-06-26 04:09:25 +02:00 committed by Andreas Kling
parent 9077c64d37
commit 409b874514
Notes: sideshowbarker 2024-07-18 11:29:42 +09:00

View file

@ -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);