VOID CmpLockRegistry( VOID ) /*++ Routine Description: Lock the registry for shared (read-only) access Arguments: None. Return Value: None, the registry lock will be held for shared access upon return. --*/ { #if DBG PVOID Caller; PVOID CallerCaller; #endif KeEnterCriticalRegion(); ExAcquireResourceShared(&CmpRegistryLock, TRUE); #if DBG RtlGetCallersAddress(&Caller, &CallerCaller); CMLOG(CML_FLOW, CMS_LOCKING) { KdPrint(("CmpLockRegistry: c, cc: %08lx %08lx\n", Caller, CallerCaller)); }
NTSTATUS DokanFreeCCB( __in PDokanCCB ccb ) { PDokanFCB fcb; ASSERT(ccb != NULL); fcb = ccb->Fcb; KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&fcb->Resource, TRUE); RemoveEntryList(&ccb->NextCCB); ExReleaseResourceLite(&fcb->Resource); KeLeaveCriticalRegion(); ExDeleteResourceLite(&ccb->Resource); if (ccb->SearchPattern) { ExFreePool(ccb->SearchPattern); } ExFreePool(ccb); InterlockedIncrement(&fcb->Vcb->CcbFreed); return STATUS_SUCCESS; }
static VOID TestResourceExclusiveAccess( IN PERESOURCE Res) { LONG Count = 0; KeEnterCriticalRegion(); ok_bool_true(ExAcquireResourceExclusiveLite(Res, FALSE), "ExAcquireResourceExclusiveLite returned"); ++Count; CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU); ok_bool_true(ExAcquireResourceExclusiveLite(Res, TRUE), "ExAcquireResourceExclusiveLite returned"); ++Count; CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU); ok_bool_true(ExAcquireResourceSharedLite(Res, FALSE), "ExAcquireResourceSharedLite returned"); ++Count; ok_bool_true(ExAcquireResourceSharedLite(Res, TRUE), "ExAcquireResourceSharedLite returned"); ++Count; ok_bool_true(ExAcquireSharedStarveExclusive(Res, FALSE), "ExAcquireSharedStarveExclusive returned"); ++Count; ok_bool_true(ExAcquireSharedStarveExclusive(Res, TRUE), "ExAcquireSharedStarveExclusive returned"); ++Count; ok_bool_true(ExAcquireSharedWaitForExclusive(Res, FALSE), "ExAcquireSharedWaitForExclusive returned"); ++Count; ok_bool_true(ExAcquireSharedWaitForExclusive(Res, TRUE), "ExAcquireSharedWaitForExclusive returned"); ++Count; CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU); ExConvertExclusiveToSharedLite(Res); CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU); while (Count--) ExReleaseResourceLite(Res); KeLeaveCriticalRegion(); }
VOID DokanCheckKeepAlive(__in PDokanDCB Dcb) { LARGE_INTEGER tickCount; ULONG mounted; // DDbgPrint("==> DokanCheckKeepAlive\n"); KeEnterCriticalRegion(); KeQueryTickCount(&tickCount); ExAcquireResourceSharedLite(&Dcb->Resource, TRUE); if (Dcb->TickCount.QuadPart < tickCount.QuadPart) { mounted = Dcb->Mounted; ExReleaseResourceLite(&Dcb->Resource); DDbgPrint(" Timeout, umount\n"); if (!mounted) { // not mounted KeLeaveCriticalRegion(); return; } DokanUnmount(Dcb); } else { ExReleaseResourceLite(&Dcb->Resource); } KeLeaveCriticalRegion(); // DDbgPrint("<== DokanCheckKeepAlive\n"); }
NTSTATUS DokanFilterCallbackAcquireForCreateSection(__in PFS_FILTER_CALLBACK_DATA CallbackData, __out PVOID *CompletionContext) { PFSRTL_ADVANCED_FCB_HEADER header; PDokanFCB fcb = NULL; PDokanCCB ccb; UNREFERENCED_PARAMETER(CompletionContext); DDbgPrint("DokanFilterCallbackAcquireForCreateSection\n"); header = CallbackData->FileObject->FsContext; ccb = CallbackData->FileObject->FsContext2; if (ccb) fcb = ccb->Fcb; if (header && header->Resource) { KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(header->Resource, TRUE); KeLeaveCriticalRegion(); } if (CallbackData->Parameters.AcquireForSectionSynchronization.SyncType != SyncTypeCreateSection) { return STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY; } else if (fcb && fcb->ShareAccess.Writers == 0) { return STATUS_FILE_LOCKED_WITH_ONLY_READERS; } else { return STATUS_FILE_LOCKED_WITH_WRITERS; } }
void dc_add_password(dc_pass *pass) { dsk_pass *d_pass; if (pass->size != 0) { KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&p_resource, TRUE); for (d_pass = f_pass; d_pass; d_pass = d_pass->next) { if (IS_EQUAL_PASS(pass, &d_pass->pass)) { break; } } if ( (d_pass == NULL) && (d_pass = mm_secure_alloc(sizeof(dsk_pass))) ) { memcpy(&d_pass->pass, pass, sizeof(dc_pass)); d_pass->next = f_pass; f_pass = d_pass; } ExReleaseResourceLite(&p_resource); KeLeaveCriticalRegion(); } }
VOID FASTCALL UserEnterExclusive(VOID) { ASSERT_NOGDILOCKS(); KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&UserLock, TRUE); gptiCurrent = PsGetCurrentThreadWin32Thread(); }
ULONG FindVDVDPdoCount( PFDO_DEVICE_DATA FdoData ) { PPDO_DEVICE_DATA pdoData = NULL; PLIST_ENTRY entry; ULONG count = 0; PAGED_CODE (); KeEnterCriticalRegion(); for (entry = FdoData->ListOfPDOs.Flink; entry != &FdoData->ListOfPDOs; entry = entry->Flink) { pdoData = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link); if(pdoData->LanscsiAdapter.LogicalTarget[0].Llu[0].ucLluType == DISK_TYPE_VDVD) count++; pdoData = NULL; } KeLeaveCriticalRegion(); return count; }
static VOID NTAPI AcquireResourceThread( PVOID Context) { NTSTATUS Status = STATUS_SUCCESS; PTHREAD_DATA ThreadData = Context; BOOLEAN Ret; KeEnterCriticalRegion(); Ret = ThreadData->AcquireResource(ThreadData->Res, ThreadData->Wait); if (ThreadData->RetExpected) ok_bool_true(Ret, "AcquireResource returned"); else ok_bool_false(Ret, "AcquireResource returned"); ok_bool_false(KeSetEvent(&ThreadData->OutEvent, 0, TRUE), "KeSetEvent returned"); Status = KeWaitForSingleObject(&ThreadData->InEvent, Executive, KernelMode, FALSE, NULL); ok_eq_hex(Status, STATUS_SUCCESS); if (Ret) ExReleaseResource(ThreadData->Res); KeLeaveCriticalRegion(); }
static VOID TestResourceSharedAccess( IN PERESOURCE Res) { LONG Count = 0; KeEnterCriticalRegion(); ok_bool_true(ExAcquireResourceSharedLite(Res, FALSE), "ExAcquireResourceSharedLite returned"); ++Count; CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU); ok_bool_true(ExAcquireResourceSharedLite(Res, FALSE), "ExAcquireResourceSharedLite returned"); ++Count; ok_bool_true(ExAcquireResourceSharedLite(Res, TRUE), "ExAcquireResourceSharedLite returned"); ++Count; ok_bool_true(ExAcquireSharedStarveExclusive(Res, FALSE), "ExAcquireSharedStarveExclusive returned"); ++Count; ok_bool_true(ExAcquireSharedStarveExclusive(Res, TRUE), "ExAcquireSharedStarveExclusive returned"); ++Count; ok_bool_true(ExAcquireSharedWaitForExclusive(Res, FALSE), "ExAcquireSharedWaitForExclusive returned"); ++Count; ok_bool_true(ExAcquireSharedWaitForExclusive(Res, TRUE), "ExAcquireSharedWaitForExclusive returned"); ++Count; CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU); /* this one fails, TRUE would deadlock */ ok_bool_false(ExAcquireResourceExclusiveLite(Res, FALSE), "ExAcquireResourceExclusiveLite returned"); CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU); /* this asserts */ if (!KmtIsCheckedBuild) ExConvertExclusiveToSharedLite(Res); CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU); while (Count--) ExReleaseResourceLite(Res); KeLeaveCriticalRegion(); }
VOID FilterDeleteControlObject( ) { UNICODE_STRING symbolicLinkName; PCONTROL_DEVICE_EXTENSION deviceExtension; PAGED_CODE(); KeEnterCriticalRegion(); KeWaitForSingleObject(&ControlLock, Executive, KernelMode, FALSE, NULL); // // If this is the last instance of the device then delete the controlobject // and symbolic link to enable the pnp manager to unload the driver. // if (!(--InstanceCount) && ControlDeviceObject) { RtlInitUnicodeString(&symbolicLinkName, SYMBOLIC_NAME_STRING); deviceExtension = ControlDeviceObject->DeviceExtension; deviceExtension->Deleted = TRUE; IoDeleteSymbolicLink(&symbolicLinkName); IoDeleteDevice(ControlDeviceObject); ControlDeviceObject = NULL; } KeSetEvent(&ControlLock, IO_NO_INCREMENT, FALSE); KeLeaveCriticalRegion(); }
static NTSTATUS EvhdDirectIoControl(ParserInstance *parser, ULONG ControlCode, PVOID pSystemBuffer, ULONG InputBufferSize, ULONG OutputBufferSize) { NTSTATUS status = STATUS_SUCCESS; PDEVICE_OBJECT pDeviceObject = NULL; KeEnterCriticalRegion(); FltAcquirePushLockExclusive(&parser->DirectIoPushLock); IoReuseIrp(parser->pDirectIoIrp, STATUS_PENDING); parser->pDirectIoIrp->Flags |= IRP_NOCACHE; parser->pDirectIoIrp->Tail.Overlay.Thread = (PETHREAD)__readgsqword(0x188); // Pointer to calling thread control block parser->pDirectIoIrp->AssociatedIrp.SystemBuffer = pSystemBuffer; // IO buffer for buffered control code // fill stack frame parameters for synchronous IRP call PIO_STACK_LOCATION pStackFrame = IoGetNextIrpStackLocation(parser->pDirectIoIrp); pDeviceObject = IoGetRelatedDeviceObject(parser->pVhdmpFileObject); pStackFrame->FileObject = parser->pVhdmpFileObject; pStackFrame->DeviceObject = pDeviceObject; pStackFrame->Parameters.DeviceIoControl.IoControlCode = ControlCode; pStackFrame->Parameters.DeviceIoControl.InputBufferLength = InputBufferSize; pStackFrame->Parameters.DeviceIoControl.OutputBufferLength = OutputBufferSize; pStackFrame->MajorFunction = IRP_MJ_DEVICE_CONTROL; pStackFrame->MinorFunction = 0; pStackFrame->Flags = 0; pStackFrame->Control = 0; IoSynchronousCallDriver(pDeviceObject, parser->pDirectIoIrp); status = parser->pDirectIoIrp->IoStatus.Status; FltReleasePushLock(&parser->DirectIoPushLock); KeLeaveCriticalRegion(); return status; }
/* * @implemented */ VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject) { PAGED_CODE(); /* Acquire the FS lock */ KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&IopDatabaseResource, TRUE); /* Simply remove the entry - if queued */ if (DeviceObject->Queue.ListEntry.Flink) { RemoveEntryList(&DeviceObject->Queue.ListEntry); } /* And notify all registered file systems */ IopNotifyFileSystemChange(DeviceObject, FALSE); /* Update operations counter */ IopFsRegistrationOps++; /* Then release the lock */ ExReleaseResourceLite(&IopDatabaseResource); KeLeaveCriticalRegion(); /* Decrease reference count to allow unload */ IopInterlockedDecrementUlong(LockQueueIoDatabaseLock, (PULONG)&DeviceObject->ReferenceCount); }
VOID SymInit(void) { KeEnterCriticalRegion(); if(bIsSymEngineInitialized == TRUE) { KeLeaveCriticalRegion(); return; } // initialize all required data structures ExInitializeNPagedLookasideList(&SymbolsLookasideList, // list to initialize NULL, // allocate function - OS supplied NULL, // free function - OS supplied 0, // flags - always zero sizeof(SYMBOL_ENTRY), // size of each entry to be allocated TAG_SYMBOL_LOOKASIDE, // SymL(ookaside) tag 0 // depth - always zero ); InitializeListHead(&SymbolsListHead); ASSERTMSG("Fast mutex must be initialized at or below DISPATCH_LEVEL", KeGetCurrentIrql() <= DISPATCH_LEVEL); ExInitializeFastMutex(&SymbolsListMutex); bIsSymEngineInitialized = TRUE; KeLeaveCriticalRegion(); }
/*++ * @name KeEnterCriticalRegion * @implemented NT4 * * The KeEnterCriticalRegion routine temporarily disables the delivery of * normal kernel APCs; special kernel-mode APCs are still delivered. * * @param None. * * @return None. * * @remarks Highest-level drivers can call this routine while running in the * context of the thread that requested the current I/O operation. * Any caller of this routine should call KeLeaveCriticalRegion as * quickly as possible. * * Callers of KeEnterCriticalRegion must be running at IRQL <= * APC_LEVEL. * *--*/ VOID NTAPI _KeEnterCriticalRegion(VOID) { /* Use inlined function */ KeEnterCriticalRegion(); }
dev_hook *dc_find_hook(wchar_t *dev_name) { PLIST_ENTRY entry; dev_hook *hook; dev_hook *found = NULL; KeEnterCriticalRegion(); ExAcquireResourceSharedLite(&hooks_sync_resource, TRUE); entry = hooks_list_head.Flink; while (entry != &hooks_list_head) { hook = CONTAINING_RECORD(entry, dev_hook, hooks_list); entry = entry->Flink; if (_wcsicmp(hook->dev_name, dev_name) == 0) { dc_reference_hook(hook); found = hook; break; } } ExReleaseResourceLite(&hooks_sync_resource); KeLeaveCriticalRegion(); return found; }
// // Increment the reference count to a PDO. // PPDO_DEVICE_DATA LookupPdoData( PFDO_DEVICE_DATA FdoData, ULONG SystemIoBusNumber ) { PPDO_DEVICE_DATA pdoData = NULL; PLIST_ENTRY entry; PAGED_CODE (); KeEnterCriticalRegion(); ExAcquireFastMutex (&FdoData->Mutex); for (entry = FdoData->ListOfPDOs.Flink; entry != &FdoData->ListOfPDOs; entry = entry->Flink) { pdoData = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link); if(pdoData->SlotNo == SystemIoBusNumber) break; pdoData = NULL; } if(pdoData) { // // increment the reference count to the PDO. // ObReferenceObject(pdoData->Self); } ExReleaseFastMutex (&FdoData->Mutex); KeLeaveCriticalRegion(); return pdoData; }
void dc_clean_pass_cache() { dsk_pass *d_pass; dsk_pass *c_pass; int loirql; if (loirql = (KeGetCurrentIrql() == PASSIVE_LEVEL)) { KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&p_resource, TRUE); } for (d_pass = f_pass; d_pass;) { c_pass = d_pass; d_pass = d_pass->next; /* zero password data */ burn(c_pass, sizeof(dsk_pass)); /* free memory if possible */ if (loirql != 0) mm_secure_free(c_pass); } f_pass = NULL; if (loirql != 0) { ExReleaseResourceLite(&p_resource); KeLeaveCriticalRegion(); } }
VOID ThreadNotifyCallback ( HANDLE ProcessId, HANDLE ThreadId, BOOLEAN Create ) { DbgPrint ( "%s ProcessId=%x ThreadId=%x %s\n", __FUNCTION__, ProcessId, ThreadId, Create ? "CREATED" : "DESTROYED" ); if ( Create ) { // Step #2 : Acquire the lock that protects the g_Tidxxx globals // (KeEnterCriticalRegion() and ExAcquireResourceExclusiveLite()) KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&g_TidLock, TRUE); g_TidArray[g_TidIndex] = ThreadId; g_TidIndex++; if ( g_TidIndex >= TID_ARRAY_SIZE ) { g_TidIndex = 0; } // Step #3 : Release the lock that protects the g_Tidxxx globals // (KeLeaveCriticalRegion() and ExReleaseResourceLite()) ExReleaseResourceLite(&g_TidLock); KeLeaveCriticalRegion(); } }
static int dc_probe_decrypt(dev_hook *hook, dc_header **header, xts_key **res_key, dc_pass *password) { xts_key *hdr_key; dsk_pass *d_pass; int resl, succs; hdr_key = NULL; succs = 0; *header = NULL; do { /* read raw volume header */ if ( (resl = io_read_header(hook, header, NULL, NULL)) != ST_OK ) { break; } if ( (hdr_key = mm_secure_alloc(sizeof(xts_key))) == NULL ) { resl = ST_NOMEM; break; } /* derive header key and decrypt header */ do { if (password != NULL) { /* probe mount with entered password */ if (succs = cp_decrypt_header(hdr_key, *header, password)) { break; } } KeEnterCriticalRegion(); ExAcquireResourceSharedLite(&p_resource, TRUE); /* probe mount with cached passwords */ for (d_pass = f_pass; d_pass; d_pass = d_pass->next) { if (succs = cp_decrypt_header(hdr_key, *header, &d_pass->pass)) { break; } } ExReleaseResourceLite(&p_resource); KeLeaveCriticalRegion(); } while (0); if (succs != 0) { *res_key = hdr_key; hdr_key = NULL; resl = ST_OK; } else { resl = ST_PASS_ERR; } } while (0); if (resl != ST_OK && *header != NULL) { mm_secure_free(*header); *header = NULL; } if (hdr_key != NULL) { mm_secure_free(hdr_key); } return resl; }
NTSTATUS DokanEventRelease(__in PDEVICE_OBJECT DeviceObject) { PDokanDCB dcb; PDokanVCB vcb; PDokanFCB fcb; PDokanCCB ccb; PLIST_ENTRY fcbEntry, fcbNext, fcbHead; PLIST_ENTRY ccbEntry, ccbNext, ccbHead; NTSTATUS status = STATUS_SUCCESS; vcb = DeviceObject->DeviceExtension; if (GetIdentifierType(vcb) != VCB) { return STATUS_INVALID_PARAMETER; } dcb = vcb->Dcb; // ExAcquireResourceExclusiveLite(&dcb->Resource, TRUE); dcb->Mounted = 0; // ExReleaseResourceLite(&dcb->Resource); // search CCB list to complete not completed Directory Notification KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&vcb->Resource, TRUE); fcbHead = &vcb->NextFCB; for (fcbEntry = fcbHead->Flink; fcbEntry != fcbHead; fcbEntry = fcbNext) { fcbNext = fcbEntry->Flink; fcb = CONTAINING_RECORD(fcbEntry, DokanFCB, NextFCB); ExAcquireResourceExclusiveLite(&fcb->Resource, TRUE); ccbHead = &fcb->NextCCB; for (ccbEntry = ccbHead->Flink; ccbEntry != ccbHead; ccbEntry = ccbNext) { ccbNext = ccbEntry->Flink; ccb = CONTAINING_RECORD(ccbEntry, DokanCCB, NextCCB); DDbgPrint(" NotifyCleanup ccb:%p, context:%X, filename:%wZ\n", ccb, (ULONG)ccb->UserContext, &fcb->FileName); FsRtlNotifyCleanup(vcb->NotifySync, &vcb->DirNotifyList, ccb); } ExReleaseResourceLite(&fcb->Resource); } ExReleaseResourceLite(&vcb->Resource); KeLeaveCriticalRegion(); ReleasePendingIrp(&dcb->PendingIrp); ReleasePendingIrp(&dcb->PendingEvent); DokanStopCheckThread(dcb); DokanStopEventNotificationThread(dcb); DokanDeleteDeviceObject(dcb); return status; }
FORCEINLINE VOID ObpSdAcquireLockShared(IN POB_SD_CACHE_LIST CacheEntry) { /* Acquire the lock */ KeEnterCriticalRegion(); ExAcquirePushLockShared(&CacheEntry->PushLock); }
BOOLEAN MrLockGlobal(BOOLEAN ex) { KeEnterCriticalRegion(); if (!ex) return ExAcquireResourceSharedLite(&g_core.mc_lock, TRUE); return ExAcquireResourceExclusiveLite(&g_core.mc_lock, TRUE); }
/* * @implemented */ VOID NTAPI SeLockSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext) { PAGED_CODE(); KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&SepSubjectContextLock, TRUE); }
VOID FLTAPI FltUnregisterFilter(_In_ PFLT_FILTER Filter) { PFLT_INSTANCE Instance; PLIST_ENTRY CurrentEntry; NTSTATUS Status; /* Set the draining flag */ Status = FltpStartingToDrainObject(&Filter->Base); if (!NT_SUCCESS(Status)) { /* Someone already unregistered us, just remove our ref and bail */ FltObjectDereference(&Filter->Base); return; } /* Lock the instance list */ KeEnterCriticalRegion(); ExAcquireResourceSharedLite(&Filter->InstanceList.rLock, TRUE); /* Set the first entry in the list */ CurrentEntry = Filter->InstanceList.rList.Flink; /* Free all instances referenced by the filter */ while (CurrentEntry != &Filter->InstanceList.rList) { /* Get the record pointer */ Instance = CONTAINING_RECORD(CurrentEntry, FLT_INSTANCE, FilterLink); // FIXME: implement (void)Instance; /* Reset the pointer and move to next entry */ Instance = NULL; CurrentEntry = CurrentEntry->Flink; } /* We're done with instances now */ ExReleaseResourceLite(&Filter->InstanceList.rLock); KeLeaveCriticalRegion(); /* Remove the reference from the base object */ FltObjectDereference(&Filter->Base); /* Wait until we're sure nothing is using the filter */ FltpObjectRundownWait(&Filter->Base.RundownRef); /* Delete the instance list lock */ ExDeleteResourceLite(&Filter->InstanceList.rLock); /* We're finished cleaning up now */ FltpExRundownCompleted(&Filter->Base.RundownRef); /* Hand the memory back */ ExFreePoolWithTag(Filter, FM_TAG_FILTER); }
NTSTATUS NTAPI FsRecLoadFileSystem(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName) { UNICODE_STRING DriverName; PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension; NTSTATUS Status = STATUS_IMAGE_ALREADY_LOADED; PAGED_CODE(); /* Make sure we haven't already been called */ if (DeviceExtension->State != Loaded) { /* Acquire the load lock */ KeWaitForSingleObject(FsRecLoadSync, Executive, KernelMode, FALSE, NULL); KeEnterCriticalRegion(); /* Make sure we're active */ if (DeviceExtension->State == Pending) { /* Load the FS driver */ RtlInitUnicodeString(&DriverName, DriverServiceName); Status = ZwLoadDriver(&DriverName); /* Loop all the linked recognizer objects */ while (DeviceExtension->State != Unloading) { /* Set them to the unload state */ DeviceExtension->State = Unloading; /* Go to the next one */ DeviceObject = DeviceExtension->Alternate; DeviceExtension = DeviceObject->DeviceExtension; } } /* Make sure that we haven't already loaded the FS */ if (DeviceExtension->State != Loaded) { /* Unregiser us, and set us as loaded */ IoUnregisterFileSystem(DeviceObject); DeviceExtension->State = Loaded; } /* Release the lock */ KeSetEvent(FsRecLoadSync, 0, FALSE); KeLeaveCriticalRegion(); } /* Return */ return Status; }
void dc_insert_hook(dev_hook *hook) { KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&hooks_sync_resource, TRUE); InsertTailList(&hooks_list_head, &hook->hooks_list); ExReleaseResourceLite(&hooks_sync_resource); KeLeaveCriticalRegion(); }
void dc_remove_hook(dev_hook *hook) { KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&hooks_sync_resource, TRUE); RemoveEntryList(&hook->hooks_list); ExReleaseResourceLite(&hooks_sync_resource); KeLeaveCriticalRegion(); }
// // find bridge limit worker [checked] // UCHAR PciFindBridgeNumberLimitWorker(__in PPCI_FDO_EXTENSION StartFdoExt,__in PPCI_FDO_EXTENSION CurFdoExt,__in UCHAR BaseBus,__out PBOOLEAN Include) { PAGED_CODE(); if(CurFdoExt != StartFdoExt) { KeEnterCriticalRegion(); KeWaitForSingleObject(&CurFdoExt->ChildListLock,Executive,KernelMode,FALSE,0); } PPCI_PDO_EXTENSION ChildBridgeExt = CurFdoExt->ChildBridgePdoList; UCHAR Limit = 0; if(ChildBridgeExt) { while(ChildBridgeExt) { if(ChildBridgeExt->NotPresent) { PciDebugPrintf(0x100000,"Skipping not present bridge PDOX @ %p\n",ChildBridgeExt); } else if(PciAreBusNumbersConfigured(ChildBridgeExt)) { if(ChildBridgeExt->Dependent.type1.SecondaryBus > BaseBus && (ChildBridgeExt->Dependent.type1.SecondaryBus < Limit || !Limit)) Limit = ChildBridgeExt->Dependent.type1.SecondaryBus; } ChildBridgeExt = ChildBridgeExt->NextBridge; } } if(Limit) { *Include = FALSE; } else { if(CurFdoExt->ParentFdoExtension) { Limit = PciFindBridgeNumberLimitWorker(StartFdoExt,CurFdoExt->ParentFdoExtension,BaseBus,Include); } else { Limit = CurFdoExt->MaxSubordinateBus; *Include = TRUE; } } if(CurFdoExt != StartFdoExt) { KeSetEvent(&CurFdoExt->ChildListLock,IO_NO_INCREMENT,FALSE); KeLeaveCriticalRegion(); } return Limit; }
VOID SortedListReadLock(IN PSORTED_LIST pSortedList) { ASSERTMSG("Pointer to sorted list must not be NULL", pSortedList != NULL); ASSERTMSG("Calling lock routine for single threaded list!", pSortedList->bIsMultiThread == TRUE); ASSERTMSG("Sorted list lock acquire must occur at or below APC_LEVEL", KeGetCurrentIrql() <= APC_LEVEL); // acquire shared lock -- multiple readers can access the list at the same time KeEnterCriticalRegion(); ExAcquireResourceSharedLite(pSortedList->pLock, TRUE); InterlockedIncrement(&pSortedList->lReaderCount); }