From 0da1273404d2b93d9225b4fc16b846aeae89025a Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Tue, 13 Apr 2021 10:38:30 -0500 Subject: [PATCH] review remarks --- src/core/kernel/exports/EmuKrnlHal.cpp | 1 - src/core/kernel/init/CxbxKrnl.cpp | 10 ++--- src/core/kernel/support/EmuFile.cpp | 52 +++++++++++++------------- src/core/kernel/support/EmuFile.h | 2 +- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/core/kernel/exports/EmuKrnlHal.cpp b/src/core/kernel/exports/EmuKrnlHal.cpp index 80addb59f..0606b8971 100644 --- a/src/core/kernel/exports/EmuKrnlHal.cpp +++ b/src/core/kernel/exports/EmuKrnlHal.cpp @@ -27,7 +27,6 @@ // ****************************************************************** #define LOG_PREFIX CXBXR_MODULE::HAL -#pragma optimize("", off) #include // For HalReadSMCTrayState, etc. #include // For PathRemoveFileSpec() diff --git a/src/core/kernel/init/CxbxKrnl.cpp b/src/core/kernel/init/CxbxKrnl.cpp index de823b1ef..bcbd1391e 100644 --- a/src/core/kernel/init/CxbxKrnl.cpp +++ b/src/core/kernel/init/CxbxKrnl.cpp @@ -997,7 +997,7 @@ void CxbxKrnlEmulate(unsigned int reserved_systems, blocks_reserved_t blocks_res // Remove extra slashes. std::string slash_search[] = { "\\\\", "//" }; std::string slash_str = "/"; - for (n = 0, i = 1; i < slash_search->size(); i++, n = 0) { + for (n = 0, i = 0; i < slash_search->size(); i++, n = 0) { while ((n = xbePath.find(slash_search[i], n)) != std::string::npos) { xbePath.replace(n, slash_search[i].size(), slash_str); n += slash_str.size(); @@ -1230,7 +1230,7 @@ void LoadXboxKeys(std::string path) // 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"); } -#pragma optimize("", off) + __declspec(noreturn) void CxbxKrnlInit ( void *pTLSData, @@ -1406,7 +1406,7 @@ __declspec(noreturn) void CxbxKrnlInit // Create default symbolic links : EmuLogInit(LOG_LEVEL::DEBUG, "Creating default symbolic links."); { - // TODO: DriveD should auto mount base on launchdata page's ; delimiter xbe path. + // TODO: DriveD should auto mount based on the launchdata page's ; delimiter in the xbe path. // This is the only symbolic link the Xbox Kernel sets, the rest are set by the application, usually via XAPI. // If the Xbe is located outside of the emulated HDD, mounting it as DeviceCdrom0 is correct // If the Xbe is located inside the emulated HDD, the full path should be used, eg: "\\Harddisk0\\partition2\\xboxdash.xbe" @@ -1419,7 +1419,7 @@ __declspec(noreturn) void CxbxKrnlInit #endif CxbxCreateSymbolicLink(DriveD, mount_d_dir); // Arrange that the Xbe path can reside outside the partitions, and put it to g_hCurDir : - EmuNtSymbolicLinkObject* xbePathSymbolicLinkObject = FindNtSymbolicLinkObjectByDriveLetter(CxbxDelimiterAutoMountDriveLetter); + EmuNtSymbolicLinkObject* xbePathSymbolicLinkObject = FindNtSymbolicLinkObjectByDriveLetter(CxbxAutoMountDriveLetter); g_hCurDir = xbePathSymbolicLinkObject->RootDirectoryHandle; } } @@ -1439,7 +1439,7 @@ __declspec(noreturn) void CxbxKrnlInit // Assign the running Xbe path, so it can be accessed via the kernel thunk 'XeImageFileName' : xbox::XeImageFileName.MaximumLength = xbox::max_path; xbox::XeImageFileName.Buffer = (PCHAR)xbox::ExAllocatePool(xbox::max_path); - sprintf(xbox::XeImageFileName.Buffer, "%c:\\%s", CxbxDelimiterAutoMountDriveLetter, fileName.c_str()); + sprintf(xbox::XeImageFileName.Buffer, "%c:\\%s", CxbxAutoMountDriveLetter, fileName.c_str()); xbox::XeImageFileName.Length = (USHORT)strlen(xbox::XeImageFileName.Buffer); EmuLogInit(LOG_LEVEL::INFO, "XeImageFileName = %s", xbox::XeImageFileName.Buffer); } diff --git a/src/core/kernel/support/EmuFile.cpp b/src/core/kernel/support/EmuFile.cpp index cc5d26acd..79b34b441 100644 --- a/src/core/kernel/support/EmuFile.cpp +++ b/src/core/kernel/support/EmuFile.cpp @@ -39,10 +39,10 @@ #pragma warning(default:4005) #include "core\kernel\init\CxbxKrnl.h" #include "Logging.h" -#include "common/util/strConverter.hpp" +#include "common/util/strConverter.hpp" // utf16_to_ascii #include -#pragma optimize("", off) + // Default Xbox Partition Table #define PE_PARTFLAGS_IN_USE 0x80000000 #define XBOX_SWAPPART1_LBA_START 0x400 @@ -445,10 +445,12 @@ NTSTATUS CxbxConvertFilePath( if (RelativePath.compare(0, 7, "serial:") == 0) return STATUS_UNRECOGNIZED_VOLUME; + // TODO: CDROM0: need access to raw file handle which doesn't exist in file system. + // Similar concept with serial: and perhaps mediaboards. // Raw handle access to the CDROM0: /*if (RelativePath.compare(0, 7, "CDROM0:") == 0) { - RelativePath = DeviceCdrom0 + "\\CDROM0.bin"; // we should have a return and likely forward to special handler function, including serial: above. + return ?; }*/ // The path seems to be a device path, look it up : @@ -625,31 +627,30 @@ XboxDevice *CxbxDeviceByHostPath(const std::string HostDevicePath) return nullptr; } -std::string CxbxConvertXboxToHostPath(const std::string_view XboxDevicePath) { - std::string XbePath; - // Convert Xbox XBE Path to Host Path - { - HANDLE rootDirectoryHandle = nullptr; - std::wstring wXbePath; - // We pretend to come from NtCreateFile to force symbolic link resolution - CxbxConvertFilePath(XboxDevicePath.data(), wXbePath, &rootDirectoryHandle, "NtCreateFile"); +// Convert Xbox XBE Path to Host Path +std::string CxbxConvertXboxToHostPath(const std::string_view XboxDevicePath) +{ + HANDLE rootDirectoryHandle = nullptr; + std::wstring wXbePath; + // We pretend to come from NtCreateFile to force symbolic link resolution + CxbxConvertFilePath(XboxDevicePath.data(), wXbePath, &rootDirectoryHandle, "NtCreateFile"); - // Convert Wide String as returned by above to a string, for XbePath - XbePath = utf16_to_ascii(wXbePath.c_str()); + // Convert Wide String as returned by above to a string, for XbePath + std::string XbePath = utf16_to_ascii(wXbePath.c_str()); - // If the rootDirectoryHandle is not null, we have a relative path - // We need to prepend the path of the root directory to get a full DOS path - if (rootDirectoryHandle != nullptr) { - char directoryPathBuffer[MAX_PATH]; - GetFinalPathNameByHandle(rootDirectoryHandle, directoryPathBuffer, MAX_PATH, VOLUME_NAME_DOS); - XbePath = directoryPathBuffer + std::string("\\") + XbePath; + // If the rootDirectoryHandle is not null, we have a relative path + // We need to prepend the path of the root directory to get a full DOS path + if (rootDirectoryHandle != nullptr) { + char directoryPathBuffer[MAX_PATH]; + GetFinalPathNameByHandle(rootDirectoryHandle, directoryPathBuffer, MAX_PATH, VOLUME_NAME_DOS); + XbePath = directoryPathBuffer + std::string("\\") + XbePath; - // Trim \\?\ from the output string, as we want the raw DOS path, not NT path - // We can do this always because GetFinalPathNameByHandle ALWAYS returns this format - // Without exception - XbePath.erase(0, 4); - } + // Trim \\?\ from the output string, as we want the raw DOS path, not NT path + // We can do this always because GetFinalPathNameByHandle ALWAYS returns this format + // Without exception + XbePath.erase(0, 4); } + return XbePath; } @@ -673,7 +674,7 @@ int CxbxRegisterDeviceHostPath(const std::string_view XboxDevicePath, std::strin // If this path is not a raw file partition, create the directory for it if (!IsFile) { - std::error_code error; + std::error_code error; // We do not want filesystem to throw an exception on directory creation. Instead, listen for return value to fail. succeeded = std::filesystem::exists(HostDevicePath) || std::filesystem::create_directory(HostDevicePath, error); } @@ -771,7 +772,6 @@ NTSTATUS EmuNtSymbolicLinkObject::Init(std::string aSymbolicLinkName, std::strin } } - RootDirectoryHandle = CreateFile(HostSymbolicLinkPath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (RootDirectoryHandle == INVALID_HANDLE_VALUE) { diff --git a/src/core/kernel/support/EmuFile.h b/src/core/kernel/support/EmuFile.h index bf3ba9d4b..cfd99747d 100644 --- a/src/core/kernel/support/EmuFile.h +++ b/src/core/kernel/support/EmuFile.h @@ -91,7 +91,7 @@ extern const std::string DeviceHarddisk0Partition17; extern const std::string DeviceHarddisk0Partition18; extern const std::string DeviceHarddisk0Partition19; extern const std::string DeviceHarddisk0Partition20; -static constexpr char CxbxDelimiterAutoMountDriveLetter = 'D'; +constexpr char CxbxAutoMountDriveLetter = 'D'; extern std::string CxbxBasePath; extern HANDLE CxbxBasePathHandle;