From b5cf0901446ff588c064fd524a14d126b8cf4b4c Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sat, 5 Dec 2015 00:29:47 -0800 Subject: [PATCH] sys: FspFsvolDevice{Lookup,Insert,Delete}Context: now require use of FsvolDeviceExtension Resource --- src/sys/device.c | 45 +++++++++++++++++++++++---------------------- src/sys/driver.h | 1 - 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/sys/device.c b/src/sys/device.c index 76f917fc..5f032751 100644 --- a/src/sys/device.c +++ b/src/sys/device.c @@ -47,9 +47,15 @@ VOID FspDeviceDeleteAll(VOID); #pragma alloc_text(PAGE, FspFsvrtDeviceInit) #pragma alloc_text(PAGE, FspFsvrtDeviceFini) #pragma alloc_text(PAGE, FspFsvolDeviceInit) -//! #pragma alloc_text(PAGE, FspFsvolDeviceFini) +#pragma alloc_text(PAGE, FspFsvolDeviceFini) #pragma alloc_text(PAGE, FspFsctlDeviceVolumeCreated) #pragma alloc_text(PAGE, FspFsctlDeviceVolumeDeleted) +#pragma alloc_text(PAGE, FspFsvolDeviceLookupContext) +#pragma alloc_text(PAGE, FspFsvolDeviceInsertContext) +#pragma alloc_text(PAGE, FspFsvolDeviceDeleteContext) +#pragma alloc_text(PAGE, FspFsvolDeviceCompareElement) +#pragma alloc_text(PAGE, FspFsvolDeviceAllocateElement) +#pragma alloc_text(PAGE, FspFsvolDeviceFreeElement) #pragma alloc_text(PAGE, FspDeviceCopyList) #pragma alloc_text(PAGE, FspDeviceDeleteList) #pragma alloc_text(PAGE, FspDeviceDeleteAll) @@ -214,26 +220,25 @@ static NTSTATUS FspFsvolDeviceInit(PDEVICE_OBJECT DeviceObject) FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); - ExInitializeFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); - RtlInitializeGenericTableAvl(&FsvolDeviceExtension->GenericTable, 0, 0, 0, 0); + RtlInitializeGenericTableAvl(&FsvolDeviceExtension->GenericTable, + FspFsvolDeviceCompareElement, FspFsvolDeviceAllocateElement, FspFsvolDeviceFreeElement, 0); return STATUS_SUCCESS; } static VOID FspFsvolDeviceFini(PDEVICE_OBJECT DeviceObject) { - // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ + PAGED_CODE(); FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); /* * Enumerate and delete all entries in the GenericTable. + * There is no need to protect accesses to the table as we are in the device destructor. */ - ExAcquireFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); FSP_DEVICE_GENERIC_TABLE_ELEMENT *Element; while (0 != (Element = RtlGetElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, 0))) RtlDeleteElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, &Element->Identifier); - ExReleaseFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); /* * Dereference the virtual volume device so that it can now go away. @@ -307,36 +312,34 @@ VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject) PVOID FspFsvolDeviceLookupContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier) { - // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ + PAGED_CODE(); FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); ASSERT(FspFsvolDeviceExtensionKind == FsvolDeviceExtension->Base.Kind); + ASSERT(ExIsResourceAcquiredExclusiveLite(&FsvolDeviceExtension->Base.Resource)); - PVOID Result; + FSP_DEVICE_GENERIC_TABLE_ELEMENT *Result; - ExAcquireFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); Result = RtlLookupElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, &Identifier); - ExReleaseFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); - return Result; + return 0 != Result ? Result->Context : 0; } PVOID FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PVOID Context, PBOOLEAN PInserted) { - // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ + PAGED_CODE(); FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); ASSERT(FspFsvolDeviceExtensionKind == FsvolDeviceExtension->Base.Kind); + ASSERT(ExIsResourceAcquiredExclusiveLite(&FsvolDeviceExtension->Base.Resource)); FSP_DEVICE_GENERIC_TABLE_ELEMENT *Result, Element = { 0 }; Element.Identifier = Identifier; Element.Context = Context; - ExAcquireFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); Result = RtlInsertElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, &Element, sizeof Element, PInserted); - ExReleaseFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); return 0 != Result ? Result->Context : 0; } @@ -344,16 +347,15 @@ PVOID FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier VOID FspFsvolDeviceDeleteContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PBOOLEAN PDeleted) { - // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ + PAGED_CODE(); FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); ASSERT(FspFsvolDeviceExtensionKind == FsvolDeviceExtension->Base.Kind); + ASSERT(ExIsResourceAcquiredExclusiveLite(&FsvolDeviceExtension->Base.Resource)); BOOLEAN Deleted; - ExAcquireFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); Deleted = RtlDeleteElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, &Identifier); - ExReleaseFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); if (0 != PDeleted) *PDeleted = Deleted; @@ -362,7 +364,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(); /* because of fast mutex use in GenericTable */ + PAGED_CODE(); if (FirstElement < SecondElement) return GenericLessThan; @@ -376,16 +378,15 @@ static RTL_GENERIC_COMPARE_RESULTS NTAPI FspFsvolDeviceCompareElement( static PVOID NTAPI FspFsvolDeviceAllocateElement( PRTL_AVL_TABLE Table, CLONG ByteSize) { - // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ + PAGED_CODE(); - /* allocate from non-paged pool because of fast mutex use */ - return ExAllocatePoolWithTag(NonPagedPool, ByteSize, FSP_TAG); + return ExAllocatePoolWithTag(PagedPool, ByteSize, FSP_TAG); } static VOID NTAPI FspFsvolDeviceFreeElement( PRTL_AVL_TABLE Table, PVOID Buffer) { - // !PAGED_CODE(); /* because of fast mutex use in GenericTable */ + PAGED_CODE(); ExFreePoolWithTag(Buffer, FSP_TAG); } diff --git a/src/sys/driver.h b/src/sys/driver.h index 727df0ec..8ee6dc96 100644 --- a/src/sys/driver.h +++ b/src/sys/driver.h @@ -304,7 +304,6 @@ typedef struct { FSP_DEVICE_EXTENSION Base; PDEVICE_OBJECT FsvrtDeviceObject; - FAST_MUTEX GenericTableFastMutex; RTL_AVL_TABLE GenericTable; } FSP_FSVOL_DEVICE_EXTENSION; static inline