co_rc_t co_os_manager_init(co_manager_t *manager, co_osdep_manager_t *osdep) { co_rc_t rc = CO_RC(OK); int i; co_osdep_manager_t dep; *osdep = dep = co_os_malloc(sizeof(*dep)); if (dep == NULL) return CO_RC(OUT_OF_MEMORY); co_global_manager = manager; memset(dep, 0, sizeof(*dep)); co_list_init(&dep->mdl_list); co_list_init(&dep->mapped_allocated_list); co_list_init(&dep->pages_unused); for (i=0; i < PFN_HASH_SIZE; i++) co_list_init(&dep->pages_hash[i]); MmResetDriverPaging(&co_global_manager); rc = co_os_mutex_create(&dep->mutex); setup_host_memory_range(manager, dep); return rc; }
IO_STATUS_BLOCK MsOpenMailslotFileSystem ( IN PVCB Vcb, IN PFILE_OBJECT FileObject, IN ACCESS_MASK DesiredAccess, IN USHORT ShareAccess ) { IO_STATUS_BLOCK iosb; PAGED_CODE(); DebugTrace(+1, Dbg, "MsOpenMailslotFileSystem, Vcb = %08lx\n", (ULONG)Vcb); try { // // Set the new share access // if (!NT_SUCCESS(iosb.Status = IoCheckShareAccess( DesiredAccess, ShareAccess, FileObject, &Vcb->ShareAccess, TRUE ))) { DebugTrace(0, Dbg, "bad share access\n", 0); try_return( NOTHING ); } // // Supply the file object with a referenced pointer to the VCB. // MsAcquireGlobalLock(); MsReferenceNode( &Vcb->Header ); if (Vcb->Header.ReferenceCount == 2) { // // Set the driver paging back to normal // MmResetDriverPaging(MsOpenMailslotFileSystem); } MsReleaseGlobalLock(); MsSetFileObject( FileObject, Vcb, NULL ); // // Set the return status. // iosb.Status = STATUS_SUCCESS; iosb.Information = FILE_OPENED; try_exit: NOTHING; } finally { DebugTrace(-1, Dbg, "MsOpenMailslotFileSystem -> Iosb.Status = %08lx\n", iosb.Status); } // // Return to the caller. // return iosb; }
PFCB MsCreateFcb ( IN PVCB Vcb, IN PDCB ParentDcb, IN PUNICODE_STRING FileName, IN PEPROCESS CreatorProcess, IN ULONG MailslotQuota, IN ULONG MaximumMessageSize ) /*++ Routine Description: This routine allocates, initializes, and inserts a new Fcb record into the in memory data structures. Arguments: Vcb - Supplies the Vcb to associate the new FCB under. ParentDcb - Supplies the parent dcb that the new FCB is under. FileName - Supplies the file name of the file relative to the directory it's in (e.g., the file \config.sys is called "CONFIG.SYS" without the preceding backslash). CreatorProcess - Supplies a pointer to our creator process MailslotQuota - Supplies the initial quota MaximumMessageSize - Supplies the size of the largest message that can be written to the mailslot Return Value: PFCB - Returns a pointer to the newly allocated FCB --*/ { PFCB fcb; PAGED_CODE(); DebugTrace(+1, Dbg, "MsCreateFcb\n", 0); // // Allocate a new FCB record, and zero its fields. // fcb = FsRtlAllocatePool( NonPagedPool, sizeof(FCB) ); RtlZeroMemory( fcb, sizeof(FCB) ); // // Set the proper node type code, node byte size, and reference count. // fcb->Header.NodeTypeCode = MSFS_NTC_FCB; fcb->Header.NodeByteSize = sizeof(FCB); fcb->Header.ReferenceCount = 1; fcb->Header.NodeState = NodeStateActive; // // Insert this FCB into our parent DCB's queue. // InsertTailList( &ParentDcb->Specific.Dcb.ParentDcbQueue, &fcb->ParentDcbLinks ); // // Initialize other FCB fields. // fcb->ParentDcb = ParentDcb; fcb->Vcb = Vcb; MsAcquireGlobalLock(); MsReferenceNode ( &Vcb->Header ); if (Vcb->Header.ReferenceCount == 2) { // // Set the driver paging back to normal // MmResetDriverPaging(MsCreateFcb); } MsReleaseGlobalLock(); fcb->CreatorProcess = CreatorProcess; ExInitializeResource( &(fcb->Resource) ); // // Initialize the CCB queue. // InitializeListHead( &fcb->Specific.Fcb.CcbQueue ); // // Set the file name. // { PWCH Name; ULONG Length; Length = FileName->Length; Name = FsRtlAllocatePool( PagedPool, Length + 2 ); RtlMoveMemory( Name, FileName->Buffer, Length ); *(PWCH)( (PCH)Name + Length ) = L'\0'; RtlInitUnicodeString( &fcb->FullFileName, Name ); RtlInitUnicodeString( &fcb->LastFileName, &Name[1] ); } // // Insert this FCB into the prefix table. // MsAcquirePrefixTableLock(); if (!RtlInsertUnicodePrefix( &Vcb->PrefixTable, &fcb->FullFileName, &fcb->PrefixTableEntry )) { DebugDump("Error trying to name into prefix table\n", 0, fcb); KeBugCheck( MAILSLOT_FILE_SYSTEM ); } MsReleasePrefixTableLock(); // // Initialize the data queue. // MsInitializeDataQueue( &fcb->DataQueue, CreatorProcess, MailslotQuota, MaximumMessageSize); // // Return to the caller. // DebugTrace(-1, Dbg, "MsCreateFcb -> %08lx\n", (ULONG)fcb); return fcb; }
NTSTATUS AWEAllocCreate(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PIO_STACK_LOCATION io_stack = IoGetCurrentIrpStackLocation(Irp); KdPrint(("AWEAlloc: Create.\n")); PAGED_CODE(); io_stack->FileObject->FsContext2 = ExAllocatePoolWithTag(NonPagedPool, sizeof(OBJECT_CONTEXT), POOL_TAG); if (io_stack->FileObject->FsContext2 == NULL) { KdPrint(("AWEAlloc: Pool allocation failed.\n")); Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return STATUS_INSUFFICIENT_RESOURCES; } RtlZeroMemory(io_stack->FileObject->FsContext2, sizeof(OBJECT_CONTEXT)); io_stack->FileObject->Flags |= FO_DELETE_ON_CLOSE | FO_TEMPORARY_FILE; io_stack->FileObject->ReadAccess = TRUE; io_stack->FileObject->WriteAccess = TRUE; io_stack->FileObject->DeleteAccess = TRUE; io_stack->FileObject->SharedRead = TRUE; io_stack->FileObject->SharedWrite = FALSE; io_stack->FileObject->SharedDelete = FALSE; KeInitializeSpinLock (&((POBJECT_CONTEXT)io_stack->FileObject->FsContext2)->IOLock); MmResetDriverPaging((PVOID)(ULONG_PTR)DriverEntry); if (io_stack->FileObject->FileName.Length != 0) { NTSTATUS status; KdPrint(("AWEAlloc: Image file requested: '%.*ws'.\n", (int)(io_stack->FileObject->FileName.Length / sizeof(*io_stack->FileObject->FileName.Buffer)), io_stack->FileObject->FileName.Buffer)); status = AWEAllocLoadImageFile((POBJECT_CONTEXT) io_stack->FileObject->FsContext2, &Irp->IoStatus, &io_stack->FileObject->FileName); IoCompleteRequest(Irp, IO_NO_INCREMENT); KdPrint(("AWEAlloc: Image file status: %#x.\n", status)); if (!NT_SUCCESS(status)) AWEAllocLogError(AWEAllocDriverObject, 0, 0, NULL, 0, 4000, status, 401, status, 0, 0, NULL, L"Image file failed."); return status; } Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return STATUS_SUCCESS; }