VirtualBox

Changeset 44979 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 11, 2013 12:10:18 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84199
Message:

VBoxGuest-win-legacy.cpp: Cleaning up. Declaring 'Vbgd' as the prefix used by VBoxGuest (we use 'Vbgl' in VBoxGuestLib).

Location:
trunk/src/VBox/Additions/common/VBoxGuest
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-legacy.cpp

    r32474 r44979  
     1/* $Id$ */
    12/** @file
    2  *
    33 * VBoxGuest-win-legacy - Windows NT4 specifics.
    4  *
    5  * Copyright (C) 2010 Oracle Corporation
     4 */
     5
     6/*
     7 * Copyright (C) 2010-2013 Oracle Corporation
    68 *
    79 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4143*******************************************************************************/
    4244RT_C_DECLS_BEGIN
    43 NTSTATUS vboxguestwinnt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
    44 static NTSTATUS vboxguestwinnt4FindPCIDevice(PULONG pBusNumber, PPCI_SLOT_NUMBER pSlotNumber);
     45static NTSTATUS vbgdNt4FindPciDevice(PULONG pulBusNumber, PPCI_SLOT_NUMBER pSlotNumber);
    4546RT_C_DECLS_END
    4647
    4748#ifdef ALLOC_PRAGMA
    48 #pragma alloc_text (INIT, vboxguestwinnt4CreateDevice)
    49 #pragma alloc_text (INIT, vboxguestwinnt4FindPCIDevice)
     49# pragma alloc_text(INIT, vbgdNt4CreateDevice)
     50# pragma alloc_text(INIT, vbgdNt4FindPciDevice)
    5051#endif
    5152
     
    5657 * @returns NT status code.
    5758 *
    58  * @param pDrvObj
    59  * @param pDevObj
    60  * @param pRegPath
    61  */
    62 NTSTATUS vboxguestwinnt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath)
     59 * @param   pDrvObj         The driver object.
     60 * @param   pDevObj         Unused. NULL. Dunno why it's here, makes no sense.
     61 * @param   pRegPath        The driver registry path.
     62 */
     63NTSTATUS vbgdNt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath)
    6364{
    64     int vrc = VINF_SUCCESS;
    65     NTSTATUS rc = STATUS_SUCCESS;
    66 
    67     Log(("VBoxGuest::vboxguestwinnt4CreateDevice: pDrvObj=%p, pDevObj=%p, pRegPath=%p\n",
    68          pDrvObj, pDevObj, pRegPath));
     65    Log(("VBoxGuest::vbgdNt4CreateDevice: pDrvObj=%p, pDevObj=%p, pRegPath=%p\n", pDrvObj, pDevObj, pRegPath));
    6966
    7067    /*
    7168     * Find our virtual PCI device
    7269     */
    73     ULONG uBusNumber, uSlotNumber;
    74     rc = vboxguestwinnt4FindPCIDevice(&uBusNumber, (PCI_SLOT_NUMBER*)&uSlotNumber);
     70    ULONG uBusNumber;
     71    PCI_SLOT_NUMBER SlotNumber;
     72    NTSTATUS rc = vbgdNt4FindPciDevice(&uBusNumber, &SlotNumber);
    7573    if (NT_ERROR(rc))
    76         Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Device not found!\n"));
    77 
    78     bool fSymbolicLinkCreated = false;
    79     UNICODE_STRING szDosName;
     74    {
     75        Log(("VBoxGuest::vbgdNt4CreateDevice: Device not found!\n"));
     76        return rc;
     77    }
     78
     79    /*
     80     * Create device.
     81     */
     82    UNICODE_STRING szDevName;
     83    RtlInitUnicodeString(&szDevName, VBOXGUEST_DEVICE_NAME_NT);
    8084    PDEVICE_OBJECT pDeviceObject = NULL;
     85    rc = IoCreateDevice(pDrvObj, sizeof(VBOXGUESTDEVEXT), &szDevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject);
    8186    if (NT_SUCCESS(rc))
    8287    {
    83         /*
    84          * Create device.
    85          */
    86         UNICODE_STRING szDevName;
    87         RtlInitUnicodeString(&szDevName, VBOXGUEST_DEVICE_NAME_NT);
    88         rc = IoCreateDevice(pDrvObj, sizeof(VBOXGUESTDEVEXT), &szDevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject);
     88        Log(("VBoxGuest::vbgdNt4CreateDevice: Device created\n"));
     89
     90        UNICODE_STRING DosName;
     91        RtlInitUnicodeString(&DosName, VBOXGUEST_DEVICE_NAME_DOS);
     92        rc = IoCreateSymbolicLink(&DosName, &szDevName);
    8993        if (NT_SUCCESS(rc))
    9094        {
    91             Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Device created\n"));
    92 
    93             RtlInitUnicodeString(&szDosName, VBOXGUEST_DEVICE_NAME_DOS);
    94             rc = IoCreateSymbolicLink(&szDosName, &szDevName);
     95            Log(("VBoxGuest::vbgdNt4CreateDevice: Symlink created\n"));
     96
     97            /*
     98             * Setup the device extension.
     99             */
     100            Log(("VBoxGuest::vbgdNt4CreateDevice: Setting up device extension ...\n"));
     101
     102            PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDeviceObject->DeviceExtension;
     103            RtlZeroMemory(pDevExt, sizeof(VBOXGUESTDEVEXT));
     104
     105            Log(("VBoxGuest::vbgdNt4CreateDevice: Device extension created\n"));
     106
     107            /* Store a reference to ourself. */
     108            pDevExt->win.s.pDeviceObject = pDeviceObject;
     109
     110            /* Store bus and slot number we've queried before. */
     111            pDevExt->win.s.busNumber  = uBusNumber;
     112            pDevExt->win.s.slotNumber = SlotNumber.u.AsULONG;
     113
     114#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
     115            rc = hlpRegisterBugCheckCallback(pDevExt);
     116#endif
     117
     118            /* Do the actual VBox init ... */
    95119            if (NT_SUCCESS(rc))
    96120            {
    97                 Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Symlink created\n"));
    98                 fSymbolicLinkCreated = true;
     121                rc = vboxguestwinInit(pDrvObj, pDeviceObject, pRegPath);
     122                if (NT_SUCCESS(rc))
     123                {
     124                    Log(("VBoxGuest::vbgdNt4CreateDevice: Returning rc = 0x%x (succcess)\n", rc));
     125                    return rc;
     126                }
     127
     128                /* bail out */
    99129            }
    100             else
    101                 Log(("VBoxGuest::vboxguestwinnt4CreateDevice: IoCreateSymbolicLink failed with rc = %#x\n", rc));
     130            IoDeleteSymbolicLink(&DosName);
    102131        }
    103132        else
    104             Log(("VBoxGuest::vboxguestwinnt4CreateDevice: IoCreateDevice failed with rc = %#x\n", rc));
     133            Log(("VBoxGuest::vbgdNt4CreateDevice: IoCreateSymbolicLink failed with rc = %#x\n", rc));
     134        IoDeleteDevice(pDeviceObject);
    105135    }
    106 
    107     /*
    108      * Setup the device extension.
    109      */
    110     PVBOXGUESTDEVEXT pDevExt = NULL;
    111     if (NT_SUCCESS(rc))
    112     {
    113         Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Setting up device extension ...\n"));
    114 
    115         pDevExt = (PVBOXGUESTDEVEXT)pDeviceObject->DeviceExtension;
    116         RtlZeroMemory(pDevExt, sizeof(VBOXGUESTDEVEXT));
    117     }
    118 
    119     if (NT_SUCCESS(rc) && pDevExt)
    120     {
    121         Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Device extension created\n"));
    122 
    123         /* Store a reference to ourself. */
    124         pDevExt->win.s.pDeviceObject = pDeviceObject;
    125 
    126         /* Store bus and slot number we've queried before. */
    127         pDevExt->win.s.busNumber = uBusNumber;
    128         pDevExt->win.s.slotNumber = uSlotNumber;
    129 
    130     #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
    131         rc = hlpRegisterBugCheckCallback(pDevExt);
    132     #endif
    133     }
    134 
    135     /* Do the actual VBox init ... */
    136     if (NT_SUCCESS(rc))
    137         rc = vboxguestwinInit(pDrvObj, pDeviceObject, pRegPath);
    138 
    139     /* Clean up in case of errors. */
    140     if (NT_ERROR(rc))
    141     {
    142         if (fSymbolicLinkCreated && szDosName.Length > 0)
    143             IoDeleteSymbolicLink(&szDosName);
    144         if (pDeviceObject)
    145             IoDeleteDevice(pDeviceObject);
    146     }
    147 
    148     Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Returning rc = 0x%x\n", rc));
     136    else
     137        Log(("VBoxGuest::vbgdNt4CreateDevice: IoCreateDevice failed with rc = %#x\n", rc));
     138    Log(("VBoxGuest::vbgdNt4CreateDevice: Returning rc = 0x%x\n", rc));
    149139    return rc;
    150140}
     
    156146 * @returns NT status code.
    157147 *
    158  * @param pBusNumber
    159  * @param pSlotNumber
    160  *
    161  */
    162 static NTSTATUS vboxguestwinnt4FindPCIDevice(PULONG pBusNumber, PPCI_SLOT_NUMBER pSlotNumber)
     148 * @param   pulBusNumber    Where to return the bus number on success.
     149 * @param   pSlotNumber     Where to return the slot number on success.
     150 */
     151static NTSTATUS vbgdNt4FindPciDevice(PULONG pulBusNumber, PPCI_SLOT_NUMBER pSlotNumber)
    163152{
    164     NTSTATUS rc;
    165 
    166     ULONG busNumber;
    167     ULONG deviceNumber;
    168     ULONG functionNumber;
    169     PCI_SLOT_NUMBER slotNumber;
    170     PCI_COMMON_CONFIG pciData;
    171 
    172     Log(("VBoxGuest::vboxguestwinnt4FindPCIDevice\n"));
    173 
    174     rc = STATUS_DEVICE_DOES_NOT_EXIST;
    175     slotNumber.u.AsULONG = 0;
     153    Log(("VBoxGuest::vbgdNt4FindPciDevice\n"));
     154
     155    PCI_SLOT_NUMBER SlotNumber;
     156    SlotNumber.u.AsULONG = 0;
    176157
    177158    /* Scan each bus. */
    178     for (busNumber = 0; busNumber < PCI_MAX_BUSES; busNumber++)
     159    for (ULONG ulBusNumber = 0; ulBusNumber < PCI_MAX_BUSES; ulBusNumber++)
    179160    {
    180161        /* Scan each device. */
    181         for (deviceNumber = 0; deviceNumber < PCI_MAX_DEVICES; deviceNumber++)
     162        for (ULONG deviceNumber = 0; deviceNumber < PCI_MAX_DEVICES; deviceNumber++)
    182163        {
    183             slotNumber.u.bits.DeviceNumber = deviceNumber;
     164            SlotNumber.u.bits.DeviceNumber = deviceNumber;
    184165
    185166            /* Scan each function (not really required...). */
    186             for (functionNumber = 0; functionNumber < PCI_MAX_FUNCTION; functionNumber++)
     167            for (ULONG functionNumber = 0; functionNumber < PCI_MAX_FUNCTION; functionNumber++)
    187168            {
    188                 slotNumber.u.bits.FunctionNumber = functionNumber;
     169                SlotNumber.u.bits.FunctionNumber = functionNumber;
    189170
    190171                /* Have a look at what's in this slot. */
    191                 if (!HalGetBusData(PCIConfiguration, busNumber, slotNumber.u.AsULONG,
    192                                    &pciData, sizeof(ULONG)))
     172                PCI_COMMON_CONFIG PciData;
     173                if (!HalGetBusData(PCIConfiguration, ulBusNumber, SlotNumber.u.AsULONG, &PciData, sizeof(ULONG)))
    193174                {
    194175                    /* No such bus, we're done with it. */
     
    197178                }
    198179
    199                 if (pciData.VendorID == PCI_INVALID_VENDORID)
    200                 {
     180                if (PciData.VendorID == PCI_INVALID_VENDORID)
    201181                    /* We have to proceed to the next function. */
    202182                    continue;
    203                 }
    204183
    205184                /* Check if it's another device. */
    206                 if ((pciData.VendorID != VMMDEV_VENDORID) ||
    207                     (pciData.DeviceID != VMMDEV_DEVICEID))
    208                 {
     185                if (   PciData.VendorID != VMMDEV_VENDORID
     186                    || PciData.DeviceID != VMMDEV_DEVICEID)
    209187                    continue;
    210                 }
    211188
    212189                /* Hooray, we've found it! */
    213                 Log(("VBoxGuest::vboxguestwinnt4FindPCIDevice: Device found!\n"));
    214 
    215                 *pBusNumber = busNumber;
    216                 *pSlotNumber = slotNumber;
    217                 rc = STATUS_SUCCESS;
     190                Log(("VBoxGuest::vbgdNt4FindPciDevice: Device found!\n"));
     191
     192                *pulBusNumber = ulBusNumber;
     193                *pSlotNumber  = SlotNumber;
     194                return STATUS_SUCCESS;
    218195            }
    219196        }
    220197    }
    221198
    222     return rc;
     199    return STATUS_DEVICE_DOES_NOT_EXIST;
    223200}
    224201
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp

    r44529 r44979  
    162162        pDrvObj->MajorFunction[IRP_MJ_WRITE]                   = vboxguestwinNotSupportedStub;
    163163#ifdef TARGET_NT4
    164         rc = vboxguestwinnt4CreateDevice(pDrvObj, NULL /* pDevObj */, pRegPath);
     164        rc = vbgdNt4CreateDevice(pDrvObj, NULL /* pDevObj */, pRegPath);
    165165#else
    166166        pDrvObj->MajorFunction[IRP_MJ_PNP]                     = vboxguestwinPnP;
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.h

    r44529 r44979  
    163163RT_C_DECLS_BEGIN
    164164#ifdef TARGET_NT4
    165 NTSTATUS   vboxguestwinnt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
     165NTSTATUS   vbgdNt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
    166166NTSTATUS   vboxguestwinInit(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
    167167#else
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette