ReactOS  0.4.14-dev-599-g2d4d3f5
ExCallback.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite Executive Callback test
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 
10 static
12 (NTAPI
16 )
17 //= (PVOID)0x809af1f4 // 2003 sp1 x86
18 //= (PVOID)0x80a7f04a // 2003 sp1 x86 checked
19 ;
20 
21 static
22 VOID
23 (NTAPI
25  IN PEX_CALLBACK_ROUTINE_BLOCK CallbackBlock
26 )
27 //= (PVOID)0x80918bb5 // 2003 sp1 x86
28 //= (PVOID)0x80a355f0 // 2003 sp1 x86 checked
29 ;
30 
33 
34 static
36 NTAPI
41 {
42  ok(0, "Callback function unexpectedly called\n");
43  return STATUS_SUCCESS;
44 }
45 
46 static
47 VOID
49 {
50  UNICODE_STRING ExAllocateCallBackName = RTL_CONSTANT_STRING(L"ExAllocateCallBack");
51  UNICODE_STRING ExFreeCallBackName = RTL_CONSTANT_STRING(L"ExFreeCallBack");
52  PEX_CALLBACK_ROUTINE_BLOCK CallbackBlock;
54 
55  if (!ExAllocateCallBack)
56  ExAllocateCallBack = MmGetSystemRoutineAddress(&ExAllocateCallBackName);
57  if (!ExFreeCallBack)
58  ExFreeCallBack = MmGetSystemRoutineAddress(&ExFreeCallBackName);
59 
61  "ExAllocateCallBack and/or ExFreeCallBack unavailable\n"))
62  return;
63 
65  ok(CallbackBlock != NULL, "CallbackBlock = NULL\n");
66 
67  if (skip(CallbackBlock != NULL, "Allocating callback failed\n"))
68  return;
69 
70  ok_eq_pointer(CallbackBlock->Function, ExCallbackFunction);
71  ok_eq_pointer(CallbackBlock->Context, &CallbackContext);
72  ok_eq_hex(KmtGetPoolTag(CallbackBlock), 'brbC');
73 
74  ExFreeCallBack(CallbackBlock);
75 }
76 
77 static
78 VOID
79 NTAPI
84 {
85  INT *InvocationCount = CallbackContext;
86 
87  ok_irql(PASSIVE_LEVEL);
88 
89  (*InvocationCount)++;
92 }
93 
94 START_TEST(ExCallback)
95 {
97  PCALLBACK_OBJECT CallbackObject;
99  UNICODE_STRING CallbackName = RTL_CONSTANT_STRING(L"\\Callback\\KmtestExCallbackTestCallback");
100  PVOID CallbackRegistration;
101  INT InvocationCount = 0;
102 
104 
105  /* TODO: Parameter tests */
106  /* TODO: Test the three predefined callbacks */
107  /* TODO: Test opening an existing callback */
108  /* TODO: Test AllowMultipleCallbacks */
109  /* TODO: Test calling multiple callbacks */
110  /* TODO: Test registering the same function twice */
111  /* TODO: Test callback object fields */
112  /* TODO: Test callback registration fields */
114  &CallbackName,
116  NULL,
117  NULL);
118 
119  CallbackObject = KmtInvalidPointer;
120  Status = ExCreateCallback(&CallbackObject,
122  TRUE,
123  TRUE);
125  ok(CallbackObject != NULL && CallbackObject != KmtInvalidPointer,
126  "CallbackObject = %p", CallbackObject);
127 
128  if (skip(NT_SUCCESS(Status), "Creating callback failed\n"))
129  return;
130 
131  CallbackRegistration = ExRegisterCallback(CallbackObject,
133  &InvocationCount);
134  ok(CallbackRegistration != NULL, "CallbackRegistration = NULL\n");
135 
136  if (!skip(CallbackRegistration != NULL, "Registering callback failed\n"))
137  {
138  ok_eq_hex(KmtGetPoolTag(CallbackRegistration), 'eRBC');
139  ok_eq_int(InvocationCount, 0);
140  ExNotifyCallback(CallbackObject,
143  ok_eq_int(InvocationCount, 1);
144  ExNotifyCallback(CallbackObject,
147  ok_eq_int(InvocationCount, 2);
148 
149  ExUnregisterCallback(CallbackRegistration);
150  }
151 
152  ObDereferenceObject(CallbackObject);
153 }
PEX_CALLBACK_ROUTINE_BLOCK NTAPI ExAllocateCallBack(IN PEX_CALLBACK_FUNCTION Function, IN PVOID Context)
Definition: callback.c:54
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
#define KmtInvalidPointer
Definition: kmt_test.h:275
#define TRUE
Definition: types.h:120
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
_IRQL_requires_same_ _In_opt_ PVOID Argument1
Definition: cmtypes.h:694
#define ok_eq_int(value, expected)
Definition: kmt_test.h:238
#define ok_eq_pointer(value, expected)
START_TEST(ExCallback)
Definition: ExCallback.c:94
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ExCreateCallback(OUT PCALLBACK_OBJECT *CallbackObject, IN POBJECT_ATTRIBUTES ObjectAttributes, IN BOOLEAN Create, IN BOOLEAN AllowMultipleCallbacks)
Definition: callback.c:361
static INT CallbackArgument1
Definition: ExCallback.c:31
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
static VOID NTAPI CallbackFunction(IN PVOID CallbackContext, IN PVOID Argument1, IN PVOID Argument2)
Definition: ExCallback.c:80
int32_t INT
Definition: typedefs.h:56
PEX_CALLBACK_FUNCTION Function
Definition: extypes.h:538
VOID NTAPI ExUnregisterCallback(IN PVOID CallbackRegistrationHandle)
Definition: callback.c:636
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3417
static VOID TestPrivateFunctions(VOID)
Definition: ExCallback.c:48
smooth NULL
Definition: ftsmooth.c:416
static INT CallbackArgument2
Definition: ExCallback.c:32
_In_ PVOID Argument2
Definition: classpnp.h:680
VOID NTAPI ExNotifyCallback(IN PCALLBACK_OBJECT CallbackObject, IN PVOID Argument1, IN PVOID Argument2)
Definition: callback.c:467
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
static NTSTATUS NTAPI ExCallbackFunction(IN PVOID CallbackContext, IN PVOID Argument1 OPTIONAL, IN PVOID Argument2 OPTIONAL)
Definition: ExCallback.c:37
static VOID(NTAPI *ExFreeCallBack)(IN PEX_CALLBACK_ROUTINE_BLOCK CallbackBlock)
ULONG KmtGetPoolTag(PVOID Memory)
#define ok(value,...)
Definition: atltest.h:57
static IN PVOID Context
Definition: ExCallback.c:19
static PEX_CALLBACK_ROUTINE_BLOCK(NTAPI *ExAllocateCallBack)(IN PEX_CALLBACK_FUNCTION Function
VOID NTAPI ExFreeCallBack(IN PEX_CALLBACK_ROUTINE_BLOCK CallbackBlock)
Definition: callback.c:77
#define skip(...)
Definition: atltest.h:64
EX_CALLBACK_FUNCTION * PEX_CALLBACK_FUNCTION
Definition: cmtypes.h:696
PVOID NTAPI ExRegisterCallback(IN PCALLBACK_OBJECT CallbackObject, IN PCALLBACK_FUNCTION CallbackFunction, IN PVOID CallbackContext)
Definition: callback.c:556
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ok_eq_hex(value, expected)
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68