Extracted VerifyWow64() function, so that the Cxbx and CxbxLoader projects share the same implementation.

For this, renamed LoaderTooling.cpp to AddressRanges.cpp, which better aligns with AddressRanges.h anyway.
This commit is contained in:
PatrickvL 2019-02-07 15:15:18 +01:00 committed by RadWolfie
parent bf115fe7ab
commit c537539c6e
6 changed files with 26 additions and 21 deletions

View File

@ -262,7 +262,7 @@ file (GLOB CXBXR_KRNL_CPP
file (GLOB CXBXR_SOURCE_EMU
"${CXBXR_KRNL_CPP}"
"${CXBXR_ROOT_DIR}/HighPerformanceGraphicsEnabler.c"
"${CXBXR_ROOT_DIR}/src/common/LoaderTooling.cpp"
"${CXBXR_ROOT_DIR}/src/common/AddressRanges.cpp"
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/glextensions.cpp"
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/gloffscreen_common.cpp"
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/gloffscreen_wgl.cpp"

View File

@ -28,7 +28,7 @@ file (GLOB HEADERS
)
file (GLOB SOURCES
"${CXBXR_ROOT_DIR}/src/common/LoaderTooling.cpp"
"${CXBXR_ROOT_DIR}/src/common/AddressRanges.cpp"
"${CXBXR_ROOT_DIR}/src/common/ReserveAddressRanges.cpp"
"${CXBXR_ROOT_DIR}/src/loader/loader.cpp"
)

View File

@ -9,7 +9,7 @@
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Common->LoaderTooling.cpp
// * Common->AddressRanges.cpp
// *
// * This file is part of the Cxbx project.
// *
@ -46,6 +46,20 @@ bool IsOptionalAddressRange(const int index)
return AddressRangeMatchesFlags(index, MAY_FAIL);
}
bool VerifyWow64()
{
typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
BOOL bIsWow64 = FALSE;
HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32"));
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(hKernel32, "IsWow64Process");
if (fnIsWow64Process != nullptr) {
HANDLE hCurrentProcess = GetCurrentProcess();
fnIsWow64Process(hCurrentProcess, &bIsWow64);
}
return (bIsWow64 != FALSE);
}
LPTSTR GetLastErrorString()
{
DWORD err = GetLastError();

View File

@ -119,5 +119,7 @@ const struct {
extern bool AddressRangeMatchesFlags(const int index, const int flags);
extern bool IsOptionalAddressRange(const int index);
extern bool VerifyWow64();
extern LPTSTR GetLastErrorString();
extern void FreeLastErrorString(LPTSTR Error);

View File

@ -27,6 +27,7 @@
#include "WndMain.h"
#include "AddressRanges.h" // For VerifyWow64()
#include "core\kernel\init\CxbxKrnl.h"
#include "core\kernel\support\Emu.h"
#include "EmuShared.h"
@ -45,14 +46,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// First detect if we are running on WoW64, if not, prevent Cxbx-Reloaded from starting
// Cxbx-Relaoded needs access to high memory, only exposed to WoW64.
typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
BOOL bIsWow64 = FALSE;
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
if (fnIsWow64Process != nullptr) {
fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
}
if (bIsWow64 == FALSE) {
if (!VerifyWow64()) {
MessageBox(NULL, "Cxbx-Reloaded can only run under WoW64\nThis means either a 64-bit version of Windows or Wine with a 64-bit prefix", "Cxbx-Reloaded",
MB_OK | MB_ICONERROR);
return EXIT_FAILURE;

View File

@ -117,15 +117,10 @@ DWORD CALLBACK rawMain()
{
(void)virtual_memory_placeholder; // prevent optimization removing this data
// Verify we're running under WOW64
BOOL bIsWow64Process;
if (!IsWow64Process(GetCurrentProcess(), &bIsWow64Process)) {
bIsWow64Process = false;
}
if (!bIsWow64Process) {
OutputMessage("Not running as a WOW64 process!\n");
// First detect if we are running on WoW64, if not, prevent Cxbx-Reloaded from starting
// Cxbx-Relaoded needs access to high memory, only exposed to WoW64.
if (!VerifyWow64()) {
OutputMessage("Cxbx-Reloaded can only run under WoW64\nThis means either a 64-bit version of Windows or Wine with a 64-bit prefix\n");
return ERROR_BAD_ENVIRONMENT;
}
@ -169,7 +164,7 @@ DWORD CALLBACK rawMain()
}
// Only after the required memory ranges are reserved, load our emulation DLL
HMODULE hEmulationDLL = LoadLibraryA("CxbxEmulator.dll");
HMODULE hEmulationDLL = LoadLibrary(TEXT("CxbxEmulator.dll"));
if (!hEmulationDLL) {
OutputMessage("Error loading CxbxEmulator.dll\n");
LPTSTR Error = GetLastErrorString();