2010-02-26 11:43:19 +00:00
|
|
|
#pragma once
|
2000-05-13 13:51:08 +00:00
|
|
|
|
2018-12-30 11:19:11 +00:00
|
|
|
#include <section_attribs.h>
|
1998-09-05 17:33:57 +00:00
|
|
|
|
2015-09-03 15:31:09 +00:00
|
|
|
|
|
|
|
|
2005-06-25 14:04:56 +00:00
|
|
|
#ifdef _NTOSKRNL_
|
|
|
|
|
2008-06-23 03:57:50 +00:00
|
|
|
#ifndef _ARM_
|
2006-10-23 22:07:45 +00:00
|
|
|
#define KeGetCurrentThread _KeGetCurrentThread
|
|
|
|
#define KeGetPreviousMode _KeGetPreviousMode
|
2008-06-23 03:57:50 +00:00
|
|
|
#endif
|
2006-10-23 22:07:45 +00:00
|
|
|
#undef PsGetCurrentProcess
|
|
|
|
#define PsGetCurrentProcess _PsGetCurrentProcess
|
2006-10-23 22:01:25 +00:00
|
|
|
|
2009-01-25 16:13:16 +00:00
|
|
|
#define RVA(m, b) ((PVOID)((ULONG_PTR)(b) + (ULONG_PTR)(m)))
|
|
|
|
|
2008-03-11 04:42:54 +00:00
|
|
|
//
|
|
|
|
// We are very lazy on ARM -- we just import intrinsics
|
|
|
|
// Question: Why wasn't this done for x86 too? (see fastintrlck.asm)
|
|
|
|
//
|
2008-08-06 10:52:33 +00:00
|
|
|
#define InterlockedDecrement _InterlockedDecrement
|
|
|
|
#define InterlockedDecrement16 _InterlockedDecrement16
|
|
|
|
#define InterlockedIncrement _InterlockedIncrement
|
|
|
|
#define InterlockedIncrement16 _InterlockedIncrement16
|
|
|
|
#define InterlockedCompareExchange _InterlockedCompareExchange
|
|
|
|
#define InterlockedCompareExchange16 _InterlockedCompareExchange16
|
|
|
|
#define InterlockedCompareExchange64 _InterlockedCompareExchange64
|
|
|
|
#define InterlockedExchange _InterlockedExchange
|
|
|
|
#define InterlockedExchangeAdd _InterlockedExchangeAdd
|
2008-08-14 19:30:32 +00:00
|
|
|
#define InterlockedOr _InterlockedOr
|
|
|
|
#define InterlockedAnd _InterlockedAnd
|
2008-03-11 04:42:54 +00:00
|
|
|
|
2009-01-30 16:45:17 +00:00
|
|
|
//
|
|
|
|
// Use inlined versions of fast/guarded mutex routines
|
|
|
|
//
|
|
|
|
#define ExEnterCriticalRegionAndAcquireFastMutexUnsafe _ExEnterCriticalRegionAndAcquireFastMutexUnsafe
|
|
|
|
#define ExReleaseFastMutexUnsafeAndLeaveCriticalRegion _ExReleaseFastMutexUnsafeAndLeaveCriticalRegion
|
|
|
|
#define ExAcquireFastMutex _ExAcquireFastMutex
|
|
|
|
#define ExReleaseFastMutex _ExReleaseFastMutex
|
|
|
|
#define ExAcquireFastMutexUnsafe _ExAcquireFastMutexUnsafe
|
|
|
|
#define ExReleaseFastMutexUnsafe _ExReleaseFastMutexUnsafe
|
|
|
|
#define ExTryToAcquireFastMutex _ExTryToAcquireFastMutex
|
|
|
|
|
|
|
|
#define KeInitializeGuardedMutex _KeInitializeGuardedMutex
|
|
|
|
#define KeAcquireGuardedMutex _KeAcquireGuardedMutex
|
|
|
|
#define KeReleaseGuardedMutex _KeReleaseGuardedMutex
|
|
|
|
#define KeAcquireGuardedMutexUnsafe _KeAcquireGuardedMutexUnsafe
|
|
|
|
#define KeReleaseGuardedMutexUnsafe _KeReleaseGuardedMutexUnsafe
|
|
|
|
#define KeTryToAcquireGuardedMutex _KeTryToAcquireGuardedMutex
|
|
|
|
|
2011-06-01 13:39:36 +00:00
|
|
|
#include "tag.h"
|
2005-06-25 14:04:56 +00:00
|
|
|
#include "ke.h"
|
|
|
|
#include "ob.h"
|
|
|
|
#include "mm.h"
|
2006-09-07 09:06:47 +00:00
|
|
|
#include "ex.h"
|
2007-12-15 18:14:41 +00:00
|
|
|
#include "cm.h"
|
2005-06-25 14:04:56 +00:00
|
|
|
#include "ps.h"
|
|
|
|
#include "cc.h"
|
|
|
|
#include "io.h"
|
|
|
|
#include "po.h"
|
|
|
|
#include "se.h"
|
|
|
|
#include "ldr.h"
|
2020-03-28 22:51:03 +00:00
|
|
|
#ifndef _WINKD_
|
|
|
|
#include "kd.h"
|
|
|
|
#endif
|
2007-03-04 19:54:39 +00:00
|
|
|
#include "kd64.h"
|
2005-09-14 01:44:19 +00:00
|
|
|
#include "fsrtl.h"
|
|
|
|
#include "lpc.h"
|
2005-09-14 01:05:50 +00:00
|
|
|
#include "rtl.h"
|
2005-06-25 14:04:56 +00:00
|
|
|
#include "dbgk.h"
|
2010-01-02 19:41:03 +00:00
|
|
|
#include "spinlock.h"
|
2005-06-25 14:04:56 +00:00
|
|
|
#include "test.h"
|
|
|
|
#include "inbv.h"
|
2006-08-28 23:56:35 +00:00
|
|
|
#include "vdm.h"
|
2006-11-12 22:51:06 +00:00
|
|
|
#include "hal.h"
|
2010-09-15 07:46:28 +00:00
|
|
|
#include "hdl.h"
|
2021-05-02 18:49:06 +00:00
|
|
|
#include "icif.h"
|
2008-02-12 04:15:53 +00:00
|
|
|
#include "arch/intrin_i.h"
|
2020-03-26 14:45:59 +00:00
|
|
|
#include <arbiter.h>
|
2005-06-25 14:04:56 +00:00
|
|
|
|
2005-08-22 13:38:30 +00:00
|
|
|
/*
|
2005-08-22 15:20:49 +00:00
|
|
|
* Use IsPointerOffset to test whether a pointer should be interpreted as an offset
|
|
|
|
* or as a pointer
|
2005-08-22 13:38:30 +00:00
|
|
|
*/
|
2008-02-07 06:40:42 +00:00
|
|
|
#if defined(_X86_) || defined(_M_AMD64) || defined(_MIPS_) || defined(_PPC_) || defined(_ARM_)
|
2005-08-22 13:38:30 +00:00
|
|
|
|
|
|
|
/* for x86 and x86-64 the MSB is 1 so we can simply test on that */
|
2005-08-22 15:20:49 +00:00
|
|
|
#define IsPointerOffset(Ptr) ((LONG_PTR)(Ptr) >= 0)
|
2005-08-22 13:38:30 +00:00
|
|
|
|
|
|
|
#elif defined(_IA64_)
|
|
|
|
|
|
|
|
/* on Itanium if the 24 most significant bits are set, we're not dealing with
|
2005-08-22 15:20:49 +00:00
|
|
|
offsets anymore. */
|
|
|
|
#define IsPointerOffset(Ptr) (((ULONG_PTR)(Ptr) & 0xFFFFFF0000000000ULL) == 0)
|
2005-08-22 13:38:30 +00:00
|
|
|
|
|
|
|
#else
|
2005-08-22 15:20:49 +00:00
|
|
|
#error IsPointerOffset() needs to be defined for this architecture
|
2005-08-22 13:38:30 +00:00
|
|
|
#endif
|
2005-08-21 15:14:36 +00:00
|
|
|
|
|
|
|
#endif
|
2000-05-13 13:51:08 +00:00
|
|
|
|
2019-01-05 09:50:11 +00:00
|
|
|
#ifndef _WIN64
|
2006-10-01 15:52:10 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300);
|
2012-04-01 13:37:20 +00:00
|
|
|
|
2006-10-01 15:52:10 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, InitialStack) == KTHREAD_INITIAL_STACK);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, KernelStack) == KTHREAD_KERNEL_STACK);
|
2012-04-01 14:15:00 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, SystemAffinityActive) == FIELD_OFFSET(KTHREAD, WaitBlock) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte));
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, ApcState.Process) == KTHREAD_APCSTATE_PROCESS);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, ApcQueueable) == FIELD_OFFSET(KTHREAD, ApcState.UserApcPending) + 1);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, ApcQueueable) == 0x3F);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, NextProcessor) == 0x40);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, DeferredProcessor) == 0x41);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, AdjustReason) == 0x42);
|
2006-10-01 15:52:10 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, NpxState) == KTHREAD_NPX_STATE);
|
2012-04-01 14:15:00 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, Alertable) == 0x58);
|
2012-04-01 13:37:20 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, SwapBusy) == 0x05D);
|
2012-04-01 14:15:00 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, Teb) == KTHREAD_TEB);
|
2012-04-01 13:37:20 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, Timer) == 0x078);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, ThreadFlags) == 0x0A0);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, WaitBlock) == 0x0A8);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, WaitBlockFill0) == 0x0A8);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, QueueListEntry) == 0x108);
|
2006-10-01 15:52:10 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, PreviousMode) == KTHREAD_PREVIOUS_MODE);
|
2012-04-01 13:37:20 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, PreviousMode) == FIELD_OFFSET(KTHREAD, WaitBlock) + sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte));
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, ResourceIndex) == FIELD_OFFSET(KTHREAD, WaitBlock) + 2*sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte));
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, LargeStack) == FIELD_OFFSET(KTHREAD, WaitBlock) + 3*sizeof(KWAIT_BLOCK) + FIELD_OFFSET(KWAIT_BLOCK, SpareByte));
|
2012-04-01 14:15:00 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, TrapFrame) == KTHREAD_TRAP_FRAME);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, CallbackStack) == KTHREAD_CALLBACK_STACK);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, ServiceTable) == KTHREAD_SERVICE_TABLE);
|
2012-04-01 13:37:20 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, FreezeCount) == FIELD_OFFSET(KTHREAD, SavedApcState.UserApcPending) + 1);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, Quantum) == FIELD_OFFSET(KTHREAD, SuspendApc.SpareByte0));
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, QuantumReset) == FIELD_OFFSET(KTHREAD, SuspendApc.SpareByte1));
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, KernelTime) == FIELD_OFFSET(KTHREAD, SuspendApc.SpareLong0));
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, TlsArray) == FIELD_OFFSET(KTHREAD, SuspendApc.SystemArgument1));
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, LegoData) == FIELD_OFFSET(KTHREAD, SuspendApc.SystemArgument2));
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTHREAD, PowerState) == FIELD_OFFSET(KTHREAD, SuspendApc.Inserted) + 1);
|
|
|
|
C_ASSERT(sizeof(KTHREAD) == 0x1B8);
|
|
|
|
|
2006-10-01 15:52:10 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KPROCESS, DirectoryTableBase) == KPROCESS_DIRECTORY_TABLE_BASE);
|
2008-11-30 05:49:18 +00:00
|
|
|
|
2010-03-12 16:28:04 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KPCR, NtTib.ExceptionList) == KPCR_EXCEPTION_LIST);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KPCR, SelfPcr) == KPCR_SELF);
|
2006-10-01 15:52:10 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KPCR, IRR) == KPCR_IRR);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KPCR, IDR) == KPCR_IDR);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KPCR, Irql) == KPCR_IRQL);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, CurrentThread) == KPCR_CURRENT_THREAD);
|
2007-04-01 19:35:05 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NextThread) == KPCR_PRCB_NEXT_THREAD);
|
2006-10-01 15:52:10 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NpxThread) == KPCR_NPX_THREAD);
|
2007-04-01 19:35:05 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) == KPCR_PRCB_DATA);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, KeSystemCalls) == KPCR_SYSTEM_CALLS);
|
2008-08-14 19:30:32 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + FIELD_OFFSET(KDPC_DATA, DpcQueueDepth) == KPCR_PRCB_DPC_QUEUE_DEPTH);
|
2007-04-01 19:35:05 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + 16 == KPCR_PRCB_DPC_COUNT);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcStack) == KPCR_PRCB_DPC_STACK);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, TimerRequest) == KPCR_PRCB_TIMER_REQUEST);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, MaximumDpcQueueDepth) == KPCR_PRCB_MAXIMUM_DPC_QUEUE_DEPTH);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcRequestRate) == KPCR_PRCB_DPC_REQUEST_RATE);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcInterruptRequested) == KPCR_PRCB_DPC_INTERRUPT_REQUESTED);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcRoutineActive) == KPCR_PRCB_DPC_ROUTINE_ACTIVE);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcLastCount) == KPCR_PRCB_DPC_LAST_COUNT);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, TimerRequest) == KPCR_PRCB_TIMER_REQUEST);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, QuantumEnd) == KPCR_PRCB_QUANTUM_END);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DeferredReadyListHead) == KPCR_PRCB_DEFERRED_READY_LIST_HEAD);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PowerState) == KPCR_PRCB_POWER_STATE_IDLE_FUNCTION);
|
2008-08-14 19:30:32 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PrcbLock) == KPCR_PRCB_PRCB_LOCK);
|
2006-10-04 05:29:30 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcStack) == KPCR_PRCB_DPC_STACK);
|
2008-10-21 15:32:49 +00:00
|
|
|
C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, IdleSchedule) == KPCR_PRCB_IDLE_SCHEDULE);
|
2006-10-01 15:52:10 +00:00
|
|
|
C_ASSERT(sizeof(FX_SAVE_AREA) == SIZEOF_FX_SAVE_AREA);
|
|
|
|
|
2007-03-26 20:28:13 +00:00
|
|
|
/* Platform specific checks */
|
|
|
|
C_ASSERT(FIELD_OFFSET(KPROCESS, IopmOffset) == KPROCESS_IOPM_OFFSET);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KPROCESS, LdtDescriptor) == KPROCESS_LDT_DESCRIPTOR0);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTSS, Esp0) == KTSS_ESP0);
|
|
|
|
C_ASSERT(FIELD_OFFSET(KTSS, IoMapBase) == KTSS_IOMAPBASE);
|
|
|
|
#endif
|