Example #1
0
/*
 * @implemented
 */
PVOID
NTAPI
IoAllocateErrorLogEntry(IN PVOID IoObject,
                        IN UCHAR EntrySize)
{
    PERROR_LOG_ENTRY LogEntry;
    ULONG LogEntrySize;
    PDEVICE_OBJECT DeviceObject;
    PDRIVER_OBJECT DriverObject;

    /* Make sure we have an object */
    if (!IoObject) return NULL;

    /* Check if we're past our buffer */
    if (IopTotalLogSize > PAGE_SIZE) return NULL;

    /* Check if this is a device object or driver object */
    if (((PDEVICE_OBJECT)IoObject)->Type == IO_TYPE_DEVICE)
    {
        /* It's a device, get the driver */
        DeviceObject = (PDEVICE_OBJECT)IoObject;
        DriverObject = DeviceObject->DriverObject;
    }
    else if (((PDEVICE_OBJECT)IoObject)->Type == IO_TYPE_DRIVER)
    {
        /* It's a driver, so we don't have a device */
        DeviceObject = NULL;
        DriverObject = (PDRIVER_OBJECT)IoObject;
    }
    else
    {
        /* Fail */
        return NULL;
    }

    /* Calculate the total size and allocate it */
    LogEntrySize = sizeof(ERROR_LOG_ENTRY) + EntrySize;
    LogEntry = ExAllocatePoolWithTag(NonPagedPool,
                                     LogEntrySize,
                                     TAG_ERROR_LOG);
    if (!LogEntry) return NULL;

    /* Reference the Objects */
    if (DeviceObject) ObReferenceObject(DeviceObject);
    if (DriverObject) ObReferenceObject(DriverObject);

    /* Update log size */
    InterlockedExchangeAdd(&IopTotalLogSize, EntrySize);

    /* Clear the entry and set it up */
    RtlZeroMemory(LogEntry, EntrySize);
    LogEntry->Type = IO_TYPE_ERROR_LOG;
    LogEntry->Size = EntrySize;
    LogEntry->DeviceObject = DeviceObject;
    LogEntry->DriverObject = DriverObject;

    /* Return the entry data */
    return (PVOID)((ULONG_PTR)LogEntry + sizeof(ERROR_LOG_ENTRY));
}
Example #2
0
static PDEVICE_OBJECT
IopTraverseDeviceNode(PDEVICE_NODE Node, PUNICODE_STRING DeviceInstance)
{
    PDEVICE_OBJECT DeviceObject;
    PDEVICE_NODE ChildNode;

    if (RtlEqualUnicodeString(&Node->InstancePath,
                              DeviceInstance, TRUE))
    {
        ObReferenceObject(Node->PhysicalDeviceObject);
        return Node->PhysicalDeviceObject;
    }

    /* Traversal of all children nodes */
    for (ChildNode = Node->Child;
         ChildNode != NULL;
         ChildNode = ChildNode->Sibling)
    {
        DeviceObject = IopTraverseDeviceNode(ChildNode, DeviceInstance);
        if (DeviceObject != NULL)
        {
            return DeviceObject;
        }
    }

    return NULL;
}
Example #3
0
NTSTATUS PPJoyBus_JoyDevRelations (IN PJOY_DEVICE_DATA JoyDeviceData, IN PIRP Irp)
{
 PDEVICE_RELATIONS	DeviceRelations;
 NTSTATUS			ntStatus;

 PAGED_CODE ();

 switch (IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryDeviceRelations.Type)
 {
  case TargetDeviceRelation:  
		DeviceRelations= (PDEVICE_RELATIONS) ExAllocatePoolWithTag (PagedPool,sizeof(DEVICE_RELATIONS),PPJOYBUS_POOL_TAG);
		if (!DeviceRelations)
		{
		 ntStatus= STATUS_INSUFFICIENT_RESOURCES;
		 break;
		}
		DeviceRelations->Count= 1;
		DeviceRelations->Objects[0]= JoyDeviceData->Self;
		ObReferenceObject (JoyDeviceData->Self);

		ntStatus = STATUS_SUCCESS;
		Irp->IoStatus.Information= (ULONG_PTR) DeviceRelations;
		break;
        
  case BusRelations:
  case EjectionRelations:
  case RemovalRelations:
  default:
		ntStatus= Irp->IoStatus.Status;
 }

 return ntStatus;
}
Example #4
0
static NTSTATUS
XenM2BPdoQueryDeviceRelations(PXENM2B_PDO_EXTENSION pPdoExt,
                              PIRP pIrp)
{
    PIO_STACK_LOCATION pIrpStack;
    PDEVICE_RELATIONS  pRelations;
    DEVICE_RELATION_TYPE Type;

    pIrpStack = IoGetCurrentIrpStackLocation(pIrp);
    Type = pIrpStack->Parameters.QueryDeviceRelations.Type;
    if (Type != TargetDeviceRelation) {
        TraceDebug(("%s: Relations Type: %d\n", __FUNCTION__, Type));
        return STATUS_SUCCESS;
    }

    if (XenM2BGetPnPState(&pPdoExt->DevicePnPState) == PnPStateDeleted) {
        TraceDebug(("%s: Target deleted\n", __FUNCTION__));
        return STATUS_NO_SUCH_DEVICE;
    }

    pRelations = ExAllocatePoolWithTag(PagedPool,
                                       sizeof(DEVICE_RELATIONS),
                                       XENM2B_POOL_TAG);
    if (pRelations == NULL) {
        TraceDebug(("%s: Relations alloc failed\n", __FUNCTION__));
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    pRelations->Count = 1;
    pRelations->Objects[0] = pPdoExt->pDevice;
    ObReferenceObject(pPdoExt->pDevice);

    pIrp->IoStatus.Information = (ULONG_PTR)pRelations;
    return STATUS_SUCCESS;
}
Example #5
0
NTKERNELAPI
PVOID
FASTCALL
ObFastReferenceObjectLocked (
    IN PEX_FAST_REF FastRef
    )
/*++

Routine Description:

    This routine does a slow object reference. This must be called while
    holding a lock.

Arguments:

    FastRef - Rundown block to be used to reference the object

Return Value:

    PVOID - Object that was referenced or NULL if there was no object.

--*/
{
    PVOID Object;
    EX_FAST_REF OldRef;

    OldRef = *FastRef;
    Object = ExFastRefGetObject (OldRef);
    if (Object != NULL) {
        ObReferenceObject (Object);
    }
    return Object;
}
Example #6
0
//载自ReactOS-0.3.4-REL-src
PETHREAD
NTAPI
GetNextProcessThread(IN PEPROCESS Process,
					 IN PETHREAD Thread OPTIONAL)
{
    PETHREAD FoundThread = NULL;
    PLIST_ENTRY ListHead, Entry;
    PAGED_CODE();
    
    if (Thread)
    {
		//  Entry = Thread->ThreadListEntry.Flink;;//   +0x22c ThreadListEntry  : _LIST_ENTRY
		Entry = (PLIST_ENTRY)((ULONG)(Thread)+0x224);
		Entry=Entry->Flink;
    }
    else
    {
        Entry = (PLIST_ENTRY)((ULONG)(Process)+0x180);//+0x190 ThreadListHead   : _LIST_ENTRY
        Entry = Entry->Flink; 
    }
	// ListHead = &Process->ThreadListHead;
	ListHead = (PLIST_ENTRY)((ULONG)Process + 0x180);
    while (ListHead != Entry)
    {
		//   FoundThread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
		FoundThread = (PETHREAD)((ULONG)Entry - 0x224);
		//    if (ObReferenceObjectSafe(FoundThread)) break;
		if (ObReferenceObject(FoundThread)) break;
        FoundThread = NULL;
        Entry = Entry->Flink;
    }
    if (Thread) ObDereferenceObject(Thread);
    return FoundThread;
}
Example #7
0
void STDCALL flush_thread(void* context) {
    DEVICE_OBJECT* devobj = context;
    device_extension* Vcb = devobj->DeviceExtension;
    LARGE_INTEGER due_time;
    
    ObReferenceObject(devobj);
    
    KeInitializeTimer(&Vcb->flush_thread_timer);
    
    due_time.QuadPart = -INTERVAL * 10000;
    
    KeSetTimer(&Vcb->flush_thread_timer, due_time, NULL);
    
    while (TRUE) {
        KeWaitForSingleObject(&Vcb->flush_thread_timer, Executive, KernelMode, FALSE, NULL);

        if (!(devobj->Vpb->Flags & VPB_MOUNTED) || Vcb->removing)
            break;
            
        do_flush(Vcb);
        
        KeSetTimer(&Vcb->flush_thread_timer, due_time, NULL);
    }
    
    ObDereferenceObject(devobj);
    KeCancelTimer(&Vcb->flush_thread_timer);
    
    KeSetEvent(&Vcb->flush_thread_finished, 0, FALSE);
    
    PsTerminateSystemThread(STATUS_SUCCESS);
}
Example #8
0
//
//	Increment the reference count to a PDO.
//
PPDO_DEVICE_DATA
LookupPdoData(
	PFDO_DEVICE_DATA	FdoData,
	ULONG				SystemIoBusNumber
	)
{
	PPDO_DEVICE_DATA	pdoData = NULL;
    PLIST_ENTRY         entry;

    PAGED_CODE ();

    KeEnterCriticalRegion();
	ExAcquireFastMutex (&FdoData->Mutex);

    for (entry = FdoData->ListOfPDOs.Flink;
         entry != &FdoData->ListOfPDOs;
         entry = entry->Flink) {

			 pdoData = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link);
             if(pdoData->SlotNo == SystemIoBusNumber)
				 break;
			pdoData = NULL;
		 }
	 if(pdoData) {
		 //
		 //	increment the reference count to the PDO.
		 //
		 ObReferenceObject(pdoData->Self);
	 }

	ExReleaseFastMutex (&FdoData->Mutex);
    KeLeaveCriticalRegion();

	return pdoData;
}
Example #9
0
NTSTATUS NTAPI
IntVideoPortChildQueryRelations(
    IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension,
    IN PIRP Irp,
    IN PIO_STACK_LOCATION IrpSp)
{
    PDEVICE_RELATIONS DeviceRelations;

    if (IrpSp->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
    {
        WARN_(VIDEOPRT, "Unsupported device relations type\n");
        return Irp->IoStatus.Status;
    }

    DeviceRelations = ExAllocatePool(NonPagedPool, sizeof(DEVICE_RELATIONS));
    if (!DeviceRelations) return STATUS_NO_MEMORY;

    DeviceRelations->Count = 1;
    DeviceRelations->Objects[0] = ChildExtension->PhysicalDeviceObject;

    ObReferenceObject(DeviceRelations->Objects[0]);

    Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;

    return STATUS_SUCCESS;
}
Example #10
0
VOID
NTAPI
CcScheduleReadAhead(IN PFILE_OBJECT FileObject,
                    IN PLARGE_INTEGER FileOffset,
                    IN ULONG Length)
{
    PWORK_QUEUE_WITH_READ_AHEAD WorkItem;

    DPRINT("Schedule read ahead %08x%08x:%x %wZ\n",
           FileOffset->HighPart,
           FileOffset->LowPart,
           Length,
           &FileObject->FileName);

    WorkItem = ExAllocatePool(NonPagedPool, sizeof(*WorkItem));
    if (!WorkItem) KeBugCheck(0);
    ObReferenceObject(FileObject);
    WorkItem->FileObject = FileObject;
    WorkItem->FileOffset = *FileOffset;
    WorkItem->Length = Length;

    ExInitializeWorkItem(((PWORK_QUEUE_ITEM)WorkItem),
                         (PWORKER_THREAD_ROUTINE)CcpReadAhead,
                         WorkItem);

    ExQueueWorkItem((PWORK_QUEUE_ITEM)WorkItem, DelayedWorkQueue);
    DPRINT("Done\n");
}
static NTSTATUS vboxNewProtDeviceRemoved(PVBOXMOUSE_DEVEXT pDevExt)
{
    if (!vboxNewProtIsEnabled())
    {
        WARN(("New Protocol is disabled"));
        return STATUS_UNSUCCESSFUL;
    }

    KIRQL Irql;
    NTSTATUS Status = STATUS_SUCCESS;
    KeAcquireSpinLock(&g_ctx.SyncLock, &Irql);
    RemoveEntryList(&pDevExt->ListEntry);
    if (g_ctx.pCurrentDevExt == pDevExt)
    {
        ObDereferenceObject(pDevExt->pdoSelf);
        g_ctx.pCurrentDevExt = NULL;
        for (PLIST_ENTRY pCur = g_ctx.DevExtList.Flink; pCur != &g_ctx.DevExtList; pCur = pCur->Flink)
        {
            PVBOXMOUSE_DEVEXT pNewCurDevExt = PVBOXMOUSE_DEVEXT_FROM_LE(pCur);
            ASMAtomicWritePtr(&g_ctx.pCurrentDevExt, pNewCurDevExt);
            /* ensure the object is not deleted while it is being used by a poller thread */
            ObReferenceObject(pNewCurDevExt->pdoSelf);
            break;
        }
    }

    KeReleaseSpinLock(&g_ctx.SyncLock, Irql);

    return Status;
}
Example #12
0
File: Irp.cpp Project: daynix/UsbDk
NTSTATUS CIoControlIrp::Create(PDEVICE_OBJECT TargetDevice,
                               ULONG IoControlCode,
                               bool IsInternal,
                               PVOID InputBuffer,
                               ULONG InputBufferLength,
                               PVOID OutputBuffer,
                               ULONG OutputBufferLength)
{
    m_Irp = IoBuildDeviceIoControlRequest(IoControlCode,
                                          TargetDevice,
                                          InputBuffer,
                                          InputBufferLength,
                                          OutputBuffer,
                                          OutputBufferLength,
                                          IsInternal ? TRUE : FALSE,
                                          m_Event,
                                          &m_IoControlStatus);

    if (m_Irp == nullptr)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    ObReferenceObject(TargetDevice);
    m_TargetDevice = TargetDevice;
    return STATUS_SUCCESS;
}
VOID
GetDosDeviceName(PDEVICE_OBJECT pDeviceObject,
				 PUNICODE_STRING pShareName,
				 PUNICODE_STRING pDosName)
{
	NTSTATUS status;
	UNICODE_STRING tempDosDrive;

	ObReferenceObject(pDeviceObject);

	status = IoVolumeDeviceToDosName(
		(PVOID)pDeviceObject,
		&tempDosDrive);

	pDosName->Length = 0;

	if(NT_SUCCESS(status))
	{
		int i = 0;
		int wchars = tempDosDrive.Length/2;
		int pos = 0;
		
		pDosName->MaximumLength = tempDosDrive.MaximumLength + 2;
		pDosName->Buffer = ExAllocatePoolWithTag(NonPagedPool, pDosName->MaximumLength, FILE_POOL_TAG);
		
		if(pDosName->Buffer != NULL)
		{
			pDosName->Buffer[pos++] = '\\';
			pDosName->Length += sizeof(WCHAR);
			for(i = 0; i < wchars; i++)
			{
				if(tempDosDrive.Buffer[i] != 0x003A)
				{
					pDosName->Buffer[pos++] = tempDosDrive.Buffer[i];
					pDosName->Length += sizeof(WCHAR); // Unicode is 2-bytes
				}
			}
			ExFreePool(tempDosDrive.Buffer);
		}
	} else {
		if(pShareName != NULL)
		{
			pDosName->MaximumLength = pShareName->MaximumLength;
			pDosName->Buffer = ExAllocatePoolWithTag(NonPagedPool, pDosName->MaximumLength, FILE_POOL_TAG);
			if(pDosName->Buffer != NULL)
			{
				RtlUnicodeStringCopy(pDosName, pShareName);
			}
		} else {
			pDosName->MaximumLength = 30; // Dont change this
			pDosName->Buffer = ExAllocatePoolWithTag(NonPagedPool, pDosName->MaximumLength, FILE_POOL_TAG);
			if(pDosName->Buffer != NULL)
			{
				RtlUnicodeStringCatString(pDosName, L"\\UNKNOWN DRIVE");
			}
		}
	}
	ObDereferenceObject(pDeviceObject);
}
Example #14
0
VOID
InitCsrProcess(VOID /*IN PEPROCESS CsrProcess*/)
{
    /* Save the EPROCESS of CSRSS */
    gpepCSRSS = PsGetCurrentProcess();
    // gpepCSRSS = CsrProcess;
    ObReferenceObject(gpepCSRSS);
}
Example #15
0
VOID
ExpShutdownWorker (
    IN PVOID Parameter
    )
{
    PETHREAD CurrentThread;
    PSHUTDOWN_WORK_ITEM  ShutdownItem;

    ShutdownItem = (PSHUTDOWN_WORK_ITEM) Parameter;

    ASSERT (ShutdownItem != NULL);

    if (ShutdownItem->PrevThread != NULL) {

        //
        // Wait for the previous thread to exit -- if it's in the same
        // queue, it probably has already, but we need to make sure
        // (and if it's not, we *definitely* need to make sure).
        //

        KeWaitForSingleObject (ShutdownItem->PrevThread,
                               Executive,
                               KernelMode,
                               FALSE,
                               NULL);

        ObDereferenceObject (ShutdownItem->PrevThread);

        ShutdownItem->PrevThread = NULL;
    }

    //
    // Decrement the worker count.
    //

    InterlockedDecrement (&ExWorkerQueue[ShutdownItem->QueueType].Info.QueueWorkerInfo);

    CurrentThread = PsGetCurrentThread();

    if ((!ExpCheckQueueShutdown(DelayedWorkQueue, ShutdownItem)) &&
        (!ExpCheckQueueShutdown(CriticalWorkQueue, ShutdownItem))) {

        //
        // We're the last worker to exit
        //

        ASSERT (!ExpLastWorkerThread);
        ExpLastWorkerThread = CurrentThread;
        ObReferenceObject (ExpLastWorkerThread);
        KeSetEvent (&ExpThreadSetManagerShutdownEvent, 0, FALSE);
    }

    KeSetKernelStackSwapEnable (TRUE);
    CurrentThread->ActiveExWorker = 0;

    PsTerminateSystemThread (STATUS_SYSTEM_SHUTDOWN);
}
Example #16
0
File: fdo.c Project: GYGit/reactos
NTSTATUS
HidClassFDO_CopyDeviceRelations(
    IN PDEVICE_OBJECT DeviceObject,
    OUT PDEVICE_RELATIONS *OutRelations)
{
    PDEVICE_RELATIONS DeviceRelations;
    PHIDCLASS_FDO_EXTENSION FDODeviceExtension;
    ULONG Index;

    //
    // get device extension
    //
    FDODeviceExtension = DeviceObject->DeviceExtension;
    ASSERT(FDODeviceExtension->Common.IsFDO);

    //
    // allocate result
    //
    DeviceRelations = ExAllocatePoolWithTag(NonPagedPool,
                                            sizeof(DEVICE_RELATIONS) + (FDODeviceExtension->DeviceRelations->Count - 1) * sizeof(PDEVICE_OBJECT),
                                            HIDCLASS_TAG);
    if (!DeviceRelations)
    {
        //
        // no memory
        //
        *OutRelations = NULL;
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    //
    // copy device objects
    //
    for (Index = 0; Index < FDODeviceExtension->DeviceRelations->Count; Index++)
    {
        //
        // reference pdo
        //
        ObReferenceObject(FDODeviceExtension->DeviceRelations->Objects[Index]);

        //
        // store object
        //
        DeviceRelations->Objects[Index] = FDODeviceExtension->DeviceRelations->Objects[Index];
    }

    //
    // set object count
    //
    DeviceRelations->Count = FDODeviceExtension->DeviceRelations->Count;

    //
    // store result
    //
    *OutRelations = DeviceRelations;
    return STATUS_SUCCESS;
}
Example #17
0
/*
 * @implemented
 */
VOID
NTAPI
IopShutdownBaseFileSystems(IN PLIST_ENTRY ListHead)
{
    PLIST_ENTRY ListEntry;
    PDEVICE_OBJECT DeviceObject;
    IO_STATUS_BLOCK StatusBlock;
    PIRP Irp;
    KEVENT Event;
    NTSTATUS Status;

    KeInitializeEvent(&Event, NotificationEvent, FALSE);

    /* Get the first entry and start looping */
    ListEntry = ListHead->Flink;
    while (ListEntry != ListHead)
    {
        /* Get the device object */
        DeviceObject = CONTAINING_RECORD(ListEntry,
                                         DEVICE_OBJECT,
                                         Queue.ListEntry);

        ObReferenceObject(DeviceObject);
        IopInterlockedIncrementUlong(LockQueueIoDatabaseLock, (PULONG)&DeviceObject->ReferenceCount);

        /* Check if we're attached */
        if (DeviceObject->AttachedDevice)
        {
            /* Get the attached device */
            DeviceObject = IoGetAttachedDevice(DeviceObject);
        }

        /* Build the shutdown IRP and call the driver */
        Irp = IoBuildSynchronousFsdRequest(IRP_MJ_SHUTDOWN,
                                           DeviceObject,
                                           NULL,
                                           0,
                                           NULL,
                                           &Event,
                                           &StatusBlock);
        Status = IoCallDriver(DeviceObject, Irp);
        if (Status == STATUS_PENDING)
        {
            /* Wait on the driver */
            KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
        }

        /* Reset the event */
        KeClearEvent(&Event);

        IopDecrementDeviceObjectRef(DeviceObject, FALSE);
        ObDereferenceObject(DeviceObject);

        /* Go to the next entry */
        ListEntry = ListEntry->Flink;
    }
}
NTSTATUS
ImScsiGetControllerObject()
{
    PDEVICE_OBJECT dev_obj;

    if (pMPDrvInfoGlobal->ControllerObject != NULL)
    {
        return STATUS_SUCCESS;
    }

    KdBreakPoint();

    for (dev_obj = pMPDrvInfoGlobal->pDriverObj->DeviceObject;
        dev_obj != NULL;
#pragma warning(suppress: 28175)
        dev_obj = dev_obj->NextDevice)
    {
        if (dev_obj->DeviceType == FILE_DEVICE_CONTROLLER)
        {
            ObReferenceObject(dev_obj);

            pMPDrvInfoGlobal->ControllerObject = dev_obj;

#if DBG
            {
                POBJECT_NAME_INFORMATION objstr = (POBJECT_NAME_INFORMATION)
                    ExAllocatePoolWithTag(NonPagedPool,
                        1024, MP_TAG_GENERAL);

                if (objstr != NULL)
                {
                    ULONG retl;
                    NTSTATUS status;

                    status = ObQueryNameString(pMPDrvInfoGlobal->ControllerObject,
                        objstr, 1024, &retl);

                    if (NT_SUCCESS(status))
                    {
                        DbgPrint("PhDskMnt::ImScsiGetControllerObject: Successfully opened '%wZ'.\n",
                            &objstr->Name);
                    }

                    ExFreePoolWithTag(objstr, MP_TAG_GENERAL);
                }
            }
#endif

            return STATUS_SUCCESS;
        }
    }
    

    DbgPrint("PhDskMnt::ImScsiGetControllerObject: Could not locate SCSI adapter device object by name.\n");

    return STATUS_DEVICE_DOES_NOT_EXIST;
}
Example #19
0
static NTSTATUS create_part0(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT DeviceObject, PUNICODE_STRING pardir, PUNICODE_STRING nameus,
                             BTRFS_UUID* uuid) {
    PDEVICE_OBJECT newdevobj;
    UNICODE_STRING name;
    NTSTATUS Status;
    part0_device_extension* p0de;
    
    static const WCHAR btrfs_partition[] = L"\\BtrfsPartition";
    
    name.Length = name.MaximumLength = pardir->Length + (wcslen(btrfs_partition) * sizeof(WCHAR));
    name.Buffer = ExAllocatePoolWithTag(PagedPool, name.Length, ALLOC_TAG);
    if (!name.Buffer) {
        ERR("out of memory\n");
        return STATUS_INSUFFICIENT_RESOURCES;
    }
    
    RtlCopyMemory(name.Buffer, pardir->Buffer, pardir->Length);
    RtlCopyMemory(&name.Buffer[pardir->Length / sizeof(WCHAR)], btrfs_partition, wcslen(btrfs_partition) * sizeof(WCHAR));
    
    Status = IoCreateDevice(DriverObject, sizeof(part0_device_extension), &name, FILE_DEVICE_DISK, FILE_DEVICE_SECURE_OPEN, FALSE, &newdevobj);
    if (!NT_SUCCESS(Status)) {
        ERR("IoCreateDevice returned %08x\n", Status);
        ExFreePool(name.Buffer);
        return Status;
    }
    
    p0de = newdevobj->DeviceExtension;
    p0de->type = VCB_TYPE_PARTITION0;
    p0de->devobj = DeviceObject;
    RtlCopyMemory(&p0de->uuid, uuid, sizeof(BTRFS_UUID));
    
    p0de->name.Length = name.Length;
    p0de->name.MaximumLength = name.MaximumLength;
    p0de->name.Buffer = ExAllocatePoolWithTag(PagedPool, p0de->name.MaximumLength, ALLOC_TAG);
    
    if (!p0de->name.Buffer) {
        ERR("out of memory\b");
        ExFreePool(name.Buffer);
        ExFreePool(p0de->name.Buffer);
        IoDeleteDevice(newdevobj);
        return STATUS_INSUFFICIENT_RESOURCES;
    }
    
    RtlCopyMemory(p0de->name.Buffer, name.Buffer, name.Length);
    
    ObReferenceObject(DeviceObject);
    
    newdevobj->StackSize = DeviceObject->StackSize + 1;
    
    newdevobj->Flags |= DO_DIRECT_IO;
    newdevobj->Flags &= ~DO_DEVICE_INITIALIZING;
    
    *nameus = name;
    
    return STATUS_SUCCESS;
}
Example #20
0
static PROSSYM_KM_OWN_CONTEXT
KdbpCaptureFileForSymbols(PFILE_OBJECT FileObject)
{
    PROSSYM_KM_OWN_CONTEXT Context = ExAllocatePool(NonPagedPool, sizeof(*Context));
    if (!Context) return NULL;
    ObReferenceObject(FileObject);
    Context->FileOffset.QuadPart = 0;
    Context->FileObject = FileObject;
    return Context;
}
Example #21
0
NTSTATUS
DokanCreateGlobalDiskDevice(
	__in PDRIVER_OBJECT DriverObject,
	__out PDOKAN_GLOBAL* DokanGlobal
	)
{
	WCHAR	deviceNameBuf[] = DOKAN_GLOBAL_DEVICE_NAME; 
	WCHAR	symbolicLinkBuf[] = DOKAN_GLOBAL_SYMBOLIC_LINK_NAME;
	NTSTATUS		status;
	UNICODE_STRING	deviceName;
	UNICODE_STRING	symbolicLinkName;
	PDEVICE_OBJECT	deviceObject;
	PDOKAN_GLOBAL	dokanGlobal;

	RtlInitUnicodeString(&deviceName, deviceNameBuf);
	RtlInitUnicodeString(&symbolicLinkName, symbolicLinkBuf);

	status = IoCreateDeviceSecure(
				DriverObject,		// DriverObject
				sizeof(DOKAN_GLOBAL),// DeviceExtensionSize
				&deviceName,		// DeviceName
				FILE_DEVICE_UNKNOWN,// DeviceType
				0,					// DeviceCharacteristics
				FALSE,				// Not Exclusive
				&sddl, // Default SDDL String
				NULL,				// Device Class GUID
				&deviceObject);		// DeviceObject

	if (!NT_SUCCESS(status)) {
		DDbgPrint("  IoCreateDevice returned 0x%x\n", status);
		return status;
	}
	DDbgPrint("DokanGlobalDevice: %wZ created\n", &deviceName);
	ObReferenceObject(deviceObject);

	status = IoCreateSymbolicLink(&symbolicLinkName, &deviceName);
	if (!NT_SUCCESS(status)) {
		DDbgPrint("  IoCreateSymbolicLink returned 0x%x\n", status);
		IoDeleteDevice(deviceObject);
		return status;
	}
	DDbgPrint("SymbolicLink: %wZ -> %wZ created\n", &deviceName, &symbolicLinkName);
	dokanGlobal = deviceObject->DeviceExtension;
	dokanGlobal->DeviceObject = deviceObject;

	RtlZeroMemory(dokanGlobal, sizeof(DOKAN_GLOBAL));
	DokanInitIrpList(&dokanGlobal->PendingService);
	DokanInitIrpList(&dokanGlobal->NotifyService);

	dokanGlobal->Identifier.Type = DGL;
	dokanGlobal->Identifier.Size = sizeof(DOKAN_GLOBAL);

	*DokanGlobal = dokanGlobal;
	return STATUS_SUCCESS;
}
Example #22
0
NTSTATUS
USBSTOR_PdoHandleDeviceRelations(
    IN PDEVICE_OBJECT DeviceObject,
    IN OUT PIRP Irp)
{
    PDEVICE_RELATIONS DeviceRelations;
    PIO_STACK_LOCATION IoStack;

    DPRINT("USBSTOR_PdoHandleDeviceRelations\n");

    //
    // get current irp stack location
    //
    IoStack = IoGetCurrentIrpStackLocation(Irp);

    //
    // check if relation type is BusRelations
    //
    if (IoStack->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
    {
        //
        // PDO handles only target device relation
        //
        return Irp->IoStatus.Status;
    }

    //
    // allocate device relations
    //
    DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS));
    if (!DeviceRelations)
    {
        //
        // no memory
        //
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    //
    // initialize device relations
    //
    DeviceRelations->Count = 1;
    DeviceRelations->Objects[0] = DeviceObject;
    ObReferenceObject(DeviceObject);

    //
    // store result
    //
    Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;

    //
    // completed successfully
    //
    return STATUS_SUCCESS;
}
Example #23
0
NTSTATUS DriverEntry(
	__in PDRIVER_OBJECT DriverObject,
	__in PUNICODE_STRING RegistryPath
	)
{
	UNICODE_STRING CfixkrName = RTL_CONSTANT_STRING( CFIXKR_DEVICE_NT_NAME );
	PFILE_OBJECT File;
	PDEVICE_OBJECT CfixkrObject;
	NTSTATUS Status;

	UNREFERENCED_PARAMETER( RegistryPath );

	KdPrint( ( "CFIXDRV: DriverEntry of test driver\n" ) );

	//
	// Install dispatch routines.
	//
	DriverObject->MajorFunction[ IRP_MJ_CREATE ]	= CfixkDrvNotImplemented;
	DriverObject->MajorFunction[ IRP_MJ_CLOSE ]		= CfixkDrvNotImplemented;
	DriverObject->DriverUnload						= CfixkDrvUnload;

	//
	// Lookup cfixkr and obtain interface.
	//
	Status = IoGetDeviceObjectPointer(
		&CfixkrName,
		FILE_WRITE_DATA,
		&File,
		&CfixkrObject );
	if ( ! NT_SUCCESS( Status ) )
	{
		KdPrint( ( "CFIX: Failed to obtain pointer to cfixkr device\n" ) );
		return Status;
	}

	Status = CfixkDrvQueryReporter( CfixkrObject );
	if ( NT_SUCCESS( Status ) )
	{
		//
		// Keep a reference to the device to lock the driver in
		// memory until we have released the interface.
		//
		ObReferenceObject( CfixkrObject );
		CfixkDrvCfixkrDevice = CfixkrObject;
	}

	//
	// We have obtained the interface, which is referenced. We can thus
	// release File while having locked the DO through the interface.
	//
	ObDereferenceObject( File );

	return Status; 
}
Example #24
0
File: fdo.c Project: GYGit/reactos
NTSTATUS
NTAPI
IsaFdoQueryDeviceRelations(
  IN PISAPNP_FDO_EXTENSION FdoExt,
  IN PIRP Irp,
  IN PIO_STACK_LOCATION IrpSp)
{
  NTSTATUS Status;
  PLIST_ENTRY CurrentEntry;
  PISAPNP_LOGICAL_DEVICE IsaDevice;
  PDEVICE_RELATIONS DeviceRelations;
  KIRQL OldIrql;
  ULONG i = 0;

  if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
      return Irp->IoStatus.Status;

  KeAcquireSpinLock(&FdoExt->Lock, &OldIrql);

  Status = IsaHwFillDeviceList(FdoExt);
  if (!NT_SUCCESS(Status))
  {
      KeReleaseSpinLock(&FdoExt->Lock, OldIrql);
      return Status;
  }

  DeviceRelations = ExAllocatePool(NonPagedPool,
                            sizeof(DEVICE_RELATIONS) + sizeof(DEVICE_OBJECT) * (FdoExt->DeviceCount - 1));
  if (!DeviceRelations)
  {
      KeReleaseSpinLock(&FdoExt->Lock, OldIrql);
      return STATUS_INSUFFICIENT_RESOURCES;
  }

  CurrentEntry = FdoExt->DeviceListHead.Flink;
  while (CurrentEntry != &FdoExt->DeviceListHead)
  {
     IsaDevice = CONTAINING_RECORD(CurrentEntry, ISAPNP_LOGICAL_DEVICE, ListEntry);

     DeviceRelations->Objects[i++] = IsaDevice->Common.Self;

     ObReferenceObject(IsaDevice->Common.Self);

     CurrentEntry = CurrentEntry->Flink;
  }

  DeviceRelations->Count = FdoExt->DeviceCount;

  KeReleaseSpinLock(&FdoExt->Lock, OldIrql);

  Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;

  return STATUS_SUCCESS;
}
Example #25
0
NTSTATUS
PsReferenceProcessFilePointer (
    IN PEPROCESS Process,
    OUT PVOID *OutFileObject
    )

/*++

Routine Description:

    This routine returns a referenced pointer to the FilePointer of Process.  
    This is a rundown protected wrapper around MmGetFileObjectForSection.

Arguments:

    Process - Supplies the process to query.

    OutFileObject - Returns the file object backing the requested section if
                    success is returned.

Return Value:

    NTSTATUS.
    
Environment:

    Kernel mode, PASSIVE_LEVEL.

--*/

{
    PFILE_OBJECT FileObject;

    PAGED_CODE();
    
    if (!ExAcquireRundownProtection (&Process->RundownProtect)) {
        return STATUS_UNSUCCESSFUL;
    }

    if (Process->SectionObject == NULL) {
        ExReleaseRundownProtection (&Process->RundownProtect);
        return STATUS_UNSUCCESSFUL;
    }

    FileObject = MmGetFileObjectForSection ((PVOID)Process->SectionObject);

    *OutFileObject = FileObject;

    ObReferenceObject (FileObject);

    ExReleaseRundownProtection (&Process->RundownProtect);

    return STATUS_SUCCESS;
}
Example #26
0
static NTSTATUS bus_query_device_relations(PIRP Irp) {
    NTSTATUS Status;
    ULONG num_children;
    LIST_ENTRY* le;
    ULONG drsize, i;
    DEVICE_RELATIONS* dr;

    ExAcquireResourceSharedLite(&pdo_list_lock, TRUE);

    num_children = 0;

    le = pdo_list.Flink;
    while (le != &pdo_list) {
        num_children++;

        le = le->Flink;
    }

    drsize = offsetof(DEVICE_RELATIONS, Objects[0]) + (num_children * sizeof(PDEVICE_OBJECT));
    dr = ExAllocatePoolWithTag(PagedPool, drsize, ALLOC_TAG);

    if (!dr) {
        ERR("out of memory\n");
        Status = STATUS_INSUFFICIENT_RESOURCES;
        goto end;
    }

    dr->Count = num_children;

    i = 0;
    le = pdo_list.Flink;
    while (le != &pdo_list) {
        pdo_device_extension* pdode = CONTAINING_RECORD(le, pdo_device_extension, list_entry);

        ObReferenceObject(pdode->pdo);
        dr->Objects[i] = pdode->pdo;
        i++;

        le = le->Flink;
    }

    Irp->IoStatus.Information = (ULONG_PTR)dr;

    Status = STATUS_SUCCESS;

end:
    ExReleaseResourceLite(&pdo_list_lock);

    Irp->IoStatus.Status = Status;
    IoCompleteRequest(Irp, IO_NO_INCREMENT);

    return Status;
}
Example #27
0
NTSTATUS
UsbhubFdoQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS* pDeviceRelations)
{
    PHUB_DEVICE_EXTENSION DeviceExtension;
    PDEVICE_RELATIONS DeviceRelations;
    ULONG i;
    ULONG Children = 0;
    ULONG NeededSize;

    DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
    DPRINT1("USBHUB: Query Bus Relations\n");

    /* Create PDOs that are missing */
    for (i = 0; i < USB_MAXCHILDREN; i++)
    {

        if (DeviceExtension->UsbChildren[i] == NULL)
        {
            continue;
        }
        Children++;
    }

    /* Fill returned structure */
    NeededSize = sizeof(DEVICE_RELATIONS);
    if (Children > 1)
        NeededSize += (Children - 1) * sizeof(PDEVICE_OBJECT);

    DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePool(PagedPool,
                                                        NeededSize);

    if (!DeviceRelations)
        return STATUS_INSUFFICIENT_RESOURCES;
    DeviceRelations->Count = Children;
    Children = 0;

    for (i = 0; i < USB_MAXCHILDREN; i++)
    {
        if (DeviceExtension->Children[i])
        {
            ObReferenceObject(DeviceExtension->Children[i]);
            DeviceRelations->Objects[Children++] = DeviceExtension->Children[i];
        }
    }

    ASSERT(Children == DeviceRelations->Count);
    *pDeviceRelations = DeviceRelations;

    WaitForUsbDeviceArrivalNotification(DeviceObject);

    return STATUS_SUCCESS;
}
Example #28
0
/*
 * @implemented
 */
NTSTATUS
NTAPI
IoEnumerateRegisteredFiltersList(OUT PDRIVER_OBJECT *DriverObjectList,
                                 IN ULONG DriverObjectListSize,
                                 OUT PULONG ActualNumberDriverObjects)
{
    PLIST_ENTRY ListEntry;
    NTSTATUS Status = STATUS_SUCCESS;
    PFS_CHANGE_NOTIFY_ENTRY ChangeEntry;
    ULONG ListSize = 0, MaximumSize = DriverObjectListSize / sizeof(PDRIVER_OBJECT);

    /* Acquire the FS lock */
    KeEnterCriticalRegion();
    ExAcquireResourceExclusiveLite(&IopDatabaseResource, TRUE);

    /* Browse the whole list */
    ListEntry = IopFsNotifyChangeQueueHead.Flink;
    while (ListEntry != &IopFsNotifyChangeQueueHead)
    {
        ChangeEntry = CONTAINING_RECORD(ListEntry,
                                        FS_CHANGE_NOTIFY_ENTRY,
                                        FsChangeNotifyList);

        /* If buffer is still big enough */
        if (ListSize < MaximumSize)
        {
            /* Reference the driver object */
            ObReferenceObject(ChangeEntry->DriverObject);
            /* And pass it to the caller */
            DriverObjectList[ListSize] = ChangeEntry->DriverObject;
        }
        else
        {
            Status = STATUS_BUFFER_TOO_SMALL;
        }

        /* Increase size counter */
        ListSize++;

        /* Go to the next entry */
        ListEntry = ListEntry->Flink;
    }

    /* Return list size */
    *ActualNumberDriverObjects = ListSize;

    /* Release the FS lock */
    ExReleaseResourceLite(&IopDatabaseResource);
    KeLeaveCriticalRegion();

    return Status;
}
Example #29
0
/**
 * Add a PDO node to a bus' list of children.  Internal.
 *
 * @v bus               The bus to add the node to.
 * @v new_node          The PDO node to add to the bus.
 *
 * Don't call this function yourself.  It doesn't perform any error-checking.
 */
static VOID STDCALL WvlBusAddNode_(WVL_SP_BUS_T bus, WVL_SP_BUS_NODE new_node) {
    PLIST_ENTRY walker;
    KIRQL irql;

    DBG(
        "Adding PDO %p to bus %p.\n",
        (PVOID) new_node->BusPrivate_.Pdo,
        (PVOID) bus
      );
    ObReferenceObject(new_node->BusPrivate_.Pdo);
    /* It's too bad about having both linked list and bus ref. */
    new_node->BusPrivate_.Bus = bus;

    /* Find a slot for the new child. */
    walker = &bus->BusPrivate_.Nodes;
    new_node->BusPrivate_.Num = 0;
    KeAcquireSpinLock(&bus->BusPrivate_.NodeLock, &irql);
    while ((walker = walker->Flink) != &bus->BusPrivate_.Nodes) {
        WVL_SP_BUS_NODE node = CONTAINING_RECORD(
            walker,
            WVL_S_BUS_NODE,
            BusPrivate_.Link
          );

        if (
            node->BusPrivate_.Num &&
            (node->BusPrivate_.Link.Blink == &bus->BusPrivate_.Nodes)
          ) {
            /* The first node's unit number is != 0.  Insert here. */
            break;
          }
        if (node->BusPrivate_.Num > new_node->BusPrivate_.Num) {
            /* There is a gap so insert here. */
            break;
          }
        /* Continue trying to find a slot. */
        new_node->BusPrivate_.Num++;
      } /* while */
    /* Insert before walker. */
    InsertTailList(walker, &new_node->BusPrivate_.Link);
    bus->BusPrivate_.NodeCount++;
    KeReleaseSpinLock(&bus->BusPrivate_.NodeLock, irql);
    new_node->Linked = TRUE;
    /* We might be floating. */
    if (bus->Pdo)
      IoInvalidateDeviceRelations(bus->Pdo, BusRelations);
    /* Hack: Use the new method for the main bus */
    if (bus == &WvBus)
      WvlAddDeviceToMainBus(new_node->BusPrivate_.Pdo);
    return;
  }
Example #30
0
NTSTATUS
QueryDeviceRelations(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp) {
  NTSTATUS status = STATUS_SUCCESS;
  PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
  DEVICE_RELATION_TYPE type = irpSp->Parameters.QueryDeviceRelations.Type;
  PDEVICE_RELATIONS DeviceRelations;
  PDokanVCB vcb;

  // QueryDeviceRelations is currently not used
  // because it does not return proper informations and verifier complained
  // We keep it for futur support of pnp

  vcb = DeviceObject->DeviceExtension;

  switch (type) {
  case RemovalRelations:
    DDbgPrint("  QueryDeviceRelations - RemovalRelations\n");
    break;
  case TargetDeviceRelation:

    DDbgPrint("  QueryDeviceRelations - TargetDeviceRelation\n");

    DeviceRelations =
        (PDEVICE_RELATIONS)ExAllocatePool(sizeof(DEVICE_RELATIONS));
    if (!DeviceRelations) {
      DDbgPrint("  can't allocate DeviceRelations\n");
      return STATUS_INSUFFICIENT_RESOURCES;
    }

    /* The PnP manager will remove this when it is done with device */
    ObReferenceObject(DeviceObject);

    DeviceRelations->Count = 1;
    DeviceRelations->Objects[0] = DeviceObject;
    Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;

    return STATUS_SUCCESS;

  case EjectionRelations:
    DDbgPrint("  QueryDeviceRelations - EjectionRelations\n");
    break;
  case BusRelations:
    DDbgPrint("  QueryDeviceRelations - BusRelations\n");
    break;
  default:
    break;
  }

  return status;
}