Cxbx-Reloaded/Source/Win32/CxbxKrnl/EmuKrnl.cpp

1369 lines
47 KiB
C++
Raw Normal View History

2003-01-26 06:18:56 +00:00
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
2003-03-27 06:23:58 +00:00
// * Cxbx->Win32->CxbxKrnl->EmuKrnl.cpp
2003-01-26 06:18:56 +00:00
// *
// * This file is part of the Cxbx 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.
// *
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
// *
// * All rights reserved
// *
// ******************************************************************
2003-03-07 22:01:44 +00:00
#define _CXBXKRNL_INTERNAL
2003-01-26 06:18:56 +00:00
#define _XBOXKRNL_LOCAL_
2003-04-02 02:23:30 +00:00
// ******************************************************************
// * prevent name collisions
// ******************************************************************
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h>
};
#include <stdio.h>
2003-05-23 02:55:39 +00:00
#include <locale.h>
2003-01-28 07:28:18 +00:00
2003-03-07 22:01:44 +00:00
// ******************************************************************
// * prevent name collisions
// ******************************************************************
2003-01-26 06:18:56 +00:00
namespace xntdll
{
#include "xntdll.h"
};
2003-04-02 02:23:30 +00:00
#include "Emu.h"
#include "EmuFS.h"
2003-04-10 07:01:24 +00:00
#include "EmuFile.h"
2003-04-26 04:32:46 +00:00
#include "EmuKrnl.h"
2003-05-23 02:55:39 +00:00
#include "EmuD3D8.h"
2003-01-26 06:18:56 +00:00
2003-03-27 03:52:19 +00:00
// ******************************************************************
// * Loaded at run-time to avoid linker conflicts
// ******************************************************************
2003-04-17 01:32:51 +00:00
static HMODULE hNtDll = GetModuleHandle("ntdll");
2003-04-10 07:01:24 +00:00
2003-06-04 02:18:40 +00:00
xntdll::FPTR_RtlInitAnsiString NT_RtlInitAnsiString = (xntdll::FPTR_RtlInitAnsiString)GetProcAddress(hNtDll, "RtlInitAnsiString");
xntdll::FPTR_RtlInitUnicodeString NT_RtlInitUnicodeString = (xntdll::FPTR_RtlInitUnicodeString)GetProcAddress(hNtDll, "RtlInitUnicodeString");
xntdll::FPTR_RtlNtStatusToDosError NT_RtlNtStatusToDosError = (xntdll::FPTR_RtlNtStatusToDosError)GetProcAddress(hNtDll, "RtlNtStatusToDosError");
2003-06-07 03:06:59 +00:00
xntdll::FPTR_RtlInitializeCriticalSection NT_RtlInitializeCriticalSection = (xntdll::FPTR_RtlInitializeCriticalSection)GetProcAddress(hNtDll, "RtlInitializeCriticalSection");
xntdll::FPTR_RtlEnterCriticalSection NT_RtlEnterCriticalSection = (xntdll::FPTR_RtlEnterCriticalSection)GetProcAddress(hNtDll, "RtlEnterCriticalSection");
xntdll::FPTR_RtlLeaveCriticalSection NT_RtlLeaveCriticalSection = (xntdll::FPTR_RtlLeaveCriticalSection)GetProcAddress(hNtDll, "RtlLeaveCriticalSection");
2003-06-04 02:18:40 +00:00
xntdll::FPTR_NtAllocateVirtualMemory NT_NtAllocateVirtualMemory = (xntdll::FPTR_NtAllocateVirtualMemory)GetProcAddress(hNtDll, "NtAllocateVirtualMemory");
xntdll::FPTR_NtClose NT_NtClose = (xntdll::FPTR_NtClose)GetProcAddress(hNtDll, "NtClose");
xntdll::FPTR_NtDelayExecution NT_NtDelayExecution = (xntdll::FPTR_NtDelayExecution)GetProcAddress(hNtDll, "NtDelayExecution");
xntdll::FPTR_NtQueryInformationFile NT_NtQueryInformationFile = (xntdll::FPTR_NtQueryInformationFile)GetProcAddress(hNtDll, "NtQueryInformationFile");
2003-06-07 03:06:59 +00:00
xntdll::FPTR_NtQueryVolumeInformationFile NT_NtQueryVolumeInformationFile = (xntdll::FPTR_NtQueryVolumeInformationFile)GetProcAddress(hNtDll, "NtQueryVolumeInformationFile");
xntdll::FPTR_NtCreateEvent NT_NtCreateEvent = (xntdll::FPTR_NtCreateEvent)GetProcAddress(hNtDll, "NtCreateEvent");
2003-06-04 02:18:40 +00:00
xntdll::FPTR_NtCreateFile NT_NtCreateFile = (xntdll::FPTR_NtCreateFile)GetProcAddress(hNtDll, "NtCreateFile");
xntdll::FPTR_NtReadFile NT_NtReadFile = (xntdll::FPTR_NtReadFile)GetProcAddress(hNtDll, "NtReadFile");
2003-06-06 04:53:27 +00:00
xntdll::FPTR_NtWriteFile NT_NtWriteFile = (xntdll::FPTR_NtWriteFile)GetProcAddress(hNtDll, "NtWriteFile");
2003-06-12 02:05:10 +00:00
xntdll::FPTR_NtSetInformationFile NT_NtSetInformationFile = (xntdll::FPTR_NtSetInformationFile)GetProcAddress(hNtDll, "NtSetInformationFile");
2003-03-27 03:52:19 +00:00
2003-01-27 09:18:33 +00:00
// ******************************************************************
2003-04-05 09:03:02 +00:00
// * (Helper) PCSTProxyParam
2003-01-27 09:18:33 +00:00
// ******************************************************************
2003-04-05 09:03:02 +00:00
typedef struct _PCSTProxyParam
2003-01-27 09:18:33 +00:00
{
IN PVOID StartContext1;
IN PVOID StartContext2;
IN PVOID StartRoutine;
}
2003-04-05 09:03:02 +00:00
PCSTProxyParam;
2003-01-27 09:18:33 +00:00
// ******************************************************************
2003-04-05 09:03:02 +00:00
// * (Helper) PCSTProxy
2003-01-27 09:18:33 +00:00
// ******************************************************************
#pragma warning(push)
#pragma warning(disable: 4731) // disable ebp modification warning
2003-04-17 01:32:51 +00:00
static DWORD WINAPI PCSTProxy
2003-01-27 09:18:33 +00:00
(
IN PVOID Parameter
)
{
2003-04-05 09:03:02 +00:00
PCSTProxyParam *iPCSTProxyParam = (PCSTProxyParam*)Parameter;
2003-01-27 09:18:33 +00:00
2003-04-05 09:03:02 +00:00
uint32 StartContext1 = (uint32)iPCSTProxyParam->StartContext1;
uint32 StartContext2 = (uint32)iPCSTProxyParam->StartContext2;
uint32 StartRoutine = (uint32)iPCSTProxyParam->StartRoutine;
2003-01-27 09:18:33 +00:00
2003-04-05 09:03:02 +00:00
delete iPCSTProxyParam;
2003-01-27 09:18:33 +00:00
2003-02-01 08:49:41 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-01 08:49:41 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): PCSTProxy\n"
2003-02-09 08:35:33 +00:00
"(\n"
" StartContext1 : 0x%.08X\n"
" StartContext2 : 0x%.08X\n"
" StartRoutine : 0x%.08X\n"
");\n",
2003-02-01 08:49:41 +00:00
GetCurrentThreadId(), StartContext1, StartContext2, StartRoutine);
}
#endif
2003-05-04 19:55:25 +00:00
EmuGenerateFS(g_pTLS, g_pTLSData);
2003-01-31 18:10:38 +00:00
2003-04-05 09:03:02 +00:00
// ******************************************************************
// * use the special calling convention
// ******************************************************************
2003-04-08 03:34:05 +00:00
__try
{
2003-04-27 04:56:09 +00:00
EmuSwapFS(); // Xbox FS
2003-04-08 03:34:05 +00:00
__asm
2003-04-25 23:49:58 +00:00
{
2003-04-08 03:34:05 +00:00
mov esi, StartRoutine
push StartContext2
push StartContext1
push offset callComplete
lea ebp, [esp-4]
jmp near esi
}
}
__except(EmuException(GetExceptionInformation()))
{
printf("Emu: WARNING!! Problem with ExceptionFilter\n");
}
2003-04-11 09:13:06 +00:00
callComplete:
2003-01-27 09:18:33 +00:00
2003-04-29 03:30:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-05-20 21:39:25 +00:00
EmuCleanThread();
2003-04-26 07:30:21 +00:00
2003-01-27 09:18:33 +00:00
return 0;
}
#pragma warning(pop)
2003-01-26 06:18:56 +00:00
using namespace xboxkrnl;
2003-02-03 23:36:24 +00:00
// ******************************************************************
// * 0x0018 ExQueryNonVolatileSetting
// ******************************************************************
XBSYSAPI EXPORTNUM(24) NTSTATUS NTAPI xboxkrnl::ExQueryNonVolatileSetting
(
2003-05-23 02:55:39 +00:00
IN DWORD ValueIndex,
OUT DWORD *Type,
OUT PUCHAR Value,
IN SIZE_T ValueLength,
OUT PSIZE_T ResultLength OPTIONAL
2003-02-03 23:36:24 +00:00
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-03 23:36:24 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-03 23:36:24 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): ExQueryNonVolatileSetting\n"
2003-02-09 08:35:33 +00:00
"(\n"
" ValueIndex : 0x%.08X\n"
" Type : 0x%.08X\n"
" Value : 0x%.08X\n"
" ValueLength : 0x%.08X\n"
" ResultLength : 0x%.08X\n"
");\n",
2003-02-03 23:36:24 +00:00
GetCurrentThreadId(), ValueIndex, Type, Value, ValueLength, ResultLength);
}
#endif
2003-02-06 05:32:40 +00:00
// ******************************************************************
// * handle eeprom read
// ******************************************************************
switch(ValueIndex)
{
case EEPROM_MISC:
{
if(Type != 0)
*Type = 0x04;
if(Value != 0)
*Value = 0;
if(ResultLength != 0)
*ResultLength = 0x04;
}
break;
default:
2003-06-10 08:18:43 +00:00
printf("ExQueryNonVolatileSetting unknown ValueIndex (%d)\n", ValueIndex);
2003-04-11 09:13:06 +00:00
break;
2003-02-06 05:32:40 +00:00
}
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-03 23:36:24 +00:00
return STATUS_SUCCESS;
}
2003-01-31 22:15:41 +00:00
// ******************************************************************
// * 0x0031 - HalReturnToFirmware
// ******************************************************************
XBSYSAPI EXPORTNUM(49) VOID DECLSPEC_NORETURN xboxkrnl::HalReturnToFirmware
(
2003-05-23 02:55:39 +00:00
RETURN_FIRMWARE Routine
2003-01-31 22:15:41 +00:00
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-01-31 22:15:41 +00:00
2003-02-21 04:51:03 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): HalReturnToFirmware\n"
2003-02-21 04:51:03 +00:00
"(\n"
" Routine : 0x%.08X\n"
");\n",
GetCurrentThreadId(), Routine);
}
#endif
2003-05-23 02:55:39 +00:00
MessageBox(g_hEmuWindow, "Warning: XBE is quitting (HalReturnToFirmware).\n\nThis process may not terminate elegantly.", "Cxbx", MB_OK);
2003-02-21 04:51:03 +00:00
ExitProcess(0);
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-21 04:51:03 +00:00
}
2003-01-31 22:15:41 +00:00
2003-04-06 20:07:36 +00:00
// ******************************************************************
// * 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
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): IoCreateFile\n"
2003-04-06 20:07:36 +00:00
"(\n"
" FileHandle : 0x%.08X\n"
" DesiredAccess : 0x%.08X\n"
2003-04-11 09:13:06 +00:00
" ObjectAttributes : 0x%.08X (%s)\n"
2003-04-06 20:07:36 +00:00
" 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",
2003-04-11 09:13:06 +00:00
GetCurrentThreadId(), FileHandle, DesiredAccess, ObjectAttributes, ObjectAttributes->ObjectName->Buffer,
IoStatusBlock, AllocationSize, FileAttributes, ShareAccess, Disposition, CreateOptions, Options);
2003-04-06 20:07:36 +00:00
}
#endif
2003-04-10 07:01:24 +00:00
NTSTATUS ret = STATUS_SUCCESS;
2003-05-23 02:55:39 +00:00
// TODO: Use NtCreateFile if necessary. If it will work, we're fine
EmuCleanup("IoCreateFile not implemented");
2003-04-06 20:07:36 +00:00
EmuSwapFS(); // Xbox FS
2003-04-10 07:01:24 +00:00
return ret;
2003-04-06 20:07:36 +00:00
}
2003-04-11 09:13:06 +00:00
// ******************************************************************
// * 0x0043 IoCreateSymbolicLink
// ******************************************************************
XBSYSAPI EXPORTNUM(67) NTSTATUS xboxkrnl::IoCreateSymbolicLink
(
IN PSTRING SymbolicLinkName,
IN PSTRING DeviceName
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): IoCreateSymbolicLink\n"
2003-04-11 09:13:06 +00:00
"(\n"
" SymbolicLinkName : 0x%.08X (%s)\n"
" DeviceName : 0x%.08X (%s)\n"
");\n",
GetCurrentThreadId(), SymbolicLinkName, SymbolicLinkName->Buffer,
DeviceName, DeviceName->Buffer);
}
#endif
2003-05-28 22:54:38 +00:00
EmuCleanup("IoCreateSymbolicLink not implemented");
2003-05-23 02:55:39 +00:00
2003-04-11 09:13:06 +00:00
// TODO: Actually um...implement this function
NTSTATUS ret = STATUS_OBJECT_NAME_COLLISION;
EmuSwapFS(); // Xbox FS
return ret;
}
2003-02-21 04:51:03 +00:00
// ******************************************************************
// * 0x0063 - KeDelayExecutionThread
// ******************************************************************
XBSYSAPI EXPORTNUM(99) NTSTATUS NTAPI xboxkrnl::KeDelayExecutionThread
(
IN KPROCESSOR_MODE WaitMode,
IN BOOLEAN Alertable,
IN PLARGE_INTEGER Interval
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-21 04:51:03 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): KeDelayExecutionThread\n"
2003-02-21 04:51:03 +00:00
"(\n"
" WaitMode : 0x%.08X\n"
" Alertable : 0x%.08X\n"
" Interval : 0x%.08X\n"
");\n",
GetCurrentThreadId(), WaitMode, Alertable, Interval);
}
#endif
2003-04-17 01:32:51 +00:00
NTSTATUS ret = NT_NtDelayExecution(Alertable, (xntdll::LARGE_INTEGER*)Interval);
2003-02-21 04:51:03 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-21 04:51:03 +00:00
2003-04-17 01:32:51 +00:00
return ret;
2003-01-31 22:15:41 +00:00
}
2003-02-03 23:36:24 +00:00
// ******************************************************************
// * 0x006B - KeInitializeDpc
// ******************************************************************
XBSYSAPI EXPORTNUM(107) VOID NTAPI xboxkrnl::KeInitializeDpc
(
KDPC *Dpc,
PKDEFERRED_ROUTINE DeferredRoutine,
PVOID DeferredContext
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-03 23:36:24 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-03 23:36:24 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): KeInitializeDpc\n"
2003-02-09 08:35:33 +00:00
"(\n"
" Dpc : 0x%.08X\n"
" DeferredRoutine : 0x%.08X\n"
" DeferredContext : 0x%.08X\n"
");\n",
2003-02-03 23:36:24 +00:00
GetCurrentThreadId(), Dpc, DeferredRoutine, DeferredContext);
}
#endif
2003-02-06 05:32:40 +00:00
Dpc->Number = 0;
2003-05-23 02:55:39 +00:00
Dpc->DeferredRoutine = DeferredRoutine;
2003-02-06 05:32:40 +00:00
Dpc->Type = DpcObject;
2003-05-23 02:55:39 +00:00
Dpc->DeferredContext = DeferredContext;
2003-02-06 05:32:40 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-03 23:36:24 +00:00
return;
}
// ******************************************************************
// * 0x0071 - KeInitializeTimerEx
// ******************************************************************
XBSYSAPI EXPORTNUM(113) VOID NTAPI xboxkrnl::KeInitializeTimerEx
(
IN PKTIMER Timer,
IN TIMER_TYPE Type
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-03 23:36:24 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-03 23:36:24 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): KeInitializeTimerEx\n"
2003-02-09 08:35:33 +00:00
"(\n"
" Timer : 0x%.08X\n"
" Type : 0x%.08X\n"
");\n",
2003-02-03 23:36:24 +00:00
GetCurrentThreadId(), Timer, Type);
}
#endif
2003-02-06 05:32:40 +00:00
Timer->Header.Type = Type + 8;
Timer->Header.Inserted = 0;
Timer->Header.Size = sizeof(*Timer) / sizeof(ULONG);
Timer->Header.SignalState = 0;
Timer->TimerListEntry.Blink = NULL;
Timer->TimerListEntry.Flink = NULL;
Timer->Header.WaitListHead.Flink = &Timer->Header.WaitListHead;
Timer->Header.WaitListHead.Blink = &Timer->Header.WaitListHead;
Timer->DueTime.QuadPart = 0;
Timer->Period = 0;
2003-02-03 23:36:24 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-03 23:36:24 +00:00
return;
}
2003-06-07 03:06:59 +00:00
// ******************************************************************
// * 0x0080 - KeQuerySystemTime
// ******************************************************************
XBSYSAPI EXPORTNUM(128) VOID NTAPI xboxkrnl::KeQuerySystemTime
(
PLARGE_INTEGER CurrentTime
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuKrnl (0x%X): KeQuerySystemTime\n"
"(\n"
" CurrentTime : 0x%.08X\n"
");\n",
GetCurrentThreadId(), CurrentTime);
}
#endif
SYSTEMTIME SystemTime;
GetSystemTime(&SystemTime);
SystemTimeToFileTime(&SystemTime, (FILETIME*)CurrentTime);
EmuSwapFS(); // Xbox FS
return;
}
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * 0x0095 - KeSetTimer
// ******************************************************************
XBSYSAPI EXPORTNUM(149) xboxkrnl::BOOLEAN NTAPI xboxkrnl::KeSetTimer
(
IN PKTIMER Timer,
IN LARGE_INTEGER DueTime,
IN PKDPC Dpc OPTIONAL
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-06 08:55:36 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): KeSetTimer\n"
2003-02-09 08:35:33 +00:00
"(\n"
" Timer : 0x%.08X\n"
" DueTime : 0x%I64X\n"
" Dpc : 0x%.08X\n"
");\n",
2003-02-06 08:55:36 +00:00
GetCurrentThreadId(), Timer, DueTime, Dpc);
}
#endif
2003-06-07 03:06:59 +00:00
EmuCleanup("KeSetTimer: Not Implemented!");
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-06 08:55:36 +00:00
2003-04-05 09:03:02 +00:00
return TRUE;
2003-02-06 08:55:36 +00:00
}
2003-05-05 06:35:37 +00:00
// ******************************************************************
// * 0x009C - KeTickCount
// ******************************************************************
XBSYSAPI EXPORTNUM(156) xboxkrnl::DWORD xboxkrnl::KeTickCount = 0;
2003-04-05 09:03:02 +00:00
// ******************************************************************
// * 0x00A4 - LaunchDataPage (actually a pointer)
// ******************************************************************
XBSYSAPI EXPORTNUM(164) xboxkrnl::DWORD xboxkrnl::LaunchDataPage = 0;
2003-06-06 00:56:10 +00:00
// ******************************************************************
// * 0x00A6 - MmAllocateContiguousMemoryEx
// ******************************************************************
XBSYSAPI EXPORTNUM(166) xboxkrnl::PVOID NTAPI xboxkrnl::MmAllocateContiguousMemoryEx
(
IN ULONG NumberOfBytes,
IN PHYSICAL_ADDRESS LowestAcceptableAddress,
IN PHYSICAL_ADDRESS HighestAcceptableAddress,
IN ULONG Alignment OPTIONAL,
IN ULONG ProtectionType
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuKrnl (0x%X): MmAllocateContiguousMemoryEx\n"
"(\n"
" NumberOfBytes : 0x%.08X\n"
" LowestAcceptableAddress : 0x%.08X\n"
" HighestAcceptableAddress : 0x%.08X\n"
" Alignment : 0x%.08X\n"
" ProtectionType : 0x%.08X\n"
");\n",
GetCurrentThreadId(), NumberOfBytes, LowestAcceptableAddress, HighestAcceptableAddress,
Alignment, ProtectionType);
}
#endif
// TODO: Make this much more efficient and correct if necessary!
// HACK: Should be aligned!!
PVOID pRet = (PVOID)new unsigned char[NumberOfBytes];
EmuSwapFS(); // Xbox FS
return pRet;
}
// ******************************************************************
// * 0x00AB - MmFreeContiguousMemory
// ******************************************************************
XBSYSAPI EXPORTNUM(171) VOID NTAPI xboxkrnl::MmFreeContiguousMemory
(
IN PVOID BaseAddress
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuKrnl (0x%X): MmFreeContiguousMemory\n"
"(\n"
" BaseAddress : 0x%.08X\n"
");\n",
GetCurrentThreadId(), BaseAddress);
}
#endif
delete BaseAddress;
EmuSwapFS(); // Xbox FS
return;
}
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * 0x00B8 - NtAllocateVirtualMemory
// ******************************************************************
XBSYSAPI EXPORTNUM(184) NTSTATUS xboxkrnl::NtAllocateVirtualMemory
(
IN OUT PVOID *BaseAddress,
IN ULONG ZeroBits,
2003-04-05 09:03:02 +00:00
IN OUT PULONG AllocationSize,
2003-02-06 08:55:36 +00:00
IN DWORD AllocationType,
IN DWORD Protect
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-06 08:55:36 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): NtAllocateVirtualMemory\n"
2003-02-09 08:35:33 +00:00
"(\n"
2003-05-22 00:27:09 +00:00
" BaseAddress : 0x%.08X (0x%.08X)\n"
2003-02-09 08:35:33 +00:00
" ZeroBits : 0x%.08X\n"
2003-05-22 00:27:09 +00:00
" AllocationSize : 0x%.08X (0x%.08X)\n"
2003-02-09 08:35:33 +00:00
" AllocationType : 0x%.08X\n"
" Protect : 0x%.08X\n"
");\n",
2003-05-22 00:27:09 +00:00
GetCurrentThreadId(), BaseAddress, *BaseAddress, ZeroBits, AllocationSize, *AllocationSize, AllocationType, Protect);
2003-02-06 08:55:36 +00:00
}
#endif
2003-06-20 18:03:21 +00:00
// TODO: HACK: WARNING: Temporary!
if(*AllocationSize == (ULONG)0x01800000)
__asm int 3
2003-04-05 09:03:02 +00:00
NTSTATUS ret = NT_NtAllocateVirtualMemory(GetCurrentProcess(), BaseAddress, ZeroBits, AllocationSize, AllocationType, Protect);
2003-02-06 08:55:36 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-06 08:55:36 +00:00
2003-04-05 09:03:02 +00:00
return ret;
2003-02-06 08:55:36 +00:00
}
2003-01-26 06:18:56 +00:00
// ******************************************************************
// * 0x00BB - NtClose
// ******************************************************************
XBSYSAPI EXPORTNUM(187) NTSTATUS NTAPI xboxkrnl::NtClose
(
2003-05-23 02:55:39 +00:00
IN HANDLE Handle
2003-01-26 06:18:56 +00:00
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-01-31 18:10:38 +00:00
2003-01-27 09:18:33 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-01-27 09:18:33 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): NtClose\n"
2003-02-09 08:35:33 +00:00
"(\n"
" Handle : 0x%.08X\n"
");\n",
2003-01-27 09:18:33 +00:00
GetCurrentThreadId(), Handle);
}
#endif
2003-04-11 09:13:06 +00:00
NTSTATUS ret = STATUS_SUCCESS;
// ******************************************************************
// * delete 'special' handles
// ******************************************************************
if(IsEmuHandle(Handle))
{
EmuHandle *iEmuHandle = EmuHandleToPtr(Handle);
delete iEmuHandle;
ret = STATUS_SUCCESS;
}
// ******************************************************************
// * close normal handles
// ******************************************************************
else
{
ret = NT_NtClose(Handle);
}
2003-01-27 09:18:33 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-01-31 18:10:38 +00:00
2003-04-05 09:03:02 +00:00
return ret;
2003-01-26 06:18:56 +00:00
}
2003-06-07 03:06:59 +00:00
// ******************************************************************
// * 0x00BD - NtCreateEvent
// ******************************************************************
XBSYSAPI EXPORTNUM(189) NTSTATUS NTAPI xboxkrnl::NtCreateEvent
(
OUT PHANDLE EventHandle,
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
IN EVENT_TYPE EventType,
IN BOOLEAN InitialState
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuKrnl (0x%X): NtCreateEvent\n"
"(\n"
" EventHandle : 0x%.08X\n"
" ObjectAttributes : 0x%.08X (\"%s\")\n"
" EventType : 0x%.08X\n"
" InitialState : 0x%.08X\n"
");\n",
GetCurrentThreadId(), EventHandle, ObjectAttributes, ObjectAttributes->ObjectName->Buffer,
EventType, InitialState);
}
#endif
char *szBuffer = ObjectAttributes->ObjectName->Buffer;
wchar_t wszObjectName[160];
xntdll::UNICODE_STRING NtUnicodeString;
xntdll::OBJECT_ATTRIBUTES NtObjAttr;
// ******************************************************************
// * Initialize Object Attributes
// ******************************************************************
{
mbstowcs(wszObjectName, szBuffer, 160);
NT_RtlInitUnicodeString(&NtUnicodeString, wszObjectName);
InitializeObjectAttributes(&NtObjAttr, &NtUnicodeString, ObjectAttributes->Attributes, ObjectAttributes->RootDirectory, NULL);
}
// ******************************************************************
// * Redirect to NtCreateEvent
// ******************************************************************
NTSTATUS ret = NT_NtCreateEvent(EventHandle, EVENT_ALL_ACCESS, &NtObjAttr, (xntdll::EVENT_TYPE)EventType, InitialState);
EmuSwapFS(); // Xbox FS
return STATUS_SUCCESS;
}
2003-04-11 09:13:06 +00:00
// ******************************************************************
// * 0x00BE - NtCreateFile
// ******************************************************************
XBSYSAPI EXPORTNUM(190) NTSTATUS NTAPI xboxkrnl::NtCreateFile
(
2003-05-23 02:55:39 +00:00
OUT PHANDLE FileHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN PLARGE_INTEGER AllocationSize OPTIONAL,
IN ULONG FileAttributes,
IN ULONG ShareAccess,
IN ULONG CreateDisposition,
IN ULONG CreateOptions
2003-04-11 09:13:06 +00:00
)
{
2003-05-23 02:55:39 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-04-11 09:13:06 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): NtCreateFile\n"
"(\n"
" FileHandle : 0x%.08X\n"
" DesiredAccess : 0x%.08X\n"
" ObjectAttributes : 0x%.08X (\"%s\")\n"
" IoStatusBlock : 0x%.08X\n"
" AllocationSize : 0x%.08X\n"
" FileAttributes : 0x%.08X\n"
" ShareAccess : 0x%.08X\n"
" CreateDisposition : 0x%.08X\n"
" CreateOptions : 0x%.08X\n"
");\n",
GetCurrentThreadId(), FileHandle, DesiredAccess, ObjectAttributes, ObjectAttributes->ObjectName->Buffer,
IoStatusBlock, AllocationSize, FileAttributes, ShareAccess, CreateDisposition, CreateOptions);
2003-04-11 09:13:06 +00:00
}
#endif
2003-05-28 22:54:38 +00:00
char *szBuffer = ObjectAttributes->ObjectName->Buffer;
2003-05-23 22:04:21 +00:00
// ******************************************************************
2003-05-28 22:54:38 +00:00
// * D:\ should map to current directory
2003-05-23 22:04:21 +00:00
// ******************************************************************
2003-05-28 22:54:38 +00:00
if( (szBuffer[0] == 'D' || szBuffer[0] == 'd') && szBuffer[1] == ':' && szBuffer[2] == '\\')
{
szBuffer += 3;
2003-05-23 22:04:21 +00:00
2003-05-28 22:54:38 +00:00
ObjectAttributes->RootDirectory = g_hCurDir;
2003-05-23 22:04:21 +00:00
2003-05-28 22:54:38 +00:00
#ifdef _DEBUG_TRACE
printf("EmuKrnl (0x%X): NtCreateFile Corrected path...\n", GetCurrentThreadId());
printf(" Org:\"%s\"\n", ObjectAttributes->ObjectName->Buffer);
printf(" New:\"%s\"\n", szBuffer);
#endif
}
2003-05-23 02:55:39 +00:00
2003-05-28 22:54:38 +00:00
wchar_t wszObjectName[160];
2003-05-23 02:55:39 +00:00
2003-05-28 22:54:38 +00:00
xntdll::UNICODE_STRING NtUnicodeString;
xntdll::OBJECT_ATTRIBUTES NtObjAttr;
2003-05-23 02:55:39 +00:00
2003-05-23 22:04:21 +00:00
// ******************************************************************
2003-05-28 22:54:38 +00:00
// * Initialize Object Attributes
2003-05-23 22:04:21 +00:00
// ******************************************************************
2003-05-28 22:54:38 +00:00
{
mbstowcs(wszObjectName, szBuffer, 160);
2003-05-23 02:55:39 +00:00
2003-05-28 22:54:38 +00:00
NT_RtlInitUnicodeString(&NtUnicodeString, wszObjectName);
2003-05-23 02:55:39 +00:00
2003-05-28 22:54:38 +00:00
InitializeObjectAttributes(&NtObjAttr, &NtUnicodeString, ObjectAttributes->Attributes, ObjectAttributes->RootDirectory, NULL);
}
2003-05-23 02:55:39 +00:00
2003-05-23 22:04:21 +00:00
// ******************************************************************
2003-05-28 22:54:38 +00:00
// * Redirect to NtCreateFile
2003-05-23 22:04:21 +00:00
// ******************************************************************
2003-05-28 22:54:38 +00:00
NTSTATUS ret = NT_NtCreateFile
(
FileHandle, DesiredAccess, &NtObjAttr, (xntdll::IO_STATUS_BLOCK*)IoStatusBlock,
(xntdll::LARGE_INTEGER*)AllocationSize, FileAttributes, ShareAccess, CreateDisposition, CreateOptions, NULL, NULL
);
2003-05-23 02:55:39 +00:00
2003-05-28 22:54:38 +00:00
// NOTE: We can map this to IoCreateFile once implemented (if ever necessary)
// xboxkrnl::IoCreateFile(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, AllocationSize, FileAttributes, ShareAccess, CreateDisposition, CreateOptions, 0);
2003-05-23 02:55:39 +00:00
EmuSwapFS(); // Xbox FS
2003-04-11 09:13:06 +00:00
return STATUS_SUCCESS;
}
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * 0x00CA - NtOpenFile
// ******************************************************************
XBSYSAPI EXPORTNUM(202) NTSTATUS xboxkrnl::NtOpenFile
(
OUT PHANDLE FileHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN ULONG ShareAccess,
IN ULONG OpenOptions
)
{
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-06 08:55:36 +00:00
{
2003-04-06 20:07:36 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-06-07 03:06:59 +00:00
printf("EmuKrnl (0x%X): NtOpenFile\n"
"(\n"
" FileHandle : 0x%.08X\n"
" DesiredAccess : 0x%.08X\n"
" ObjectAttributes : 0x%.08X (\"%s\")\n"
" IoStatusBlock : 0x%.08X\n"
" ShareAccess : 0x%.08X\n"
" CreateOptions : 0x%.08X\n"
");\n",
GetCurrentThreadId(), FileHandle, DesiredAccess, ObjectAttributes, ObjectAttributes->ObjectName->Buffer,
IoStatusBlock, ShareAccess, OpenOptions);
2003-04-06 20:07:36 +00:00
EmuSwapFS(); // Xbox FS
2003-02-06 08:55:36 +00:00
}
#endif
2003-06-07 03:06:59 +00:00
return NtCreateFile(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, NULL, 0, ShareAccess, FILE_OPEN, OpenOptions);
2003-02-06 08:55:36 +00:00
}
2003-05-28 22:54:38 +00:00
// ******************************************************************
// * 0x00D3 - NtQueryInformationFile
// ******************************************************************
XBSYSAPI EXPORTNUM(211) NTSTATUS NTAPI xboxkrnl::NtQueryInformationFile
(
2003-06-07 03:06:59 +00:00
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PFILE_FS_SIZE_INFORMATION FileInformation,
IN ULONG Length,
IN FILE_INFORMATION_CLASS FileInfo
2003-05-28 22:54:38 +00:00
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuKrnl (0x%X): NtQueryInformationFile\n"
"(\n"
" FileHandle : 0x%.08X\n"
" IoStatusBlock : 0x%.08X\n"
" FileInformation : 0x%.08X\n"
" Length : 0x%.08X\n"
" FileInformationClass: 0x%.08X\n"
");\n",
GetCurrentThreadId(), FileHandle, IoStatusBlock, FileInformation,
Length, FileInfo);
}
#endif
2003-05-29 03:17:15 +00:00
NTSTATUS ret = NT_NtQueryInformationFile
(
FileHandle,
(xntdll::PIO_STATUS_BLOCK)IoStatusBlock,
2003-06-07 03:06:59 +00:00
(xntdll::PFILE_FS_SIZE_INFORMATION)FileInformation,
2003-05-29 03:17:15 +00:00
Length,
(xntdll::FILE_INFORMATION_CLASS)FileInfo
);
2003-05-28 22:54:38 +00:00
EmuSwapFS(); // Xbox FS
2003-05-29 03:17:15 +00:00
return ret;
2003-05-28 22:54:38 +00:00
}
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * 0x00DA - NtQueryVolumeInformationFile
// ******************************************************************
XBSYSAPI EXPORTNUM(218) NTSTATUS NTAPI xboxkrnl::NtQueryVolumeInformationFile
(
2003-06-07 03:06:59 +00:00
IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PFILE_FS_SIZE_INFORMATION FileInformation,
IN ULONG Length,
IN FS_INFORMATION_CLASS FileInformationClass
2003-02-06 08:55:36 +00:00
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-06 08:55:36 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): NtQueryVolumeInformationFile\n"
2003-02-09 08:35:33 +00:00
"(\n"
" FileHandle : 0x%.08X\n"
" IoStatusBlock : 0x%.08X\n"
" FileInformation : 0x%.08X\n"
" Length : 0x%.08X\n"
" FileInformationClass: 0x%.08X\n"
");\n",
2003-02-06 08:55:36 +00:00
GetCurrentThreadId(), FileHandle, IoStatusBlock, FileInformation,
Length, FileInformationClass);
}
#endif
2003-06-07 03:06:59 +00:00
if(FileInformationClass != FileFsSizeInformation)
EmuCleanup("NtQueryVolumeInformationFile: Unsupported FileInformationClass");
2003-04-12 11:21:35 +00:00
2003-06-07 03:06:59 +00:00
NTSTATUS ret = NT_NtQueryVolumeInformationFile
(
FileHandle,
(xntdll::PIO_STATUS_BLOCK)IoStatusBlock,
(xntdll::PFILE_FS_SIZE_INFORMATION)FileInformation, Length,
(xntdll::FS_INFORMATION_CLASS)FileInformationClass
);
/*
2003-04-11 09:13:06 +00:00
{
2003-06-07 03:06:59 +00:00
FILE_FS_SIZE_INFORMATION *SizeInfo = (FILE_FS_SIZE_INFORMATION*)FileInformation;
2003-04-11 09:13:06 +00:00
2003-06-07 03:06:59 +00:00
SizeInfo->TotalAllocationUnits.QuadPart = 0x4C468;
SizeInfo->AvailableAllocationUnits.QuadPart = 0x2F125;
SizeInfo->SectorsPerAllocationUnit = 32;
SizeInfo->BytesPerSector = 512;
2003-04-11 09:13:06 +00:00
}
2003-06-07 03:06:59 +00:00
*/
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-06 08:55:36 +00:00
2003-06-07 03:06:59 +00:00
return ret;
2003-02-06 08:55:36 +00:00
}
2003-06-04 02:18:40 +00:00
// ******************************************************************
// * 0x00DA - NtReadFile
// ******************************************************************
XBSYSAPI EXPORTNUM(219) NTSTATUS NTAPI xboxkrnl::NtReadFile
(
IN HANDLE FileHandle, // TODO: correct paramters
IN HANDLE Event OPTIONAL,
IN PVOID ApcRoutine OPTIONAL,
IN PVOID ApcContext,
OUT PVOID IoStatusBlock,
OUT PVOID Buffer,
IN ULONG Length,
IN PLARGE_INTEGER ByteOffset OPTIONAL
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuKrnl (0x%X): NtReadFile\n"
"(\n"
" FileHandle : 0x%.08X\n"
" Event : 0x%.08X\n"
" ApcRoutine : 0x%.08X\n"
" ApcContext : 0x%.08X\n"
" IoStatusBlock : 0x%.08X\n"
" Buffer : 0x%.08X\n"
" Length : 0x%.08X\n"
" ByteOffset : 0x%.08X\n"
");\n",
GetCurrentThreadId(), FileHandle, Event, ApcRoutine,
ApcContext, IoStatusBlock, Buffer, Length, ByteOffset);
}
#endif
NTSTATUS ret = NT_NtReadFile(FileHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, Buffer, Length, (xntdll::LARGE_INTEGER*)ByteOffset, 0);
EmuSwapFS(); // Xbox FS
return ret;
}
2003-06-12 02:05:10 +00:00
// ******************************************************************
// * 0x00E2 - NtSetInformationFile
// ******************************************************************
XBSYSAPI EXPORTNUM(226) NTSTATUS NTAPI xboxkrnl::NtSetInformationFile
(
IN HANDLE FileHandle, // TODO: correct paramters
OUT PVOID IoStatusBlock,
IN PVOID FileInformation,
IN ULONG Length,
IN ULONG FileInformationClass
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuKrnl (0x%X): NtSetInformationFile\n"
"(\n"
" FileHandle : 0x%.08X\n"
" IoStatusBlock : 0x%.08X\n"
" FileInformation : 0x%.08X\n"
" Length : 0x%.08X\n"
" FileInformationClass : 0x%.08X\n"
");\n",
GetCurrentThreadId(), FileHandle, IoStatusBlock, FileInformation,
Length, FileInformationClass);
}
#endif
NTSTATUS ret = NT_NtSetInformationFile(FileHandle, IoStatusBlock, FileInformation, Length, FileInformationClass);
2003-06-13 00:37:41 +00:00
EmuSwapFS(); // Xbox FS
2003-06-12 02:05:10 +00:00
return ret;
}
2003-06-06 04:53:27 +00:00
// ******************************************************************
// * 0x00DA - NtWriteFile
// ******************************************************************
XBSYSAPI EXPORTNUM(236) NTSTATUS NTAPI xboxkrnl::NtWriteFile
(
IN HANDLE FileHandle, // TODO: correct paramters
IN PVOID Event,
IN PVOID ApcRoutine,
IN PVOID ApcContext,
OUT PVOID IoStatusBlock,
IN PVOID Buffer,
IN ULONG Length,
IN PVOID ByteOffset
)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
printf("EmuKrnl (0x%X): NtWriteFile\n"
"(\n"
" FileHandle : 0x%.08X\n"
" Event : 0x%.08X\n"
" ApcRoutine : 0x%.08X\n"
" ApcContext : 0x%.08X\n"
" IoStatusBlock : 0x%.08X\n"
" Buffer : 0x%.08X\n"
" Length : 0x%.08X\n"
" ByteOffset : 0x%.08X\n"
");\n",
GetCurrentThreadId(), FileHandle, Event, ApcRoutine,
ApcContext, IoStatusBlock, Buffer, Length, ByteOffset);
}
#endif
NTSTATUS ret = NT_NtWriteFile(FileHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, Buffer, Length, (xntdll::LARGE_INTEGER*)ByteOffset, 0);
EmuSwapFS(); // Xbox FS
return ret;
}
2003-01-26 06:18:56 +00:00
// ******************************************************************
// * 0x00FF - PsCreateSystemThreadEx
// ******************************************************************
XBSYSAPI EXPORTNUM(255) NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadEx
(
OUT PHANDLE ThreadHandle,
IN ULONG ThreadExtraSize,
IN ULONG KernelStackSize,
IN ULONG TlsDataSize,
OUT PULONG ThreadId OPTIONAL,
IN PVOID StartContext1,
IN PVOID StartContext2,
IN BOOLEAN CreateSuspended,
IN BOOLEAN DebugStack,
IN PKSTART_ROUTINE StartRoutine
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-01-31 18:10:38 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): PsCreateSystemThreadEx\n"
2003-02-09 08:35:33 +00:00
"(\n"
" ThreadHandle : 0x%.08X\n"
" ThreadExtraSize : 0x%.08X\n"
" KernelStackSize : 0x%.08X\n"
" TlsDataSize : 0x%.08X\n"
" ThreadId : 0x%.08X\n"
" StartContext1 : 0x%.08X\n"
" StartContext2 : 0x%.08X\n"
" CreateSuspended : 0x%.08X\n"
" DebugStack : 0x%.08X\n"
" StartRoutine : 0x%.08X\n"
");\n",
2003-01-27 09:18:33 +00:00
GetCurrentThreadId(), ThreadHandle, ThreadExtraSize, KernelStackSize, TlsDataSize, ThreadId,
StartContext1, StartContext2, CreateSuspended, DebugStack, StartRoutine);
}
#endif
2003-04-05 09:03:02 +00:00
// ******************************************************************
// * create thread, using our special proxy technique
// ******************************************************************
{
DWORD dwThreadId;
2003-01-27 09:18:33 +00:00
2003-04-05 09:03:02 +00:00
// PCSTProxy is responsible for cleaning up this pointer
::PCSTProxyParam *iPCSTProxyParam = new ::PCSTProxyParam();
2003-01-27 09:18:33 +00:00
2003-04-05 09:03:02 +00:00
iPCSTProxyParam->StartContext1 = StartContext1;
iPCSTProxyParam->StartContext2 = StartContext2;
iPCSTProxyParam->StartRoutine = StartRoutine;
2003-01-27 09:18:33 +00:00
2003-04-25 16:55:24 +00:00
*ThreadHandle = CreateThread(NULL, NULL, &PCSTProxy, iPCSTProxyParam, CreateSuspended ? CREATE_SUSPENDED : NULL, &dwThreadId);
2003-01-27 09:18:33 +00:00
2003-04-05 09:03:02 +00:00
if(ThreadId != NULL)
*ThreadId = dwThreadId;
}
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-01-31 18:10:38 +00:00
2003-01-26 06:18:56 +00:00
return STATUS_SUCCESS;
}
2003-04-29 03:30:58 +00:00
// ******************************************************************
// * PsTerminateSystemThread
// ******************************************************************
XBSYSAPI EXPORTNUM(258) VOID NTAPI xboxkrnl::PsTerminateSystemThread(IN NTSTATUS ExitStatus)
{
EmuSwapFS(); // Win2k/XP FS
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): PsTerminateSystemThread\n"
2003-04-29 03:30:58 +00:00
"(\n"
" ExitStatus : 0x%.08X\n"
");\n",
GetCurrentThreadId(), ExitStatus);
}
#endif
ExitThread(ExitStatus);
EmuSwapFS(); // Xbox FS
return;
}
2003-01-26 06:18:56 +00:00
// ******************************************************************
2003-01-31 22:15:41 +00:00
// * 0x0115 RtlEnterCriticalSection
2003-01-26 06:18:56 +00:00
// ******************************************************************
2003-02-01 08:49:41 +00:00
XBSYSAPI EXPORTNUM(277) VOID NTAPI xboxkrnl::RtlEnterCriticalSection
(
IN PRTL_CRITICAL_SECTION CriticalSection
)
2003-01-26 06:18:56 +00:00
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-01-31 18:10:38 +00:00
2003-01-31 22:15:41 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-01-31 22:15:41 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): RtlEnterCriticalSection\n"
2003-02-09 08:35:33 +00:00
"(\n"
" CriticalSection : 0x%.08X\n"
");\n",
2003-02-01 08:49:41 +00:00
GetCurrentThreadId(), CriticalSection);
2003-01-31 22:15:41 +00:00
}
#endif
2003-01-26 06:18:56 +00:00
2003-04-05 09:03:02 +00:00
// This seems redundant, but xbox software doesn't always do it
2003-06-12 02:05:10 +00:00
if(CriticalSection->LockCount == -1)
NT_RtlInitializeCriticalSection((xntdll::_RTL_CRITICAL_SECTION*)CriticalSection);
2003-02-01 08:49:41 +00:00
2003-04-05 09:03:02 +00:00
NT_RtlEnterCriticalSection((xntdll::_RTL_CRITICAL_SECTION*)CriticalSection);
2003-02-01 08:49:41 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-04-05 09:03:02 +00:00
return;
2003-01-31 22:15:41 +00:00
}
2003-01-31 18:10:38 +00:00
2003-03-27 03:52:19 +00:00
// ******************************************************************
// * 0x0121 - RtlInitAnsiString
// ******************************************************************
XBSYSAPI EXPORTNUM(289) VOID NTAPI xboxkrnl::RtlInitAnsiString
(
IN OUT PANSI_STRING DestinationString,
IN PCSZ SourceString
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-03-27 03:52:19 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
#ifdef _DEBUG_TRACE
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): RtlInitAnsiString\n"
2003-03-27 03:52:19 +00:00
"(\n"
" DestinationString : 0x%.08X\n"
" SourceString : 0x%.08X (\"%s\")\n"
");\n",
GetCurrentThreadId(), DestinationString, SourceString, SourceString);
}
#endif
NT_RtlInitAnsiString((xntdll::PANSI_STRING)DestinationString, (xntdll::PCSZ)SourceString);
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-03-27 03:52:19 +00:00
return;
}
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * 0x0123 - RtlInitializeCriticalSection
// ******************************************************************
XBSYSAPI EXPORTNUM(291) VOID NTAPI xboxkrnl::RtlInitializeCriticalSection
(
IN PRTL_CRITICAL_SECTION CriticalSection
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-06 08:55:36 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-06 08:55:36 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): RtlInitializeCriticalSection\n"
2003-02-09 08:35:33 +00:00
"(\n"
" CriticalSection : 0x%.08X\n"
");\n",
2003-02-06 08:55:36 +00:00
GetCurrentThreadId(), CriticalSection);
}
#endif
2003-04-05 09:03:02 +00:00
NT_RtlInitializeCriticalSection((xntdll::_RTL_CRITICAL_SECTION*)CriticalSection);
2003-02-06 08:55:36 +00:00
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-06 08:55:36 +00:00
return;
}
2003-01-31 22:15:41 +00:00
// ******************************************************************
// * 0x0126 RtlEnterCriticalSection
// ******************************************************************
2003-02-01 08:49:41 +00:00
XBSYSAPI EXPORTNUM(294) VOID NTAPI xboxkrnl::RtlLeaveCriticalSection
(
IN PRTL_CRITICAL_SECTION CriticalSection
)
2003-01-31 22:15:41 +00:00
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-01-31 22:15:41 +00:00
2003-04-05 09:03:02 +00:00
// Note: We need to execute this before debug output to avoid trouble
NT_RtlLeaveCriticalSection((xntdll::_RTL_CRITICAL_SECTION*)CriticalSection);
2003-01-31 22:15:41 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-01-31 22:15:41 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): RtlLeaveCriticalSection\n"
2003-02-09 08:35:33 +00:00
"(\n"
" CriticalSection : 0x%.08X\n"
");\n",
2003-02-01 08:49:41 +00:00
GetCurrentThreadId(), CriticalSection);
2003-01-31 22:15:41 +00:00
}
#endif
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-04-05 09:03:02 +00:00
return;
2003-02-03 23:36:24 +00:00
}
// ******************************************************************
// * 0x012D - RtlNtStatusToDosError
// ******************************************************************
XBSYSAPI EXPORTNUM(301) xboxkrnl::ULONG NTAPI xboxkrnl::RtlNtStatusToDosError
(
2003-05-23 02:55:39 +00:00
IN NTSTATUS Status
2003-02-03 23:36:24 +00:00
)
{
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Win2k/XP FS
2003-02-03 23:36:24 +00:00
// ******************************************************************
// * debug trace
// ******************************************************************
2003-02-06 22:33:57 +00:00
#ifdef _DEBUG_TRACE
2003-02-03 23:36:24 +00:00
{
2003-05-23 02:55:39 +00:00
printf("EmuKrnl (0x%X): RtlNtStatusToDosError\n"
2003-02-09 08:35:33 +00:00
"(\n"
" Status : 0x%.08X\n"
");\n",
2003-02-03 23:36:24 +00:00
GetCurrentThreadId(), Status);
}
#endif
2003-02-01 08:49:41 +00:00
2003-04-05 09:03:02 +00:00
ULONG ret = NT_RtlNtStatusToDosError(Status);
2003-03-27 06:23:58 +00:00
EmuSwapFS(); // Xbox FS
2003-02-03 23:36:24 +00:00
2003-04-05 09:03:02 +00:00
return ret;
2003-04-11 09:13:06 +00:00
}
// ******************************************************************
// * 0x0141 - XboxHardwareInfo
// ******************************************************************
XBSYSAPI EXPORTNUM(322) XBOX_HARDWARE_INFO xboxkrnl::XboxHardwareInfo =
{
0xC0000035,
0,0,0,0
};