Merge pull request #921 from PatrickvL/kernel_rtl

Kernel Rtl
This commit is contained in:
Luke Usher 2018-02-17 11:59:55 +00:00 committed by GitHub
commit 0382400ef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1001 additions and 243 deletions

View File

@ -219,6 +219,7 @@
<ClInclude Include="..\..\src\CxbxKrnl\EmuDSoundInline.hpp" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuFile.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuFS.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuKrnlKi.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuKrnlLogging.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuNtDll.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuSha.h" />
@ -494,6 +495,7 @@
<ClCompile Include="..\..\src\CxbxKrnl\EmuKrnlIo.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuKrnlKd.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuKrnlKe.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuKrnlKi.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuKrnlLogging.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuKrnlMm.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuKrnlNt.cpp" />

View File

@ -241,6 +241,9 @@
<ClCompile Include="..\..\src\devices\video\swizzle.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\EmuKrnlKi.cpp">
<Filter>Kernel</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\Cxbx\DlgControllerConfig.h">
@ -471,6 +474,9 @@
<ClInclude Include="..\..\src\devices\MCPXDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\EmuKrnlKi.h">
<Filter>Kernel</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\video\swizzle.h">
<Filter>Hardware</Filter>
</ClInclude>

View File

@ -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
);
// ******************************************************************

View File

@ -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!)

View File

@ -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 */

View File

@ -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"

View File

@ -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;

View File

@ -61,12 +61,6 @@ namespace xboxkrnl
#include <locale>
#include <codecvt>
// prevent name collisions
namespace NtDll
{
#include "EmuNtDll.h"
};
volatile DWORD HalInterruptRequestRegister = APC_LEVEL | DISPATCH_LEVEL;
HalSystemInterrupt HalSystemInterrupts[MAX_BUS_INTERRUPT_LEVEL + 1];

View File

@ -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 <chrono>
@ -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);

View File

@ -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 <caustik@caustik.com>
// * (c) 2016 Patrick van Logchem <pvanlogchem@gmail.com>
// *
// * All rights reserved
// *
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
#define LOG_PREFIX "KRNL"
// prevent name collisions
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h> // 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);
}

52
src/CxbxKrnl/EmuKrnlKi.h Normal file
View File

@ -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 <pvanlogchem@gmail.com>
// *
// * 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
);

View File

@ -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()

File diff suppressed because it is too large Load Diff

View File

@ -43,15 +43,6 @@
#include "Emu.h"
#include "EmuFS.h"
#include "Logging.h"
// ******************************************************************
// * prevent name collisions
// ******************************************************************
namespace NtDll
{
#include "EmuNtDll.h"
};
#include "EmuXTL.h"
#include "EmuD3D8Logging.h" // for log rendering of X_D3DFORMAT, etc.

View File

@ -40,15 +40,6 @@
#include "Emu.h"
#include "Logging.h"
#include "EmuFS.h"
// ******************************************************************
// * prevent name collisions
// ******************************************************************
namespace NtDll
{
#include "EmuNtDll.h"
};
#include "EmuXTL.h"
/*

View File

@ -64,14 +64,6 @@ bool g_bXInputOpenCalled = false;
XTL::PXPP_DEVICE_TYPE gDeviceType_Gamepad = nullptr;
// ******************************************************************
// * prevent name collisions
// ******************************************************************
namespace NtDll
{
#include "EmuNtDll.h"
};
#include "EmuXTL.h"