Пример #1
0
err_t
LibTCPShutdown(PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
{
    struct lwip_callback_msg *msg;
    err_t ret;

    msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
    if (msg)
    {
        KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);

        msg->Input.Shutdown.Connection = Connection;
        msg->Input.Shutdown.shut_rx = shut_rx;
        msg->Input.Shutdown.shut_tx = shut_tx;

        tcpip_callback_with_block(LibTCPShutdownCallback, msg, 1);

        if (WaitForEventSafely(&msg->Event))
            ret = msg->Output.Shutdown.Error;
        else
            ret = ERR_CLSD;

        ExFreeToNPagedLookasideList(&MessageLookasideList, msg);

        return ret;
    }

    return ERR_MEM;
}
Пример #2
0
/* KphProtectAddEntry
 * 
 * Protects the specified process.
 * 
 * Thread safety: Full
 * IRQL: <= DISPATCH_LEVEL
 */
PKPH_PROCESS_ENTRY KphProtectAddEntry(
    __in PEPROCESS Process,
    __in HANDLE Tag,
    __in LOGICAL AllowKernelMode,
    __in ACCESS_MASK ProcessAllowMask,
    __in ACCESS_MASK ThreadAllowMask
    )
{
    KIRQL oldIrql;
    PKPH_PROCESS_ENTRY entry;
    
    /* Prevent the lookaside list from being freed. */
    if (!ExAcquireRundownProtection(&ProtectedProcessRundownProtect))
        return NULL;
    
    entry = ExAllocateFromNPagedLookasideList(&ProtectedProcessLookasideList);
    /* Lookaside list no longer needed. */
    ExReleaseRundownProtection(&ProtectedProcessRundownProtect);
    
    if (!entry)
        return NULL;
    
    entry->Process = Process;
    entry->CreatorProcess = PsGetCurrentProcess();
    entry->Tag = Tag;
    entry->AllowKernelMode = AllowKernelMode;
    entry->ProcessAllowMask = ProcessAllowMask;
    entry->ThreadAllowMask = ThreadAllowMask;
    
    KeAcquireSpinLock(&ProtectedProcessListLock, &oldIrql);
    InsertHeadList(&ProtectedProcessListHead, &entry->ListEntry);
    KeReleaseSpinLock(&ProtectedProcessListLock, oldIrql);
    
    return entry;
}
Пример #3
0
err_t
LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
{
    err_t ret;
    struct lwip_callback_msg *msg;

    msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
    if (msg)
    {
        KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);

        msg->Input.Close.Connection = Connection;
        msg->Input.Close.Callback = callback;

        if (safe)
            LibTCPCloseCallback(msg);
        else
            tcpip_callback_with_block(LibTCPCloseCallback, msg, 1);

        if (WaitForEventSafely(&msg->Event))
            ret = msg->Output.Close.Error;
        else
            ret = ERR_CLSD;

        ExFreeToNPagedLookasideList(&MessageLookasideList, msg);

        return ret;
    }

    return ERR_MEM;
}
Пример #4
0
struct tcp_pcb *
LibTCPSocket(void *arg)
{
    struct lwip_callback_msg *msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
    struct tcp_pcb *ret;

    if (msg)
    {
        KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
        msg->Input.Socket.Arg = arg;

        tcpip_callback_with_block(LibTCPSocketCallback, msg, 1);

        if (WaitForEventSafely(&msg->Event))
            ret = msg->Output.Socket.NewPcb;
        else
            ret = NULL;

        ExFreeToNPagedLookasideList(&MessageLookasideList, msg);

        return ret;
    }

    return NULL;
}
Пример #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 );
	}
}
Пример #6
0
PTCP_PCB
LibTCPListen(PCONNECTION_ENDPOINT Connection, const u8_t backlog)
{
    struct lwip_callback_msg *msg;
    PTCP_PCB ret;

    msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
    if (msg)
    {
        KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
        msg->Input.Listen.Connection = Connection;
        msg->Input.Listen.Backlog = backlog;

        tcpip_callback_with_block(LibTCPListenCallback, msg, 1);

        if (WaitForEventSafely(&msg->Event))
            ret = msg->Output.Listen.NewPcb;
        else
            ret = NULL;

        ExFreeToNPagedLookasideList(&MessageLookasideList, msg);

        return ret;
    }

    return NULL;
}
Пример #7
0
void *mm_alloc(size_t size, int flags)
{
	alloc_block *block;
	char        *p_mem = NULL;
	int          i;
	
	if (flags & MEM_FAST)
	{
		for (i = 0; i < NUM_MEM_LISTS; i++) {
			if ((512u << i) < size) continue;
			p_mem = ExAllocateFromNPagedLookasideList(&mem_lists[i]); 
			break;
		}
	}
	if (p_mem == NULL) /* if memory not allocated, allocate from pool */
	{
		if (flags & MEM_SUCCESS)
			p_mem = mm_alloc_success(APOOL_TYPE(flags), ALLOC_SIZE(size), '1_cd'); else
			p_mem = ExAllocatePoolWithTag(APOOL_TYPE(flags), ALLOC_SIZE(size), '1_cd');
		
		if (p_mem == NULL) return NULL;
		flags &= ~MEM_FAST;
	}
	/* memory block must be 16byte aligned */
	if (dSZ(p_mem) & (16-1)) p_mem += 8, flags |= MEM_PADDED;
	/* initialize alloc_block struct */
	block = pv(p_mem);
	block->size  = size;
	block->flags = flags;
	block->index = i;
	/* zero memory if needed */
	if (flags & MEM_ZEROED) memset(block->data, 0, size);
	return &block->data;
}
Пример #8
0
err_t
LibTCPConnect(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
{
    struct lwip_callback_msg *msg;
    err_t ret;

    msg = ExAllocateFromNPagedLookasideList(&MessageLookasideList);
    if (msg)
    {
        KeInitializeEvent(&msg->Event, NotificationEvent, FALSE);
        msg->Input.Connect.Connection = Connection;
        msg->Input.Connect.IpAddress = ipaddr;
        msg->Input.Connect.Port = port;

        tcpip_callback_with_block(LibTCPConnectCallback, msg, 1);

        if (WaitForEventSafely(&msg->Event))
        {
            ret = msg->Output.Connect.Error;
        }
        else
            ret = ERR_CLSD;

        ExFreeToNPagedLookasideList(&MessageLookasideList, msg);

        return ret;
    }

    return ERR_MEM;
}
Пример #9
0
NTSTATUS Notification_Recieve(NOTIFICATION_QUEUE *queue, PIRP irp) {
	PIO_STACK_LOCATION irpstack = IoGetCurrentIrpStackLocation(irp);
	KIRQL irq;

	if(irpstack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(PGNOTIFICATION)) {
		irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
		irp->IoStatus.Information = 0;
		IoCompleteRequest(irp, IO_NO_INCREMENT);

		return STATUS_BUFFER_TOO_SMALL;
	}
	
	KeAcquireSpinLock(&queue->lock, &irq);

	if(IsListEmpty(&queue->notification_list)) {
		PGIRPNODE *irpnode;
		KIRQL crirq;

		irpnode = ExAllocateFromNPagedLookasideList(&queue->lookaside);

		InitializeListHead(&irpnode->entry);

		irpnode->irp = irp;
		//irp->Tail.Overlay.DriverContext[0] = irpnode;

		InsertTailList(&queue->irp_list, &irpnode->entry);

		IoMarkIrpPending(irp);

		IoAcquireCancelSpinLock(&crirq);

#pragma warning(push)
#pragma warning(disable:4311 4312)
		//IoSetCancelRoutine generates warnings in 32-bit due to silly macroisms.
		IoSetCancelRoutine(irp, Notification_OnCancel);
#pragma warning(pop)

		IoReleaseCancelSpinLock(crirq);
		
		KeReleaseSpinLock(&queue->lock, irq);

		return STATUS_PENDING;
	}
	else {
		PGNOTIFYNODE *notifynode = (PGNOTIFYNODE*)RemoveHeadList(&queue->notification_list);
		PGNOTIFICATION *notification = irp->AssociatedIrp.SystemBuffer;

		RtlCopyMemory(notification, &notifynode->notification, sizeof(PGNOTIFICATION));
		ExFreeToNPagedLookasideList(&queue->lookaside, notifynode);
		--queue->queued;
		
		KeReleaseSpinLock(&queue->lock, irq);

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

		return STATUS_SUCCESS;
	}
}
Пример #10
0
INLINE
PNON_PAGED_FCB
LfsAllocateNonPagedFcb (
    )
{
    return (PNON_PAGED_FCB) ExAllocateFromNPagedLookasideList( &GlobalLfs.NonPagedFcbLookasideList );
}
BOOLEAN SympAddSymbol(IN PCHAR pszSymbolName, IN ULONG64 uSymbolAddress, IN ULONG uOffset, IN ULONG uBitPosition, IN ULONG uBitLength)
{
	ASSERTMSG("Cannot add symbol with NULL name", pszSymbolName != NULL);
	ASSERTMSG("SymbolEngine must be initialized prior to this call", bIsSymEngineInitialized == TRUE);

	// it is possible that we got symbol with zero address, offset -1, bit position -1, and length -1 if the symbol was not found during
	// enumeration in user mode. In that case, and only in that case, we return error!
	// NOTE: uSymbolAddress of -1 is used when symbols are initialized in order to send the array of wanted symbols to the user mode
	if(uSymbolAddress == 0 && uOffset == -1 && uBitPosition == -1 && uBitLength == -1)
	{
		KdPrint(("[DEBUG] WARNING - Symbol was probably not found in user mode, cannot add symbol with unknown address and unknown offset\n"));
		return FALSE;
	}

	// if symbol with this name already exists
	if(SympFindSymbol(pszSymbolName) != NULL)
	{
		// don't want to "update" the address -- use SymUpdateSymbol function instead
		KdPrint(("[DEBUG] WARNING - Symbol %s with address 0x%x already exists -- use SymUpdateFunction() to update the address\n", pszSymbolName, uSymbolAddress));
		return TRUE;
	}

	// get memory from lookaside list
	PSYMBOL_ENTRY pSymbolEntry = (PSYMBOL_ENTRY) ExAllocateFromNPagedLookasideList(&SymbolsLookasideList);
	if(pSymbolEntry == NULL)
	{
		KdPrint(("[DEBUG] ERROR - Not enough memory in lookaside list to allocate new symbol entry\n"));
		return FALSE;
	}

	// copy string from passed parameter
	if(RtlStringCbCopyA(pSymbolEntry->Symbol.name, MAX_SYM_NAME, pszSymbolName) == STATUS_INVALID_PARAMETER)
	{
		KdPrint(("[DEBUG] ERROR - Error while copying symbol name to SYMBOL_ENTRY structure\n"));
		return FALSE;
	}

	// copy address from the passed parameter
	pSymbolEntry->Symbol.u64address = uSymbolAddress;

	// copy offset from the passed parameter
	pSymbolEntry->Symbol.uOffset = uOffset;

	// copy bit position from the passed parameter
	pSymbolEntry->Symbol.uBitPosition = uBitPosition;

	// copy bit length from the passed parameter
	pSymbolEntry->Symbol.uBitLength = uBitLength;

	// insert it to list (thread safe)
	ASSERTMSG("Fast mutex acquire must occur at or below APC_LEVEL", KeGetCurrentIrql() <= APC_LEVEL);
	ExAcquireFastMutex(&SymbolsListMutex);
	InsertHeadList(&SymbolsListHead, &pSymbolEntry->ListEntry);
	++uSymbolCount;
	ASSERTMSG("Fast mutex release must occur at APC_LEVEL", KeGetCurrentIrql() == APC_LEVEL);
	ExReleaseFastMutex(&SymbolsListMutex);

	return TRUE;
}
Пример #12
0
void *kmem_cache_alloc(struct kmem_cache *kmc, int flags)
{
	void *buf = NULL;

	buf = ExAllocateFromNPagedLookasideList(&(kmc->npll));

	return buf;
}
Пример #13
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);
}
Пример #14
0
FLT_PKT*
AllocateFltPacket()
{
    FLT_PKT* pFltPkt = (FLT_PKT*)ExAllocateFromNPagedLookasideList(&g_PktLookaside);

    if (pFltPkt)
        RtlZeroMemory(pFltPkt, sizeof(*pFltPkt));

    return pFltPkt;
}
Пример #15
0
NTSTATUS TCPSendData
( PCONNECTION_ENDPOINT Connection,
  PCHAR BufferData,
  ULONG SendLength,
  PULONG BytesSent,
  ULONG Flags,
  PTCP_COMPLETION_ROUTINE Complete,
  PVOID Context )
{
    NTSTATUS Status;
    PTDI_BUCKET Bucket;
    KIRQL OldIrql;

    LockObject(Connection, &OldIrql);

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

    TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Connection = %x\n", Connection));
    TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Connection->SocketContext = %x\n",
                           Connection->SocketContext));

    Status = TCPTranslateError(LibTCPSend(Connection,
                                          BufferData,
                                          SendLength,
                                          BytesSent,
                                          FALSE));
    
    TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Send: %x, %d\n", Status, SendLength));

    /* Keep this request around ... there was no data yet */
    if (Status == STATUS_PENDING)
    {
        /* Freed in TCPSocketState */
        Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList);
        if (!Bucket)
        {
            UnlockObject(Connection, OldIrql);
            TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Failed to allocate bucket\n"));
            return STATUS_NO_MEMORY;
        }
        
        Bucket->Request.RequestNotifyObject = Complete;
        Bucket->Request.RequestContext = Context;
        
        InsertTailList( &Connection->SendRequest, &Bucket->Entry );
        TI_DbgPrint(DEBUG_TCP,("[IP, TCPSendData] Queued write irp\n"));
    }

    UnlockObject(Connection, OldIrql);

    TI_DbgPrint(DEBUG_TCP, ("[IP, TCPSendData] Leaving. Status = %x\n", Status));

    return Status;
}
Пример #16
0
/*
 * For packets coming from the generic adapter, netmap expects
 * an mbuf with a persistent copy of the data.
 * For the time being we construct a brand new mbuf and
 * pass it to the handler.
 * We use this routine also in a way similar to m_getcl(),
 * passing a NULL pointer does not initialize the buffer (we need the length).
 * We have two pools, one for the mbuf and one for the cluster.
 * XXX we could do with a single allocation.
 */
struct mbuf *
win_make_mbuf(struct net_device *ifp, uint32_t length, const char *data)
{
	struct mbuf *m = ExAllocateFromNPagedLookasideList(&ifp->mbuf_pool);
	//DbgPrint("win_make_mbuf - Data: %p - length: %i", data, length);
	if (m == NULL) {
		DbgPrint("Netmap.sys: Failed to allocate memory from the mbuf!!!");
		return NULL;
	}
	m->m_len = length;
	m->pkt = ExAllocateFromNPagedLookasideList(&ifp->mbuf_packets_pool);
	if (m->pkt == NULL) {
		DbgPrint("Netmap.sys: Failed to allocate memory from the mbuf packet!!!");
		ExFreeToNPagedLookasideList(&ifp->mbuf_pool, m);
		return NULL;
	}
	m->dev = ifp;
	if (data) // XXX otherwise zero memory ?
		RtlCopyMemory(m->pkt, data, length);
	return m;
}
Пример #17
0
INLINE
PERESOURCE
LfsAllocateResource (
    )
{
    PERESOURCE Resource;

    Resource = (PERESOURCE) ExAllocateFromNPagedLookasideList( &GlobalLfs.EResourceLookasideList );

    ExInitializeResourceLite( Resource );

    return Resource;
}
Пример #18
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;
}
Пример #19
0
PXIFS_CCB	
XixFsdAllocateCCB(VOID)
{
	BOOLEAN				IsFromLookasideList = FALSE;
	PXIFS_CCB			CCB = NULL;

	PAGED_CODE();
	DebugTrace((DEBUG_LEVEL_TRACE|DEBUG_LEVEL_INFO), (DEBUG_TARGET_CREATE|DEBUG_TARGET_CCB), 
		("Enter XixFsdAllocateCCB\n"));


	// allocate memory
	CCB = ExAllocateFromNPagedLookasideList(&(XifsCcbLookasideList));
	if(!CCB)
	{
		CCB = ExAllocatePoolWithTag(NonPagedPool, sizeof(XIFS_CCB),TAG_CCB);
		if(!CCB)
		{
			//debug message
			DebugTrace(DEBUG_LEVEL_ERROR, (DEBUG_TARGET_CREATE|DEBUG_TARGET_CCB), 
				("ERROR XixFsdAllocateCCB Can't allocate\n"));
			return NULL;
		}
		IsFromLookasideList = FALSE;
	} else {
		IsFromLookasideList = TRUE;
	}

	RtlZeroMemory(CCB,sizeof(XIFS_CCB));

	CCB->NodeTypeCode = XIFS_NODE_CCB;
	CCB->NodeByteSize = sizeof(sizeof(XIFS_CCB));
	
	InitializeListHead(&CCB->LinkToFCB);

	
	if (!IsFromLookasideList) {
		XifsdSetFlag(CCB->CCBFlags, XIFSD_CCB_NOT_FROM_POOL);

		DebugTrace(DEBUG_LEVEL_CRITICAL, (DEBUG_TARGET_CREATE|DEBUG_TARGET_CCB), 
			("XixFsdAllocateCCB CCBFlags(0x%x)\n",CCB->CCBFlags));
	}

	DebugTrace((DEBUG_LEVEL_TRACE|DEBUG_LEVEL_INFO), (DEBUG_TARGET_CREATE|DEBUG_TARGET_CCB), 
		("Exit XixFsdAllocateCCB(%p)\n",CCB));

	return CCB;	
}
Пример #20
0
__drv_mustHoldCriticalRegion
PFFS_CCB
FFSAllocateCcb(
	VOID)
{
	PFFS_CCB Ccb;

    PAGED_CODE();

	ExAcquireResourceExclusiveLite(
			&FFSGlobal->LAResource,
			TRUE);

	Ccb = (PFFS_CCB)(ExAllocateFromNPagedLookasideList(&(FFSGlobal->FFSCcbLookasideList)));

	ExReleaseResourceForThreadLite(
			&FFSGlobal->LAResource,
			ExGetCurrentResourceThread());

	if (Ccb == NULL)
	{
		Ccb = (PFFS_CCB)ExAllocatePoolWithTag(NonPagedPool, sizeof(FFS_CCB), FFS_POOL_TAG);

		RtlZeroMemory(Ccb, sizeof(FFS_CCB));

		SetFlag(Ccb->Flags, CCB_FROM_POOL);
	}
	else
	{
		RtlZeroMemory(Ccb, sizeof(FFS_CCB));
	}

	if (!Ccb)
	{
		return NULL;
	}

	Ccb->Identifier.Type = FFSCCB;
	Ccb->Identifier.Size = sizeof(FFS_CCB);

	Ccb->CurrentByteOffset = 0;

	Ccb->DirectorySearchPattern.Length = 0;
	Ccb->DirectorySearchPattern.MaximumLength = 0;
	Ccb->DirectorySearchPattern.Buffer = 0;

	return Ccb;
}
Пример #21
0
VOID
ExDeleteNPagedLookasideList (
    IN PNPAGED_LOOKASIDE_LIST Lookaside
    )

/*++

Routine Description:

    This function removes a paged lookaside structure from the system paged
    lookaside list and frees any entries specified by the lookaside structure.

Arguments:

    Lookaside - Supplies a pointer to a nonpaged lookaside list structure.

Return Value:

    None.

--*/

{

    PVOID Entry;
    KIRQL OldIrql;

    //
    // Acquire the nonpaged system lookaside list lock and remove the
    // specified lookaside list structure from the list.
    //

    ExAcquireSpinLock(&ExNPagedLookasideLock, &OldIrql);
    RemoveEntryList(&Lookaside->L.ListEntry);
    ExReleaseSpinLock(&ExNPagedLookasideLock, OldIrql);

    //
    // Remove all pool entries from the specified lookaside structure
    // and free them.
    //

    Lookaside->L.Allocate = ExpDummyAllocate;
    while ((Entry = ExAllocateFromNPagedLookasideList(Lookaside)) != NULL) {
        (Lookaside->L.Free)(Entry);
    }

    return;
}
Пример #22
0
PFAT_IRP_CONTEXT
NTAPI
FatBuildIrpContext(PIRP Irp,
                   BOOLEAN CanWait)
{
    PIO_STACK_LOCATION IrpSp;
    PFAT_IRP_CONTEXT IrpContext;
    PVOLUME_DEVICE_OBJECT VolumeObject;

    /* Get current IRP stack location */
    IrpSp = IoGetCurrentIrpStackLocation(Irp);

    /* Allocate memory for the Irp context */
    IrpContext = ExAllocateFromNPagedLookasideList(&FatGlobalData.IrpContextList);

    /* Zero init memory */
    RtlZeroMemory(IrpContext, sizeof(FAT_IRP_CONTEXT));

    /* Save IRP, MJ and MN */
    IrpContext->Irp = Irp;
    IrpContext->Stack = IrpSp;
    IrpContext->MajorFunction = IrpSp->MajorFunction;
    IrpContext->MinorFunction = IrpSp->MinorFunction;

    /* Set DeviceObject */
    if (IrpSp->FileObject)
    {
        IrpContext->DeviceObject = IrpSp->FileObject->DeviceObject;

        /* Save VCB pointer */
        VolumeObject = (PVOLUME_DEVICE_OBJECT)IrpSp->DeviceObject;
        IrpContext->Vcb = &VolumeObject->Vcb;

        /* TODO: Handle write-through */
    }
    else if (IrpContext->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL)
    {
        /* Handle FSCTRL case */
        IrpContext->DeviceObject = IrpSp->Parameters.MountVolume.Vpb->RealDevice;
    }

    /* Set Wait flag */
    if (CanWait) IrpContext->Flags |= IRPCONTEXT_CANWAIT;

    /* Return prepared context */
    return IrpContext;
}
Пример #23
0
PNTFS_FCB
NtfsCreateFCB(PCWSTR FileName,
              PCWSTR Stream,
              PNTFS_VCB Vcb)
{
    PNTFS_FCB Fcb;

    ASSERT(Vcb);
    ASSERT(Vcb->Identifier.Type == NTFS_TYPE_VCB);

    Fcb = ExAllocateFromNPagedLookasideList(&NtfsGlobalData->FcbLookasideList);
    RtlZeroMemory(Fcb, sizeof(NTFS_FCB));

    Fcb->Identifier.Type = NTFS_TYPE_FCB;
    Fcb->Identifier.Size = sizeof(NTFS_TYPE_FCB);

    Fcb->Vcb = Vcb;

    if (FileName)
    {
        wcscpy(Fcb->PathName, FileName);
        if (wcsrchr(Fcb->PathName, '\\') != 0)
        {
            Fcb->ObjectName = wcsrchr(Fcb->PathName, '\\');
        }
        else
        {
            Fcb->ObjectName = Fcb->PathName;
        }
    }

    if (Stream)
    {
        wcscpy(Fcb->Stream, Stream);
    }
    else
    {
        Fcb->Stream[0] = UNICODE_NULL;
    }

    ExInitializeResourceLite(&Fcb->MainResource);

    Fcb->RFCB.Resource = &(Fcb->MainResource);

    return Fcb;
}
Пример #24
0
static NTSTATUS
DefaultDispatch(
	PDEVICE_OBJECT	DeviceObject,
	PIRP			Irp
	)
{
	NTSTATUS				status;
	PIO_STACK_LOCATION		IrpStack;
	PMYCONTEXT				MyContext;
	PDRIVER_ENTRY			DrvEntry;
	PDEVICE_ENTRY			DevEntry;

	IrpStack = IoGetCurrentIrpStackLocation(Irp);

	DevEntry = LookupEntryByDevObj(DeviceObject);
	if ( DevEntry )
	{
		MyContext = ExAllocateFromNPagedLookasideList(&ContextLookaside);
		if ( MyContext )
		{
			MyContext->Context = IrpStack->Context;
			MyContext->Control = IrpStack->Control;
			MyContext->MajorFunction = IrpStack->MajorFunction;
			MyContext->CompletionRoutine = IrpStack->CompletionRoutine;

			IrpStack->CompletionRoutine = MyCompletionRoutine;
			IrpStack->Context = MyContext;
			IrpStack->Control = SL_INVOKE_ON_SUCCESS | SL_INVOKE_ON_ERROR | SL_INVOKE_ON_CANCEL;
		}

		status = (DevEntry->DrvEntry->DriverDispatch[IrpStack->MajorFunction])(DeviceObject, Irp);
	}
	else
	{
		DrvEntry = LookupEntryByDrvObj(DeviceObject->DriverObject);
		if ( !DrvEntry )
		{
			DbgPrint("***** UH-OH\n");
			return STATUS_DEVICE_NOT_READY;
		}

		status = (DrvEntry->DriverDispatch[IrpStack->MajorFunction])(DeviceObject, Irp);
	}

	return status;
}
Пример #25
0
void Insert(DWORD key, PDATA pData, PHASHTABLE pHashTable)
{
	PTWOWAY pNode = NULL; 
	PTWOWAY pNewNode = NULL;
	PLIST_ENTRY pListHead = NULL;

	pNode = Find(key, pHashTable);
	// The node with the given key was not found.
	if (pNode == NULL)
	{
		pNewNode = ExAllocateFromNPagedLookasideList(pLookasideList_TWOWAY);
		if (pNewNode == NULL)
		{
			DbgPrint("ExAllocateFromNPagedLookasideList returned NULL!\n");
			return;
		}
		
		// Insert the data to the node.
		pNewNode->key = key;
		pNewNode->data.threadID = pData->threadID;
		pNewNode->data.processID = pData->processID;
		if (STATUS_SUCCESS != RtlStringCbCopyA(pNewNode->data.imageName, 16, pData->imageName))
		{
			DbgPrint("RtlStringCbCopyA failed!\n");
		}

		// Insert the node to the doubly-linked list.
		pListHead = pHashTable->pListHeads[Hash(key, pHashTable->tableSize)];
		InsertTailList(pListHead, &pNewNode->linkfield);
#ifdef MY_DEBUG
		DbgPrint("INSERT: thread ID = 0x%x process ID = 0x%x image = %s\n", pData->threadID, pData->processID, pData->imageName);
#endif
	}
#ifdef MY_DEBUG
	else
	{
		if (pNode->data.processID != pData->processID)
		{
			DbgPrint("Node with key = 0x%x already in list\n", key);
			DbgPrint("OLD: thread ID = 0x%x process ID = 0x%x image = %s\n", pNode->data.threadID, pNode->data.processID, pNode->data.imageName);
			DbgPrint("NEW: thread ID = 0x%x process ID = 0x%x image = %s\n", pData->threadID, pData->processID, pData->imageName);
		}
	}
#endif
}
Пример #26
0
// Create a node event handler for the specified node
NodeEventHandler* CreateNodeEventHandler(EventHandlerManager* event_handler_manager, PFILE_OBJECT node)
{
	NodeEventHandler* node_event_handler = NULL;

	node_event_handler = (NodeEventHandler*)ExAllocateFromNPagedLookasideList(&event_handler_manager->event_handlers_pool);

	if(node_event_handler == NULL)
		return NULL;

	node_event_handler->node = node;
	node_event_handler->num_handlers = 0;

	RtlZeroMemory(node_event_handler->handlers, sizeof(EventHandler) * TDI_EVENT_HANDLERS_MAX);

	InsertHashMap(&event_handler_manager->event_handlers, (UINT)node, node_event_handler);

	return node_event_handler;
}
Пример #27
0
FLT_PKT*
CreateFltPacketWithBuffer()
{
    FLT_PKT* pFltPkt;

    pFltPkt = AllocateFltPacket();
    if (NULL == pFltPkt)
        return NULL;

    pFltPkt->pBuf = ExAllocateFromNPagedLookasideList(&g_DataLookaside);
    if (NULL == pFltPkt->pBuf) {
        FreeFltPkt(pFltPkt);
        return NULL;
    }

    RtlZeroMemory(pFltPkt->pBuf, MAX_ETHER_SIZE);
    return pFltPkt;
}
Пример #28
0
PXIFS_FCB 	
XixFsdAllocateFCB(VOID)
{
	BOOLEAN				IsFromLookasideList = FALSE;
	PXIFS_FCB			FCB = NULL;
	uint32				i = 0;
	
	PAGED_CODE();
	DebugTrace((DEBUG_LEVEL_TRACE|DEBUG_LEVEL_INFO), (DEBUG_TARGET_CREATE|DEBUG_TARGET_FCB), 
		("Enter XixFsdAllocateFCB\n"));

	// allocate memory
	FCB = ExAllocateFromNPagedLookasideList(&(XifsFcbLookasideList));
	if(!FCB)
	{
		FCB = ExAllocatePoolWithTag(NonPagedPool, sizeof(XIFS_FCB),TAG_FCB);
		if(!FCB)
		{
			//debug message
			DebugTrace(DEBUG_LEVEL_ERROR, (DEBUG_TARGET_CREATE|DEBUG_TARGET_FCB), 
				("ERROR XixFsAllocateFCB Can't allocate\n"));
			return NULL;
		}
		IsFromLookasideList = FALSE;
	} else {
		IsFromLookasideList = TRUE;
	}
	
	RtlZeroMemory(FCB,sizeof(XIFS_FCB));
	
	if (!IsFromLookasideList) {
		XifsdSetFlag(FCB->FCBFlags, XIFSD_FCB_NOT_FROM_POOL);
		
		DebugTrace(DEBUG_LEVEL_CRITICAL, (DEBUG_TARGET_CREATE|DEBUG_TARGET_FCB), 
			("XixFsdAllocateFCB FCBFlags(0x%x)\n",FCB->FCBFlags));
	}
		
	FCB->NodeTypeCode = XIFS_NODE_FCB;
	FCB->NodeByteSize = sizeof(sizeof(XIFS_FCB));

	DebugTrace((DEBUG_LEVEL_TRACE|DEBUG_LEVEL_INFO), (DEBUG_TARGET_CREATE|DEBUG_TARGET_FCB), 
		("Exit XixFsdAllocateFCB(%p)\n",FCB));
	return FCB;	
}
Пример #29
0
void cp_parallelized_crypt(
	   int   is_encrypt, xts_key *key, fc_callback on_complete, 
	   void *param, const unsigned char *in, unsigned char *out, u32 len, u64 offset)
{
	req_item *item;
	req_part *part;
	u32       part_sz;
	u32       part_of;

	if ( (len < F_OP_THRESOLD) ||
		 ((item = ExAllocateFromNPagedLookasideList(&pool_req_mem)) == NULL) )
	{
		if (is_encrypt != 0) {
			xts_encrypt(in, out, len, offset, key);
		} else {
			xts_decrypt(in, out, len, offset, key);
		}
		on_complete(param); return;
	}
	item->is_encrypt = is_encrypt;
	item->length = len;
	item->in  = in;
	item->out = out;
	item->offset      = offset;
	item->on_complete = on_complete;
	item->param = param;
	item->key   = key;

	part_sz = _align(len / dc_cpu_count, F_MIN_REQ);
	part_of = 0; part = &item->parts[0];
	do
	{
		part_sz      = min(part_sz, len);
		part->item   = item;
		part->offset = part_of;
		part->length = part_sz;

		InterlockedPushEntrySList(&pool_head, &part->entry);

		part_of += part_sz; len -= part_sz; part++;
	} while (len != 0);

	KeSetEvent(&pool_signal_event, IO_NO_INCREMENT, FALSE);
}
Пример #30
0
PXIFS_CLOSE_FCB_CTX	
XixFsdAllocateCloseFcbCtx(VOID)
{
	BOOLEAN						IsFromLookasideList = FALSE;
	PXIFS_CLOSE_FCB_CTX			Ctx = NULL;

	PAGED_CODE();
	DebugTrace((DEBUG_LEVEL_TRACE|DEBUG_LEVEL_INFO), (DEBUG_TARGET_CLOSE), 
		("Enter XixFsdAllocateCloseFcbCtx \n"));

	// allocate memory
	Ctx = ExAllocateFromNPagedLookasideList(&(XifsCloseFcbCtxList));
	if(!Ctx)
	{
		Ctx = ExAllocatePoolWithTag(PagedPool, sizeof(XIFS_CLOSE_FCB_CTX),TAG_CLOSEFCBCTX);
		if(!Ctx)
		{
			DebugTrace(DEBUG_LEVEL_ERROR, (DEBUG_TARGET_CLOSE), 
				("ERROR XixFsdAllocateCloseFcbCtx Can't allocate\n"));
			//debug message
			return NULL;
		}
		IsFromLookasideList = FALSE;
	} else {
		IsFromLookasideList = TRUE;
	}


	RtlZeroMemory(Ctx,sizeof(XIFS_CLOSE_FCB_CTX));

	InitializeListHead(&(Ctx->DelayedCloseLink));
	
	if (!IsFromLookasideList) {
		XifsdSetFlag(Ctx->CtxFlags, XIFSD_CTX_FLAGS_NOT_FROM_POOL);

		DebugTrace(DEBUG_LEVEL_CRITICAL, (DEBUG_TARGET_CLOSE), 
			(" XixFsdAllocateCloseFcbCtx CtxFlags(0x%x)\n",Ctx->CtxFlags));
	}

	DebugTrace((DEBUG_LEVEL_TRACE|DEBUG_LEVEL_INFO), (DEBUG_TARGET_CLOSE), 
		("Exit XixFsdAllocateCloseFcbCtx (%p)\n", Ctx));
	return Ctx;	
}