VirtualBox

Changeset 44989 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Mar 11, 2013 2:40:02 PM (12 years ago)
Author:
vboxsync
Message:

VBoxGuest-win*: More cleanups.

File:
1 edited

Legend:

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

    r44988 r44989  
    2828#include <VBox/log.h>
    2929#include <VBox/VBoxGuestLib.h>
     30#include <iprt/string.h>
    3031
    3132/*
     
    206207     * Create device.
    207208     */
     209    UNICODE_STRING DevName;
     210    RtlInitUnicodeString(&DevName, VBOXGUEST_DEVICE_NAME_NT);
    208211    PDEVICE_OBJECT pDeviceObject = NULL;
    209     PVBOXGUESTDEVEXTWIN pDevExt = NULL;
    210     UNICODE_STRING devName;
    211     UNICODE_STRING win32Name;
    212     RtlInitUnicodeString(&devName, VBOXGUEST_DEVICE_NAME_NT);
    213     rc = IoCreateDevice(pDrvObj, sizeof(VBOXGUESTDEVEXTWIN), &devName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject);
     212    rc = IoCreateDevice(pDrvObj, sizeof(VBOXGUESTDEVEXTWIN), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject);
    214213    if (NT_SUCCESS(rc))
    215214    {
     
    217216         * Create symbolic link (DOS devices).
    218217         */
    219         RtlInitUnicodeString(&win32Name, VBOXGUEST_DEVICE_NAME_DOS);
    220         rc = IoCreateSymbolicLink(&win32Name, &devName);
     218        UNICODE_STRING DosName;
     219        RtlInitUnicodeString(&DosName, VBOXGUEST_DEVICE_NAME_DOS);
     220        rc = IoCreateSymbolicLink(&DosName, &DevName);
    221221        if (NT_SUCCESS(rc))
    222222        {
     
    224224             * Setup the device extension.
    225225             */
    226             pDevExt = (PVBOXGUESTDEVEXTWIN)pDeviceObject->DeviceExtension;
    227             RtlZeroMemory(pDevExt, sizeof(VBOXGUESTDEVEXT));
     226            PVBOXGUESTDEVEXTWIN pDevExt = (PVBOXGUESTDEVEXTWIN)pDeviceObject->DeviceExtension;
     227            RT_ZERO(*pDevExt);
    228228
    229229            KeInitializeSpinLock(&pDevExt->MouseEventAccessLock);
     
    234234
    235235            pDevExt->pNextLowerDriver = IoAttachDeviceToDeviceStack(pDeviceObject, pDevObj);
    236             if (pDevExt->pNextLowerDriver == NULL)
     236            if (pDevExt->pNextLowerDriver != NULL)
     237            {
     238                /*
     239                 * If we reached this point we're fine with the basic driver setup,
     240                 * so continue to init our own things.
     241                 */
     242#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
     243                vbgdNtBugCheckCallback(pDevExt); /* Ignore failure! */
     244#endif
     245                if (NT_SUCCESS(rc))
     246                {
     247                    /* VBoxGuestPower is pageable; ensure we are not called at elevated IRQL */
     248                    pDeviceObject->Flags |= DO_POWER_PAGABLE;
     249
     250                    /* Driver is ready now. */
     251                    pDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
     252                    Log(("VBoxGuest::vbgdNtGuestAddDevice: returning with rc = 0x%x (success)\n", rc));
     253                    return rc;
     254                }
     255
     256                IoDetachDevice(pDevExt->pNextLowerDriver);
     257            }
     258            else
    237259            {
    238260                Log(("VBoxGuest::vbgdNtGuestAddDevice: IoAttachDeviceToDeviceStack did not give a nextLowerDriver!\n"));
    239261                rc = STATUS_DEVICE_NOT_CONNECTED;
    240262            }
     263
     264            /* bail out */
     265            IoDeleteSymbolicLink(&DosName);
    241266        }
    242267        else
    243268            Log(("VBoxGuest::vbgdNtGuestAddDevice: IoCreateSymbolicLink failed with rc=%#x!\n", rc));
     269        IoDeleteDevice(pDeviceObject);
    244270    }
    245271    else
    246272        Log(("VBoxGuest::vbgdNtGuestAddDevice: IoCreateDevice failed with rc=%#x!\n", rc));
    247 
    248     if (NT_SUCCESS(rc))
    249     {
    250         /*
    251          * If we reached this point we're fine with the basic driver setup,
    252          * so continue to init our own things.
    253          */
    254 #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
    255         vbgdNtBugCheckCallback(pDevExt); /* Ignore failure! */
    256 #endif
    257         /* VBoxGuestPower is pageable; ensure we are not called at elevated IRQL */
    258         pDeviceObject->Flags |= DO_POWER_PAGABLE;
    259 
    260         /* Driver is ready now. */
    261         pDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
    262     }
    263 
    264     /* Cleanup on error. */
    265     if (NT_ERROR(rc))
    266     {
    267         if (pDevExt)
    268         {
    269             if (pDevExt->pNextLowerDriver)
    270                 IoDetachDevice(pDevExt->pNextLowerDriver);
    271         }
    272         IoDeleteSymbolicLink(&win32Name);
    273         if (pDeviceObject)
    274             IoDeleteDevice(pDeviceObject);
    275     }
    276 
    277273    Log(("VBoxGuest::vbgdNtGuestAddDevice: returning with rc = 0x%x\n", rc));
    278274    return rc;
     
    810806                if (   vrc == VERR_NOT_SUPPORTED
    811807                    || vrc == VERR_INVALID_PARAMETER)
    812                 {
    813808                    Status = STATUS_INVALID_PARAMETER;
    814                 }
    815809                else if (vrc == VERR_OUT_OF_RANGE)
    816810                    Status = STATUS_INVALID_BUFFER_SIZE;
Note: See TracChangeset for help on using the changeset viewer.

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