diff options
Diffstat (limited to 'loader_launcher_proxy/Memory.cpp')
-rw-r--r-- | loader_launcher_proxy/Memory.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/loader_launcher_proxy/Memory.cpp b/loader_launcher_proxy/Memory.cpp index 6c69d80f..bd19502a 100644 --- a/loader_launcher_proxy/Memory.cpp +++ b/loader_launcher_proxy/Memory.cpp @@ -14,6 +14,7 @@ void LoadTier0Handle() const int STATIC_ALLOC_SIZE = 4096; size_t g_iStaticAllocated = 0; +void* g_pLastAllocated = nullptr; char pStaticAllocBuf[STATIC_ALLOC_SIZE]; // they should never be used here, except in LibraryLoadError? @@ -48,6 +49,29 @@ void free(void* p) (*g_ppMemAllocSingleton)->m_vtable->Free(*g_ppMemAllocSingleton, p); } +void* realloc(void* old_ptr, size_t size) { + // it was allocated into the static buffer + if (old_ptr >= pStaticAllocBuf && old_ptr <= pStaticAllocBuf + STATIC_ALLOC_SIZE) + { + if (g_pLastAllocated == old_ptr) + { + // nothing was allocated after this + size_t old_size = g_iStaticAllocated - ((size_t)g_pLastAllocated - (size_t)pStaticAllocBuf); + size_t diff = size - old_size; + if (diff > 0) + g_iStaticAllocated += diff; + return old_ptr; + } + else + { + return malloc(size); + } + } + + if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton) + return (*g_ppMemAllocSingleton)->m_vtable->Realloc(*g_ppMemAllocSingleton, old_ptr, size); +} + void* operator new(size_t n) { return malloc(n); |