diff --git a/build/win32/Cxbx.vcxproj b/build/win32/Cxbx.vcxproj
index b1aef1063..17eaefa50 100644
--- a/build/win32/Cxbx.vcxproj
+++ b/build/win32/Cxbx.vcxproj
@@ -219,6 +219,7 @@
+
@@ -494,6 +495,7 @@
+
diff --git a/build/win32/Cxbx.vcxproj.filters b/build/win32/Cxbx.vcxproj.filters
index 7a598415d..78b52d605 100644
--- a/build/win32/Cxbx.vcxproj.filters
+++ b/build/win32/Cxbx.vcxproj.filters
@@ -241,6 +241,9 @@
Hardware
+
+ Kernel
+
@@ -471,6 +474,9 @@
Hardware
+
+ Kernel
+
Hardware
diff --git a/import/OpenXDK/include/xboxkrnl/rtl.h b/import/OpenXDK/include/xboxkrnl/rtl.h
index b11c23d7e..231120107 100644
--- a/import/OpenXDK/include/xboxkrnl/rtl.h
+++ b/import/OpenXDK/include/xboxkrnl/rtl.h
@@ -74,7 +74,7 @@ XBSYSAPI EXPORTNUM(267) NTSTATUS NTAPI RtlCharToInteger
// * compare block of memory, return number of equivalent bytes.
// *
// ******************************************************************
-XBSYSAPI EXPORTNUM(268) BOOLEAN NTAPI RtlCompareMemory
+XBSYSAPI EXPORTNUM(268) SIZE_T NTAPI RtlCompareMemory
(
IN CONST VOID *Source1,
IN CONST VOID *Source2,
@@ -183,7 +183,7 @@ XBSYSAPI EXPORTNUM(279) BOOLEAN NTAPI RtlEqualString
(
IN PSTRING String1,
IN PSTRING String2,
- IN BOOLEAN CaseSensitive
+ IN BOOLEAN CaseInsensitive
);
// ******************************************************************
@@ -193,7 +193,7 @@ XBSYSAPI EXPORTNUM(280) BOOLEAN NTAPI RtlEqualUnicodeString
(
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2,
- IN BOOLEAN CaseSensitive
+ IN BOOLEAN CaseInSensitive
);
// ******************************************************************
@@ -279,7 +279,7 @@ XBSYSAPI EXPORTNUM(289) VOID NTAPI RtlInitAnsiString
XBSYSAPI EXPORTNUM(290) VOID NTAPI RtlInitUnicodeString
(
IN OUT PUNICODE_STRING DestinationString,
- IN PSTRING SourceString
+ IN PCWSTR SourceString
);
// ******************************************************************
diff --git a/import/OpenXDK/include/xboxkrnl/xboxkrnl.h b/import/OpenXDK/include/xboxkrnl/xboxkrnl.h
index e915b6555..ebb3be7a5 100644
--- a/import/OpenXDK/include/xboxkrnl/xboxkrnl.h
+++ b/import/OpenXDK/include/xboxkrnl/xboxkrnl.h
@@ -153,11 +153,14 @@ typedef long NTSTATUS;
#define STATUS_PENDING ((DWORD )0x00000103L)
#endif
#define STATUS_TIMER_RESUME_IGNORED ((DWORD )0x40000025L)
+#define STATUS_BUFFER_OVERFLOW ((DWORD )0x80000005L)
#define STATUS_UNSUCCESSFUL ((DWORD )0xC0000001)
#define STATUS_UNRECOGNIZED_MEDIA ((DWORD )0xC0000014)
#ifndef STATUS_NO_MEMORY
#define STATUS_NO_MEMORY ((DWORD )0xC0000017L)
#endif
+#define STATUS_BUFFER_TOO_SMALL ((DWORD )0xC0000023L)
+#define STATUS_INVALID_PARAMETER_2 ((DWORD )0xC00000F0L)
#define STATUS_ALERTED ((DWORD )0x00000101)
#define STATUS_USER_APC ((DWORD )0x000000C0L)
// The SCSI input buffer was too large (not necessarily an error!)
diff --git a/src/CxbxKrnl/CxbxKrnl.cpp b/src/CxbxKrnl/CxbxKrnl.cpp
index 2c1cda78f..782f2a229 100644
--- a/src/CxbxKrnl/CxbxKrnl.cpp
+++ b/src/CxbxKrnl/CxbxKrnl.cpp
@@ -68,12 +68,6 @@ namespace xboxkrnl
#include "devices\Xbox.h" // For InitXboxHardware()
#include "devices\LED.h" // For LED::Sequence
-/* prevent name collisions */
-namespace NtDll
-{
- #include "EmuNtDll.h"
-};
-
/*! thread local storage */
Xbe::TLS *CxbxKrnl_TLS = NULL;
/*! thread local storage data */
diff --git a/src/CxbxKrnl/Emu.cpp b/src/CxbxKrnl/Emu.cpp
index b19f619da..368208f4e 100644
--- a/src/CxbxKrnl/Emu.cpp
+++ b/src/CxbxKrnl/Emu.cpp
@@ -46,13 +46,6 @@ namespace xboxkrnl
#include "Emu.h"
#include "EmuX86.h"
#include "EmuFS.h"
-
-// prevent name collisions
-namespace NtDll
-{
- #include "EmuNtDll.h"
-};
-
#include "EmuXTL.h"
#include "EmuShared.h"
#include "HLEDataBase.h"
diff --git a/src/CxbxKrnl/EmuKrnl.cpp b/src/CxbxKrnl/EmuKrnl.cpp
index 03b275f9a..5d867233f 100644
--- a/src/CxbxKrnl/EmuKrnl.cpp
+++ b/src/CxbxKrnl/EmuKrnl.cpp
@@ -51,6 +51,7 @@ namespace xboxkrnl
#include "Logging.h"
#include "EmuKrnlLogging.h"
#include "EmuKrnl.h" // for HalSystemInterrupts
+#include "EmuKrnlKi.h" // for KiLockDispatcherDatabase
#include "CxbxKrnl.h"
#include "EmuXTL.h"
@@ -132,23 +133,6 @@ xboxkrnl::PLIST_ENTRY RemoveTailList(xboxkrnl::PLIST_ENTRY pListHead)
// ******************************************************************
xboxkrnl::KPCR* KeGetPcr();
-// ******************************************************************
-// * KiLockDispatcherDatabase()
-// ******************************************************************
-// * Not exported in kernel thunk table
-// * NOTE: This is a macro on the Xbox, however we implement it
-// * as a function because a macro doesn't compile this: *(&OldIrql)
-// ******************************************************************
-void xboxkrnl::KiLockDispatcherDatabase
-(
- OUT KIRQL* OldIrql
-)
-{
- LOG_FUNC_ONE_ARG_OUT(OldIrql);
-
- *(OldIrql) = KeRaiseIrqlToDpcLevel();
-}
-
// Interrupts
extern volatile DWORD HalInterruptRequestRegister;
diff --git a/src/CxbxKrnl/EmuKrnlHal.cpp b/src/CxbxKrnl/EmuKrnlHal.cpp
index 26374a907..8dee26d7c 100644
--- a/src/CxbxKrnl/EmuKrnlHal.cpp
+++ b/src/CxbxKrnl/EmuKrnlHal.cpp
@@ -61,12 +61,6 @@ namespace xboxkrnl
#include
#include
-// prevent name collisions
-namespace NtDll
-{
-#include "EmuNtDll.h"
-};
-
volatile DWORD HalInterruptRequestRegister = APC_LEVEL | DISPATCH_LEVEL;
HalSystemInterrupt HalSystemInterrupts[MAX_BUS_INTERRUPT_LEVEL + 1];
diff --git a/src/CxbxKrnl/EmuKrnlKe.cpp b/src/CxbxKrnl/EmuKrnlKe.cpp
index 6c0226ecf..5b65c8257 100644
--- a/src/CxbxKrnl/EmuKrnlKe.cpp
+++ b/src/CxbxKrnl/EmuKrnlKe.cpp
@@ -56,6 +56,7 @@ namespace NtDll
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
#include "Emu.h" // For EmuWarning()
#include "EmuKrnl.h" // For InitializeListHead(), etc.
+#include "EmuKrnlKi.h" // For KiRemoveTreeTimer(), KiInsertTreeTimer()
#include "EmuFile.h" // For IsEmuHandle(), NtStatusToString()
#include
@@ -83,53 +84,6 @@ xboxkrnl::ULONGLONG LARGE_INTEGER2ULONGLONG(xboxkrnl::LARGE_INTEGER value)
return *((PULONGLONG)&value);
}
-// TODO : Move all Ki* functions to EmuKrnlKi.h/cpp :
-
-#define KiRemoveTreeTimer(Timer) \
- (Timer)->Header.Inserted = FALSE; \
- RemoveEntryList(&(Timer)->TimerListEntry)
-
-BOOLEAN KiInsertTimerTable(
- IN xboxkrnl::LARGE_INTEGER Interval,
- xboxkrnl::ULONGLONG,
- IN xboxkrnl::PKTIMER Timer
-)
-{
- // TODO
- return TRUE;
-}
-
-BOOLEAN KiInsertTreeTimer(
- IN xboxkrnl::PKTIMER Timer,
- IN xboxkrnl::LARGE_INTEGER Interval
-)
-{
- // Is the given time absolute (indicated by a positive number)?
- if (Interval.u.HighPart >= 0) {
- // Convert absolute time to a time relative to the system time :
- xboxkrnl::LARGE_INTEGER SystemTime;
- xboxkrnl::KeQuerySystemTime(&SystemTime);
- Interval.QuadPart = SystemTime.QuadPart - Interval.QuadPart;
- if (Interval.u.HighPart >= 0) {
- // If the relative time is already passed, return without inserting :
- Timer->Header.Inserted = FALSE;
- Timer->Header.SignalState = TRUE;
- return FALSE;
- }
-
- Timer->Header.Absolute = TRUE;
- }
- else
- // Negative intervals are relative, not absolute :
- Timer->Header.Absolute = FALSE;
-
- if (Timer->Period == 0)
- Timer->Header.SignalState = FALSE;
-
- Timer->Header.Inserted = TRUE;
- return KiInsertTimerTable(Interval, xboxkrnl::KeQueryInterruptTime(), Timer);
-}
-
// ******************************************************************
// * KeGetPcr()
// * NOTE: This is a macro on the Xbox, however we implement it
@@ -1525,7 +1479,7 @@ XBSYSAPI EXPORTNUM(144) xboxkrnl::ULONG NTAPI xboxkrnl::KeSetDisableBoostThread
KiLockDispatcherDatabase(&oldIRQL);
ULONG prevDisableBoost = Thread->DisableBoost;
- Thread->DisableBoost = Disable;
+ Thread->DisableBoost = (CHAR)Disable;
KiUnlockDispatcherDatabase(oldIRQL);
diff --git a/src/CxbxKrnl/EmuKrnlKi.cpp b/src/CxbxKrnl/EmuKrnlKi.cpp
new file mode 100644
index 000000000..11103eead
--- /dev/null
+++ b/src/CxbxKrnl/EmuKrnlKi.cpp
@@ -0,0 +1,91 @@
+// 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
+// ******************************************************************
+// *
+// * .,-::::: .,:: .::::::::. .,:: .:
+// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
+// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
+// * $$$ Y$$$P $$""""Y$$ Y$$$P
+// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
+// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
+// *
+// * Cxbx->src->CxbxKrnl->EmuKrnlKi.cpp
+// *
+// * 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
+// * (c) 2016 Patrick van Logchem
+// *
+// * All rights reserved
+// *
+// ******************************************************************
+#define _XBOXKRNL_DEFEXTRN_
+
+#define LOG_PREFIX "KRNL"
+
+// prevent name collisions
+namespace xboxkrnl
+{
+#include // For KeBugCheck, etc.
+};
+
+#include "Logging.h" // For LOG_FUNC()
+#include "EmuKrnlLogging.h"
+
+//#include "EmuKrnl.h" // For InitializeListHead(), etc.
+
+xboxkrnl::BOOLEAN KiInsertTimerTable(
+ IN xboxkrnl::LARGE_INTEGER Interval,
+ xboxkrnl::ULONGLONG,
+ IN xboxkrnl::PKTIMER Timer
+)
+{
+ // TODO
+ return TRUE;
+}
+
+xboxkrnl::BOOLEAN KiInsertTreeTimer(
+ IN xboxkrnl::PKTIMER Timer,
+ IN xboxkrnl::LARGE_INTEGER Interval
+)
+{
+ // Is the given time absolute (indicated by a positive number)?
+ if (Interval.u.HighPart >= 0) {
+ // Convert absolute time to a time relative to the system time :
+ xboxkrnl::LARGE_INTEGER SystemTime;
+ xboxkrnl::KeQuerySystemTime(&SystemTime);
+ Interval.QuadPart = SystemTime.QuadPart - Interval.QuadPart;
+ if (Interval.u.HighPart >= 0) {
+ // If the relative time is already passed, return without inserting :
+ Timer->Header.Inserted = FALSE;
+ Timer->Header.SignalState = TRUE;
+ return FALSE;
+ }
+
+ Timer->Header.Absolute = TRUE;
+ }
+ else
+ // Negative intervals are relative, not absolute :
+ Timer->Header.Absolute = FALSE;
+
+ if (Timer->Period == 0)
+ Timer->Header.SignalState = FALSE;
+
+ Timer->Header.Inserted = TRUE;
+ return KiInsertTimerTable(Interval, xboxkrnl::KeQueryInterruptTime(), Timer);
+}
diff --git a/src/CxbxKrnl/EmuKrnlKi.h b/src/CxbxKrnl/EmuKrnlKi.h
new file mode 100644
index 000000000..47e304dd8
--- /dev/null
+++ b/src/CxbxKrnl/EmuKrnlKi.h
@@ -0,0 +1,52 @@
+// ******************************************************************
+// *
+// * .,-::::: .,:: .::::::::. .,:: .:
+// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
+// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
+// * $$$ Y$$$P $$""""Y$$ Y$$$P
+// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
+// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
+// *
+// * Cxbx->src->CxbxKrnl->EmuKrnlKi.h
+// *
+// * 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) 2018 Patrick van Logchem
+// *
+// * All rights reserved
+// *
+// ******************************************************************
+#pragma once
+
+#define KiLockDispatcherDatabase(OldIrql) \
+ *(OldIrql) = KeRaiseIrqlToDpcLevel()
+
+#define KiLockApcQueue(Thread, OldIrql) \
+ *(OldIrql) = KeRaiseIrqlToSynchLevel()
+
+#define KiUnlockApcQueue(Thread, OldIrql) \
+ KfLowerIrql((OldIrql))
+
+#define KiRemoveTreeTimer(Timer) \
+ (Timer)->Header.Inserted = FALSE; \
+ RemoveEntryList(&(Timer)->TimerListEntry)
+
+xboxkrnl::BOOLEAN KiInsertTreeTimer(
+ IN xboxkrnl::PKTIMER Timer,
+ IN xboxkrnl::LARGE_INTEGER Interval
+);
\ No newline at end of file
diff --git a/src/CxbxKrnl/EmuKrnlOb.cpp b/src/CxbxKrnl/EmuKrnlOb.cpp
index 04bab0faa..18885e8e9 100644
--- a/src/CxbxKrnl/EmuKrnlOb.cpp
+++ b/src/CxbxKrnl/EmuKrnlOb.cpp
@@ -46,13 +46,6 @@ namespace xboxkrnl
#include "Logging.h" // For LOG_FUNC()
#include "EmuKrnlLogging.h"
-
-// prevent name collisions
-namespace NtDll
-{
-#include "EmuNtDll.h"
-};
-
#include "CxbxKrnl.h" // For CxbxKrnlCleanup
#include "Emu.h" // For EmuWarning()
#include "EmuKrnl.h" // For OBJECT_TO_OBJECT_HEADER()
diff --git a/src/CxbxKrnl/EmuKrnlRtl.cpp b/src/CxbxKrnl/EmuKrnlRtl.cpp
index e2ce7cc61..26a29d986 100644
--- a/src/CxbxKrnl/EmuKrnlRtl.cpp
+++ b/src/CxbxKrnl/EmuKrnlRtl.cpp
@@ -58,6 +58,11 @@ namespace NtDll
#ifdef _WIN32
+// Prevent errors compiling
+#undef RtlFillMemory
+#undef RtlMoveMemory
+#undef RtlZeroMemory
+
#include