ReactOS 0.4.15-dev-7788-g1ad9096
Object.c
Go to the documentation of this file.
1/*
2* PROJECT: Filesystem Filter Manager
3* LICENSE: GPL - See COPYING in the top level directory
4* FILE: drivers/filters/fltmgr/Object.c
5* PURPOSE: Miscellaneous library functions
6* PROGRAMMERS: Ged Murphy (gedmurphy@reactos.org)
7*/
8
9// NOTE: Split this file into filter object and device object functions
10// when the code base grows sufficiently
11
12/* INCLUDES ******************************************************************/
13
14#include "fltmgr.h"
15#include "fltmgrint.h"
16
17#define NDEBUG
18#include <debug.h>
19
20
21/* DATA *********************************************************************/
22
23#define ExpChangePushlock(x, y, z) InterlockedCompareExchangePointer((PVOID*)x, (PVOID)y, (PVOID)z)
24
25//
26// Pushlock bits
27//
28#define EX_PUSH_LOCK_LOCK_V ((ULONG_PTR)0x0)
29#define EX_PUSH_LOCK_LOCK ((ULONG_PTR)0x1)
30#define EX_PUSH_LOCK_WAITING ((ULONG_PTR)0x2)
31#define EX_PUSH_LOCK_WAKING ((ULONG_PTR)0x4)
32#define EX_PUSH_LOCK_MULTIPLE_SHARED ((ULONG_PTR)0x8)
33#define EX_PUSH_LOCK_SHARE_INC ((ULONG_PTR)0x10)
34#define EX_PUSH_LOCK_PTR_BITS ((ULONG_PTR)0xf)
35
36/* EXPORTED FUNCTIONS ******************************************************/
37
38
40FLTAPI
42{
44 {
46 }
47
48 return STATUS_SUCCESS;
49}
50
51VOID
52FLTAPI
54{
56}
57
58
59_Acquires_lock_(_Global_critical_region_)
61VOID
62FLTAPI
63FltAcquirePushLockExclusive(_Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_lock_(*_Curr_) PEX_PUSH_LOCK PushLock)
64{
66
67 /* Try acquiring the lock */
69 {
70 /* Someone changed it, use the slow path */
72 }
73
74 /* Sanity check */
75 FLT_ASSERT(PushLock->Locked);
76}
77
78
79_Acquires_lock_(_Global_critical_region_)
81VOID
82FLTAPI
83FltAcquirePushLockShared(_Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_lock_(*_Curr_) PEX_PUSH_LOCK PushLock)
84{
85 EX_PUSH_LOCK NewValue;
86
88
89 /* Try acquiring the lock */
91 if (ExpChangePushlock(PushLock, NewValue.Ptr, 0))
92 {
93 /* Someone changed it, use the slow path */
95 }
96
97 /* Sanity checks */
98 ASSERT(PushLock->Locked);
99}
100
101_Releases_lock_(_Global_critical_region_)
103VOID
104FLTAPI
105FltReleasePushLock(_Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_) PEX_PUSH_LOCK PushLock)
106{
107 EX_PUSH_LOCK OldValue = *PushLock;
108 EX_PUSH_LOCK NewValue;
109
110 /* Sanity checks */
111 FLT_ASSERT(OldValue.Locked);
112
113 /* Check if the pushlock is shared */
114 if (OldValue.Shared > 1)
115 {
116 /* Decrease the share count */
117 NewValue.Value = OldValue.Value - EX_PUSH_LOCK_SHARE_INC;
118 }
119 else
120 {
121 /* Clear the pushlock entirely */
122 NewValue.Value = 0;
123 }
124
125 /* Check if nobody is waiting on us and try clearing the lock here */
126 if ((OldValue.Waiting) ||
127 (ExpChangePushlock(PushLock, NewValue.Ptr, OldValue.Ptr) !=
128 OldValue.Ptr))
129 {
130 /* We have waiters, use the long path */
131 ExfReleasePushLock(PushLock);
132 }
133
135}
136
139FLTAPI
140FltClose(_In_ HANDLE FileHandle)
141{
142 PAGED_CODE();
143
144 return ZwClose(FileHandle);
145}
146
150FLTAPI
151FltCreateFileEx(_In_ PFLT_FILTER Filter,
166{
169}
170
174FLTAPI
175FltCreateFile(_In_ PFLT_FILTER Filter,
189{
190 return FltCreateFileEx(Filter,
191 Instance,
193 NULL,
202 EaBuffer,
203 EaLength,
204 Flags);
205}
206
207
208
209/* INTERNAL FUNCTIONS ******************************************************/
210
211VOID
213{
215}
216
219{
220 return ExAcquireRundownProtection(RundownRef);
221}
222
225{
226 ExReleaseRundownProtection(RundownRef);
227 return TRUE;
228}
229
232{
233 return _InterlockedExchange((PLONG)RundownRef, 1);
234}
235
237NTAPI
239{
240 //return FltpExWaitForRundownProtectionRelease(RundownRef);
241 return 0;
242}
243
247{
248 PDEVICE_OBJECT BaseDeviceObject;
250
251 /*
252 * Get the lowest device object on the stack, which may be the
253 * object we were passed, and lookup the name for that object
254 */
255 BaseDeviceObject = IoGetDeviceAttachmentBaseRef(DeviceObject);
256 Status = FltpGetObjectName(BaseDeviceObject, ObjectName);
257 ObDereferenceObject(BaseDeviceObject);
258
259 return Status;
260}
261
265{
266 OBJECT_NAME_INFORMATION LocalNameInfo;
267 POBJECT_NAME_INFORMATION ObjectNameInfo = &LocalNameInfo;
270
271 if (ObjectName == NULL)
273
274 /* Get the size of the buffer required to hold the nameinfo */
276 &LocalNameInfo,
277 sizeof(LocalNameInfo),
278 &ReturnLength);
280 {
281 ObjectNameInfo = ExAllocatePoolWithTag(PagedPool,
284 if (ObjectNameInfo == NULL) return STATUS_INSUFFICIENT_RESOURCES;
285
286 /* Get the actual name info now we have the buffer to hold it */
288 ObjectNameInfo,
290 &ReturnLength);
291 }
292
293
294 if (NT_SUCCESS(Status))
295 {
296 /* Make sure the buffer we were passed is large enough to hold the string */
297 if (ObjectName->MaximumLength < ObjectNameInfo->Name.Length)
298 {
299 /* It wasn't, let's enlarge the buffer */
301 ObjectNameInfo->Name.Length,
302 FALSE);
303
304 }
305
306 if (NT_SUCCESS(Status))
307 {
308 /* Copy the object name into the callers buffer */
309 RtlCopyUnicodeString(ObjectName, &ObjectNameInfo->Name);
310 }
311 }
312
313 if (ObjectNameInfo != &LocalNameInfo)
314 {
316 }
317
318 return Status;
319}
320
321ULONG
323{
325
326 /* Store the old count and increment */
327 Result = &Object->PointerCount;
328 InterlockedIncrementSizeT(&Object->PointerCount);
329
330 /* Return the initial value */
331 return *Result;
332}
333
334VOID
336{
337 if (InterlockedDecrementSizeT(&Object->PointerCount) == 0)
338 {
339 // Cleanup
341 }
342}
#define PAGED_CODE()
VOID FltpObjectPointerDereference(_In_ PFLT_OBJECT Object)
Definition: Object.c:335
BOOLEAN FltpExAcquireRundownProtection(_Inout_ PEX_RUNDOWN_REF RundownRef)
Definition: Object.c:218
BOOLEAN FltpExRundownCompleted(_Inout_ PEX_RUNDOWN_REF RundownRef)
Definition: Object.c:231
NTSTATUS FltpGetObjectName(_In_ PVOID Object, _Inout_ PUNICODE_STRING ObjectName)
Definition: Object.c:263
ULONG FltpObjectPointerReference(_In_ PFLT_OBJECT Object)
Definition: Object.c:322
#define EX_PUSH_LOCK_SHARE_INC
Definition: Object.c:33
#define EX_PUSH_LOCK_LOCK
Definition: Object.c:29
#define EX_PUSH_LOCK_LOCK_V
Definition: Object.c:28
VOID FLTAPI FltObjectDereference(_Inout_ PVOID Object)
Definition: Object.c:53
BOOLEAN FltpExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RundownRef)
Definition: Object.c:224
VOID FltpExInitializeRundownProtection(_Out_ PEX_RUNDOWN_REF RundownRef)
Definition: Object.c:212
NTSTATUS NTAPI FltpObjectRundownWait(_Inout_ PEX_RUNDOWN_REF RundownRef)
Definition: Object.c:238
#define ExpChangePushlock(x, y, z)
Definition: Object.c:23
NTSTATUS FltpGetBaseDeviceObjectName(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PUNICODE_STRING ObjectName)
Definition: Object.c:245
NTSTATUS FLTAPI FltObjectReference(_Inout_ PVOID Object)
Definition: Object.c:41
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define UNIMPLEMENTED
Definition: debug.h:115
#define _Acquires_lock_(lock)
#define _Requires_lock_held_(lock)
#define _Requires_lock_not_held_(lock)
#define _Releases_lock_(lock)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#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
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT ShareAccess
Definition: create.c:4147
#define _IRQL_requires_max_(irql)
Definition: driverspecs.h:230
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define PagedPool
Definition: env_spec_w32.h:308
#define ExReleaseRundownProtection
Definition: ex.h:136
#define ExInitializeRundownProtection
Definition: ex.h:137
#define ExAcquireRundownProtection
Definition: ex.h:135
IN PVCB IN PDIRENT OUT PULONG EaLength
Definition: fatprocs.h:878
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:322
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1236
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1801
#define FLT_ASSERT(_e)
Definition: fltkernel.h:49
NTSTATUS FltpReallocateUnicodeString(_In_ PUNICODE_STRING String, _In_ SIZE_T NewLength, _In_ BOOLEAN CopyExisting)
Definition: Lib.c:39
#define FM_TAG_UNICODE_STRING
Definition: fltmgr.h:20
Status
Definition: gdiplustypes.h:25
#define InterlockedDecrementSizeT(a)
Definition: interlocked.h:153
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
#define InterlockedIncrementSizeT(a)
Definition: interlocked.h:220
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define _Inout_
Definition: ms_sal.h:378
#define _Outptr_opt_
Definition: ms_sal.h:429
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define _In_reads_bytes_opt_(size)
Definition: ms_sal.h:322
#define _In_opt_
Definition: ms_sal.h:309
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
ULONG ACCESS_MASK
Definition: nt_native.h:40
PDEVICE_OBJECT NTAPI IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1419
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_FLT_DELETING_OBJECT
Definition: ntstatus.h:1432
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
NTSTATUS NTAPI ObQueryNameString(IN PVOID Object, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength)
Definition: obname.c:1207
VOID FASTCALL ExfReleasePushLock(PEX_PUSH_LOCK PushLock)
Definition: pushlock.c:810
VOID FASTCALL ExfAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: pushlock.c:471
VOID FASTCALL ExfAcquirePushLockShared(PEX_PUSH_LOCK PushLock)
Definition: pushlock.c:645
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG_PTR Value
Definition: extypes.h:465
PVOID Ptr
Definition: extypes.h:466
ULONG_PTR Waiting
Definition: extypes.h:460
ULONG_PTR Shared
Definition: extypes.h:463
ULONG_PTR Locked
Definition: extypes.h:459
UNICODE_STRING Name
Definition: nt_native.h:1270
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
int32_t * PLONG
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:120
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_opt_ WDFWMIINSTANCE * Instance
Definition: wdfwmi.h:481
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG _In_opt_ PVOID EaBuffer
Definition: iofuncs.h:845
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ObDereferenceObject
Definition: obfuncs.h:203