aboutsummaryrefslogtreecommitdiff
path: root/loader_launcher_proxy/Memory.cpp
diff options
context:
space:
mode:
authorp0358 <p0358@users.noreply.github.com>2021-12-30 02:58:19 +0100
committerp0358 <p0358@users.noreply.github.com>2021-12-30 02:58:19 +0100
commitd2ee389192aa425ef9c81b2c3367ffb0de6976d0 (patch)
treef244033f6d85055ca272f8369942969848d053f5 /loader_launcher_proxy/Memory.cpp
parentc18b293ba739424bee6db39e2e5a3081b0010a13 (diff)
downloadNorthstarLauncher-d2ee389192aa425ef9c81b2c3367ffb0de6976d0.tar.gz
NorthstarLauncher-d2ee389192aa425ef9c81b2c3367ffb0de6976d0.zip
Refactor and fix of various issues, add run_northstar.txt support
Diffstat (limited to 'loader_launcher_proxy/Memory.cpp')
-rw-r--r--loader_launcher_proxy/Memory.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/loader_launcher_proxy/Memory.cpp b/loader_launcher_proxy/Memory.cpp
index d5642ca5..6c69d80f 100644
--- a/loader_launcher_proxy/Memory.cpp
+++ b/loader_launcher_proxy/Memory.cpp
@@ -1,11 +1,11 @@
#include "pch.h"
-HMODULE hTier0Module;
+extern HMODULE hTier0Module;
IMemAlloc** g_ppMemAllocSingleton;
void LoadTier0Handle()
{
- hTier0Module = GetModuleHandleA("tier0.dll");
+ if (!hTier0Module) hTier0Module = GetModuleHandleA("tier0.dll");
if (!hTier0Module) return;
g_ppMemAllocSingleton = (IMemAlloc**)GetProcAddress(hTier0Module, "g_pMemAllocSingleton");
@@ -16,9 +16,9 @@ const int STATIC_ALLOC_SIZE = 4096;
size_t g_iStaticAllocated = 0;
char pStaticAllocBuf[STATIC_ALLOC_SIZE];
-// they should never be used here, except in LibraryLoadError
+// they should never be used here, except in LibraryLoadError?
-void* operator new(size_t n)
+void* malloc(size_t n)
{
// allocate into static buffer
if (g_iStaticAllocated + n <= STATIC_ALLOC_SIZE)
@@ -30,7 +30,7 @@ void* operator new(size_t n)
else
{
// try to fallback to g_pMemAllocSingleton
- if (!hTier0Module) LoadTier0Handle();
+ if (!hTier0Module || !g_ppMemAllocSingleton) LoadTier0Handle();
if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
return (*g_ppMemAllocSingleton)->m_vtable->Alloc(*g_ppMemAllocSingleton, n);
else
@@ -38,7 +38,7 @@ void* operator new(size_t n)
}
}
-void operator delete(void* p)
+void free(void* p)
{
// if it was allocated into the static buffer, just do nothing, safest way to deal with it
if (p >= pStaticAllocBuf && p <= pStaticAllocBuf + STATIC_ALLOC_SIZE)
@@ -47,3 +47,13 @@ void operator delete(void* p)
if (g_ppMemAllocSingleton && *g_ppMemAllocSingleton)
(*g_ppMemAllocSingleton)->m_vtable->Free(*g_ppMemAllocSingleton, p);
}
+
+void* operator new(size_t n)
+{
+ return malloc(n);
+}
+
+void operator delete(void* p)
+{
+ return free(p);
+}