#include <ntdef.h>
#include <ntstatus.h>
-#ifdef __GNUC__
#include "intrin.h"
-#endif
#if !defined(_NTHAL_)
#define NTHALAPI DECLSPEC_IMPORT
ULONG Flags;
} ARBITER_INTERFACE, *PARBITER_INTERFACE;
+typedef enum _KPROFILE_SOURCE {
+ ProfileTime,
+ ProfileAlignmentFixup,
+ ProfileTotalIssues,
+ ProfilePipelineDry,
+ ProfileLoadInstructions,
+ ProfilePipelineFrozen,
+ ProfileBranchInstructions,
+ ProfileTotalNonissues,
+ ProfileDcacheMisses,
+ ProfileIcacheMisses,
+ ProfileCacheMisses,
+ ProfileBranchMispredictions,
+ ProfileStoreInstructions,
+ ProfileFpInstructions,
+ ProfileIntegerInstructions,
+ Profile2Issue,
+ Profile3Issue,
+ Profile4Issue,
+ ProfileSpecialInstructions,
+ ProfileTotalCycles,
+ ProfileIcacheIssues,
+ ProfileDcacheAccesses,
+ ProfileMemoryBarrierCycles,
+ ProfileLoadLinkedIssues,
+ ProfileMaximum
+} KPROFILE_SOURCE;
+
typedef enum _HAL_QUERY_INFORMATION_CLASS {
HalInstalledBusInformation,
HalProfileSourceInformation,
HalGenerateCmcInterrupt
} HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
+typedef struct _HAL_PROFILE_SOURCE_INTERVAL
+{
+ KPROFILE_SOURCE Source;
+ ULONG_PTR Interval;
+} HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
+
+typedef struct _HAL_PROFILE_SOURCE_INFORMATION
+{
+ KPROFILE_SOURCE Source;
+ BOOLEAN Supported;
+ ULONG Interval;
+} HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
+
typedef struct _MAP_REGISTER_ENTRY
{
PVOID MapRegister;
extern NTSYSAPI PHAL_DISPATCH HalDispatchTable;
#define HALDISPATCH ((PHAL_DISPATCH)&HalDispatchTable)
#else
-extern DECLSPEC_EXPORT HAL_DISPATCH HalDispatchTable;
+extern __declspec(dllexport) HAL_DISPATCH HalDispatchTable;
#define HALDISPATCH (&HalDispatchTable)
#endif
#define HalEndOfBoot HALDISPATCH->HalEndOfBoot
#define HalMirrorVerify HALDISPATCH->HalMirrorVerify
-#ifndef _NTOSKRNL_
-#define HalDeviceControl HALDISPATCH->HalDeviceControl
-#define HalIoAssignDriveLetters HALDISPATCH->HalIoAssignDriveLetters
-#define HalIoReadPartitionTable HALDISPATCH->HalIoReadPartitionTable
-#define HalIoSetPartitionInformation HALDISPATCH->HalIoSetPartitionInformation
-#define HalIoWritePartitionTable HALDISPATCH->HalIoWritePartitionTable
-#endif
-
typedef enum _FILE_INFORMATION_CLASS {
FileDirectoryInformation = 1,
FileFullDirectoryInformation,
(DDKAPI *PKINTERRUPT_ROUTINE)(
VOID);
-typedef enum _KPROFILE_SOURCE {
- ProfileTime,
- ProfileAlignmentFixup,
- ProfileTotalIssues,
- ProfilePipelineDry,
- ProfileLoadInstructions,
- ProfilePipelineFrozen,
- ProfileBranchInstructions,
- ProfileTotalNonissues,
- ProfileDcacheMisses,
- ProfileIcacheMisses,
- ProfileCacheMisses,
- ProfileBranchMispredictions,
- ProfileStoreInstructions,
- ProfileFpInstructions,
- ProfileIntegerInstructions,
- Profile2Issue,
- Profile3Issue,
- Profile4Issue,
- ProfileSpecialInstructions,
- ProfileTotalCycles,
- ProfileIcacheIssues,
- ProfileDcacheAccesses,
- ProfileMemoryBarrierCycles,
- ProfileLoadLinkedIssues,
- ProfileMaximum
-} KPROFILE_SOURCE;
-
typedef enum _CREATE_FILE_TYPE {
CreateFileTypeNone,
CreateFileTypeNamedPipe,
} PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
typedef ULONG_PTR
-(*PDRIVER_VERIFIER_THUNK_ROUTINE)(
+(NTAPI *PDRIVER_VERIFIER_THUNK_ROUTINE)(
IN PVOID Context);
typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
ULONG Spare1;
} KFLOATING_SAVE, *PKFLOATING_SAVE;
-#ifdef _MSC_VER
-//
-// FIXME: Intrinsics
-//
-unsigned char __readfsbyte(const unsigned long Offset);
-#pragma intrinsic(__readfsbyte)
-#endif
-
-
FORCEINLINE
ULONG
KeGetCurrentProcessorNumber(VOID)
USHORT SegFs;
USHORT SegGs;
USHORT SegSs;
- USHORT EFlags;
+ ULONG EFlags;
/* Debug */
ULONG64 Dr0;
IN ULONG Length
);
-#define PCI_DATA_TAG TAG('P', 'C', 'I', ' ')
+#define PCI_DATA_TAG ' ICP'
#define PCI_DATA_VERSION 1
typedef struct _PCIBUSDATA
#elif defined(_M_ARM) // !defined (_X86_)
+ FORCEINLINE
+ VOID
+ KeInitializeSpinLock(IN PKSPIN_LOCK SpinLock)
+ {
+ /* Clear the lock */
+ *SpinLock = 0;
+ }
+
NTHALAPI
KIRQL
FASTCALL
#define ROUND_TO_PAGES(Size) \
((ULONG_PTR) (((ULONG_PTR) Size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)))
+
+
+#if defined(_X86_) || defined(_AMD64_)
+
+//
+// x86 and x64 performs a 0x2C interrupt
+//
+#define DbgRaiseAssertionFailure __int2c
+
+#elif defined(_ARM_)
+
+//
+// TODO
+//
+
+#else
+#error Unsupported Architecture
+#endif
+
#if DBG
#define ASSERT(exp) \
(VOID)((!(exp)) ? \
- RtlAssert( #exp, __FILE__, __LINE__, NULL ), FALSE : TRUE)
+ RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ), FALSE : TRUE)
#define ASSERTMSG(msg, exp) \
(VOID)((!(exp)) ? \
- RtlAssert( #exp, __FILE__, __LINE__, msg ), FALSE : TRUE)
+ RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, msg ), FALSE : TRUE)
#define RTL_SOFT_ASSERT(exp) \
- (VOID)((!(_exp)) ? \
+ (VOID)((!(exp)) ? \
DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE)
#define RTL_SOFT_ASSERTMSG(msg, exp) \
#define RTL_SOFT_VERIFY(exp) RTL_SOFT_ASSERT(exp)
#define RTL_SOFT_VERIFYMSG(msg, exp) RTL_SOFT_ASSERTMSG(msg, exp)
+#if defined(_MSC_VER)
+
+#define NT_ASSERT(exp) \
+ ((!(exp)) ? \
+ (__annotation(L"Debug", L"AssertFail", L#exp), \
+ DbgRaiseAssertionFailure(), FALSE) : TRUE)
+
+#define NT_ASSERTMSG(msg, exp) \
+ ((!(exp)) ? \
+ (__annotation(L"Debug", L"AssertFail", L##msg), \
+ DbgRaiseAssertionFailure(), FALSE) : TRUE)
+
+#define NT_ASSERTMSGW(msg, exp) \
+ ((!(exp)) ? \
+ (__annotation(L"Debug", L"AssertFail", msg), \
+ DbgRaiseAssertionFailure(), FALSE) : TRUE)
+
+#else
+
+//
+// GCC doesn't support __annotation (nor PDB)
+//
+#define NT_ASSERT(exp) \
+ (VOID)((!(exp)) ? (DbgRaiseAssertionFailure(), FALSE) : TRUE)
+
+#define NT_ASSERTMSG NT_ASSERT
+#define NT_ASSERTMSGW NT_ASSERT
+
+#endif
+
#else /* !DBG */
#define ASSERT(exp) ((VOID) 0)
#define RTL_SOFT_VERIFY(exp) ((exp) ? TRUE : FALSE)
#define RTL_SOFT_VERIFYMSG(msg, exp) ((exp) ? TRUE : FALSE)
+#define NT_ASSERT(exp) ((VOID)0)
+#define NT_ASSERTMSG(exp) ((VOID)0)
+#define NT_ASSERTMSGW(exp) ((VOID)0)
+
#endif /* DBG */
/* HACK HACK HACK - GCC (or perhaps LD) is messing this up */
#define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
#define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
+NTKERNELAPI
+VOID
+NTAPI
+KeFlushQueuedDpcs(
+ VOID
+);
+
NTHALAPI
VOID
NTAPI
IN ULONG ProbeMode);
NTKERNELAPI
-ULONG
+SIZE_T
NTAPI
MmSizeOfMdl(
IN PVOID Base,
KdEnableDebugger(
VOID);
+NTKERNELAPI
+BOOLEAN
+NTAPI
+KdRefreshDebuggerNotPresent(
+ VOID
+);
+
#if (NTDDI_VERSION >= NTDDI_WS03SP1)
NTKERNELAPI
NTSTATUS
vDbgPrintEx(
IN ULONG ComponentId,
IN ULONG Level,
- IN LPCSTR Format,
+ IN PCCH Format,
IN va_list ap);
ULONG
NTAPI
vDbgPrintExWithPrefix(
- IN LPCSTR Prefix,
+ IN PCCH Prefix,
IN ULONG ComponentId,
IN ULONG Level,
- IN LPCSTR Format,
+ IN PCCH Format,
IN va_list ap);
NTKERNELAPI
ULONG
DDKCDECLAPI
DbgPrintReturnControlC(
- IN PCH Format,
+ IN PCCH Format,
IN ...);
+ULONG
+NTAPI
+DbgPrompt(
+ IN PCCH Prompt,
+ OUT PCH Response,
+ IN ULONG MaximumResponseLength
+);
+
NTKERNELAPI
-BOOLEAN
+NTSTATUS
NTAPI
DbgQueryDebugFilterState(
IN ULONG ComponentId,
#endif /* !DBG */
-#if defined(_NTDDK_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
+#if defined(__GNUC__)
+
+extern NTKERNELAPI BOOLEAN KdDebuggerNotPresent;
+extern NTKERNELAPI BOOLEAN KdDebuggerEnabled;
+#define KD_DEBUGGER_ENABLED KdDebuggerEnabled
+#define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
+
+#elif defined(_NTDDK_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
extern NTKERNELAPI PBOOLEAN KdDebuggerNotPresent;
extern NTKERNELAPI PBOOLEAN KdDebuggerEnabled;