Exemplo n.º 1
0
PFCB
CdfsCreateFCB(PCWSTR FileName)
{
    PFCB Fcb;

    Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(FCB), TAG_FCB);
    if(!Fcb) return NULL;

    RtlZeroMemory(Fcb, sizeof(FCB));

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

    ExInitializeResourceLite(&Fcb->PagingIoResource);
    ExInitializeResourceLite(&Fcb->MainResource);
    ExInitializeResourceLite(&Fcb->NameListResource);
    Fcb->RFCB.PagingIoResource = &Fcb->PagingIoResource;
    Fcb->RFCB.Resource = &Fcb->MainResource;
    Fcb->RFCB.IsFastIoPossible = FastIoIsNotPossible;
    InitializeListHead(&Fcb->ShortNameList);

    return(Fcb);
}
Exemplo n.º 2
0
// We must NOT call without VCB lcok
PDokanFCB
DokanAllocateFCB(
	__in PDokanVCB Vcb
	)
{
	PDokanFCB fcb = ExAllocatePool(sizeof(DokanFCB));

	if (fcb == NULL) {
		return NULL;
	}

	ASSERT(fcb != NULL);
	ASSERT(Vcb != NULL);

	RtlZeroMemory(fcb, sizeof(DokanFCB));

	fcb->Identifier.Type = FCB;
	fcb->Identifier.Size = sizeof(DokanFCB);

	fcb->Vcb = Vcb;

	ExInitializeResourceLite(&fcb->MainResource);
	ExInitializeResourceLite(&fcb->PagingIoResource);

	ExInitializeFastMutex(&fcb->AdvancedFCBHeaderMutex);

#if _WIN32_WINNT >= 0x0501
	FsRtlSetupAdvancedHeader(&fcb->AdvancedFCBHeader, &fcb->AdvancedFCBHeaderMutex);
#else
	if (DokanFsRtlTeardownPerStreamContexts) {
		FsRtlSetupAdvancedHeader(&fcb->AdvancedFCBHeader, &fcb->AdvancedFCBHeaderMutex);
	}
#endif


	fcb->AdvancedFCBHeader.ValidDataLength.LowPart = 0xffffffff;
	fcb->AdvancedFCBHeader.ValidDataLength.HighPart = 0x7fffffff;

	fcb->AdvancedFCBHeader.Resource = &fcb->MainResource;
	fcb->AdvancedFCBHeader.PagingIoResource = &fcb->PagingIoResource;

	fcb->AdvancedFCBHeader.AllocationSize.QuadPart = 4096;
	fcb->AdvancedFCBHeader.FileSize.QuadPart = 4096;

	fcb->AdvancedFCBHeader.IsFastIoPossible = FastIoIsNotPossible;

	ExInitializeResourceLite(&fcb->Resource);

	InitializeListHead(&fcb->NextCCB);
	InsertTailList(&Vcb->NextFCB, &fcb->NextFCB);

	InterlockedIncrement(&Vcb->FcbAllocated);

	return fcb;
}
Exemplo n.º 3
0
PFCB
NTAPI
FatCreateDcb(IN PFAT_IRP_CONTEXT IrpContext,
             IN PVCB Vcb,
             IN PFCB ParentDcb,
             IN FF_FILE *FileHandle)
{
    PFCB Fcb;

    /* Allocate it and zero it */
    Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(FCB), TAG_FCB);
    RtlZeroMemory(Fcb, sizeof(FCB));

    /* Set node types */
    Fcb->Header.NodeTypeCode = FAT_NTC_DCB;
    Fcb->Header.NodeByteSize = sizeof(FCB);
    Fcb->Condition = FcbGood;

    /* Initialize resources */
    Fcb->Header.Resource = &Fcb->Resource;
    ExInitializeResourceLite(Fcb->Header.Resource);

    Fcb->Header.PagingIoResource = &Fcb->PagingIoResource;
    ExInitializeResourceLite(Fcb->Header.PagingIoResource);

    /* Initialize mutexes */
    Fcb->Header.FastMutex = &Fcb->HeaderMutex;
    ExInitializeFastMutex(&Fcb->HeaderMutex);
    FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);

    /* Insert into parent's DCB list */
    InsertHeadList(&ParentDcb->Dcb.ParentDcbList, &Fcb->ParentDcbLinks);

    /* Set backlinks */
    Fcb->ParentFcb = ParentDcb;
    Fcb->Vcb = Vcb;

    /* Initialize parent dcb list */
    InitializeListHead(&Fcb->Dcb.ParentDcbList);

    /* Set FullFAT handle */
    Fcb->FatHandle = FileHandle;

    /* Set names */
    if (FileHandle)
    {
        FatSetFcbNames(IrpContext, Fcb);

        /* Ensure the full name is set */
        FatSetFullFileNameInFcb(IrpContext, Fcb);
    }

    return Fcb;
}
Exemplo n.º 4
0
PFCB
NTAPI
FatCreateFcb(IN PFAT_IRP_CONTEXT IrpContext,
             IN PVCB Vcb,
             IN PFCB ParentDcb,
             IN FF_FILE *FileHandle)
{
    PFCB Fcb;

    /* Allocate it and zero it */
    Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(FCB), TAG_FCB);
    RtlZeroMemory(Fcb, sizeof(FCB));

    /* Set node types */
    Fcb->Header.NodeTypeCode = FAT_NTC_FCB;
    Fcb->Header.NodeByteSize = sizeof(FCB);
    Fcb->Condition = FcbGood;

    /* Initialize resources */
    Fcb->Header.Resource = &Fcb->Resource;
    ExInitializeResourceLite(Fcb->Header.Resource);

    Fcb->Header.PagingIoResource = &Fcb->PagingIoResource;
    ExInitializeResourceLite(Fcb->Header.PagingIoResource);

    /* Initialize mutexes */
    Fcb->Header.FastMutex = &Fcb->HeaderMutex;
    ExInitializeFastMutex(&Fcb->HeaderMutex);
    FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);

    /* Insert into parent's DCB list */
    InsertTailList(&ParentDcb->Dcb.ParentDcbList, &Fcb->ParentDcbLinks);

    /* Set backlinks */
    Fcb->ParentFcb = ParentDcb;
    Fcb->Vcb = Vcb;

    /* Set file handle and sizes */
    Fcb->Header.FileSize.LowPart = FileHandle->Filesize;
    Fcb->Header.ValidDataLength.LowPart = FileHandle->Filesize;
    Fcb->FatHandle = FileHandle;

    /* Initialize locks */
    FsRtlInitializeFileLock(&Fcb->Fcb.Lock, NULL, NULL);
    FsRtlInitializeOplock(&Fcb->Fcb.Oplock);

    /* Set names */
    FatSetFcbNames(IrpContext, Fcb);

    return Fcb;
}
Exemplo n.º 5
0
INIT_FUNCTION
NTSTATUS
NTAPI
InitTimerImpl(VOID)
{
   ULONG BitmapBytes;

   ExInitializeFastMutex(&Mutex);

   BitmapBytes = ROUND_UP(NUM_WINDOW_LESS_TIMERS, sizeof(ULONG) * 8) / 8;
   WindowLessTimersBitMapBuffer = ExAllocatePoolWithTag(NonPagedPool, BitmapBytes, TAG_TIMERBMP);
   if (WindowLessTimersBitMapBuffer == NULL)
   {
      return STATUS_UNSUCCESSFUL;
   }

   RtlInitializeBitMap(&WindowLessTimersBitMap,
                       WindowLessTimersBitMapBuffer,
                       BitmapBytes * 8);

   /* yes we need this, since ExAllocatePoolWithTag isn't supposed to zero out allocated memory */
   RtlClearAllBits(&WindowLessTimersBitMap);

   ExInitializeResourceLite(&TimerLock);
   InitializeListHead(&TimersListHead);

   return STATUS_SUCCESS;
}
Exemplo n.º 6
0
INIT_FUNCTION
NTSTATUS
NTAPI
InitUserImpl(VOID)
{
    NTSTATUS Status;

    ExInitializeResourceLite(&UserLock);

    if (!UserCreateHandleTable())
    {
        ERR("Failed creating handle table\n");
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    Status = InitSessionImpl();
    if (!NT_SUCCESS(Status))
    {
        ERR("Error init session impl.\n");
        return Status;
    }

    InitUserAtoms();

    InitSysParams();

    return STATUS_SUCCESS;
}
Exemplo n.º 7
0
BOOLEAN
SepInitializeWorkList(
    VOID
    )

/*++

Routine Description:

    Initializes the mutex and list head used to queue work from the
    Executive to LSA.  This mechanism operates on top of the normal ExWorkerThread
    mechanism by capturing the first thread to perform LSA work and keeping it
    until all the current work is done.

    The reduces the number of worker threads that are blocked on I/O to LSA.

Arguments:

    None.


Return Value:

    TRUE if successful, FALSE otherwise.

--*/

{
    PAGED_CODE();

    ExInitializeResourceLite(&SepLsaQueueLock);
    InitializeListHead(&SepLsaQueue);
    return( TRUE );
}
Exemplo n.º 8
0
NTSTATUS 
DriverEntry(
    PDRIVER_OBJECT DriverObject,
    PUNICODE_STRING RegistryPath )
{
    NTSTATUS            Status;

    UNREFERENCED_PARAMETER(RegistryPath);

    DriverObject->DriverUnload  = DriverUnload;

    DbgPrint ( "%s DriverObject=%p\n", __FUNCTION__, DriverObject );

    // Step #1 : Initialize the lock that protects the g_Tidxxx globals (ExInitializeResourceLite())
    ExInitializeResourceLite(&g_TidLock);

    Status = PsSetCreateThreadNotifyRoutine( ThreadNotifyCallback ); 
    if ( ! NT_SUCCESS ( Status ) ) {
        DbgPrint ( "%s PsSetCreateThreadNotifyRoutine() FAIL=%08x\n", __FUNCTION__, Status );
        goto Exit;
    }

    Status = STATUS_SUCCESS;

Exit :
    return Status;
}
Exemplo n.º 9
0
static NTSTATUS _DymArraySynchronizationAlloc(PUTILS_DYM_ARRAY Array)
{
	NTSTATUS status = STATUS_UNSUCCESSFUL;
	DEBUG_ENTER_FUNCTION("Array=0x%p", Array);

	switch (Array->PoolType) {
		case PagedPool:
			Array->LockPaged = (PERESOURCE)HeapMemoryAllocNonPaged(sizeof(ERESOURCE));
			if (Array->LockPaged != NULL) {
				status = ExInitializeResourceLite(Array->LockPaged);
				if (!NT_SUCCESS(status))
					HeapMemoryFree(Array->LockPaged);
			} else status = STATUS_INSUFFICIENT_RESOURCES;
			break;
		case NonPagedPool:
			Array->LockNonPaged = (PKSPIN_LOCK)HeapMemoryAllocNonPaged(sizeof(KSPIN_LOCK));
			if (Array->LockNonPaged != NULL) {
				KeInitializeSpinLock(Array->LockNonPaged);
				status = STATUS_SUCCESS;
			} else status = STATUS_INSUFFICIENT_RESOURCES;
			break;
		default:
			DEBUG_ERROR("Invalid pool type supplied (%u)", Array->PoolType);
			status = STATUS_NOT_SUPPORTED;
			break;
	}

	DEBUG_EXIT_FUNCTION("0x%x", status);
	return status;
}
Exemplo n.º 10
0
PDokanCCB
DokanAllocateCCB(
	__in PDokanDCB	Dcb,
	__in PDokanFCB	Fcb
	)
{
	PDokanCCB ccb = ExAllocatePool(sizeof(DokanCCB));

	if (ccb == NULL)
		return NULL;

	ASSERT(ccb != NULL);
	ASSERT(Fcb != NULL);

	RtlZeroMemory(ccb, sizeof(DokanCCB));

	ccb->Identifier.Type = CCB;
	ccb->Identifier.Size = sizeof(DokanCCB);

	ccb->Fcb = Fcb;

	ExInitializeResourceLite(&ccb->Resource);

	InitializeListHead(&ccb->NextCCB);

	ExAcquireResourceExclusiveLite(&Fcb->Resource, TRUE);
	InsertTailList(&Fcb->NextCCB, &ccb->NextCCB);
	ExReleaseResourceLite(&Fcb->Resource);

	ccb->MountId = Dcb->MountId;

	return ccb;
}
Exemplo n.º 11
0
VOID
INIT_FUNCTION
IopInitBootLog(BOOLEAN StartBootLog)
{
    ExInitializeResourceLite(&IopBootLogResource);
    if (StartBootLog) IopStartBootLog();
}
Exemplo n.º 12
0
NTSTATUS SortedListCreate(	OUT PSORTED_LIST pSortedList,IN ULONG uSizeOfEntry, IN POOL_TYPE poolType,
                            IN ULONG uPoolTag, IN BOOLEAN bMultiThread, IN SORTEDLISTENTRYCLEANUP pfnCleanupFunc
                         )
{
    ASSERTMSG("Pointer to sorted list must not be NULL", pSortedList != NULL);
    ASSERTMSG("Cleanup function must not be NULL", pfnCleanupFunc != NULL);

    NTSTATUS status = STATUS_SUCCESS;
    // initialize all variables of the sorted list
    RtlZeroMemory(pSortedList, sizeof(SORTED_LIST));
    pSortedList->poolType = poolType;
    pSortedList->uPoolTag = uPoolTag;
    pSortedList->uSizeOfEntry = uSizeOfEntry;
    pSortedList->uElementCount = 0;
    pSortedList->head = pSortedList->tail = NULL;
    pSortedList->bIsMultiThread = bMultiThread;
    pSortedList->bIsWriteLocked = FALSE;
    pSortedList->lReaderCount = 0;
    pSortedList->pLock = NULL;

    // if multithreaded list
    if(bMultiThread)
    {
        pSortedList->pLock = (PERESOURCE) ExAllocatePoolWithTag(NonPagedPool, sizeof(ERESOURCE), uPoolTag);
        status = ExInitializeResourceLite(pSortedList->pLock);
    }

    pSortedList->pfnEntryCleanup = pfnCleanupFunc;

    return status;
}
Exemplo n.º 13
0
NTSTATUS HandleTableCreate(EHashTableType HandleTableType, CHANDLE_TABLE_HANDLE_CREATED *HandleCreateProcedure, CHANDLE_TABLE_HANDLE_DELETED *HandleDeleteProcedure, CHANDLE_TABLE_HANDLE_TRANSLATED *HandleTranslateProcedure, PCHANDLE_TABLE *HandleTable)
{
	POOL_TYPE poolType = (HandleTableType == httPassiveLevel) ? PagedPool : NonPagedPool;
	PCHANDLE_TABLE tmpHandleTable = NULL;
	NTSTATUS status = STATUS_UNSUCCESSFUL;
	DEBUG_ENTER_FUNCTION("HandleTableType=%u; HandleCreateProcedure=0x%p; HandleDeleteProcedure=0x%p; HandleTranslateProcedure=0x%p; HandleTable=0x%p", HandleTableType, HandleCreateProcedure, HandleDeleteProcedure, HandleTranslateProcedure, HandleTable);

	tmpHandleTable = (PCHANDLE_TABLE)HeapMemoryAllocNonPaged(sizeof(CHANDLE_TABLE));
	if (tmpHandleTable != NULL) {
		tmpHandleTable->NextFreeHandle = 1;
		tmpHandleTable->HandleTableType = HandleTableType;
		tmpHandleTable->PoolType = poolType;
		tmpHandleTable->HandleCreateProcedure = HandleCreateProcedure;
		tmpHandleTable->HandleDeleteProcedure = HandleDeleteProcedure;
		tmpHandleTable->HandleTranslateProcedure = HandleTranslateProcedure;
		switch (tmpHandleTable->HandleTableType) {
			case httPassiveLevel:
				status = ExInitializeResourceLite(&tmpHandleTable->LockP);
				break;
			case httDispatchLevel:
				KeInitializeSpinLock(&tmpHandleTable->LockD);
				tmpHandleTable->ExclusiveLocker = NULL;
				status = STATUS_SUCCESS;
				break;
			case httNoSynchronization:
				status = STATUS_SUCCESS;
				break;
			default:
				status = STATUS_NOT_SUPPORTED;
				break;
		}

		if (NT_SUCCESS(status)) {
			status = HashTableCreate(httNoSynchronization, 37, _HashFunction, _CompareFunction, _FreeFunction, &tmpHandleTable->HashTable);
			if (NT_SUCCESS(status))
				*HandleTable = tmpHandleTable;

			if (!NT_SUCCESS(status)) {
				switch (tmpHandleTable->HandleTableType) {
					case httPassiveLevel:
						ExDeleteResourceLite(&tmpHandleTable->LockP);
						break;
					case httDispatchLevel:
						break;
					case httNoSynchronization:
						break;
					default:
						break;
				}
			}
		}

		if (!NT_SUCCESS(status))
			HeapMemoryFree(tmpHandleTable);
	} else status = STATUS_INSUFFICIENT_RESOURCES;

	DEBUG_EXIT_FUNCTION("0x%x, *HandleTable=0x%p", status, *HandleTable);
	return status;
}
Exemplo n.º 14
0
NTSTATUS
CtxCreateStreamHandleContext (
    __deref_out PSTREAMHANDLE_CONTEXT *StreamHandleContext
    )
/*++

Routine Description:

    This routine creates a new stream context

Arguments:

    StreamContext         - Returns the stream context

Return Value:

    Status

--*/
{
    NTSTATUS status;
    PSTREAMHANDLE_CONTEXT streamHandleContext;

    PAGED_CODE();

    //
    //  Allocate a stream context
    //

    status = FltAllocateContext( g_FileFltContext.FileFltHandle,
                                 FLT_STREAMHANDLE_CONTEXT,
                                 STREAMHANDLE_CONTEXT_SIZE,
                                 NonPagedPool,
                                 &streamHandleContext );

    if (!NT_SUCCESS( status )) {


        return status;
    }

    //
    //  Initialize the newly created context
    //

    RtlZeroMemory( streamHandleContext, STREAMHANDLE_CONTEXT_SIZE );

    streamHandleContext->Resource = FsAllocateResource();
    if(streamHandleContext->Resource == NULL) {

        FltReleaseContext( streamHandleContext );
        return STATUS_INSUFFICIENT_RESOURCES;
    }
    ExInitializeResourceLite( streamHandleContext->Resource );

    *StreamHandleContext = streamHandleContext;

    return STATUS_SUCCESS;
}
Exemplo n.º 15
0
// Initialize a log file related code such as a flushing thread.
_Use_decl_annotations_ static NTSTATUS LogpInitializeBufferInfo(
    const wchar_t *log_file_path, LogBufferInfo *info) {
  PAGED_CODE();
  NT_ASSERT(log_file_path);
  NT_ASSERT(info);

  KeInitializeSpinLock(&info->spin_lock);

  auto status = RtlStringCchCopyW(
      info->log_file_path, RTL_NUMBER_OF_FIELD(LogBufferInfo, log_file_path),
      log_file_path);
  if (!NT_SUCCESS(status)) {
    return status;
  }

  status = ExInitializeResourceLite(&info->resource);
  if (!NT_SUCCESS(status)) {
    return status;
  }
  info->resource_initialized = true;

  // Allocate two log buffers on NonPagedPool.
  info->log_buffer1 = reinterpret_cast<char *>(
      ExAllocatePoolWithTag(NonPagedPoolNx, kLogpBufferSize, kLogpPoolTag));
  if (!info->log_buffer1) {
    LogpFinalizeBufferInfo(info);
    return STATUS_INSUFFICIENT_RESOURCES;
  }

  info->log_buffer2 = reinterpret_cast<char *>(
      ExAllocatePoolWithTag(NonPagedPoolNx, kLogpBufferSize, kLogpPoolTag));
  if (!info->log_buffer2) {
    LogpFinalizeBufferInfo(info);
    return STATUS_INSUFFICIENT_RESOURCES;
  }

  // Initialize these buffers
  RtlFillMemory(info->log_buffer1, kLogpBufferSize, 0xff);  // for diagnostic
  info->log_buffer1[0] = '\0';
  info->log_buffer1[kLogpBufferSize - 1] = '\0';  // at the end

  RtlFillMemory(info->log_buffer2, kLogpBufferSize, 0xff);  // for diagnostic
  info->log_buffer2[0] = '\0';
  info->log_buffer2[kLogpBufferSize - 1] = '\0';  // at the end

  // Buffer should be used is log_buffer1, and location should be written logs
  // is the head of the buffer.
  info->log_buffer_head = info->log_buffer1;
  info->log_buffer_tail = info->log_buffer1;

  status = LogpInitializeLogFile(info);
  if (status == STATUS_OBJECT_PATH_NOT_FOUND) {
    HYPERPLATFORM_LOG_INFO("The log file needs to be activated later.");
    status = STATUS_REINITIALIZATION_NEEDED;
  } else if (!NT_SUCCESS(status)) {
    LogpFinalizeBufferInfo(info);
  }
  return status;
}
Exemplo n.º 16
0
NTSTATUS FspFileNodeCreate(PDEVICE_OBJECT DeviceObject,
    ULONG ExtraSize, FSP_FILE_NODE **PFileNode)
{
    PAGED_CODE();

    *PFileNode = 0;

    FSP_FILE_NODE_NONPAGED *NonPaged = FspAllocNonPaged(sizeof *NonPaged);
    if (0 == NonPaged)
        return STATUS_INSUFFICIENT_RESOURCES;

    FSP_FILE_NODE *FileNode = FspAlloc(sizeof *FileNode + ExtraSize);
    if (0 == FileNode)
    {
        FspFree(NonPaged);
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    RtlZeroMemory(NonPaged, sizeof *NonPaged);
    ExInitializeResourceLite(&NonPaged->Resource);
    ExInitializeResourceLite(&NonPaged->PagingIoResource);
    ExInitializeFastMutex(&NonPaged->HeaderFastMutex);
    KeInitializeSpinLock(&NonPaged->DirInfoSpinLock);

    RtlZeroMemory(FileNode, sizeof *FileNode + ExtraSize);
    FileNode->Header.NodeTypeCode = FspFileNodeFileKind;
    FileNode->Header.NodeByteSize = sizeof *FileNode;
    FileNode->Header.IsFastIoPossible = FastIoIsNotPossible;
    FileNode->Header.Resource = &NonPaged->Resource;
    FileNode->Header.PagingIoResource = &NonPaged->PagingIoResource;
    FileNode->Header.ValidDataLength.QuadPart = MAXLONGLONG;
        /* disable ValidDataLength functionality */
    FsRtlSetupAdvancedHeader(&FileNode->Header, &NonPaged->HeaderFastMutex);
    FileNode->NonPaged = NonPaged;
    FileNode->RefCount = 1;
    FileNode->FsvolDeviceObject = DeviceObject;
    FspDeviceReference(FileNode->FsvolDeviceObject);
    RtlInitEmptyUnicodeString(&FileNode->FileName, FileNode->FileNameBuf, (USHORT)ExtraSize);

    FsRtlInitializeFileLock(&FileNode->FileLock, FspFileNodeCompleteLockIrp, 0);

    *PFileNode = FileNode;

    return STATUS_SUCCESS;
}
Exemplo n.º 17
0
PAGEABLE
NTSTATUS
MESSAGETABLE_Create(
	_Out_	PHMESSAGETABLE	phMessageTable
)
{
	NTSTATUS		eStatus			= STATUS_UNSUCCESSFUL;
	PMESSAGE_TABLE	ptMessageTable	= NULL;

	ASSERT(PASSIVE_LEVEL == KeGetCurrentIrql());

	if (NULL == phMessageTable)
	{
		eStatus = STATUS_INVALID_PARAMETER;
		goto lblCleanup;
	}

	ptMessageTable = ExAllocatePoolWithTag(NonPagedPool,
										   sizeof(*ptMessageTable),
										   MESSAGE_TABLE_POOL_TAG);
	if (NULL == ptMessageTable)
	{
		eStatus = STATUS_INSUFFICIENT_RESOURCES;
		goto lblCleanup;
	}
	RtlSecureZeroMemory(ptMessageTable, sizeof(*ptMessageTable));

	RtlInitializeGenericTableAvl(&(ptMessageTable->tTable),
								 &messagetable_CompareRoutine,
								 &messagetable_AllocateRoutine,
								 &messagetable_FreeRoutine,
								 NULL);
	ptMessageTable->bTableInitialized = TRUE;

	eStatus = ExInitializeResourceLite(&(ptMessageTable->tLock));
	if (!NT_SUCCESS(eStatus))
	{
		goto lblCleanup;
	}
	ptMessageTable->bLockInitialized = TRUE;

	// Transfer ownership:
	*phMessageTable = (HMESSAGETABLE)ptMessageTable;
	ptMessageTable = NULL;

	eStatus = STATUS_SUCCESS;

lblCleanup:
#pragma warning(suppress: 4133)	// warning C4133: 'function': incompatible types - from 'PMESSAGE_TABLE' to 'HMESSAGETABLE'
	CLOSE(ptMessageTable, MESSAGETABLE_Destroy);

	return eStatus;
}
Exemplo n.º 18
0
NTSTATUS
iCtx_CreateStreamContext (
    __in PFLT_RELATED_OBJECTS FltObjects,
    __deref_out PSTREAM_CONTEXT *StreamContext
    )
/*++

Routine Description:

    This routine creates a new stream context

Arguments:

    StreamContext         - Returns the stream context

Return Value:

    Status

--*/
{
    NTSTATUS status;
    PSTREAM_CONTEXT streamContext;

    PAGED_CODE();

    status = FltAllocateContext( FltObjects->Filter,
                                 FLT_STREAM_CONTEXT,
                                 STREAM_CONTEXT_SIZE,
                                 NonPagedPool,
                                 &streamContext );
    if (!NT_SUCCESS( status )) 
	{
        return status;
    }

    //  Initialize the newly created context
    RtlZeroMemory( streamContext, STREAM_CONTEXT_SIZE );

    streamContext->Resource = ExAllocatePoolWithTag( NonPagedPool, sizeof( ERESOURCE ),RESOURCE_TAG );
    if(streamContext->Resource == NULL)
	{
        FltReleaseContext( streamContext );
        return STATUS_INSUFFICIENT_RESOURCES;
    }
    ExInitializeResourceLite( streamContext->Resource );

    KeInitializeSpinLock(&streamContext->Resource1) ; 

    *StreamContext = streamContext;

    return STATUS_SUCCESS;
}
Exemplo n.º 19
0
INLINE
PERESOURCE
LfsAllocateResource (
    )
{
    PERESOURCE Resource;

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

    ExInitializeResourceLite( Resource );

    return Resource;
}
Exemplo n.º 20
0
VOID
	CDirControlList::Init()
{
	KdPrintKrnl(LOG_PRINTF_LEVEL_INFO, LOG_RECORED_LEVEL_NEED, L"begin");

	InitializeListHead(&ms_ListHead);
	KeInitializeSpinLock(&ms_SpLock);	
	ExInitializeResourceLite(&ms_Lock);

	KdPrintKrnl(LOG_PRINTF_LEVEL_INFO, LOG_RECORED_LEVEL_NEED, L"end");

	return;
}
Exemplo n.º 21
0
/*++

Routine Description:

    This routine creates a new stream context

Arguments:

    StreamContext         - Returns the stream context

Return Value:

    Status

--*/
NTSTATUS
CtxCreateStreamHandleContext (
    __deref_out PCTX_STREAMHANDLE_CONTEXT *StreamHandleContext
    )

{
    NTSTATUS status;
    PCTX_STREAMHANDLE_CONTEXT streamHandleContext;

    PAGED_CODE();

    //
    //  Allocate a stream context
    //

    DebugTrace( DEBUG_TRACE_STREAMHANDLE_CONTEXT_OPERATIONS,
                ("[Ctx]: Allocating stream handle context \n") );

    status = FltAllocateContext( Globals.Filter,
                                 FLT_STREAMHANDLE_CONTEXT,
                                 CTX_STREAMHANDLE_CONTEXT_SIZE,
                                 PagedPool,
                                 &streamHandleContext );

    if (!NT_SUCCESS( status ))
	{
        DebugTrace( DEBUG_TRACE_STREAMHANDLE_CONTEXT_OPERATIONS | DEBUG_TRACE_ERROR,
                    ("[Ctx]: Failed to allocate stream handle context with status 0x%x \n",
                     status) );

        return status;
    }

    //
    //  Initialize the newly created context
    //

    RtlZeroMemory( streamHandleContext, CTX_STREAMHANDLE_CONTEXT_SIZE );

    streamHandleContext->Resource = CtxAllocateResource();
    if(streamHandleContext->Resource == NULL)
	{
        FltReleaseContext( streamHandleContext );
        return STATUS_INSUFFICIENT_RESOURCES;
    }
    ExInitializeResourceLite( streamHandleContext->Resource );

    *StreamHandleContext = streamHandleContext;

    return STATUS_SUCCESS;
}
Exemplo n.º 22
0
AFSProcessCB *
AFSInitializeProcessCB( IN ULONGLONG ParentProcessId,
                        IN ULONGLONG ProcessId)
{

    AFSProcessCB *pProcessCB = NULL;
    AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSDeviceObject->DeviceExtension;

    __Enter
    {

        pProcessCB = (AFSProcessCB *)AFSExAllocatePoolWithTag( NonPagedPool,
                                                               sizeof( AFSProcessCB),
                                                               AFS_PROCESS_CB_TAG);

        if( pProcessCB == NULL)
        {
            try_return( pProcessCB);
        }

        RtlZeroMemory( pProcessCB,
                       sizeof( AFSProcessCB));

        pProcessCB->TreeEntry.HashIndex = (ULONGLONG)ProcessId;

        pProcessCB->ParentProcessId = (ULONGLONG)ParentProcessId;

        if( pDeviceExt->Specific.Control.ProcessTree.TreeHead == NULL)
        {
            pDeviceExt->Specific.Control.ProcessTree.TreeHead = (AFSBTreeEntry *)pProcessCB;
        }
        else
        {
            AFSInsertHashEntry( pDeviceExt->Specific.Control.ProcessTree.TreeHead,
                                &pProcessCB->TreeEntry);
        }

        ExInitializeResourceLite( &pProcessCB->Lock);

        pProcessCB->ActiveAuthGroup = &AFSNoPAGAuthGroup;

try_exit:

        NOTHING;
    }

    return pProcessCB;
}
Exemplo n.º 23
0
Arquivo: fcb.c Projeto: GYGit/reactos
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;
}
Exemplo n.º 24
0
NTSTATUS MrStartCore(
    IN PDRIVER_OBJECT   drvobj,
    IN PUNICODE_STRING  regpath
    )
{
    NTSTATUS            status;

    __try {

        /* initialize core structure */
        ExInitializeResourceLite(&g_core.mc_lock);
        InitializeListHead(&g_core.mc_dcb_list);

        /* store registry path */
        g_core.mc_reg = *regpath;
        g_core.mc_reg.Buffer = MrAlloc(regpath->MaximumLength);
        if (g_core.mc_reg.Buffer)
            RtlCopyMemory(g_core.mc_reg.Buffer, regpath->Buffer,
                          regpath->MaximumLength);

        /* query resitry */
        status = MrQueryRegistry(regpath);
        if (!NT_SUCCESS(status)) {
            __leave;
        }

        /* create device object */
        g_core.mc_devobj = MrCreateDevice(drvobj,
                                          MOURE_DEVICE,
                                          MOURE_SYMLNK);
        if (NULL == g_core.mc_devobj) {
            status = STATUS_INSUFFICIENT_RESOURCES;
            __leave;
        }

    } __finally {

        if (!NT_SUCCESS(status)) {
            /* do cleanup */
            MrStopCore();
        }
    }

    return status;
}
Exemplo n.º 25
0
VOID
NTAPI
NpInitializeVcb(VOID)
{
    PAGED_CODE();

    RtlZeroMemory(NpVcb, sizeof(*NpVcb));

    NpVcb->NodeType = NPFS_NTC_VCB;
    RtlInitializeUnicodePrefix(&NpVcb->PrefixTable);
    ExInitializeResourceLite(&NpVcb->Lock);
    RtlInitializeGenericTable(&NpVcb->EventTable,
                              NpEventTableCompareRoutine,
                              NpEventTableAllocate,
                              NpEventTableDeallocate,
                              0);
    NpInitializeWaitQueue(&NpVcb->WaitQueue);
}
Exemplo n.º 26
0
BOOLEAN
NameCacheInit(PKLG_NAME_CACHE* ppNameCache)
{
	PKLG_NAME_CACHE pNameCacheTmp;
	DWORD cou;
	if (ppNameCache == NULL)
	{
		DbPrint(DC_NAMEC,DL_WARNING, ("Whatta hella!? NameCacheInit: incorrect NameCache IN parameter\n"));
		DbgBreakPoint();
		return FALSE;
	}

	if (*ppNameCache != NULL)
	{
		DbPrint(DC_NAMEC,DL_WARNING, ("NameCache - already inited!\n"));
		DbgBreakPoint();
		return FALSE;
	}
	
	*ppNameCache = ExAllocatePoolWithTag(NonPagedPool, sizeof(KLG_NAME_CACHE), 'NboS');
	if  (*ppNameCache == NULL)
	{
		DbPrint(DC_NAMEC,DL_WARNING, ("NameCache not inited - low memory\n"));
		DbgBreakPoint();
		return FALSE;
	}

	pNameCacheTmp = *ppNameCache;
	ExInitializeResourceLite(&pNameCacheTmp->m_CacheResource);
	for (cou = 0; cou < HASH_SIZE; cou++)
	{
		pNameCacheTmp->m_NameCache[cou] = NULL;
#ifdef __DBG__
		pNameCacheTmp->m_NameCacheLen[cou]=0;
#endif
	}
#ifdef __DBG__
	pNameCacheTmp->m_NCLen = 0;
	
#endif
	DbPrint(DC_NAMEC, DL_INFO, ("NameCacheInit complete\n"));

	return TRUE;
}
Exemplo n.º 27
0
PAIMemObject
_AIMem_Init(int BlockSize)
{
	PAIMemObject pAIMem;
	pAIMem = (PAIMemObject) ExAllocatePoolWithTag(NonPagedPool, sizeof(AIMemObject), '~boS');
	if (pAIMem == 0)
		return 0;
	
	ExInitializeResourceLite(&pAIMem->m_CacheResource);
#ifdef __DBG__	
	pAIMem->m_dwMaxItems = 0;
	pAIMem->m_dwCurItems = 0;
#endif
	pAIMem->m_Hint = 0;
	pAIMem->m_BlockSize = BlockSize;
	if (_AIMem_InitBlocks(pAIMem, BlockSize) == 0)
	{
		_AIMem_Done(pAIMem);
		pAIMem = 0;
	}

	return pAIMem;
}
Exemplo n.º 28
0
PNTFS_FCB
NtfsCreateFCB(PCWSTR FileName,
              PNTFS_VCB Vcb)
{
    PNTFS_FCB Fcb;

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

    Fcb = ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_FCB), TAG_FCB);
    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;
        }
    }

    ExInitializeResourceLite(&Fcb->MainResource);

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

    return Fcb;
}
Exemplo n.º 29
0
EXTERN_C static NTSTATUS LogpInitializeBufferInfo(
    _In_ const wchar_t *LogFilePath, _In_opt_ PDEVICE_OBJECT DeviceObject,
    _Inout_ LogBufferInfo *Info) {
  NT_ASSERT(LogFilePath);
  NT_ASSERT(Info);

  KeInitializeSpinLock(&Info->SpinLock);

  auto status = ExInitializeResourceLite(&Info->Resource);
  if (!NT_SUCCESS(status)) {
    return status;
  }
  Info->ResourceInitialized = true;

  if (DeviceObject) {
    // We can handle IRP_MJ_SHUTDOWN in order to flush buffered log entries.
    status = IoRegisterShutdownNotification(DeviceObject);
    if (!NT_SUCCESS(status)) {
      LogpFinalizeBufferInfo(DeviceObject, Info);
      return status;
    }
  }

  // Allocate two log buffers on NonPagedPool.
  Info->LogBuffer1 = reinterpret_cast<char *>(ExAllocatePoolWithTag(
      NonPagedPoolNx, LOGP_BUFFER_SIZE, LOGP_POOL_TAG_NAME));
  if (!Info->LogBuffer1) {
    LogpFinalizeBufferInfo(DeviceObject, Info);
    return STATUS_INSUFFICIENT_RESOURCES;
  }

  Info->LogBuffer2 = reinterpret_cast<char *>(ExAllocatePoolWithTag(
      NonPagedPoolNx, LOGP_BUFFER_SIZE, LOGP_POOL_TAG_NAME));
  if (!Info->LogBuffer2) {
    LogpFinalizeBufferInfo(DeviceObject, Info);
    return STATUS_INSUFFICIENT_RESOURCES;
  }

  // Initialize these buffers
  RtlFillMemory(Info->LogBuffer1, LOGP_BUFFER_SIZE, 0xff);  // for debug
  Info->LogBuffer1[0] = '\0';
  Info->LogBuffer1[LOGP_BUFFER_SIZE - 1] = '\0';  // at the end

  RtlFillMemory(Info->LogBuffer2, LOGP_BUFFER_SIZE, 0xff);  // for debug
  Info->LogBuffer2[0] = '\0';
  Info->LogBuffer2[LOGP_BUFFER_SIZE - 1] = '\0';  // at the end

  // Buffer should be used is LogBuffer1, and location should be written logs
  // is the head of the buffer.
  Info->LogBufferHead = Info->LogBuffer1;
  Info->LogBufferTail = Info->LogBuffer1;

  // Initialize a log file
  UNICODE_STRING logFilePathU = {};
  RtlInitUnicodeString(&logFilePathU, LogFilePath);

  OBJECT_ATTRIBUTES oa = {};
  InitializeObjectAttributes(&oa, &logFilePathU,
                             OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, nullptr,
                             nullptr);

  IO_STATUS_BLOCK ioStatus = {};
  status = ZwCreateFile(
      &Info->LogFileHandle, FILE_APPEND_DATA | SYNCHRONIZE, &oa, &ioStatus,
      nullptr, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OPEN_IF,
      FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE, nullptr, 0);
  if (!NT_SUCCESS(status)) {
    LogpFinalizeBufferInfo(DeviceObject, Info);
    return status;
  }

  // Initialize a log buffer flush thread.
  Info->BufferFlushThreadShouldBeAlive = true;
  status = PsCreateSystemThread(&Info->BufferFlushThreadHandle, GENERIC_ALL,
                                nullptr, nullptr, nullptr,
                                LogpBufferFlushThreadRoutine, Info);
  if (!NT_SUCCESS(status)) {
    LogpFinalizeBufferInfo(DeviceObject, Info);
    return status;
  }

  return status;
}
Exemplo n.º 30
0
NTSTATUS NTAPI
DriverEntry(PDRIVER_OBJECT DriverObject,
            PUNICODE_STRING RegistryPath)
/*
 * FUNCTION: Called by the system to initalize the driver
 * ARGUMENTS:
 *           DriverObject = object describing this driver
 *           RegistryPath = path to our configuration entries
 * RETURNS: Success or failure
 */
{
  NTSTATUS Status;
  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(DEVICE_NAME);

  TRACE_(NTFS, "DriverEntry(%p, '%wZ')\n", DriverObject, RegistryPath);

  /* Initialize global data */
  NtfsGlobalData = ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_GLOBAL_DATA), 'GRDN');
  if (!NtfsGlobalData)
  {
    Status = STATUS_INSUFFICIENT_RESOURCES;
    goto ErrorEnd;
  }
  RtlZeroMemory(NtfsGlobalData, sizeof(NTFS_GLOBAL_DATA));
  NtfsGlobalData->Identifier.Type = NTFS_TYPE_GLOBAL_DATA;
  NtfsGlobalData->Identifier.Size = sizeof(NTFS_GLOBAL_DATA);
  
  ExInitializeResourceLite(&NtfsGlobalData->Resource);

  /* Keep trace of Driver Object */
  NtfsGlobalData->DriverObject = DriverObject;

  /* Initialize IRP functions array */
  NtfsInitializeFunctionPointers(DriverObject);
  
  /* Initialize CC functions array */
  NtfsGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = NtfsAcqLazyWrite; 
  NtfsGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = NtfsRelLazyWrite; 
  NtfsGlobalData->CacheMgrCallbacks.AcquireForReadAhead = NtfsAcqReadAhead; 
  NtfsGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = NtfsRelReadAhead; 

  /* Driver can't be unloaded */
  DriverObject->DriverUnload = NULL;

  Status = IoCreateDevice(DriverObject,
                          sizeof(NTFS_GLOBAL_DATA),
                          &DeviceName,
                          FILE_DEVICE_DISK_FILE_SYSTEM,
                          0,
                          FALSE,
                          &NtfsGlobalData->DeviceObject);
  if (!NT_SUCCESS(Status))
  {
    WARN_(NTFS, "IoCreateDevice failed with status: %lx\n", Status);
    goto ErrorEnd;
  }
  
  NtfsGlobalData->DeviceObject->Flags |= DO_DIRECT_IO;

  /* Register file system */
  IoRegisterFileSystem(NtfsGlobalData->DeviceObject);
  ObReferenceObject(NtfsGlobalData->DeviceObject);

ErrorEnd:
  if (!NT_SUCCESS(Status))
  {
    if (NtfsGlobalData)
    {
      ExDeleteResourceLite(&NtfsGlobalData->Resource);
      ExFreePoolWithTag(NtfsGlobalData, 'GRDN');
    }
  }

  return Status;
}