Example #1
0
BOOLEAN ChewCreate(VOID (*Worker)(PVOID), PVOID WorkerContext)
{
    PWORK_ITEM Item;
    Item = ExAllocatePoolWithTag(NonPagedPool, 
                                 sizeof(WORK_ITEM),
                                 CHEW_TAG);

    if (Item)
    {
        Item->WorkItem = IoAllocateWorkItem(WorkQueueDevice);
        if (!Item->WorkItem)
        {
            ExFreePool(Item);
            return FALSE;
        }

        Item->Worker = Worker;
        Item->WorkerContext = WorkerContext;
        ExInterlockedInsertTailList(&WorkQueue, &Item->Entry, &WorkQueueLock);
        KeResetEvent(&WorkQueueClear);
        IoQueueWorkItem(Item->WorkItem, ChewWorkItem, DelayedWorkQueue, Item);

        return TRUE;
    }
    else
    {
        return FALSE;
    }
}
Example #2
0
VOID PushEvent(IN PEVENTDATA pEvtData)
/*++

Routine Description:

	“违规事件”压栈


Arguments:

	pEvtData - 指定“违规事件”


Return Value:

	None.

Author:

	Fypher

--*/
{

	PAGED_CODE();

	ExInterlockedInsertTailList(&g_EventDataLinkListHead, &pEvtData->ListEntry, &g_EventDataLock);
	InterlockedIncrement(&g_ulEventDataCount);

	KeReleaseSemaphore(&g_EventDataSemaphore, 0, 1, FALSE);
}
Example #3
0
/*
 * @implemented
 */
VOID
EXPORT
NdisCompleteBindAdapter(
    IN  NDIS_HANDLE BindAdapterContext,
    IN  NDIS_STATUS Status,
    IN  NDIS_STATUS OpenStatus)
/*
 * FUNCTION: Indicates a packet to bound protocols
 * ARGUMENTS:
 *     Adapter = Pointer to logical adapter
 *     Packet  = Pointer to packet to indicate
 * RETURNS:
 *     Status of operation
 * NOTES:
 *     - FIXME: partially-implemented
 */
{
  PROTOCOL_BINDING *Protocol = (PROTOCOL_BINDING *)BindAdapterContext;

  if (!NT_SUCCESS(Status)) {
      NDIS_DbgPrint(MIN_TRACE, ("Binding failed (%x)\n", Status));
      return;
  }

  /* Put protocol binding struct on global list */
  ExInterlockedInsertTailList(&ProtocolListHead, &Protocol->ListEntry, &ProtocolListLock);
}
Example #4
0
void TestList()
{
	LIST_ENTRY tHead;
	InitializeListHead(&tHead);

	MyListNode* pData;
	ULONG i=0;

	KSPIN_LOCK tLock;
	KeInitializeSpinLock(&tLock);

	KdPrint(("begin insert data to list \n"));
	for(i=0; i<10; i++)
	{
		KdPrint(("insert one %d\n",i));
		pData = (MyListNode*)ExAllocatePool(PagedPool,sizeof(MyListNode));
		pData->data = i;
		ExInterlockedInsertTailList(&tHead,&pData->ListEntry,&tLock);
	}

	KdPrint(("begin remove from link and print"));
	while(!IsListEmpty(&tHead))
	{
		MyListNode* pCurNode = (MyListNode*)ExInterlockedRemoveHeadList(&tHead,&tLock);
		KdPrint(("%d  ",pCurNode->data));
		ExFreePool(pCurNode);
	}
}
Example #5
0
VOID __stdcall Filter(ULONG ServiceId, ULONG TableBase, ULONG Argc, ULONG StackAddr) {
	ULONG pid = (ULONG)PsGetCurrentProcessId();
	if (pid == g_nPid) {
		ULONG i;
		PXBoxData pData=(PXBoxData)ExAllocateFromNPagedLookasideList(&g_nPageList);
		if(!pData)
			return;
		
		if (StackAddr < MmUserProbeAddress)
			pData->bFromUser = 1;
		else
			pData->bFromUser = 0;
		
		if (TableBase == (ULONG)KeServiceDescriptorTable.ServiceTableBase)
			pData->bFromSSDT = 1;
		else
			pData->bFromSSDT = 0;

		if (Argc > 16)
			Argc = 16;
		pData->argc = (UCHAR)Argc;
		for (i = 0; i < Argc; ++i)
			pData->args[i] = ((PULONG)StackAddr)[i];

		pData->pid = (ULONG)pid;
		pData->tid = (ULONG)PsGetCurrentThreadId();
		pData->sid = ServiceId;
		KeQuerySystemTime(&pData->time);
		ExInterlockedInsertTailList(&g_linkListHead, &pData->ListEntry, &g_lock);
		KeReleaseSemaphore( &g_keySemaphore, 0, 1, FALSE );
	}
}
Example #6
0
NTSTATUS EncryptedIoQueueAddIrp (EncryptedIoQueue *queue, PIRP irp)
{
	NTSTATUS status;

	InterlockedIncrement (&queue->OutstandingIoCount);
	if (queue->StopPending)
	{
		Dump ("STATUS_DEVICE_NOT_READY  out=%d\n", queue->OutstandingIoCount);
		status = STATUS_DEVICE_NOT_READY;
		goto err;
	}

	status = IoAcquireRemoveLock (&queue->RemoveLock, irp);
	if (!NT_SUCCESS (status))
		goto err;

#ifdef TC_TRACE_IO_QUEUE
	{
		PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation (irp);
		Dump ("* %I64d [%I64d] %c len=%d out=%d\n", irpSp->MajorFunction == IRP_MJ_WRITE ? irpSp->Parameters.Write.ByteOffset : irpSp->Parameters.Read.ByteOffset, GetElapsedTime (&queue->LastPerformanceCounter), irpSp->MajorFunction == IRP_MJ_WRITE ? 'W' : 'R', irpSp->MajorFunction == IRP_MJ_WRITE ? irpSp->Parameters.Write.Length : irpSp->Parameters.Read.Length, queue->OutstandingIoCount);
	}
#endif

	IoMarkIrpPending (irp);

	ExInterlockedInsertTailList (&queue->MainThreadQueue, &irp->Tail.Overlay.ListEntry, &queue->MainThreadQueueLock);
	KeSetEvent (&queue->MainThreadQueueNotEmptyEvent, IO_DISK_INCREMENT, FALSE);
	
	return STATUS_PENDING;

err:
	DecrementOutstandingIoCount (queue);
	return status;
}
Example #7
0
PDRAID_LISTEN_CONTEXT 
DraidCreateListenContext(
	PDRAID_GLOBALS DraidGlobals,
	PLPX_ADDRESS Addr
) {
	KIRQL	oldIrql;
	BOOLEAN AlreadyExist;
	PLIST_ENTRY listEntry;
	PDRAID_LISTEN_CONTEXT ListenContext;
		
	//
	// Check address is already in the listen context list
	//
	ACQUIRE_SPIN_LOCK(&DraidGlobals->ListenContextSpinlock, &oldIrql);
	AlreadyExist = FALSE;
	for (listEntry = DraidGlobals->ListenContextList.Flink;
		listEntry != &DraidGlobals->ListenContextList;
		listEntry = listEntry->Flink) 
	{
		ListenContext = CONTAINING_RECORD (listEntry, DRAID_LISTEN_CONTEXT, Link);
		if (!ListenContext->Destroy && RtlCompareMemory(ListenContext->Addr.Node, 
			Addr->Node, 6) == 6) {
			KDPrintM(DBG_LURN_INFO, ("New LPX address already exist.Ignoring.\n"));
			AlreadyExist = TRUE;
			break;
		}
	}
	RELEASE_SPIN_LOCK(&DraidGlobals->ListenContextSpinlock, oldIrql);
	if (AlreadyExist) {
		return NULL;
	}

	//
	// Alloc listen context
	//
	ListenContext = ExAllocatePoolWithTag(NonPagedPool, sizeof(DRAID_LISTEN_CONTEXT), 
		DRAID_LISTEN_CONTEXT_POOL_TAG);
	if (!ListenContext) {
		KDPrintM(DBG_LURN_INFO, ("Failed to alloc listen context\n"));
		return NULL;
	}
	RtlZeroMemory(ListenContext, sizeof(DRAID_LISTEN_CONTEXT));
	
	KeInitializeEvent(
			&ListenContext->TdiListenContext.CompletionEvent, 
			NotificationEvent, 
			FALSE
			);
	InitializeListHead(&ListenContext->Link);

	RtlCopyMemory(ListenContext->Addr.Node, Addr->Node, 6);
	ListenContext->Addr.Port = HTONS(DRIX_ARBITER_PORT_NUM_BASE);

	ExInterlockedInsertTailList(&DraidGlobals->ListenContextList, 
		&ListenContext->Link, 
		&DraidGlobals->ListenContextSpinlock
	);
	return ListenContext;
}
Example #8
0
NTSTATUS
DraidRegisterClient(
	PDRAID_CLIENT_INFO Client
) {
	ASSERT(g_DraidGlobals);
	ExInterlockedInsertTailList(&g_DraidGlobals->ClientList, &Client->AllClientList, &g_DraidGlobals->ClientListSpinlock);
	return STATUS_SUCCESS;
}
Example #9
0
NTSTATUS 
DraidRegisterArbiter(
	PDRAID_ARBITER_INFO Arbiter
) {
	ASSERT(g_DraidGlobals);
	ExInterlockedInsertTailList(&g_DraidGlobals->ArbiterList, &Arbiter->AllArbiterList, &g_DraidGlobals->ArbiterListSpinlock);
	return STATUS_SUCCESS;
}
void RosKmAdapter::DoWork(void)
{
    bool done = false;

    while (!done)
    {
        NTSTATUS status = KeWaitForSingleObject(
            &m_workerThreadEvent,
            Executive,
            KernelMode,
            FALSE,
            NULL);

        status;
        NT_ASSERT(status == STATUS_SUCCESS);

        if (m_workerExit)
        {
            done = true;
            continue;
        }

        for (;;)
        {
            ROSDMABUFSUBMISSION *   pDmaBufSubmission = DequeueDmaBuffer(&m_dmaBufQueueLock);
            if (pDmaBufSubmission == NULL)
            {
                break;
            }

            ROSDMABUFINFO * pDmaBufInfo = pDmaBufSubmission->m_pDmaBufInfo;

            if (pDmaBufInfo->m_DmaBufState.m_bPaging)
            {
                //
                // Run paging buffer in software
                //

                ProcessPagingBuffer(pDmaBufSubmission);

                NotifyDmaBufCompletion(pDmaBufSubmission);
            }
            else
            {
                //
                // Process render DMA buffer
                //

                ProcessRenderBuffer(pDmaBufSubmission);

                NotifyDmaBufCompletion(pDmaBufSubmission);
            }

            ExInterlockedInsertTailList(&m_dmaBufSubmissionFree, &pDmaBufSubmission->m_QueueEntry, &m_dmaBufQueueLock);
        }
    }
}
Example #11
0
void LibTCPEnqueuePacket(PCONNECTION_ENDPOINT Connection, struct pbuf *p)
{
    PQUEUE_ENTRY qp;

    qp = (PQUEUE_ENTRY)ExAllocateFromNPagedLookasideList(&QueueEntryLookasideList);
    qp->p = p;
    qp->Offset = 0;

    ExInterlockedInsertTailList(&Connection->PacketQueue, &qp->ListEntry, &Connection->Lock);
}
Example #12
0
NTSTATUS FileWrite(__in BASE_FILE * File, __in PIRP Irp,
		   __in PIO_STACK_LOCATION IrpStack)
{
	BASE_DEVICE *Device = BaseFileGetDevice(File);
	DEVICE_DATA *DeviceData = (DEVICE_DATA *) BaseDeviceGetPrivate(Device);
	ULONG Length = IrpStack->Parameters.Write.Length;
	PVOID Buffer;
	BUFFER_DATA *BufferData;
	size_t Size;
	NTSTATUS Status = STATUS_SUCCESS;

	PAGED_CODE();

	__try {
		ASSERT(Irp->MdlAddress);
		if (Irp->MdlAddress == NULL) {
			TRACE_MSG(TRACE_LEVEL_ERROR, TRACE_FLAG_DEFAULT,
				  "Null MDL pointer\n");
			Status = STATUS_INVALID_PARAMETER;
			__leave;
		}
		Buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
						      NormalPagePriority);
		if (Buffer == NULL) {
			Status = STATUS_INSUFFICIENT_RESOURCES;
			TRACE_ERR("MmGetSystemAddressForMdlSafe", Status);
			__leave;
		}
		Size = FIELD_OFFSET(BUFFER_DATA, Data) + Length;
		BufferData =
		    (BUFFER_DATA *) ExAllocatePoolWithTag(NonPagedPool, Size,
							  SAMPLE_POOL_TAG);
		if (BufferData == NULL) {
			Status = STATUS_INSUFFICIENT_RESOURCES;
			TRACE_ERR("ExAllocatePoolWithTag", Status);
			__leave;
		}
		TRACE_MSG(TRACE_LEVEL_INFO, TRACE_FLAG_DEFAULT,
			  "Write %u bytes\n",
			  IrpStack->Parameters.Write.Length);
		RtlCopyMemory(BufferData->Data, Buffer, Length);
		BufferData->Length = Length;
		ExInterlockedInsertTailList(&DeviceData->BufferList,
					    &BufferData->ListEntry,
					    &DeviceData->BufferListLock);
		Irp->IoStatus.Information = Length;
	}
	__finally {
		BaseFileCompleteRequest(File, Irp, Status);
	}
	return Status;
}
Example #13
0
NTSTATUS PacketRead( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp )
{
	POPEN_INSTANCE      open;
	PNDIS_PACKET        pPacket;
	NDIS_STATUS         status;
	NTSTATUS            ntStatus;
	PIO_STACK_LOCATION  irpSp;

	// DebugPrint(("Read\n"));

	open = DeviceObject->DeviceExtension;

	IoIncrement(open);

	if(!open->Bound) {
		ntStatus = STATUS_DEVICE_NOT_READY;
		goto ERROR;
	}

	irpSp = IoGetCurrentIrpStackLocation(Irp);

	if (irpSp->Parameters.Read.Length < ETHERNET_HEADER_LENGTH) {
		ntStatus = STATUS_BUFFER_TOO_SMALL;
		goto ERROR;
	}

	NdisAllocatePacket( &status, &pPacket, open->PacketPool );
	if (status != NDIS_STATUS_SUCCESS) {
		// DebugPrint(("Packet: Read- No free packets\n"));
		ntStatus = STATUS_INSUFFICIENT_RESOURCES;
		goto ERROR;
	}

	RESERVED(pPacket)->Irp=Irp;
	RESERVED(pPacket)->pMdl=NULL;
	IoMarkIrpPending(Irp);

	IoSetCancelRoutine(Irp, PacketCancelRoutine);

	ExInterlockedInsertTailList(
			&open->RcvList,
			&RESERVED(pPacket)->ListElement,
			&open->RcvQSpinLock);

	return STATUS_PENDING;

ERROR:
	Irp->IoStatus.Status = ntStatus;
	IoCompleteRequest (Irp, IO_NO_INCREMENT);
	IoDecrement(open);
	return ntStatus;
}
Example #14
0
NTSTATUS
CompletionIrpCompletionRoutine(
		IN PDEVICE_OBJECT		DeviceObject,
		IN PIRP					Irp,
		IN PCOMPLETION_DATA		Context
	)
{
    PMINIPORT_DEVICE_EXTENSION	HwDeviceExtension = Context->HwDeviceExtension;

	PSCSI_REQUEST_BLOCK			completionSrb = Context->CompletionSrb;
	PCCB						shippedCcb = Context->ShippedCcb;


	KDPrint(4, ("Entered\n"));
	UNREFERENCED_PARAMETER(DeviceObject);

	if(completionSrb->DataBuffer) 
	{
		KDPrint(2, ("Unexpected IRP completion!!! "
			"Maybe completion SRB did not reach NDASSCSI's StartIo routine.\n"));
		ASSERT(completionSrb->DataBuffer);

		InterlockedDecrement(&HwDeviceExtension->RequestExecuting);
		LsuDecrementTdiClientInProgress();

		InitializeListHead(&shippedCcb->ListEntry);
		LsCcbSetStatusFlag(shippedCcb, CCBSTATUS_FLAG_TIMER_COMPLETE);
		ExInterlockedInsertTailList(
				&HwDeviceExtension->CcbTimerCompletionList,
				&shippedCcb->ListEntry,
				&HwDeviceExtension->CcbTimerCompletionListSpinLock
				);

		completionSrb->DataBuffer = NULL;
	} else {
		//
		//	Free the CCB if it is not going to the timer completion routine
		//	and allocated from the system pool by NDASSCSI.
		//
		if(Context->ShippedCcbAllocatedFromPool)
			LsCcbPostCompleteCcb(shippedCcb);
	}

	// Free resources
	ExFreePoolWithTag(completionSrb, NDSC_PTAG_SRB);
	ExFreePoolWithTag(Context, NDSC_PTAG_CMPDATA);
	IoFreeIrp(Irp);

	return STATUS_MORE_PROCESSING_REQUIRED;
}
Example #15
0
NTSTATUS
FileDiskReadWrite (
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp
    )
{
    PDEVICE_EXTENSION   device_extension;
    PIO_STACK_LOCATION  io_stack;
//得到扩展设备
    device_extension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
//判断是否有物理设备。没有打开文件,就返回失败
    if (!device_extension->media_in_device)
    {
        Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
        Irp->IoStatus.Information = 0;

        IoCompleteRequest(Irp, IO_NO_INCREMENT);

        return STATUS_NO_MEDIA_IN_DEVICE;
    }

    io_stack = IoGetCurrentIrpStackLocation(Irp);
//  读0长的时候立刻成功
    if (io_stack->Parameters.Read.Length == 0)
    {
        Irp->IoStatus.Status = STATUS_SUCCESS;
        Irp->IoStatus.Information = 0;

        IoCompleteRequest(Irp, IO_NO_INCREMENT);

        return STATUS_SUCCESS;
    }
//放入队列里面去
    IoMarkIrpPending(Irp);
 // 把请求写入链表
    ExInterlockedInsertTailList(
        &device_extension->list_head,
        &Irp->Tail.Overlay.ListEntry,
        &device_extension->list_lock
        );
// 设置事件。让线程循环运行。
    KeSetEvent(
        &device_extension->request_event,
        (KPRIORITY) 0,
        FALSE
        );

    return STATUS_PENDING;
}
Example #16
0
NTSTATUS TCPReceiveData
( PCONNECTION_ENDPOINT Connection,
  PNDIS_BUFFER Buffer,
  ULONG ReceiveLength,
  PULONG BytesReceived,
  ULONG ReceiveFlags,
  PTCP_COMPLETION_ROUTINE Complete,
  PVOID Context )
{
    PTDI_BUCKET Bucket;
    PUCHAR DataBuffer;
    UINT DataLen, Received;
    NTSTATUS Status;

    TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Called for %d bytes (on socket %x)\n",
                           ReceiveLength, Connection->SocketContext));

    NdisQueryBuffer(Buffer, &DataBuffer, &DataLen);

    Status = LibTCPGetDataFromConnectionQueue(Connection, DataBuffer, DataLen, &Received);

    if (Status == STATUS_PENDING)
    {
        Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
        if (!Bucket)
        {
            TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Failed to allocate bucket\n"));

            return STATUS_NO_MEMORY;
        }
    
        Bucket->Request.RequestNotifyObject = Complete;
        Bucket->Request.RequestContext = Context;

        ExInterlockedInsertTailList( &Connection->ReceiveRequest, &Bucket->Entry, &Connection->Lock );
        TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Queued read irp\n"));

        TI_DbgPrint(DEBUG_TCP,("[IP, TCPReceiveData] Leaving. Status = STATUS_PENDING\n"));

        (*BytesReceived) = 0;
    }
    else
    {
        (*BytesReceived) = Received;
    }

    return Status;
}
Example #17
0
void
sys_mbox_post(sys_mbox_t *mbox, void *msg)
{
    PLWIP_MESSAGE_CONTAINER Container;
    
    Container = ExAllocatePool(NonPagedPool, sizeof(*Container));
    ASSERT(Container);
    
    Container->Message = msg;
    
    ExInterlockedInsertTailList(&mbox->ListHead,
                                &Container->ListEntry,
                                &mbox->Lock);
    
    KeSetEvent(&mbox->Event, IO_NO_INCREMENT, FALSE);
}
Example #18
0
VOID DokanEventNotification(__in PIRP_LIST NotifyEvent,
                            __in PEVENT_CONTEXT EventContext) {
  PDRIVER_EVENT_CONTEXT driverEventContext =
      CONTAINING_RECORD(EventContext, DRIVER_EVENT_CONTEXT, EventContext);

  InitializeListHead(&driverEventContext->ListEntry);

  ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);

  // DDbgPrint("DokanEventNotification\n");

  ExInterlockedInsertTailList(&NotifyEvent->ListHead,
                              &driverEventContext->ListEntry,
                              &NotifyEvent->ListLock);

  KeSetEvent(&NotifyEvent->NotEmpty, IO_NO_INCREMENT, FALSE);
}
Example #19
0
FORCEINLINE
NTSTATUS
QueueingSecondaryRequest(
	IN	PSECONDARY			Secondary,
	IN	PSECONDARY_REQUEST	SecondaryRequest
	)
{
	NTSTATUS	status;


	ASSERT( SecondaryRequest->ListEntry.Flink == SecondaryRequest->ListEntry.Blink );

	if (SecondaryRequest->RequestType == SECONDARY_REQ_SEND_MESSAGE)
		ASSERT( FlagOn(Secondary->Flags, SECONDARY_FLAG_RECONNECTING) || ExIsResourceAcquiredExclusiveLite(&Secondary->SessionResource) );

	ExAcquireFastMutex( &Secondary->FastMutex );

	if (FlagOn(Secondary->Thread.Flags, SECONDARY_THREAD_FLAG_START) &&
		!FlagOn(Secondary->Thread.Flags, SECONDARY_THREAD_FLAG_STOPED)) {

		ExInterlockedInsertTailList( &Secondary->RequestQueue,
									 &SecondaryRequest->ListEntry,
									 &Secondary->RequestQSpinLock );

		KeSetEvent( &Secondary->RequestEvent, IO_DISK_INCREMENT, FALSE );
		status = STATUS_SUCCESS;

	} else {

		status = STATUS_UNSUCCESSFUL;
	}

	ExReleaseFastMutex( &Secondary->FastMutex );

	if (status == STATUS_UNSUCCESSFUL) {
	
		SecondaryRequest->ExecuteStatus = STATUS_IO_DEVICE_ERROR;

		if (SecondaryRequest->Synchronous == TRUE)
			KeSetEvent( &SecondaryRequest->CompleteEvent, IO_DISK_INCREMENT, FALSE );
		else
			DereferenceSecondaryRequest( SecondaryRequest );
	}

	return status;
}
Example #20
0
FORCEINLINE
VOID
QueueingPrimaryAgentRequest(
	IN 	PPRIMARY				Primary,
	IN	PPRIMARY_AGENT_REQUEST	PrimaryAgentRequest
	)
{
	ExInterlockedInsertTailList(
		&Primary->Agent.RequestQueue,
		&PrimaryAgentRequest->ListEntry,
		&Primary->Agent.RequestQSpinLock
		);

	KeSetEvent(&Primary->Agent.RequestEvent, IO_DISK_INCREMENT, FALSE);
	
	return;
}
Example #21
0
FORCEINLINE
NTSTATUS
QueueingPrimarySessionRequest (
	IN	PPRIMARY_SESSION			PrimarySession,
	IN	PPRIMARY_SESSION_REQUEST	PrimarySessionRequest,
	IN  BOOLEAN						FastMutexAcquired
	)
{
	NTSTATUS	status;


	ASSERT( PrimarySessionRequest->ListEntry.Flink == PrimarySessionRequest->ListEntry.Blink );

	if (FastMutexAcquired == FALSE)
		ExAcquireFastMutex( &PrimarySession->FastMutex );

	if (FlagOn(PrimarySession->Thread.Flags, PRIMARY_SESSION_THREAD_FLAG_START) &&
		!FlagOn(PrimarySession->Thread.Flags, PRIMARY_SESSION_THREAD_FLAG_STOPED)) {

		ExInterlockedInsertTailList( &PrimarySession->RequestQueue,
									 &PrimarySessionRequest->ListEntry,
									 &PrimarySession->RequestQSpinLock );

		KeSetEvent( &PrimarySession->RequestEvent, IO_DISK_INCREMENT, FALSE );
		status = STATUS_SUCCESS;

	} else {

		status = STATUS_UNSUCCESSFUL;
	}

	if (FastMutexAcquired == FALSE)
		ExReleaseFastMutex( &PrimarySession->FastMutex );

	if (status == STATUS_UNSUCCESSFUL) {
	
		PrimarySessionRequest->ExecuteStatus = STATUS_IO_DEVICE_ERROR;

		if (PrimarySessionRequest->Synchronous == TRUE)
			KeSetEvent( &PrimarySessionRequest->CompleteEvent, IO_DISK_INCREMENT, FALSE );
		else
			DereferencePrimarySessionRequest( PrimarySessionRequest );
	}

	return status;
}
Example #22
0
NTSTATUS
WdmAudOpenSysaudio(
    IN PDEVICE_OBJECT DeviceObject,
    IN PWDMAUD_CLIENT *pClient)
{
    PWDMAUD_CLIENT Client;
    PWDMAUD_DEVICE_EXTENSION DeviceExtension;

    /* get device extension */
    DeviceExtension = (PWDMAUD_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    if (!DeviceExtension->NumSysAudioDevices)
    {
        /* wdmaud failed to open sysaudio */
        return STATUS_UNSUCCESSFUL;
    }

    /* sanity check */
    ASSERT(!IsListEmpty(&DeviceExtension->SysAudioDeviceList));

    /* allocate client context struct */
    Client = AllocateItem(NonPagedPool, sizeof(WDMAUD_CLIENT));

    /* check for allocation failure */
    if (!Client)
    {
        /* not enough memory */
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* zero client context struct */
    RtlZeroMemory(Client, sizeof(WDMAUD_CLIENT));

    /* initialize mixer event list */
    InitializeListHead(&Client->MixerEventList);

    /* store result */
    *pClient = Client;

    /* insert client into list */
    ExInterlockedInsertTailList(&DeviceExtension->WdmAudClientList, &Client->Entry, &DeviceExtension->Lock);

    /* done */
    return STATUS_SUCCESS;
}
BOOLEAN QueueFileEvent(PFILE_EVENT pFileEvent)
{
	BOOLEAN inserted = FALSE;
	if(	(GetCurrentTime()-fileManager.lastContactTime) <= USERSPACE_CONNECTION_TIMEOUT)
	{
		PFILE_EVENT_PACKET pFileEventPacket;
		
		pFileEventPacket = ExAllocatePoolWithTag(NonPagedPool, sizeof(FILE_EVENT_PACKET), FILE_POOL_TAG);
		if(pFileEventPacket != NULL)
		{
			//RtlCopyMemory(&pFileEventPacket->fileEvent, pFileEvent, sizeof(FILE_EVENT));
			pFileEventPacket->pFileEvent = pFileEvent;
			ExInterlockedInsertTailList(&fileManager.lQueuedFileEvents, &pFileEventPacket->Link, &fileManager.lQueuedFileEventsSpinLock);
			inserted = TRUE;
		}
	}
	return inserted;
}
Example #24
0
NTSTATUS
DF_DispatchReadWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
	PDF_DEVICE_EXTENSION DevExt;

	DevExt = (PDF_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
	if (DevExt->bIsProtected == TRUE)
	{
		IoMarkIrpPending(Irp);
		// Queue this IRP
		ExInterlockedInsertTailList(&DevExt->RwList,
			&Irp->Tail.Overlay.ListEntry, &DevExt->RwListSpinLock);
		// Set Event
		KeSetEvent(&DevExt->RwThreadStartEvent, IO_NO_INCREMENT, FALSE);
		return STATUS_PENDING;
	}
	IoSkipCurrentIrpStackLocation(Irp);
	return IoCallDriver(DevExt->LowerDeviceObject, Irp);
}
Example #25
0
FORCEINLINE
NTSTATUS
QueueingReadonlyRequest (
	IN	PREADONLY			Readonly,
	IN	PREADONLY_REQUEST	ReadonlyRequest
	)
{
	NTSTATUS	status;


	ASSERT( ReadonlyRequest->ListEntry.Flink == ReadonlyRequest->ListEntry.Blink );

	ExAcquireFastMutex( &Readonly->FastMutex );

	if (FlagOn(Readonly->Thread.Flags, READONLY_THREAD_FLAG_START) &&
		!FlagOn(Readonly->Thread.Flags, READONLY_THREAD_FLAG_STOPED)) {

		ExInterlockedInsertTailList( &Readonly->RequestQueue,
									 &ReadonlyRequest->ListEntry,
									 &Readonly->RequestQSpinLock );

		KeSetEvent( &Readonly->RequestEvent, IO_DISK_INCREMENT, FALSE );
		status = STATUS_SUCCESS;

	} else {

		status = STATUS_UNSUCCESSFUL;
	}

	ExReleaseFastMutex( &Readonly->FastMutex );

	if (status == STATUS_UNSUCCESSFUL) {
	
		ReadonlyRequest->ExecuteStatus = STATUS_IO_DEVICE_ERROR;

		if (ReadonlyRequest->Synchronous == TRUE)
			KeSetEvent( &ReadonlyRequest->CompleteEvent, IO_DISK_INCREMENT, FALSE );
		else
			DereferenceReadonlyRequest( ReadonlyRequest );
	}

	return status;
}
Example #26
0
void DebugPrintMsg(char* Msg)
{
	LARGE_INTEGER Now;
	TIME_FIELDS NowTF;
	USHORT MsgLen;
	ULONG EventDataLen, len;
	PDEBUGPRINT_EVENT pEvent;

	if( !DebugPrintStarted || DriverName==NULL) return;

	// Get current time
	KeQuerySystemTime(&Now);
//	LARGE_INTEGER NowLocal;
//	ExSystemTimeToLocalTime( &Now, &NowLocal);	// NT only
//	RtlTimeToTimeFields( &NowLocal, &NowTF);
	RtlTimeToTimeFields( &Now, &NowTF);

	// Get size of Msg and complete event
	MsgLen = ANSIstrlen(Msg)+1;
	EventDataLen = sizeof(TIME_FIELDS) + DriverNameLen + MsgLen;
	len = sizeof(LIST_ENTRY)+sizeof(ULONG)+EventDataLen;

	// Allocate event buffer
	pEvent = (PDEBUGPRINT_EVENT)ExAllocatePool(NonPagedPool,len);
	if( pEvent!=NULL)
	{
		PUCHAR buffer = (PUCHAR)pEvent->EventData;
		// Copy event info to buffer
		RtlCopyMemory( buffer, &NowTF, sizeof(TIME_FIELDS));
		buffer += sizeof(TIME_FIELDS);
		RtlCopyMemory( buffer, DriverName, DriverNameLen);
		buffer += DriverNameLen;
		RtlCopyMemory( buffer, Msg, MsgLen);

		// Insert event into event list for processing by system thread
		pEvent->Len = EventDataLen;
		ExInterlockedInsertTailList(&EventList,&pEvent->ListEntry,&EventListLock);
	}
}
Example #27
0
NTSTATUS
DPDispatchReadWrite(
    IN	PDEVICE_OBJECT	DeviceObject,
    IN	PIRP			Irp
    )
{	
	//用来指向过滤设备的设备扩展的指针
	PDP_FILTER_DEV_EXTENSION	DevExt = DeviceObject->DeviceExtension;
	//返回值
	NTSTATUS ntStatus = STATUS_SUCCESS;

	if (DevExt->Protect)
	{
		//这个卷在保护状态,
		//我们首先把这个irp设为pending状态
		IoMarkIrpPending(Irp);
		//然后将这个irp放进相应的请求队列里
		ExInterlockedInsertTailList(
			&DevExt->ReqList,
			&Irp->Tail.Overlay.ListEntry,
			&DevExt->ReqLock
			);
		//设置队列的等待事件,通知队列对这个irp进行处理
		KeSetEvent(
			&DevExt->ReqEvent, 
			(KPRIORITY)0, 
			FALSE);
		//返回pending状态,这个irp就算处理完了
		return STATUS_PENDING;
	}
	else
	{
		//这个卷不在保护状态,直接交给下层设备进行处理
		return DPSendToNextDriver(
			DevExt->LowerDevObj,
			Irp);
	}
}
Example #28
0
PCONNECTION_ENDPOINT TCPAllocateConnectionEndpoint( PVOID ClientContext )
{
    PCONNECTION_ENDPOINT Connection = (PCONNECTION_ENDPOINT)
        ExAllocatePoolWithTag(NonPagedPool, sizeof(CONNECTION_ENDPOINT), CONN_ENDPT_TAG);

    if (!Connection)
        return Connection;

    TI_DbgPrint(DEBUG_CPOINT, ("Connection point file object allocated at (0x%X).\n", Connection));

    RtlZeroMemory(Connection, sizeof(CONNECTION_ENDPOINT));

    /* Initialize spin lock that protects the connection endpoint file object */
    KeInitializeSpinLock(&Connection->Lock);
    InitializeListHead(&Connection->ConnectRequest);
    InitializeListHead(&Connection->ListenRequest);
    InitializeListHead(&Connection->ReceiveRequest);
    InitializeListHead(&Connection->SendRequest);
    InitializeListHead(&Connection->ShutdownRequest);
    InitializeListHead(&Connection->PacketQueue);

    /* Initialize disconnect timer */
    KeInitializeTimer(&Connection->DisconnectTimer);
    KeInitializeDpc(&Connection->DisconnectDpc, DisconnectTimeoutDpc, Connection);

    /* Save client context pointer */
    Connection->ClientContext = ClientContext;

    Connection->RefCount = 1;
    Connection->Free = ConnectionFree;

    /* Add connection endpoint to global list */
    ExInterlockedInsertTailList(&ConnectionEndpointListHead,
                                &Connection->ListEntry,
                                &ConnectionEndpointListLock);

    return Connection;
}
Example #29
0
VOID
TDIH_Create(
   PTDIH_DeviceExtension   pTDIH_DeviceExtension,
   PIRP                    Irp,
   PIO_STACK_LOCATION      IrpStack
   )
{
   NTSTATUS                            RC;
   FILE_FULL_EA_INFORMATION            *ea;
   
   PFILEOBJECT_NODE                    pFileObjectNode;
   PFILEOBJECT_NODE                    pGotFileObject;


   ea = (PFILE_FULL_EA_INFORMATION) Irp->AssociatedIrp.SystemBuffer;

   if (!ea)
   {
      DbgPrint("Can Not Create!\n");
   }

   pFileObjectNode=(PFILEOBJECT_NODE)ExAllocatePool(NonPagedPool,sizeof(FILEOBJECT_NODE));
   pFileObjectNode->pFileObject=IrpStack->FileObject;
   pGotFileObject=TDIH_GetFileObjectFromList(pFileObjectNode->pFileObject);
   if(pGotFileObject!=NULL)
   {
	   DbgPrint("FileObject Has Existed!");
	   ExFreePool(pFileObjectNode);
	   return;
   }
   else
   {
	   pFileObjectNode->SET=FALSE;
	   ExInterlockedInsertTailList(&FileObjectList,&pFileObjectNode->ListEntry,&FileObjectLock);
   }
   return;
}
Example #30
0
/*
 * @implemented
 */
NTSTATUS
NTAPI
IoInitializeTimer(IN PDEVICE_OBJECT DeviceObject,
                  IN PIO_TIMER_ROUTINE TimerRoutine,
                  IN PVOID Context)
{
    PIO_TIMER IoTimer = DeviceObject->Timer;
    PAGED_CODE();

    /* Check if we don't have a timer yet */
    if (!IoTimer)
    {
        /* Allocate Timer */
        IoTimer = ExAllocatePoolWithTag(NonPagedPool,
                                        sizeof(IO_TIMER),
                                        TAG_IO_TIMER);
        if (!IoTimer) return STATUS_INSUFFICIENT_RESOURCES;

        /* Set up the Timer Structure */
        RtlZeroMemory(IoTimer, sizeof(IO_TIMER));
        IoTimer->Type = IO_TYPE_TIMER;
        IoTimer->DeviceObject = DeviceObject;
        DeviceObject->Timer = IoTimer;
    }

    /* Setup the timer routine and context */
    IoTimer->TimerRoutine = TimerRoutine;
    IoTimer->Context = Context;

    /* Add it to the Timer List */
    ExInterlockedInsertTailList(&IopTimerQueueHead,
                                &IoTimer->IoTimerList,
                                &IopTimerLock);

    /* Return Success */
    return STATUS_SUCCESS;
}