From 9944a5bfb9fc4b8d4e5894c190ed80a48f73b663 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 17:12:28 +0200 Subject: [PATCH] eggAllocator matching --- config/SOUE01/splits.txt | 1 + config/SOUE01/symbols.txt | 14 +++++------ configure.py | 2 +- include/egg/core/eggAllocator.h | 5 ++-- include/rvl/MEM/mem_allocator.h | 2 +- src/egg/core/eggAllocator.cpp | 42 +++++++++++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/egg/core/eggAllocator.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 7fefadea..b372f9ee 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -257,6 +257,7 @@ egg/core/eggStream.cpp: egg/core/eggAllocator.cpp: .text start:0x804952D0 end:0x804953F0 .data start:0x8056E8D0 end:0x8056E8E8 + .sdata2 start:0x8057F2F0 end:0x8057F2F8 egg/core/eggHeap.cpp: .text start:0x804953F0 end:0x80495AB0 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 669414f7..976825e5 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26184,12 +26184,12 @@ getUncompressedSize__Q23EGG14StreamDecompRLFPCv = .text:0x80495290; // type:func getHeaderSize__Q23EGG14StreamDecompRLFv = .text:0x804952A0; // type:function size:0x8 getUncompressedSize__Q23EGG14StreamDecompLZFPCv = .text:0x804952B0; // type:function size:0x8 getHeaderSize__Q23EGG14StreamDecompLZFv = .text:0x804952C0; // type:function size:0x8 -egg_allocator_pfAlloc = .text:0x804952D0; // type:function size:0x1C -egg_allocator_pfFree = .text:0x804952F0; // type:function size:0x14 -MEMInitAllocatorForHeap = .text:0x80495310; // type:function size:0x1C -__ct__Q23EGG9AllocatorFPQ23EGG4Heapl = .text:0x80495330; // type:function size:0x50 +MEM_AllocFor_Heap__FP12MEMAllocatorUi = .text:0x804952D0; // type:function size:0x1C scope:local +MEM_FreeFor_Heap__FP12MEMAllocatorPv = .text:0x804952F0; // type:function size:0x14 scope:local +MEMInitAllocatorFor_Heap__FP12MEMAllocatoriPv = .text:0x80495310; // type:function size:0x1C +__ct__Q23EGG9AllocatorFPQ23EGG4Heapi = .text:0x80495330; // type:function size:0x50 __dt__Q23EGG9AllocatorFv = .text:0x80495380; // type:function size:0x40 -alloc__Q23EGG9AllocatorFUl = .text:0x804953C0; // type:function size:0x14 +alloc__Q23EGG9AllocatorFUi = .text:0x804953C0; // type:function size:0x14 free__Q23EGG9AllocatorFPv = .text:0x804953E0; // type:function size:0x10 initialize__Q23EGG4HeapFv = .text:0x804953F0; // type:function size:0x40 __ct__Q23EGG4HeapFP12MEMiHeapHead = .text:0x80495430; // type:function size:0x90 @@ -37094,7 +37094,7 @@ lbl_8056E870 = .data:0x8056E870; // type:object size:0x18 lbl_8056E888 = .data:0x8056E888; // type:object size:0x18 lbl_8056E8A0 = .data:0x8056E8A0; // type:object size:0x18 lbl_8056E8B8 = .data:0x8056E8B8; // type:object size:0x18 -lbl_8056E8D0 = .data:0x8056E8D0; // type:object size:0x18 +__vt__Q23EGG9Allocator = .data:0x8056E8D0; // type:object size:0x14 lbl_8056E8E8 = .data:0x8056E8E8; // type:object size:0x68 lbl_8056E950 = .data:0x8056E950; // type:object size:0x30 lbl_8056E980 = .data:0x8056E980; // type:object size:0x10 @@ -47590,7 +47590,7 @@ lbl_8057F2DC = .sdata2:0x8057F2DC; // type:object size:0x4 data:float lbl_8057F2E0 = .sdata2:0x8057F2E0; // type:object size:0x4 data:float lbl_8057F2E4 = .sdata2:0x8057F2E4; // type:object size:0x4 data:float lbl_8057F2E8 = .sdata2:0x8057F2E8; // type:object size:0x8 data:float -lbl_8057F2F0 = .sdata2:0x8057F2F0; // type:object size:0x8 +eggAllocatorFuncs = .sdata2:0x8057F2F0; // type:object size:0x8 scope:local lbl_8057F2F8 = .sdata2:0x8057F2F8; // type:object size:0x4 data:float lbl_8057F300 = .sdata2:0x8057F300; // type:object size:0x8 data:double lbl_8057F308 = .sdata2:0x8057F308; // type:object size:0x4 data:float diff --git a/configure.py b/configure.py index 830c0c10..2385c5bd 100644 --- a/configure.py +++ b/configure.py @@ -344,7 +344,7 @@ config.libs = [ Object(NonMatching, "egg/core/eggDvdFile.cpp"), Object(NonMatching, "egg/core/eggDvdRipper.cpp"), Object(NonMatching, "egg/core/eggStream.cpp"), - Object(NonMatching, "egg/core/eggAllocator.cpp"), + Object(Matching, "egg/core/eggAllocator.cpp"), Object(NonMatching, "egg/core/eggHeap.cpp"), Object(NonMatching, "egg/core/eggExpHeap.cpp"), Object(NonMatching, "egg/core/eggFrmHeap.cpp"), diff --git a/include/egg/core/eggAllocator.h b/include/egg/core/eggAllocator.h index 454539fe..6a4e32de 100644 --- a/include/egg/core/eggAllocator.h +++ b/include/egg/core/eggAllocator.h @@ -3,9 +3,8 @@ #include "rvl/MEM.h" #include -// /* 80495310 */ MEMInitAllocatorFor_Heap(MEMAllocator* alloc, s32 align, void* heap); -// /* 804952f0 */ MEM_AllocFor_Heap(MEMAllocator* alloc, void* block); -// /* 804952d0 */ MEM_AllocFor_Heap(MEMAllocator* alloc, u32 size, s32 align); +/* 80495310 */ void MEMInitAllocatorFor_Heap(MEMAllocator* alloc, s32 align, void* heap); + namespace EGG { class Heap; class Allocator : public MEMAllocator { diff --git a/include/rvl/MEM/mem_allocator.h b/include/rvl/MEM/mem_allocator.h index 3146fe87..c29054c4 100644 --- a/include/rvl/MEM/mem_allocator.h +++ b/include/rvl/MEM/mem_allocator.h @@ -19,7 +19,7 @@ typedef struct MEMAllocatorFuncs { typedef struct MEMAllocator { const MEMAllocatorFuncs *funcs; // at 0x0 - struct MEMiHeapHead *heap; // at 0x4 + void *heap; // at 0x4 u32 heapParam1; // at 0x8 u32 heapParam2; // at 0xC } MEMAllocator; diff --git a/src/egg/core/eggAllocator.cpp b/src/egg/core/eggAllocator.cpp new file mode 100644 index 00000000..b8ce55f2 --- /dev/null +++ b/src/egg/core/eggAllocator.cpp @@ -0,0 +1,42 @@ +#include +#include + +/* 804952d0 */ static void *MEM_AllocFor_Heap(MEMAllocator* alloc, u32 size) { + return static_cast(static_cast(alloc)->heap)->alloc(size, alloc->heapParam1); +} +/* 804952f0 */ static void MEM_FreeFor_Heap(MEMAllocator* alloc, void* block) { + return static_cast(static_cast(alloc)->heap)->free(block); +} + +const MEMAllocatorFuncs eggAllocatorFuncs = { + &MEM_AllocFor_Heap, + &MEM_FreeFor_Heap, +}; + +// TODO this is used from eggHeap for some reason. Figure out +// the correct privacy boundary later. +/* 80495310 */ void MEMInitAllocatorFor_Heap(MEMAllocator* alloc, s32 align, void* heap) { + alloc->funcs = &eggAllocatorFuncs; + alloc->heap = heap; + alloc->heapParam1 = align; + alloc->heapParam2 = 0; +} + + +namespace EGG { + +/* 80495330 */ Allocator::Allocator(Heap *heap, s32 align) : mHeap(heap), align(align) { + MEMInitAllocatorFor_Heap(this, align, heap); +} + +/* 80495380 */ Allocator::~Allocator() {} + +/* 804953c0 */ void *Allocator::alloc(u32 size) { + return Heap::alloc(size, align, mHeap); +} + +/* 804953e0 */ void Allocator::free(void *block) { + Heap::free(block, mHeap); +} + +} // namespace EGG