ReactOS 0.4.16-dev-188-g678aa63
ke.h File Reference
#include "pshpack4.h"
#include "poppack.h"
Include dependency graph for ke.h:

Go to the source code of this file.

Classes

struct  _CONTEXT
 
struct  _KPCR
 

Macros

#define PASSIVE_LEVEL   0
 
#define LOW_LEVEL   0
 
#define APC_LEVEL   1
 
#define DISPATCH_LEVEL   2
 
#define CMCI_LEVEL   5
 
#define PROFILE_LEVEL   27
 
#define CLOCK1_LEVEL   28
 
#define CLOCK2_LEVEL   28
 
#define IPI_LEVEL   29
 
#define POWER_LEVEL   30
 
#define HIGH_LEVEL   31
 
#define CLOCK_LEVEL   CLOCK2_LEVEL
 
#define KIP0PCRADDRESS   0xffdff000
 
#define KI_USER_SHARED_DATA   0xffdf0000
 
#define SharedUserData   ((KUSER_SHARED_DATA * CONST)KI_USER_SHARED_DATA)
 
#define PAGE_SIZE   0x1000
 
#define PAGE_SHIFT   12L
 
#define KeGetDcacheFillSize()   1L
 
#define EFLAG_SIGN   0x8000
 
#define EFLAG_ZERO   0x4000
 
#define EFLAG_SELECT   (EFLAG_SIGN | EFLAG_ZERO)
 
#define RESULT_NEGATIVE   ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
 
#define RESULT_ZERO   ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
 
#define RESULT_POSITIVE   ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
 
#define YieldProcessor   _mm_pause
 
#define KeMemoryBarrierWithoutFence()   _ReadWriteBarrier()
 
#define KeLowerIrql(a)   KfLowerIrql(a)
 
#define KeRaiseIrql(a, b)   *(b) = KfRaiseIrql(a)
 
#define KeAcquireSpinLock(a, b)   *(b) = KfAcquireSpinLock(a)
 
#define KeReleaseSpinLock(a, b)   KfReleaseSpinLock(a,b)
 
#define KeAcquireSpinLockAtDpcLevel(SpinLock)   KefAcquireSpinLockAtDpcLevel(SpinLock)
 
#define KeReleaseSpinLockFromDpcLevel(SpinLock)   KefReleaseSpinLockFromDpcLevel(SpinLock)
 
#define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
 
#define DbgRaiseAssertionFailure   __int2c
 
#define KeQueryTickCount(CurrentCount)   _KeQueryTickCount(CurrentCount)
 
#define PAUSE_PROCESSOR   YieldProcessor();
 
#define KERNEL_STACK_SIZE   12288
 
#define KERNEL_LARGE_STACK_SIZE   61440
 
#define KERNEL_LARGE_STACK_COMMIT   12288
 
#define SIZE_OF_80387_REGISTERS   80
 
#define CONTEXT_i386   0x10000
 
#define CONTEXT_i486   0x10000
 
#define CONTEXT_CONTROL   (CONTEXT_i386|0x00000001L)
 
#define CONTEXT_INTEGER   (CONTEXT_i386|0x00000002L)
 
#define CONTEXT_SEGMENTS   (CONTEXT_i386|0x00000004L)
 
#define CONTEXT_FLOATING_POINT   (CONTEXT_i386|0x00000008L)
 
#define CONTEXT_DEBUG_REGISTERS   (CONTEXT_i386|0x00000010L)
 
#define CONTEXT_EXTENDED_REGISTERS   (CONTEXT_i386|0x00000020L)
 
#define CONTEXT_FULL   (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
 
#define CONTEXT_ALL
 
#define CONTEXT_XSTATE   (CONTEXT_i386 | 0x00000040L)
 
#define PCR_MINOR_VERSION   1
 
#define PCR_MAJOR_VERSION   1
 
#define IsNEC_98   (SharedUserData->AlternativeArchitecture == NEC98x86)
 
#define IsNotNEC_98   (SharedUserData->AlternativeArchitecture != NEC98x86)
 
#define SetNEC_98   (SharedUserData->AlternativeArchitecture = NEC98x86)
 
#define SetNotNEC_98   (SharedUserData->AlternativeArchitecture = StandardDesign)
 

Typedefs

typedef struct _CONTEXT CONTEXT
 
typedef struct _KPCR KPCR
 
typedef struct _KPCRPKPCR
 

Functions

 $if (_WDMDDK_) typedef struct _KFLOATING_SAVE
 
FORCEINLINE VOID KeMemoryBarrier (VOID)
 
 _IRQL_requires_max_ (HIGH_LEVEL) _IRQL_saves_ NTHALAPI KIRQL NTAPI KeGetCurrentIrql(VOID)
 
 _IRQL_requires_max_ (DISPATCH_LEVEL) _IRQL_saves_ _IRQL_raises_(DISPATCH_LEVEL) NTHALAPI KIRQL NTAPI KeRaiseIrqlToDpcLevel(VOID)
 
NTHALAPI KIRQL NTAPI KeRaiseIrqlToSynchLevel (VOID)
 
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _IRQL_requires_ (DISPATCH_LEVEL) NTHALAPI VOID FASTCALL KfReleaseSpinLock(_Inout_ PKSPIN_LOCK SpinLock
 
_Requires_lock_not_held_ SpinLock _Acquires_lock_ SpinLock _IRQL_requires_min_ (DISPATCH_LEVEL) NTKERNELAPI VOID FASTCALL KefAcquireSpinLockAtDpcLevel(_Inout_ PKSPIN_LOCK SpinLock)
 
NTSYSAPI PKTHREAD NTAPI KeGetCurrentThread (VOID)
 
 _Always_ (_Post_satisfies_(return<=0)) _Must_inspect_result_ _IRQL_requires_max_(DISPATCH_LEVEL) _Kernel_float_saved_ _At_(*FloatSave
 
 _Kernel_requires_resource_not_held_ (FloatState) _Kernel_acquires_resource_(FloatState)) NTKERNELAPI NTSTATUS NTAPI KeSaveFloatingPointState(_Out_ PKFLOATING_SAVE FloatSave)
 
 _Success_ (1) _Kernel_float_restored_ _At_(*FloatSave
 
 _Kernel_requires_resource_held_ (FloatState) _Kernel_releases_resource_(FloatState)) NTKERNELAPI NTSTATUS NTAPI KeRestoreFloatingPointState(_In_ PKFLOATING_SAVE FloatSave)
 
FORCEINLINE ULONG NTAPI KeGetCurrentProcessorIndex (VOID)
 
FORCEINLINE VOID _KeQueryTickCount (OUT PLARGE_INTEGER CurrentCount)
 
 $endif (_WDMDDK_) $if(_NTDDK_) typedef struct _FLOATING_SAVE_AREA
 
FORCEINLINE ULONG KeGetCurrentProcessorNumber (VOID)
 

Variables

 KFLOATING_SAVE
 
PKFLOATING_SAVE
 
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
 
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
 
 FLOATING_SAVE_AREA
 
PFLOATING_SAVE_AREA
 

Macro Definition Documentation

◆ APC_LEVEL

#define APC_LEVEL   1

◆ CLOCK1_LEVEL

#define CLOCK1_LEVEL   28

◆ CLOCK2_LEVEL

#define CLOCK2_LEVEL   28

◆ CLOCK_LEVEL

#define CLOCK_LEVEL   CLOCK2_LEVEL

◆ CMCI_LEVEL

#define CMCI_LEVEL   5

◆ CONTEXT_ALL

#define CONTEXT_ALL
Value:
#define CONTEXT_DEBUG_REGISTERS
#define CONTEXT_CONTROL
#define CONTEXT_INTEGER
#define CONTEXT_FLOATING_POINT
#define CONTEXT_SEGMENTS
#define CONTEXT_EXTENDED_REGISTERS

◆ CONTEXT_CONTROL

#define CONTEXT_CONTROL   (CONTEXT_i386|0x00000001L)

◆ CONTEXT_DEBUG_REGISTERS

#define CONTEXT_DEBUG_REGISTERS   (CONTEXT_i386|0x00000010L)

◆ CONTEXT_EXTENDED_REGISTERS

#define CONTEXT_EXTENDED_REGISTERS   (CONTEXT_i386|0x00000020L)

◆ CONTEXT_FLOATING_POINT

#define CONTEXT_FLOATING_POINT   (CONTEXT_i386|0x00000008L)

◆ CONTEXT_FULL

◆ CONTEXT_i386

#define CONTEXT_i386   0x10000

◆ CONTEXT_i486

#define CONTEXT_i486   0x10000

◆ CONTEXT_INTEGER

#define CONTEXT_INTEGER   (CONTEXT_i386|0x00000002L)

◆ CONTEXT_SEGMENTS

#define CONTEXT_SEGMENTS   (CONTEXT_i386|0x00000004L)

◆ CONTEXT_XSTATE

#define CONTEXT_XSTATE   (CONTEXT_i386 | 0x00000040L)

◆ DbgRaiseAssertionFailure

#define DbgRaiseAssertionFailure   __int2c

Definition at line 191 of file ke.h.

◆ DISPATCH_LEVEL

#define DISPATCH_LEVEL   2

◆ EFLAG_SELECT

#define EFLAG_SELECT   (EFLAG_SIGN | EFLAG_ZERO)

◆ EFLAG_SIGN

#define EFLAG_SIGN   0x8000

◆ EFLAG_ZERO

#define EFLAG_ZERO   0x4000

◆ HIGH_LEVEL

#define HIGH_LEVEL   31

◆ IPI_LEVEL

#define IPI_LEVEL   29

◆ IsNEC_98

#define IsNEC_98   (SharedUserData->AlternativeArchitecture == NEC98x86)

Definition at line 352 of file ke.h.

◆ IsNotNEC_98

#define IsNotNEC_98   (SharedUserData->AlternativeArchitecture != NEC98x86)

Definition at line 357 of file ke.h.

◆ KeAcquireSpinLock

#define KeAcquireSpinLock (   a,
  b 
)    *(b) = KfAcquireSpinLock(a)

Definition at line 114 of file ke.h.

◆ KeAcquireSpinLockAtDpcLevel

#define KeAcquireSpinLockAtDpcLevel (   SpinLock)    KefAcquireSpinLockAtDpcLevel(SpinLock)

Definition at line 135 of file ke.h.

◆ KeFlushIoBuffers

#define KeFlushIoBuffers (   _Mdl,
  _ReadOperation,
  _DmaOperation 
)

Definition at line 188 of file ke.h.

◆ KeGetDcacheFillSize

#define KeGetDcacheFillSize ( )    1L

◆ KeLowerIrql

#define KeLowerIrql (   a)    KfLowerIrql(a)

Definition at line 79 of file ke.h.

◆ KeMemoryBarrierWithoutFence

#define KeMemoryBarrierWithoutFence ( )    _ReadWriteBarrier()

Definition at line 64 of file ke.h.

◆ KeQueryTickCount

#define KeQueryTickCount (   CurrentCount)    _KeQueryTickCount(CurrentCount)

Definition at line 211 of file ke.h.

◆ KeRaiseIrql

#define KeRaiseIrql (   a,
  b 
)    *(b) = KfRaiseIrql(a)

Definition at line 89 of file ke.h.

◆ KeReleaseSpinLock

#define KeReleaseSpinLock (   a,
  b 
)    KfReleaseSpinLock(a,b)

Definition at line 125 of file ke.h.

◆ KeReleaseSpinLockFromDpcLevel

#define KeReleaseSpinLockFromDpcLevel (   SpinLock)    KefReleaseSpinLockFromDpcLevel(SpinLock)

Definition at line 145 of file ke.h.

◆ KERNEL_LARGE_STACK_COMMIT

#define KERNEL_LARGE_STACK_COMMIT   12288

◆ KERNEL_LARGE_STACK_SIZE

#define KERNEL_LARGE_STACK_SIZE   61440

◆ KERNEL_STACK_SIZE

#define KERNEL_STACK_SIZE   12288

◆ KI_USER_SHARED_DATA

#define KI_USER_SHARED_DATA   0xffdf0000

◆ KIP0PCRADDRESS

#define KIP0PCRADDRESS   0xffdff000

◆ LOW_LEVEL

#define LOW_LEVEL   0

◆ PAGE_SHIFT

#define PAGE_SHIFT   12L

◆ PAGE_SIZE

#define PAGE_SIZE   0x1000

◆ PASSIVE_LEVEL

#define PASSIVE_LEVEL   0

◆ PAUSE_PROCESSOR

#define PAUSE_PROCESSOR   YieldProcessor();

◆ PCR_MAJOR_VERSION

#define PCR_MAJOR_VERSION   1

Definition at line 287 of file ke.h.

◆ PCR_MINOR_VERSION

#define PCR_MINOR_VERSION   1

Definition at line 286 of file ke.h.

◆ POWER_LEVEL

#define POWER_LEVEL   30

◆ PROFILE_LEVEL

#define PROFILE_LEVEL   27

◆ RESULT_NEGATIVE

#define RESULT_NEGATIVE   ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)

◆ RESULT_POSITIVE

#define RESULT_POSITIVE   ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)

◆ RESULT_ZERO

#define RESULT_ZERO   ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)

◆ SetNEC_98

#define SetNEC_98   (SharedUserData->AlternativeArchitecture = NEC98x86)

Definition at line 362 of file ke.h.

◆ SetNotNEC_98

#define SetNotNEC_98   (SharedUserData->AlternativeArchitecture = StandardDesign)

Definition at line 367 of file ke.h.

◆ SharedUserData

◆ SIZE_OF_80387_REGISTERS

#define SIZE_OF_80387_REGISTERS   80

◆ YieldProcessor

#define YieldProcessor   _mm_pause

Definition at line 48 of file ke.h.

Typedef Documentation

◆ CONTEXT

◆ KPCR

typedef struct _KPCR KPCR

◆ PKPCR

typedef struct _KPCR * PKPCR

Function Documentation

◆ $endif()

$endif ( _WDMDDK_  )

Definition at line 213 of file ke.h.

244 {
245 ULONG ControlWord;
246 ULONG StatusWord;
247 ULONG TagWord;
248 ULONG ErrorOffset;
249 ULONG ErrorSelector;
250 ULONG DataOffset;
251 ULONG DataSelector;
252 UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
253 ULONG Cr0NpxState;
* PFLOATING_SAVE_AREA
Definition: ke.h:254
FLOATING_SAVE_AREA
Definition: ke.h:254
#define SIZE_OF_80387_REGISTERS
uint32_t ULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ $if()

$if ( _WDMDDK_  )

Kernel definitions for x86

Definition at line 1 of file ke.h.

35 {
36 ULONG ControlWord;
37 ULONG StatusWord;
38 ULONG ErrorOffset;
39 ULONG ErrorSelector;
40 ULONG DataOffset;
41 ULONG DataSelector;
42 ULONG Cr0NpxState;
43 ULONG Spare1;
KFLOATING_SAVE
Definition: ke.h:33
* PKFLOATING_SAVE
Definition: ke.h:33

Referenced by $endif().

◆ _Always_()

_Always_ ( _Post_satisfies_(return<=0)  )

◆ _IRQL_requires_()

Definition at line 394 of file expool.c.

1465{
1466 SIZE_T OldSize = PoolBigPageTableSize;
1467 SIZE_T NewSize, NewSizeInBytes;
1468 PPOOL_TRACKER_BIG_PAGES NewTable;
1469 PPOOL_TRACKER_BIG_PAGES OldTable;
1470 ULONG i;
1471 ULONG PagesFreed;
1472 ULONG Hash;
1473 ULONG HashMask;
1474
1475 /* Must be holding ExpLargePoolTableLock */
1477
1478 /* Make sure we don't overflow */
1479 if (Shrink)
1480 {
1481 NewSize = OldSize / 2;
1482
1483 /* Make sure we don't shrink too much. */
1485
1487 ASSERT(NewSize <= OldSize);
1488
1489 /* If there is only one page left, then keep it around. Not a failure either. */
1490 if (NewSize == OldSize)
1491 {
1494 return TRUE;
1495 }
1496 }
1497 else
1498 {
1499 if (!NT_SUCCESS(RtlSIZETMult(2, OldSize, &NewSize)))
1500 {
1501 DPRINT1("Overflow expanding big page table. Size=%lu\n", OldSize);
1503 return FALSE;
1504 }
1505
1506 /* Make sure we don't stupidly waste pages */
1508 ASSERT(NewSize > OldSize);
1509 }
1510
1511 if (!NT_SUCCESS(RtlSIZETMult(sizeof(POOL_TRACKER_BIG_PAGES), NewSize, &NewSizeInBytes)))
1512 {
1513 DPRINT1("Overflow while calculating big page table size. Size=%lu\n", OldSize);
1515 return FALSE;
1516 }
1517
1518 NewTable = MiAllocatePoolPages(NonPagedPool, NewSizeInBytes);
1519 if (NewTable == NULL)
1520 {
1521 DPRINT("Could not allocate %lu bytes for new big page table\n", NewSizeInBytes);
1523 return FALSE;
1524 }
1525
1526 DPRINT("%s big pool tracker table to %lu entries\n", Shrink ? "Shrinking" : "Expanding", NewSize);
1527
1528 /* Initialize the new table */
1529 RtlZeroMemory(NewTable, NewSizeInBytes);
1530 for (i = 0; i < NewSize; i++)
1531 {
1532 NewTable[i].Va = (PVOID)POOL_BIG_TABLE_ENTRY_FREE;
1533 }
1534
1535 /* Copy over all items */
1536 OldTable = PoolBigPageTable;
1537 HashMask = NewSize - 1;
1538 for (i = 0; i < OldSize; i++)
1539 {
1540 /* Skip over empty items */
1541 if ((ULONG_PTR)OldTable[i].Va & POOL_BIG_TABLE_ENTRY_FREE)
1542 {
1543 continue;
1544 }
1545
1546 /* Recalculate the hash due to the new table size */
1547 Hash = ExpComputePartialHashForAddress(OldTable[i].Va) % HashMask;
1548
1549 /* Find the location in the new table */
1550 while (!((ULONG_PTR)NewTable[Hash].Va & POOL_BIG_TABLE_ENTRY_FREE))
1551 {
1552 if (++Hash == NewSize)
1553 Hash = 0;
1554 }
1555
1556 /* We must have space */
1558
1559 /* Finally, copy the item */
1560 NewTable[Hash] = OldTable[i];
1561 }
1562
1563 /* Activate the new table */
1564 PoolBigPageTable = NewTable;
1567
1568 /* Release the lock, we're done changing global state */
1570
1571 /* Free the old table and update our tracker */
1572 PagesFreed = MiFreePoolPages(OldTable);
1573 ExpRemovePoolTracker('looP', PagesFreed << PAGE_SHIFT, 0);
1574 ExpInsertPoolTracker('looP', ALIGN_UP_BY(NewSizeInBytes, PAGE_SIZE), 0);
1575
1576 return TRUE;
1577}
#define ALIGN_DOWN_BY(size, align)
#define ALIGN_UP_BY(size, align)
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
static int Hash(const char *)
Definition: reader.c:2257
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define NonPagedPool
Definition: env_spec_w32.h:307
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG ExpPoolBigEntriesInUse
Definition: expool.c:55
VOID NTAPI ExpRemovePoolTracker(IN ULONG Key, IN SIZE_T NumberOfBytes, IN POOL_TYPE PoolType)
Definition: expool.c:760
SIZE_T PoolBigPageTableSize
Definition: expool.c:47
FORCEINLINE ULONG ExpComputePartialHashForAddress(IN PVOID BaseAddress)
Definition: expool.c:457
PPOOL_TRACKER_BIG_PAGES PoolBigPageTable
Definition: expool.c:50
#define POOL_BIG_TABLE_ENTRY_FREE
Definition: expool.c:23
KSPIN_LOCK ExpLargePoolTableLock
Definition: expool.c:54
VOID NTAPI ExpInsertPoolTracker(IN ULONG Key, IN SIZE_T NumberOfBytes, IN POOL_TYPE PoolType)
Definition: expool.c:851
SIZE_T PoolBigPageTableHash
Definition: expool.c:47
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ASSERT(a)
Definition: mode.c:44
PVOID NTAPI MiAllocatePoolPages(IN POOL_TYPE PoolType, IN SIZE_T SizeInBytes)
Definition: pool.c:422
ULONG NTAPI MiFreePoolPages(IN PVOID StartingAddress)
Definition: pool.c:918
#define DPRINT
Definition: sndvol32.h:73
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

◆ _IRQL_requires_max_() [1/2]

_IRQL_requires_max_ ( DISPATCH_LEVEL  )

Definition at line 3557 of file common.c.

3587{
3589 BOOLEAN requestSent = FALSE;
3590
3591 BOOLEAN shouldRetry = TRUE;
3592 PCDB cdb = (PCDB)DeviceExtension->PowerContext.Srb.Cdb;
3593 ULONG timeoutValue = DeviceExtension->TimeOutValue;
3594 ULONG retryCount = 1;
3595
3596 // reset some fields.
3597 DeviceExtension->PowerContext.RetryIntervalIn100ns = 0;
3598 status = PowerContextReuseRequest(DeviceExtension);
3599 RequestClearSendTime(DeviceExtension->PowerContext.PowerRequest);
3600
3601 if (!NT_SUCCESS(status))
3602 {
3603 return status;
3604 }
3605
3606 // set proper timeout value and max retry count.
3607 switch(DeviceExtension->PowerContext.PowerChangeState.PowerDown)
3608 {
3612 break;
3613
3615 // Case of issuing SYNC CACHE command. Do not use power irp timeout remaining time in this case
3616 // as we want to give best try on SYNC CACHE command.
3617 retryCount = MAXIMUM_RETRIES;
3618 timeoutValue = DeviceExtension->TimeOutValue;
3619 break;
3620
3622 {
3623 // Case of issuing STOP UNIT command
3624 // As "Imme" bit is set to '1', this command should be completed in short time.
3625 // This command is at low importance, failure of this command has very small impact.
3626 ULONG secondsRemaining = 0;
3627
3628#if (WINVER >= 0x0601)
3629 // this API is introduced in Windows7
3630 PoQueryWatchdogTime(DeviceExtension->LowerPdo, &secondsRemaining);
3631#endif
3632
3633 if (secondsRemaining == 0)
3634 {
3635 // not able to retrieve remaining time from PoQueryWatchdogTime API, use default values.
3636 retryCount = MAXIMUM_RETRIES;
3637 timeoutValue = SCSI_CDROM_TIMEOUT;
3638 }
3639 else
3640 {
3641 // plan to leave about 30 seconds to lower level drivers if possible.
3642 if (secondsRemaining >= 32)
3643 {
3644 retryCount = (secondsRemaining - 30)/SCSI_CDROM_TIMEOUT + 1;
3645 timeoutValue = SCSI_CDROM_TIMEOUT;
3646
3647 if (retryCount > MAXIMUM_RETRIES)
3648 {
3649 retryCount = MAXIMUM_RETRIES;
3650 }
3651
3652 if (retryCount == 1)
3653 {
3654 timeoutValue = secondsRemaining - 30;
3655 }
3656 }
3657 else
3658 {
3659 // issue the command with minimal timeout value and do not retry on it.
3660 retryCount = 1;
3661 timeoutValue = 2;
3662 }
3663 }
3664 }
3665 break;
3666 default:
3667 NT_ASSERT( FALSE );
3669 return status;
3670 }
3671
3672 DeviceExtension->PowerContext.RetryCount = retryCount;
3673
3674 // issue command.
3675 while (shouldRetry)
3676 {
3677
3678 // set SRB fields.
3679 DeviceExtension->PowerContext.Srb.SrbFlags = SRB_FLAGS_NO_DATA_TRANSFER |
3684
3685 DeviceExtension->PowerContext.Srb.Function = SRB_FUNCTION_EXECUTE_SCSI;
3686 DeviceExtension->PowerContext.Srb.TimeOutValue = timeoutValue;
3687
3688 if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceInitial)
3689 {
3690 DeviceExtension->PowerContext.Srb.Function = SRB_FUNCTION_LOCK_QUEUE;
3691 }
3692 else if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceLocked)
3693 {
3694 DeviceExtension->PowerContext.Srb.Function = SRB_FUNCTION_QUIESCE_DEVICE;
3695 }
3696 else if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceQuiesced)
3697 {
3698 // Case of issuing SYNC CACHE command.
3699 DeviceExtension->PowerContext.Srb.CdbLength = 10;
3700 cdb->SYNCHRONIZE_CACHE10.OperationCode = SCSIOP_SYNCHRONIZE_CACHE;
3701 }
3702 else if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceFlushed)
3703 {
3704 // Case of issuing STOP UNIT command.
3705 DeviceExtension->PowerContext.Srb.CdbLength = 6;
3706 cdb->START_STOP.OperationCode = SCSIOP_START_STOP_UNIT;
3707 cdb->START_STOP.Start = 0;
3708 cdb->START_STOP.Immediate = 1;
3709 }
3710 else if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceStopped)
3711 {
3712 DeviceExtension->PowerContext.Srb.Function = SRB_FUNCTION_UNLOCK_QUEUE;
3713 }
3714
3715 // Set up completion routine and context if requested
3717 {
3718 WdfRequestSetCompletionRoutine(DeviceExtension->PowerContext.PowerRequest,
3720 Context);
3721 }
3722
3723 status = RequestSend(DeviceExtension,
3724 DeviceExtension->PowerContext.PowerRequest,
3725 DeviceExtension->IoTarget,
3727 &requestSent);
3728
3729 if (requestSent)
3730 {
3731 if ((CompletionRoutine == NULL) &&
3732 (SRB_STATUS(DeviceExtension->PowerContext.Srb.SrbStatus) != SRB_STATUS_SUCCESS))
3733 {
3734 TracePrint((TRACE_LEVEL_ERROR,
3735 TRACE_FLAG_POWER,
3736 "%p\tError occured when issuing %s command to device. Srb %p, Status %x\n",
3737 DeviceExtension->PowerContext.PowerRequest,
3738 (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceQuiesced) ? "SYNC CACHE" : "STOP UNIT",
3739 &DeviceExtension->PowerContext.Srb,
3740 DeviceExtension->PowerContext.Srb.SrbStatus));
3741
3742 NT_ASSERT(!(TEST_FLAG(DeviceExtension->PowerContext.Srb.SrbStatus, SRB_STATUS_QUEUE_FROZEN)));
3743
3744 shouldRetry = RequestSenseInfoInterpret(DeviceExtension,
3745 DeviceExtension->PowerContext.PowerRequest,
3746 &(DeviceExtension->PowerContext.Srb),
3747 retryCount - DeviceExtension->PowerContext.RetryCount,
3748 &status,
3749 &(DeviceExtension->PowerContext.RetryIntervalIn100ns));
3750
3751 if (shouldRetry && (DeviceExtension->PowerContext.RetryCount-- == 0))
3752 {
3753 shouldRetry = FALSE;
3754 }
3755 }
3756 else
3757 {
3758 // succeeded, do not need to retry.
3759 shouldRetry = FALSE;
3760 }
3761
3762 }
3763 else
3764 {
3765 // request failed to be sent
3766 shouldRetry = FALSE;
3767 }
3768
3769 if (shouldRetry)
3770 {
3772 t.QuadPart = -DeviceExtension->PowerContext.RetryIntervalIn100ns;
3774
3775 status = PowerContextReuseRequest(DeviceExtension);
3776 if (!NT_SUCCESS(status))
3777 {
3778 shouldRetry = FALSE;
3779 }
3780 }
3781 }
3782
3783 if (DeviceExtension->PowerContext.PowerChangeState.PowerDown == PowerDownDeviceQuiesced)
3784 {
3785 // record SYNC CACHE command completion time stamp.
3786 KeQueryTickCount(&DeviceExtension->PowerContext.Step1CompleteTime);
3787 }
3788
3789 return status;
3790}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define MAXIMUM_RETRIES
Definition: cdrom.h:124
#define SCSI_CDROM_TIMEOUT
Definition: cdrom.h:680
BOOLEAN RequestSenseInfoInterpret(_In_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_ WDFREQUEST Request, _In_ PSCSI_REQUEST_BLOCK Srb, _In_ ULONG RetriedCount, _Out_ NTSTATUS *Status, _Out_opt_ _Deref_out_range_(0, MAXIMUM_RETRY_FOR_SINGLE_IO_IN_100NS_UNITS) LONGLONG *RetryIntervalIn100ns)
Definition: sense.c:2467
#define TEST_FLAG(Flags, Bit)
Definition: cdrom.h:1495
@ PowerDownDeviceStopped
Definition: cdrom.h:412
@ PowerDownDeviceQuiesced
Definition: cdrom.h:410
@ PowerDownDeviceInitial
Definition: cdrom.h:408
@ PowerDownDeviceLocked
Definition: cdrom.h:409
@ PowerDownDeviceFlushed
Definition: cdrom.h:411
union _CDB * PCDB
#define SCSIOP_START_STOP_UNIT
Definition: cdrw_hw.h:897
#define SCSIOP_SYNCHRONIZE_CACHE
Definition: cdrw_hw.h:918
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
NTSTATUS RequestSend(_In_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_ WDFREQUEST Request, _In_ WDFIOTARGET IoTarget, _In_ ULONG Flags, _Out_opt_ PBOOLEAN RequestSent)
Definition: common.c:3793
VOID RequestClearSendTime(_In_ WDFREQUEST Request)
Definition: common.c:111
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:315
#define SRB_FLAGS_NO_DATA_TRANSFER
Definition: srb.h:402
#define SRB_FUNCTION_LOCK_QUEUE
Definition: srb.h:332
#define SRB_FUNCTION_UNLOCK_QUEUE
Definition: srb.h:333
#define SRB_FLAGS_BYPASS_LOCKED_QUEUE
Definition: srb.h:410
#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER
Definition: srb.h:397
#define SRB_STATUS(Status)
Definition: srb.h:389
#define SRB_STATUS_QUEUE_FROZEN
Definition: srb.h:386
#define SRB_FLAGS_NO_QUEUE_FREEZE
Definition: srb.h:404
#define SRB_STATUS_SUCCESS
Definition: srb.h:341
#define KeDelayExecutionThread(mode, foo, t)
Definition: env_spec_w32.h:484
GLdouble GLdouble t
Definition: gl.h:2047
#define KernelMode
Definition: asm.h:34
#define SRB_FLAGS_D3_PROCESSING
Definition: srb.h:165
#define SRB_FUNCTION_QUIESCE_DEVICE
Definition: srb.h:99
#define KeQueryTickCount(CurrentCount)
Definition: ke.h:43
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ps.c:97
Definition: cdrw_hw.h:28
struct _CDB::_START_STOP START_STOP
struct _CDB::_SYNCHRONIZE_CACHE10 SYNCHRONIZE_CACHE10
@ WDF_REQUEST_SEND_OPTION_SYNCHRONOUS
Definition: wdfrequest.h:109
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
Definition: wdfrequest.h:895
#define NT_ASSERT
Definition: rtlfuncs.h:3324

◆ _IRQL_requires_max_() [2/2]

_IRQL_requires_max_ ( HIGH_LEVEL  )

Definition at line 134 of file wdfdpc.h.

151{
152 return ((PFN_WDFDPCENQUEUE) WdfFunctions[WdfDpcEnqueueTableIndex])(WdfDriverGlobals, Dpc);
153}
#define WdfFunctions
Definition: wdf.h:66
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
PWDF_DRIVER_GLOBALS WdfDriverGlobals
@ WdfDpcEnqueueTableIndex
Definition: wdffuncenum.h:137

◆ _IRQL_requires_min_()

Definition at line 1015 of file mm.h.

1021{
1022 PKSPIN_LOCK_QUEUE LockQueue;
1023
1025 LockQueue = &KeGetCurrentPrcb()->LockQueue[LockQueuePfnLock];
1026 KeAcquireQueuedSpinLockAtDpcLevel(LockQueue);
1027}
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1150
@ LockQueuePfnLock
Definition: ketypes.h:660

◆ _KeQueryTickCount()

FORCEINLINE VOID _KeQueryTickCount ( OUT PLARGE_INTEGER  CurrentCount)

Definition at line 195 of file ke.h.

197{
198 for (;;) {
199#ifdef NONAMELESSUNION
200 CurrentCount->s.HighPart = KeTickCount.High1Time;
201 CurrentCount->s.LowPart = KeTickCount.LowPart;
202 if (CurrentCount->s.HighPart == KeTickCount.High2Time) break;
203#else
204 CurrentCount->HighPart = KeTickCount.High1Time;
205 CurrentCount->LowPart = KeTickCount.LowPart;
206 if (CurrentCount->HighPart == KeTickCount.High2Time) break;
207#endif
209 }
210}
#define YieldProcessor
Definition: ke.h:48
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
Definition: clock.c:19
LONG High1Time
Definition: ketypes.h:930
LONG High2Time
Definition: ketypes.h:931
ULONG LowPart
Definition: ketypes.h:929

◆ _Kernel_requires_resource_held_()

_Kernel_requires_resource_held_ ( FloatState  )

Definition at line 149 of file ke.h.

154{
155 UNREFERENCED_PARAMETER(FloatSave);
156 return STATUS_SUCCESS;
157}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ _Kernel_requires_resource_not_held_()

_Kernel_requires_resource_not_held_ ( FloatState  )

Definition at line 137 of file ke.h.

142{
143 UNREFERENCED_PARAMETER(FloatSave);
144 return STATUS_SUCCESS;
145}

◆ _Success_()

_Success_ ( )

◆ KeGetCurrentProcessorIndex()

FORCEINLINE ULONG NTAPI KeGetCurrentProcessorIndex ( VOID  )

Definition at line 176 of file ke.h.

177{
178 return __readfsbyte(0x51);
179}
PPC_QUAL unsigned char __readfsbyte(const unsigned long Offset)
Definition: intrin_ppc.h:360

◆ KeGetCurrentProcessorNumber()

FORCEINLINE ULONG KeGetCurrentProcessorNumber ( VOID  )

Definition at line 343 of file ke.h.

344{
346}
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
Definition: ke.h:294
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

◆ KeGetCurrentThread()

NTSYSAPI PKTHREAD NTAPI KeGetCurrentThread ( VOID  )

Definition at line 379 of file ke.h.

380{
381 /* Return the current thread */
382 return ((PKIPCR)KeGetPcr())->PrcbData.CurrentThread;
383}
#define KeGetPcr()
Definition: ketypes.h:81

◆ KeMemoryBarrier()

FORCEINLINE VOID KeMemoryBarrier ( VOID  )

Definition at line 52 of file ke.h.

53{
54 LONG Barrier, *Dummy = &Barrier;
55 (VOID)Dummy;
56
57#if defined(__GNUC__)
58 __asm__ __volatile__ ("xchg %%eax, %0" : : "m" (Barrier) : "%eax");
59#elif defined(_MSC_VER)
60 __asm xchg [Barrier], eax
61#endif
62}
#define VOID
Definition: acefi.h:82
long LONG
Definition: pedump.c:60
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85

◆ KeRaiseIrqlToSynchLevel()

NTHALAPI KIRQL NTAPI KeRaiseIrqlToSynchLevel ( VOID  )

Definition at line 156 of file pic.c.

157{
158 PKPCR Pcr = KeGetPcr();
159 KIRQL CurrentIrql;
160
161 /* Save and update IRQL */
162 CurrentIrql = Pcr->Irql;
163 Pcr->Irql = SYNCH_LEVEL;
164
165#ifdef IRQL_DEBUG
166 /* Validate correct raise */
167 if (CurrentIrql > SYNCH_LEVEL)
168 {
169 /* Crash system */
170 KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
171 CurrentIrql,
173 0,
174 1);
175 }
176#endif
177
178 /* Return the previous value */
179 return CurrentIrql;
180}
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
KIRQL Irql
Definition: ke.h:311

Referenced by _Requires_lock_not_held_(), KeDelayExecutionThread(), KeFlushEntireTb(), KeQueryBasePriorityThread(), KeRemoveQueue(), KeSignalGateBoostPriority(), KeWaitForMultipleObjects(), KeWaitForSingleObject(), KiRetireDpcList(), and NtYieldExecution().

Variable Documentation

◆ FLOATING_SAVE_AREA

Definition at line 254 of file ke.h.

◆ KeTickCount

NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
extern

Definition at line 19 of file clock.c.

Referenced by KeQueryTickCount().

◆ KFLOATING_SAVE

Definition at line 44 of file ke.h.

◆ NewIrql

◆ PFLOATING_SAVE_AREA

Definition at line 254 of file ke.h.

◆ PKFLOATING_SAVE

Definition at line 44 of file ke.h.