ReactOS 0.4.15-dev-7953-g1f49173
cmhook.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/config/cmhook.c
5 * PURPOSE: Configuration Manager - Registry Notifications/Callbacks
6 * PROGRAMMERS: Thomas Weidenmueller (w3seek@reactos.org)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "ntoskrnl.h"
12#define NDEBUG
13#include "debug.h"
14
15/* GLOBALS *******************************************************************/
16
19
22
23typedef struct _REGISTRY_CALLBACK
24{
32
33/* PRIVATE FUNCTIONS *********************************************************/
34
35CODE_SEG("INIT")
36VOID
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}
57
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}
102
103/* PUBLIC FUNCTIONS **********************************************************/
104
105/*
106 * @implemented
107 */
109NTAPI
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}
145
146/*
147 * @implemented
148 */
150NTAPI
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 PAGED_CODE()
#define CODE_SEG(...)
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
_In_ PVOID Argument2
Definition: classpnp.h:721
#define CMP_MAX_CALLBACKS
Definition: cm.h:72
LIST_ENTRY CmiCallbackHead
Definition: cmhook.c:20
VOID NTAPI CmpInitCallback(VOID)
Definition: cmhook.c:38
FAST_MUTEX CmiCallbackLock
Definition: cmhook.c:21
struct _REGISTRY_CALLBACK REGISTRY_CALLBACK
EX_CALLBACK CmpCallBackVector[100]
Definition: cmhook.c:18
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
struct _REGISTRY_CALLBACK * PREGISTRY_CALLBACK
NTSTATUS NTAPI CmRegisterCallback(IN PEX_CALLBACK_FUNCTION Function, IN PVOID Context, IN OUT PLARGE_INTEGER Cookie)
Definition: cmhook.c:110
NTSTATUS NTAPI CmUnRegisterCallback(IN LARGE_INTEGER Cookie)
Definition: cmhook.c:151
ULONG CmpCallBackCount
Definition: cmhook.c:17
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ULONG_PTR
Definition: config.h:101
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define PagedPool
Definition: env_spec_w32.h:308
#define ExWaitForRundownProtectionRelease
Definition: ex.h:138
#define ExReleaseRundownProtection
Definition: ex.h:136
#define ExInitializeRundownProtection
Definition: ex.h:137
#define ExAcquireRundownProtection
Definition: ex.h:135
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
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
VOID NTAPI ExInitializeCallBack(IN OUT PEX_CALLBACK Callback)
Definition: callback.c:46
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LARGE_INTEGER Cookie
Definition: cmhook.c:29
LIST_ENTRY ListEntry
Definition: cmhook.c:25
EX_RUNDOWN_REF RundownRef
Definition: cmhook.c:26
PEX_CALLBACK_FUNCTION Function
Definition: cmhook.c:27
BOOLEAN PendingDelete
Definition: cmhook.c:30
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:14
enum _REG_NOTIFY_CLASS REG_NOTIFY_CLASS
_IRQL_requires_same_ _In_opt_ PVOID Argument1
Definition: cmtypes.h:696
EX_CALLBACK_FUNCTION * PEX_CALLBACK_FUNCTION
Definition: cmtypes.h:698
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
FAST_MUTEX
Definition: extypes.h:17