From c87b8c948a2ca25251b0a144d3a9770044c2540c Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Fri, 4 Dec 2015 16:17:06 -0800 Subject: [PATCH] sys: FspFsvolDeviceLookupContext --- src/sys/device.c | 34 ++++++++++++++++++++++++++-------- src/sys/driver.h | 1 + 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/sys/device.c b/src/sys/device.c index dfcc5161..23da0afe 100644 --- a/src/sys/device.c +++ b/src/sys/device.c @@ -24,6 +24,7 @@ BOOLEAN FspDeviceRetain(PDEVICE_OBJECT DeviceObject); VOID FspDeviceRelease(PDEVICE_OBJECT DeviceObject); VOID FspFsctlDeviceVolumeCreated(PDEVICE_OBJECT DeviceObject); VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject); +PVOID FspFsvolDeviceLookupContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier); NTSTATUS FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PVOID Context, PBOOLEAN PInserted); VOID FspFsvolDeviceDeleteContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, @@ -304,10 +305,26 @@ VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject) IoUnregisterFileSystem(DeviceObject); } +PVOID FspFsvolDeviceLookupContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier) +{ + // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ + + FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); + ASSERT(FspFsvolDeviceExtensionKind == FsvolDeviceExtension->Base.Kind); + + PVOID Result; + + ExAcquireFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); + Result = RtlLookupElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, &Identifier); + ExReleaseFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); + + return Result; +} + NTSTATUS FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PVOID Context, PBOOLEAN PInserted) { - // !PAGED_CODE(); + // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); ASSERT(FspFsvolDeviceExtensionKind == FsvolDeviceExtension->Base.Kind); @@ -328,14 +345,15 @@ NTSTATUS FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identif VOID FspFsvolDeviceDeleteContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PBOOLEAN PDeleted) { - // !PAGED_CODE(); + // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); ASSERT(FspFsvolDeviceExtensionKind == FsvolDeviceExtension->Base.Kind); + BOOLEAN Deleted; + ExAcquireFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); - BOOLEAN Deleted = RtlDeleteElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, - &Identifier); + Deleted = RtlDeleteElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, &Identifier); ExReleaseFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); if (0 != PDeleted) @@ -345,7 +363,7 @@ VOID FspFsvolDeviceDeleteContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, static RTL_GENERIC_COMPARE_RESULTS NTAPI FspFsvolDeviceCompareElement( PRTL_AVL_TABLE Table, PVOID FirstElement, PVOID SecondElement) { - // !PAGED_CODE(); + // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ if (FirstElement < SecondElement) return GenericLessThan; @@ -359,16 +377,16 @@ static RTL_GENERIC_COMPARE_RESULTS NTAPI FspFsvolDeviceCompareElement( static PVOID NTAPI FspFsvolDeviceAllocateElement( PRTL_AVL_TABLE Table, CLONG ByteSize) { - // !PAGED_CODE(); + // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ - /* allocate from non-paged pool because of fast mutex use in GenericTable */ + /* allocate from non-paged pool because of fast mutex use */ return ExAllocatePoolWithTag(NonPagedPool, ByteSize, FSP_TAG); } static VOID NTAPI FspFsvolDeviceFreeElement( PRTL_AVL_TABLE Table, PVOID Buffer) { - // !PAGED_CODE(); + // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ ExFreePoolWithTag(Buffer, FSP_TAG); } diff --git a/src/sys/driver.h b/src/sys/driver.h index bff4a3d2..3bf72922 100644 --- a/src/sys/driver.h +++ b/src/sys/driver.h @@ -341,6 +341,7 @@ BOOLEAN FspDeviceRetain(PDEVICE_OBJECT DeviceObject); VOID FspDeviceRelease(PDEVICE_OBJECT DeviceObject); VOID FspFsctlDeviceVolumeCreated(PDEVICE_OBJECT DeviceObject); VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject); +PVOID FspFsvolDeviceLookupContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier); NTSTATUS FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PVOID Context, PBOOLEAN PInserted); VOID FspFsvolDeviceDeleteContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier,