MCPcopy Create free account
hub / github.com/Fable2Recomp/Fable2Recomp / lhHeapRealloc_entry

Function lhHeapRealloc_entry

src/heap.cpp:49–91  ·  view source on GitHub ↗

lhHeapRealloc replacement — unified alloc/realloc/free (Lua allocator protocol) r3 = heap (ignored), r4 = old_ptr, r5 = old_size, r6 = new_size

Source from the content-addressed store, hash-verified

47// lhHeapRealloc replacement — unified alloc/realloc/free (Lua allocator protocol)
48// r3 = heap (ignored), r4 = old_ptr, r5 = old_size, r6 = new_size
49ppc_u32_result_t lhHeapRealloc_entry(ppc_u32_t heap, ppc_u32_t old_ptr, ppc_u32_t old_size, ppc_u32_t new_size) {
50 uint32_t optr = static_cast<uint32_t>(old_ptr);
51 uint32_t osize = static_cast<uint32_t>(old_size);
52 uint32_t nsize = static_cast<uint32_t>(new_size);
53
54 // Free
55 if (nsize == 0) {
56 if (optr && InArena(optr)) {
57 mspace_free(g_mspace, GuestToHost(optr));
58 }
59 return 0;
60 }
61
62 // Alloc (no old pointer)
63 if (!optr) {
64 void* ptr = mspace_malloc(g_mspace, nsize);
65 if (!ptr) {
66 REXLOG_WARN("lhHeapRealloc: mspace_malloc({}) failed", nsize);
67 return 0;
68 }
69 return HostToGuest(ptr);
70 }
71
72 // Realloc — old pointer outside our arena (pre-hook allocation)
73 if (!InArena(optr)) {
74 REXLOG_WARN("lhHeapRealloc: old ptr 0x{:08X} OOB, treating as new alloc({})", optr, nsize);
75 void* ptr = mspace_malloc(g_mspace, nsize);
76 if (!ptr) {
77 REXLOG_WARN("lhHeapRealloc: mspace_malloc({}) failed", nsize);
78 return 0;
79 }
80 return HostToGuest(ptr);
81 }
82
83 // Realloc — old pointer in our arena
84 void* old_host = GuestToHost(optr);
85 void* new_host = mspace_realloc(g_mspace, old_host, nsize);
86 if (!new_host) {
87 REXLOG_WARN("lhHeapRealloc: mspace_realloc({}) failed", nsize);
88 return 0;
89 }
90 return HostToGuest(new_host);
91}
92
93// lh_PhysicalAllocCached replacement — redirects physical memory allocations
94// to our native heap with proper alignment.

Callers

nothing calls this directly

Calls 3

InArenaFunction · 0.85
GuestToHostFunction · 0.85
HostToGuestFunction · 0.85

Tested by

no test coverage detected