本文整理汇总了C++中ExAcquireFastMutex函数的典型用法代码示例。如果您正苦于以下问题:C++ ExAcquireFastMutex函数的具体用法?C++ ExAcquireFastMutex怎么用?C++ ExAcquireFastMutex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ExAcquireFastMutex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bus_plugin_dev
NTSTATUS bus_plugin_dev(ioctl_usbvbus_plugin * plugin, PFDO_DEVICE_DATA fdodata,
PFILE_OBJECT fo)
{
PDEVICE_OBJECT pdo;
PPDO_DEVICE_DATA pdodata, old_pdodata;
NTSTATUS status;
ULONG len;
PLIST_ENTRY entry;
unsigned long i;
PAGED_CODE ();
Bus_KdPrint (fdodata, BUS_DBG_PNP_INFO,
("Exposing PDO\n"
"======addr: %d\n"
"======vendor:product: %04x:%04x\n",
plugin->addr,
plugin->vendor, plugin->product));
if(plugin->addr <= 0)
return STATUS_INVALID_PARAMETER;
ExAcquireFastMutex (&fdodata->Mutex);
for (entry = fdodata->ListOfPDOs.Flink;
entry != &fdodata->ListOfPDOs;
entry = entry->Flink) {
pdodata = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link);
if (plugin->addr == pdodata->SerialNo &&
pdodata->DevicePnPState != SurpriseRemovePending)
{
ExReleaseFastMutex (&fdodata->Mutex);
return STATUS_INVALID_PARAMETER;
}
}
ExReleaseFastMutex (&fdodata->Mutex);
// Create the PDO
//
Bus_KdPrint(fdodata, BUS_DBG_PNP_NOISE,
("fdodata->NextLowerDriver = 0x%p\n", fdodata->NextLowerDriver));
//
// PDO must have a name. You should let the system auto generate a
// name by specifying FILE_AUTOGENERATED_DEVICE_NAME in the
// DeviceCharacteristics parameter. Let us create a secure deviceobject,
// in case the child gets installed as a raw device (RawDeviceOK), to prevent
// an unpriviledged user accessing our device. This function is avaliable
// in a static WDMSEC.LIB and can be used in Win2k, XP, and Server 2003
// Just make sure that the GUID specified here is not a setup class GUID.
// If you specify a setup class guid, you must make sure that class is
// installed before enumerating the PDO.
//
status = IoCreateDeviceSecure(fdodata->Self->DriverObject,
sizeof (PDO_DEVICE_DATA),
NULL,
FILE_DEVICE_BUS_EXTENDER,
FILE_AUTOGENERATED_DEVICE_NAME |FILE_DEVICE_SECURE_OPEN,
FALSE,
&SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RWX_RES_RWX, // allow normal users to access the devices
(LPCGUID)&GUID_SD_BUSENUM_PDO,
&pdo);
if (!NT_SUCCESS (status)) {
return status;
}
pdodata = (PPDO_DEVICE_DATA) pdo->DeviceExtension;
#define HARDWARE_IDS_TPL L"USB\\Vid_%04x&Pid_%04x&Rev_%04xZUSB\\Vid_%04x&Pid_%04xZ"
len = sizeof(HARDWARE_IDS_TPL);
pdodata->HardwareIDs =
ExAllocatePoolWithTag (NonPagedPool, len, BUSENUM_POOL_TAG);
if (NULL == pdodata->HardwareIDs) {
IoDeleteDevice(pdo);
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlStringCchPrintfW(pdodata->HardwareIDs, len/sizeof(wchar_t),
HARDWARE_IDS_TPL,
plugin->vendor, plugin->product, plugin->version,
plugin->vendor, plugin->product);
for(i=0;i<len/sizeof(wchar_t);i++){
if('Z'==pdodata->HardwareIDs[i])
pdodata->HardwareIDs[i]=0;
}
#define COMPATIBLE_IDS_TPL L"USB\\Class_%02x&SubClass_%02x&Prot_%02xZUSB\\Class_%02x&SubClass_%02xZUSB\\Class_%02xZ"
#define COMPATIBLE_COMPOSITE_IDS_TPL L"USB\\Class_%02x&SubClass_%02x&Prot_%02xZUSB\\Class_%02x&SubClass_%02xZUSB\\Class_%02xZUSB\\COMPOSITEZ"
if(plugin->inum>1)
len = sizeof(COMPATIBLE_COMPOSITE_IDS_TPL);
else
len = sizeof(COMPATIBLE_IDS_TPL);
pdodata->compatible_ids =
ExAllocatePoolWithTag (NonPagedPool, len, BUSENUM_POOL_TAG);
if (NULL == pdodata->compatible_ids) {
//.........这里部分代码省略.........
示例2: DoPdoPnP
// for pdo
NTSTATUS DoPdoPnP(PDEVICE_OBJECT pDevice,PIRP pIrp)
{
NTSTATUS status = STATUS_SUCCESS;
PPdoExt pPdoExt = static_cast<PPdoExt>(pDevice->DeviceExtension);
PIO_STACK_LOCATION pIoStack = IoGetCurrentIrpStackLocation(pIrp);
switch(pIoStack->MinorFunction)
{
case IRP_MN_START_DEVICE:
// set power state
pPdoExt->m_devPowerState = PowerDeviceD0;
POWER_STATE state;
state.DeviceState = PowerDeviceD0;
PoSetPowerState(pDevice,DevicePowerState,state);
// set pnp state directly
case IRP_MN_STOP_DEVICE:
case IRP_MN_QUERY_STOP_DEVICE:
case IRP_MN_QUERY_REMOVE_DEVICE:
SetNewPnpState(pPdoExt,pIoStack->MinorFunction);
break;
// check prev state
case IRP_MN_CANCEL_REMOVE_DEVICE:
if(pPdoExt->m_ulCurrentPnpState == IRP_MN_QUERY_REMOVE_DEVICE)
{
RestorePnpState(pPdoExt);
}
break;
// the same
case IRP_MN_CANCEL_STOP_DEVICE:
if(pPdoExt->m_ulCurrentPnpState == IRP_MN_QUERY_STOP_DEVICE)
{
RestorePnpState(pPdoExt);
}
break;
// remove
case IRP_MN_REMOVE_DEVICE:
{
// delete only if we have reported the device physical removal
if(pPdoExt->m_bReportMissing)
{
SetNewPnpState(pPdoExt,IRP_MN_REMOVE_DEVICE);
PDEVICE_OBJECT pFdo = pPdoExt->m_pParentFdo;
if(pFdo)
{
PFdoExt pFdoExt = static_cast<PFdoExt>(pFdo->DeviceExtension);
// update fdo's pointer
ExAcquireFastMutex(&pFdoExt->m_mutexEnumPdo);
pFdoExt->m_pEnumPdo = NULL;
ExReleaseFastMutex(&pFdoExt->m_mutexEnumPdo);
}
// delete device
IoDeleteDevice(pDevice);
}
// if it's present
if(pPdoExt->m_bPresent)
{
// set it as stopped
SetNewPnpState(pPdoExt,IRP_MN_STOP_DEVICE);
}
}
break;
// query caps
case IRP_MN_QUERY_CAPABILITIES:
{
PDEVICE_CAPABILITIES pCaps = pIoStack->Parameters.DeviceCapabilities.Capabilities;
// version check
if(pCaps->Version != 1 || pCaps->Size < sizeof(DEVICE_CAPABILITIES))
{
status = STATUS_UNSUCCESSFUL;
break;
}
IO_STATUS_BLOCK ioStatus;
KEVENT pnpEvent;
PDEVICE_OBJECT pTargetObject;
PIO_STACK_LOCATION pIrpStack;
PIRP pPnpIrp;
DEVICE_CAPABILITIES parentCaps;
RtlZeroMemory(&parentCaps,sizeof(DEVICE_CAPABILITIES));
parentCaps.Size = sizeof(DEVICE_CAPABILITIES);
parentCaps.Version = 1;
parentCaps.Address = -1;
parentCaps.UINumber = -1;
KeInitializeEvent(&pnpEvent,NotificationEvent,FALSE);
//.........这里部分代码省略.........
示例3: SecondaryRecoverySession
//.........这里部分代码省略.........
} else {
continue;
}
KeInitializeEvent( &Secondary->ReadyEvent, NotificationEvent, FALSE );
KeInitializeEvent( &Secondary->RequestEvent, NotificationEvent, FALSE );
InitializeObjectAttributes(&objectAttributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
status = PsCreateSystemThread( &Secondary->ThreadHandle,
THREAD_ALL_ACCESS,
&objectAttributes,
NULL,
NULL,
SecondaryThreadProc,
Secondary );
if (!NT_SUCCESS(status)) {
ASSERT( NDASNTFS_UNEXPECTED );
break;
}
status = ObReferenceObjectByHandle( Secondary->ThreadHandle,
FILE_READ_DATA,
NULL,
KernelMode,
&Secondary->ThreadObject,
NULL );
if (!NT_SUCCESS(status)) {
ASSERT( NDASNTFS_INSUFFICIENT_RESOURCES );
break;
}
timeOut.QuadPart = -NDASNTFS_TIME_OUT;
status = KeWaitForSingleObject( &Secondary->ReadyEvent,
Executive,
KernelMode,
FALSE,
&timeOut );
if(status != STATUS_SUCCESS) {
ASSERT( NDASNTFS_BUG );
break;
}
KeClearEvent( &Secondary->ReadyEvent );
InterlockedIncrement( &Secondary->SessionId );
ExAcquireFastMutex( &Secondary->FastMutex );
if (!FlagOn(Secondary->Thread.Flags, SECONDARY_THREAD_FLAG_START) || FlagOn(Secondary->Thread.Flags, SECONDARY_THREAD_FLAG_STOPED)) {
ExReleaseFastMutex( &Secondary->FastMutex );
if(Secondary->Thread.SessionStatus == STATUS_DISK_CORRUPT_ERROR) {
status = STATUS_SUCCESS;
break;
}
timeOut.QuadPart = -NDASNTFS_TIME_OUT;
status = KeWaitForSingleObject( Secondary->ThreadObject,
Executive,
KernelMode,
FALSE,
&timeOut );
if(status != STATUS_SUCCESS) {
ASSERT( NDASNTFS_BUG );
return status;
}
DebugTrace( 0, Dbg, ("Secondary_Stop: thread stoped\n") );
ObDereferenceObject( Secondary->ThreadObject );
Secondary->ThreadHandle = 0;
Secondary->ThreadObject = 0;
RtlZeroMemory( &Secondary->Thread.Flags, sizeof(SECONDARY) - FIELD_OFFSET(SECONDARY, Thread.Flags) );
continue;
}
ExReleaseFastMutex( &Secondary->FastMutex );
status = STATUS_SUCCESS;
DebugTrace( 0, Dbg2, ("SessionRecovery Success Secondary = %p\n", Secondary) );
break;
}
示例4: SecondaryTryClose
VOID
SecondaryTryClose (
IN PSECONDARY Secondary
)
{
PIRP_CONTEXT irpContext;
BOOLEAN secondaryResourceAcquired = FALSE;
BOOLEAN acquiredVcb = FALSE;
BOOLEAN wait;
irpContext = FatAllocateIrpContext();
if (irpContext == NULL) {
return;
}
DebugTrace2( 0, Dbg, ("Secondary_TryCloseFiles start\n") );
try {
RtlZeroMemory( irpContext, sizeof(IRP_CONTEXT) );
SetFlag( irpContext->Flags, IRP_CONTEXT_FLAG_WAIT );
SetFlag( irpContext->NdasFatFlags, NDAS_FAT_IRP_CONTEXT_FLAG_SECONDARY_CONTEXT );
irpContext->Vcb = &Secondary->VolDo->Vcb;
secondaryResourceAcquired = SecondaryAcquireResourceSharedLite( irpContext,
&Secondary->VolDo->Resource,
FALSE );
if (secondaryResourceAcquired == FALSE) {
leave;
}
wait = BooleanFlagOn( irpContext->Flags, IRP_CONTEXT_FLAG_WAIT );
acquiredVcb = FatAcquireExclusiveVcb( irpContext, irpContext->Vcb );
if (acquiredVcb == FALSE) {
leave;
}
FsRtlEnterFileSystem();
FatFspClose( &Secondary->VolDo->Vcb );
FsRtlExitFileSystem();
DebugTrace2( 0, Dbg, ("Secondary_TryCloseFiles FatFspClose, Secondary->VolDo->Vcb.SecondaryOpenCount = %d\n",
Secondary->VolDo->Vcb.SecondaryOpenFileCount) );
SetFlag( irpContext->NdasFatFlags, NDAS_FAT_IRP_CONTEXT_FLAG_TRY_CLOSE_FILES );
Secondary_TryCloseFilExts( Secondary );
} finally {
ClearFlag( irpContext->NdasFatFlags, NDAS_FAT_IRP_CONTEXT_FLAG_TRY_CLOSE_FILES );
if (acquiredVcb) {
FatReleaseVcb( irpContext, irpContext->Vcb );
}
DebugTrace2( 0, Dbg, ("Secondary_TryCloseFiles exit\n") );
ExAcquireFastMutex( &Secondary->FastMutex );
Secondary->TryCloseActive = FALSE;
ExReleaseFastMutex( &Secondary->FastMutex );
if (secondaryResourceAcquired)
SecondaryReleaseResourceLite( NULL, &Secondary->VolDo->Resource );
Secondary_Dereference(Secondary);
FatFreeIrpContext(irpContext);
}
return;
}
示例5: FatCommonPnp
//.........这里部分代码省略.........
FatCompleteRequest( IrpContext, Irp, Status );
return Status;
}
#if __NDAS_FAT__
if (OurDeviceObject->NetdiskEnableMode == NETDISK_SECONDARY)
SetFlag( IrpContext->NdFatFlags, ND_FAT_IRP_CONTEXT_FLAG_SECONDARY_CONTEXT );
#endif
Vcb = &OurDeviceObject->Vcb;
//
// Case on the minor code.
//
#if __NDAS_FAT_SECONDARY__
if ( ((PVOLUME_DEVICE_OBJECT)IrpSp->DeviceObject)->Secondary &&
( ((PVOLUME_DEVICE_OBJECT)IrpSp->DeviceObject)->NetdiskEnableMode == NETDISK_SECONDARY ||
((PVOLUME_DEVICE_OBJECT)IrpSp->DeviceObject)->NetdiskEnableMode == NETDISK_SECONDARY2PRIMARY ) )
{
PSECONDARY Secondary = ((PVOLUME_DEVICE_OBJECT)IrpSp->DeviceObject)->Secondary;
Status = STATUS_SUCCESS;
Secondary_Reference( Secondary );
switch ( IrpSp->MinorFunction ) {
case IRP_MN_QUERY_REMOVE_DEVICE: {
DebugTrace2( 0, Dbg, ("FatCommonPnp: IRP_MN_QUERY_REMOVE_DEVICE NetdiskEnableMode = %d\n", ((PVOLUME_DEVICE_OBJECT)IrpSp->DeviceObject)->NetdiskEnableMode) );
ExAcquireFastMutex( &Secondary->FastMutex );
if (!Secondary->TryCloseActive) {
Secondary->TryCloseActive = TRUE;
ExReleaseFastMutex( &Secondary->FastMutex );
Secondary_Reference( Secondary );
//FatDebugTraceLevel |= DEBUG_TRACE_CLOSE;
SecondaryTryClose( IrpContext, Secondary );
//FatDebugTraceLevel &= ~DEBUG_TRACE_CLOSE;
} else {
ExReleaseFastMutex( &Secondary->FastMutex );
}
if (Vcb->SecondaryOpenFileCount) {
LARGE_INTEGER interval;
// Wait all files closed
interval.QuadPart = (1 * HZ); //delay 1 seconds
KeDelayExecutionThread(KernelMode, FALSE, &interval);
}
#if 0
if (Vcb->SecondaryOpenFileCount) {
LONG ccbCount;
PLIST_ENTRY ccbListEntry;
PVOID restartKey;
PFCB fcb;
示例6: Bus_InitializePdo
VOID
Bus_InitializePdo (
PDEVICE_OBJECT Pdo,
PFDO_DEVICE_DATA FdoData
)
{
PPDO_DEVICE_DATA pdoData;
int acpistate;
DEVICE_POWER_STATE ntState;
PAGED_CODE ();
pdoData = (PPDO_DEVICE_DATA) Pdo->DeviceExtension;
DPRINT("pdo 0x%p, extension 0x%p\n", Pdo, pdoData);
if (pdoData->AcpiHandle)
acpi_bus_get_power(pdoData->AcpiHandle, &acpistate);
else
acpistate = ACPI_STATE_D0;
switch(acpistate)
{
case ACPI_STATE_D0:
ntState = PowerDeviceD0;
break;
case ACPI_STATE_D1:
ntState = PowerDeviceD1;
break;
case ACPI_STATE_D2:
ntState = PowerDeviceD2;
break;
case ACPI_STATE_D3:
ntState = PowerDeviceD3;
break;
default:
DPRINT1("Unknown power state (%d) returned by acpi\n",acpistate);
ntState = PowerDeviceUnspecified;
break;
}
//
// Initialize the rest
//
pdoData->Common.IsFDO = FALSE;
pdoData->Common.Self = Pdo;
pdoData->ParentFdo = FdoData->Common.Self;
INITIALIZE_PNP_STATE(pdoData->Common);
pdoData->Common.DevicePowerState = ntState;
pdoData->Common.SystemPowerState = FdoData->Common.SystemPowerState;
Pdo->Flags |= DO_POWER_PAGABLE;
ExAcquireFastMutex (&FdoData->Mutex);
InsertTailList(&FdoData->ListOfPDOs, &pdoData->Link);
FdoData->NumPDOs++;
ExReleaseFastMutex (&FdoData->Mutex);
// This should be the last step in initialization.
Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
}
示例7: Secondary_Create
//.........这里部分代码省略.........
ExInitializeFastMutex( &secondary->RecoveryCcbQMutex );
InitializeListHead( &secondary->DeletedFcbQueue );
KeQuerySystemTime( &secondary->TryCloseTime );
secondary->TryCloseWorkItem = IoAllocateWorkItem( (PDEVICE_OBJECT)VolDo );
KeInitializeEvent( &secondary->ReadyEvent, NotificationEvent, FALSE );
InitializeListHead( &secondary->RequestQueue );
KeInitializeSpinLock( &secondary->RequestQSpinLock );
KeInitializeEvent( &secondary->RequestEvent, NotificationEvent, FALSE );
InitializeListHead( &secondary->FcbQueue );
ExInitializeFastMutex( &secondary->FcbQMutex );
KeInitializeEvent( &secondary->RecoveryReadyEvent, NotificationEvent, FALSE );
InitializeObjectAttributes( &objectAttributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL );
secondary->SessionId = 0;
status = PsCreateSystemThread( &secondary->ThreadHandle,
THREAD_ALL_ACCESS,
&objectAttributes,
NULL,
NULL,
SecondaryThreadProc,
secondary );
if (!NT_SUCCESS(status)) {
ASSERT( NDASFAT_UNEXPECTED );
Secondary_Close( secondary );
return NULL;
}
status = ObReferenceObjectByHandle( secondary->ThreadHandle,
FILE_READ_DATA,
NULL,
KernelMode,
&secondary->ThreadObject,
NULL );
if (!NT_SUCCESS(status)) {
ASSERT( NDASFAT_INSUFFICIENT_RESOURCES );
Secondary_Close( secondary );
return NULL;
}
secondary->SessionId ++;
timeOut.QuadPart = -NDASFAT_TIME_OUT;
status = KeWaitForSingleObject( &secondary->ReadyEvent,
Executive,
KernelMode,
FALSE,
&timeOut );
if (status != STATUS_SUCCESS) {
NDAS_ASSERT( FALSE );
Secondary_Close( secondary );
return NULL;
}
KeClearEvent( &secondary->ReadyEvent );
ExAcquireFastMutex( &secondary->FastMutex );
if (!FlagOn(secondary->Thread.Flags, SECONDARY_THREAD_FLAG_START) ||
FlagOn(secondary->Thread.Flags, SECONDARY_THREAD_FLAG_STOPED)) {
if (secondary->Thread.SessionStatus != STATUS_DISK_CORRUPT_ERROR &&
secondary->Thread.SessionStatus != STATUS_UNRECOGNIZED_VOLUME) {
ExReleaseFastMutex( &secondary->FastMutex );
Secondary_Close( secondary );
return NULL;
}
}
ASSERT( secondary->Thread.SessionContext.SessionSlotCount != 0 );
ClearFlag( secondary->Flags, SECONDARY_FLAG_INITIALIZING );
SetFlag( secondary->Flags, SECONDARY_FLAG_START );
ExReleaseFastMutex( &secondary->FastMutex );
DebugTrace2( 0, Dbg2,
("Secondary_Create: The client thread are ready secondary = %p\n", secondary) );
return secondary;
}
示例8: Readonly_Close
VOID
Readonly_Close (
IN PREADONLY Readonly
)
{
NTSTATUS status;
LARGE_INTEGER timeOut;
PLIST_ENTRY readonlyRequestEntry;
PREADONLY_REQUEST readonlyRequest;
SPY_LOG_PRINT( LFS_DEBUG_READONLY_INFO, ("Readonly close Readonly = %p\n", Readonly) );
ExAcquireFastMutex( &Readonly->FastMutex );
ASSERT( !FlagOn(Readonly->Flags, READONLY_FLAG_RECONNECTING) );
if (FlagOn(Readonly->Flags, READONLY_FLAG_CLOSED)) {
//ASSERT( FALSE );
ExReleaseFastMutex( &Readonly->FastMutex );
return;
}
SetFlag( Readonly->Flags, READONLY_FLAG_CLOSED );
ExReleaseFastMutex( &Readonly->FastMutex );
FsRtlNotifyUninitializeSync( &Readonly->NotifySync );
if (Readonly->ThreadHandle == NULL) {
//ASSERT( FALSE );
Readonly_Dereference( Readonly );
return;
}
ASSERT( Readonly->ThreadObject != NULL );
SPY_LOG_PRINT( LFS_DEBUG_READONLY_TRACE, ("Readonly close READONLY_REQ_DISCONNECT Readonly = %p\n", Readonly) );
readonlyRequest = AllocReadonlyRequest( Readonly, 0, FALSE );
readonlyRequest->RequestType = READONLY_REQ_DISCONNECT;
QueueingReadonlyRequest( Readonly, readonlyRequest );
readonlyRequest = AllocReadonlyRequest( Readonly, 0, FALSE );
readonlyRequest->RequestType = READONLY_REQ_DOWN;
QueueingReadonlyRequest( Readonly, readonlyRequest );
SPY_LOG_PRINT( LFS_DEBUG_READONLY_TRACE, ("Readonly close READONLY_REQ_DISCONNECT end Readonly = %p\n", Readonly) );
timeOut.QuadPart = -LFS_TIME_OUT;
status = KeWaitForSingleObject( Readonly->ThreadObject,
Executive,
KernelMode,
FALSE,
&timeOut );
if (status == STATUS_SUCCESS) {
SPY_LOG_PRINT( LFS_DEBUG_READONLY_TRACE, ("Readonly_Close: thread stoped Readonly = %p\n", Readonly) );
ObDereferenceObject( Readonly->ThreadObject );
Readonly->ThreadHandle = NULL;
Readonly->ThreadObject = NULL;
} else {
ASSERT( LFS_BUG );
return;
}
if (!IsListEmpty(&Readonly->FcbQueue))
NDAS_ASSERT( FALSE );
if (!IsListEmpty(&Readonly->CcbQueue))
NDAS_ASSERT( FALSE );
if (!IsListEmpty(&Readonly->RequestQueue))
NDAS_ASSERT( FALSE );
while (readonlyRequestEntry = ExInterlockedRemoveHeadList(&Readonly->RequestQueue,
&Readonly->RequestQSpinLock)) {
PREADONLY_REQUEST readonlyRequest2;
InitializeListHead( readonlyRequestEntry );
readonlyRequest2 = CONTAINING_RECORD( readonlyRequestEntry,
READONLY_REQUEST,
ListEntry );
readonlyRequest2->ExecuteStatus = STATUS_IO_DEVICE_ERROR;
if (readonlyRequest2->Synchronous == TRUE)
//.........这里部分代码省略.........
示例9: ReadonlyThreadProc
VOID
ReadonlyThreadProc (
IN PREADONLY Readonly
)
{
BOOLEAN readonlyThreadTerminate = FALSE;
PLIST_ENTRY readonlyRequestEntry;
SPY_LOG_PRINT( LFS_DEBUG_READONLY_TRACE, ("ReadonlyThreadProc: Start Readonly = %p\n", Readonly) );
Readonly_Reference( Readonly );
Readonly->Thread.Flags = READONLY_THREAD_FLAG_INITIALIZING;
ExAcquireFastMutex( &Readonly->FastMutex );
SetFlag( Readonly->Thread.Flags, READONLY_THREAD_FLAG_START );
ClearFlag( Readonly->Thread.Flags, READONLY_THREAD_FLAG_INITIALIZING );
ExReleaseFastMutex( &Readonly->FastMutex );
KeSetEvent( &Readonly->ReadyEvent, IO_DISK_INCREMENT, FALSE );
readonlyThreadTerminate = FALSE;
while (readonlyThreadTerminate == FALSE) {
PKEVENT events[2];
LONG eventCount;
NTSTATUS eventStatus;
LARGE_INTEGER timeOut;
ASSERT( KeGetCurrentIrql() == PASSIVE_LEVEL );
eventCount = 0;
events[eventCount++] = &Readonly->RequestEvent;
timeOut.QuadPart = -LFS_READONLY_THREAD_FLAG_TIME_OUT;
eventStatus = KeWaitForMultipleObjects( eventCount,
events,
WaitAny,
Executive,
KernelMode,
TRUE,
&timeOut,
NULL );
if (eventStatus == STATUS_TIMEOUT) {
ReadonlyTryCloseCcb( Readonly );
ReadonlyDismountVolumeStart( Readonly );
continue;
}
ASSERT( KeGetCurrentIrql() == PASSIVE_LEVEL );
ASSERT( eventCount < THREAD_WAIT_OBJECTS );
if (!NT_SUCCESS( eventStatus ) || eventStatus >= eventCount) {
ASSERT( LFS_UNEXPECTED );
SetFlag( Readonly->Thread.Flags, READONLY_THREAD_FLAG_ERROR );
readonlyThreadTerminate = TRUE;
continue;
}
KeClearEvent( events[eventStatus] );
if (eventStatus == 0) {
while (!FlagOn(Readonly->Thread.Flags, READONLY_THREAD_FLAG_STOPED) &&
(readonlyRequestEntry = ExInterlockedRemoveHeadList(&Readonly->RequestQueue,
&Readonly->RequestQSpinLock))) {
PREADONLY_REQUEST readonlyRequest;
InitializeListHead( readonlyRequestEntry );
readonlyRequest = CONTAINING_RECORD( readonlyRequestEntry,
READONLY_REQUEST,
ListEntry );
if (!(readonlyRequest->RequestType == READONLY_REQ_DISCONNECT ||
readonlyRequest->RequestType == READONLY_REQ_DOWN ||
readonlyRequest->RequestType == READONLY_REQ_SEND_MESSAGE)) {
ASSERT( FALSE );
ExAcquireFastMutex( &Readonly->FastMutex );
SetFlag( Readonly->Thread.Flags, READONLY_THREAD_FLAG_STOPED | READONLY_THREAD_FLAG_ERROR );
ExReleaseFastMutex( &Readonly->FastMutex );
ExInterlockedInsertHeadList( &Readonly->RequestQueue,
&readonlyRequest->ListEntry,
&Readonly->RequestQSpinLock );
readonlyThreadTerminate = TRUE;
break;
}
//.........这里部分代码省略.........
示例10: IsRegionExempted
//
// Checks to see if a supplied region is exempted from being allocated into
//
BOOLEAN IsRegionExempted(
IN PVOID RegionBase,
IN ULONG RegionSize,
OUT PULONG EndDisplacement OPTIONAL)
{
PLIST_ENTRY Current;
BOOLEAN Exempted = FALSE;
//
// Acquire the region exemption list mutex
//
ExAcquireFastMutex(
&RegionExemptionListMutex);
//
// Enumerate through all of the region exemptions
//
for (Current = RegionExemptionList.Flink;
(Current != &RegionExemptionList) && (!Exempted);
Current = Current->Flink)
{
PREGION_EXEMPTION Exemption = (PREGION_EXEMPTION)Current;
Exempted = (
(IsAddressInsideRange(
RegionBase,
Exemption->Base,
Exemption->Size)) ||
(IsAddressInsideRange(
Exemption->Base,
RegionBase,
RegionSize))) ? TRUE : FALSE;
//
// If this region is exempted and the caller requested a displacement
// calculation, pass one back to them such that they can optimize their
// search by knowing how much to add to their region base to get outside
// of the exempted region.
//
if ((Exempted) &&
(EndDisplacement))
{
//
// The number of bytes that will have to be incremented by to get the
// supplied region out of the area of the exempted region is calculated
// by subtracting the end of the exempted region from the start of the
// supplied region.
//
*EndDisplacement = (ULONG)((Exemption->Base + Exemption->Size) - (ULONG_PTR)RegionBase);
//
// Assert that the end of the exempted region is always greater than
// the region base, which should always be true.
//
ASSERT((Exemption->Base + Exemption->Size) > (ULONG_PTR)RegionBase);
}
}
//
// Release the region exemption list mutex
//
ExReleaseFastMutex(
&RegionExemptionListMutex);
return Exempted;
}
示例11: ReadonlyPassThrough
BOOLEAN
ReadonlyPassThrough (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PFILESPY_DEVICE_EXTENSION DevExt,
OUT PNTSTATUS NtStatus
)
{
NTSTATUS status = STATUS_SUCCESS;
BOOLEAN result = FALSE;
PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
PFILE_OBJECT fileObject = irpSp->FileObject;
BOOLEAN fastMutexAcquired = FALSE;
UNREFERENCED_PARAMETER( DeviceObject );
ASSERT( DevExt->LfsDeviceExt.ReferenceCount );
LfsDeviceExt_Reference( &DevExt->LfsDeviceExt );
PrintIrp( LFS_DEBUG_READONLY_NOISE, __FUNCTION__, &DevExt->LfsDeviceExt, Irp );
ASSERT( KeGetCurrentIrql() <= APC_LEVEL );
ExAcquireFastMutex( &DevExt->LfsDeviceExt.FastMutex );
fastMutexAcquired = TRUE;
try {
if (!FlagOn(DevExt->LfsDeviceExt.Flags, LFS_DEVICE_FLAG_MOUNTED)) {
result = FALSE;
leave;
}
ASSERT( DevExt->LfsDeviceExt.AttachedToDeviceObject == DevExt->NLExtHeader.AttachedToDeviceObject );
if (DevExt->LfsDeviceExt.AttachedToDeviceObject == NULL) {
NDAS_ASSERT( FALSE );
result = FALSE;
leave;
}
if (!(FlagOn(DevExt->LfsDeviceExt.Flags, LFS_DEVICE_FLAG_MOUNTED) && !FlagOn(DevExt->LfsDeviceExt.Flags, LFS_DEVICE_FLAG_DISMOUNTED))) {
ASSERT( DevExt->LfsDeviceExt.Readonly == NULL || ReadonlyLookUpCcb(DevExt->LfsDeviceExt.Readonly, fileObject) == NULL );
result = FALSE;
leave;
}
switch (irpSp->MajorFunction) {
case IRP_MJ_PNP:
break;
default:
ExReleaseFastMutex( &DevExt->LfsDeviceExt.FastMutex );
fastMutexAcquired = FALSE;
if (DevExt->LfsDeviceExt.Readonly) {
status = ReadonlyRedirectIrp( DevExt, Irp, &result );
} else {
result = FALSE;
}
leave;
}
if (irpSp->MajorFunction == IRP_MJ_PNP) {
PrintIrp( LFS_DEBUG_READONLY_NOISE, __FUNCTION__, &DevExt->LfsDeviceExt, Irp );
if (irpSp->MinorFunction == IRP_MN_SURPRISE_REMOVAL) {
if (DevExt->LfsDeviceExt.NetdiskPartition == NULL) {
NDAS_ASSERT( FALSE );
} else {
SetFlag( DevExt->LfsDeviceExt.Flags, LFS_DEVICE_FLAG_SURPRISE_REMOVED );
ExReleaseFastMutex( &DevExt->LfsDeviceExt.FastMutex );
fastMutexAcquired = FALSE;
NetdiskManager_SurpriseRemoval( GlobalLfs.NetdiskManager,
DevExt->LfsDeviceExt.NetdiskPartition,
DevExt->LfsDeviceExt.NetdiskEnabledMode );
}
DevExt->LfsDeviceExt.NetdiskPartition = NULL;
//.........这里部分代码省略.........
示例12: Bus_FDO_PnP
//.........这里部分代码省略.........
// call the next driver.
//
//
// First check to see whether you have received cancel-remove
// without first receiving a query-remove. This could happen if
// someone above us fails a query-remove and passes down the
// subsequent cancel-remove.
//
if (RemovePending == DeviceData->DevicePnPState)
{
//
// We did receive a query-remove, so restore.
//
RESTORE_PREVIOUS_PNP_STATE(DeviceData);
}
Irp->IoStatus.Status = STATUS_SUCCESS;// You must not fail the IRP.
break;
case IRP_MN_SURPRISE_REMOVAL:
//
// The device has been unexpectedly removed from the machine
// and is no longer available for I/O. Bus_RemoveFdo clears
// all the resources, frees the interface and de-registers
// with WMI, but it doesn't delete the FDO. That's done
// later in Remove device query.
//
SET_NEW_PNP_STATE(DeviceData, SurpriseRemovePending);
Bus_RemoveFdo(DeviceData);
ExAcquireFastMutex (&DeviceData->Mutex);
listHead = &DeviceData->ListOfPDOs;
for(entry = listHead->Flink,nextEntry = entry->Flink;
entry != listHead;
entry = nextEntry,nextEntry = entry->Flink) {
pdoData = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link);
RemoveEntryList (&pdoData->Link);
InitializeListHead (&pdoData->Link);
pdoData->ParentFdo = NULL;
pdoData->ReportedMissing = TRUE;
}
ExReleaseFastMutex (&DeviceData->Mutex);
Irp->IoStatus.Status = STATUS_SUCCESS; // You must not fail the IRP.
break;
case IRP_MN_REMOVE_DEVICE:
//
// The Plug & Play system has dictated the removal of this device.
// We have no choice but to detach and delete the device object.
//
//
// Check the state flag to see whether you are surprise removed
//
if (DeviceData->DevicePnPState != SurpriseRemovePending)
{
示例13: Bus_EjectDevice
NTSTATUS
Bus_EjectDevice (
PBUSENUM_EJECT_HARDWARE Eject,
PFDO_DEVICE_DATA FdoData
)
/*++
Routine Description:
The user application has told us to eject the device from the bus.
In a real situation the driver gets notified by an interrupt when the
user presses the Eject button on the device.
Arguments:
Eject - pointer to Eject hardware structure.
FdoData - contains the list to iterate over
Returns:
STATUS_SUCCESS upon successful removal from the list
STATUS_INVALID_PARAMETER if the removal was unsuccessful
--*/
{
PLIST_ENTRY entry;
PPDO_DEVICE_DATA pdoData;
BOOLEAN found = FALSE, ejectAll;
PAGED_CODE ();
ejectAll = (0 == Eject->SerialNo);
ExAcquireFastMutex (&FdoData->Mutex);
if (ejectAll) {
Bus_KdPrint (FdoData, BUS_DBG_IOCTL_NOISE,
("Ejecting all the pdos!\n"));
} else {
Bus_KdPrint (FdoData, BUS_DBG_IOCTL_NOISE,
("Ejecting %d\n", Eject->SerialNo));
}
if (FdoData->NumPDOs == 0) {
//
// Somebody in user space isn't playing nice!!!
//
Bus_KdPrint (FdoData, BUS_DBG_IOCTL_ERROR,
("No devices to eject!\n"));
ExReleaseFastMutex (&FdoData->Mutex);
return STATUS_NO_SUCH_DEVICE;
}
//
// Scan the list to find matching PDOs
//
for (entry = FdoData->ListOfPDOs.Flink;
entry != &FdoData->ListOfPDOs;
entry = entry->Flink) {
pdoData = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link);
Bus_KdPrint (FdoData, BUS_DBG_IOCTL_NOISE,
("found device %d\n", pdoData->SerialNo));
if (ejectAll || Eject->SerialNo == pdoData->SerialNo) {
Bus_KdPrint (FdoData, BUS_DBG_IOCTL_INFO,
("Ejected %d\n", pdoData->SerialNo));
found = TRUE;
IoRequestDeviceEject(pdoData->Self);
if (!ejectAll) {
break;
}
}
}
ExReleaseFastMutex (&FdoData->Mutex);
if (found) {
return STATUS_SUCCESS;
}
Bus_KdPrint (FdoData, BUS_DBG_IOCTL_ERROR,
("Device %d is not present\n", Eject->SerialNo));
return STATUS_INVALID_PARAMETER;
}
示例14: bus_unplug_dev
NTSTATUS
bus_unplug_dev (
int addr,
PFDO_DEVICE_DATA fdodata
)
{
PLIST_ENTRY entry;
PPDO_DEVICE_DATA pdodata;
int found=0, all;
PAGED_CODE ();
if(addr<0||addr>127)
return STATUS_INVALID_PARAMETER;
all = (0 == addr);
ExAcquireFastMutex (&fdodata->Mutex);
if (all) {
Bus_KdPrint (fdodata, BUS_DBG_IOCTL_NOISE,
("Plugging out all the devices!\n"));
} else {
Bus_KdPrint (fdodata, BUS_DBG_IOCTL_NOISE,
("Plugging out %d\n", addr));
}
if (fdodata->NumPDOs == 0) {
//
// We got a 2nd plugout...somebody in user space isn't playing nice!!!
//
Bus_KdPrint (fdodata, BUS_DBG_IOCTL_ERROR,
("BAD BAD BAD...2 removes!!! Send only one!\n"));
ExReleaseFastMutex (&fdodata->Mutex);
return STATUS_NO_SUCH_DEVICE;
}
for (entry = fdodata->ListOfPDOs.Flink;
entry != &fdodata->ListOfPDOs;
entry = entry->Flink) {
pdodata = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link);
Bus_KdPrint (fdodata, BUS_DBG_IOCTL_NOISE,
("found device %d\n", pdodata->SerialNo));
if (all || addr == pdodata->SerialNo) {
Bus_KdPrint (fdodata, BUS_DBG_IOCTL_INFO,
("Plugging out %d\n", pdodata->SerialNo));
pdodata->Present = FALSE;
complete_pending_read_irp(pdodata);
found = 1;
if (!all) {
break;
}
}
}
ExReleaseFastMutex (&fdodata->Mutex);
if (found) {
IoInvalidateDeviceRelations (fdodata->UnderlyingPDO, BusRelations);
ExAcquireFastMutex (&fdodata->Mutex);
for (entry = fdodata->ListOfPDOs.Flink;
entry != &fdodata->ListOfPDOs;
entry = entry->Flink) {
pdodata = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link);
if( pdodata->Present ==FALSE){
complete_pending_irp(pdodata);
SET_NEW_PNP_STATE(pdodata,PNP_DEVICE_REMOVED);
IoInvalidateDeviceState(pdodata->Self);
}
}
ExReleaseFastMutex (&fdodata->Mutex);
Bus_KdPrint (fdodata, BUS_DBG_IOCTL_ERROR,
("Device %d plug out finished\n", addr));
return STATUS_SUCCESS;
}
return STATUS_INVALID_PARAMETER;
}
示例15: ExFreeToPagedLookasideList
VOID
ExFreeToPagedLookasideList(
IN PPAGED_LOOKASIDE_LIST Lookaside,
IN PVOID Entry
)
/*++
Routine Description:
This function inserts (pushes) the specified entry into the specified
paged lookaside list.
Arguments:
Lookaside - Supplies a pointer to a paged lookaside list structure.
Entry - Supples a pointer to the entry that is inserted in the
lookaside list.
Return Value:
None.
--*/
{
Lookaside->L.TotalFrees += 1;
#if !defined(_PPC_)
if (Isx86FeaturePresent(KF_CMPXCHG8B)) {
if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
Lookaside->L.FreeMisses += 1;
(Lookaside->L.Free)(Entry);
} else {
ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
(PSINGLE_LIST_ENTRY)Entry,
NULL);
}
return;
}
#endif
ExAcquireFastMutex(&Lookaside->Lock);
if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
ExReleaseFastMutex(&Lookaside->Lock);
Lookaside->L.FreeMisses += 1;
(Lookaside->L.Free)(Entry);
} else {
PushEntryList(&Lookaside->L.ListHead.Next, (PSINGLE_LIST_ENTRY)Entry);
Lookaside->L.ListHead.Depth += 1;
ExReleaseFastMutex(&Lookaside->Lock);
}
return;
}