本文整理汇总了C++中KeWaitForSingleObject函数的典型用法代码示例。如果您正苦于以下问题:C++ KeWaitForSingleObject函数的具体用法?C++ KeWaitForSingleObject怎么用?C++ KeWaitForSingleObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了KeWaitForSingleObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TtdiSend
BOOLEAN
TtdiSend()
{
USHORT i, Iteration, Increment;
HANDLE RdrHandle, RdrConnectionHandle;
KEVENT Event1;
PFILE_OBJECT AddressObject, ConnectionObject;
PDEVICE_OBJECT DeviceObject;
NTSTATUS Status;
PMDL SendMdl, ReceiveMdl;
IO_STATUS_BLOCK Iosb1;
TDI_CONNECTION_INFORMATION RequestInformation;
TDI_CONNECTION_INFORMATION ReturnInformation;
PTRANSPORT_ADDRESS ListenBlock;
PTRANSPORT_ADDRESS ConnectBlock;
PTDI_ADDRESS_NETBIOS temp;
PUCHAR MessageBuffer;
ULONG MessageBufferLength;
ULONG CurrentBufferLength;
PUCHAR SendBuffer;
ULONG SendBufferLength;
PIRP Irp;
Status = KeWaitForSingleObject (&TdiSendEvent, Suspended, KernelMode, FALSE, NULL);
SendBufferLength = (ULONG)BUFFER_SIZE;
MessageBufferLength = (ULONG)BUFFER_SIZE;
DbgPrint( "\n****** Start of Send Test ******\n" );
XBuff = ExAllocatePool (NonPagedPool, BUFFER_SIZE);
if (XBuff == (PVOID)NULL) {
DbgPrint ("Unable to allocate nonpaged pool for send buffer exiting\n");
return FALSE;
}
RBuff = ExAllocatePool (NonPagedPool, BUFFER_SIZE);
if (RBuff == (PVOID)NULL) {
DbgPrint ("Unable to allocate nonpaged pool for receive buffer exiting\n");
return FALSE;
}
ListenBlock = ExAllocatePool (NonPagedPool, sizeof (TRANSPORT_ADDRESS) +
sizeof (TDI_ADDRESS_NETBIOS));
ConnectBlock = ExAllocatePool (NonPagedPool, sizeof (TRANSPORT_ADDRESS) +
sizeof (TDI_ADDRESS_NETBIOS));
ListenBlock->TAAddressCount = 1;
ListenBlock->Address[0].AddressType = TDI_ADDRESS_TYPE_NETBIOS;
ListenBlock->Address[0].AddressLength = sizeof (TDI_ADDRESS_NETBIOS);
temp = (PTDI_ADDRESS_NETBIOS)ListenBlock->Address[0].Address;
temp->NetbiosNameType = TDI_ADDRESS_NETBIOS_TYPE_UNIQUE;
for (i=0;i<16;i++) {
temp->NetbiosName[i] = ClientName[i];
}
ConnectBlock->TAAddressCount = 1;
ConnectBlock->Address[0].AddressType = TDI_ADDRESS_TYPE_NETBIOS;
ConnectBlock->Address[0].AddressLength = sizeof (TDI_ADDRESS_NETBIOS);
temp = (PTDI_ADDRESS_NETBIOS)ConnectBlock->Address[0].Address;
temp->NetbiosNameType = TDI_ADDRESS_NETBIOS_TYPE_UNIQUE;
for (i=0;i<16;i++) {
temp->NetbiosName[i] = ServerName[i];
}
//
// Create an event for the synchronous I/O requests that we'll be issuing.
//
KeInitializeEvent (
&Event1,
SynchronizationEvent,
FALSE);
Status = TtdiOpenAddress (&RdrHandle, AnyName);
if (!NT_SUCCESS(Status)) {
DbgPrint( "\n****** Send Test: FAILED on open of client: %lC ******\n", Status );
return FALSE;
}
Status = ObReferenceObjectByHandle (
RdrHandle,
0L,
NULL,
KernelMode,
(PVOID *) &AddressObject,
NULL);
//
// Open the connection on the transport.
//
Status = TtdiOpenConnection (&RdrConnectionHandle, 1);
if (!NT_SUCCESS(Status)) {
DbgPrint( "\n****** Send Test: FAILED on open of server Connection: %lC ******\n", Status );
return FALSE;
}
//.........这里部分代码省略.........
示例2: FakeNDISReceiveHandler
//.........这里部分代码省略.........
NdisMoveMemory(pBuffer + HeaderBufferSize, pLookaheadBuffer, PacketSize);
// do the filtering work
if (TRUE == RabbitHole(pBuffer, HeaderBufferSize + PacketSize)) {
NdisFreeMemory(pBuffer, 0, 0);
return NDIS_STATUS_NOT_ACCEPTED;
}
NdisFreeMemory(pBuffer, 0, 0);
}
else // Lookahead buffer contains an incomplete packet
{
//
// get the full packet
//
// DbgPrint("Get Full Packet!\r\n");
//if (MacHandle == NULL) {
// DbgPrint("MacHandle == NULL!(0: FakeNDISReceiveHandler)\r\n");
// NdisFreeMemory(pBuffer, 0, 0);
// return NDIS_STATUS_NOT_ACCEPTED;
//}
// make pBuffer a NDIS buffer to hold data
NdisAllocateBuffer(&status, &pNdisBuffer, g_BufferPool, pBuffer + HeaderBufferSize, PacketSize);
if (status != NDIS_STATUS_SUCCESS/* || pNdisBuffer == NULL*/) {
DbgPrint("allocate pNdisBuffer(size = %d) failed in FakeNDISReceiveHandler!\r\n", PacketSize);
NdisFreeMemory(pBuffer, 0, 0);
return NDIS_STATUS_NOT_ACCEPTED;
}
// allocate a NIDS packet to chain buffer in.
NdisAllocatePacket(&status, &pNdisPacket, g_PacketPool);
if (status != NDIS_STATUS_SUCCESS/* || pNdisPacket == NULL*/) {
DbgPrint("allocate pNdisPacket failed in FakeNDISReceiveHandler!\r\n");
NdisFreeBuffer(pNdisBuffer);
NdisFreeMemory(pBuffer, 0, 0);
return NDIS_STATUS_NOT_ACCEPTED;
}
NDIS_SET_PACKET_STATUS(pNdisPacket, STATUS_SUCCESS);
// Bring explosives.
KeInitializeEvent(&evt, NotificationEvent, FALSE);
*(PKEVENT *)(pNdisPacket->ProtocolReserved) = &evt;
NdisChainBufferAtFront(pNdisPacket, pNdisBuffer);
// try to get complete packet
NdisTransferData(&status, pNode->pOpenBlock, MacReceiveContext, 0, PacketSize, pNdisPacket, &ulLen);
if (status == NDIS_STATUS_PENDING) { // wait for the right time
//
// Path 2 of 3, not tested yet! Warning: An Error may occur!
//
DbgPrint("NdisTransferData is pending in FakeNDISReceiveHandler!\r\n", status);
KeWaitForSingleObject(&evt, Executive, KernelMode, FALSE, NULL);
} else if (status != NDIS_STATUS_SUCCESS) {
DbgPrint("NdisTransferData failed(status == 0x%08x) in FakeNDISReceiveHandler!\r\n", status);
NdisFreePacket(pNdisPacket);
NdisFreeBuffer(pNdisBuffer);
NdisFreeMemory(pBuffer, 0, 0);
return NDIS_STATUS_NOT_ACCEPTED;
}
//
// Path 3 of 3, Filtering doesn't seem to work properly.
//
// do the filtering work
if (TRUE == FilterPacket_ReceiveHandler(pBuffer, HeaderBufferSize, pNdisPacket)) {
NdisFreePacket(pNdisPacket);
NdisFreeBuffer(pNdisBuffer);
NdisFreeMemory(pBuffer, 0, 0);
return NDIS_STATUS_NOT_ACCEPTED;
}
NdisFreePacket(pNdisPacket);
NdisFreeBuffer(pNdisBuffer);
NdisFreeMemory(pBuffer, 0, 0);
}
// call the original NDIS routine.
__asm {
pushad;
push PacketSize;
push LookaheadBufferSize;
push pLookaheadBuffer;
push HeaderBufferSize;
push pHeaderBuffer;
push MacReceiveContext;
push ProtocolBindingContext;
mov eax, ulFunAddr;
call eax;
mov status, eax;
popad;
}
return status;
}
示例3: FatPnpRemove
NTSTATUS
FatPnpRemove (
PIRP_CONTEXT IrpContext,
PIRP Irp,
PVCB Vcb
)
/*++
Routine Description:
This routine handles the PnP remove operation. This is our notification
that the underlying storage device for the volume we have is gone, and
an excellent indication that the volume will never reappear. The filesystem
is responsible for initiation or completion of the dismount.
Arguments:
Irp - Supplies the Irp to process
Vcb - Supplies the volume being removed.
Return Value:
NTSTATUS - The return status for the operation
--*/
{
NTSTATUS Status;
KEVENT Event;
BOOLEAN VcbDeleted;
//
// REMOVE - a storage device is now gone. We either got
// QUERY'd and said yes OR got a SURPRISE OR a storage
// stack failed to spin back up from a sleep/stop state
// (the only case in which this will be the first warning).
//
// Note that it is entirely unlikely that we will be around
// for a REMOVE in the first two cases, as we try to intiate
// dismount.
//
//
// Acquire the global resource so that we can try to vaporize
// the volume, and the vcb resource itself.
//
#if __NDAS_FAT_SECONDARY__
if (FlagOn(IrpContext->NdFatFlags, ND_FAT_IRP_CONTEXT_FLAG_SECONDARY_CONTEXT))
FatAcquireExclusiveSecondaryVcb( IrpContext, Vcb );
else
FatAcquireExclusiveVcb( IrpContext, Vcb );
#else
FatAcquireExclusiveVcb( &IrpContext, Vcb );
#endif
//
// The device will be going away. Remove our lock (benign
// if we never had it).
//
(VOID) FatUnlockVolumeInternal( IrpContext, Vcb, NULL );
//
// We need to pass this down before starting the dismount, which
// could disconnect us immediately from the stack.
//
//
// Get the next stack location, and copy over the stack location
//
IoCopyCurrentIrpStackLocationToNext( Irp );
//
// Set up the completion routine
//
KeInitializeEvent( &Event, NotificationEvent, FALSE );
IoSetCompletionRoutine( Irp,
FatPnpCompletionRoutine,
&Event,
TRUE,
TRUE,
TRUE );
//
// Send the request and wait.
//
Status = IoCallDriver(Vcb->TargetDeviceObject, Irp);
if (Status == STATUS_PENDING) {
KeWaitForSingleObject( &Event,
Executive,
KernelMode,
FALSE,
//.........这里部分代码省略.........
示例4: NdFatSecondaryCommonWrite3
//.........这里部分代码省略.........
ndfsWinxpRequestHeader->Write.ForceWrite = TRUE;
DebugTrace2( 0, Dbg, ("ndfsWinxpRequestHeader->Write.ByteOffset = %I64d, ndfsWinxpRequestHeader->Write.Length = %d\n",
ndfsWinxpRequestHeader->Write.ByteOffset, ndfsWinxpRequestHeader->Write.Length) );
ndfsWinxpRequestData = (_U8 *)(ndfsWinxpRequestHeader+1);
if (inputBufferLength) {
try {
RtlCopyMemory( ndfsWinxpRequestData,
inputBuffer + totalWriteLength,
inputBufferLength );
} except (EXCEPTION_EXECUTE_HANDLER) {
DebugTrace2( 0, Dbg2, ("RedirectIrp: Exception - Input buffer is not valid\n") );
status = GetExceptionCode();
break;
}
}
//if (fcb->Header.FileSize.LowPart < 100)
// DbgPrint( "data = %s\n", ndfsWinxpRequestData );
secondaryRequest->RequestType = SECONDARY_REQ_SEND_MESSAGE;
QueueingSecondaryRequest( volDo->Secondary, secondaryRequest );
timeOut.QuadPart = -NDFAT_TIME_OUT;
status = KeWaitForSingleObject( &secondaryRequest->CompleteEvent, Executive, KernelMode, FALSE, &timeOut );
if (status != STATUS_SUCCESS) {
secondaryRequest = NULL;
status = STATUS_IO_DEVICE_ERROR;
leave;
}
KeClearEvent( &secondaryRequest->CompleteEvent );
if (secondaryRequest->ExecuteStatus != STATUS_SUCCESS) {
if (IrpContext->OriginatingIrp)
PrintIrp( Dbg2, "secondaryRequest->ExecuteStatus != STATUS_SUCCESS", NULL, IrpContext->OriginatingIrp );
DebugTrace2( 0, Dbg2, ("secondaryRequest->ExecuteStatus != STATUS_SUCCESS file = %s, line = %d\n", __FILE__, __LINE__) );
if (FlagOn(Irp->Flags, IRP_PAGING_IO)) {
try_return( status = STATUS_FILE_LOCK_CONFLICT );
} else {
FatRaiseStatus( IrpContext, STATUS_CANT_WAIT );
}
}
ndfsWinxpReplytHeader = (PNDFS_WINXP_REPLY_HEADER)secondaryRequest->NdfsReplyData;
if (ndfsWinxpReplytHeader->Status != STATUS_SUCCESS) {
DebugTrace2( 0, Dbg, ("ndfsWinxpReplytHeader->Status = %x\n", ndfsWinxpReplytHeader->Status) );
示例5: NtSecureConnectPort
//.........这里部分代码省略.........
if (NT_SUCCESS(Status))
{
/* Return the handle */
*PortHandle = Handle;
LPCTRACE(LPC_CONNECT_DEBUG,
"Handle: %p. Length: %lx\n",
Handle,
PortMessageLength);
/* Check if maximum length was requested */
if (MaxMessageLength) *MaxMessageLength = PortMessageLength;
/* Check if we had a client view */
if (ClientView)
{
/* Copy it back */
RtlCopyMemory(ClientView,
&ConnectMessage->ClientView,
sizeof(PORT_VIEW));
}
/* Check if we had a server view */
if (ServerView)
{
/* Copy it back */
RtlCopyMemory(ServerView,
&ConnectMessage->ServerView,
sizeof(REMOTE_PORT_VIEW));
}
}
}
else
{
/* No connection port, we failed */
if (SectionToMap) ObDereferenceObject(SectionToMap);
/* Acquire the lock */
KeAcquireGuardedMutex(&LpcpLock);
/* Check if it's because the name got deleted */
if (!(ClientPort->ConnectionPort) ||
(Port->Flags & LPCP_NAME_DELETED))
{
/* Set the correct status */
Status = STATUS_OBJECT_NAME_NOT_FOUND;
}
else
{
/* Otherwise, the caller refused us */
Status = STATUS_PORT_CONNECTION_REFUSED;
}
/* Release the lock */
KeReleaseGuardedMutex(&LpcpLock);
/* Kill the port */
ObDereferenceObject(ClientPort);
}
/* Free the message */
LpcpFreeToPortZone(Message, 0);
}
else
{
/* No reply message, fail */
if (SectionToMap) ObDereferenceObject(SectionToMap);
ObDereferenceObject(ClientPort);
Status = STATUS_PORT_CONNECTION_REFUSED;
}
/* Return status */
ObDereferenceObject(Port);
return Status;
Cleanup:
/* We failed, free the message */
SectionToMap = LpcpFreeConMsg(&Message, &ConnectMessage, Thread);
/* Check if the semaphore got signaled */
if (KeReadStateSemaphore(&Thread->LpcReplySemaphore))
{
/* Wait on it */
KeWaitForSingleObject(&Thread->LpcReplySemaphore,
WrExecutive,
KernelMode,
FALSE,
NULL);
}
/* Check if we had a message and free it */
if (Message) LpcpFreeToPortZone(Message, 0);
/* Dereference other objects */
if (SectionToMap) ObDereferenceObject(SectionToMap);
ObDereferenceObject(ClientPort);
/* Return status */
ObDereferenceObject(Port);
return Status;
}
示例6: TdiSendMessage
NTSTATUS
TdiSendMessage(
ULONG Ip,
USHORT Port,
PCHAR Message,
ULONG Length
)
{
PFILE_OBJECT ConnectionFileObject, AddressFileObject;
HANDLE AddressHandle, ConnectionHandle;
CHAR Buffer[80], Data[] = "Hello from Gary";
NTSTATUS Status;
KEVENT Done;
KeInitializeEvent(&Done, NotificationEvent, FALSE);
Status = TdiCreateConnection(&ConnectionHandle, &ConnectionFileObject);
if (!NT_SUCCESS(Status)) return Status;
Status = TdiCreateAddress(&AddressHandle, &AddressFileObject, SOCK_STREAM, 0, 0);
if (!NT_SUCCESS(Status)) return Status;
do
{
IO_STATUS_BLOCK IoStatus;
KEVENT Event;
Status = TdiSetEventHandler(AddressFileObject, TDI_EVENT_DISCONNECT, TdiEventDisconnect, &Done);
if (!NT_SUCCESS(Status)) break;
Status = TdiSetEventHandler(AddressFileObject, TDI_EVENT_ERROR, TdiEventError, 0);
if (!NT_SUCCESS(Status)) break;
Status = TdiSetEventHandler(AddressFileObject, TDI_EVENT_RECEIVE, TdiEventReceive, 0);
if (!NT_SUCCESS(Status)) break;
Status = TdiBind(ConnectionFileObject, AddressHandle);
if (!NT_SUCCESS(Status)) break;
Status = TdiConnect(ConnectionFileObject, Ip, Port, NULL);
if (!NT_SUCCESS(Status)) break;
Status = TdiSend(ConnectionFileObject, Message, Length);
if (!NT_SUCCESS(Status)) break;
Status = TdiDisconnect(ConnectionFileObject);
if (!NT_SUCCESS(Status)) break;
KeWaitForSingleObject(&Done, UserRequest, KernelMode, FALSE, 0);
} while (0);
ObDereferenceObject(ConnectionFileObject);
ObDereferenceObject(AddressFileObject);
ZwClose(ConnectionHandle);
ZwClose(AddressHandle);
return Status;
}
示例7: XenUsb_Connect
NTSTATUS
XenUsb_Connect(PVOID context, BOOLEAN suspend) {
NTSTATUS status;
PXENUSB_DEVICE_DATA xudd = context;
PFN_NUMBER pfn;
ULONG i;
if (!suspend) {
xudd->handle = XnOpenDevice(xudd->pdo, XenUsb_DeviceCallback, xudd);
}
if (!xudd->handle) {
FUNCTION_MSG("Cannot open Xen device\n");
return STATUS_UNSUCCESSFUL;
}
if (xudd->device_state != DEVICE_STATE_INACTIVE) {
for (i = 0; i <= 5 && xudd->backend_state != XenbusStateInitialising && xudd->backend_state != XenbusStateInitWait && xudd->backend_state != XenbusStateInitialised; i++) {
FUNCTION_MSG("Waiting for XenbusStateInitXxx\n");
if (xudd->backend_state == XenbusStateClosed) {
status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "state", XenbusStateInitialising);
}
KeWaitForSingleObject(&xudd->backend_event, Executive, KernelMode, FALSE, NULL);
}
if (xudd->backend_state != XenbusStateInitialising && xudd->backend_state != XenbusStateInitWait && xudd->backend_state != XenbusStateInitialised) {
FUNCTION_MSG("Backend state timeout\n");
return STATUS_UNSUCCESSFUL;
}
if (!NT_SUCCESS(status = XnBindEvent(xudd->handle, &xudd->event_channel, XenUsb_HandleEvent_DIRQL, xudd))) {
FUNCTION_MSG("Cannot allocate event channel\n");
return STATUS_UNSUCCESSFUL;
}
FUNCTION_MSG("event_channel = %d\n", xudd->event_channel);
status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "event-channel", xudd->event_channel);
xudd->urb_sring = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENUSB_POOL_TAG);
if (!xudd->urb_sring) {
FUNCTION_MSG("Cannot allocate urb_sring\n");
return STATUS_UNSUCCESSFUL;
}
SHARED_RING_INIT(xudd->urb_sring);
FRONT_RING_INIT(&xudd->urb_ring, xudd->urb_sring, PAGE_SIZE);
pfn = (PFN_NUMBER)(MmGetPhysicalAddress(xudd->urb_sring).QuadPart >> PAGE_SHIFT);
FUNCTION_MSG("usb sring pfn = %d\n", (ULONG)pfn);
xudd->urb_sring_gref = XnGrantAccess(xudd->handle, (ULONG)pfn, FALSE, INVALID_GRANT_REF, XENUSB_POOL_TAG);
FUNCTION_MSG("usb sring_gref = %d\n", xudd->urb_sring_gref);
status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "urb-ring-ref", xudd->urb_sring_gref);
xudd->conn_sring = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENUSB_POOL_TAG);
if (!xudd->conn_sring) {
FUNCTION_MSG("Cannot allocate conn_sring\n");
return STATUS_UNSUCCESSFUL;
}
SHARED_RING_INIT(xudd->conn_sring);
FRONT_RING_INIT(&xudd->conn_ring, xudd->conn_sring, PAGE_SIZE);
pfn = (PFN_NUMBER)(MmGetPhysicalAddress(xudd->conn_sring).QuadPart >> PAGE_SHIFT);
FUNCTION_MSG("conn sring pfn = %d\n", (ULONG)pfn);
xudd->conn_sring_gref = XnGrantAccess(xudd->handle, (ULONG)pfn, FALSE, INVALID_GRANT_REF, XENUSB_POOL_TAG);
FUNCTION_MSG("conn sring_gref = %d\n", xudd->conn_sring_gref);
status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "conn-ring-ref", xudd->conn_sring_gref);
/* fill conn ring with requests */
for (i = 0; i < USB_CONN_RING_SIZE; i++) {
usbif_conn_request_t *req = RING_GET_REQUEST(&xudd->conn_ring, i);
req->id = (uint16_t)i;
}
xudd->conn_ring.req_prod_pvt = i;
status = XnWriteInt32(xudd->handle, XN_BASE_FRONTEND, "state", XenbusStateConnected);
for (i = 0; i <= 5 && xudd->backend_state != XenbusStateConnected; i++) {
FUNCTION_MSG("Waiting for XenbusStateConnected\n");
KeWaitForSingleObject(&xudd->backend_event, Executive, KernelMode, FALSE, NULL);
}
if (xudd->backend_state != XenbusStateConnected) {
FUNCTION_MSG("Backend state timeout\n");
return STATUS_UNSUCCESSFUL;
}
xudd->device_state = DEVICE_STATE_ACTIVE;
}
return STATUS_SUCCESS;
}
示例8: Secondary_Close
VOID
Secondary_Close (
IN PSECONDARY Secondary
)
{
NTSTATUS status;
LARGE_INTEGER timeOut;
PLIST_ENTRY secondaryRequestEntry;
PSECONDARY_REQUEST secondaryRequest;
DebugTrace2( 0, Dbg2,
("Secondary close Secondary = %p\n", Secondary) );
ExAcquireFastMutex( &Secondary->FastMutex );
if (FlagOn(Secondary->Flags, SECONDARY_FLAG_CLOSED)) {
//ASSERT( FALSE );
ExReleaseFastMutex( &Secondary->FastMutex );
return;
}
SetFlag( Secondary->Flags, SECONDARY_FLAG_CLOSED );
ExReleaseFastMutex( &Secondary->FastMutex );
if (Secondary->ThreadHandle == NULL) {
Secondary_Dereference( Secondary );
return;
}
ASSERT( Secondary->ThreadObject != NULL );
DebugTrace2( 0, Dbg, ("Secondary close SECONDARY_REQ_DISCONNECT Secondary = %p\n", Secondary) );
secondaryRequest = AllocSecondaryRequest( Secondary, 0, FALSE );
secondaryRequest->RequestType = SECONDARY_REQ_DISCONNECT;
QueueingSecondaryRequest( Secondary, secondaryRequest );
secondaryRequest = AllocSecondaryRequest( Secondary, 0, FALSE );
secondaryRequest->RequestType = SECONDARY_REQ_DOWN;
QueueingSecondaryRequest( Secondary, secondaryRequest );
DebugTrace2( 0, Dbg, ("Secondary close SECONDARY_REQ_DISCONNECT end Secondary = %p\n", Secondary) );
timeOut.QuadPart = -NDASFAT_TIME_OUT;
status = KeWaitForSingleObject( Secondary->ThreadObject,
Executive,
KernelMode,
FALSE,
&timeOut );
if (status == STATUS_SUCCESS) {
DebugTrace2( 0, Dbg, ("Secondary_Close: thread stoped Secondary = %p\n", Secondary));
ObDereferenceObject( Secondary->ThreadObject );
Secondary->ThreadHandle = NULL;
Secondary->ThreadObject = NULL;
} else {
ASSERT( NDASFAT_BUG );
return;
}
ASSERT( Secondary->VolDo->Vcb.SecondaryOpenFileCount == 0 );
ASSERT( IsListEmpty(&Secondary->FcbQueue) );
ASSERT( IsListEmpty(&Secondary->RecoveryCcbQueue) );
ASSERT( IsListEmpty(&Secondary->RequestQueue) );
while (secondaryRequestEntry = ExInterlockedRemoveHeadList(&Secondary->RequestQueue,
&Secondary->RequestQSpinLock)) {
PSECONDARY_REQUEST secondaryRequest2;
InitializeListHead( secondaryRequestEntry );
secondaryRequest2 = CONTAINING_RECORD( secondaryRequestEntry,
SECONDARY_REQUEST,
ListEntry );
secondaryRequest2->ExecuteStatus = STATUS_IO_DEVICE_ERROR;
if (secondaryRequest2->Synchronous == TRUE)
KeSetEvent( &secondaryRequest2->CompleteEvent, IO_DISK_INCREMENT, FALSE );
else
DereferenceSecondaryRequest( secondaryRequest2 );
}
Secondary_Dereference( Secondary );
//.........这里部分代码省略.........
示例9: AFSDumpTraceFiles
void
AFSDumpTraceFiles()
{
NTSTATUS ntStatus = STATUS_SUCCESS;
HANDLE hDirectory = NULL;
OBJECT_ATTRIBUTES stObjectAttribs;
IO_STATUS_BLOCK stIoStatus;
LARGE_INTEGER liTime, liLocalTime;
TIME_FIELDS timeFields;
ULONG ulBytesWritten = 0;
HANDLE hDumpFile = NULL;
ULONG ulBytesProcessed, ulCopyLength;
LARGE_INTEGER liOffset;
ULONG ulDumpLength = 0;
BOOLEAN bSetEvent = FALSE;
__Enter
{
AFSAcquireShared( &AFSDbgLogLock,
TRUE);
ulDumpLength = AFSDbgBufferLength - AFSDbgLogRemainingLength;
AFSReleaseResource( &AFSDbgLogLock);
if( AFSDumpFileLocation.Length == 0 ||
AFSDumpFileLocation.Buffer == NULL ||
AFSDbgBufferLength == 0 ||
ulDumpLength == 0 ||
AFSDumpFileName.MaximumLength == 0 ||
AFSDumpFileName.Buffer == NULL ||
AFSDumpBuffer == NULL)
{
try_return( ntStatus);
}
//
// Go open the cache file
//
InitializeObjectAttributes( &stObjectAttribs,
&AFSDumpFileLocation,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
NULL,
NULL);
ntStatus = ZwCreateFile( &hDirectory,
GENERIC_READ | GENERIC_WRITE,
&stObjectAttribs,
&stIoStatus,
NULL,
0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);
if( !NT_SUCCESS( ntStatus))
{
try_return( ntStatus);
}
ntStatus = KeWaitForSingleObject( &AFSDumpFileEvent,
Executive,
KernelMode,
FALSE,
NULL);
if( !NT_SUCCESS( ntStatus))
{
try_return( ntStatus);
}
bSetEvent = TRUE;
AFSDumpFileName.Length = 0;
RtlZeroMemory( AFSDumpFileName.Buffer,
AFSDumpFileName.MaximumLength);
KeQuerySystemTime( &liTime);
ExSystemTimeToLocalTime( &liTime,
&liLocalTime);
RtlTimeToTimeFields( &liLocalTime,
&timeFields);
ntStatus = RtlStringCchPrintfW( AFSDumpFileName.Buffer,
AFSDumpFileName.MaximumLength/sizeof( WCHAR),
L"AFSDumpFile %d.%d.%d %d.%d.%d.log",
timeFields.Month,
timeFields.Day,
timeFields.Year,
timeFields.Hour,
//.........这里部分代码省略.........
示例10: KbFilter_PnP
//.........这里部分代码省略.........
#line 182
errorFn();
}
} else {
#line 185
if (compRegistered != 0) {
{
#line 187
errorFn();
}
} else {
#line 190
compRegistered = 1;
}
}
{
#line 194
irpSp___0 = Irp__Tail__Overlay__CurrentStackLocation - 1;
#line 195
irpSp__Context = event;
#line 196
irpSp__Control = 224;
#line 200
status = IofCallDriver(devExt__TopOfStack,
Irp);
}
{
#line 203
__cil_tmp23 = (long )status;
#line 203
if (__cil_tmp23 == 259) {
{
#line 205
KeWaitForSingleObject(event, Executive,
KernelMode,
0, 0);
}
}
}
#line 212
if (status >= 0) {
#line 213
if (myStatus >= 0) {
#line 214
devExt__Started = 1;
#line 215
devExt__Removed = 0;
#line 216
devExt__SurpriseRemoved = 0;
}
}
{
#line 224
Irp__IoStatus__Status = status;
#line 225
myStatus = status;
#line 226
Irp__IoStatus__Information = 0;
#line 227
IofCompleteRequest(Irp, 0);
}
goto switch_0_break;
switch_0_23:
#line 231
devExt__SurpriseRemoved = 1;
#line 232
示例11: 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;
}
示例12: LspPollingThread
VOID
LspPollingThread(
IN PVOID Context
)
/*++
Routine Description:
This is the main thread that removes IRP from the queue
and peforms I/O on it.
Arguments:
Context -- pointer to the device object
--*/
{
PDEVICE_OBJECT DeviceObject = Context;
PDEVICE_EXTENSION DevExtension = DeviceObject->DeviceExtension;
PIRP Irp;
NTSTATUS Status;
KeSetPriorityThread(KeGetCurrentThread(), LOW_REALTIME_PRIORITY );
//
// Now enter the main IRP-processing loop
//
while( TRUE )
{
//
// Wait indefinitely for an IRP to appear in the work queue or for
// the Unload routine to stop the thread. Every successful return
// from the wait decrements the semaphore count by 1.
//
KeWaitForSingleObject(
&DevExtension->IrpQueueSemaphore,
Executive,
KernelMode,
FALSE,
NULL );
//
// See if thread was awakened because driver is unloading itself...
//
if( DevExtension->ThreadShouldStop )
{
PsTerminateSystemThread( STATUS_SUCCESS );
}
//
// Remove a pending IRP from the queue.
//
Irp = IoCsqRemoveNextIrp(&DevExtension->CancelSafeQueue, NULL);
if(!Irp)
{
LSP_KDPRINT(("Oops, a queued irp got cancelled\n"));
continue; // go back to waiting
}
while(TRUE)
{
//
// Perform I/O
//
Status = LspPollDevice(DeviceObject, Irp);
if(Status == STATUS_PENDING)
{
//
// Device is not ready, so sleep for a while and try again.
//
KeDelayExecutionThread(
KernelMode,
FALSE,
&DevExtension->PollingInterval);
}
else
{
//
// I/O is successful, so complete the Irp.
//
Irp->IoStatus.Status = Status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
break;
}
}
//
// Go back to the top of the loop to see if there's another request waiting.
//
} // end of while-loop
}
示例13: LspUnload
VOID
LspUnload(
IN PDRIVER_OBJECT DriverObject
)
/*++
Routine Description:
Free all the allocated resources, etc.
Arguments:
DriverObject - pointer to a driver object.
Return Value:
VOID
--*/
{
NTSTATUS status;
PDEVICE_OBJECT deviceObject = DriverObject->DeviceObject;
UNICODE_STRING uniWin32NameString;
PDEVICE_EXTENSION deviceExtension = deviceObject->DeviceExtension;
PAGED_CODE();
LSP_KDPRINT(("LspUnload Enter\n"));
//
// Set the Stop flag
//
deviceExtension->ThreadShouldStop = TRUE;
//
// Make sure the thread wakes up
//
KeReleaseSemaphore(&deviceExtension->IrpQueueSemaphore,
0, // No priority boost
1, // Increment semaphore by 1
TRUE );// WaitForXxx after this call
//
// Wait for the thread to terminate
//
KeWaitForSingleObject(deviceExtension->ThreadObject,
Executive,
KernelMode,
FALSE,
NULL );
ObDereferenceObject(deviceExtension->ThreadObject);
IoFreeWorkItem(deviceExtension->CloseWorkItem);
//
// Create counted string version of our Win32 device name.
//
RtlInitUnicodeString( &uniWin32NameString, LSP_DOS_DEVICE_NAME_U );
IoDeleteSymbolicLink( &uniWin32NameString );
ASSERT(!deviceObject->AttachedDevice);
IoDeleteDevice( deviceObject );
LSP_KDPRINT(("LspUnload Exit\n"));
return;
}
示例14: TtdiReceive
BOOLEAN
TtdiReceive()
{
USHORT i, Iteration, Increment;
SHORT j,k;
HANDLE SvrHandle, SvrConnectionHandle;
PFILE_OBJECT AddressObject, ConnectionObject;
PDEVICE_OBJECT DeviceObject;
NTSTATUS Status;
PMDL SendMdl, ReceiveMdl;
IO_STATUS_BLOCK Iosb1;
TDI_CONNECTION_INFORMATION RequestInformation;
TDI_CONNECTION_INFORMATION ReturnInformation;
PTRANSPORT_ADDRESS ListenBlock;
PTRANSPORT_ADDRESS ConnectBlock;
PTDI_ADDRESS_NETBIOS temp;
PUCHAR MessageBuffer;
ULONG MessageBufferLength;
ULONG CurrentBufferLength;
PUCHAR SendBuffer;
ULONG SendBufferLength;
PIRP Irp;
KEVENT Event1;
Status = KeWaitForSingleObject (&TdiReceiveEvent, Suspended, KernelMode, FALSE, NULL);
SendBufferLength = (ULONG)BUFFER_SIZE;
MessageBufferLength = (ULONG)BUFFER_SIZE;
DbgPrint( "\n****** Start of Receive Test ******\n" );
XBuff = ExAllocatePool (NonPagedPool, BUFFER_SIZE);
if (XBuff == (PVOID)NULL) {
DbgPrint ("Unable to allocate nonpaged pool for send buffer exiting\n");
return FALSE;
}
RBuff = ExAllocatePool (NonPagedPool, BUFFER_SIZE);
if (RBuff == (PVOID)NULL) {
DbgPrint ("Unable to allocate nonpaged pool for receive buffer exiting\n");
return FALSE;
}
ListenBlock = ExAllocatePool (NonPagedPool, sizeof (TRANSPORT_ADDRESS) +
sizeof (TDI_ADDRESS_NETBIOS));
ConnectBlock = ExAllocatePool (NonPagedPool, sizeof (TRANSPORT_ADDRESS) +
sizeof (TDI_ADDRESS_NETBIOS));
ListenBlock->TAAddressCount = 1;
ListenBlock->Address[0].AddressType = TDI_ADDRESS_TYPE_NETBIOS;
ListenBlock->Address[0].AddressLength = sizeof (TDI_ADDRESS_NETBIOS);
temp = (PTDI_ADDRESS_NETBIOS)ListenBlock->Address[0].Address;
temp->NetbiosNameType = TDI_ADDRESS_NETBIOS_TYPE_UNIQUE;
for (i=0;i<16;i++) {
temp->NetbiosName[i] = ClientName[i];
}
ConnectBlock->TAAddressCount = 1;
ConnectBlock->Address[0].AddressType = TDI_ADDRESS_TYPE_NETBIOS;
ConnectBlock->Address[0].AddressLength = sizeof (TDI_ADDRESS_NETBIOS);
temp = (PTDI_ADDRESS_NETBIOS)ConnectBlock->Address[0].Address;
temp->NetbiosNameType = TDI_ADDRESS_NETBIOS_TYPE_UNIQUE;
for (i=0;i<16;i++) {
temp->NetbiosName[i] = ServerName[i];
}
//
// Create an event for the synchronous I/O requests that we'll be issuing.
//
KeInitializeEvent (
&Event1,
SynchronizationEvent,
FALSE);
Status = TtdiOpenAddress (&SvrHandle, ServerName);
if (!NT_SUCCESS(Status)) {
DbgPrint( "\n****** Receive Test: FAILED on open of server Address: %lC ******\n", Status );
return FALSE;
}
Status = ObReferenceObjectByHandle (
SvrHandle,
0L,
NULL,
KernelMode,
(PVOID *) &AddressObject,
NULL);
if (!NT_SUCCESS(Status)) {
DbgPrint( "\n****** Receive Test: FAILED on open of server Address: %lC ******\n", Status );
return FALSE;
}
Status = TtdiOpenConnection (&SvrConnectionHandle, 2);
if (!NT_SUCCESS(Status)) {
DbgPrint( "\n****** Receive Test: FAILED on open of server Connection: %lC ******\n", Status );
return FALSE;
//.........这里部分代码省略.........
示例15: PspExitThread
//.........这里部分代码省略.........
if (CurrentProcess->ExitStatus == STATUS_PENDING)
{
/* Use the last exit status */
CurrentProcess->ExitStatus = CurrentProcess->
LastThreadExitStatus;
}
}
else
{
/* Just a normal exit, write the code */
CurrentProcess->ExitStatus = ExitStatus;
}
/* Loop all the current threads */
FirstEntry = &CurrentProcess->ThreadListHead;
CurrentEntry = FirstEntry->Flink;
while (FirstEntry != CurrentEntry)
{
/* Get the thread on the list */
OtherThread = CONTAINING_RECORD(CurrentEntry,
ETHREAD,
ThreadListEntry);
/* Check if it's a thread that's still alive */
if ((OtherThread != Thread) &&
!(KeReadStateThread(&OtherThread->Tcb)) &&
(ObReferenceObjectSafe(OtherThread)))
{
/* It's a live thread and we referenced it, unlock process */
ExReleasePushLockExclusive(&CurrentProcess->ProcessLock);
KeLeaveCriticalRegion();
/* Wait on the thread */
KeWaitForSingleObject(OtherThread,
Executive,
KernelMode,
FALSE,
NULL);
/* Check if we had a previous thread to dereference */
if (PreviousThread) ObDereferenceObject(PreviousThread);
/* Remember the thread and re-lock the process */
PreviousThread = OtherThread;
KeEnterCriticalRegion();
ExAcquirePushLockExclusive(&CurrentProcess->ProcessLock);
}
/* Go to the next thread */
CurrentEntry = CurrentEntry->Flink;
}
}
else if (ExitStatus != STATUS_THREAD_IS_TERMINATING)
{
/* Write down the exit status of the last thread to get killed */
CurrentProcess->LastThreadExitStatus = ExitStatus;
}
/* Unlock the Process */
ExReleasePushLockExclusive(&CurrentProcess->ProcessLock);
KeLeaveCriticalRegion();
/* Check if we had a previous thread to dereference */
if (PreviousThread) ObDereferenceObject(PreviousThread);
/* Check if the process has a debug port and if this is a user thread */