ReactOS  0.4.12-dev-916-gffc4e30
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

INIT_FUNCTION 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 }
_IRQL_requires_same_ _In_opt_ PVOID Argument1
Definition: cmtypes.h:694
NTKERNELAPI VOID FASTCALL ExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RunRef)
LONG NTSTATUS
Definition: precomp.h:26
#define ExAcquireRundownProtection
Definition: ex.h:130
BOOLEAN PendingDelete
Definition: cmhook.c:30
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define PAGED_CODE()
Definition: video.h:57
EX_RUNDOWN_REF RundownRef
Definition: cmhook.c:26
LIST_ENTRY CmiCallbackHead
Definition: cmhook.c:20
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_In_ PVOID Argument2
Definition: classpnp.h:680
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FAST_MUTEX CmiCallbackLock
Definition: cmhook.c:21
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
return STATUS_SUCCESS
Definition: btrfs.c:2725
PEX_CALLBACK_FUNCTION Function
Definition: cmhook.c:27

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

◆ CmpInitCallback()

INIT_FUNCTION VOID NTAPI CmpInitCallback ( VOID  )

Definition at line 38 of file cmhook.c.

39 {
40  ULONG i;
41  PAGED_CODE();
42 
43  /* Reset counter */
44  CmpCallBackCount = 0;
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 }
VOID NTAPI ExInitializeCallBack(IN OUT PEX_CALLBACK Callback)
Definition: callback.c:46
#define CMP_MAX_CALLBACKS
Definition: cm.h:79
#define PAGED_CODE()
Definition: video.h:57
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
LIST_ENTRY CmiCallbackHead
Definition: cmhook.c:20
EX_CALLBACK CmpCallBackVector[100]
Definition: cmhook.c:18
FAST_MUTEX CmiCallbackLock
Definition: cmhook.c:21
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
ULONG CmpCallBackCount
Definition: cmhook.c:17
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int ULONG
Definition: retypes.h:1

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();
116  ASSERT(Function && Cookie);
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;
138  InsertTailList(&CmiCallbackHead, &Callback->ListEntry);
139 
141 
142  *Cookie = Callback->Cookie;
143  return STATUS_SUCCESS;
144 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define InsertTailList(ListHead, Entry)
NTKERNELAPI VOID FASTCALL ExInitializeRundownProtection(_Out_ PEX_RUNDOWN_REF RunRef)
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define PAGED_CODE()
Definition: video.h:57
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY CmiCallbackHead
Definition: cmhook.c:20
FAST_MUTEX CmiCallbackLock
Definition: cmhook.c:21
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:13
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
struct tagContext Context
Definition: acpixf.h:1012
#define ULONG_PTR
Definition: config.h:101
return STATUS_SUCCESS
Definition: btrfs.c:2725
LPFNPSPCALLBACK Callback
Definition: desk.c:111

◆ 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
BOOLEAN PendingDelete
Definition: cmhook.c:30
LARGE_INTEGER Cookie
Definition: cmhook.c:29
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define PAGED_CODE()
Definition: video.h:57
EX_RUNDOWN_REF RundownRef
Definition: cmhook.c:26
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
LIST_ENTRY CmiCallbackHead
Definition: cmhook.c:20
NTKERNELAPI VOID FASTCALL ExWaitForRundownProtectionRelease(_Inout_ PEX_RUNDOWN_REF RunRef)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY ListEntry
Definition: cmhook.c:25
FAST_MUTEX CmiCallbackLock
Definition: cmhook.c:21
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:13
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Definition: typedefs.h:117
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2725
LONGLONG QuadPart
Definition: typedefs.h:112

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().