From 1bb0b6be107a1702c468b321ba388902206973a7 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Mon, 21 Dec 2015 15:19:55 -0800 Subject: [PATCH] sys: device: replace device Resource with GenericTableFastMutex --- src/sys/device.c | 32 +++++++++++++++++++------------- src/sys/driver.h | 4 +++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/sys/device.c b/src/sys/device.c index dc439578..1cd37925 100644 --- a/src/sys/device.c +++ b/src/sys/device.c @@ -24,6 +24,8 @@ static VOID FspFsvolDeviceInitComplete(PDEVICE_OBJECT DeviceObject); static VOID FspFsvolDeviceFini(PDEVICE_OBJECT DeviceObject); static IO_TIMER_ROUTINE FspFsvolDeviceTimerRoutine; static WORKER_THREAD_ROUTINE FspFsvolDeviceExpirationRoutine; +VOID FspFsvolDeviceLockContext(PDEVICE_OBJECT DeviceObject); +VOID FspFsvolDeviceUnlockContext(PDEVICE_OBJECT DeviceObject); PVOID FspFsvolDeviceLookupContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier); PVOID FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PVOID Context, FSP_DEVICE_GENERIC_TABLE_ELEMENT *ElementStorage, PBOOLEAN PInserted); @@ -46,6 +48,8 @@ VOID FspDeviceDeleteAll(VOID); #pragma alloc_text(PAGE, FspFsvolDeviceInit) #pragma alloc_text(PAGE, FspFsvolDeviceInitComplete) #pragma alloc_text(PAGE, FspFsvolDeviceFini) +#pragma alloc_text(PAGE, FspFsvolDeviceLockContext) +#pragma alloc_text(PAGE, FspFsvolDeviceUnlockContext) #pragma alloc_text(PAGE, FspFsvolDeviceLookupContext) #pragma alloc_text(PAGE, FspFsvolDeviceInsertContext) #pragma alloc_text(PAGE, FspFsvolDeviceDeleteContext) @@ -277,10 +281,8 @@ static NTSTATUS FspFsvolDeviceInit(PDEVICE_OBJECT DeviceObject) ExInitializeWorkItem(&FsvolDeviceExtension->ExpirationWorkItem, FspFsvolDeviceExpirationRoutine, DeviceObject); - /* initialize our resource */ - ExInitializeResourceLite(&FsvolDeviceExtension->Resource); - /* initialize our generic table */ + ExInitializeFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); RtlInitializeGenericTableAvl(&FsvolDeviceExtension->GenericTable, FspFsvolDeviceCompareElement, FspFsvolDeviceAllocateElement, FspFsvolDeviceFreeElement, 0); @@ -338,9 +340,6 @@ static VOID FspFsvolDeviceFini(PDEVICE_OBJECT DeviceObject) /* free the spare VPB if we still have it */ if (0 != FsvolDeviceExtension->SwapVpb) FspFreeExternal(FsvolDeviceExtension->SwapVpb); - - /* delete our resource */ - ExDeleteResourceLite(&FsvolDeviceExtension->Resource); } static VOID FspFsvolDeviceTimerRoutine(PDEVICE_OBJECT DeviceObject, PVOID Context) @@ -394,13 +393,23 @@ static VOID FspFsvolDeviceExpirationRoutine(PVOID Context) FspDeviceRelease(DeviceObject); } +VOID FspFsvolDeviceLockContext(PDEVICE_OBJECT DeviceObject) +{ + FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); + ExAcquireFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); +} + +VOID FspFsvolDeviceUnlockContext(PDEVICE_OBJECT DeviceObject) +{ + FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); + ExReleaseFastMutex(&FsvolDeviceExtension->GenericTableFastMutex); +} + PVOID FspFsvolDeviceLookupContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier) { PAGED_CODE(); FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); - ASSERT(ExIsResourceAcquiredExclusiveLite(&FsvolDeviceExtension->Resource)); - FSP_DEVICE_GENERIC_TABLE_ELEMENT_DATA *Result; Result = RtlLookupElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, &Identifier); @@ -414,10 +423,9 @@ PVOID FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier PAGED_CODE(); FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); - ASSERT(ExIsResourceAcquiredExclusiveLite(&FsvolDeviceExtension->Resource)); - ASSERT(0 != ElementStorage); - FSP_DEVICE_GENERIC_TABLE_ELEMENT_DATA *Result, Element = { 0 }; + + ASSERT(0 != ElementStorage); Element.Identifier = Identifier; Element.Context = Context; @@ -437,8 +445,6 @@ VOID FspFsvolDeviceDeleteContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PAGED_CODE(); FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(DeviceObject); - ASSERT(ExIsResourceAcquiredExclusiveLite(&FsvolDeviceExtension->Resource)); - BOOLEAN Deleted; Deleted = RtlDeleteElementGenericTableAvl(&FsvolDeviceExtension->GenericTable, &Identifier); diff --git a/src/sys/driver.h b/src/sys/driver.h index 4a8d1219..d7397d67 100644 --- a/src/sys/driver.h +++ b/src/sys/driver.h @@ -375,9 +375,9 @@ typedef struct KSPIN_LOCK ExpirationLock; WORK_QUEUE_ITEM ExpirationWorkItem; BOOLEAN ExpirationInProgress; + FAST_MUTEX GenericTableFastMutex; RTL_AVL_TABLE GenericTable; PVOID GenericTableElementStorage; - ERESOURCE Resource; } FSP_FSVOL_DEVICE_EXTENSION; static inline FSP_DEVICE_EXTENSION *FspDeviceExtension(PDEVICE_OBJECT DeviceObject) @@ -401,6 +401,8 @@ VOID FspDeviceInitComplete(PDEVICE_OBJECT DeviceObject); VOID FspDeviceDelete(PDEVICE_OBJECT DeviceObject); BOOLEAN FspDeviceRetain(PDEVICE_OBJECT DeviceObject); VOID FspDeviceRelease(PDEVICE_OBJECT DeviceObject); +VOID FspFsvolDeviceLockContext(PDEVICE_OBJECT DeviceObject); +VOID FspFsvolDeviceUnlockContext(PDEVICE_OBJECT DeviceObject); PVOID FspFsvolDeviceLookupContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier); PVOID FspFsvolDeviceInsertContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier, PVOID Context, FSP_DEVICE_GENERIC_TABLE_ELEMENT *ElementStorage, PBOOLEAN PInserted);