Example #1
0
VOID
DeleteHandleTable(PPROVIDER_HANDLE_BLOCK HandleTable)
{
    PPROVIDER_HANDLE_BLOCK Current;
    PLIST_ENTRY CurrentEntry;

    CloseAllHandles(HandleTable);

    CurrentEntry = RemoveHeadList(&HandleTable->Entry);

    while (CurrentEntry != &HandleTable->Entry)
    {
        Current = CONTAINING_RECORD(CurrentEntry,
                                    PROVIDER_HANDLE_BLOCK,
                                    Entry);

        HeapFree(GlobalHeap, 0, Current);

        CurrentEntry = RemoveHeadList(&HandleTable->Entry);
    }
}
Example #2
0
static VOID
Pkt0FinalizeIrpQueue(PLIST_ENTRY IrpQueue)
{
    PLIST_ENTRY entry;
    PIRP irp;

    while (!IsListEmpty(IrpQueue)) {
        entry = RemoveHeadList(IrpQueue);
        irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.ListEntry);
        Pkt0CompleteIrp(irp, STATUS_PIPE_CLOSING, 0);
    }
}
Example #3
0
/*
  Cancel routine for queued read operations initiated by user-mode daemons.
*/
void 
ssh_interceptor_iodevice_cancel_queued_read(PDEVICE_OBJECT device,
                                            PIRP irp)
{
  SshInterceptorIoDevice io_dev;
  PLIST_ENTRY entry, next_entry;
  LIST_ENTRY  cancelled_irps;

  /* Cancel processing is protected by queue-specific lock, not by the (one 
     and only) system-wide Cancel lock */
  IoReleaseCancelSpinLock(irp->CancelIrql);

  io_dev = SSH_NTDEV_TO_SSHDEV(device);

  NdisInitializeListHead(&cancelled_irps);

  SSH_DEBUG(SSH_D_MIDSTART, 
            ("ssh_interceptor_iodevice_cancel_queued_read()"));

  /* Find and dequeue all canceled IRPs (not just the one given as argument).
     Complete the IRPs after releasing the spin lock. */
  NdisAcquireSpinLock(&io_dev->read_queue_lock);
  entry = io_dev->read_queue.Flink;
  while (entry && (entry != &io_dev->read_queue))
    {
      next_entry = entry->Flink;

      irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.ListEntry);
      if (irp->Cancel)
        {
          RemoveEntryList(entry);
          InsertTailList(&cancelled_irps, entry);
        }

      entry = next_entry;
    }
  NdisReleaseSpinLock(&io_dev->read_queue_lock);

  while (!IsListEmpty(&cancelled_irps))
    {
      entry = RemoveHeadList(&cancelled_irps);

      irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.ListEntry);

      irp->IoStatus.Status = STATUS_CANCELLED;
      irp->IoStatus.Information = 0;
      IoCompleteRequest(irp, IO_NO_INCREMENT);

      SSH_DEBUG(SSH_D_NICETOKNOW,
                ("IoCompleteRequest(irp = 0x%p, status = STATUS_CANCELLED)",
                irp));
    };
}
Example #4
0
void AdapterStop() {
    PLIST_ENTRY ListEntry;
    PDHCP_ADAPTER Adapter;
    ApiLock();
    while( !IsListEmpty( &AdapterList ) ) {
        ListEntry = (PLIST_ENTRY)RemoveHeadList( &AdapterList );
        Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
        free( Adapter );
    }
    ApiUnlock();
    WSACleanup();
}
Example #5
0
__inline SshDeviceBuffer
ssh_iodevice_buffer_alloc(SshInterceptorIoDevice io_dev,
                          Boolean reliable)
{
  SshDeviceBuffer buf = NULL;
  PLIST_ENTRY entry;

  /* 1. Try to get a SshDeviceBuffer from a free list */
  entry = NdisInterlockedRemoveHeadList(&io_dev->free_list,
                                        &io_dev->free_list_lock);
  if (entry)
    buf = CONTAINING_RECORD(entry, SshDeviceBufferStruct, link);

  /* 2. If failed and this is a reliable message, try to replace
     an existing unreliable one */
  if ((buf == NULL) && (reliable))
    {
      NdisAcquireSpinLock(&io_dev->output_queue_lock);
      if (!IsListEmpty(&io_dev->unreliable_output_queue))
        {
          /* We found an existing unreliable message */
          entry = RemoveHeadList(&io_dev->unreliable_output_queue);

          /* We must remove the entry from output_queue too */
          buf = CONTAINING_RECORD(entry, SshDeviceBufferStruct,
                                  unreliable_list_link);

          SSH_ASSERT(buf != io_dev->current_read_buf);

          /* This removes the entry from output_queue */
          RemoveEntryList(&(buf->link));
        }
      NdisReleaseSpinLock(&io_dev->output_queue_lock);

      /* If found, we must delete the old message */
      if (buf != NULL)
        ssh_free(buf->addr);
    }

  /* 3. If still failed, try to allocate memory for a new
     SshDeviceBuffer */
  if ((buf == NULL) && (reliable))
    {
      buf = ssh_malloc(sizeof(*buf));
      if (buf)
        {
          /* This buffer will be deleted after use */
          buf->pre_allocated = 0;
        }
    }

  return buf;
}
Example #6
0
NDIS_STATUS NDIS_API PacketReceiveIndicate(IN NDIS_HANDLE ProtocolBindingContext,
                                           IN NDIS_HANDLE MacReceiveContext,
                                           IN PVOID       HeaderBuffer,
                                           IN UINT        HeaderBufferSize,
                                           IN PVOID       LookaheadBuffer,
                                           IN UINT        LookaheadBufferSize,
                                           IN UINT        PacketSize)
{
  // upcall on packet arrival

  POPEN_INSTANCE      Open;
  PLIST_ENTRY         PacketListEntry;
  PNDIS_PACKET        pPacket;
  NDIS_STATUS         Status;
  UINT                BytesTransfered = 0;
  PPACKET_RESERVED    pReserved;


  if (HeaderBufferSize != ETHERNET_HEADER_LENGTH)
    return NDIS_STATUS_NOT_ACCEPTED;
  
  Open = (POPEN_INSTANCE) ProtocolBindingContext;
  
  //  See if there are any pending reads that we can satisfy
  NdisAcquireSpinLock(&Open->RcvQSpinLock); // fixed 5.11.97
  
  if (IsListEmpty(&Open->RcvList)) { 
    NdisReleaseSpinLock(&Open->RcvQSpinLock);
    return NDIS_STATUS_NOT_ACCEPTED;
  }

  PacketListEntry = RemoveHeadList(&Open->RcvList);
  NdisReleaseSpinLock(&Open->RcvQSpinLock);
  
  pReserved = CONTAINING_RECORD(PacketListEntry, PACKET_RESERVED, ListElement);
  pPacket = CONTAINING_RECORD(pReserved, NDIS_PACKET, ProtocolReserved);
  
  // Copy the MAC header
  NdisMoveMemory(RESERVED(pPacket)->lpBuffer, HeaderBuffer, HeaderBufferSize);

  //  Call the Mac to transfer the data portion of the packet
  NdisTransferData(&Status, Open->AdapterHandle, MacReceiveContext, 0, PacketSize, pPacket, &BytesTransfered);
  if (Status == NDIS_STATUS_PENDING)
    return NDIS_STATUS_PENDING;

  if (Status == NDIS_STATUS_SUCCESS) {
    PacketTransferDataComplete(Open, pPacket, Status, BytesTransfered);
    return NDIS_STATUS_SUCCESS;
  }

  PacketTransferDataComplete(Open, pPacket, Status, 0);
  return NDIS_STATUS_SUCCESS;
}
//
// Dynamic heaps are conceptually the same concept as dynamic buffers, but for descriptors
// instead of buffer data.
//
HRESULT DX12Framework::AllocateVersionedDescriptorHeap(DescriptorHeap** ppHeap)
{
    //
    // Grab a heap from our lookaside list if possible.
    //
    if (!IsListEmpty(&m_DynamicDescriptorHeapListHead))
    {
        LIST_ENTRY* pEntry = RemoveHeadList(&m_DynamicDescriptorHeapListHead);
        *ppHeap = static_cast<DescriptorHeap*>(pEntry);
        return S_OK;
    }

    //
    // No available buffers, let's try to allocate a new one.
    //
    HRESULT hr;
    ID3D12DescriptorHeap* pD3DDescriptorHeap = nullptr;

    D3D12_DESCRIPTOR_HEAP_DESC Desc = {};
    Desc.NumDescriptors = DYNAMIC_HEAP_SIZE;
    Desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
    Desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;

    hr = m_pDevice->CreateDescriptorHeap(&Desc, IID_PPV_ARGS(&pD3DDescriptorHeap));
    if (FAILED(hr))
    {
        LOG_WARNING("Failed to create D3D12 descriptor heap, hr=0x%.8x", hr);
        goto cleanup;
    }

    DescriptorHeap* pHeap = nullptr;
    try
    {
        pHeap = new DescriptorHeap();
    }
    catch (std::bad_alloc&)
    {
        LOG_WARNING("Failed to allocate dynamic descriptor heap");
        hr = E_OUTOFMEMORY;
        goto cleanup;
    }

    pHeap->pHeap = pD3DDescriptorHeap;

    *ppHeap = pHeap;

    return S_OK;

cleanup:
    SafeRelease(pD3DDescriptorHeap);
    return hr;
}
Example #8
0
PLIST_ENTRY
IopErrorLogGetEntry(
    )

/*++

Routine Description:

    This routine gets the next entry from the head of the error log queue
    and returns it to the caller.

Arguments:

    None.

Return Value:

    The return value is a pointer to the packet removed, or NULL if there were
    no packets on the queue.

--*/

{
    KIRQL irql;
    PLIST_ENTRY listEntry;

    //
    // Remove the next packet from the queue, if there is one.
    //

    ExAcquireSpinLock( &IopErrorLogLock, &irql );
    if (IsListEmpty( &IopErrorLogListHead )) {

        //
        // Indicate no more work will be done in the context of this worker
        // thread and indicate to the caller that no packets were located.
        //

        IopErrorLogPortPending = FALSE;
        listEntry = (PLIST_ENTRY) NULL;
    } else {

        //
        // Remove the next packet from the head of the list.
        //

        listEntry = RemoveHeadList( &IopErrorLogListHead );
    }

    ExReleaseSpinLock( &IopErrorLogLock, irql );
    return listEntry;
}
Example #9
0
PQUEUE_ENTRY LibTCPDequeuePacket(PCONNECTION_ENDPOINT Connection)
{
    PLIST_ENTRY Entry;
    PQUEUE_ENTRY qp = NULL;

    if (IsListEmpty(&Connection->PacketQueue)) return NULL;

    Entry = RemoveHeadList(&Connection->PacketQueue);

    qp = CONTAINING_RECORD(Entry, QUEUE_ENTRY, ListEntry);

    return qp;
}
Example #10
0
VOID FASTCALL
HistoryDeleteBuffers(PCONSOLE Console)
{
    PLIST_ENTRY CurrentEntry;
    PHISTORY_BUFFER HistoryBuffer;

    while (!IsListEmpty(&Console->HistoryBuffers))
    {
        CurrentEntry = RemoveHeadList(&Console->HistoryBuffers);
        HistoryBuffer = CONTAINING_RECORD(CurrentEntry, HISTORY_BUFFER, ListEntry);
        HistoryDeleteBuffer(HistoryBuffer);
    }
}
Example #11
0
File: device.c Project: iXit/wine
static void HID_Device_processQueue(DEVICE_OBJECT *device)
{
    LIST_ENTRY *entry;
    IRP *irp;
    BASE_DEVICE_EXTENSION *ext = device->DeviceExtension;
    UINT buffer_size = RingBuffer_GetBufferSize(ext->ring_buffer);
    HID_XFER_PACKET *packet;

    packet = HeapAlloc(GetProcessHeap(), 0, buffer_size);

    entry = RemoveHeadList(&ext->irp_queue);
    while(entry != &ext->irp_queue)
    {
        int ptr;
        irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.s.ListEntry);
        ptr = PtrToUlong( irp->Tail.Overlay.OriginalFileObject->FsContext );

        RingBuffer_Read(ext->ring_buffer, ptr, packet, &buffer_size);
        if (buffer_size)
        {
            NTSTATUS rc;
            ULONG out_length;
            IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
            packet->reportBuffer = (BYTE *)packet + sizeof(*packet);
            TRACE_(hid_report)("Processing Request (%i)\n",ptr);
            rc = copy_packet_into_buffer(packet, irp->AssociatedIrp.SystemBuffer, irpsp->Parameters.Read.Length, &out_length);
            irp->IoStatus.u.Status = rc;
            irp->IoStatus.Information = out_length;
        }
        else
        {
            irp->IoStatus.Information = 0;
            irp->IoStatus.u.Status = STATUS_UNSUCCESSFUL;
        }
        IoCompleteRequest( irp, IO_NO_INCREMENT );
        entry = RemoveHeadList(&ext->irp_queue);
    }
    HeapFree(GetProcessHeap(), 0, packet);
}
void CParaNdisRX::FreeRxDescriptorsFromList()
{
    while (!IsListEmpty(&m_NetReceiveBuffers))
    {
        pRxNetDescriptor pBufferDescriptor = (pRxNetDescriptor)RemoveHeadList(&m_NetReceiveBuffers);
        ParaNdis_FreeRxBufferDescriptor(m_Context, pBufferDescriptor);
    }
    for (UINT i = 0; i < ARRAYSIZE(m_ReservedRxBufferMemory); i++) {
        if (m_ReservedRxBufferMemory[i].Virtual) {
            ParaNdis_FreePhysicalMemory(m_Context, &m_ReservedRxBufferMemory[i]);
        }
    }
}
Example #13
0
// 清空监控目录
NTSTATUS FilemonCleanGuardPath(PIO_STACK_LOCATION pStack, PIRP pIrp)
{
	KIRQL			irql;
	PLIST_ENTRY		pList		= NULL;
	
	KeAcquireSpinLock(&FltData.spinkLock, &irql);
	while(&FltData.listGuard != (pList = RemoveHeadList(&FltData.listGuard)))
	{
		PFILEMON_GUARD		pGuardPath		= NULL;
	}
	KeReleaseSpinLock(&FltData.spinkLock, irql);
	return STATUS_SUCCESS;
}
VOID SignalLatch (PCountDownLatch CountDownLatch) {
	// decrementa o contador interno, desbloqueando todas as threads em espera se este chegar a zero

	if (CountDownLatch->counter == 0) {
	}

	CountDownLatch->counter--;
	if (CountDownLatch->counter == 0) {
		while (!IsListEmpty(&CountDownLatch->Waiters)) {
			PWAIT_BLOCK WaitBlockPtr = CONTAINING_RECORD(RemoveHeadList(&CountDownLatch->Waiters), WAIT_BLOCK, Link);
			UtActivate(WaitBlockPtr->Thread);
		}
	}
}
VOID CleanupReads( PDEVICE_EXTENSION pdx, PFILE_OBJECT pfo, NTSTATUS status )
{
    PIO_STACK_LOCATION ReadStack;
    PLIST_ENTRY        head, next, current;
    LIST_ENTRY         CancelList;
    PIRP               ReadIrp;
    KIRQL              OldIrql;
    
    // manually cancel all pending reads that match this file handle
    InitializeListHead( &CancelList );

    KeAcquireSpinLock (&pdx->ReadIrpLock, &OldIrql );

    head = &pdx->ReadIrpList;

    for( next=head->Flink; next != head; )
    {
        ReadIrp   = CONTAINING_RECORD( next, IRP, Tail.Overlay.ListEntry );
        ReadStack = IoGetCurrentIrpStackLocation( ReadIrp );

        // advance next pointer now, as we want to muck with it
        current = next;
        next    = next->Flink;

        // skip IRPs that do not match
        // if pfo == NULL, then don't skip anything
        if(pfo && pfo != ReadStack->FileObject )
        {
            KdPrint((DRIVERNAME " - Skipping IRP, it belongs to a different handle\n"));
            continue;
        }

        // add it to the cancel list 
        RemoveEntryList( current              );
        InsertTailList ( &CancelList, current );
    }

    KeReleaseSpinLock( &pdx->ReadIrpLock, OldIrql );

    // now complete the IRPs we cancelled 
    while (!IsListEmpty(&CancelList))
    {
        next    = RemoveHeadList( &CancelList );
        ReadIrp = CONTAINING_RECORD(next, IRP, Tail.Overlay.ListEntry);
        
        IoSetCancelRoutine ( ReadIrp, NULL             );
        IoReleaseRemoveLock( &pdx->RemoveLock, ReadIrp );
        CompleteRequest    ( ReadIrp, status, 0        );
    }
}
Example #16
0
static VOID
VenetFreeTx(PADAPTER a)
{
    LIST_ENTRY 	*e;
    PTCB		t;

    /* Free list */
    while(!IsListEmpty(&a->tcbFree)) {
        e = RemoveHeadList(&a->tcbFree);
        t = CONTAINING_RECORD(e, TCB, list);
        VenetFree(t, sizeof(ADAPTER));
    }

    /* Busy list.  Sanity check, should be empty */
    while(!IsListEmpty(&a->tcbBusy)) {
        e = RemoveHeadList(&a->tcbBusy);
        t = CONTAINING_RECORD(e, TCB, list);
        VenetFree(t, sizeof(ADAPTER));
    }

    a->vif.destroy(a->txHandle);
    a->txHandle = NULL;
}
Example #17
0
void BleServiceDbUnloadRecord(void)
{
    if (BleDbCtx(loadCount) == 1)
    {
        BT_GattUnregisterConnectedEvent(&BleDbCtx(gattHandler));
        ATTDB_UnRegisterBondStatus(&BleDbCtx(bondingHandler));

        while (!IsListEmpty(&BleDbCtx(servicedbList)))
        {
            free_ctrl_buffer(RemoveHeadList(&BleDbCtx(servicedbList)));
        }
    }
    BleDbCtx(loadCount)--;
}
Example #18
0
void free_lastundo(GEM_WINDOW *gwnd)
{
  UNDO_DEF   *undo ;
  VXIMAGE    *vimage ;
  LIST_ENTRY *entry ;

  if ( !GWIsWindowValid( gwnd ) ) return ;
  vimage = (VXIMAGE *) gwnd->Extension ;
  if ( IsListEmpty( &vimage->UndoListHead ) ) return ;

  entry  = RemoveHeadList( &vimage->UndoListHead ) ;
  undo   = GET_UNDO_DEF_FROM_LIST_ENTRY( entry ) ;
  FreeUndoBuffer( undo ) ;
}
Example #19
0
PIRP
USBSTOR_RemoveIrp(
    IN PDEVICE_OBJECT DeviceObject)
{
    KIRQL OldLevel;
    PFDO_DEVICE_EXTENSION FDODeviceExtension;
    PLIST_ENTRY Entry;
    PIRP Irp = NULL;

    //
    // get FDO device extension
    //
    FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    //
    // sanity check
    //
    ASSERT(FDODeviceExtension->Common.IsFDO);

    //
    // acquire lock
    //
    KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel);

    //
    // check if list is empty
    //
    if (!IsListEmpty(&FDODeviceExtension->IrpListHead))
    {
        //
        // remove entry
        //
        Entry = RemoveHeadList(&FDODeviceExtension->IrpListHead);

        //
        // get offset to start of irp
        //
        Irp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
    }

    //
    // release list lock
    //
    KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel);

    //
    // return result
    //
    return Irp;
}
Example #20
0
NTSTATUS NTAPI ReceiveComplete
( PDEVICE_OBJECT DeviceObject,
  PIRP Irp,
  PVOID Context ) {
    PAFD_FCB FCB = (PAFD_FCB)Context;
    PLIST_ENTRY NextIrpEntry;
    PIRP NextIrp;
    PAFD_RECV_INFO RecvReq;
    PIO_STACK_LOCATION NextIrpSp;

    UNREFERENCED_PARAMETER(DeviceObject);

    AFD_DbgPrint(MID_TRACE,("Called\n"));

    if( !SocketAcquireStateLock( FCB ) )
        return STATUS_FILE_CLOSED;

    ASSERT(FCB->ReceiveIrp.InFlightRequest == Irp);
    FCB->ReceiveIrp.InFlightRequest = NULL;

    if( FCB->State == SOCKET_STATE_CLOSED ) {
        /* Cleanup our IRP queue because the FCB is being destroyed */
        while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
            NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
            NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
            NextIrpSp = IoGetCurrentIrpStackLocation(NextIrp);
            RecvReq = GetLockedData(NextIrp, NextIrpSp);
            NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
            NextIrp->IoStatus.Information = 0;
            UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
            if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
            (void)IoSetCancelRoutine(NextIrp, NULL);
            IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
        }
        SocketStateUnlock( FCB );
        return STATUS_FILE_CLOSED;
    } else if( FCB->State == SOCKET_STATE_LISTENING ) {
        AFD_DbgPrint(MIN_TRACE,("!!! LISTENER GOT A RECEIVE COMPLETE !!!\n"));
        SocketStateUnlock( FCB );
        return STATUS_INVALID_PARAMETER;
    }

    HandleReceiveComplete( FCB, Irp->IoStatus.Status, Irp->IoStatus.Information );

    ReceiveActivity( FCB, NULL );

    SocketStateUnlock( FCB );

    return STATUS_SUCCESS;
}
Example #21
0
ULONG
ApsFlushLogQueue(
	VOID
	)
{
	PLIST_ENTRY ListEntry;
	PAPS_LOG_ENTRY LogEntry;
	ULONG IsLogging;
	ULONG Length;
	ULONG Complete;
	ULONG Count = 0;
	CHAR Buffer[APS_PAGESIZE];

	IsLogging = InterlockedCompareExchange(&ApsLogObject.Flag, 0, 0);
	if (!IsLogging) {
		return 0;
	}

	EnterCriticalSection(&ApsLogObject.Lock);

	if (IsListEmpty(&ApsLogObject.ListHead)) {
		LeaveCriticalSection(&ApsLogObject.Lock);
		return 0;
	}

	//
	// Hand over queued log entries to QueueListHead
	//

	while (IsListEmpty(&ApsLogObject.ListHead) != TRUE) {

		ListEntry = RemoveHeadList(&ApsLogObject.ListHead);
		LogEntry = CONTAINING_RECORD(ListEntry, APS_LOG_ENTRY, ListEntry);

		StringCchPrintfA(Buffer, APS_PAGESIZE, "\r\n%02d:%02d:%02d:%03d %04x %s %s", 
			    LogEntry->TimeStamp.wHour, LogEntry->TimeStamp.wMinute, 
				LogEntry->TimeStamp.wSecond, LogEntry->TimeStamp.wMilliseconds, 
				LogEntry->ProcessId, LogLevelString[LogEntry->Level], LogEntry->Text); 

		Length = (ULONG)strlen(Buffer);
		WriteFile(ApsLogObject.FileObject, Buffer, Length, &Complete, NULL);
		ApsFree(LogEntry);

		Count += 1;
	}

	ApsLogObject.ListDepth = 0;
	LeaveCriticalSection(&ApsLogObject.Lock);
	return Count;
}
Example #22
0
__declspec(dllexport) BOOL WINAPI 
QSI_Close(DWORD open_context) 
{
  SshInterceptorIoDevice io_dev = (SshInterceptorIoDevice)open_context;

  /* Validate the context. */
  if (io_dev != the_interceptor->ipm_device)
    return FALSE;
		
  /* Decrement the reference count as appropriate. */
  if (InterlockedDecrement(&io_dev->stream_interface_refcount) == 0) 
    {
      /* Indicate that the device is now closed. */
      NdisAcquireSpinLock(&io_dev->output_queue_lock);
      io_dev->open = 0;
      io_dev->cancel_io = 0;
      NdisReleaseSpinLock(&io_dev->output_queue_lock);

      /* Uninitialize the packetizer object */
      ssh_interceptor_pktizer_uninit(&io_dev->pktizer);

      /* Indicate the close status. */
      if (io_dev->status_cb) 
        io_dev->status_cb(FALSE, io_dev->cb_context);
	
      /* Free any buffers in the output queue. */
      while (!IsListEmpty(&io_dev->output_queue)) 
        {
          SshDeviceBuffer buf;
          PLIST_ENTRY entry;

          entry = RemoveHeadList(&io_dev->output_queue);
          buf = CONTAINING_RECORD(entry, SshDeviceBufferStruct, link);
          ssh_iodevice_buffer_free(io_dev, buf);
        };

      if (io_dev->current_read_buf)
        {
          ssh_iodevice_buffer_free(io_dev, io_dev->current_read_buf);
          io_dev->current_read_buf = NULL;
        }
    }
  else
    {
      SSH_NOTREACHED;
    }

  return TRUE;
}
Example #23
0
ULONG CALLBACK
MspLogProcedure(
	IN PVOID Context
	)
{
	PLIST_ENTRY ListEntry;
	PMSP_LOG_ENTRY LogEntry;
	ULONG IsLogging;
	ULONG Length;
	PCHAR Buffer;
	ULONG Complete;

	IsLogging = InterlockedCompareExchange(&MspLogObject.Flag, 0, 0);
	if (!IsLogging) {
		return 0;
	}

	EnterCriticalSection(&MspLogObject.Lock);

	if (IsListEmpty(&MspLogObject.ListHead)) {
		LeaveCriticalSection(&MspLogObject.Lock);
		return 0;
	}

	//
	// Hand over queued log entries to QueueListHead
	//

	Buffer = _alloca(4096);

	while (IsListEmpty(&MspLogObject.ListHead) != TRUE) {

		ListEntry = RemoveHeadList(&MspLogObject.ListHead);
		LogEntry = CONTAINING_RECORD(ListEntry, MSP_LOG_ENTRY, ListEntry);

		StringCchPrintfA(Buffer, 4096, "\r\n%02d:%02d:%02d:%03d %04x %s %s", 
			    LogEntry->TimeStamp.wHour, LogEntry->TimeStamp.wMinute, 
				LogEntry->TimeStamp.wSecond, LogEntry->TimeStamp.wMilliseconds, 
				LogEntry->ProcessId, LogLevelString[LogEntry->Level], LogEntry->Text); 

		Length = (ULONG) strlen(Buffer);
		WriteFile(MspLogObject.FileObject, Buffer, Length, &Complete, NULL);
		MspFree(LogEntry);
	}

	MspLogObject.ListDepth = 0;
	LeaveCriticalSection(&MspLogObject.Lock);
	return 0;
}
Example #24
0
static NTSTATUS
LsapDeregisterLogonProcess(PLSA_API_MSG RequestMsg,
                           PLSAP_LOGON_CONTEXT LogonContext)
{
    TRACE("LsapDeregisterLogonProcess(%p %p)\n", RequestMsg, LogonContext);

    RemoveHeadList(&LogonContext->Entry);

    NtClose(LogonContext->ClientProcessHandle);
    NtClose(LogonContext->ConnectionHandle);

    RtlFreeHeap(RtlGetProcessHeap(), 0, LogonContext);

    return STATUS_SUCCESS;
}
Example #25
0
FmpPacket *FmpGetPacket(FmpChannel *channel)
{
    FmpPacket *pkt = NULL;

    if (!IsListEmpty(&channel->packet_pool))
    {
        pkt = (FmpPacket *)RemoveHeadList(&channel->packet_pool);
    }
    else
    {
        kal_trace(BT_TRACE_BLE_PROFILES, FMP_PACKETPOOL_EMPTY);
    }
    Report(("[FMP] get packet: %x"));
    return pkt;
}
void CParaNdisRX::PopulateQueue()
{
    LIST_ENTRY TempList;
    CLockedContext<CNdisSpinLock> autoLock(m_Lock);


    InitializeListHead(&TempList);

    while (!IsListEmpty(&m_NetReceiveBuffers))
    {
        pRxNetDescriptor pBufferDescriptor =
            (pRxNetDescriptor)RemoveHeadList(&m_NetReceiveBuffers);
        InsertTailList(&TempList, &pBufferDescriptor->listEntry);
    }
    m_NetNofReceiveBuffers = 0;
    while (!IsListEmpty(&TempList))
    {
        pRxNetDescriptor pBufferDescriptor =
            (pRxNetDescriptor)RemoveHeadList(&TempList);
        if (AddRxBufferToQueue(pBufferDescriptor))
        {
            InsertTailList(&m_NetReceiveBuffers, &pBufferDescriptor->listEntry);
            m_NetNofReceiveBuffers++;
        }
        else
        {
            /* TODO - NetMaxReceiveBuffers should take into account all queues */
            DPrintf(0, ("FAILED TO REUSE THE BUFFER!!!!\n"));
            ParaNdis_FreeRxBufferDescriptor(m_Context, pBufferDescriptor);
            m_Context->NetMaxReceiveBuffers--;
        }
    }
    m_Reinsert = true;

    m_VirtQueue.Kick();
}
Example #27
0
VOID
	EventLogFlush(PEVENT_LOG EventLog)
{
	KIRQL Irql;
	PLIST_ENTRY ListEntry = NULL;
	PSREQUEST request = NULL;
	LIST_ENTRY FreeListHead;

	InitializeListHead(&FreeListHead);

	KeAcquireSpinLock(&EventLog->EventListLock, &Irql);
	while (!IsListEmpty(&EventLog->EventListHead)) {
		ListEntry = RemoveHeadList(&EventLog->EventListHead);
		request = CONTAINING_RECORD(ListEntry, SREQUEST, ListEntry);
		InsertHeadList(&FreeListHead, &request->ListEntry);
	}
	KeReleaseSpinLock(&EventLog->EventListLock, Irql);

	while (!IsListEmpty(&FreeListHead)) {
		ListEntry = RemoveHeadList(&FreeListHead);
		request = CONTAINING_RECORD(ListEntry, SREQUEST, ListEntry);
		SRequestDelete(request);
	}
}
Example #28
0
VOID FASTCALL
PurgeInputBuffer(PCONSOLE Console)
{
    PLIST_ENTRY CurrentEntry;
    ConsoleInput* Event;

    while (!IsListEmpty(&Console->InputBuffer.InputEvents))
    {
        CurrentEntry = RemoveHeadList(&Console->InputBuffer.InputEvents);
        Event = CONTAINING_RECORD(CurrentEntry, ConsoleInput, ListEntry);
        ConsoleFreeHeap(Event);
    }

    CloseHandle(Console->InputBuffer.ActiveEvent);
}
Example #29
0
void SoraKReleaseTXLock(PQUEUED_RW_LOCK RWLock)
{
    KIRQL Irq;

    KeAcquireSpinLock(&RWLock->Lock, &Irq);
    if (RWLock->RWSummary == -1)
    {
        RWLock->RWSummary = 0;

        while(!IsListEmpty(&RWLock->WaitingList))
        {
            PLIST_ENTRY entry = RemoveHeadList(&RWLock->WaitingList);
            InitializeListHead(entry); 
            PRW_REQ req = CONTAINING_RECORD(entry, RW_REQ, __List);
            if (req->Type == WrReq)
            {
                if (RWLock->RWSummary == 0)
                {
                    DbgPrint("[UExtK]SoraKReleaseTXLock: wake up TX\n");
                    req->LockObtained = TRUE;
                    RWLock->RWSummary = -1;
                    break;
                }
                else
                {
                    InsertHeadList(&RWLock->WaitingList, entry); //push back
                    break;
                }
            }
            else //read
            {
                if (RWLock->RWSummary >= 0)
                {
                    req->LockObtained = TRUE;
                    DbgPrint("[UExtK]SoraKReleaseTXLock: wake up RX\n");
                    RWLock->RWSummary++;
                }
                else
                {
                    InsertHeadList(&RWLock->WaitingList, entry); //push back
                    break;
                }
            }   
        }
    }
    KeReleaseSpinLock(&RWLock->Lock, Irq);
    DbgPrint("[UExtK] SoraKReleaseTXLock: RW Summary %d\n", RWLock->RWSummary);
}
Example #30
0
NTSTATUS
NTAPI
MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
{
   PMM_ALLOCATION_REQUEST Request;
   PLIST_ENTRY Entry;
   KIRQL OldIrql;

   if (Page == 0)
   {
      DPRINT1("Tried to release page zero.\n");
      KeBugCheck(MEMORY_MANAGEMENT);
   }

   KeAcquireSpinLock(&AllocationListLock, &OldIrql);
   if (MmGetReferenceCountPage(Page) == 1)
   {
      (void)InterlockedDecrementUL(&MiMemoryConsumers[Consumer].PagesUsed);
      if (IsListEmpty(&AllocationListHead) || MmAvailablePages < MiMinimumAvailablePages)
      {
         KeReleaseSpinLock(&AllocationListLock, OldIrql);
         if(Consumer == MC_USER) MmRemoveLRUUserPage(Page);
         OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
         MmDereferencePage(Page);
         KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
      }
      else
      {
         Entry = RemoveHeadList(&AllocationListHead);
         Request = CONTAINING_RECORD(Entry, MM_ALLOCATION_REQUEST, ListEntry);
         KeReleaseSpinLock(&AllocationListLock, OldIrql);
         if(Consumer == MC_USER) MmRemoveLRUUserPage(Page);
         MiZeroPhysicalPage(Page);
         Request->Page = Page;
         KeSetEvent(&Request->Event, IO_NO_INCREMENT, FALSE);
      }
   }
   else
   {
      KeReleaseSpinLock(&AllocationListLock, OldIrql);
      if(Consumer == MC_USER) MmRemoveLRUUserPage(Page);
      OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
      MmDereferencePage(Page);
      KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
   }

   return(STATUS_SUCCESS);
}