From d2bcb2920b77fcf61462ce52819cce180224dc2b Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Sun, 6 Apr 2003 20:07:36 +0000 Subject: [PATCH] NtOpenFile/IoCreateFile --- CxbxKrnl.dsp | 2 +- Source/Win32/Cxbx/EmuExe.cpp | 7 +++- Source/Win32/Cxbx/Wnd.cpp | 5 ++- Source/Win32/CxbxKrnl/Emu.cpp | 2 + Source/Win32/CxbxKrnl/EmuD3D8.cpp | 4 ++ Source/Win32/CxbxKrnl/EmuKrnl.cpp | 57 ++++++++++++++++++++++++++- Source/Win32/CxbxKrnl/KernelThunk.cpp | 2 +- 7 files changed, 72 insertions(+), 7 deletions(-) diff --git a/CxbxKrnl.dsp b/CxbxKrnl.dsp index c15aacf39..c86ca8373 100644 --- a/CxbxKrnl.dsp +++ b/CxbxKrnl.dsp @@ -79,7 +79,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 d3d8.lib dinput8.lib dxguid.lib ntdll.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"Bin\Debug/Cxbx.dll" /pdbtype:sept /libpath:"Lib" +# ADD LINK32 d3d8.lib dinput8.lib dxguid.lib ntdll.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"libc" /pdbtype:sept /libpath:"Lib" # SUBTRACT LINK32 /pdb:none !ENDIF diff --git a/Source/Win32/Cxbx/EmuExe.cpp b/Source/Win32/Cxbx/EmuExe.cpp index 645c91e77..963f6cb7f 100644 --- a/Source/Win32/Cxbx/EmuExe.cpp +++ b/Source/Win32/Cxbx/EmuExe.cpp @@ -483,9 +483,12 @@ EmuExe::EmuExe(Xbe *x_Xbe, DebugMode x_debug_mode, char *x_debug_filename) : Exe *(uint32*)&m_bzSection[i][0x30] = dwVirtAddr + 0x38; *(uint32*)&m_bzSection[i][0x34] = 0; *(uint16*)&m_bzSection[i][0x38] = 0x0001; - - memcpy(&m_bzSection[i][0x3A], "_EmuNoFunc@0\0\0cxbx.dll\0\0\0\0\0\0", 28); +#ifdef _DEBUG + memcpy(&m_bzSection[i][0x3A], "_EmuNoFunc@0\0\0CxbxKrnl.dll\0\0", 28); +#else + memcpy(&m_bzSection[i][0x3A], "_EmuNoFunc@0\0\0Cxbx.dll\0\0\0\0\0\0", 28); +#endif // ****************************************************************** // * TLS Data // ****************************************************************** diff --git a/Source/Win32/Cxbx/Wnd.cpp b/Source/Win32/Cxbx/Wnd.cpp index 193944e54..fc841336e 100644 --- a/Source/Win32/Cxbx/Wnd.cpp +++ b/Source/Win32/Cxbx/Wnd.cpp @@ -69,8 +69,11 @@ bool Wnd::ProcessMessages() // initialize window if(!m_initialized) { +#ifdef _DEBUG + HMODULE hCxbxDll = GetModuleHandle("CxbxKrnl.dll"); +#else HMODULE hCxbxDll = GetModuleHandle("Cxbx.dll"); - +#endif m_initialized = true; WNDCLASS wnd_class; diff --git a/Source/Win32/CxbxKrnl/Emu.cpp b/Source/Win32/CxbxKrnl/Emu.cpp index d06854884..904faf1b9 100644 --- a/Source/Win32/CxbxKrnl/Emu.cpp +++ b/Source/Win32/CxbxKrnl/Emu.cpp @@ -48,6 +48,8 @@ namespace xboxkrnl #include "EmuShared.h" #include "HLEDataBase.h" +#include + // ****************************************************************** // * global / static // ****************************************************************** diff --git a/Source/Win32/CxbxKrnl/EmuD3D8.cpp b/Source/Win32/CxbxKrnl/EmuD3D8.cpp index d5b1dcc37..d7fa1d233 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8.cpp @@ -120,7 +120,11 @@ void EmuRenderWindow(PVOID) // * register window class // ****************************************************************** { +#ifdef _DEBUG + HMODULE hCxbxDll = GetModuleHandle("CxbxKrnl.dll"); +#else HMODULE hCxbxDll = GetModuleHandle("Cxbx.dll"); +#endif WNDCLASSEX wc = { diff --git a/Source/Win32/CxbxKrnl/EmuKrnl.cpp b/Source/Win32/CxbxKrnl/EmuKrnl.cpp index f7005b0a4..c8a3d0b40 100644 --- a/Source/Win32/CxbxKrnl/EmuKrnl.cpp +++ b/Source/Win32/CxbxKrnl/EmuKrnl.cpp @@ -229,6 +229,53 @@ XBSYSAPI EXPORTNUM(49) VOID DECLSPEC_NORETURN xboxkrnl::HalReturnToFirmware EmuSwapFS(); // Xbox FS } +// ****************************************************************** +// * 0x0042 - IoCreateFile +// ****************************************************************** +XBSYSAPI EXPORTNUM(66) NTSTATUS NTAPI xboxkrnl::IoCreateFile +( + OUT PHANDLE FileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN PLARGE_INTEGER AllocationSize, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG Disposition, + IN ULONG CreateOptions, + IN ULONG Options +) +{ + EmuSwapFS(); // Win2k/XP FS + + // ****************************************************************** + // * debug trace + // ****************************************************************** + #ifdef _DEBUG_TRACE + { + printf("EmuKrnl (0x%.08X): IoCreateFile\n" + "(\n" + " FileHandle : 0x%.08X\n" + " DesiredAccess : 0x%.08X\n" + " ObjectAttributes : 0x%.08X\n" + " IoStatusBlock : 0x%.08X\n" + " AllocationSize : 0x%.08X\n" + " FileAttributes : 0x%.08X\n" + " ShareAccess : 0x%.08X\n" + " Disposition : 0x%.08X\n" + " CreateOptions : 0x%.08X\n" + " Options : 0x%.08X\n" + ");\n", + GetCurrentThreadId(), FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, + AllocationSize, FileAttributes, ShareAccess, Disposition, CreateOptions, Options); + } + #endif + + EmuSwapFS(); // Xbox FS + + return STATUS_SUCCESS; +} + // ****************************************************************** // * 0x0063 - KeDelayExecutionThread // ****************************************************************** @@ -463,13 +510,17 @@ XBSYSAPI EXPORTNUM(202) NTSTATUS xboxkrnl::NtOpenFile IN ULONG OpenOptions ) { - EmuSwapFS(); // Win2k/XP FS + // Note: Since we are simply redirecting to IoCreateFile, we do not + // want to swap FS registers like normal (except for when + // _DEBUG_TRACE is enabled) // ****************************************************************** // * debug trace // ****************************************************************** #ifdef _DEBUG_TRACE { + EmuSwapFS(); // Win2k/XP FS + printf("EmuKrnl (0x%.08X): NtOpenFile\n" "(\n" " FileHandle : 0x%.08X\n" @@ -481,10 +532,12 @@ XBSYSAPI EXPORTNUM(202) NTSTATUS xboxkrnl::NtOpenFile ");\n", GetCurrentThreadId(), FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, ShareAccess, OpenOptions); + + EmuSwapFS(); // Xbox FS } #endif - EmuSwapFS(); // Xbox FS + xboxkrnl::IoCreateFile(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, 0, 0, ShareAccess, 1, OpenOptions, 0); return STATUS_SUCCESS; } diff --git a/Source/Win32/CxbxKrnl/KernelThunk.cpp b/Source/Win32/CxbxKrnl/KernelThunk.cpp index 5cbde0867..cb21a228b 100644 --- a/Source/Win32/CxbxKrnl/KernelThunk.cpp +++ b/Source/Win32/CxbxKrnl/KernelThunk.cpp @@ -130,7 +130,7 @@ extern "C" CXBXKRNL_API uint32 KernelThunkTable[367] = (uint32)PANIC(0x003F), // 0x003F (63) (uint32)PANIC(0x0040), // 0x0040 (64) (uint32)PANIC(0x0041), // 0x0041 (65) - (uint32)PANIC(0x0042), // 0x0042 (66) + (uint32)&xboxkrnl::IoCreateFile, // 0x0042 (66) (uint32)PANIC(0x0043), // 0x0043 (67) (uint32)PANIC(0x0044), // 0x0044 (68) (uint32)PANIC(0x0045), // 0x0045 (69)