diff options
author | p0358 <p0358@users.noreply.github.com> | 2021-12-30 04:47:16 +0100 |
---|---|---|
committer | p0358 <p0358@users.noreply.github.com> | 2021-12-30 04:47:16 +0100 |
commit | 2404f063433064e90059e6b3153f663e10d1f884 (patch) | |
tree | 4ca5351bb75e404b93b6ce430c6cbf8ea1a6db86 /loader_launcher_proxy | |
parent | b302ffcad2f433ccbe02674e381d4d27252bb122 (diff) | |
download | NorthstarLauncher-2404f063433064e90059e6b3153f663e10d1f884.tar.gz NorthstarLauncher-2404f063433064e90059e6b3153f663e10d1f884.zip |
add realloc too
Diffstat (limited to 'loader_launcher_proxy')
-rw-r--r-- | loader_launcher_proxy/Memory.cpp | 24 | ||||
-rw-r--r-- | loader_launcher_proxy/Memory.h | 15 |
2 files changed, 36 insertions, 3 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); diff --git a/loader_launcher_proxy/Memory.h b/loader_launcher_proxy/Memory.h index 928e403c..c983966c 100644 --- a/loader_launcher_proxy/Memory.h +++ b/loader_launcher_proxy/Memory.h @@ -5,10 +5,19 @@ class IMemAlloc public: struct VTable { - void* unknown[1]; + void* unknown[1]; // alloc debug void* (*Alloc) (IMemAlloc* memAlloc, size_t nSize); - void* unknown2[3]; - void(*Free) (IMemAlloc* memAlloc, void* pMem); + void* unknown2[1]; // realloc debug + void* (*Realloc)(IMemAlloc* memAlloc, void* pMem, size_t nSize); + void* unknown3[1]; // free #1 + void (*Free) (IMemAlloc* memAlloc, void* pMem); + void* unknown4[2]; // nullsubs, maybe CrtSetDbgFlag + size_t(*GetSize) (IMemAlloc* memAlloc, void* pMem); + void* unknown5[9]; // they all do literally nothing + void (*DumpStats) (IMemAlloc* memAlloc); + void (*DumpStatsFileBase) (IMemAlloc* memAlloc, const char* pchFileBase); + void* unknown6[4]; + int (*heapchk) (IMemAlloc* memAlloc); }; VTable* m_vtable; |