ReactOS 0.4.16-dev-1524-ga5ab400
KeDpc.c File Reference
#include <kmt_test.h>
#include <debug.h>
Include dependency graph for KeDpc.c:

Go to the source code of this file.

Macros

#define ok_dpccount()   ok(DpcCount == ExpectedDpcCount, "DpcCount = %ld, expected %ld\n", DpcCount, ExpectedDpcCount);
 

Functions

static VOID NTAPI DpcHandler (IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
 START_TEST (KeDpc)
 

Variables

static volatile LONG DpcCount
 
static volatile UCHAR DpcImportance
 
static KDEFERRED_ROUTINE DpcHandler
 

Macro Definition Documentation

◆ ok_dpccount

#define ok_dpccount ( )    ok(DpcCount == ExpectedDpcCount, "DpcCount = %ld, expected %ld\n", DpcCount, ExpectedDpcCount);

Function Documentation

◆ DpcHandler()

static VOID NTAPI DpcHandler ( IN PRKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)
static

Definition at line 23 of file KeDpc.c.

28{
29 PKPRCB Prcb = KeGetCurrentPrcb();
30
31 ok_irql(DISPATCH_LEVEL);
33 ok(DeferredContext == Dpc, "DeferredContext = %p, Dpc = %p, expected equal\n", DeferredContext, Dpc);
36
37 /* KDPC object contents */
38 ok_eq_uint(Dpc->Type, DpcObject);
39 ok_eq_uint(Dpc->Importance, DpcImportance);
40 ok_eq_uint(Dpc->Number, 0);
41 ok(Dpc->DpcListEntry.Blink != NULL, "\n");
42 ok(Dpc->DpcListEntry.Blink != &Dpc->DpcListEntry, "\n");
43 if (!skip(Dpc->DpcListEntry.Blink != NULL, "DpcListEntry.Blink == NULL\n"))
44 ok_eq_pointer(Dpc->DpcListEntry.Flink, Dpc->DpcListEntry.Blink->Flink);
45
46 ok(Dpc->DpcListEntry.Flink != NULL, "\n");
47 ok(Dpc->DpcListEntry.Flink != &Dpc->DpcListEntry, "\n");
48 if (!skip(Dpc->DpcListEntry.Flink != NULL, "DpcListEntry.Flink == NULL\n"))
49 ok_eq_pointer(Dpc->DpcListEntry.Blink, Dpc->DpcListEntry.Flink->Blink);
50
51 ok_eq_pointer(Dpc->DeferredRoutine, DpcHandler);
52 ok_eq_pointer(Dpc->DeferredContext, DeferredContext);
53 ok_eq_pointer(Dpc->SystemArgument1, SystemArgument1);
54 ok_eq_pointer(Dpc->SystemArgument2, SystemArgument2);
55 ok_eq_pointer(Dpc->DpcData, NULL);
56
58 {
60 /* this DPC is not in the list anymore, but it was at the head! */
61 ok_eq_pointer(Prcb->DpcData[DPC_NORMAL].DpcListHead.Flink, Dpc->DpcListEntry.Flink);
62 ok_eq_pointer(Prcb->DpcData[DPC_NORMAL].DpcListHead.Blink, Dpc->DpcListEntry.Blink);
63 }
64}
static volatile UCHAR DpcImportance
Definition: KeDpc.c:16
static KDEFERRED_ROUTINE DpcHandler
Definition: KeDpc.c:18
static volatile LONG DpcCount
Definition: KeDpc.c:15
#define ok_eq_pointer(value, expected)
Definition: apitest.h:44
#define GetNTVersion()
Definition: apitest.h:17
#define ok_eq_uint(value, expected)
Definition: apitest.h:46
#define InterlockedIncrement
Definition: armddk.h:53
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1187
@ DpcObject
Definition: ketypes.h:425
#define _WIN32_WINNT_WS03
Definition: sdkddkver.h:23
KDPC_DATA DpcData[2]
Definition: ketypes.h:774
UCHAR DpcRoutineActive
Definition: ketypes.h:786
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
#define DPC_NORMAL
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:688
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:687
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:689

◆ START_TEST()

START_TEST ( KeDpc  )

Definition at line 66 of file KeDpc.c.

67{
69 KDPC Dpc;
70 KIRQL Irql, Irql2, Irql3;
71 LONG ExpectedDpcCount = 0;
72 BOOLEAN Ret;
73 int i;
74
75 DpcCount = 0;
77
78#define ok_dpccount() ok(DpcCount == ExpectedDpcCount, "DpcCount = %ld, expected %ld\n", DpcCount, ExpectedDpcCount);
79 trace("Dpc = %p\n", &Dpc);
80 memset(&Dpc, 0x55, sizeof Dpc);
82 /* check the Dpc object's fields */
84 ok_eq_uint(Dpc.Importance, DpcImportance);
85 ok_eq_uint(Dpc.Number, 0);
86 ok_eq_pointer(Dpc.DpcListEntry.Flink, (LIST_ENTRY *)0x5555555555555555LL);
87 if (Dpc.DpcListEntry.Blink)
88 ok_eq_pointer(Dpc.DpcListEntry.Blink, (LIST_ENTRY *)0x5555555555555555LL);
89 ok_eq_pointer(Dpc.DeferredRoutine, DpcHandler);
90 ok_eq_pointer(Dpc.DeferredContext, &Dpc);
91 ok_eq_pointer(Dpc.SystemArgument1, (PVOID)0x5555555555555555LL);
92 ok_eq_pointer(Dpc.SystemArgument2, (PVOID)0x5555555555555555LL);
93 ok_eq_pointer(Dpc.DpcData, NULL);
94
96 {
97 // Windows 8+ is stricter about misusing DPC, these tests bugcheck there.
98
99 /* simply run the Dpc a few times */
100 for (i = 0; i < 5; ++i)
101 {
102 ok_dpccount();
103 Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
104 ok_bool_true(Ret, "KeInsertQueueDpc returned");
105 ++ExpectedDpcCount;
106 ok_dpccount();
107 }
108
109 /* insert into queue at high irql
110 * -> should only run when lowered to APC_LEVEL,
111 * inserting a second time should fail
112 */
114 for (i = 0; i < 5; ++i)
115 {
117 ok_dpccount();
118 Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
119 ok_bool_true(Ret, "KeInsertQueueDpc returned");
120 Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xdef, (PVOID)0x123);
121 ok_bool_false(Ret, "KeInsertQueueDpc returned");
122 ok_dpccount();
123 KeRaiseIrql(HIGH_LEVEL, &Irql3);
124 ok_dpccount();
125 KeLowerIrql(Irql3);
126 ok_dpccount();
127 KeLowerIrql(Irql2);
128 ++ExpectedDpcCount;
129 ok_dpccount();
130 }
132
133 /* now test removing from the queue */
135 for (i = 0; i < 5; ++i)
136 {
138 ok_dpccount();
139 Ret = KeRemoveQueueDpc(&Dpc);
140 ok_bool_false(Ret, "KeRemoveQueueDpc returned");
141 Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
142 ok_bool_true(Ret, "KeInsertQueueDpc returned");
143 ok_dpccount();
144 KeRaiseIrql(HIGH_LEVEL, &Irql3);
145 ok_dpccount();
146 KeLowerIrql(Irql3);
147 ok_dpccount();
148 Ret = KeRemoveQueueDpc(&Dpc);
149 ok_bool_true(Ret, "KeRemoveQueueDpc returned");
150 KeLowerIrql(Irql2);
151 ok_dpccount();
152 }
154 }
155
156 /* parameter checks */
158 _SEH2_TRY {
162 } _SEH2_END;
164
165 if (!skip(Status == STATUS_SUCCESS, "KeInitializeDpc failed\n") &&
167 {
168 // Inserting NULL in a DPC gives a TIMER_OR_DPC_INVALID bugcheck on Windows 8+.
170 Ret = KeInsertQueueDpc(&Dpc, NULL, NULL);
171 ok_bool_true(Ret, "KeInsertQueueDpc returned");
172 Ret = KeRemoveQueueDpc(&Dpc);
173 ok_bool_true(Ret, "KeRemoveQueueDpc returned");
175 }
176
178 _SEH2_TRY {
182 } _SEH2_END;
184
185 /* These result in IRQL_NOT_LESS_OR_EQUAL on 2k3 -- IRQLs 0x1f and 0xff (?)
186 Ret = KeInsertQueueDpc(NULL, NULL, NULL);
187 Ret = KeRemoveQueueDpc(NULL);*/
188
189 ok_dpccount();
190 ok_irql(PASSIVE_LEVEL);
191 trace("Final Dpc count: %ld, expected %ld\n", DpcCount, ExpectedDpcCount);
192}
#define ok_dpccount()
unsigned char BOOLEAN
#define ok_eq_hex(value, expected)
Definition: apitest.h:62
#define ok_bool_false(value, desc)
Definition: apitest.h:64
#define ok_bool_true(value, desc)
Definition: apitest.h:63
#define trace
Definition: atltest.h:70
LONG NTSTATUS
Definition: precomp.h:26
_Out_ PKIRQL Irql
Definition: csq.h:179
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
BOOLEAN NTAPI KeRemoveQueueDpc(IN PKDPC Dpc)
Definition: dpc.c:878
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
Status
Definition: gdiplustypes.h:25
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 EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
long LONG
Definition: pedump.c:60
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define memset(x, y, z)
Definition: compat.h:39
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: ketypes.h:699
Definition: typedefs.h:120
@ MediumImportance
Definition: ketypes.h:694

Variable Documentation

◆ DpcCount

volatile LONG DpcCount
static

Definition at line 15 of file KeDpc.c.

Referenced by DpcHandler(), and START_TEST().

◆ DpcHandler

KDEFERRED_ROUTINE DpcHandler
static

Definition at line 18 of file KeDpc.c.

Referenced by DpcHandler(), and START_TEST().

◆ DpcImportance

volatile UCHAR DpcImportance
static

Definition at line 16 of file KeDpc.c.

Referenced by DpcHandler(), and START_TEST().