Exemple #1
0
/** Locks a given table bucket for shared access.
 *
 *  @param Table Table which bucket is about to be locked.
 *  @param Index A zero-based index of the bucket to lock.
 *  @param Irql Address of variable. If the table is not a dispatch IRQL
 *  one, this parameter is ignored. Otherwise, the variable is filled with
 *  the current IRQL value just before the locking in shared mode is performed.
 *
 *  @remark
 *  If access to the table is not synchronized, the routine performs nothing.
 *
 *  The @link(HASH_TABLE_IRQL_VALIDATE) is used to check whether the caller
 *  runs at a valid IRQL.
 */
static VOID HashTableLockShared(PHASH_TABLE Table, ULONG32 Index, PKIRQL Irql)
{
   HASH_TABLE_IRQL_VALIDATE(Table);
   ASSERT(Index < Table->Size);

   switch (Table->Type) {
      case httPassiveLevel:
         KeEnterCriticalRegion();
         ExAcquireResourceSharedLite(&Table->Locks[Index], TRUE);
         break;
      case httDispatchLevel:
         KeAcquireSpinLock(&Table->DispatchLocks[Index], Irql);
         break;
      case httNoSynchronization:
         break;
      default:
         DEBUG_ERROR("Invalid hash table type: %u", Table->Type);
         break;
   }

   return;
}
void
RosKmAdapter::QueueDmaBuffer(
    IN_CONST_PDXGKARG_SUBMITCOMMAND pSubmitCommand)
{
    ROSDMABUFINFO *         pDmaBufInfo = (ROSDMABUFINFO *)pSubmitCommand->pDmaBufferPrivateData;
    KIRQL                   OldIrql;
    ROSDMABUFSUBMISSION *   pDmaBufSubmission;

    KeAcquireSpinLock(&m_dmaBufQueueLock, &OldIrql);

    //
    // Combination indicating preparation error, thus the DMA buffer should be discarded
    //
    if ((pSubmitCommand->DmaBufferPhysicalAddress.QuadPart == 0) &&
            (pSubmitCommand->DmaBufferSubmissionStartOffset == 0) &&
            (pSubmitCommand->DmaBufferSubmissionEndOffset == 0))
    {
        m_ErrorHit.m_PreparationError = 1;
    }

    if (!pDmaBufInfo->m_DmaBufState.m_bSubmittedOnce)
    {
        pDmaBufInfo->m_DmaBufState.m_bSubmittedOnce = 1;
    }

    NT_ASSERT(!IsListEmpty(&m_dmaBufSubmissionFree));

    pDmaBufSubmission = CONTAINING_RECORD(RemoveHeadList(&m_dmaBufSubmissionFree), ROSDMABUFSUBMISSION, m_QueueEntry);

    pDmaBufSubmission->m_pDmaBufInfo = pDmaBufInfo;

    pDmaBufSubmission->m_StartOffset = pSubmitCommand->DmaBufferSubmissionStartOffset;
    pDmaBufSubmission->m_EndOffset = pSubmitCommand->DmaBufferSubmissionEndOffset;
    pDmaBufSubmission->m_SubmissionFenceId = pSubmitCommand->SubmissionFenceId;

    InsertTailList(&m_dmaBufQueue, &pDmaBufSubmission->m_QueueEntry);

    KeReleaseSpinLock(&m_dmaBufQueueLock, OldIrql);
}
Exemple #3
0
VOID
NtfsReleaseFCB(PNTFS_VCB Vcb,
               PNTFS_FCB Fcb)
{
    KIRQL oldIrql;

    DPRINT("releasing FCB at %p: %S, refCount:%d\n",
           Fcb,
           Fcb->PathName,
           Fcb->RefCount);

    KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
    Fcb->RefCount--;
    if (Fcb->RefCount <= 0 && !NtfsFCBIsDirectory(Fcb))
    {
        RemoveEntryList(&Fcb->FcbListEntry);
        CcUninitializeCacheMap(Fcb->FileObject, NULL, NULL);
        NtfsDestroyFCB(Fcb);
    }

    KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
}
Exemple #4
0
ULONG datapipe_get(datapipe_t *dp, char *buf, ULONG size)
{
	struct datapipe_entry *de;
	ULONG result = 0;
	KIRQL irql;

	KeAcquireSpinLock(&dp->guard, &irql);
	de = dp->first;

	if (!de) goto done;
	if (de->size > size) goto done;

	dp->first = de->next;

	memcpy(buf, de->data, de->size);
	result = de->size;

	free(de);
done:
	KeReleaseSpinLock(&dp->guard, irql);
	return result;
}
static NTSTATUS vboxNewProtDeviceAdded(PVBOXMOUSE_DEVEXT pDevExt)
{
    if (!vboxNewProtIsEnabled())
    {
        WARN(("New Protocol is disabled"));
        return STATUS_UNSUCCESSFUL;
    }

    NTSTATUS Status = STATUS_SUCCESS;
    KIRQL Irql;
    KeAcquireSpinLock(&g_ctx.SyncLock, &Irql);
    InsertHeadList(&g_ctx.DevExtList, &pDevExt->ListEntry);
    if (!g_ctx.pCurrentDevExt)
    {
        ASMAtomicWritePtr(&g_ctx.pCurrentDevExt, pDevExt);
        /* ensure the object is not deleted while it is being used by a poller thread */
        ObReferenceObject(pDevExt->pdoSelf);
    }
    KeReleaseSpinLock(&g_ctx.SyncLock, Irql);

    return Status;
}
Exemple #6
0
VOID
NdasPortClearLpxLocalAddressList(
	PNDASPORT_DRIVER_EXTENSION DriverExtension)
{
	PLIST_ENTRY entry;
	KIRQL oldIrql;

	KeAcquireSpinLock(&DriverExtension->LpxLocalAddressListSpinLock, &oldIrql);
	
	entry = DriverExtension->LpxLocalAddressList.Flink;
	while (entry != &DriverExtension->LpxLocalAddressList)
	{
		PTDI_ADDRESS_LPX_LIST_ENTRY lpxAddressEntry;

		lpxAddressEntry = CONTAINING_RECORD(
			entry, 
			TDI_ADDRESS_LPX_LIST_ENTRY, 
			ListEntry);

		//
		// Forward the link first
		//
		entry = entry->Flink;
		
		//
		// And remove the actual entry
		//
		RemoveEntryList(&lpxAddressEntry->ListEntry);
		
		//
		// Now we can free the allocated list
		//
		ExFreePoolWithTag(
			lpxAddressEntry,
			NDASPORT_TAG_TDI);
	}

	KeReleaseSpinLock(&DriverExtension->LpxLocalAddressListSpinLock, oldIrql);
}
Exemple #7
0
VOID CancelRoutine(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
{
  LIST_ENTRY queueToComplete;
  PC0C_IO_PORT pIoPort;
  PC0C_IRP_STATE pState;
  KIRQL oldIrql;
  PC0C_IRP_QUEUE pQueue;

  IoReleaseCancelSpinLock(pIrp->CancelIrql);

  pIoPort = FDO_PORT_TO_IO_PORT(pDevObj);
  pState = GetIrpState(pIrp);
  HALT_UNLESS(pState);

  pQueue = &pIoPort->irpQueues[pState->iQueue];

  InitializeListHead(&queueToComplete);

  KeAcquireSpinLock(pIoPort->pIoLock, &oldIrql);

  if (pState->flags & C0C_IRP_FLAG_IN_QUEUE) {
    RemoveEntryList(&pIrp->Tail.Overlay.ListEntry);
    pState->flags &= ~C0C_IRP_FLAG_IN_QUEUE;
  }

  pIrp->IoStatus.Status = STATUS_CANCELLED;
  InsertTailList(&queueToComplete, &pIrp->Tail.Overlay.ListEntry);

  if (pState->flags & C0C_IRP_FLAG_IS_CURRENT) {
    ShiftQueue(pQueue);

    if (pState->iQueue == C0C_QUEUE_WRITE)
      ReadWrite(pIoPort->pIoPortRemote, FALSE, pIoPort, FALSE, &queueToComplete);
  }

  KeReleaseSpinLock(pIoPort->pIoLock, oldIrql);

  FdoPortCompleteQueue(&queueToComplete);
}
Exemple #8
0
void Notification_Send(NOTIFICATION_QUEUE *queue, const PGNOTIFICATION *notification) {
	KIRQL irq;

	KeAcquireSpinLock(&queue->lock, &irq);

	if(IsListEmpty(&queue->irp_list)) {
		if(queue->queued < 64) {
			PGNOTIFYNODE *notifynode;

			notifynode = ExAllocateFromNPagedLookasideList(&queue->lookaside);
			
			InitializeListHead(&notifynode->entry);
			RtlCopyMemory(&notifynode->notification, notification, sizeof(PGNOTIFICATION));

			InsertTailList(&queue->notification_list, &notifynode->entry);
			++queue->queued;
		}
		
		KeReleaseSpinLock(&queue->lock, irq);
	}
	else {
		PGIRPNODE *irpnode = (PGIRPNODE*)RemoveHeadList(&queue->irp_list);
		PGNOTIFICATION *irpnotification = irpnode->irp->AssociatedIrp.SystemBuffer;
		PIRP irp;

		RtlCopyMemory(irpnotification, notification, sizeof(PGNOTIFICATION));

		irp = irpnode->irp;
		ExFreeToNPagedLookasideList(&queue->lookaside, irpnode);

		KeReleaseSpinLock(&queue->lock, irq);

		irp->IoStatus.Status = STATUS_SUCCESS;
		irp->IoStatus.Information = sizeof(PGNOTIFICATION);

		IoCompleteRequest(irp, IO_NO_INCREMENT);
	}
}
Exemple #9
0
VOID
XenM2BPdoUnlink(PXENM2B_PDO_EXTENSION pPdoExt,
                BOOLEAN Locked)
{
    PXENM2B_FDO_EXTENSION pFdoExt;
    PXENM2B_HID_CONTEXT   pHidCtx = pPdoExt->pHidCtx;
    PLIST_ENTRY           pEntry = &pPdoExt->ListEntry;
    KIRQL                 Irql;

    ASSERT(pPdoExt->pFdo != NULL);
    pFdoExt = (PXENM2B_FDO_EXTENSION)pPdoExt->pFdo->DeviceExtension;
    ASSERT(pFdoExt != NULL);

    if (!Locked)
        KeAcquireSpinLock(&pFdoExt->PdoListLock, &Irql);

    // If we are unlinking the active Pdo due to a device removal we need to reset the active hid context.
    //
    if (pFdoExt->pActiveHidCtx == pHidCtx) {
        pFdoExt->pActiveHidCtx = NULL;
        XenM2BReleaseHidContext(pHidCtx);
    }

    RemoveEntryList(pEntry);
    pPdoExt->pFdo = NULL;
    ASSERT(pFdoExt->References != 0);
    pFdoExt->References--;

    if (!Locked)
        KeReleaseSpinLock(&pFdoExt->PdoListLock, Irql);

    // If the removed Pdo had the final reference to the Fdo, delete the Fdo now.
    //
    if (pFdoExt->References == 0) {
        ASSERT(!Locked);
        XenM2BDeleteDevice(pFdoExt);
    }
}
Exemple #10
0
BOOL
STREAMAPI
RemoveFromListIfAvailable (
    IN OUT PHW_STREAM_REQUEST_BLOCK *pSrb,
    IN KSPIN_LOCK                   *SpinLock,
    IN OUT BOOL                     *BusyFlag,
    IN LIST_ENTRY                   *ListHead
    )
{
    KIRQL                       Irql;

    KeAcquireSpinLock (SpinLock, &Irql);

    //
    // If the queue is now empty, clear the busy flag, and return
    //
    if (IsListEmpty(ListHead)) {
        *BusyFlag = FALSE;
        KeReleaseSpinLock(SpinLock, Irql);
        return FALSE;
    }
    //
    // otherwise extract the SRB
    //
    else {
        PUCHAR          ptr;
        PSRB_EXTENSION  pSrbExt;

        ptr = (PUCHAR)RemoveHeadList(ListHead);
        *BusyFlag = TRUE;
        KeReleaseSpinLock(SpinLock, Irql);
        // Get the SRB out of the SRB extension and return it
        pSrbExt = (PSRB_EXTENSION) (((PUCHAR) ptr) -
                     FIELDOFFSET(SRB_EXTENSION, ListEntry));
        *pSrb = pSrbExt->pSrb;
    }
    return TRUE;
}
Exemple #11
0
VOID 
AnlgTunerScanRemoveEvent(
                        PFILE_OBJECT  FileObject,
                        struct _KSEVENT_ENTRY*  EventEntry
	)
{
    KIRQL OldIrql;
    CEncoderDevice* pEncDevice = NULL;

    DbgPrint("AnlgTunerScanRemoveEvent enter!\n");
    PKSFILTER Filter = KsGetFilterFromFileObject(FileObject);
    ASSERT(Filter);
    if (!Filter) return;
    ASSERT(EventEntry);

    PKSDEVICE pDevice = KsFilterGetDevice(Filter);
    pEncDevice = reinterpret_cast<CEncoderDevice *>(pDevice->Context);

    KeAcquireSpinLock(&pEncDevice->EventHandlerSpinLock, &OldIrql);

    if(pEncDevice->ScanInitialization)
		RemoveEntryList(&EventEntry->ListEntry);
    if (pEncDevice->pScanEvent) 
    {

        pEncDevice->pScanEvent = NULL;
        pEncDevice->EventData = NULL;
        pEncDevice->ScanInitialization = FALSE;
        if (EventHandler)//if not already stopped due to the end of the range stop it
        {
            EventHandler->bStopScan = TRUE;
            KeSetEvent(&(EventHandler->TuneEvent), 0,FALSE);
        }
    }
    KeReleaseSpinLock(&pEncDevice->EventHandlerSpinLock, OldIrql);
	return;

}
/*++

ClasspDequeueIdleRequest

Routine Description:

    This function will remove the next idle request from the list.
    If there are no requests in the queue, then it will return NULL.

Arguments:

    FdoExtension         - Pointer to the functional device extension

Return Value:

    Pointer to removed IRP

--*/
PIRP
ClasspDequeueIdleRequest(
    PFUNCTIONAL_DEVICE_EXTENSION FdoExtension
    )
{
    PCLASS_PRIVATE_FDO_DATA fdoData = FdoExtension->PrivateFdoData;
    PLIST_ENTRY listEntry = NULL;
    PIRP irp = NULL;
    KIRQL oldIrql;

    KeAcquireSpinLock(&fdoData->IdleListLock, &oldIrql);

    if (fdoData->IdleIoCount > 0) {
        listEntry = RemoveHeadList(&fdoData->IdleIrpList);
        //
        // Make sure we actaully removed a request from the list
        //
        NT_ASSERT(listEntry != &fdoData->IdleIrpList);
        //
        // Decrement the idle I/O count.
        //
        fdoData->IdleIoCount--;
        //
        // Stop the timer on last request
        //
        if (fdoData->IdleIoCount == 0) {
            ClasspStopIdleTimer(fdoData);
        }
        irp = CONTAINING_RECORD(listEntry, IRP, Tail.Overlay.ListEntry);
        NT_ASSERT(irp->Type == IO_TYPE_IRP);


        InitializeListHead(&irp->Tail.Overlay.ListEntry);
    }

    KeReleaseSpinLock(&fdoData->IdleListLock, oldIrql);
    return irp;
}
Exemple #13
0
VOID KillSelectsForFCB( PAFD_DEVICE_EXTENSION DeviceExt,
                        PFILE_OBJECT FileObject,
                        BOOLEAN OnlyExclusive ) {
    KIRQL OldIrql;
    PLIST_ENTRY ListEntry;
    PAFD_ACTIVE_POLL Poll;
    PIRP Irp;
    PAFD_POLL_INFO PollReq;
    PAFD_HANDLE HandleArray;
    UINT i;

    AFD_DbgPrint(MID_TRACE,("Killing selects that refer to %p\n", FileObject));

    KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );

    ListEntry = DeviceExt->Polls.Flink;
    while ( ListEntry != &DeviceExt->Polls ) {
        Poll = CONTAINING_RECORD(ListEntry, AFD_ACTIVE_POLL, ListEntry);
        ListEntry = ListEntry->Flink;
        Irp = Poll->Irp;
        PollReq = Irp->AssociatedIrp.SystemBuffer;
        HandleArray = AFD_HANDLES(PollReq);

        for( i = 0; i < PollReq->HandleCount; i++ ) {
            AFD_DbgPrint(MAX_TRACE,("Req: %u, This %p\n",
                                    HandleArray[i].Handle, FileObject));
            if( (PVOID)HandleArray[i].Handle == FileObject &&
                (!OnlyExclusive || (OnlyExclusive && Poll->Exclusive)) ) {
                ZeroEvents( PollReq->Handles, PollReq->HandleCount );
                SignalSocket( Poll, NULL, PollReq, STATUS_CANCELLED );
            }
        }
    }

    KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );

    AFD_DbgPrint(MID_TRACE,("Done\n"));
}
Exemple #14
0
NTSTATUS FdoPortClose(IN PC0C_FDOPORT_EXTENSION pDevExt, IN PIRP pIrp)
{
  NTSTATUS status;
  LIST_ENTRY queueToComplete;
  KIRQL oldIrql;
  PC0C_IO_PORT pIoPort;

  pIoPort = pDevExt->pIoPortLocal;

  pIoPort->isOpen = FALSE;

  if (pIoPort->pIoPortRemote->plugInMode)
    IoInvalidateDeviceRelations(pIoPort->pIoPortRemote->pPhDevObj, BusRelations);

  InitializeListHead(&queueToComplete);

  KeAcquireSpinLock(pIoPort->pIoLock, &oldIrql);

  pIoPort->escapeChar = 0;
  pIoPort->writeHoldingRemote = 0;
  pIoPort->sendXonXoff = 0;
  SetModemControl(pIoPort, C0C_MCR_OUT2, C0C_MCR_MASK | C0C_MCR_OPEN, &queueToComplete);
  FreeBuffer(&pIoPort->readBuf);
  SetBreakHolding(pIoPort, FALSE, &queueToComplete);

  KeReleaseSpinLock(pIoPort->pIoLock, oldIrql);

  FdoPortCompleteQueue(&queueToComplete);

  status = FdoPortStartIrp(pIoPort, pIrp, C0C_QUEUE_CLOSE, StartIrpClose);

  if (status != STATUS_PENDING) {
    pIrp->IoStatus.Status = status;
    IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  }

  return status;
}
Exemple #15
0
void vboxVhwaHlpOverlayDstRectUnion(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, RECT *pRect)
{
    if (vboxVhwaHlpOverlayListIsEmpty(pDevExt, VidPnSourceId))
    {
        memset(pRect, 0, sizeof (*pRect));
        return;
    }

    PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
    KIRQL OldIrql;
    KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
    if (pSource->cOverlays)
    {
        PVBOXWDDM_OVERLAY pOverlay = VBOXWDDM_OVERLAY_FROM_ENTRY(pSource->OverlayList.Flink);
        *pRect = pOverlay->DstRect;
        while (pOverlay->ListEntry.Flink != &pSource->OverlayList)
        {
            pOverlay = VBOXWDDM_OVERLAY_FROM_ENTRY(pOverlay->ListEntry.Flink);
            vboxWddmRectUnite(pRect, &pOverlay->DstRect);
        }
    }
    KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
}
Exemple #16
0
VOID FspFileNodeSetDirInfo(FSP_FILE_NODE *FileNode, PCVOID Buffer, ULONG Size)
{
    // !PAGED_CODE();

    FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension =
        FspFsvolDeviceExtension(FileNode->FsvolDeviceObject);
    FSP_FILE_NODE_NONPAGED *NonPaged = FileNode->NonPaged;
    KIRQL Irql;
    UINT64 DirInfo;

    /* no need to acquire the DirInfoSpinLock as the FileNode is acquired */
    DirInfo = NonPaged->DirInfo;

    FspMetaCacheInvalidateItem(FsvolDeviceExtension->DirInfoCache, DirInfo);
    DirInfo = 0 != Buffer ?
        FspMetaCacheAddItem(FsvolDeviceExtension->DirInfoCache, Buffer, Size) : 0;
    FileNode->DirInfoChangeNumber++;

    /* acquire the DirInfoSpinLock to protect against concurrent FspFileNodeInvalidateDirInfo */
    KeAcquireSpinLock(&NonPaged->DirInfoSpinLock, &Irql);
    NonPaged->DirInfo = DirInfo;
    KeReleaseSpinLock(&NonPaged->DirInfoSpinLock, Irql);
}
Exemple #17
0
/*
 * If there is buffer allocated for given control device, writes global
 * PCAP header to the buffer, otherwise does nothing.
 */
VOID USBPcapBufferInitializeBuffer(PDEVICE_EXTENSION pDevExt)
{
    PDEVICE_EXTENSION      pRootExt;
    PUSBPCAP_ROOTHUB_DATA  pData;
    KIRQL                  irql;

    ASSERT(pDevExt->deviceMagic == USBPCAP_MAGIC_CONTROL);

    pRootExt = (PDEVICE_EXTENSION)pDevExt->context.control.pRootHubObject->DeviceExtension;
    pData = pRootExt->context.usb.pDeviceData->pRootData;

    if (pData->buffer == NULL)
    {
        return;
    }

    /* Buffer found - reset all data and write global PCAP header */
    KeAcquireSpinLock(&pData->bufferLock, &irql);
    pData->readOffset = 0;
    pData->writeOffset = 0;
    USBPcapWriteGlobalHeader(pData);
    KeReleaseSpinLock(&pData->bufferLock, irql);
}
Exemple #18
0
void
free_adapter_list(void)
{
	KIRQL irql;
	struct adapter_entry *adapter;

	KeAcquireSpinLock(&g_list_guard, &irql);

	__try {

		for (adapter = g_first; adapter != NULL;) {
			struct adapter_entry *adapter2 = adapter->next;
			free(adapter);
			adapter = adapter2;
		}

		g_first = g_last = NULL;
		g_count = 0;

	} __finally {
		KeReleaseSpinLock(&g_list_guard, irql);
	}
}
Exemple #19
0
static void
usbd_xfer_complete(struct ndis_softc *sc, struct ndisusb_ep *ne,
    struct ndisusb_xfer *nx, usb_error_t status)
{
	struct ndisusb_xferdone *nd;
	uint8_t irql;

	nd = malloc(sizeof(struct ndisusb_xferdone), M_USBDEV,
	    M_NOWAIT | M_ZERO);
	if (nd == NULL) {
		device_printf(sc->ndis_dev, "out of memory");
		return;
	}
	nd->nd_xfer = nx;
	nd->nd_status = status;

	KeAcquireSpinLock(&sc->ndisusb_xferdonelock, &irql);
	InsertTailList((&sc->ndisusb_xferdonelist), (&nd->nd_donelist));
	KeReleaseSpinLock(&sc->ndisusb_xferdonelock, irql);

	IoQueueWorkItem(sc->ndisusb_xferdoneitem,
	    (io_workitem_func)usbd_xfertask_wrap, WORKQUEUE_CRITICAL, sc);
}
Exemple #20
0
ACPI_STATUS
AcpiOsSignalSemaphore(
    ACPI_SEMAPHORE Handle,
    UINT32 Units)
{
    PACPI_SEM Sem = Handle;
    KIRQL OldIrql;

    if (!Handle)
    {
        DPRINT1("Bad parameter\n");
        return AE_BAD_PARAMETER;
    }

    KeAcquireSpinLock(&Sem->Lock, &OldIrql);

    Sem->CurrentUnits += Units;
    KeSetEvent(&Sem->Event, IO_NO_INCREMENT, FALSE);

    KeReleaseSpinLock(&Sem->Lock, OldIrql);

    return AE_OK;
}
Exemple #21
0
VOID NTAPI
SerialSendByte(
	IN PKDPC Dpc,
	IN PVOID pDeviceExtension, // real type PSERIAL_DEVICE_EXTENSION
	IN PVOID Unused1,
	IN PVOID Unused2)
{
	PSERIAL_DEVICE_EXTENSION DeviceExtension;
	PUCHAR ComPortBase;
	UCHAR Byte;
	KIRQL Irql;
	UCHAR IER;
	NTSTATUS Status;

	DeviceExtension = (PSERIAL_DEVICE_EXTENSION)pDeviceExtension;
	ComPortBase = ULongToPtr(DeviceExtension->BaseAddress);

	KeAcquireSpinLock(&DeviceExtension->OutputBufferLock, &Irql);
	while (!IsCircularBufferEmpty(&DeviceExtension->OutputBuffer)
		&& READ_PORT_UCHAR(SER_LSR(ComPortBase)) & SR_LSR_THR_EMPTY)
	{
		Status = PopCircularBufferEntry(&DeviceExtension->OutputBuffer, &Byte);
		if (!NT_SUCCESS(Status))
			break;
		WRITE_PORT_UCHAR(SER_THR(ComPortBase), Byte);
		INFO_(SERIAL, "Byte sent to COM%lu: 0x%02x\n",
			DeviceExtension->ComPort, Byte);
		DeviceExtension->SerialPerfStats.TransmittedCount++;
	}
	if (!IsCircularBufferEmpty(&DeviceExtension->OutputBuffer))
	{
		/* allow new interrupts */
		IER = READ_PORT_UCHAR(SER_IER(ComPortBase));
		WRITE_PORT_UCHAR(SER_IER(ComPortBase), IER | SR_IER_THR_EMPTY);
	}
	KeReleaseSpinLock(&DeviceExtension->OutputBufferLock, Irql);
}
NTSTATUS CheckProtectProcess(__in HANDLE ProcessId)
{
	// 这里要先判断链表是否为空
	if (IsListEmpty(&ProtectProcessList.HeadList))
		return STATUS_NOT_FOUND;

	KIRQL irql;
	KeAcquireSpinLock(&ProtectProcessList.Lock, &irql);

	// 链表头
	PLIST_ENTRY pList = ProtectProcessList.HeadList.Flink;

	BOOLEAN isFind = FALSE;
	while (pList != &ProtectProcessList.HeadList)
	{
		PPROTECT_PROCESS element = CONTAINING_RECORD(pList, PROTECT_PROCESS, ListEntry);

		if (element->ProcessId == ProcessId)
		{
			KdPrint(("[ISISandBox] CheckProtectProcess Find ProcessId : %u.\n", element->ProcessId));
			isFind = TRUE;
			break;
		}

		pList = pList->Flink;
	}

	KeReleaseSpinLock(&ProtectProcessList.Lock, irql);

	if (isFind)
		return STATUS_SUCCESS;
	else
	{
		KdPrint(("[ISISandBox] CheckProtectProcess Cannot find ProcessId : %u.\n", ProcessId));
		return STATUS_NOT_FOUND;
	}
}
Exemple #23
0
VOID
Ik220SetDeviceFlags(IN PIK220_DEVICE_EXTENSION PDevExt, OUT PULONG PFlags,
                    IN ULONG Value, IN BOOLEAN Set)
/*++

Routine Description:

   Sets flags in a value protected by the flags spinlock.  This is used
   to set values that would stop IRP's from being accepted.

Arguments:
   PDevExt - Device extension attached to PDevObj

   PFlags - Pointer to the flags variable that needs changing

   Value - Value to modify flags variable with

   Set - TRUE if |= , FALSE if &=

Return Value:

   None.

--*/
{
   KIRQL oldIrql;

   KeAcquireSpinLock(&PDevExt->FlagsLock, &oldIrql);

   if (Set) {
      *PFlags |= Value;
   } else {
      *PFlags &= ~Value;
   }

   KeReleaseSpinLock(&PDevExt->FlagsLock, oldIrql);
}
Exemple #24
0
VOID ASUSACPIDeviceNotifyHandler(PVOID Context,ULONG NotifyValue)
{
	KdPrint(("Context=0x%X,NotifyValue=0x%X\n",Context,NotifyValue));
	KERNEL_DEVICE_INFO *pTemp,*pInfo=(KERNEL_DEVICE_INFO*)g_pdx->pDeviceNofityInfo;
	UCHAR ucValid=0;
	while(pInfo)
	{
		pTemp=pInfo;
		pInfo=(KERNEL_DEVICE_INFO*)pInfo->pList.Blink;
		if(pTemp->pdo==Context)
		{
			ucValid=1;
			if(pTemp->ulHooked)
			{
				if(pTemp->pCallBack)
				{
					KdPrint(("Invoking Old RoutineX\n"));
					pTemp->pCallBack(pTemp->pParam,NotifyValue);
				}
			}break;
		}
		if(pInfo==g_pdx->pDeviceNofityInfo)break;
	}
	if(ucValid)
	{
		KIRQL irql;
		KeAcquireSpinLock(&NotifyLock,&irql);
		if(g_ulNotifyCount>255)
			g_ulNotifyCount=0;
		NotifyBuffer[g_ulNotifyCount].pdo=(PDEVICE_OBJECT)Context;
		NotifyBuffer[g_ulNotifyCount].ulNotifyValue=NotifyValue;
		g_ulNotifyCount++;
		KeReleaseSpinLock(&NotifyLock,irql);
		if(g_pApNotifyEvent)
			KeSetEvent(g_pApNotifyEvent,0,0);
	}
}
Exemple #25
0
main () {


  while(1) {
    //get the write lock

    KeAcquireSpinLock(&devExt->writeListLock);

    nPacketsOld = nPackets; 
    request = devExt->WriteListHeadVa;

    if (!(loop_count<loop_max)) {
        break;
    }
    
    if(request && request->status){
      devExt->WriteListHeadVa = request->Next;
      KeReleaseSpinLock(&devExt->writeListLock);
      irp = request->irp;
      if(request->status > 0){
	irp->Status = 1;
	irp->Information = request->status;
      }
      else{
	irp->Status = 0;
	irp->Information = request->status;
      }
      nPackets++;
    loop_count++;
    }
    if (nPackets == nPacketsOld) {
        break;
    }
  } 
  
  KeReleaseSpinLock(&devExt->writeListLock);
}
Exemple #26
0
VOID
NTAPI
IopTimerDispatch(IN PKDPC Dpc,
                 IN PVOID DeferredContext,
                 IN PVOID SystemArgument1,
                 IN PVOID SystemArgument2)
{
    KIRQL OldIrql;
    PLIST_ENTRY TimerEntry;
    PIO_TIMER Timer;
    ULONG i;

    /* Check if any Timers are actualyl enabled as of now */
    if (IopTimerCount)
    {
        /* Lock the Timers */
        KeAcquireSpinLock(&IopTimerLock, &OldIrql);

        /* Call the Timer Routine of each enabled Timer */
        for (TimerEntry = IopTimerQueueHead.Flink, i = IopTimerCount;
            (TimerEntry != &IopTimerQueueHead) && i;
            TimerEntry = TimerEntry->Flink)
        {
            /* Get the timer and check if it's enabled */
            Timer = CONTAINING_RECORD(TimerEntry, IO_TIMER, IoTimerList);
            if (Timer->TimerEnabled)
            {
                /* Call the timer routine */
                Timer->TimerRoutine(Timer->DeviceObject, Timer->Context);
                i--;
            }
        }

        /* Unlock the Timers */
        KeReleaseSpinLock(&IopTimerLock, OldIrql);
    }
}
Exemple #27
0
VOID
CleanupAsyncList(PEHCI_HOST_CONTROLLER hcd)
{
    PQUEUE_TRANSFER_DESCRIPTOR Descriptor;
    PQUEUE_HEAD QueueHead;
    KIRQL OldIrql;

    KeAcquireSpinLock(&hcd->Lock, &OldIrql);

    QueueHead = hcd->CompletedListQueue;
    QueueHead = QueueHead->NextQueueHead;

    while (QueueHead != hcd->CompletedListQueue)
    {
        Descriptor = QueueHead->FirstTransferDescriptor;
        while (Descriptor)
        {
            if (Descriptor->Token.Bits.PIDCode == PID_CODE_SETUP_TOKEN)
                ReleaseMemory(hcd, Descriptor->BufferPointerVA[0]);
            FreeDescriptor(hcd, Descriptor);
            Descriptor = Descriptor->NextDescriptor;
        }

        if (QueueHead->FreeMdl)
        {
            DPRINT("Freeing Mdl %x, StartVA %x\n", QueueHead->Mdl, QueueHead->Mdl->StartVa);
            IoFreeMdl(QueueHead->Mdl);
        }
        
        QueueHead = QueueHead->NextQueueHead;
    }
    
    hcd->CompletedListQueue->NextQueueHead = hcd->CompletedListQueue;
    hcd->CompletedListQueue->PreviousQueueHead = hcd->CompletedListQueue;
    
    KeReleaseSpinLock(&hcd->Lock, OldIrql);
}
Exemple #28
0
VOID    DbgExFreePool( IN PVOID ptr )
/*++
--*/
{
    PMEM_NODE   p = (PMEM_NODE)((ULONG)ptr - sizeof(MEM_NODE));
    KIRQL       irql;

    if( pHead == NULL )return;
    KdPrint(("Free %x\n",p ));
    ASSERT( p->magic == MEM_MAGIC );

    KeAcquireSpinLock( &lock,&irql );

    if( p->prev == NULL ){
        pHead = p->next;
        //pHead->prev = NULL;
    }
    else
    {
        p->prev->next = p->next;
    }

    if( p->next == NULL )
    {
        pTail = p->prev;
        //pTail->next = NULL;
    }
    else
    {
        p->next->prev = p->prev;
    }
    cBytes -= p->size;
    KeReleaseSpinLock( &lock,irql );

    ExFreePoolWithTag( p,MEM_TAG ); 
    
}
NTSTATUS CheckMatchExpression(__in WCHAR Expression[], __in ULONG ExpressionLength)
{
	// 这里要先判断链表是否为空
	if (IsListEmpty(&MatchExpressionList.HeadList))
		return STATUS_NOT_FOUND;

	KIRQL irql;
	KeAcquireSpinLock(&MatchExpressionList.Lock, &irql);

	// 链表头
	PLIST_ENTRY pList = MatchExpressionList.HeadList.Flink;

	BOOLEAN isFind = FALSE;
	while (pList != &MatchExpressionList.HeadList)
	{
		PMATCH_EXPRESSION element = CONTAINING_RECORD(pList, MATCH_EXPRESSION, ListEntry);

		if (RtlCompareMemory(element->Expression, Expression, ExpressionLength) == ExpressionLength)
		{
			KdPrint(("[ISISandBox] CheckMatchExpression Find Expression : %S.\n", Expression));
			isFind = TRUE;
			break;
		}

		pList = pList->Flink;
	}

	KeReleaseSpinLock(&MatchExpressionList.Lock, irql);

	if (isFind)
		return STATUS_SUCCESS;
	else
	{
		KdPrint(("[ISISandBox] CheckMatchExpression Cannot find Expression : %S.\n", Expression));
		return STATUS_NOT_FOUND;
	}
}
Exemple #30
0
/* KphProtectFindEntry
 * 
 * Finds process protection data.
 * 
 * Thread safety: Full/Limited. The returned pointer is not guaranteed to 
 * point to a valid process entry. However, the copied entry is safe to 
 * read.
 * IRQL: <= DISPATCH_LEVEL
 */
PKPH_PROCESS_ENTRY KphProtectFindEntry(
    __in PEPROCESS Process,
    __in HANDLE Tag,
    __out_opt PKPH_PROCESS_ENTRY ProcessEntryCopy
    )
{
    KIRQL oldIrql;
    PLIST_ENTRY entry = ProtectedProcessListHead.Flink;
    
    KeAcquireSpinLock(&ProtectedProcessListLock, &oldIrql);
    
    while (entry != &ProtectedProcessListHead)
    {
        PKPH_PROCESS_ENTRY processEntry = 
            CONTAINING_RECORD(entry, KPH_PROCESS_ENTRY, ListEntry);
        
        if (
            (Process != NULL && processEntry->Process == Process) || 
            (Tag != NULL && processEntry->Tag == Tag)
            )
        {
            /* Copy the entry if requested. */
            if (ProcessEntryCopy)
                memcpy(ProcessEntryCopy, processEntry, sizeof(KPH_PROCESS_ENTRY));
            
            KeReleaseSpinLock(&ProtectedProcessListLock, oldIrql);
            
            return processEntry;
        }
        
        entry = entry->Flink;
    }
    
    KeReleaseSpinLock(&ProtectedProcessListLock, oldIrql);
    
    return NULL;
}