Skip to content

Commit

Permalink
remove exception guards on startup, probably worse than the alternati…
Browse files Browse the repository at this point in the history
…ve especially now that it's two stage
  • Loading branch information
ianpatt committed Sep 1, 2023
1 parent 78bc920 commit 8978924
Showing 1 changed file with 31 additions and 56 deletions.
87 changes: 31 additions & 56 deletions sfse/sfse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,80 +88,55 @@ void SFSE_Preinit()
if(runOnce) return;
runOnce = true;

#ifndef _DEBUG
__try {
#endif

SYSTEMTIME now;
GetSystemTime(&now);
SYSTEMTIME now;
GetSystemTime(&now);

_MESSAGE("SFSE runtime: initialize (version = %d.%d.%d %08X %04d-%02d-%02d %02d:%02d:%02d, os = %s)",
SFSE_VERSION_INTEGER, SFSE_VERSION_INTEGER_MINOR, SFSE_VERSION_INTEGER_BETA, RUNTIME_VERSION,
now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond,
getOSInfoStr().c_str());
_MESSAGE("SFSE runtime: initialize (version = %d.%d.%d %08X %04d-%02d-%02d %02d:%02d:%02d, os = %s)",
SFSE_VERSION_INTEGER, SFSE_VERSION_INTEGER_MINOR, SFSE_VERSION_INTEGER_BETA, RUNTIME_VERSION,
now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond,
getOSInfoStr().c_str());

_MESSAGE("imagebase = %016I64X", g_moduleHandle);
_MESSAGE("reloc mgr imagebase = %016I64X", RelocationManager::s_baseAddr);
_MESSAGE("imagebase = %016I64X", g_moduleHandle);
_MESSAGE("reloc mgr imagebase = %016I64X", RelocationManager::s_baseAddr);

#ifdef _DEBUG
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);

WaitForDebugger();
WaitForDebugger();
#endif

if(!g_branchTrampoline.create(1024 * 64))
{
_ERROR("couldn't create branch trampoline. this is fatal. skipping remainder of init process.");
return;
}

if(!g_localTrampoline.create(1024 * 64, g_moduleHandle))
{
_ERROR("couldn't create codegen buffer. this is fatal. skipping remainder of init process.");
return;
}

// scan plugin folder
g_pluginManager.init();

// preload plugins
g_pluginManager.installPlugins(PluginManager::kPhase_Preload);

#ifndef _DEBUG
if(!g_branchTrampoline.create(1024 * 64))
{
_ERROR("couldn't create branch trampoline. this is fatal. skipping remainder of init process.");
return;
}
__except(EXCEPTION_EXECUTE_HANDLER)

if(!g_localTrampoline.create(1024 * 64, g_moduleHandle))
{
_ERROR("exception thrown during preinit");
_ERROR("couldn't create codegen buffer. this is fatal. skipping remainder of init process.");
return;
}
#endif

// scan plugin folder
g_pluginManager.init();

// preload plugins
g_pluginManager.installPlugins(PluginManager::kPhase_Preload);

_MESSAGE("preinit complete");
}

static bool isInit = false;

void SFSE_Initialize()
{
if(isInit) return;
isInit = true;

#ifndef _DEBUG
__try {
#endif

// load plugins
g_pluginManager.installPlugins(PluginManager::kPhase_Preload);
g_pluginManager.loadComplete();
static bool runOnce = false;
if(runOnce) return;
runOnce = true;

FlushInstructionCache(GetCurrentProcess(), NULL, 0);
// load plugins
g_pluginManager.installPlugins(PluginManager::kPhase_Preload);
g_pluginManager.loadComplete();

#ifndef _DEBUG
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
_ERROR("exception thrown during init");
}
#endif
FlushInstructionCache(GetCurrentProcess(), NULL, 0);

_MESSAGE("init complete");
}
Expand Down

0 comments on commit 8978924

Please sign in to comment.