ReactOS 0.4.15-dev-8235-gcd88a97
cmhook.c File Reference
#include "ntoskrnl.h"
#include "debug.h"
Include dependency graph for cmhook.c:

Go to the source code of this file.

Classes

struct  _REGISTRY_CALLBACK
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _REGISTRY_CALLBACK REGISTRY_CALLBACK
 
typedef struct _REGISTRY_CALLBACKPREGISTRY_CALLBACK
 

Functions

VOID NTAPI CmpInitCallback (VOID)
 
NTSTATUS CmiCallRegisteredCallbacks (IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
 
NTSTATUS NTAPI CmRegisterCallback (IN PEX_CALLBACK_FUNCTION Function, IN PVOID Context, IN OUT PLARGE_INTEGER Cookie)
 
NTSTATUS NTAPI CmUnRegisterCallback (IN LARGE_INTEGER Cookie)
 

Variables

ULONG CmpCallBackCount = 0
 
EX_CALLBACK CmpCallBackVector [100]
 
LIST_ENTRY CmiCallbackHead
 
FAST_MUTEX CmiCallbackLock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cmhook.c.

Typedef Documentation

◆ PREGISTRY_CALLBACK

◆ REGISTRY_CALLBACK

Function Documentation

◆ CmiCallRegisteredCallbacks()

NTSTATUS CmiCallRegisteredCallbacks ( IN REG_NOTIFY_CLASS  Argument1,
IN PVOID  Argument2 
)

Definition at line 59 of file cmhook.c.

61{
62 PLIST_ENTRY CurrentEntry;
64 PREGISTRY_CALLBACK CurrentCallback;
65 PAGED_CODE();
66
68
69 for (CurrentEntry = CmiCallbackHead.Flink;
70 CurrentEntry != &CmiCallbackHead;
71 CurrentEntry = CurrentEntry->Flink)
72 {
73 CurrentCallback = CONTAINING_RECORD(CurrentEntry, REGISTRY_CALLBACK, ListEntry);
74 if (!CurrentCallback->PendingDelete &&
75 ExAcquireRundownProtection(&CurrentCallback->RundownRef))
76 {
77 /* don't hold locks during the callbacks! */
79
80 Status = CurrentCallback->Function(CurrentCallback->Context,
82 Argument2);
83
85
86 /* don't release the rundown protection before holding the callback lock
87 so the pointer to the next callback isn't cleared in case this callback
88 get's deleted */
89 ExReleaseRundownProtection(&CurrentCallback->RundownRef);
90 if(!NT_SUCCESS(Status))
91 {
92 /* one callback returned failure, don't call any more callbacks */
93 break;
94 }
95 }
96 }
97
99
100 return Status;
101}
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
_In_ PVOID Argument2
Definition: classpnp.h:721
LIST_ENTRY CmiCallbackHead
Definition: cmhook.c:20
FAST_MUTEX CmiCallbackLock
Definition: cmhook.c:21
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExReleaseRundownProtection
Definition: ex.h:136
#define ExAcquireRundownProtection
Definition: ex.h:135
Status
Definition: gdiplustypes.h:25
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
EX_RUNDOWN_REF RundownRef
Definition: cmhook.c:26
PEX_CALLBACK_FUNCTION Function
Definition: cmhook.c:27
BOOLEAN PendingDelete
Definition: cmhook.c:30
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_IRQL_requires_same_ _In_opt_ PVOID Argument1
Definition: cmtypes.h:696

Referenced by CmpDeleteKeyObject(), NtDeleteKey(), NtDeleteValueKey(), NtEnumerateKey(), NtEnumerateValueKey(), NtQueryKey(), NtQueryValueKey(), and NtSetValueKey().

◆ CmpInitCallback()

VOID NTAPI CmpInitCallback ( VOID  )

Definition at line 38 of file cmhook.c.

39{
40 ULONG i;
41 PAGED_CODE();
42
43 /* Reset counter */
45
46 /* Loop all the callbacks */
47 for (i = 0; i < CMP_MAX_CALLBACKS; i++)
48 {
49 /* Initialize this one */
51 }
52
53 /* ROS: Initialize old-style callbacks for now */
56}
#define CMP_MAX_CALLBACKS
Definition: cm.h:72
EX_CALLBACK CmpCallBackVector[100]
Definition: cmhook.c:18
ULONG CmpCallBackCount
Definition: cmhook.c:17
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
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
VOID NTAPI ExInitializeCallBack(IN OUT PEX_CALLBACK Callback)
Definition: callback.c:46
uint32_t ULONG
Definition: typedefs.h:59
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274

Referenced by CmInitSystem1().

◆ CmRegisterCallback()

NTSTATUS NTAPI CmRegisterCallback ( IN PEX_CALLBACK_FUNCTION  Function,
IN PVOID  Context,
IN OUT PLARGE_INTEGER  Cookie 
)

Definition at line 110 of file cmhook.c.

113{
115 PAGED_CODE();
117
119 sizeof(REGISTRY_CALLBACK),
120 'bcMC');
121 if (Callback == NULL)
122 {
124 }
125
126 /* initialize the callback */
128 Callback->Function = Function;
129 Callback->Context = Context;
130 Callback->PendingDelete = FALSE;
131
132 /* add it to the callback list and receive a cookie for the callback */
134
135 /* FIXME - to receive a unique cookie we'll just return the pointer to the
136 callback object */
137 Callback->Cookie.QuadPart = (ULONG_PTR)Callback;
139
141
142 *Cookie = Callback->Cookie;
143 return STATUS_SUCCESS;
144}
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define ULONG_PTR
Definition: config.h:101
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define ExInitializeRundownProtection
Definition: ex.h:137
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:14

◆ CmUnRegisterCallback()

NTSTATUS NTAPI CmUnRegisterCallback ( IN LARGE_INTEGER  Cookie)

Definition at line 151 of file cmhook.c.

152{
153 PLIST_ENTRY CurrentEntry;
154 PREGISTRY_CALLBACK CurrentCallback;
155 PAGED_CODE();
156
158
159 for (CurrentEntry = CmiCallbackHead.Flink;
160 CurrentEntry != &CmiCallbackHead;
161 CurrentEntry = CurrentEntry->Flink)
162 {
163 CurrentCallback = CONTAINING_RECORD(CurrentEntry, REGISTRY_CALLBACK, ListEntry);
164 if (CurrentCallback->Cookie.QuadPart == Cookie.QuadPart)
165 {
166 if (!CurrentCallback->PendingDelete)
167 {
168 /* found the callback, don't unlink it from the list yet so we don't screw
169 the calling loop */
170 CurrentCallback->PendingDelete = TRUE;
172
173 /* if the callback is currently executing, wait until it finished */
175
176 /* time to unlink it. It's now safe because every attempt to acquire a
177 runtime protection on this callback will fail */
179 RemoveEntryList(&CurrentCallback->ListEntry);
181
182 /* free the callback */
183 ExFreePoolWithTag(CurrentCallback, 'bcMC');
184 return STATUS_SUCCESS;
185 }
186 else
187 {
188 /* pending delete, pretend like it already is deleted */
190 return STATUS_UNSUCCESSFUL;
191 }
192 }
193 }
194
196
197 return STATUS_UNSUCCESSFUL;
198}
#define TRUE
Definition: types.h:120
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define ExWaitForRundownProtectionRelease
Definition: ex.h:138
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
LARGE_INTEGER Cookie
Definition: cmhook.c:29
LIST_ENTRY ListEntry
Definition: cmhook.c:25
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
LONGLONG QuadPart
Definition: typedefs.h:114

Variable Documentation

◆ CmiCallbackHead

LIST_ENTRY CmiCallbackHead

◆ CmiCallbackLock

FAST_MUTEX CmiCallbackLock

◆ CmpCallBackCount

ULONG CmpCallBackCount = 0

Definition at line 17 of file cmhook.c.

Referenced by CmpInitCallback().

◆ CmpCallBackVector

EX_CALLBACK CmpCallBackVector[100]

Definition at line 18 of file cmhook.c.

Referenced by CmpInitCallback().