Fix getMaxAllocatableSize & CMemBlock::getBlock on 64-bit

This commit is contained in:
PJB3005
2026-02-24 21:39:45 +01:00
parent 6e0c9f2637
commit 696cf75ed3
3 changed files with 17 additions and 3 deletions
+9 -1
View File
@@ -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();
+6
View File
@@ -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
*
+2 -2
View File
@@ -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);
}