ReactOS 0.4.16-dev-959-g2ec3a19
ldrnotify.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS NT Layer/System API
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: DLL Load Notification Implementation
5 * COPYRIGHT: Copyright 2024 Ratin Gao <ratin@knsoft.org>
6 */
7
8#include "ntdll_vista.h"
9
10/* GLOBALS *******************************************************************/
11
13{
18
19static RTL_STATIC_LIST_HEAD(LdrpDllNotificationList);
20
21/* Initialize critical section statically */
25};
28 -1,
29 0,
30 0,
31 0,
32 0
33};
34
35/* FUNCTIONS *****************************************************************/
36
41 _In_ PLDR_DLL_NOTIFICATION_FUNCTION NotificationFunction,
44{
46
47 /* Check input parameters */
48 if (Flags != 0 || NotificationFunction == NULL || Cookie == NULL)
49 {
51 }
52
53 /* Allocate new entry and assign input values */
54 NewEntry = RtlAllocateHeap(LdrpHeap, 0, sizeof(*NewEntry));
55 if (NewEntry == NULL)
56 {
57 return STATUS_NO_MEMORY;
58 }
59 NewEntry->Callback = NotificationFunction;
60 NewEntry->Context = Context;
61
62 /* Add node to the end of global list */
64 InsertTailList(&LdrpDllNotificationList, &NewEntry->List);
66
67 /* Cookie is address of the new entry */
68 *Cookie = NewEntry;
69 return STATUS_SUCCESS;
70}
71
76{
79
80 /* Find entry to remove */
82 for (Entry = LdrpDllNotificationList.Flink;
83 Entry != &LdrpDllNotificationList;
84 Entry = Entry->Flink)
85 {
86 if (Entry == Cookie)
87 {
90 break;
91 }
92 }
94
95 if (NT_SUCCESS(Status))
96 {
98 }
99 return Status;
100}
101
102VOID
103NTAPI
106 _In_ ULONG NotificationReason)
107{
111
112 /*
113 * LDR_DLL_LOADED_NOTIFICATION_DATA and LDR_DLL_UNLOADED_NOTIFICATION_DATA
114 * currently are the same. Use C_ASSERT to ensure it, then fill either of them.
115 */
116#define LdrpAssertDllNotificationDataMember(x)\
117 C_ASSERT(FIELD_OFFSET(LDR_DLL_NOTIFICATION_DATA, Loaded.x) ==\
118 FIELD_OFFSET(LDR_DLL_NOTIFICATION_DATA, Unloaded.x))
119
120 C_ASSERT(sizeof(NotificationData.Loaded) == sizeof(NotificationData.Unloaded));
126
127#undef LdrpAssertDllNotificationDataMember
128
129 NotificationData.Loaded.Flags = 0; /* Reserved and always 0, not DllEntry->Flags */
130 NotificationData.Loaded.FullDllName = &DllEntry->FullDllName;
131 NotificationData.Loaded.BaseDllName = &DllEntry->BaseDllName;
132 NotificationData.Loaded.DllBase = DllEntry->DllBase;
133 NotificationData.Loaded.SizeOfImage = DllEntry->SizeOfImage;
134
135 /* Send notification to all registered callbacks */
138 {
139 for (Entry = LdrpDllNotificationList.Flink;
140 Entry != &LdrpDllNotificationList;
141 Entry = Entry->Flink)
142 {
144 NotificationEntry->Callback(NotificationReason,
146 NotificationEntry->Context);
147 }
148 }
150 {
152 }
153 _SEH2_END;
154}
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
Status
Definition: gdiplustypes.h:25
#define C_ASSERT(e)
Definition: intsafe.h:73
struct _LDR_DLL_NOTIFICATION_ENTRY * PLDR_DLL_NOTIFICATION_ENTRY
static RTL_CRITICAL_SECTION_DEBUG LdrpDllNotificationLockDebug
Definition: ldrnotify.c:23
#define LdrpAssertDllNotificationDataMember(x)
NTSTATUS NTAPI LdrUnregisterDllNotification(_In_ PVOID Cookie)
Definition: ldrnotify.c:74
struct _LDR_DLL_NOTIFICATION_ENTRY LDR_DLL_NOTIFICATION_ENTRY
static RTL_CRITICAL_SECTION LdrpDllNotificationLock
Definition: ldrnotify.c:22
VOID NTAPI LdrpSendDllNotifications(_In_ PLDR_DATA_TABLE_ENTRY DllEntry, _In_ ULONG NotificationReason)
Definition: ldrnotify.c:104
NTSTATUS NTAPI LdrRegisterDllNotification(_In_ ULONG Flags, _In_ PLDR_DLL_NOTIFICATION_FUNCTION NotificationFunction, _In_opt_ PVOID Context, _Out_ PVOID *Cookie)
Definition: ldrnotify.c:39
_In_ PCWSTR FullDllName
Definition: ldrtypes.h:264
VOID(NTAPI * PLDR_DLL_NOTIFICATION_FUNCTION)(_In_ ULONG NotificationReason, _In_ PCLDR_DLL_NOTIFICATION_DATA NotificationData, _In_opt_ PVOID Context)
Definition: ldrtypes.h:232
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
PVOID LdrpHeap
Definition: ldrinit.c:3
#define STATUS_DLL_NOT_FOUND
Definition: ntstatus.h:545
#define _SEH2_FINALLY
Definition: pseh2_64.h:130
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define STATUS_SUCCESS
Definition: shellext.h:65
base of all file and directory entries
Definition: entries.h:83
Definition: btrfs_drv.h:1876
Definition: ldrnotify.c:13
PVOID Context
Definition: ldrnotify.c:16
LIST_ENTRY List
Definition: ldrnotify.c:14
PLDR_DLL_NOTIFICATION_FUNCTION Callback
Definition: ldrnotify.c:15
Definition: typedefs.h:120
struct _RTL_CRITICAL_SECTION * CriticalSection
Definition: rtltypes.h:1422
#define NTAPI
Definition: typedefs.h:36
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PCWDF_DEVICE_PNP_NOTIFICATION_DATA NotificationData
Definition: wdfdevice.h:782
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:14
_In_ ULONG _In_opt_ PVOID _In_ PDRIVER_OBJECT _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE _Inout_opt_ __drv_aliasesMem PVOID _Outptr_result_nullonfailure_ _At_ * NotificationEntry(return==0, __drv_allocatesMem(Mem))) PVOID *NotificationEntry
#define RTL_STATIC_LIST_HEAD(x)
Definition: rtlfuncs.h:47