ReactOS 0.4.16-dev-106-g10b08aa
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 /* this DPC is not in the list anymore, but it was at the head! */
59 ok_eq_pointer(Prcb->DpcData[DPC_NORMAL].DpcListHead.Flink, Dpc->DpcListEntry.Flink);
60 ok_eq_pointer(Prcb->DpcData[DPC_NORMAL].DpcListHead.Blink, Dpc->DpcListEntry.Blink);
61}
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:59
#define ok_eq_uint(value, expected)
Definition: apitest.h:61
#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:1161
@ DpcObject
Definition: ketypes.h:425
KDPC_DATA DpcData[2]
Definition: ketypes.h:760
UCHAR DpcRoutineActive
Definition: ketypes.h:772
_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 63 of file KeDpc.c.

64{
66 KDPC Dpc;
67 KIRQL Irql, Irql2, Irql3;
68 LONG ExpectedDpcCount = 0;
69 BOOLEAN Ret;
70 int i;
71
72 DpcCount = 0;
74
75#define ok_dpccount() ok(DpcCount == ExpectedDpcCount, "DpcCount = %ld, expected %ld\n", DpcCount, ExpectedDpcCount);
76 trace("Dpc = %p\n", &Dpc);
77 memset(&Dpc, 0x55, sizeof Dpc);
79 /* check the Dpc object's fields */
81 ok_eq_uint(Dpc.Importance, DpcImportance);
82 ok_eq_uint(Dpc.Number, 0);
83 ok_eq_pointer(Dpc.DpcListEntry.Flink, (LIST_ENTRY *)0x5555555555555555LL);
84 ok_eq_pointer(Dpc.DpcListEntry.Blink, (LIST_ENTRY *)0x5555555555555555LL);
85 ok_eq_pointer(Dpc.DeferredRoutine, DpcHandler);
86 ok_eq_pointer(Dpc.DeferredContext, &Dpc);
87 ok_eq_pointer(Dpc.SystemArgument1, (PVOID)0x5555555555555555LL);
88 ok_eq_pointer(Dpc.SystemArgument2, (PVOID)0x5555555555555555LL);
89 ok_eq_pointer(Dpc.DpcData, NULL);
90
91 /* simply run the Dpc a few times */
92 for (i = 0; i < 5; ++i)
93 {
95 Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
96 ok_bool_true(Ret, "KeInsertQueueDpc returned");
97 ++ExpectedDpcCount;
99 }
100
101 /* insert into queue at high irql
102 * -> should only run when lowered to APC_LEVEL,
103 * inserting a second time should fail
104 */
106 for (i = 0; i < 5; ++i)
107 {
109 ok_dpccount();
110 Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
111 ok_bool_true(Ret, "KeInsertQueueDpc returned");
112 Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xdef, (PVOID)0x123);
113 ok_bool_false(Ret, "KeInsertQueueDpc returned");
114 ok_dpccount();
115 KeRaiseIrql(HIGH_LEVEL, &Irql3);
116 ok_dpccount();
117 KeLowerIrql(Irql3);
118 ok_dpccount();
119 KeLowerIrql(Irql2);
120 ++ExpectedDpcCount;
121 ok_dpccount();
122 }
124
125 /* now test removing from the queue */
127 for (i = 0; i < 5; ++i)
128 {
130 ok_dpccount();
131 Ret = KeRemoveQueueDpc(&Dpc);
132 ok_bool_false(Ret, "KeRemoveQueueDpc returned");
133 Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
134 ok_bool_true(Ret, "KeInsertQueueDpc returned");
135 ok_dpccount();
136 KeRaiseIrql(HIGH_LEVEL, &Irql3);
137 ok_dpccount();
138 KeLowerIrql(Irql3);
139 ok_dpccount();
140 Ret = KeRemoveQueueDpc(&Dpc);
141 ok_bool_true(Ret, "KeRemoveQueueDpc returned");
142 KeLowerIrql(Irql2);
143 ok_dpccount();
144 }
146
147 /* parameter checks */
149 _SEH2_TRY {
153 } _SEH2_END;
155
156 if (!skip(Status == STATUS_SUCCESS, "KeInitializeDpc failed\n"))
157 {
159 Ret = KeInsertQueueDpc(&Dpc, NULL, NULL);
160 ok_bool_true(Ret, "KeInsertQueueDpc returned");
161 Ret = KeRemoveQueueDpc(&Dpc);
162 ok_bool_true(Ret, "KeRemoveQueueDpc returned");
164 }
165
167 _SEH2_TRY {
171 } _SEH2_END;
173
174 /* These result in IRQL_NOT_LESS_OR_EQUAL on 2k3 -- IRQLs 0x1f and 0xff (?)
175 Ret = KeInsertQueueDpc(NULL, NULL, NULL);
176 Ret = KeRemoveQueueDpc(NULL);*/
177
178 ok_dpccount();
179 ok_irql(PASSIVE_LEVEL);
180 trace("Final Dpc count: %ld, expected %ld\n", DpcCount, ExpectedDpcCount);
181}
#define ok_dpccount()
unsigned char BOOLEAN
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_bool_false(value, desc)
Definition: apitest.h:79
#define ok_bool_true(value, desc)
Definition: apitest.h:78
#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
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
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:85
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
long LONG
Definition: pedump.c:60
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define memset(x, y, z)
Definition: compat.h:39
#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().