ReactOS  0.4.14-dev-77-gd9e7c48
Object.c File Reference
#include "fltmgr.h"
#include "fltmgrint.h"
#include <debug.h>
Include dependency graph for Object.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define ExpChangePushlock(x, y, z)   InterlockedCompareExchangePointer((PVOID*)x, (PVOID)y, (PVOID)z)
 
#define EX_PUSH_LOCK_LOCK_V   ((ULONG_PTR)0x0)
 
#define EX_PUSH_LOCK_LOCK   ((ULONG_PTR)0x1)
 
#define EX_PUSH_LOCK_WAITING   ((ULONG_PTR)0x2)
 
#define EX_PUSH_LOCK_WAKING   ((ULONG_PTR)0x4)
 
#define EX_PUSH_LOCK_MULTIPLE_SHARED   ((ULONG_PTR)0x8)
 
#define EX_PUSH_LOCK_SHARE_INC   ((ULONG_PTR)0x10)
 
#define EX_PUSH_LOCK_PTR_BITS   ((ULONG_PTR)0xf)
 

Functions

NTSTATUS FLTAPI FltObjectReference (_Inout_ PVOID Object)
 
VOID FLTAPI FltObjectDereference (_Inout_ PVOID Object)
 
 _Acquires_lock_ (_Global_critical_region_)
 
 _Releases_lock_ (_Global_critical_region_)
 
 _IRQL_requires_max_ (PASSIVE_LEVEL)
 
VOID FltpExInitializeRundownProtection (_Out_ PEX_RUNDOWN_REF RundownRef)
 
BOOLEAN FltpExAcquireRundownProtection (_Inout_ PEX_RUNDOWN_REF RundownRef)
 
BOOLEAN FltpExReleaseRundownProtection (_Inout_ PEX_RUNDOWN_REF RundownRef)
 
BOOLEAN FltpExRundownCompleted (_Inout_ PEX_RUNDOWN_REF RundownRef)
 
NTSTATUS NTAPI FltpObjectRundownWait (_Inout_ PEX_RUNDOWN_REF RundownRef)
 
NTSTATUS FltpGetBaseDeviceObjectName (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PUNICODE_STRING ObjectName)
 
NTSTATUS FltpGetObjectName (_In_ PVOID Object, _Inout_ PUNICODE_STRING ObjectName)
 
ULONG FltpObjectPointerReference (_In_ PFLT_OBJECT Object)
 
VOID FltpObjectPointerDereference (_In_ PFLT_OBJECT Object)
 

Macro Definition Documentation

◆ EX_PUSH_LOCK_LOCK

#define EX_PUSH_LOCK_LOCK   ((ULONG_PTR)0x1)

Definition at line 29 of file Object.c.

◆ EX_PUSH_LOCK_LOCK_V

#define EX_PUSH_LOCK_LOCK_V   ((ULONG_PTR)0x0)

Definition at line 28 of file Object.c.

◆ EX_PUSH_LOCK_MULTIPLE_SHARED

#define EX_PUSH_LOCK_MULTIPLE_SHARED   ((ULONG_PTR)0x8)

Definition at line 32 of file Object.c.

◆ EX_PUSH_LOCK_PTR_BITS

#define EX_PUSH_LOCK_PTR_BITS   ((ULONG_PTR)0xf)

Definition at line 34 of file Object.c.

◆ EX_PUSH_LOCK_SHARE_INC

#define EX_PUSH_LOCK_SHARE_INC   ((ULONG_PTR)0x10)

Definition at line 33 of file Object.c.

◆ EX_PUSH_LOCK_WAITING

#define EX_PUSH_LOCK_WAITING   ((ULONG_PTR)0x2)

Definition at line 30 of file Object.c.

◆ EX_PUSH_LOCK_WAKING

#define EX_PUSH_LOCK_WAKING   ((ULONG_PTR)0x4)

Definition at line 31 of file Object.c.

◆ ExpChangePushlock

#define ExpChangePushlock (   x,
  y,
  z 
)    InterlockedCompareExchangePointer((PVOID*)x, (PVOID)y, (PVOID)z)

Definition at line 23 of file Object.c.

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file Object.c.

Function Documentation

◆ _Acquires_lock_()

_Acquires_lock_ ( _Global_critical_region_  )

Definition at line 59 of file Object.c.

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 }
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
VOID FASTCALL ExfAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: pushlock.c:471
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define EX_PUSH_LOCK_LOCK_V
Definition: Object.c:28
signed int * PLONG
Definition: retypes.h:5
#define FLT_ASSERT(_e)
Definition: fltkernel.h:49

◆ _IRQL_requires_max_()

_IRQL_requires_max_ ( PASSIVE_LEVEL  )

Definition at line 137 of file Object.c.

141 {
142  PAGED_CODE();
143 
144  return ZwClose(FileHandle);
145 }
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define PAGED_CODE()
Definition: video.h:57
HANDLE FileHandle
Definition: stats.c:38

◆ _Releases_lock_()

_Releases_lock_ ( _Global_critical_region_  )

Definition at line 101 of file Object.c.

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 }
ULONG_PTR Value
Definition: extypes.h:465
PVOID Ptr
Definition: extypes.h:466
ULONG_PTR Waiting
Definition: extypes.h:460
VOID FASTCALL ExfReleasePushLock(PEX_PUSH_LOCK PushLock)
Definition: pushlock.c:810
#define ExpChangePushlock(x, y, z)
Definition: Object.c:23
ULONG_PTR Shared
Definition: extypes.h:463
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define EX_PUSH_LOCK_SHARE_INC
Definition: Object.c:33
ULONG_PTR Locked
Definition: extypes.h:459
#define FLT_ASSERT(_e)
Definition: fltkernel.h:49

◆ FltObjectDereference()

VOID FLTAPI FltObjectDereference ( _Inout_ PVOID  Object)

Definition at line 53 of file Object.c.

54 {
56 }
BOOLEAN FltpExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RundownRef)
Definition: Object.c:224
static IUnknown Object
Definition: main.c:512

Referenced by _IRQL_requires_max_(), CreateClientPort(), FltEnumerateVolumes(), FltpServerPortClose(), FltStartFiltering(), and FltUnregisterFilter().

◆ FltObjectReference()

NTSTATUS FLTAPI FltObjectReference ( _Inout_ PVOID  Object)

Definition at line 41 of file Object.c.

42 {
44  {
46  }
47 
48  return STATUS_SUCCESS;
49 }
#define STATUS_FLT_DELETING_OBJECT
Definition: ntstatus.h:1214
BOOLEAN FltpExAcquireRundownProtection(_Inout_ PEX_RUNDOWN_REF RundownRef)
Definition: Object.c:218
static IUnknown Object
Definition: main.c:512
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by _IRQL_requires_max_(), CreateClientPort(), FltEnumerateVolumes(), FltRegisterFilter(), and FltStartFiltering().

◆ FltpExAcquireRundownProtection()

BOOLEAN FltpExAcquireRundownProtection ( _Inout_ PEX_RUNDOWN_REF  RundownRef)

Definition at line 218 of file Object.c.

219 {
220  return ExAcquireRundownProtection(RundownRef);
221 }
#define ExAcquireRundownProtection
Definition: ex.h:130

Referenced by FltObjectReference().

◆ FltpExInitializeRundownProtection()

VOID FltpExInitializeRundownProtection ( _Out_ PEX_RUNDOWN_REF  RundownRef)

Definition at line 212 of file Object.c.

213 {
214  ExInitializeRundownProtection(RundownRef);
215 }
NTKERNELAPI VOID FASTCALL ExInitializeRundownProtection(_Out_ PEX_RUNDOWN_REF RunRef)

Referenced by FltRegisterFilter().

◆ FltpExReleaseRundownProtection()

BOOLEAN FltpExReleaseRundownProtection ( _Inout_ PEX_RUNDOWN_REF  RundownRef)

Definition at line 224 of file Object.c.

225 {
226  ExReleaseRundownProtection(RundownRef);
227  return TRUE;
228 }
#define TRUE
Definition: types.h:120
NTKERNELAPI VOID FASTCALL ExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RunRef)

Referenced by FltObjectDereference().

◆ FltpExRundownCompleted()

BOOLEAN FltpExRundownCompleted ( _Inout_ PEX_RUNDOWN_REF  RundownRef)

Definition at line 231 of file Object.c.

232 {
233  return _InterlockedExchange((PLONG)RundownRef, 1);
234 }
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
signed int * PLONG
Definition: retypes.h:5

Referenced by FltUnregisterFilter().

◆ FltpGetBaseDeviceObjectName()

NTSTATUS FltpGetBaseDeviceObjectName ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PUNICODE_STRING  ObjectName 
)

Definition at line 245 of file Object.c.

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 }
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
PDEVICE_OBJECT NTAPI IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1419
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS FltpGetObjectName(_In_ PVOID Object, _Inout_ PUNICODE_STRING ObjectName)
Definition: Object.c:263

Referenced by FltpEnumerateFileSystemVolumes(), and FltpFsNotification().

◆ FltpGetObjectName()

NTSTATUS FltpGetObjectName ( _In_ PVOID  Object,
_Inout_ PUNICODE_STRING  ObjectName 
)

Definition at line 263 of file Object.c.

265 {
266  POBJECT_NAME_INFORMATION ObjectNameInfo = NULL;
267  OBJECT_NAME_INFORMATION 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,
282  ReturnLength,
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,
289  ReturnLength,
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)
314  {
315  ExFreePoolWithTag(ObjectNameInfo, FM_TAG_UNICODE_STRING);
316  }
317 
318  return Status;
319 }
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ObQueryNameString(IN PVOID Object, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength)
Definition: obname.c:1209
UNICODE_STRING Name
Definition: nt_native.h:1270
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define FM_TAG_UNICODE_STRING
Definition: fltmgr.h:18
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS FltpReallocateUnicodeString(_In_ PUNICODE_STRING String, _In_ SIZE_T NewLength, _In_ BOOLEAN CopyExisting)
Definition: Lib.c:39
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static IUnknown Object
Definition: main.c:512
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by FltpAttachToFileSystemDevice(), FltpEnumerateFileSystemVolumes(), and FltpGetBaseDeviceObjectName().

◆ FltpObjectPointerDereference()

VOID FltpObjectPointerDereference ( _In_ PFLT_OBJECT  Object)

Definition at line 335 of file Object.c.

336 {
337  if (InterlockedDecrementSizeT(&Object->PointerCount) == 0)
338  {
339  // Cleanup
340  FLT_ASSERT(FALSE);
341  }
342 }
static IUnknown Object
Definition: main.c:512
#define InterlockedDecrementSizeT(a)
Definition: interlocked.h:153
#define FLT_ASSERT(_e)
Definition: fltkernel.h:49

Referenced by FltpServerPortDelete().

◆ FltpObjectPointerReference()

ULONG FltpObjectPointerReference ( _In_ PFLT_OBJECT  Object)

Definition at line 322 of file Object.c.

323 {
324  PULONG Result;
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 }
#define InterlockedIncrementSizeT(a)
Definition: interlocked.h:220
_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:426
static IUnknown Object
Definition: main.c:512
unsigned int * PULONG
Definition: retypes.h:1

Referenced by _IRQL_requires_max_().

◆ FltpObjectRundownWait()

NTSTATUS NTAPI FltpObjectRundownWait ( _Inout_ PEX_RUNDOWN_REF  RundownRef)

Definition at line 238 of file Object.c.

239 {
240  //return FltpExWaitForRundownProtectionRelease(RundownRef);
241  return 0;
242 }

Referenced by FltUnregisterFilter().