diff --git a/include/JSystem/JKernel/JKRExpHeap.h b/include/JSystem/JKernel/JKRExpHeap.h index 1535ba757b..a31b2c5e84 100644 --- a/include/JSystem/JKernel/JKRExpHeap.h +++ b/include/JSystem/JKernel/JKRExpHeap.h @@ -35,7 +35,7 @@ public: CMemBlock* getNextBlock() const { return mNext; } u32 getSize() const { return size; } u8 getGroupId() const { return mGroupId; } - static CMemBlock* getBlock(void* data) { return (CMemBlock*)((uintptr_t)data + -0x10); } + static CMemBlock* getBlock(void* data) { return (CMemBlock*)((uintptr_t)data + -sizeof(CMemBlock)); } private: /* 0x0 */ u16 mMagic; @@ -44,9 +44,17 @@ public: /* 0x4 */ u32 size; /* 0x8 */ CMemBlock* mPrev; /* 0xC */ CMemBlock* mNext; +#if BIT_64 + // Ensure padded to 0x20 bytes on 64-bit + void* _pad; +#endif }; // Size: 0x10 friend class CMemBlock; +#if TARGET_PC + static_assert(sizeof(CMemBlock) == MEM_BLOCK_SIZE); +#endif + protected: JKRExpHeap(void* data, u32 size, JKRHeap* parent, bool errorFlag); virtual ~JKRExpHeap(); diff --git a/include/JSystem/JKernel/JKRHeap.h b/include/JSystem/JKernel/JKRHeap.h index c23b72180f..67fb6b8e6d 100644 --- a/include/JSystem/JKernel/JKRHeap.h +++ b/include/JSystem/JKernel/JKRHeap.h @@ -16,6 +16,12 @@ extern u8 JKRValue_DEBUGFILL_DELETE; extern s32 fillcheck_dispcount; extern bool data_8074A8D0_debug; +#if BIT_64 +#define MEM_BLOCK_SIZE 0x20 +#else +#define MEM_BLOCK_SIZE 0x10 +#endif + /** * @ingroup jsystem-jkernel * diff --git a/src/JSystem/JKernel/JKRHeap.cpp b/src/JSystem/JKernel/JKRHeap.cpp index 8960b58c7a..1ad3eedceb 100644 --- a/src/JSystem/JKernel/JKRHeap.cpp +++ b/src/JSystem/JKernel/JKRHeap.cpp @@ -313,8 +313,8 @@ u8 JKRHeap::getCurrentGroupId() { } u32 JKRHeap::getMaxAllocatableSize(int alignment) { - u32 maxFreeBlock = (uintptr_t)getMaxFreeBlock(); - u32 ptrOffset = (alignment - 1) & alignment - (maxFreeBlock & 0xf); + uintptr_t maxFreeBlock = (uintptr_t)getMaxFreeBlock(); + uintptr_t ptrOffset = (alignment - 1) & alignment - (maxFreeBlock & (MEM_BLOCK_SIZE - 1)); return ~(alignment - 1) & (getFreeSize() - ptrOffset); }