Merge pull request #2271 from RadWolfie/cleanup-kernel-process

Some cleanup kernel process
This commit is contained in:
ergo720 2021-08-31 00:32:30 +02:00 committed by GitHub
commit b405153c7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 1257 additions and 1073 deletions

View File

@ -122,6 +122,7 @@ file (GLOB CXBXR_HEADER_EMU_IMPORT
)
file (GLOB CXBXR_HEADER_EMU
"${CXBXR_ROOT_DIR}/src/common/AddressRanges.h"
"${CXBXR_ROOT_DIR}/src/common/FilePaths.hpp"
"${CXBXR_ROOT_DIR}/src/common/audio/converter.hpp"
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/glextensions.h"
"${CXBXR_ROOT_DIR}/src/common/util/gloffscreen/gloffscreen.h"
@ -176,6 +177,7 @@ file (GLOB CXBXR_HEADER_EMU
"${CXBXR_ROOT_DIR}/src/core/kernel/exports/EmuKrnlKi.h"
"${CXBXR_ROOT_DIR}/src/core/kernel/exports/EmuKrnlLogging.h"
"${CXBXR_ROOT_DIR}/src/core/kernel/init/CxbxKrnl.h"
"${CXBXR_ROOT_DIR}/src/core/kernel/init/KrnlPatches.hpp"
"${CXBXR_ROOT_DIR}/src/core/kernel/memory-manager/PhysicalMemory.h"
"${CXBXR_ROOT_DIR}/src/core/kernel/memory-manager/PoolManager.h"
"${CXBXR_ROOT_DIR}/src/core/kernel/memory-manager/VMManager.h"
@ -183,6 +185,7 @@ file (GLOB CXBXR_HEADER_EMU
"${CXBXR_ROOT_DIR}/src/core/kernel/support/EmuFile.h"
"${CXBXR_ROOT_DIR}/src/core/kernel/support/EmuFS.h"
"${CXBXR_ROOT_DIR}/src/core/kernel/support/EmuNtDll.h"
"${CXBXR_ROOT_DIR}/src/core/kernel/support/PatchRdtsc.hpp"
"${CXBXR_ROOT_DIR}/src/devices/ADM1032Device.h"
"${CXBXR_ROOT_DIR}/src/devices/EEPROMDevice.h"
"${CXBXR_ROOT_DIR}/src/devices/network/NVNetDevice.h"
@ -360,6 +363,7 @@ file (GLOB CXBXR_SOURCE_EMU
"${CXBXR_ROOT_DIR}/src/core/kernel/support/EmuFile.cpp"
"${CXBXR_ROOT_DIR}/src/core/kernel/support/EmuFS.cpp"
"${CXBXR_ROOT_DIR}/src/core/kernel/support/EmuNtDll.cpp"
"${CXBXR_ROOT_DIR}/src/core/kernel/support/PatchRdtsc.cpp"
"${CXBXR_ROOT_DIR}/src/devices/ADM1032Device.cpp"
"${CXBXR_ROOT_DIR}/src/devices/EEPROMDevice.cpp"
"${CXBXR_ROOT_DIR}/src/devices/network/NVNetDevice.cpp"

View File

@ -143,7 +143,7 @@ xbox::XBOX_EEPROM *CxbxRestoreEEPROM(char *szFilePath_EEPROM_bin)
unsigned int FileSize = len_li.u.LowPart;
if (FileSize != 256)
{
CxbxKrnlCleanup("%s : EEPROM.bin file is not 256 bytes large!\n", __func__);
CxbxrKrnlAbort("%s : EEPROM.bin file is not 256 bytes large!\n", __func__);
return nullptr;
}

162
src/common/FilePaths.hpp Normal file
View File

@ -0,0 +1,162 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * This file is part of the Cxbx-Reloaded project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * All rights reserved
// *
// ******************************************************************
#pragma once
//TODO: Possible move CxbxResolveHostToFullPath inline function someplace else if become useful elsewhere.
// Let filesystem library clean it up for us, including resolve host's symbolic link path.
// Since internal kernel do translate to full path than preserved host symoblic link path.
static inline void CxbxResolveHostToFullPath(std::filesystem::path& file_path, std::string_view finish_error_sentence) {
std::error_code error;
std::filesystem::path sanityPath = std::filesystem::canonical(file_path, error);
if (error.value() != 0) {
CxbxrKrnlAbortEx(LOG_PREFIX_INIT, "Could not resolve to %s: %s", finish_error_sentence.data(), file_path.string().c_str());
}
file_path = sanityPath;
}
// TODO: Eventually, we should remove this function to start using std::filesystem::path method for all host paths.
static inline void CxbxResolveHostToFullPath(std::string& file_path, std::string_view finish_error_sentence) {
std::filesystem::path sanityPath(file_path);
CxbxResolveHostToFullPath(sanityPath, finish_error_sentence);
file_path = sanityPath.string();
}
// NOTE: Do NOT modify g_<custom>BasePath variables after this call!
void CxbxrInitFilePaths()
{
if (g_Settings) {
g_DataFilePath = g_Settings->GetDataLocation();
}
else {
char dataLoc[MAX_PATH];
g_EmuShared->GetDataLocation(dataLoc);
g_DataFilePath = dataLoc;
}
// Make sure our data folder exists :
bool result = std::filesystem::exists(g_DataFilePath);
if (!result && !std::filesystem::create_directory(g_DataFilePath)) {
CxbxrKrnlAbort("%s : Couldn't create Cxbx-Reloaded's data folder!", __func__);
}
// Make sure the EmuDisk folder exists
g_DiskBasePath = g_DataFilePath + "\\EmuDisk";
result = std::filesystem::exists(g_DiskBasePath);
if (!result && !std::filesystem::create_directory(g_DiskBasePath)) {
CxbxrKrnlAbort("%s : Couldn't create Cxbx-Reloaded EmuDisk folder!", __func__);
}
CxbxResolveHostToFullPath(g_DiskBasePath, "Cxbx-Reloaded's EmuDisk directory");
g_DiskBasePath = std::filesystem::path(g_DiskBasePath).append("").string();
// Make sure the EmuDMu folder exists
g_MuBasePath = g_DataFilePath + "\\EmuMu";
result = std::filesystem::exists(g_MuBasePath);
if (!result && !std::filesystem::create_directory(g_MuBasePath)) {
CxbxrKrnlAbort("%s : Couldn't create Cxbx-Reloaded EmuMu folder!", __func__);
}
CxbxResolveHostToFullPath(g_MuBasePath, "Cxbx-Reloaded's EmuMu directory");
g_MuBasePath = std::filesystem::path(g_MuBasePath).append("").string();
snprintf(szFilePath_EEPROM_bin, MAX_PATH, "%s\\EEPROM.bin", g_DataFilePath.c_str());
GetModuleFileName(GetModuleHandle(nullptr), szFilePath_CxbxReloaded_Exe, MAX_PATH);
}
// Loads a keys.bin file as generated by dump-xbox
// See https://github.com/JayFoxRox/xqemu-tools/blob/master/dump-xbox.c
static void LoadXboxKeys()
{
std::string keys_path = g_DataFilePath + "\\keys.bin";
// Attempt to open Keys.bin
FILE* fp = fopen(keys_path.c_str(), "rb");
if (fp != nullptr) {
// Determine size of Keys.bin
xbox::XBOX_KEY_DATA keys[2];
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
rewind(fp);
// If the size of Keys.bin is correct (two keys), read it
if (size == xbox::XBOX_KEY_LENGTH * 2) {
fread(keys, xbox::XBOX_KEY_LENGTH, 2, fp);
memcpy(xbox::XboxEEPROMKey, &keys[0], xbox::XBOX_KEY_LENGTH);
memcpy(xbox::XboxCertificateKey, &keys[1], xbox::XBOX_KEY_LENGTH);
}
else {
EmuLog(LOG_LEVEL::WARNING, "Keys.bin has an incorrect filesize. Should be %d bytes", xbox::XBOX_KEY_LENGTH * 2);
}
fclose(fp);
return;
}
// If we didn't already exit the function, keys.bin could not be loaded
EmuLog(LOG_LEVEL::WARNING, "Failed to load Keys.bin. Cxbx-Reloaded will be unable to read Save Data from a real Xbox");
}
static HANDLE hMapDataHash = nullptr;
static bool CxbxLockFilePath()
{
std::stringstream filePathHash("Local\\");
uint64_t hashValue = XXH3_64bits(g_DataFilePath.c_str(), g_DataFilePath.length() + 1);
if (!hashValue) {
CxbxrKrnlAbort("%s : Couldn't generate Cxbx-Reloaded's data folder hash!", __func__);
}
filePathHash << std::hex << hashValue;
hMapDataHash = CreateFileMapping(
INVALID_HANDLE_VALUE, // Paging file
nullptr, // default security attributes
PAGE_READONLY, // readonly access
0, // size: high 32 bits
/*Dummy size*/4, // size: low 32 bits
filePathHash.str().c_str() // name of map object
);
if (hMapDataHash == nullptr) {
return false;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
PopupError(nullptr, "Data path directory is currently in use.\nUse a different data path directory or stop emulation from another process.");
CloseHandle(hMapDataHash);
return false;
}
return true;
}
static void CxbxUnlockFilePath()
{
// Close opened file path lockdown shared memory.
if (hMapDataHash) {
CloseHandle(hMapDataHash);
hMapDataHash = nullptr;
}
}

View File

@ -809,7 +809,7 @@ void Settings::SyncToEmulator()
g_EmuShared->SetHackSettings(&m_hacks);
// register data location setting
g_EmuShared->SetStorageLocation(GetDataLocation().c_str());
g_EmuShared->SetDataLocation(GetDataLocation().c_str());
// reset title mount path
g_EmuShared->SetTitleMountPath("");

View File

@ -96,7 +96,7 @@ void InputDeviceManager::Initialize(bool is_gui, HWND hwnd)
lck.unlock();
if (Sdl::InitStatus < 0 || XInput::InitStatus < 0 || RawInput::InitStatus < 0) {
CxbxKrnlCleanup("Failed to initialize input subsystem! Consult debug log for more information");
CxbxrKrnlAbort("Failed to initialize input subsystem! Consult debug log for more information");
}
UpdateOpt(is_gui);

View File

@ -84,7 +84,7 @@ bool EmuShared::Init(long long sessionID)
);
if(hMapObject == NULL)
return false; // CxbxKrnlCleanupEx(CXBXR_MODULE::INIT, "Could not map shared memory!");
return false; // CxbxrKrnlAbortEx(CXBXR_MODULE::INIT, "Could not map shared memory!");
if(GetLastError() == ERROR_ALREADY_EXISTS)
bRequireConstruction = false;
@ -105,7 +105,7 @@ bool EmuShared::Init(long long sessionID)
if (g_EmuShared == nullptr) {
CloseHandle(hMapObject);
return false; // CxbxKrnlCleanupEx(CXBXR_MODULE::INIT, "Could not map view of shared memory!");
return false; // CxbxrKrnlAbortEx(CXBXR_MODULE::INIT, "Could not map view of shared memory!");
}
}

View File

@ -246,10 +246,10 @@ class EmuShared : public Mutex
void SetLogPopupTestCase(const bool value) { Lock(); m_core.bLogPopupTestCase = value; Unlock(); }
// ******************************************************************
// * File storage location
// * Data location path
// ******************************************************************
void GetStorageLocation(char *path) { Lock(); strncpy(path, m_core.szStorageLocation, xbox::max_path); Unlock(); }
void SetStorageLocation(const char *path) { Lock(); strncpy(m_core.szStorageLocation, path, xbox::max_path); Unlock(); }
void GetDataLocation(char *path) { Lock(); strncpy(path, m_core.szStorageLocation, xbox::max_path); Unlock(); }
void SetDataLocation(const char *path) { Lock(); strncpy(m_core.szStorageLocation, path, xbox::max_path); Unlock(); }
// ******************************************************************
// * ClipCursor flag Accessors

View File

@ -196,7 +196,7 @@ class Win7Policy final : public AffinityPolicy
public:
bool Initialize() {
if (!GetProcessAffinityMask(g_CurrentProcessHandle, &CPUXbox, &CPUOthers))
CxbxKrnlCleanupEx(CXBXR_MODULE::INIT, "GetProcessAffinityMask failed.");
CxbxrKrnlAbortEx(CXBXR_MODULE::INIT, "GetProcessAffinityMask failed.");
// For the other threads, remove one bit from the processor mask:
CPUOthers = ((CPUXbox - 1) & CPUXbox);

View File

@ -20,14 +20,14 @@ bool ImGuiUI::Initialize()
IMGUI_CHECKVERSION();
m_imgui_context = ImGui::CreateContext();
if (!m_imgui_context) {
CxbxKrnlCleanup("Unable to create ImGui context!");
CxbxrKrnlAbort("Unable to create ImGui context!");
return false;
}
ImGuiIO& io = ImGui::GetIO();
#if 0 // TODO: Currently most voted for memory, so this block of code is disabled. And may will add an option between file vs memory.
// May be best ideal to do manual update call than ImGui's internal auto update.
g_EmuShared->GetStorageLocation(m_file_path);
g_EmuShared->GetDataLocation(m_file_path);
if (m_file_path[0] == '\0') {
return false;
}
@ -45,6 +45,11 @@ bool ImGuiUI::Initialize()
g_EmuShared->GetOverlaySettings(&m_settings);
g_EmuShared->GetFlagsLLE(&m_lle_flags);
// Internal initialize (when necessary, move into its own function.)
fps_counter = 30.0f;
// Miscs
m_audio.Initialize();
m_video.Initialize();
@ -56,7 +61,7 @@ void ImGuiUI::Shutdown()
size_t ini_size = IMGUI_INI_SIZE_MAX;
const char* temp_ini_settings = ImGui::SaveIniSettingsToMemory(&ini_size);
if (ini_size > IMGUI_INI_SIZE_MAX) {
CxbxKrnlCleanup("ImGui ini settings is too large: %d > %d (IMGUI_INI_SIZE_MAX)", ini_size, IMGUI_INI_SIZE_MAX);
CxbxrKrnlAbort("ImGui ini settings is too large: %d > %d (IMGUI_INI_SIZE_MAX)", ini_size, IMGUI_INI_SIZE_MAX);
}
g_EmuShared->SetImGuiIniSettings(temp_ini_settings);
g_EmuShared->SetOverlaySettings(&m_settings);
@ -76,6 +81,36 @@ void ImGuiUI::ToggleImGui()
g_EmuShared->SetImGuiFocusFlag(m_is_focus);
}
static clock_t g_DeltaTime = 0; // Used for benchmarking/fps count
static unsigned int g_Frames = 0;
// ******************************************************************
// * update the current milliseconds per frame
// ******************************************************************
void ImGuiUI::UpdateCurrentMSpFAndFPS() {
if (g_EmuShared) {
fps_counter = (float)(g_Frames * 0.5 + fps_counter * 0.5);
g_EmuShared->SetCurrentFPS(&fps_counter);
}
}
void ImGuiUI::UpdateFPSCounter()
{
static clock_t lastDrawFunctionCallTime = 0;
clock_t currentDrawFunctionCallTime = clock();
g_DeltaTime += currentDrawFunctionCallTime - lastDrawFunctionCallTime;
lastDrawFunctionCallTime = currentDrawFunctionCallTime;
g_Frames++;
if (g_DeltaTime >= CLOCKS_PER_SEC) {
UpdateCurrentMSpFAndFPS();
g_Frames = 0;
g_DeltaTime -= CLOCKS_PER_SEC;
}
}
void ImGuiUI::DrawMenu()
{
if (!m_is_focus) {
@ -116,9 +151,6 @@ void ImGuiUI::DrawWidgets()
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing)) {
if (m_settings.fps) {
float fps_counter;
g_EmuShared->GetCurrentFPS(&fps_counter);
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "FPS: %.2f MS / F : %.2f", fps_counter, (float)(1000.0 / fps_counter));
}

View File

@ -28,6 +28,7 @@ public:
void ToggleImGui();
bool IsImGuiFocus();
void UpdateFPSCounter();
void DrawMenu();
void DrawWidgets();
@ -48,6 +49,8 @@ protected:
callback(this, arg);
}
void UpdateCurrentMSpFAndFPS();
std::mutex m_imgui_mutex;
ImGuiContext* m_imgui_context;
char m_file_path[FILENAME_MAX+1];
@ -57,6 +60,7 @@ protected:
ImGuiVideo m_video;
overlay_settings m_settings;
unsigned int m_lle_flags;
float fps_counter;
// Make them as settings storage.
/*bool m_show_fps;
bool m_show_LLE_stats;

View File

@ -223,8 +223,6 @@ static inline void EmuVerifyResourceIsRegistered(xbox::X_D3DRes
static void UpdateCurrentMSpFAndFPS(); // Used for benchmarking/fps count
static void CxbxImpl_SetRenderTarget(xbox::X_D3DSurface *pRenderTarget, xbox::X_D3DSurface *pNewZStencil);
extern void UpdateFPSCounter();
#define CXBX_D3DCOMMON_IDENTIFYING_MASK (X_D3DCOMMON_TYPE_MASK | X_D3DCOMMON_D3DCREATED)
@ -864,7 +862,7 @@ inline bool IsResourceTypeGPUReadable(const DWORD ResourceType)
// assert(false); // Fixup's are not allowed to be registered
break;
default:
CxbxKrnlCleanup("Unhandled resource type");
CxbxrKrnlAbort("Unhandled resource type");
}
return false;
@ -1697,7 +1695,7 @@ void EmuD3DInit()
{
// xbox Direct3DCreate8 returns "1" always, so we need our own ptr
if(FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &g_pDirect3D)))
CxbxKrnlCleanup("Could not initialize Direct3D8!");
CxbxrKrnlAbort("Could not initialize Direct3D8!");
g_pDirect3D->GetDeviceCaps(g_EmuCDPD.Adapter, g_EmuCDPD.DeviceType, &g_D3DCaps);
@ -1801,14 +1799,14 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpParam)
{
if(bRet == -1)
{
CxbxKrnlCleanup("GetMessage failed!");
CxbxrKrnlAbort("GetMessage failed!");
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CxbxKrnlCleanup(nullptr);
CxbxrKrnlAbort(nullptr);
}
return 0;
@ -2050,7 +2048,7 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
case SIZE_MINIMIZED:
{
if(g_XBVideo.bFullScreen)
CxbxKrnlCleanup(nullptr);
CxbxrKrnlAbort(nullptr);
if(!g_bEmuSuspended)
{
@ -2479,7 +2477,7 @@ static void CreateDefaultD3D9Device
DEBUG_D3DRESULT(hr, "IDirect3D::CreateDeviceEx");
if(FAILED(hr))
CxbxKrnlCleanup("IDirect3D::CreateDeviceEx failed");
CxbxrKrnlAbort("IDirect3D::CreateDeviceEx failed");
// Which texture formats does this device support?
DetermineSupportedD3DFormats();
@ -2796,7 +2794,7 @@ ConvertedIndexBuffer& CxbxUpdateActiveIndexBuffer
if (CacheEntry.pHostIndexBuffer == nullptr) {
CacheEntry.pHostIndexBuffer = CxbxCreateIndexBuffer(RequiredIndexCount);
if (!CacheEntry.pHostIndexBuffer)
CxbxKrnlCleanup("CxbxUpdateActiveIndexBuffer: IndexBuffer Create Failed!");
CxbxrKrnlAbort("CxbxUpdateActiveIndexBuffer: IndexBuffer Create Failed!");
}
// TODO : Speeds this up, perhaps by hashing less often, and/or by
@ -2815,7 +2813,7 @@ ConvertedIndexBuffer& CxbxUpdateActiveIndexBuffer
HRESULT hRet = CacheEntry.pHostIndexBuffer->Lock(0, /*entire SizeToLock=*/0, (D3DLockData **)&pHostIndexBufferData, D3DLOCK_DISCARD);
DEBUG_D3DRESULT(hRet, "CacheEntry.pHostIndexBuffer->Lock");
if (pHostIndexBufferData == nullptr) {
CxbxKrnlCleanup("CxbxUpdateActiveIndexBuffer: Could not lock index buffer!");
CxbxrKrnlAbort("CxbxUpdateActiveIndexBuffer: Could not lock index buffer!");
}
// Determine highest and lowest index in use :
@ -2839,7 +2837,7 @@ ConvertedIndexBuffer& CxbxUpdateActiveIndexBuffer
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetIndices");
if (FAILED(hRet))
CxbxKrnlCleanup("CxbxUpdateActiveIndexBuffer: SetIndices Failed!");
CxbxrKrnlAbort("CxbxUpdateActiveIndexBuffer: SetIndices Failed!");
return CacheEntry;
}
@ -2852,13 +2850,13 @@ void UpdateHostBackBufferDesc()
0, D3DBACKBUFFER_TYPE_MONO, &pCurrentHostBackBuffer);
if (hRet != D3D_OK) {
CxbxKrnlCleanup("Unable to get host backbuffer surface");
CxbxrKrnlAbort("Unable to get host backbuffer surface");
}
hRet = pCurrentHostBackBuffer->GetDesc(&g_HostBackBufferDesc);
if (hRet != D3D_OK) {
pCurrentHostBackBuffer->Release();
CxbxKrnlCleanup("Unable to determine host backbuffer dimensions");
CxbxrKrnlAbort("Unable to determine host backbuffer dimensions");
}
pCurrentHostBackBuffer->Release();
@ -3026,11 +3024,11 @@ void Direct3D_CreateDevice_Start
CxbxVertexShaderSetFlags();
if (!XboxRenderStates.Init()) {
CxbxKrnlCleanup("Failed to init XboxRenderStates");
CxbxrKrnlAbort("Failed to init XboxRenderStates");
}
if (!XboxTextureStates.Init(&XboxRenderStates)) {
CxbxKrnlCleanup("Failed to init XboxTextureStates");
CxbxrKrnlAbort("Failed to init XboxTextureStates");
}
SetXboxMultiSampleType(pPresentationParameters->MultiSampleType);
@ -3084,7 +3082,7 @@ void Direct3D_CreateDevice_End
// At this point, g_pXbox_BackBufferSurface should now point to a valid render target
// if it still doesn't, we cannot continue without crashing at draw time
if (g_pXbox_BackBufferSurface == xbox::zeroptr) {
CxbxKrnlCleanup("Unable to determine default Xbox backbuffer");
CxbxrKrnlAbort("Unable to determine default Xbox backbuffer");
}
// Set the backbuffer as the initial rendertarget
@ -4047,7 +4045,7 @@ xbox::X_D3DSurface* WINAPI xbox::EMUPATCH(D3DDevice_GetBackBuffer2)
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->GetBackBuffer");
if (FAILED(hRet))
CxbxKrnlCleanup("Unable to retrieve back buffer");
CxbxrKrnlAbort("Unable to retrieve back buffer");
SetHostSurface(pXboxBackBuffer, pCurrentHostBackBuffer); // No iTextureStage!
@ -4070,7 +4068,7 @@ xbox::X_D3DSurface* WINAPI xbox::EMUPATCH(D3DDevice_GetBackBuffer2)
// Now pXboxBackbuffer points to the requested Xbox backbuffer
if (pXboxBackBuffer == nullptr) {
CxbxKrnlCleanup("D3DDevice_GetBackBuffer2: Could not get Xbox backbuffer");
CxbxrKrnlAbort("D3DDevice_GetBackBuffer2: Could not get Xbox backbuffer");
}
@ -5483,7 +5481,7 @@ xbox::dword_xt WINAPI xbox::EMUPATCH(D3DDevice_Swap)
frameStartTime = std::chrono::steady_clock::now();
UpdateFPSCounter();
g_renderbase->UpdateFPSCounter();
if (Flags == CXBX_SWAP_PRESENT_FORWARD) // Only do this when forwarded from Present
{
@ -5746,7 +5744,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
PCFormat = D3DFMT_A8R8G8B8;
} else {
// Otherwise, use a best matching format
/*CxbxKrnlCleanup*/EmuLog(LOG_LEVEL::WARNING, "Encountered a completely incompatible %s format!", ResourceTypeName);
/*CxbxrKrnlAbort*/EmuLog(LOG_LEVEL::WARNING, "Encountered a completely incompatible %s format!", ResourceTypeName);
PCFormat = EmuXB2PC_D3DFormat(X_Format);
}
}
@ -5874,7 +5872,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
// If the fallback failed, show an error and exit execution.
if (hRet != D3D_OK) {
// We cannot safely continue in this state.
CxbxKrnlCleanup("CreateImageSurface Failed!\n\nError: %s\nDesc: %s",
CxbxrKrnlAbort("CreateImageSurface Failed!\n\nError: %s\nDesc: %s",
DXGetErrorString(hRet), DXGetErrorDescription(hRet));
}
@ -5942,7 +5940,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
if (hRet != D3D_OK) {
CxbxKrnlCleanup("CreateTexture Failed!\n\n"
CxbxrKrnlAbort("CreateTexture Failed!\n\n"
"Error: 0x%X\nFormat: %d\nDimensions: %dx%d", hRet, PCFormat, hostWidth, hostHeight);
}
@ -5968,7 +5966,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
}
if (hRet != D3D_OK) {
CxbxKrnlCleanup("CreateVolumeTexture Failed!\n\nError: %s\nDesc: %s",
CxbxrKrnlAbort("CreateVolumeTexture Failed!\n\nError: %s\nDesc: %s",
DXGetErrorString(hRet), DXGetErrorDescription(hRet));
}
@ -5997,7 +5995,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
}
if (hRet != D3D_OK) {
CxbxKrnlCleanup("CreateCubeTexture Failed!\n\nError: \nDesc: "/*,
CxbxrKrnlAbort("CreateCubeTexture Failed!\n\nError: \nDesc: "/*,
DXGetErrorString(hRet), DXGetErrorDescription(hRet)*/);
}
@ -6127,7 +6125,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
pDst, dwDstRowPitch, dwDstSlicePitch,
pxMipDepth,//used pxMipDepth here because in 3D mip map the 3rd dimension also shrinked to 1/2 at each mip level.
iTextureStage)) {
CxbxKrnlCleanup("Unhandled conversion!");
CxbxrKrnlAbort("Unhandled conversion!");
}
}
}
@ -6555,7 +6553,7 @@ void UpdateFixedFunctionVertexShaderState()
auto hRet = g_pD3DDevice->SetVertexShaderConstantF(0, (float*)&ffShaderState, fixedFunctionStateSize);
if (FAILED(hRet)) {
CxbxKrnlCleanup("Failed to write fixed-function HLSL state");
CxbxrKrnlAbort("Failed to write fixed-function HLSL state");
}
}
@ -7165,14 +7163,14 @@ void CxbxAssureQuadListD3DIndexBuffer(UINT NrOfQuadIndices)
// Create a new native index buffer of the above determined size :
g_pQuadToTriangleHostIndexBuffer = CxbxCreateIndexBuffer(NrOfTriangleIndices);
if (g_pQuadToTriangleHostIndexBuffer == nullptr)
CxbxKrnlCleanup("CxbxAssureQuadListD3DIndexBuffer : IndexBuffer Create Failed!");
CxbxrKrnlAbort("CxbxAssureQuadListD3DIndexBuffer : IndexBuffer Create Failed!");
// Put quadlist-to-triangle-list index mappings into this buffer :
INDEX16* pHostIndexBufferData = nullptr;
hRet = g_pQuadToTriangleHostIndexBuffer->Lock(0, /*entire SizeToLock=*/0, (D3DLockData **)&pHostIndexBufferData, D3DLOCK_DISCARD);
DEBUG_D3DRESULT(hRet, "g_pQuadToTriangleHostIndexBuffer->Lock");
if (pHostIndexBufferData == nullptr)
CxbxKrnlCleanup("CxbxAssureQuadListD3DIndexBuffer : Could not lock index buffer!");
CxbxrKrnlAbort("CxbxAssureQuadListD3DIndexBuffer : Could not lock index buffer!");
memcpy(pHostIndexBufferData, CxbxAssureQuadListIndexData(NrOfQuadIndices), NrOfTriangleIndices * sizeof(INDEX16));
@ -7184,7 +7182,7 @@ void CxbxAssureQuadListD3DIndexBuffer(UINT NrOfQuadIndices)
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetIndices");
if (FAILED(hRet))
CxbxKrnlCleanup("CxbxAssureQuadListD3DIndexBuffer : SetIndices Failed!"); // +DxbxD3DErrorString(hRet));
CxbxrKrnlAbort("CxbxAssureQuadListD3DIndexBuffer : SetIndices Failed!"); // +DxbxD3DErrorString(hRet));
}
// TODO : Move to own file
@ -7198,7 +7196,7 @@ void CxbxDrawIndexedClosingLine(INDEX16 LowIndex, INDEX16 HighIndex)
if (g_pClosingLineLoopHostIndexBuffer == nullptr) {
g_pClosingLineLoopHostIndexBuffer = CxbxCreateIndexBuffer(VERTICES_PER_LINE);
if (g_pClosingLineLoopHostIndexBuffer == nullptr)
CxbxKrnlCleanup("Unable to create g_pClosingLineLoopHostIndexBuffer for D3DPT_LINELOOP emulation");
CxbxrKrnlAbort("Unable to create g_pClosingLineLoopHostIndexBuffer for D3DPT_LINELOOP emulation");
}
INDEX16 *pCxbxClosingLineLoopIndexBufferData = nullptr;

View File

@ -361,9 +361,9 @@ DWORD NormalizeValue(DWORD xboxState, DWORD value) {
uint32_t XboxTextureStateConverter::Get(int textureStage, DWORD xboxState) {
if (textureStage < 0 || textureStage > 3)
CxbxKrnlCleanup("Requested texture stage was out of range: %d", textureStage);
CxbxrKrnlAbort("Requested texture stage was out of range: %d", textureStage);
if (xboxState < xbox::X_D3DTSS_FIRST || xboxState > xbox::X_D3DTSS_LAST)
CxbxKrnlCleanup("Requested texture state was out of range: %d", xboxState);
CxbxrKrnlAbort("Requested texture state was out of range: %d", xboxState);
// Read the value of the current stage/state from the Xbox data structure
DWORD rawValue = D3D__TextureState[(textureStage * xbox::X_D3DTS_STAGESIZE) + XboxTextureStateOffsets[xboxState]];

View File

@ -1047,7 +1047,7 @@ D3DFORMAT EmuXB2PC_D3DFormat(xbox::X_D3DFORMAT Format)
case ((xbox::X_D3DFORMAT)0xffffffff):
return D3DFMT_UNKNOWN; // TODO -oCXBX: Not sure if this counts as swizzled or not...
default:
CxbxKrnlCleanup("EmuXB2PC_D3DFormat: Unknown Format (0x%.08X)", Format);
CxbxrKrnlAbort("EmuXB2PC_D3DFormat: Unknown Format (0x%.08X)", Format);
}
return D3DFMT_UNKNOWN;
@ -1129,7 +1129,7 @@ xbox::X_D3DFORMAT EmuPC2XB_D3DFormat(D3DFORMAT Format, bool bPreferLinear)
result = xbox::X_D3DFMT_VERTEXDATA;
break;
default:
CxbxKrnlCleanup("EmuPC2XB_D3DFormat: Unknown Format (%d)", Format);
CxbxrKrnlAbort("EmuPC2XB_D3DFormat: Unknown Format (%d)", Format);
}
return result;

View File

@ -90,7 +90,7 @@ else if((uint32)State < 20)
else if((uint32)State > 255)
State = (D3DTRANSFORMSTATETYPE)(State - 250);
else
CxbxKrnlCleanupEx(LOG_PREFIX_D3DCVT, "Unknown Transform State Type (%d)", State);
CxbxrKrnlAbortEx(LOG_PREFIX_D3DCVT, "Unknown Transform State Type (%d)", State);
//*/
// convert from xbox to pc texture transform state types
@ -115,7 +115,7 @@ inline D3DTRANSFORMSTATETYPE EmuXB2PC_D3DTS(xbox::X_D3DTRANSFORMSTATETYPE State)
return D3DTS_WORLDMATRIX(State - 256);
}
CxbxKrnlCleanupEx(LOG_PREFIX_D3DCVT, "Unknown Transform State Type (%d)", State);
CxbxrKrnlAbortEx(LOG_PREFIX_D3DCVT, "Unknown Transform State Type (%d)", State);
return (D3DTRANSFORMSTATETYPE)0;
}

View File

@ -43,7 +43,7 @@
#include "core\hle\D3D8\Direct3D9\PixelShader.h" // EmuCompilePixelShader
#include "core\hle\D3D8\XbD3D8Logging.h" // For D3DErrorString()
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup()
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort()
#include "util\hasher.h"
#include "core\hle\D3D8\Direct3D9\FixedFunctionPixelShader.hlsli"
@ -930,7 +930,7 @@ IDirect3DPixelShader9* GetFixedFunctionShader()
IDirect3DPixelShader9* pShader = nullptr;
auto hRet = g_pD3DDevice->CreatePixelShader((DWORD*)pShaderBlob->GetBufferPointer(), &pShader);
if (hRet != S_OK)
CxbxKrnlCleanup("Failed to compile fixed function pixel shader");
CxbxrKrnlAbort("Failed to compile fixed function pixel shader");
pShaderBlob->Release();
// Insert the shader into the cache

View File

@ -84,7 +84,7 @@ void CxbxPatchedStream::Activate(CxbxDrawContext *pDrawContext, UINT HostStreamN
uiCachedHostVertexStride);
//DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetStreamSource");
if (FAILED(hRet)) {
CxbxKrnlCleanup("Failed to set the type patched buffer as the new stream source!\n");
CxbxrKrnlAbort("Failed to set the type patched buffer as the new stream source!\n");
// TODO : test-case : XDK Cartoon hits the above case when the vertex cache size is 0.
}
}
@ -244,7 +244,7 @@ void CxbxVertexBufferConverter::ConvertStream
if (pDrawContext->pXboxVertexStreamZeroData != xbox::zeroptr) {
// There should only be one stream (stream zero) in this case
if (XboxStreamNumber != 0) {
CxbxKrnlCleanup("Trying to patch a Draw..UP with more than stream zero!");
CxbxrKrnlAbort("Trying to patch a Draw..UP with more than stream zero!");
}
pXboxVertexData = (uint8_t *)pDrawContext->pXboxVertexStreamZeroData;
@ -350,7 +350,7 @@ void CxbxVertexBufferConverter::ConvertStream
pHostVertexData = (uint8_t*)malloc(dwHostVertexDataSize);
if (pHostVertexData == nullptr) {
CxbxKrnlCleanup("Couldn't allocate the new stream zero buffer");
CxbxrKrnlAbort("Couldn't allocate the new stream zero buffer");
}
} else {
HRESULT hRet = g_pD3DDevice->CreateVertexBuffer(
@ -363,14 +363,14 @@ void CxbxVertexBufferConverter::ConvertStream
);
if (FAILED(hRet)) {
CxbxKrnlCleanup("Failed to create vertex buffer");
CxbxrKrnlAbort("Failed to create vertex buffer");
}
}
// If we need to lock a host vertex buffer, do so now
if (pHostVertexData == nullptr && pNewHostVertexBuffer != nullptr) {
if (FAILED(pNewHostVertexBuffer->Lock(0, 0, (D3DLockData **)&pHostVertexData, D3DLOCK_DISCARD))) {
CxbxKrnlCleanup("Couldn't lock vertex buffer");
CxbxrKrnlAbort("Couldn't lock vertex buffer");
}
}
@ -609,7 +609,7 @@ void CxbxVertexBufferConverter::ConvertStream
void CxbxVertexBufferConverter::Apply(CxbxDrawContext *pDrawContext)
{
if ((pDrawContext->XboxPrimitiveType < xbox::X_D3DPT_POINTLIST) || (pDrawContext->XboxPrimitiveType > xbox::X_D3DPT_POLYGON))
CxbxKrnlCleanup("Unknown primitive type: 0x%.02X\n", pDrawContext->XboxPrimitiveType);
CxbxrKrnlAbort("Unknown primitive type: 0x%.02X\n", pDrawContext->XboxPrimitiveType);
CxbxVertexDeclaration* pCxbxVertexDeclaration = CxbxGetVertexDeclaration();

View File

@ -574,7 +574,7 @@ namespace XboxVertexShaderDecoder
}
if (pShader->Instructions.size() >= VSH_MAX_INTERMEDIATE_COUNT) {
CxbxKrnlCleanup("Shader exceeds conversion buffer!");
CxbxrKrnlAbort("Shader exceeds conversion buffer!");
}
VSH_INTERMEDIATE_FORMAT intermediate;
@ -1161,14 +1161,14 @@ void CxbxUpdateHostVertexShader()
EmuCompileFixedFunction(&pBlob);
if (pBlob) {
hRet = g_pD3DDevice->CreateVertexShader((DWORD*)pBlob->GetBufferPointer(), &ffHlsl);
if (FAILED(hRet)) CxbxKrnlCleanup("Failed to create fixed-function shader");
if (FAILED(hRet)) CxbxrKrnlAbort("Failed to create fixed-function shader");
}
}
fixedFunctionShader = ffHlsl;
}
hRet = g_pD3DDevice->SetVertexShader(fixedFunctionShader);
if (FAILED(hRet)) CxbxKrnlCleanup("Failed to set fixed-function shader");
if (FAILED(hRet)) CxbxrKrnlAbort("Failed to set fixed-function shader");
}
else if (g_Xbox_VertexShaderMode == VertexShaderMode::Passthrough && g_bUsePassthroughHLSL) {
if (passthroughshader == nullptr) {

View File

@ -174,13 +174,13 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(DirectSoundCreate)
}
if (dsErrorMsg != nullptr) {
CxbxKrnlCleanup(dsErrorMsg, hRet);
CxbxrKrnlAbort(dsErrorMsg, hRet);
}
hRet = g_pDSound8->SetCooperativeLevel(GET_FRONT_WINDOW_HANDLE, DSSCL_PRIORITY);
if (hRet != DS_OK) {
CxbxKrnlCleanup("g_pDSound8->SetCooperativeLevel Failed!");
CxbxrKrnlAbort("g_pDSound8->SetCooperativeLevel Failed!");
}
// clear sound buffer cache
@ -208,7 +208,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(DirectSoundCreate)
hRet = g_pDSound8->CreateSoundBuffer(&bufferDesc, &g_pDSoundPrimaryBuffer, nullptr);
if (hRet != DS_OK) {
CxbxKrnlCleanup("Creating primary buffer for DirectSound Failed!");
CxbxrKrnlAbort("Creating primary buffer for DirectSound Failed!");
}
/* Quote from MDSN "For the primary buffer, you must use the
@ -221,7 +221,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(DirectSoundCreate)
hRet = g_pDSoundPrimaryBuffer->QueryInterface(IID_IDirectSound3DListener8, (LPVOID*)&g_pDSoundPrimary3DListener8);
if (hRet != DS_OK) {
CxbxKrnlCleanup("Creating primary 3D Listener for DirectSound Failed!");
CxbxrKrnlAbort("Creating primary 3D Listener for DirectSound Failed!");
}
initialized = true;

View File

@ -173,7 +173,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(DirectSoundCreateBuffer)
hRet = xbox::EMUPATCH(DirectSoundCreate)(nullptr, &g_pDSound8, nullptr);
if (hRet != DS_OK) {
CxbxKrnlCleanup("Unable to initialize DirectSound!");
CxbxrKrnlAbort("Unable to initialize DirectSound!");
}
}
@ -238,7 +238,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(DirectSoundCreateBuffer)
EmuLog(LOG_LEVEL::WARNING, output.str().c_str());
output.str("");
output << static_cast<DS_RESULT>(hRet);
CxbxKrnlCleanup("DSB: DSoundBufferCreate error: %s", output.str().c_str());
CxbxrKrnlAbort("DSB: DSoundBufferCreate error: %s", output.str().c_str());
}
else {
if (pdsbd->dwFlags & DSBCAPS_CTRL3D) {
@ -460,7 +460,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(IDirectSoundBuffer_Lock)
}
if (hRet != DS_OK) {
CxbxKrnlCleanup("IDirectSoundBuffer_Lock Failed!");
CxbxrKrnlAbort("IDirectSoundBuffer_Lock Failed!");
}
// Host lock position
@ -632,7 +632,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(IDirectSoundBuffer_Play)
pThis->X_lock.dwLockBytes2);
if (dwFlags & ~(X_DSBPLAY_LOOPING | X_DSBPLAY_FROMSTART | X_DSBPLAY_SYNCHPLAYBACK)) {
CxbxKrnlCleanup("Unsupported Playing Flags");
CxbxrKrnlAbort("Unsupported Playing Flags");
}
pThis->EmuPlayFlags = dwFlags;

View File

@ -274,7 +274,7 @@ static inline void GeneratePCMFormat(
}
if (DSBufferDesc.lpwfxFormat == nullptr) {
CxbxKrnlCleanup("Unable to allocate DSBufferDesc.Xb_lpwfxFormat");
CxbxrKrnlAbort("Unable to allocate DSBufferDesc.Xb_lpwfxFormat");
}
if (Xb_lpwfxFormat != xbox::zeroptr) {
@ -358,7 +358,7 @@ static inline void DSoundGenericUnlock(
HRESULT hRet = pDSBuffer->Unlock(Host_lock.pLockPtr1, Host_lock.dwLockBytes1, Host_lock.pLockPtr2, Host_lock.dwLockBytes2);
if (hRet != DS_OK) {
CxbxKrnlCleanup("DirectSoundBuffer Unlock Failed!");
CxbxrKrnlAbort("DirectSoundBuffer Unlock Failed!");
}
Host_lock.pLockPtr1 = nullptr;
@ -485,7 +485,7 @@ static inline void DSoundBufferRelease(
if (pDS3DBuffer != nullptr) {
refCount = pDS3DBuffer->Release();
if (refCount > 0) {
CxbxKrnlCleanup("Nope, wasn't fully cleaned up.");
CxbxrKrnlAbort("Nope, wasn't fully cleaned up.");
}
}
@ -554,7 +554,7 @@ static inline void DSoundBufferResizeUpdate(
hRet = pThis->EmuDirectSoundBuffer8->Lock(0, 0, &pThis->Host_lock.pLockPtr1, &pThis->Host_lock.dwLockBytes1,
nullptr, nullptr, DSBLOCK_ENTIREBUFFER);
if (hRet != DS_OK) {
CxbxKrnlCleanup("Unable to lock region buffer!");
CxbxrKrnlAbort("Unable to lock region buffer!");
}
DSoundGenericUnlock(pThis->EmuFlags,
pThis->EmuDirectSoundBuffer8,
@ -630,7 +630,7 @@ static inline void DSoundBufferRegenWithNewFormat(
HRESULT hRet = pDSBuffer->GetStatus(&dwStatus);
if (hRet != DS_OK) {
CxbxKrnlCleanup("Unable to retrieve current status for replace DS buffer!");
CxbxrKrnlAbort("Unable to retrieve current status for replace DS buffer!");
}
pDSBuffer->Stop();
@ -638,7 +638,7 @@ static inline void DSoundBufferRegenWithNewFormat(
hRet = pDSBuffer->GetCurrentPosition(&dwPlayCursor, nullptr);
if (hRet != DS_OK) {
CxbxKrnlCleanup("Unable to retrieve current position for replace DS buffer!");
CxbxrKrnlAbort("Unable to retrieve current position for replace DS buffer!");
}
// TODO: Untested if transfer buffer to new audio buffer is necessary.
@ -922,7 +922,7 @@ static inline HRESULT HybridDirectSoundBuffer_Play(
{
if (dwFlags & ~(X_DSBPLAY_LOOPING | X_DSBPLAY_FROMSTART | X_DSBPLAY_SYNCHPLAYBACK)) {
CxbxKrnlCleanup("Unsupported Playing Flags");
CxbxrKrnlAbort("Unsupported Playing Flags");
}
// rewind buffer
if ((dwFlags & X_DSBPLAY_FROMSTART)) {

View File

@ -222,7 +222,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(DirectSoundCreateStream)
hRet = xbox::EMUPATCH(DirectSoundCreate)(nullptr, &g_pDSound8, nullptr);
if (hRet != DS_OK) {
CxbxKrnlCleanup("Unable to initialize DirectSound!");
CxbxrKrnlAbort("Unable to initialize DirectSound!");
}
}
@ -299,7 +299,7 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(DirectSoundCreateStream)
EmuLog(LOG_LEVEL::WARNING, output.str().c_str());
output.str("");
output << static_cast<DS_RESULT>(hRet);
CxbxKrnlCleanup("DSS: DSoundBufferCreate error: %s", output.str().c_str());
CxbxrKrnlAbort("DSS: DSoundBufferCreate error: %s", output.str().c_str());
}
else {
if (DSBufferDesc.dwFlags & DSBCAPS_CTRL3D) {

View File

@ -191,7 +191,7 @@ void CDECL EmuOutputMessage(xb_output_message mFlag,
break;
}
case XB_OUTPUT_MESSAGE_ERROR: {
CxbxKrnlCleanup("%s", message);
CxbxrKrnlAbort("%s", message);
break;
}
case XB_OUTPUT_MESSAGE_DEBUG:
@ -381,9 +381,9 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader)
<< std::endl;
// Make sure the Symbol Cache directory exists
std::string cachePath = std::string(szFolder_CxbxReloadedData) + "\\SymbolCache\\";
std::string cachePath = g_DataFilePath + "\\SymbolCache\\";
if (!std::filesystem::exists(cachePath) && !std::filesystem::create_directory(cachePath)) {
CxbxKrnlCleanup("Couldn't create Cxbx-Reloaded SymbolCache folder!");
CxbxrKrnlAbort("Couldn't create Cxbx-Reloaded SymbolCache folder!");
}
// Hash the loaded XBE's header, use it as a filename

View File

@ -370,7 +370,7 @@ void SetupXboxDeviceTypes()
// Sanity check: Where all these device offsets within Xbox memory
if ((deviceTableStartOffset >= g_SystemMaxMemory) || (deviceTableEndOffset >= g_SystemMaxMemory)) {
CxbxKrnlCleanup("DeviceTable Location is outside of Xbox Memory range");
CxbxrKrnlAbort("DeviceTable Location is outside of Xbox Memory range");
}
// Iterate through the table until we find gamepad
@ -903,7 +903,7 @@ xbox::void_xt WINAPI xbox::EMUPATCH(XRegisterThreadNotifyRoutine)
{
// I honestly don't expect this to happen, but if it does...
if(g_iThreadNotificationCount >= 16)
CxbxKrnlCleanup("Too many thread notification routines installed\n");
CxbxrKrnlAbort("Too many thread notification routines installed\n");
// Find an empty spot in the thread notification array
for(int i = 0; i < 16; i++)
@ -1141,7 +1141,7 @@ xbox::dword_xt WINAPI xbox::EMUPATCH(XLaunchNewImageA)
// Other options include LDT_NONE, LDT_FROM_DEBUGGER_CMDLINE and LDT_FROM_UPDATE
}
else
CxbxKrnlCleanup("The xbe rebooted to Dashboard and xboxdash.xbe could not be found");
CxbxrKrnlAbort("The xbe rebooted to Dashboard and xboxdash.xbe could not be found");
}
strncpy(&(xbox::LaunchDataPage->Header.szLaunchPath[0]), lpTitlePath, 520);

View File

@ -31,7 +31,7 @@
#include "core\kernel\support\Emu.h"
#include "common\Logging.h"
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup()
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort()
#include "core\hle\XAPI\Xapi.h" // For EMUPATCH
#include "core\hle\D3D8\XbD3D8Logging.h" // for log rendering of X_D3DFORMAT, etc.
#include "core\hle\XGRAPHIC\XGraphic.h"
@ -84,7 +84,7 @@ xbox::void_xt WINAPI xbox::EMUPATCH(XGSwizzleRect)
else
{
if(pPoint != NULL && (pPoint->x != 0 || pPoint->y != 0))
CxbxKrnlCleanup("Temporarily unsupported swizzle (very easy fix)");
CxbxrKrnlAbort("Temporarily unsupported swizzle (very easy fix)");
DWORD dwMaxY = Height;
DWORD dwChunkSize = Width;
@ -150,7 +150,7 @@ xbox::void_xt WINAPI xbox::EMUPATCH(XGSwizzleBox)
else
{
if(pPoint != NULL && (pPoint->u != 0 || pPoint->v != 0 || pPoint->w != 0))
CxbxKrnlCleanup("Temporarily unsupported swizzle (very easy fix)");
CxbxrKrnlAbort("Temporarily unsupported swizzle (very easy fix)");
DWORD dwMaxY = Height;
DWORD dwMaxZ = Depth;
@ -232,10 +232,10 @@ xbox::void_xt WINAPI xbox::EMUPATCH(XGSetTextureHeader)
LOG_FUNC_END;
/*if( Data != 0 )
CxbxKrnlCleanup("Data != 0 (XGSetTextureHeader)" );
CxbxrKrnlAbort("Data != 0 (XGSetTextureHeader)" );
if( Pitch != 0 )
CxbxKrnlCleanup("Pitch != 0 (XGSetTextureHeader)" );*/
CxbxrKrnlAbort("Pitch != 0 (XGSetTextureHeader)" );*/
pTexture->Common = X_D3DCOMMON_TYPE_TEXTURE + 1; // Set refcount to 1
pTexture->Data = Data;

View File

@ -148,7 +148,7 @@ extern void ExecuteDpcQueue();
void KiUnexpectedInterrupt()
{
xbox::KeBugCheck(TRAP_CAUSE_UNKNOWN); // see
CxbxKrnlCleanup("Unexpected Software Interrupt!");
CxbxrKrnlAbort("Unexpected Software Interrupt!");
}
void CallSoftwareInterrupt(const xbox::KIRQL SoftwareIrql)

View File

@ -41,7 +41,7 @@ namespace NtDll
#include "core\kernel\support\EmuNtDll.h" // For NtDelayExecution(), etc.
};
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort
#include "core\kernel\support\Emu.h" // For EmuLog(LOG_LEVEL::WARNING, )
#include "EmuKrnl.h" // For InsertHeadList, InsertTailList, RemoveHeadList

View File

@ -33,7 +33,7 @@
#include "Logging.h" // For LOG_FUNC()
#include "EmuKrnl.h" // For InitializeListHead(), etc.
#include "EmuKrnlLogging.h"
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup, and CxbxExec
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort, and CxbxExec
#include "core\kernel\support\Emu.h" // For EmuLog(LOG_LEVEL::WARNING, )
#include "EmuKrnl.h"
#include "devices\x86\EmuX86.h" // HalReadWritePciSpace needs this
@ -489,7 +489,7 @@ XBSYSAPI EXPORTNUM(49) xbox::void_xt DECLSPEC_NORETURN NTAPI xbox::HalReturnToFi
switch (Routine) {
case ReturnFirmwareHalt:
CxbxKrnlCleanup("Emulated Xbox is halted");
CxbxrKrnlAbort("Emulated Xbox is halted");
break;
case ReturnFirmwareReboot:

View File

@ -32,7 +32,7 @@
#include <core\kernel\exports\xboxkrnl.h> // For IoCompletionObjectType, etc.
#include "Logging.h" // For LOG_FUNC()
#include "EmuKrnlLogging.h"
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort
#include "core\kernel\support\Emu.h" // For EmuLog(LOG_LEVEL::WARNING, )
#include "core\kernel\support\EmuFile.h" // For CxbxCreateSymbolicLink(), etc.
#include "CxbxDebugger.h"

View File

@ -75,7 +75,7 @@ namespace NtDll
#include "core\kernel\support\EmuNtDll.h" // For NtDelayExecution(), etc.
};
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort
#include "core\kernel\support\Emu.h" // For EmuLog(LOG_LEVEL::WARNING, )
#include "EmuKrnl.h" // For InitializeListHead(), etc.
#include "EmuKrnlKi.h" // For KiRemoveTreeTimer(), KiInsertTreeTimer()
@ -465,7 +465,7 @@ XBSYSAPI EXPORTNUM(96) xbox::ntstatus_xt NTAPI xbox::KeBugCheckEx
int result = MessageBoxA(g_hEmuWindow, buffer, "KeBugCheck", MB_YESNO | MB_ICONWARNING);
if (result == IDNO) {
CxbxKrnlCleanup(NULL);
CxbxrKrnlAbort(NULL);
}
KeBugCheckIgnored = true;

View File

@ -34,7 +34,7 @@
#include "Logging.h" // For LOG_FUNC()
#include "EmuKrnl.h" // For DefaultLaunchDataPage
#include "EmuKrnlLogging.h"
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort
#include "core\kernel\support\Emu.h" // For EmuLog(LOG_LEVEL::WARNING, )
#include "core\kernel\memory-manager\VMManager.h"
#include "EmuShared.h"

View File

@ -39,7 +39,7 @@ namespace NtDll
#include "core\kernel\support\EmuNtDll.h"
};
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort
#include "core\kernel\exports\EmuKrnlKe.h"
#include "core\kernel\support\Emu.h" // For EmuLog(LOG_LEVEL::WARNING, )
#include "core\kernel\support\EmuFile.h" // For EmuNtSymbolicLinkObject, NtStatusToString(), etc.
@ -1099,7 +1099,7 @@ XBSYSAPI EXPORTNUM(207) xbox::ntstatus_xt NTAPI xbox::NtQueryDirectoryFile
NTSTATUS ret;
if (FileInformationClass != FileDirectoryInformation) // Due to unicode->string conversion
CxbxKrnlCleanup("Unsupported FileInformationClass");
CxbxrKrnlAbort("Unsupported FileInformationClass");
NtDll::UNICODE_STRING NtFileMask;

View File

@ -39,7 +39,7 @@
#include <core\kernel\exports\xboxkrnl.h> // For ObDirectoryObjectType, etc.
#include "Logging.h" // For LOG_FUNC()
#include "EmuKrnlLogging.h"
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort
#include "EmuKrnl.h" // For OBJECT_TO_OBJECT_HEADER()
#include "core\kernel\support\EmuFile.h" // For EmuNtSymbolicLinkObject, NtStatusToString(), etc.
#include <cassert>

View File

@ -318,7 +318,7 @@ XBSYSAPI EXPORTNUM(257) xbox::ntstatus_xt NTAPI xbox::PsSetCreateThreadNotifyRou
// I honestly don't expect this to happen, but if it does...
if (g_iThreadNotificationCount >= PSP_MAX_CREATE_THREAD_NOTIFY)
CxbxKrnlCleanup("Too many thread notification routines installed\n");
CxbxrKrnlAbort("Too many thread notification routines installed\n");
// Find an empty spot in the thread notification array
for (int i = 0; i < PSP_MAX_CREATE_THREAD_NOTIFY; i++)

View File

@ -40,7 +40,7 @@ namespace NtDll
#include "core\kernel\support\EmuNtDll.h"
};
#include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup()
#include "core\kernel\init\CxbxKrnl.h" // For CxbxrKrnlAbort()
#include "core\kernel\support\Emu.h" // For EmuLog(LOG_LEVEL::WARNING, )
#include <assert.h>
@ -701,7 +701,7 @@ XBSYSAPI EXPORTNUM(277) xbox::void_xt NTAPI xbox::RtlEnterCriticalSection
);
if (!nt_success(result))
{
CxbxKrnlCleanup("Waiting for event of a critical section returned %lx.", result);
CxbxrKrnlAbort("Waiting for event of a critical section returned %lx.", result);
};
}
CriticalSection->OwningThread = thread;

File diff suppressed because it is too large Load Diff

View File

@ -146,13 +146,10 @@ bool HandleFirstLaunch();
/*! Cxbx Kernel Entry Point */
void CxbxKrnlEmulate(unsigned int system, blocks_reserved_t blocks_reserved);
/*! initialize emulation */
__declspec(noreturn) void CxbxKrnlInit(void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, const char *szDebugFilename, Xbe::Header *XbeHeader, uint32_t XbeHeaderSize, void (*Entry)(), int BootFlags);
/*! cleanup emulation */
__declspec(noreturn) void CxbxKrnlCleanupEx(CXBXR_MODULE cxbxr_module, const char *szErrorMessage, ...);
[[noreturn]] void CxbxrKrnlAbortEx(CXBXR_MODULE cxbxr_module, const char *szErrorMessage, ...);
#define CxbxKrnlCleanup(fmt, ...) CxbxKrnlCleanupEx(LOG_PREFIX, fmt, ##__VA_ARGS__)
#define CxbxrKrnlAbort(fmt, ...) CxbxrKrnlAbortEx(LOG_PREFIX, fmt, ##__VA_ARGS__)
/*! register a thread handle */
void CxbxKrnlRegisterThread(HANDLE hThread);
@ -173,7 +170,7 @@ void CxbxKrnlPrintUEM(ULONG ErrorCode);
void CxbxPrintUEMInfo(ULONG ErrorCode);
/*! terminate the calling thread */
__declspec(noreturn) void CxbxKrnlTerminateThread();
[[noreturn]] void CxbxKrnlTerminateThread();
/*! kernel panic (trap for unimplemented kernel functions) */
void CxbxKrnlPanic();
@ -183,11 +180,7 @@ void CxbxKrnlNoFunc();
void CxbxInitPerformanceCounters(); // Implemented in EmuKrnlKe.cpp
void CxbxInitFilePaths();
// For emulation usage only
bool CxbxLockFilePath();
void CxbxUnlockFilePath();
void CxbxrInitFilePaths();
bool CxbxIsElevated();
@ -215,12 +208,10 @@ extern Xbe *CxbxKrnl_Xbe;
/*! parent window handle */
extern HWND CxbxKrnl_hEmuParent;
extern DebugMode CxbxKrnl_DebugMode;
extern std::string CxbxKrnl_DebugFileName;
/*! file paths */
extern char szFilePath_CxbxReloaded_Exe[MAX_PATH];
extern char szFolder_CxbxReloadedData[MAX_PATH];
extern std::string g_DataFilePath;
extern char szFilePath_EEPROM_bin[MAX_PATH];
extern char szFilePath_Xbe[xbox::max_path*2];

View File

@ -0,0 +1,77 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * This file is part of the Cxbx-Reloaded project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * All rights reserved
// *
// ******************************************************************
#pragma once
// NOTE: This file is intended to be used only with Cxbxkrnl.cpp file.
// NOTE2: If need to extern function/variable, please do in Cxbxkrnl.h file.
static void CxbxrKrnlSetupDummyHeader() {
// TODO : The following seems to cause a crash when booting the game "Forza Motorsport",
// according to https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/issues/101#issuecomment-277230140
// Create a fake kernel header for XapiRestrictCodeSelectorLimit
// Thanks advancingdragon / DirtBox
PDUMMY_KERNEL DummyKernel = (PDUMMY_KERNEL)XBOX_KERNEL_BASE;
memset(DummyKernel, 0, sizeof(DUMMY_KERNEL));
// XapiRestrictCodeSelectorLimit only checks these fields.
DummyKernel->DosHeader.e_lfanew = sizeof(IMAGE_DOS_HEADER); // RVA of NtHeaders
DummyKernel->FileHeader.SizeOfOptionalHeader = 0;
DummyKernel->FileHeader.NumberOfSections = 1;
// as long as this doesn't start with "INIT"
strncpy_s((PSTR)DummyKernel->SectionHeader.Name, 8, "DONGS", 8);
EmuLogInit(LOG_LEVEL::INFO, "Initialized dummy kernel image header.");
}
// TODO: If possible, maybe make this as optional patch when kernel emulation is fully done.
static void ApplyMediaPatches()
{
// Patch the XBE Header to allow running from all media types
g_pCertificate->dwAllowedMedia |= 0
| XBEIMAGE_MEDIA_TYPE_HARD_DISK
| XBEIMAGE_MEDIA_TYPE_DVD_X2
| XBEIMAGE_MEDIA_TYPE_DVD_CD
| XBEIMAGE_MEDIA_TYPE_CD
| XBEIMAGE_MEDIA_TYPE_DVD_5_RO
| XBEIMAGE_MEDIA_TYPE_DVD_9_RO
| XBEIMAGE_MEDIA_TYPE_DVD_5_RW
| XBEIMAGE_MEDIA_TYPE_DVD_9_RW
;
// Patch the XBE Header to allow running on all regions
g_pCertificate->dwGameRegion = 0
| XBEIMAGE_GAME_REGION_MANUFACTURING
| XBEIMAGE_GAME_REGION_NA
| XBEIMAGE_GAME_REGION_JAPAN
| XBEIMAGE_GAME_REGION_RESTOFWORLD
;
// Patch the XBE Security Flag
// This field is only present if the Xbe Size is >= than our Certificate Structure
// This works as our structure is large enough to fit the newer certificate size,
// while dwSize is the actual size of the certificate in the Xbe.
// Source: Various Hacked Kernels
if (g_pCertificate->dwSize >= sizeof(Xbe::Certificate)) {
g_pCertificate->dwSecurityFlags &= ~1;
}
}

View File

@ -259,7 +259,7 @@ void PoolManager::DeallocatePool(VAddr addr)
assert((Entry->PoolType & POOL_TYPE_MASK) != 0);
if (!IS_POOL_HEADER_MARKED_ALLOCATED(Entry)) {
CxbxKrnlCleanup("Pool at address 0x%X is already free!", addr);
CxbxrKrnlAbort("Pool at address 0x%X is already free!", addr);
}
MARK_POOL_HEADER_FREED(Entry);

View File

@ -104,7 +104,7 @@ void VMManager::Initialize(unsigned int SystemType, int BootFlags, blocks_reserv
for (int i = 0; i < 64; i++) {
LPVOID ret = VirtualAlloc((LPVOID)(PAGE_TABLES_BASE + i * m_AllocationGranularity), m_AllocationGranularity, MEM_COMMIT, PAGE_READWRITE);
if (ret != (LPVOID)(PAGE_TABLES_BASE + i * KiB(64))) {
CxbxKrnlCleanup("VirtualAlloc failed to commit the memory for the page tables. The error was 0x%08X", GetLastError());
CxbxrKrnlAbort("VirtualAlloc failed to commit the memory for the page tables. The error was 0x%08X", GetLastError());
}
}
@ -293,14 +293,14 @@ void VMManager::InitializeSystemAllocations()
void VMManager::GetPersistentMemory()
{
if (m_PersistentMemoryHandle != nullptr) {
CxbxKrnlCleanup("Persistent memory is already opened!");
CxbxrKrnlAbort("Persistent memory is already opened!");
return;
}
std::string persisted_mem_sid = str_persistent_memory_s + std::to_string(cli_config::GetSessionID());
m_PersistentMemoryHandle = OpenFileMapping(FILE_MAP_READ, FALSE, persisted_mem_sid.c_str());
if (m_PersistentMemoryHandle == nullptr) {
CxbxKrnlCleanup("Couldn't open persistent memory! OpenFileMapping failed with error 0x%08X", GetLastError());
CxbxrKrnlAbort("Couldn't open persistent memory! OpenFileMapping failed with error 0x%08X", GetLastError());
return;
}
}
@ -308,13 +308,13 @@ void VMManager::GetPersistentMemory()
void VMManager::RestorePersistentMemory()
{
if (m_PersistentMemoryHandle == nullptr) {
CxbxKrnlCleanup("Persistent memory is not open!");
CxbxrKrnlAbort("Persistent memory is not open!");
return;
}
PersistedMemory* persisted_mem = (PersistedMemory*)MapViewOfFile(m_PersistentMemoryHandle, FILE_MAP_READ, 0, 0, 0);
if (persisted_mem == nullptr) {
CxbxKrnlCleanup("Couldn't restore persistent memory! MapViewOfFile failed with error 0x%08X", GetLastError());
CxbxrKrnlAbort("Couldn't restore persistent memory! MapViewOfFile failed with error 0x%08X", GetLastError());
return;
}
@ -457,12 +457,12 @@ void VMManager::SavePersistentMemory()
std::string persistent_mem_sid = str_persistent_memory_s + std::to_string(cli_config::GetSessionID());
m_PersistentMemoryHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, num_persisted_ptes * PAGE_SIZE + num_persisted_ptes * 4 * 2 + sizeof(PersistedMemory), persistent_mem_sid.c_str());
if (m_PersistentMemoryHandle == NULL) {
CxbxKrnlCleanup("Couldn't persist memory! CreateFileMapping failed with error 0x%08X", GetLastError());
CxbxrKrnlAbort("Couldn't persist memory! CreateFileMapping failed with error 0x%08X", GetLastError());
return;
}
addr = MapViewOfFile(m_PersistentMemoryHandle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
if (addr == nullptr) {
CxbxKrnlCleanup("Couldn't persist memory! MapViewOfFile failed with error 0x%08X", GetLastError());
CxbxrKrnlAbort("Couldn't persist memory! MapViewOfFile failed with error 0x%08X", GetLastError());
return;
}

View File

@ -30,6 +30,7 @@
#include <core\kernel\exports\xboxkrnl.h>
#include "core\kernel\init\CxbxKrnl.h"
#include "core/kernel/support/PatchRdtsc.hpp"
#include "Emu.h"
#include "devices\x86\EmuX86.h"
#include "EmuShared.h"

View File

@ -98,7 +98,7 @@ io_mu_metadata::io_mu_metadata(const std::wstring_view root_path) : m_root_path(
std::wstring path = m_root_path + static_cast<wchar_t>(L'F' + i) + L".bin";
std::fstream fs(path, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
if (!fs.is_open()) {
CxbxKrnlCleanup("%s: could not open MU bin file at \"%ls\"!", __func__, path.c_str());
CxbxrKrnlAbort("%s: could not open MU bin file at \"%ls\"!", __func__, path.c_str());
}
fs.seekg(0);
fs.read(m_buff[i], sizeof(FATX_SUPERBLOCK));
@ -209,7 +209,7 @@ void CxbxCreatePartitionHeaderFile(std::string filename, bool partition0 = false
{
HANDLE hf = CreateFile(filename.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
if (!hf) {
CxbxKrnlCleanup("CxbxCreatePartitionHeaderFile Failed\nUnable to create file: %s (%s)", filename.c_str());
CxbxrKrnlAbort("CxbxCreatePartitionHeaderFile Failed\nUnable to create file: %s (%s)", filename.c_str());
return;
}
@ -229,7 +229,7 @@ XboxPartitionTable CxbxGetPartitionTable()
XboxPartitionTable table;
FILE* fp = fopen((g_DiskBasePath + "Partition0.bin").c_str(), "rb");
if (fp == nullptr) {
CxbxKrnlCleanup("CxbxGetPartitionTable Failed:\nUnable to open file: %s", (g_DiskBasePath + "Partition0.bin").c_str());
CxbxrKrnlAbort("CxbxGetPartitionTable Failed:\nUnable to open file: %s", (g_DiskBasePath + "Partition0.bin").c_str());
}
fread(&table, sizeof(XboxPartitionTable), 1, fp);
@ -267,7 +267,7 @@ std::wstring CxbxGetFinalPathNameByHandle(HANDLE hFile)
DWORD size = GetFinalPathNameByHandleW(hFile, path.data(), INITIAL_BUF_SIZE, VOLUME_NAME_DOS);
if (size == 0) {
CxbxKrnlCleanup("CxbxGetPartitionNumberFromHandle Failed:\nUnable to determine path for HANDLE 0x%08X", hFile);
CxbxrKrnlAbort("CxbxGetPartitionNumberFromHandle Failed:\nUnable to determine path for HANDLE 0x%08X", hFile);
}
// If the function fails because lpszFilePath is too small to hold the string plus the terminating null character,
@ -581,7 +581,7 @@ NTSTATUS CxbxConvertFilePath(
RelativePath.erase(0, 5); // Remove '$HOME'
}
else
CxbxKrnlCleanup(("Unsupported path macro : " + OriginalPath).c_str());
CxbxrKrnlAbort(("Unsupported path macro : " + OriginalPath).c_str());
}
// Check if the path starts with a relative path indicator :
else if (RelativePath[0] == '.') {// "4x4 Evo 2" needs this
@ -938,7 +938,7 @@ NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::strin
if (RootDirectoryHandle == INVALID_HANDLE_VALUE)
{
result = STATUS_DEVICE_DOES_NOT_EXIST; // TODO : Is this the correct error?
CxbxKrnlCleanup((std::string("Could not map ") + HostSymbolicLinkPath).c_str());
CxbxrKrnlAbort((std::string("Could not map ") + HostSymbolicLinkPath).c_str());
}
else
{
@ -1321,7 +1321,7 @@ void CxbxLaunchNewXbe(const std::string& XbePath) {
std::string cliCommands;
if (!cli_config::GenCMD(cliCommands))
{
CxbxKrnlCleanup("Could not launch %s", XbePath.c_str());
CxbxrKrnlAbort("Could not launch %s", XbePath.c_str());
}
CxbxDebugger::ReportNewTarget(cliCommands.c_str());
@ -1332,7 +1332,7 @@ void CxbxLaunchNewXbe(const std::string& XbePath) {
{
if (const auto &err = CxbxExec(false, nullptr, false))
{
CxbxKrnlCleanup("Could not launch %s\n\nThe reason was: %s", XbePath.c_str(), err->c_str());
CxbxrKrnlAbort("Could not launch %s\n\nThe reason was: %s", XbePath.c_str(), err->c_str());
}
}

View File

@ -0,0 +1,200 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * This file is part of the Cxbx-Reloaded project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * All rights reserved
// *
// ******************************************************************
#define LOG_PREFIX CXBXR_MODULE::CXBXR
#define LOG_PREFIX_INIT CXBXR_MODULE::INIT
#include <cstdint>
#include <string>
#include <vector>
#include "core\kernel\init\CxbxKrnl.h"
static std::vector<xbox::addr_xt> g_RdtscPatches;
#define OPCODE_PATCH_RDTSC 0x90EF // OUT DX, EAX; NOP
bool IsRdtscInstruction(xbox::addr_xt addr)
{
// First the fastest check - does addr contain exact patch from PatchRdtsc?
// Second check - is addr on the rdtsc patch list?
return (*(uint16_t*)addr == OPCODE_PATCH_RDTSC)
// Note : It's not needed to check for g_SkipRdtscPatching,
// as when that's set, the g_RdtscPatches vector will be empty
// anyway, failing this lookup :
&& (std::find(g_RdtscPatches.begin(), g_RdtscPatches.end(), addr) != g_RdtscPatches.end());
}
static void PatchRdtsc(xbox::addr_xt addr)
{
// Patch away rdtsc with an opcode we can intercept
// We use a privilaged instruction rather than int 3 for debugging
// When using int 3, attached debuggers trap and rdtsc is used often enough
// that it makes Cxbx-Reloaded unusable
// A privilaged instruction (like OUT) does not suffer from this
EmuLogInit(LOG_LEVEL::DEBUG, "Patching rdtsc opcode at 0x%.8X", (DWORD)addr);
*(uint16_t*)addr = OPCODE_PATCH_RDTSC;
g_RdtscPatches.push_back(addr);
}
static const uint8_t rdtsc_pattern[] = {
0x89,//{ 0x0F,0x31,0x89 }, // two false positives in Stranger's Wrath
0xC3,//{ 0x0F,0x31,0xC3 },
0x8B,//{ 0x0F,0x31,0x8B }, // one false positive in Sonic Rider .text 88 5C 0F 31, two false positives in Stranger's Wrath
0xB9,//{ 0x0F,0x31,0xB9 },
0xC7,//{ 0x0F,0x31,0xC7 },
0x8D,//{ 0x0F,0x31,0x8D },
0x68,//{ 0x0F,0x31,0x68 },
0x5A,//{ 0x0F,0x31,0x5A },
0x29,//{ 0x0F,0x31,0x29 },
0xF3,//{ 0x0F,0x31,0xF3 },
0xE9,//{ 0x0F,0x31,0xE9 },
0x2B,//{ 0x0F,0x31,0x2B },
0x50,//{ 0x0F,0x31,0x50 }, // 0x50 only used in ExaSkeleton .text , but encounter false positive in RalliSport .text 83 E2 0F 31
0x0F,//{ 0x0F,0x31,0x0F },
0x3B,//{ 0x0F,0x31,0x3B },
0xD9,//{ 0x0F,0x31,0xD9 },
0x57,//{ 0x0F,0x31,0x57 },
0xB9,//{ 0x0F,0x31,0xB9 },
0x85,//{ 0x0F,0x31,0x85 },
0x83,//{ 0x0F,0x31,0x83 },
0x33,//{ 0x0F,0x31,0x33 },
0xF7,//{ 0x0F,0x31,0xF7 }, // one false positive in Stranger's Wrath
0x8A,//{ 0x0F,0x31,0x8A }, // 8A and 56 only apears in RalliSport 2 .text , need to watch whether any future false positive.
0x56,//{ 0x0F,0x31,0x56 }
0x6A, // 6A, 39, EB, F6, A1, 01 only appear in Unreal Championship, 01 is at WMVDEC section
0x39,
0xEB,
0xF6,
0xA1,
0x01, // one false positive in Group S Challenge [1.05] .text E8 0F 31 01 00
0xA3
};
static const int sizeof_rdtsc_pattern = sizeof(rdtsc_pattern);
void PatchRdtscInstructions()
{
uint8_t rdtsc[2] = { 0x0F, 0x31 };
// Iterate through each CODE section
for (uint32_t sectionIndex = 0; sectionIndex < CxbxKrnl_Xbe->m_Header.dwSections; sectionIndex++) {
if (!CxbxKrnl_Xbe->m_SectionHeader[sectionIndex].dwFlags.bExecutable) {
continue;
}
// Skip some segments known to never contain rdtsc (to avoid false positives)
if (std::string(CxbxKrnl_Xbe->m_szSectionName[sectionIndex]) == "DSOUND"
|| std::string(CxbxKrnl_Xbe->m_szSectionName[sectionIndex]) == "XGRPH"
|| std::string(CxbxKrnl_Xbe->m_szSectionName[sectionIndex]) == ".data"
|| std::string(CxbxKrnl_Xbe->m_szSectionName[sectionIndex]) == ".rdata"
|| std::string(CxbxKrnl_Xbe->m_szSectionName[sectionIndex]) == "XMV"
|| std::string(CxbxKrnl_Xbe->m_szSectionName[sectionIndex]) == "XONLINE"
|| std::string(CxbxKrnl_Xbe->m_szSectionName[sectionIndex]) == "MDLPL") {
continue;
}
EmuLogInit(LOG_LEVEL::INFO, "Searching for rdtsc in section %s", CxbxKrnl_Xbe->m_szSectionName[sectionIndex]);
xbox::addr_xt startAddr = CxbxKrnl_Xbe->m_SectionHeader[sectionIndex].dwVirtualAddr;
//rdtsc is two bytes instruction, it needs at least one opcode byte after it to finish a function, so the endAddr need to substract 3 bytes.
xbox::addr_xt endAddr = startAddr + CxbxKrnl_Xbe->m_SectionHeader[sectionIndex].dwSizeofRaw - 3;
for (xbox::addr_xt addr = startAddr; addr <= endAddr; addr++)
{
if (memcmp((void*)addr, rdtsc, 2) == 0)
{
uint8_t next_byte = *(uint8_t*)(addr + 2);
// If the following byte matches the known pattern.
int i = 0;
for (i = 0; i < sizeof_rdtsc_pattern; i++)
{
if (next_byte == rdtsc_pattern[i])
{
if (next_byte == 0x8B)
{
if (*(uint8_t*)(addr - 2) == 0x88 && *(uint8_t*)(addr - 1) == 0x5C)
{
EmuLogInit(LOG_LEVEL::INFO, "Skipped false positive: rdtsc pattern 0x%.2X, @ 0x%.8X", next_byte, (DWORD)addr);
continue;
}
if (*(uint8_t*)(addr - 2) == 0x24 && *(uint8_t*)(addr - 1) == 0x0C)
{
EmuLogInit(LOG_LEVEL::INFO, "Skipped false positive: rdtsc pattern 0x%.2X, @ 0x%.8X", next_byte, (DWORD)addr);
continue;
}
}
if (next_byte == 0x89)
{
if (*(uint8_t*)(addr + 4) == 0x8B && *(uint8_t*)(addr - 5) == 0x04)
{
EmuLogInit(LOG_LEVEL::INFO, "Skipped false positive: rdtsc pattern 0x%.2X, @ 0x%.8X", next_byte, (DWORD)addr);
continue;
}
}
if (next_byte == 0x50)
{
if (*(uint8_t*)(addr - 2) == 0x83 && *(uint8_t*)(addr - 1) == 0xE2)
{
EmuLogInit(LOG_LEVEL::INFO, "Skipped false positive: rdtsc pattern 0x%.2X, @ 0x%.8X", next_byte, (DWORD)addr);
continue;
}
}
if (next_byte == 0x01)
{
if (*(uint8_t*)(addr - 1) == 0xE8 && *(uint8_t*)(addr + 3) == 0x00)
{
EmuLogInit(LOG_LEVEL::INFO, "Skipped false positive: rdtsc pattern 0x%.2X, @ 0x%.8X", next_byte, (DWORD)addr);
continue;
}
}
if (next_byte == 0xF7)
{
if (*(uint8_t*)(addr - 1) == 0xE8 && *(uint8_t*)(addr + 3) == 0xFF)
{
EmuLogInit(LOG_LEVEL::INFO, "Skipped false positive: rdtsc pattern 0x%.2X, @ 0x%.8X", next_byte, (DWORD)addr);
continue;
}
}
PatchRdtsc(addr);
//the first for loop already increment addr per loop. we only increment one more time so the addr will point to the byte next to the found rdtsc instruction. this is important since there is at least one case that two rdtsc instructions are next to each other.
addr += 1;
//if a match found, break the pattern matching loop and keep looping addr for next rdtsc.
break;
}
}
if (i >= sizeof_rdtsc_pattern)
{
//no pattern matched, keep record for detections we treat as non-rdtsc for future debugging.
EmuLogInit(LOG_LEVEL::INFO, "Skipped potential rdtsc: Unknown opcode pattern 0x%.2X, @ 0x%.8X", next_byte, (DWORD)addr);
}
}
}
}
EmuLogInit(LOG_LEVEL::INFO, "Done patching rdtsc, total %d rdtsc instructions patched", g_RdtscPatches.size());
}

View File

@ -0,0 +1,34 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * This file is part of the Cxbx-Reloaded project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * All rights reserved
// *
// ******************************************************************
#pragma once
#include "core\kernel\exports\xboxkrnl.h"
// NOTE: This file is intended to be used only with Cxbxkrnl.cpp file.
// NOTE2: If need to include header, please do in Cxbxkrnl.cpp file.
bool IsRdtscInstruction(xbox::addr_xt addr);
void PatchRdtscInstructions();

View File

@ -335,7 +335,7 @@ void OHCI::OHCI_FrameBoundaryWorker()
if (!m_Registers.HcDoneHead) {
// From the OHCI standard: "This is set to zero whenever HC writes the content of this
// register to HCCA. It also sets the WritebackDoneHead of HcInterruptStatus."
CxbxKrnlCleanup("HcDoneHead is zero but WritebackDoneHead interrupt is not set!\n");
CxbxrKrnlAbort("HcDoneHead is zero but WritebackDoneHead interrupt is not set!\n");
}
if (m_Registers.HcInterrupt & m_Registers.HcInterruptStatus) {
@ -372,7 +372,7 @@ void OHCI::OHCI_FrameBoundaryWorker()
void OHCI::OHCI_FatalError()
{
// According to the standard, an OHCI will stop operating, and set itself into error state
// (which can be queried by MMIO). Instead of calling directly CxbxKrnlCleanup, we let the
// (which can be queried by MMIO). Instead of calling directly CxbxrKrnlAbort, we let the
// HCD know the problem so that it can try to solve it
OHCI_SetInterrupt(OHCI_INTR_UE);

View File

@ -486,7 +486,7 @@ void USBDevice::USB_PacketCopy(USBPacket* p, void* ptr, size_t bytes)
IoVecFromBuffer(iov->IoVecStruct, iov->IoVecNumber, p->ActualLength, ptr, bytes);
break;
default:
CxbxKrnlCleanup("%s has an invalid pid: %x\n", __func__, p->Pid);
CxbxrKrnlAbort("%s has an invalid pid: %x\n", __func__, p->Pid);
}
p->ActualLength += bytes;
}

View File

@ -1040,7 +1040,6 @@ void cxbx_gl_render_overlays(NV2AState *d)
}
}
extern void UpdateFPSCounter();
void NV2ADevice::UpdateHostDisplay(NV2AState *d)
{
PGRAPHState *pg = &d->pgraph;
@ -1096,7 +1095,7 @@ void NV2ADevice::UpdateHostDisplay(NV2AState *d)
// glo_set_current(NULL);
UpdateFPSCounter();
g_renderbase->UpdateFPSCounter();
}
// TODO: Fix this properly
@ -1140,7 +1139,7 @@ void CxbxReserveNV2AMemory(NV2AState *d)
for (int i = 0; i < 16; i++) {
LPVOID ret = VirtualAlloc((LPVOID)(NV2A_ADDR + NV_PRAMIN_ADDR + i * 64 * ONE_KB), 64 * ONE_KB, MEM_COMMIT, PAGE_READWRITE);
if (ret != (LPVOID)(NV2A_ADDR + NV_PRAMIN_ADDR + i * 64 * ONE_KB)) {
CxbxKrnlCleanup("VirtualAlloc failed to commit the memory for the nv2a pramin. The error was 0x%08X", GetLastError());
CxbxrKrnlAbort("VirtualAlloc failed to commit the memory for the nv2a pramin. The error was 0x%08X", GetLastError());
}
}

View File

@ -198,7 +198,7 @@ void WriteEepromInMemory(HWND hDlg)
// Finally, recalculate the hash and the checksums
uint8_t EepromKey[16] = { 0 };
std::basic_ifstream<uint8_t> EepromFile(std::string(szFolder_CxbxReloadedData) + "\\keys.bin", std::ios::binary);
std::basic_ifstream<uint8_t> EepromFile(g_DataFilePath + "\\keys.bin", std::ios::binary);
if (EepromFile.is_open()) {
EepromFile.read(EepromKey, 16);
EepromFile.close();

View File

@ -112,9 +112,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
WndMain *MainWindow = new WndMain(hInstance);
// NOTE: CxbxInitFilePaths must be initalize AFTER WndMain for data directory option from user.
/* Initialize Cxbx File Paths */
CxbxInitFilePaths();
// NOTE: CxbxrInitFilePaths must be initalize AFTER WndMain for data directory option from user.
/* Initialize Cxbx-Reloaded File Paths */
CxbxrInitFilePaths();
/*! wait for window to be created, or failure */
while(!MainWindow->isCreated() && MainWindow->ProcessMessages())

View File

@ -214,8 +214,8 @@ WndMain::WndMain(HINSTANCE x_hInstance) :
g_Settings->Verify();
// NOTE: This is a requirement for pre-verification from GUI. Used in CxbxInitFilePaths function.
g_EmuShared->SetStorageLocation(g_Settings->GetDataLocation().c_str());
// NOTE: This is a requirement for pre-verification from GUI. Used in CxbxrInitFilePaths function.
g_EmuShared->SetDataLocation(g_Settings->GetDataLocation().c_str());
unsigned int i = 0;
do {