static void usbd_task(device_object *dobj, void *arg) { irp *ip; list_entry *l; struct ndis_softc *sc = arg; struct ndisusb_ep *ne; struct ndisusb_task *nt; union usbd_urb *urb; if (IsListEmpty(&sc->ndisusb_tasklist)) return; KeAcquireSpinLockAtDpcLevel(&sc->ndisusb_tasklock); l = sc->ndisusb_tasklist.nle_flink; while (l != &sc->ndisusb_tasklist) { nt = CONTAINING_RECORD(l, struct ndisusb_task, nt_tasklist); ip = nt->nt_ctx; urb = usbd_geturb(ip); KeReleaseSpinLockFromDpcLevel(&sc->ndisusb_tasklock); NDISUSB_LOCK(sc); switch (nt->nt_type) { case NDISUSB_TASK_TSTART: ne = usbd_get_ndisep(ip, urb->uu_bulkintr.ubi_epdesc); if (ne == NULL) goto exit; usbd_transfer_start(ne->ne_xfer[0]); break; case NDISUSB_TASK_IRPCANCEL: ne = usbd_get_ndisep(ip, (nt->nt_type == NDISUSB_TASK_IRPCANCEL) ? urb->uu_bulkintr.ubi_epdesc : urb->uu_pipe.upr_handle); if (ne == NULL) goto exit; usbd_transfer_stop(ne->ne_xfer[0]); usbd_transfer_start(ne->ne_xfer[0]); break; case NDISUSB_TASK_VENDOR: ne = (urb->uu_vcreq.uvc_trans_flags & USBD_TRANSFER_DIRECTION_IN) ? &sc->ndisusb_dread_ep : &sc->ndisusb_dwrite_ep; usbd_transfer_start(ne->ne_xfer[0]); break; default: break; } exit: NDISUSB_UNLOCK(sc); KeAcquireSpinLockAtDpcLevel(&sc->ndisusb_tasklock); l = l->nle_flink; RemoveEntryList(&nt->nt_tasklist); free(nt, M_USBDEV); } KeReleaseSpinLockFromDpcLevel(&sc->ndisusb_tasklock); }
KIRQL KeAcquireInterruptSpinLock ( __inout PKINTERRUPT Interrupt ) /*++ Routine Description: This function raises the IRQL to the interrupt synchronization level and acquires the actual spin lock associated with an interrupt object. Arguments: Interrupt - Supplies a pointer to a control object of type interrupt. Return Value: The previous IRQL is returned as the function value. --*/ { KIRQL OldIrql; // // Raise IRQL to interrupt synchronization level and acquire the actual // spin lock associated with the interrupt object. // KeRaiseIrql(Interrupt->SynchronizeIrql, &OldIrql); KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock); return OldIrql; }
/* * @implemented */ BOOLEAN NTAPI KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt, IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID SynchronizeContext OPTIONAL) { BOOLEAN Success; KIRQL OldIrql; /* Raise IRQL */ OldIrql = KfRaiseIrql(Interrupt->SynchronizeIrql); /* Acquire interrupt spinlock */ KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock); /* Call the routine */ Success = SynchronizeRoutine(SynchronizeContext); /* Release lock */ KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock); /* Lower IRQL */ KfLowerIrql(OldIrql); /* Return status */ return Success; }
int tdi_send(PIRP irp, PIO_STACK_LOCATION irps, struct completion *completion) { TDI_REQUEST_KERNEL_SEND *param = (TDI_REQUEST_KERNEL_SEND *)(&irps->Parameters); struct ot_entry *ote_conn; KIRQL irql; KdPrint(("[tdi_fw] tdi_send: connobj: 0x%x; SendLength: %u; SendFlags: 0x%x\n", irps->FileObject, param->SendLength, param->SendFlags)); ote_conn = ot_find_fileobj(irps->FileObject, &irql); if (ote_conn != NULL) { ULONG bytes = param->SendLength; ote_conn->bytes_out += bytes; // traffic stats KeAcquireSpinLockAtDpcLevel(&g_traffic_guard); g_traffic[TRAFFIC_TOTAL_OUT] += bytes; if (ote_conn->log_disconnect) g_traffic[TRAFFIC_COUNTED_OUT] += bytes; KeReleaseSpinLockFromDpcLevel(&g_traffic_guard); KeReleaseSpinLock(&g_ot_hash_guard, irql); } // TODO: process TDI_SEND_AND_DISCONNECT flag (used by IIS for example) return FILTER_ALLOW; }
NTSTATUS tdi_receive_complete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context) { PIO_STACK_LOCATION irps = IoGetCurrentIrpStackLocation(Irp); struct ot_entry *ote_conn; KIRQL irql; KdPrint(("[tdi_fw] tdi_receive_complete: connobj: 0x%x; status: 0x%x; received: %u\n", irps->FileObject, Irp->IoStatus.Status, Irp->IoStatus.Information)); ote_conn = ot_find_fileobj(irps->FileObject, &irql); if (ote_conn != NULL) { ULONG bytes = Irp->IoStatus.Information; ote_conn->bytes_in += bytes; // traffic stats KeAcquireSpinLockAtDpcLevel(&g_traffic_guard); g_traffic[TRAFFIC_TOTAL_IN] += bytes; if (ote_conn->log_disconnect) g_traffic[TRAFFIC_COUNTED_IN] += bytes; KeReleaseSpinLockFromDpcLevel(&g_traffic_guard); KeReleaseSpinLock(&g_ot_hash_guard, irql); } return tdi_generic_complete(DeviceObject, Irp, Context); }
void TimerDpcInterrupt(IN PKDPC Dpc, IN PEventHandlerData EventBlock,IN PVOID SystemArg1,IN PVOID SystemArg2) { UNREFERENCED_PARAMETER(Dpc); UNREFERENCED_PARAMETER(SystemArg1); UNREFERENCED_PARAMETER(SystemArg2); if (!EventBlock) return; if (!EventBlock->bStopScan) { // CEncoderDevice* EncDevice = EventBlock->pDevice; // // Reschedule the timer for the next interrupt time. // if(EventBlock->CurrentFrequency <= EventBlock->ScanData.EndFrequency) { KeSetEvent(&(EventBlock->InitEvent), 0,FALSE); } else { KeAcquireSpinLockAtDpcLevel(&(EventHandler->LockAccess)); EventBlock->bStopScan = TRUE; EventBlock->CurrentFrequency = EventBlock->ScanData.EndFrequency; KeReleaseSpinLockFromDpcLevel(&(EventHandler->LockAccess)); KeSetEvent(&(EventBlock->ThreadEvent), 0,FALSE); } } else { // // If someone is waiting on the hardware to stop, raise the stop // event and clear the flag. // KeSetEvent(&(EventBlock->ThreadEvent), 0,FALSE); } }
VOID NTAPI CancelQueued(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PDEVICE_EXTENSION deviceExtension; KIRQL oldIrql; FreeBT_DbgPrint(3, ("FBTUSB: CancelQueued: Entered\n")); deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension; oldIrql = Irp->CancelIrql; // Release the cancel spin lock IoReleaseCancelSpinLock(Irp->CancelIrql); // Acquire the queue lock KeAcquireSpinLockAtDpcLevel(&deviceExtension->QueueLock); // Remove the cancelled Irp from queue and release the lock RemoveEntryList(&Irp->Tail.Overlay.ListEntry); KeReleaseSpinLock(&deviceExtension->QueueLock, oldIrql); // complete with STATUS_CANCELLED Irp->IoStatus.Status = STATUS_CANCELLED; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); FreeBT_DbgPrint(3, ("FBTUSB: CancelQueued: Leaving\n")); return; }
VOID NotifierDisconnect( IN PXENVIF_NOTIFIER Notifier ) { KeAcquireSpinLockAtDpcLevel(&Notifier->Lock); ASSERT(Notifier->Connected); Notifier->Connected = FALSE; STORE(Release, Notifier->StoreInterface); Notifier->StoreInterface = NULL; DEBUG(Deregister, Notifier->DebugInterface, Notifier->DebugCallback); Notifier->DebugCallback = NULL; DEBUG(Release, Notifier->DebugInterface); Notifier->DebugInterface = NULL; EVTCHN(Close, Notifier->EvtchnInterface, Notifier->Evtchn); Notifier->Evtchn = NULL; Notifier->Events = 0; EVTCHN(Release, Notifier->EvtchnInterface); Notifier->EvtchnInterface = NULL; KeReleaseSpinLockFromDpcLevel(&Notifier->Lock); }
/////////////////////////////////////////////////////////////////////////////////////////////////// // testdrvQueueCancelRoutine // Cancel routine used for queue IRPs while in the queue // // Arguments: // IN DeviceObject // Device object for our device // // IN Irp // IRP to be cancelled // // Return Value: // none // VOID testdrvQueueCancelRoutine( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { KIRQL oldIrql; PTESTDRV_QUEUE queue; // release the system cancel spinlock oldIrql = Irp->CancelIrql; IoReleaseCancelSpinLock(DISPATCH_LEVEL); // get our queue from the IRP queue = (PTESTDRV_QUEUE)Irp->Tail.Overlay.DriverContext[0]; ASSERT(queue != NULL); // grab the queue protection KeAcquireSpinLockAtDpcLevel(&queue->QueueLock); // remove our IRP from the queue RemoveEntryList(&Irp->Tail.Overlay.ListEntry); // drop the queue protection KeReleaseSpinLock(&queue->QueueLock, oldIrql); // cancel the IRP Irp->IoStatus.Status = STATUS_CANCELLED; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return; }
/////////////////////////////////////////////////////////////////////////////////////////////////// // testdrvListCancelRoutine // Cancel routine used for our cancel safe IRP list // // Arguments: // IN DeviceObject // Device object for our device // // IN Irp // IRP to be cancelled // // Return Value: // none // VOID testdrvListCancelRoutine( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { KIRQL oldIrql; PTESTDRV_LIST list; oldIrql = Irp->CancelIrql; // release the system cancel spinlock IoReleaseCancelSpinLock(DISPATCH_LEVEL); // get our list context from the IRP list = (PTESTDRV_LIST)Irp->Tail.Overlay.DriverContext[0]; // grab the list protection KeAcquireSpinLockAtDpcLevel(&list->ListLock); // remove our IRP from the list RemoveEntryList(&Irp->Tail.Overlay.ListEntry); // drop the list protection KeReleaseSpinLock(&list->ListLock, oldIrql); // cancel the IRP Irp->IoStatus.Status = STATUS_CANCELLED; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return; }
VOID WriteToBuffer( //PRING_BUFFER pRb, const PCHAR pMsg, ULONG size ) { PKSPIN_LOCK spinLock; KIRQL currentIrql, oldIrql; //in init KeInitializeSpinLock(&spinLock); KeRaiseIrql(HIGH_LEVEL, &oldIrql); //currentIrql = KeGetCurrentIrql(); KeAcquireSpinLockAtDpcLevel(spinLock, ¤tIrql); bNeedFlush = WriteToBufferHelper( pRb, pMsg, size); KeReleaseSpinLockFromDpcLevel(spinLock, currentIrql); KeLowerIrql(&oldIrql); if (bNeedFlush) if (KeGetCurrentIrql()<2) { KeSetEvent } else { KeInsertQueuedDpc } }
VOID NTAPI ExpTimerDpcRoutine(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2) { PETIMER Timer = DeferredContext; BOOLEAN Inserted = FALSE; /* Reference the timer */ if (!ObReferenceObjectSafe(Timer)) return; /* Lock the Timer */ KeAcquireSpinLockAtDpcLevel(&Timer->Lock); /* Check if the timer is associated */ if (Timer->ApcAssociated) { /* Queue the APC */ Inserted = KeInsertQueueApc(&Timer->TimerApc, SystemArgument1, SystemArgument2, IO_NO_INCREMENT); } /* Release the Timer */ KeReleaseSpinLockFromDpcLevel(&Timer->Lock); /* Dereference it if we couldn't queue the APC */ if (!Inserted) ObDereferenceObject(Timer); }
VOID NTAPI VideoPortAcquireSpinLockAtDpcLevel( IN PVOID HwDeviceExtension, IN PSPIN_LOCK SpinLock) { TRACE_(VIDEOPRT, "VideoPortAcquireSpinLockAtDpcLevel\n"); KeAcquireSpinLockAtDpcLevel((PKSPIN_LOCK)SpinLock); }
VOID NdisDprAcquireSpinLock( IN PNDIS_SPIN_LOCK SpinLock ) { KeAcquireSpinLockAtDpcLevel(&SpinLock->SpinLock); SpinLock->OldIrql = DISPATCH_LEVEL; }
static VOID CfixkrsAcquireLockFilamentRegistry( __in PCFIXKRP_FILAMENT_REGISTRY Registry, __out PKIRQL OldIrql ) { KeRaiseIrql( SYNCH_LEVEL, OldIrql ); KeAcquireSpinLockAtDpcLevel( &Registry->Lock ); }
VOID NTAPI USBSTOR_Cancel( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PFDO_DEVICE_EXTENSION FDODeviceExtension; // // get FDO device extension // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; // // sanity check // ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL); ASSERT(FDODeviceExtension->Common.IsFDO); // // acquire irp list lock // KeAcquireSpinLockAtDpcLevel(&FDODeviceExtension->IrpListLock); // // remove the irp from the list // RemoveEntryList(&Irp->Tail.Overlay.ListEntry); // // release irp list lock // KeReleaseSpinLockFromDpcLevel(&FDODeviceExtension->IrpListLock); // // now release the cancel lock // IoReleaseCancelSpinLock(Irp->CancelIrql); // // set cancel status // Irp->IoStatus.Status = STATUS_CANCELLED; // // now cancel the irp // USBSTOR_QueueTerminateRequest(DeviceObject, Irp); IoCompleteRequest(Irp, IO_NO_INCREMENT); // // start the next one // USBSTOR_QueueNextRequest(DeviceObject); }
/*++ Routine Description: handle TXDone interrupt routine.. Arguments: FdoData Pointer to our FdoData Return Value: None --*/ VOID BthHandleTxRingDmaDoneInterrupt( IN PRTBTH_ADAPTER pAd, IN INT_SOURCE_CSR_STRUC TxRingBitmap) { PRT_TX_RING pTxRing; PTXD_STRUC pTxD; UCHAR RingIdx; UCHAR Count; UINT8 TxRingSize; for (RingIdx = 0; RingIdx < NUM_OF_TX_RING; RingIdx++) { Count = 0; pTxRing = &pAd->TxRing[RingIdx]; KeAcquireSpinLockAtDpcLevel(&pAd->SendLock); RT_IO_READ32(pAd, TX_DTX_IDX0 + RingIdx * RINGREG_DIFF, &pTxRing->TxDmaIdx); while ((pTxRing->TxDmaIdx != 0xffffffff) && (pTxRing->TxSwFreeIdx != pTxRing->TxDmaIdx)) { #if 0 if (pTxRing->TxDmaIdx >= TX_RING_SIZE) { DebugPrint(ERROR, DBG_MISC, "BthHandleTxRingDmaDoneInterrupt: Invalid pTxRing->TxDmaIdx = 0x%08x\n", pTxRing->TxDmaIdx); // // Invalid value, try to read it again. // It should be fine after read again. // RT_IO_READ32(pAd, TX_DTX_IDX0 + RingIdx * RINGREG_DIFF, &pTxRing->TxDmaIdx); Count++; if (Count > 10) break; continue; } #endif pTxD = (PTXD_STRUC) (pTxRing->Cell[pTxRing->TxSwFreeIdx].AllocVa); if(pTxD->DmaDone == 0) { break; } //pTxD->DmaDone = 0; //DebugPrint(TRACE, DBG_MISC, "-->%s(TxRing-%d):pTxRing->TxDmaIdx=0x%x, pTxRing->TxSwFreeIdx=0x%x!\n", __FUNCTION__, RingIdx, pTxRing->TxDmaIdx, pTxRing->TxSwFreeIdx); TxRingSize = BthGetTxRingSize(pAd, RingIdx); //INC_RING_INDEX(pTxRing->TxSwFreeIdx, TX_RING_SIZE); INC_RING_INDEX(pTxRing->TxSwFreeIdx, TxRingSize); KeSetEvent(&pAd->CoreEventTriggered, 1, FALSE); } KeReleaseSpinLockFromDpcLevel(&pAd->SendLock); } }
static int32_t usbd_func_vendorclass(irp *ip) { device_t dev = IRP_NDIS_DEV(ip); int32_t error; struct ndis_softc *sc = device_get_softc(dev); struct ndisusb_ep *ne; struct ndisusb_xfer *nx; struct usbd_urb_vendor_or_class_request *vcreq; union usbd_urb *urb; if (!(sc->ndisusb_status & NDISUSB_STATUS_SETUP_EP)) { /* * XXX In some cases the interface number isn't 0. However * some driver (eg. RTL8187L NDIS driver) calls this function * before calling URB_FUNCTION_SELECT_CONFIGURATION. */ error = usbd_setup_endpoint_default(ip, 0); if (error != USB_ERR_NORMAL_COMPLETION) return usbd_usb2urb(error); sc->ndisusb_status |= NDISUSB_STATUS_SETUP_EP; } urb = usbd_geturb(ip); vcreq = &urb->uu_vcreq; ne = (vcreq->uvc_trans_flags & USBD_TRANSFER_DIRECTION_IN) ? &sc->ndisusb_dread_ep : &sc->ndisusb_dwrite_ep; IRP_NDISUSB_EP(ip) = ne; ip->irp_cancelfunc = (cancel_func)usbd_irpcancel_wrap; nx = malloc(sizeof(struct ndisusb_xfer), M_USBDEV, M_NOWAIT | M_ZERO); if (nx == NULL) { device_printf(IRP_NDIS_DEV(ip), "out of memory\n"); return (USBD_STATUS_NO_MEMORY); } nx->nx_ep = ne; nx->nx_priv = ip; KeAcquireSpinLockAtDpcLevel(&ne->ne_lock); InsertTailList((&ne->ne_pending), (&nx->nx_next)); KeReleaseSpinLockFromDpcLevel(&ne->ne_lock); /* we've done to setup xfer. Let's transfer it. */ ip->irp_iostat.isb_status = STATUS_PENDING; ip->irp_iostat.isb_info = 0; USBD_URB_STATUS(urb) = USBD_STATUS_PENDING; IoMarkIrpPending(ip); error = usbd_taskadd(ip, NDISUSB_TASK_VENDOR); if (error != USBD_STATUS_SUCCESS) return (error); return (USBD_STATUS_PENDING); }
__inline VOID MP_FREE_SEND_PACKET( __in PFDO_DATA FdoData, __in PMP_TCB pMpTcb, __in NTSTATUS Status ) /*++ Routine Description: Recycle a MP_TCB and complete the packet if necessary Assumption: Send spinlock has been acquired Arguments: FdoData Pointer to our FdoData pMpTcb Pointer to MP_TCB Status Irp completion status Return Value: None --*/ { PIRP Irp; ASSERT(MP_TEST_FLAG(pMpTcb, fMP_TCB_IN_USE)); Irp = pMpTcb->Irp; pMpTcb->Irp = NULL; pMpTcb->Count = 0; MP_CLEAR_FLAGS(pMpTcb); FdoData->CurrSendHead = FdoData->CurrSendHead->Next; FdoData->nBusySend--; ASSERT(FdoData->nBusySend >= 0); if (Irp) { KeReleaseSpinLockFromDpcLevel(&FdoData->SendLock); NICCompleteSendRequest(FdoData, Irp, Status, pMpTcb->PacketLength, TRUE // Yes, we are calling at DISPATCH_LEVEL ); KeAcquireSpinLockAtDpcLevel(&FdoData->SendLock); } }
NTSTATUS tdi_event_chained_receive( IN PVOID TdiEventContext, IN CONNECTION_CONTEXT ConnectionContext, IN ULONG ReceiveFlags, IN ULONG ReceiveLength, IN ULONG StartingOffset, IN PMDL Tsdu, IN PVOID TsduDescriptor) { TDI_EVENT_CONTEXT *ctx = (TDI_EVENT_CONTEXT *)TdiEventContext; PFILE_OBJECT connobj = ot_find_conn_ctx(ctx->fileobj, ConnectionContext); NTSTATUS status; KdPrint(("[tdi_fw] tdi_event_chained_receive: addrobj 0x%x; connobj: 0x%x; %u; flags: 0x%x\n", ctx->fileobj, connobj, ReceiveLength, ReceiveFlags)); status = ((PTDI_IND_CHAINED_RECEIVE)(ctx->old_handler)) (ctx->old_context, ConnectionContext, ReceiveFlags,ReceiveLength , StartingOffset, Tsdu, TsduDescriptor); KdPrint(("[tdi_fw] tdi_event_chained_receive: status 0x%x\n", status)); if (status == STATUS_SUCCESS || status == STATUS_PENDING) { struct ot_entry *ote_conn; KIRQL irql; ote_conn = ot_find_fileobj(connobj, &irql); if (ote_conn != NULL) { ULONG bytes = ReceiveLength; ote_conn->bytes_in += bytes; // traffic stats KeAcquireSpinLockAtDpcLevel(&g_traffic_guard); g_traffic[TRAFFIC_TOTAL_IN] += bytes; if (ote_conn->log_disconnect) g_traffic[TRAFFIC_COUNTED_IN] += bytes; KeReleaseSpinLockFromDpcLevel(&g_traffic_guard); KeReleaseSpinLock(&g_ot_hash_guard, irql); } } return status; }
BOOLEAN compdev_post_event_select_driver(PUSB_DEV_MANAGER dev_mgr, DEV_HANDLE dev_handle) { PUSB_EVENT pevent; BOOLEAN bret; PUSB_DEV pdev; USE_BASIC_NON_PENDING_IRQL; if (dev_mgr == NULL || dev_handle == 0) return FALSE; if (usb_query_and_lock_dev(dev_mgr, dev_handle, &pdev) != STATUS_SUCCESS) return FALSE; KeAcquireSpinLockAtDpcLevel(&dev_mgr->event_list_lock); lock_dev(pdev, TRUE); if (dev_state(pdev) == USB_DEV_STATE_ZOMB) { bret = FALSE; goto LBL_OUT; } pevent = alloc_event(&dev_mgr->event_pool, 1); if (pevent == NULL) { bret = FALSE; goto LBL_OUT; } pevent->flags = USB_EVENT_FLAG_ACTIVE; pevent->event = USB_EVENT_DEFAULT; pevent->pdev = pdev; pevent->context = 0; pevent->param = 0; pevent->pnext = 0; //vertical queue for serialized operation pevent->process_event = compdev_event_select_if_driver; pevent->process_queue = event_list_default_process_queue; InsertTailList(&dev_mgr->event_list, &pevent->event_link); KeSetEvent(&dev_mgr->wake_up_event, 0, FALSE); // wake up the dev_mgr_thread bret = TRUE; LBL_OUT: unlock_dev(pdev, TRUE); KeReleaseSpinLockFromDpcLevel(&dev_mgr->event_list_lock); usb_unlock_dev(pdev); return bret; }
VOID NTAPI ExpTimerApcKernelRoutine(IN PKAPC Apc, IN OUT PKNORMAL_ROUTINE* NormalRoutine, IN OUT PVOID* NormalContext, IN OUT PVOID* SystemArgument1, IN OUT PVOID* SystemArguemnt2) { PETIMER Timer; KIRQL OldIrql; ULONG DerefsToDo = 1; PETHREAD Thread = PsGetCurrentThread(); /* We need to find out which Timer we are */ Timer = CONTAINING_RECORD(Apc, ETIMER, TimerApc); /* Lock the Timer */ KeAcquireSpinLock(&Timer->Lock, &OldIrql); /* Lock the Thread's Active Timer List*/ KeAcquireSpinLockAtDpcLevel(&Thread->ActiveTimerListLock); /* Make sure that the Timer is valid, and that it belongs to this thread */ if ((Timer->ApcAssociated) && (&Thread->Tcb == Timer->TimerApc.Thread)) { /* Check if it's not periodic */ if (!Timer->Period) { /* Remove it from the Active Timers List */ RemoveEntryList(&Timer->ActiveTimerListEntry); /* Disable it */ Timer->ApcAssociated = FALSE; DerefsToDo++; } } else { /* Clear the normal routine */ *NormalRoutine = NULL; } /* Release locks */ KeReleaseSpinLockFromDpcLevel(&Thread->ActiveTimerListLock); KeReleaseSpinLock(&Timer->Lock, OldIrql); /* Dereference as needed */ ObDereferenceObjectEx(Timer, DerefsToDo); }
ACPI_CPU_FLAGS AcpiOsAcquireLock( ACPI_SPINLOCK Handle) { KIRQL OldIrql; if ((OldIrql = KeGetCurrentIrql()) >= DISPATCH_LEVEL) { KeAcquireSpinLockAtDpcLevel((PKSPIN_LOCK)Handle); } else { KeAcquireSpinLock((PKSPIN_LOCK)Handle, &OldIrql); } return (ACPI_CPU_FLAGS)OldIrql; }
static int32_t usbd_func_bulkintr(irp *ip) { int32_t error; struct ndisusb_ep *ne; struct ndisusb_xfer *nx; struct usbd_urb_bulk_or_intr_transfer *ubi; union usbd_urb *urb; usb_endpoint_descriptor_t *ep; urb = usbd_geturb(ip); ubi = &urb->uu_bulkintr; ep = ubi->ubi_epdesc; if (ep == NULL) return (USBD_STATUS_INVALID_PIPE_HANDLE); ne = usbd_get_ndisep(ip, ep); if (ne == NULL) { device_printf(IRP_NDIS_DEV(ip), "get NULL endpoint info.\n"); return (USBD_STATUS_INVALID_PIPE_HANDLE); } nx = malloc(sizeof(struct ndisusb_xfer), M_USBDEV, M_NOWAIT | M_ZERO); if (nx == NULL) { device_printf(IRP_NDIS_DEV(ip), "out of memory\n"); return (USBD_STATUS_NO_MEMORY); } nx->nx_ep = ne; nx->nx_priv = ip; KeAcquireSpinLockAtDpcLevel(&ne->ne_lock); InsertTailList((&ne->ne_pending), (&nx->nx_next)); KeReleaseSpinLockFromDpcLevel(&ne->ne_lock); /* we've done to setup xfer. Let's transfer it. */ ip->irp_iostat.isb_status = STATUS_PENDING; ip->irp_iostat.isb_info = 0; USBD_URB_STATUS(urb) = USBD_STATUS_PENDING; IoMarkIrpPending(ip); error = usbd_taskadd(ip, NDISUSB_TASK_TSTART); if (error != USBD_STATUS_SUCCESS) return (error); return (USBD_STATUS_PENDING); }
VOID NICFreeQueuedSendPackets( __in PFDO_DATA FdoData ) /*++ Routine Description: Free and complete the pended sends on SendQueueHead Assumption: spinlock has been acquired Arguments: FdoData Pointer to our FdoData Return Value: None --*/ { PLIST_ENTRY pEntry; PIRP irp; NTSTATUS status = MP_GET_STATUS_FROM_FLAGS(FdoData); DebugPrint(TRACE, DBG_WRITE, "--> NICFreeQueuedSendPackets\n"); while (!IsListEmpty(&FdoData->SendQueueHead)) { pEntry = RemoveHeadList(&FdoData->SendQueueHead); FdoData->nWaitSend--; KeReleaseSpinLockFromDpcLevel(&FdoData->SendLock); ASSERT(pEntry); irp = CONTAINING_RECORD(pEntry, IRP, Tail.Overlay.ListEntry); NICCompleteSendRequest(FdoData, irp, status, 0, TRUE); KeAcquireSpinLockAtDpcLevel(&FdoData->SendLock); } DebugPrint(TRACE, DBG_WRITE, "<-- NICFreeQueuedSendPackets\n"); }
static struct ndisusb_xfer * usbd_aq_getfirst(struct ndis_softc *sc, struct ndisusb_ep *ne) { struct ndisusb_xfer *nx; KeAcquireSpinLockAtDpcLevel(&ne->ne_lock); if (IsListEmpty(&ne->ne_active)) { device_printf(sc->ndis_dev, "%s: the active queue can't be empty.\n", __func__); KeReleaseSpinLockFromDpcLevel(&ne->ne_lock); return (NULL); } nx = CONTAINING_RECORD(ne->ne_active.nle_flink, struct ndisusb_xfer, nx_next); RemoveEntryList(&nx->nx_next); KeReleaseSpinLockFromDpcLevel(&ne->ne_lock); return (nx); }
void complete_pending_irp(PPDO_DEVICE_DATA pdodata) { PIRP irp; struct urb_req * urb_r; PLIST_ENTRY le; KIRQL oldirql; int count=0; LARGE_INTEGER interval; //FIXME KdPrint(("finish pending irp\n")); KeRaiseIrql(DISPATCH_LEVEL, &oldirql); do { irp=NULL; le=NULL; KeAcquireSpinLockAtDpcLevel(&pdodata->q_lock); if (!IsListEmpty(&pdodata->ioctl_q)) le = RemoveHeadList(&pdodata->ioctl_q); if(le){ urb_r = CONTAINING_RECORD(le, struct urb_req, list); /* FIMXE event */ irp = urb_r->irp; } if(irp==NULL){ KeReleaseSpinLock(&pdodata->q_lock, oldirql); break; } if(count>2){ KeReleaseSpinLock(&pdodata->q_lock, oldirql); KdPrint(("sleep 50ms, let pnp manager send irp")); interval.QuadPart=-500000; KeDelayExecutionThread(KernelMode, FALSE, &interval); KeRaiseIrql(DISPATCH_LEVEL, &oldirql); } else { KeReleaseSpinLock(&pdodata->q_lock, DISPATCH_LEVEL); } ExFreeToNPagedLookasideList(&g_lookaside, urb_r); irp->IoStatus.Status = STATUS_DEVICE_NOT_CONNECTED; IoSetCancelRoutine(irp, NULL); IoCompleteRequest (irp, IO_NO_INCREMENT); count++; }while(1); }
static FORCEINLINE BOOLEAN __NotifierUnmask( IN PXENVIF_NOTIFIER Notifier ) { BOOLEAN Pending; KeAcquireSpinLockAtDpcLevel(&Notifier->Lock); Pending = (Notifier->Connected) ? EVTCHN(Unmask, Notifier->EvtchnInterface, Notifier->Evtchn, FALSE) : FALSE; KeReleaseSpinLockFromDpcLevel(&Notifier->Lock); return Pending; }
VOID Log(char *format, ...) { KIRQL CurrentIrql; unsigned short size; va_list args; UCHAR buffer[1024] = {0}; va_start(args, format); CurrentIrql = KeGetCurrentIrql(); if (CurrentIrql < DISPATCH_LEVEL) { KeRaiseIrqlToDpcLevel(); } KeAcquireSpinLockAtDpcLevel(g_LogLock); /* RtlZeroMemory(&buffer, sizeof(buffer));*/ /* vsnprintf((PUCHAR)&buffer, sizeof(buffer), "%d:", g_LogIndex);*/ /* buffer[1023] = '\0';*/ /* size = strlen(buffer);*/ /* InsertLogEntry(buffer, size);*/ /* */ RtlZeroMemory(&buffer, sizeof(buffer)); vsnprintf((PUCHAR)&buffer, sizeof(buffer), (PUCHAR)format, args); buffer[1023] = '\0'; size = strlen(buffer); InsertLogEntry(buffer, size); KeReleaseSpinLockFromDpcLevel(g_LogLock); if (CurrentIrql < DISPATCH_LEVEL) { KeLowerIrql(CurrentIrql); } }
/* * @implemented */ VOID EXPORT EthFilterDprIndicateReceiveComplete( IN PETH_FILTER Filter) /* * FUNCTION: Receive indication complete function for Ethernet devices * ARGUMENTS: * Filter = Pointer to Ethernet filter */ { PLIST_ENTRY CurrentEntry; PLOGICAL_ADAPTER Adapter; PADAPTER_BINDING AdapterBinding; NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n")); if( !Filter ) { NDIS_DbgPrint(MIN_TRACE, ("Filter is NULL\n")); return; } Adapter = (PLOGICAL_ADAPTER)((PETHI_FILTER)Filter)->Miniport; NDIS_DbgPrint(MAX_TRACE, ("acquiring miniport block lock\n")); KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock); { CurrentEntry = Adapter->ProtocolListHead.Flink; while (CurrentEntry != &Adapter->ProtocolListHead) { AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry); (*AdapterBinding->ProtocolBinding->Chars.ReceiveCompleteHandler)( AdapterBinding->NdisOpenBlock.ProtocolBindingContext); CurrentEntry = CurrentEntry->Flink; } } KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock); }