Index: trunk/src/VBox/Additions/common/VBoxGuest/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/common/VBoxGuest/Makefile.kmk	(revision 32317)
+++ trunk/src/VBox/Additions/common/VBoxGuest/Makefile.kmk	(revision 32322)
@@ -35,5 +35,5 @@
  VBoxGuest_DEFS.linux    = KBUILD_MODNAME=KBUILD_STR\(vboxguest\) KBUILD_BASENAME=KBUILD_STR\(vboxguest\) DEBUG_HASH=2 DEBUG_HASH2=3 EXPORT_SYMTAB
  VBoxGuest_DEFS.solaris  = VBOX_SVN_REV=$(VBOX_SVN_REV)
- VBoxGuest_DEFS.win      = VBOX_SVN_REV=$(VBOX_SVN_REV) # VBOX_WITH_VRDP_SESSION_HANDLING
+ VBoxGuest_DEFS.win      = # VBOX_WITH_VRDP_SESSION_HANDLING
  ifeq ($(KBUILD_TYPE),release)
   # Allow stopping/removing the driver without a reboot
@@ -60,7 +60,7 @@
    ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
     VBoxGuest_LIBS      += \
-    	$(PATH_SDK_WINDDKWLH_LIB)/aux_klib.lib \
-    	$(PATH_SDK_WINDDKWLH_LIB)/ksecdd.lib \
-    	$(PATH_SDK_WINDDKWLH_LIB)/BufferOverflowK.lib
+      	$(PATH_SDK_WINDDKWLH_LIB)/aux_klib.lib \
+      	$(PATH_SDK_WINDDKWLH_LIB)/ksecdd.lib \
+      	$(PATH_SDK_WINDDKWLH_LIB)/BufferOverflowK.lib
     VBoxGuest.cpp_SDKS   = WINDDKWLH
    endif
@@ -74,7 +74,9 @@
   	VBoxGuest.cpp \
   	VBoxGuest2.cpp
-  VBoxGuest_SOURCES.win = \
+  ifeq ($(KBUILD_TARGET), win)
+   VBoxGuest_SOURCES += \
   	VBoxGuest-$(KBUILD_TARGET)-pnp.cpp \
   	win/VBoxGuest.rc
+  endif
   VBoxGuest2.cpp_DEFS    = VBOX_SVN_REV=$(VBOX_SVN_REV)
   VBoxGuest.cpp_DEFS     = VBOX_SVN_REV=$(VBOX_SVN_REV)
@@ -119,10 +121,12 @@
   # Windows NT4 driver.
   #
-  #SYSMODS.x86 += VBoxGuestNT # Not yet buildable!
+  SYSMODS.x86 += VBoxGuestNT
   VBoxGuestNT_EXTENDS = VBoxGuest
   VBoxGuestNT_NOINST  = $(NO_SUCH_VARIABLE)
   VBoxGuestNT_DEFS    = $(VBoxGuest_DEFS) TARGET_NT4
   VBoxGuestNT_SOURCES = \
- 	VBoxGuest-$(KBUILD_TARGET).cpp \
+  	VBoxGuest.cpp \
+  	VBoxGuest2.cpp \
+  	VBoxGuest-$(KBUILD_TARGET).cpp \
   	VBoxGuest-$(KBUILD_TARGET)-legacy.cpp \
   	win/VBoxGuest.rc
Index: trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-legacy.cpp
===================================================================
--- trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-legacy.cpp	(revision 32317)
+++ trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-legacy.cpp	(revision 32322)
@@ -1,8 +1,7 @@
 /** @file
- * VBoxGuest -- VirtualBox Win32 guest support driver
- */
-
-/*
- * Copyright (C) 2006-2010 Oracle Corporation
+ *
+ * VBoxGuest-win-legacy - Windows NT4 specifics.
+ *
+ * Copyright (C) 2010 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -15,15 +14,14 @@
  */
 
-// enable backdoor logging
-//#define LOG_ENABLED
-
 /*******************************************************************************
 *   Header Files                                                               *
 *******************************************************************************/
-#include "NTLegacy.h"
-#include "Helper.h"
-
+#include "VBoxGuest-win.h"
+#include "VBoxGuestInternal.h"
+#include <VBox/err.h>
+#include <VBox/log.h>
+#include <VBox/version.h>
 #include <VBox/VBoxGuestLib.h>
-#include "../../common/VBoxGuest/VBoxGuest2.h"
+
 
 /*******************************************************************************
@@ -31,19 +29,26 @@
 *******************************************************************************/
 
+/* Reenable logging, this was #undef'ed on iprt/log.h for RING0. */
+#define LOG_ENABLED
+
+#ifndef PCI_MAX_BUSES
+# define PCI_MAX_BUSES 256
+#endif
+
 
 /*******************************************************************************
 *   Internal Functions                                                         *
 *******************************************************************************/
-extern "C"
-{
-static NTSTATUS            findPCIDevice(PULONG pBusNumber, PPCI_SLOT_NUMBER pSlotNumber);
-static void                freeDeviceResources(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj);
-}
+RT_C_DECLS_BEGIN
+static NTSTATUS vboxguestwinnt4FindPCIDevice(PULONG pBusNumber, PPCI_SLOT_NUMBER pSlotNumber);
+static void     vboxguestwinnt4FreeDeviceResources(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj);
+RT_C_DECLS_END
 
 #ifdef ALLOC_PRAGMA
-#pragma alloc_text (INIT, ntCreateDevice)
-#pragma alloc_text (INIT, findPCIDevice)
-#pragma alloc_text (INIT, freeDeviceResources)
+#pragma alloc_text (INIT, vboxguestwinnt4CreateDevice)
+#pragma alloc_text (INIT, vboxguestwinnt4FindPCIDevice)
+#pragma alloc_text (INIT, vboxguestwinnt4FreeDeviceResources)
 #endif
+
 
 /**
@@ -53,262 +58,81 @@
  * @param
  */
-NTSTATUS ntCreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath)
+NTSTATUS vboxguestwinnt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath)
 {
-    ULONG busNumber, slotNumber;
     int vrc = VINF_SUCCESS;
     NTSTATUS rc = STATUS_SUCCESS;
 
-    dprintf(("VBoxGuest::ntCreateDevice: entered, pDrvObj=%x, pDevObj=%x, pRegPath=%x\n",
-        pDrvObj, pDevObj, pRegPath));
+    Log(("VBoxGuest::vboxguestwinnt4CreateDevice: pDrvObj=%x, pDevObj=%x, pRegPath=%x\n",
+         pDrvObj, pDevObj, pRegPath));
 
     /*
      * Find our virtual PCI device
      */
-    rc = findPCIDevice(&busNumber, (PCI_SLOT_NUMBER*)&slotNumber);
-    if (!NT_SUCCESS(rc))
-    {
-        dprintf(("VBoxGuest::createDevice: device not found, returning\n"));
-        return rc;
-    }
-
-    /*
-     * Create device.
-     */
-    PDEVICE_OBJECT deviceObject = NULL;
-    UNICODE_STRING  DevName;
-    RtlInitUnicodeString(&DevName, VBOXGUEST_DEVICE_NAME_NT);
-    rc = IoCreateDevice(pDrvObj, sizeof(VBOXGUESTDEVEXT), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &deviceObject);
-    if (!NT_SUCCESS(rc))
-    {
-        dprintf(("VBoxGuest::ntCreateDevice: IoCreateDevice failed with rc=%#x!\n", rc));
-        return rc;
-    }
-    dprintf(("VBoxGuest::ntCreateDevice: device created\n"));
-    UNICODE_STRING DosName;
-    RtlInitUnicodeString(&DosName, VBOXGUEST_DEVICE_NAME_DOS);
-    rc = IoCreateSymbolicLink(&DosName, &DevName);
-    if (!NT_SUCCESS(rc))
-    {
-        dprintf(("VBoxGuest::ntCreateDevice: IoCreateSymbolicLink failed with rc=%#x!\n", rc));
-        IoDeleteDevice(deviceObject);
-        return rc;
-    }
-    dprintf(("VBoxGuest::ntCreateDevice: symlink created\n"));
+    ULONG uBusNumber, uSlotNumber;
+    rc = vboxguestwinnt4FindPCIDevice(&uBusNumber, (PCI_SLOT_NUMBER*)&uSlotNumber);
+    if (NT_ERROR(rc))
+        Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Device not found!\n"));
+
+    PDEVICE_OBJECT pDeviceObject = NULL;
+    if (NT_SUCCESS(rc))
+    {
+        /*
+         * Create device.
+         */
+        UNICODE_STRING szDevName;
+        RtlInitUnicodeString(&szDevName, VBOXGUEST_DEVICE_NAME_NT);
+        rc = IoCreateDevice(pDrvObj, sizeof(VBOXGUESTDEVEXT), &szDevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject);
+        if (NT_SUCCESS(rc))
+        {
+            Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Device created\n"));
+
+            UNICODE_STRING DosName;
+            RtlInitUnicodeString(&DosName, VBOXGUEST_DEVICE_NAME_DOS);
+            rc = IoCreateSymbolicLink(&DosName, &szDevName);
+            if (NT_ERROR(rc))
+            {
+                Log(("VBoxGuest::vboxguestwinnt4CreateDevice: IoCreateSymbolicLink failed with rc = %#x\n", rc));
+                //IoDeleteDevice(pDeviceObject);
+            }
+            Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Symlink created\n"));
+        }
+        else
+            Log(("VBoxGuest::vboxguestwinnt4CreateDevice: IoCreateDevice failed with rc = %#x\n", rc));
+    }
 
     /*
      * Setup the device extension.
      */
-    PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)deviceObject->DeviceExtension;
-    RtlZeroMemory(pDevExt, sizeof(VBOXGUESTDEVEXT));
-
-    if (pDevObj) /* pDevObj always is NULL at the moment, so don't attach to the driver stack */
-    {
-        pDevExt->nextLowerDriver = IoAttachDeviceToDeviceStack(deviceObject, pDevObj);
-        if (pDevExt->nextLowerDriver == NULL)
-        {
-            dprintf(("VBoxGuest::ntCreateDevice: IoAttachDeviceToDeviceStack did not give a nextLowerDrive\n"));
-            IoDeleteSymbolicLink(&DosName);
-            IoDeleteDevice(deviceObject);
-            return STATUS_NO_SUCH_DEVICE;
-        }
-        dprintf(("VBoxGuest::ntCreateDevice: device attached to stack\n"));
-    }
-
-#ifdef VBOX_WITH_HGCM
-    /* Create global spinlock for all driver sessions */
-    int rc2 = RTSpinlockCreate(&pDevExt->SessionSpinlock);
-    if (RT_FAILURE(rc2))
-    {
-        dprintf(("VBoxGuest::ntCreateDevice: RTSpinlockCreate failed\n"));
-        IoDetachDevice(pDevExt->nextLowerDriver);
-        IoDeleteSymbolicLink(&DosName);
-        IoDeleteDevice(deviceObject);
-        return STATUS_DRIVER_UNABLE_TO_LOAD;
-    }
-    dprintf(("VBoxGuest::ntCreateDevice: spinlock created\n"));
-#endif
-
-    /* Store a reference to ourself */
-    pDevExt->deviceObject = deviceObject;
-    /* Store bus and slot number we've queried before */
-    pDevExt->busNumber = busNumber;
-    pDevExt->slotNumber = slotNumber;
-
-#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
-    rc = hlpRegisterBugCheckCallback(pDevExt);
-#endif
-
-    //
-    // let's have a look at what our PCI adapter offers
-    //
-    dprintf(("VBoxGuest::ntCreateDevice: starting to scan PCI resources of VBoxGuest\n"));
-    // assign the PCI resources
-    PCM_RESOURCE_LIST resourceList;
-    UNICODE_STRING classNameString;
-    RtlInitUnicodeString(&classNameString, L"VBoxGuestAdapter");
-    rc = HalAssignSlotResources(pRegPath, &classNameString,
-                                pDrvObj, pDevObj,
-                                PCIBus, busNumber, slotNumber,
-                                &resourceList);
-    if (!NT_SUCCESS(rc))
-    {
-        dprintf(("VBoxGuest::ntCreateDevice: HalAssignSlotResources failed with rc=%#x!\n", rc));
-        freeDeviceResources(pDrvObj, pDevObj);
-        return rc;
-    }
-
-    rc = VBoxScanPCIResourceList(resourceList, pDevExt);
-
-    rc = VbglInit (pDevExt->startPortAddress, pDevExt->pVMMDevMemory);
-    if (!RT_SUCCESS(rc))
-    {
-        dprintf(("VBoxGuest::START_DEVICE: VbglInit failed. rc = %d\n", rc));
-    }
-
-
-    rc = VbglGRAlloc ((VMMDevRequestHeader **)&pDevExt->irqAckEvents, sizeof (VMMDevEvents), VMMDevReq_AcknowledgeEvents);
-    if (!RT_SUCCESS(rc))
-    {
-       dprintf(("VBoxGuest::START_DEVICE: VbglAlloc failed for irqAckEvents. rc = %d\n", rc));
-    }
-    rc = VbglGRAlloc ((VMMDevRequestHeader **)&pDevExt->powerStateRequest, sizeof (VMMDevPowerStateRequest), VMMDevReq_SetPowerStatus);
-    if (!RT_SUCCESS(rc))
-    {
-       dprintf(("VBoxGuest::START_DEVICE: VbglAlloc failed for powerStateRequest. rc = %d\n", rc));
-    }
-
-#if 0
-    //
-    // now proceed to the busmaster DMA stuff
-    //
-
-    DEVICE_DESCRIPTION deviceDescription;
-    ULONG numberOfMapRegisters;
-    deviceDescription.Version = DEVICE_DESCRIPTION_VERSION;
-    deviceDescription.Master = TRUE;
-    deviceDescription.ScatterGather = TRUE;
-    deviceDescription.BusNumber = pDevExt->busNumber;
-    deviceDescription.InterfaceType = PCIBus;
-    deviceDescription.MaximumLength = MAXIMUM_TRANSFER_LENGTH;
-    pDevExt->adapterObject = HalGetAdapter(&deviceDescription, &numberOfMapRegisters);
-    if (pDevExt->adapterObject == NULL)
-    {
-        dprintf(("VBoxGuest::ntCreateDevice: HalGetAdapter failed!\n"));
-        freeDeviceResources(pDrvObj, pDevObj);
-        return rc;
-    }
-
-    // @todo allocate S/G buffer
-#endif
-
-
-    //
-    // it's time to map the I/O and memory spaces
-    //
-
-    // Map physical address of VMMDev memory
-    rc = hlpVBoxMapVMMDevMemory (pDevExt);
-    if (!NT_SUCCESS(rc))
-    {
-        dprintf(("VBoxGuest::ntCreateDevice: Unable to map VMMDev Memory, rc=%#x!\n", rc));
-        freeDeviceResources(pDrvObj, pDevObj);
-        return rc;
-    }
-
-    //
-    // now we need an ISR and DPC
-    //
-
-    // register DPC routine
-    dprintf(("VBoxGuest::ntCreateDevice: initializing DPC...\n"));
-    IoInitializeDpcRequest(pDevExt->deviceObject, VBoxGuestDpcHandler);
-    // get an interrupt vector
-    ULONG vector;
-    KIRQL irql;
-    KAFFINITY affinity;
-    // only proceed if the device provides an interrupt
-    if (pDevExt->interruptLevel || pDevExt->interruptVector)
-    {
-        vector = HalGetInterruptVector(PCIBus,
-                                       pDevExt->busNumber,
-                                       pDevExt->interruptLevel,
-                                       pDevExt->interruptVector,
-                                       &irql,
-                                       &affinity);
-        dprintf(("VBoxGuest::ntCreateDevice: HalGetInterruptVector returns vector %u\n", vector));
-        rc = IoConnectInterrupt(&pDevExt->interruptObject,              // out: interrupt object
-                                (PKSERVICE_ROUTINE)VBoxGuestIsrHandler, // ISR
-                                pDevExt,                                // context
-                                NULL,                                   // optional spinlock
-                                vector,                                 // interrupt vector
-                                irql,                                   // interrupt level
-                                irql,                                   // interrupt level
-                                pDevExt->interruptMode,                 // LevelSensitive or Latched
-                                TRUE,                                   // shareable interrupt
-                                affinity,                               // CPU affinity
-                                FALSE);                                 // don't save FPU stack
-        if (!NT_SUCCESS(rc))
-        {
-            dprintf(("VBoxGuest::ntCreateDevice: Unable to connect interrupt, rc=%#x!\n", rc));
-            pDevExt->interruptObject = NULL;
-            freeDeviceResources(pDrvObj, pDevObj);
-            return rc;
-        }
-        dprintf(("VBoxGuest::ntCreateDevice: IRQ connected!\n"));
-    }
-
+    PVBOXGUESTDEVEXT pDevExt = NULL;
     if (NT_SUCCESS(rc))
     {
-        // create our thread to inform the VBoxMouse driver
-        rc = createThreads(pDevExt);
+        Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Setting up device extension ...\n"));
+
+        pDevExt = (PVBOXGUESTDEVEXT)pDeviceObject->DeviceExtension;
+        Assert(pDevExt);
+        RtlZeroMemory(pDevExt, sizeof(VBOXGUESTDEVEXT));
+    }
+
+    if (   NT_SUCCESS(rc)
+        && pDevExt)
+    {
+        /* Store a reference to ourself. */
+        pDevExt->win.s.pDeviceObject = pDeviceObject;
+
+        /* Store bus and slot number we've queried before. */
+        pDevExt->win.s.busNumber = uBusNumber;
+        pDevExt->win.s.slotNumber = uSlotNumber;
+
+    #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
+        rc = hlpRegisterBugCheckCallback(pDevExt);
+    #endif
     }
 
     if (NT_SUCCESS(rc))
     {
-        // initialize the event notification semaphore
-        KeInitializeEvent(&pDevExt->keventNotification, NotificationEvent, FALSE);
-
-        /* Preallocated constant timeout 250ms for HGCM async waiter. */
-        pDevExt->HGCMWaitTimeout.QuadPart  = 250;
-        pDevExt->HGCMWaitTimeout.QuadPart *= -10000;     /* relative in 100ns units */
-    }
-
-    /** @todo Cleanup on failure. */
-
-    /** @todo Don't mix up IPRT rc and NTSTATUS rc above! */
-
-    if (NT_SUCCESS(rc))
-    {
-        vrc = VBoxGuestReportGuestInfo(hlpVBoxWinVersionToOSType(winVersion));
-        if (RT_SUCCESS(vrc))
-        {
-            vrc = VBoxInitMemBalloon(pDevExt);
-            if (RT_SUCCESS(vrc))
-            {
-                vrc = VBoxGuestReportDriverStatus(true /* Driver is active */);
-                if (RT_FAILURE(vrc))
-                    dprintf(("VBoxGuest::VBoxGuestPnp::IRP_MN_START_DEVICE: could not report guest driver status, vrc = %d\n", vrc));
-            }
-            else
-                dprintf(("VBoxGuest::VBoxGuestPnp::IRP_MN_START_DEVICE: could not init mem balloon, vrc = %d\n", vrc));
-        }
-        else
-            dprintf(("VBoxGuest::VBoxGuestPnp::IRP_MN_START_DEVICE: could not report guest information to host, vrc = %d\n", vrc));
-
-        if (RT_FAILURE(vrc))
-            rc = STATUS_UNSUCCESSFUL;
-    }
-
-    if (NT_SUCCESS(rc))
-    {
-        // ready to rumble!
-        pDevExt->devState = WORKING;
-    }
-    else
-    {
-        freeDeviceResources(pDrvObj, pDevObj);
-    }
-
-    dprintf(("returning from ntCreateDevice with rc = 0x%x\n, vrc = %Rrc", rc, vrc));
+        rc = vboxguestwinInit(pDrvObj, pDevObj, pRegPath);
+    }
+
+    Log(("VBoxGuest::vboxguestwinnt4CreateDevice: Returning rc = 0x%x\n", rc));
     return rc;
 }
@@ -320,5 +144,5 @@
  * @returns NT error codes
  */
-static NTSTATUS findPCIDevice(PULONG pBusNumber, PPCI_SLOT_NUMBER pSlotNumber)
+static NTSTATUS vboxguestwinnt4FindPCIDevice(PULONG pBusNumber, PPCI_SLOT_NUMBER pSlotNumber)
 {
     NTSTATUS rc;
@@ -330,24 +154,27 @@
     PCI_COMMON_CONFIG pciData;
 
-    dprintf(("findPCIDevice\n"));
+    Log(("VBoxGuest::vboxguestwinnt4FindPCIDevice\n"));
 
     rc = STATUS_DEVICE_DOES_NOT_EXIST;
     slotNumber.u.AsULONG = 0;
-    // scan each bus
+
+    /* Scan each bus. */
     for (busNumber = 0; busNumber < PCI_MAX_BUSES; busNumber++)
     {
-        // scan each device
+        /* Scan each device. */
         for (deviceNumber = 0; deviceNumber < PCI_MAX_DEVICES; deviceNumber++)
         {
             slotNumber.u.bits.DeviceNumber = deviceNumber;
-            // scan each function (not really required...)
+
+            /* Scan each function (not really required...). */
             for (functionNumber = 0; functionNumber < PCI_MAX_FUNCTION; functionNumber++)
             {
                 slotNumber.u.bits.FunctionNumber = functionNumber;
-                // have a look at what's in this slot
+
+                /* Have a look at what's in this slot. */
                 if (!HalGetBusData(PCIConfiguration, busNumber, slotNumber.u.AsULONG,
                                    &pciData, sizeof(ULONG)))
                 {
-                    // no such bus, we're done with it
+                    /* No such bus, we're done with it. */
                     deviceNumber = PCI_MAX_DEVICES;
                     break;
@@ -356,9 +183,9 @@
                 if (pciData.VendorID == PCI_INVALID_VENDORID)
                 {
-                    // we have to proceed to the next function
+                    /* We have to proceed to the next function. */
                     continue;
                 }
 
-                // check if it's another device
+                /* Check if it's another device. */
                 if ((pciData.VendorID != VMMDEV_VENDORID) ||
                     (pciData.DeviceID != VMMDEV_DEVICEID))
@@ -367,6 +194,7 @@
                 }
 
-                // Hooray, we've found it!
-                dprintf(("device found!\n"));
+                /* Hooray, we've found it! */
+                Log(("VBoxGuest::vboxguestwinnt4FindPCIDevice: Device found!\n"));
+
                 *pBusNumber = busNumber;
                 *pSlotNumber = slotNumber;
@@ -379,34 +207,2 @@
 }
 
-/**
- * Helper function to cleanup resources
- *
- * @param   pDrvObj     Driver object.
- * @param   pDevObj     Device object.
- */
-static void freeDeviceResources(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj)
-{
-    PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
-
-    // if there's no device extension, we're screwed
-    if (!pDevExt)
-    {
-        dprintf(("freeDeviceResources: FATAL ERROR! device extension pointer is NULL! Not freeing resources!\n"));
-        return;
-    }
-
-    // indicate that the device is no longer ready
-    pDevExt->devState = STOPPED;
-
-    // disconnect interrupts
-    if (pDevExt->interruptObject)
-    {
-        IoDisconnectInterrupt(pDevExt->interruptObject);
-    }
-
-    // unmap mem/io resources
-    hlpVBoxUnmapVMMDevMemory (pDevExt);
-
-    VBoxCleanupMemBalloon(pDevExt);
-}
-
Index: trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-pnp.cpp
===================================================================
--- trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-pnp.cpp	(revision 32317)
+++ trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-pnp.cpp	(revision 32322)
@@ -170,92 +170,9 @@
                 else
                 {
-                    vboxguestwinShowDeviceResources(&pStack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList);
-
-                    vboxguestwinScanPCIResourceList(pStack->Parameters.StartDevice.AllocatedResourcesTranslated,
-                                                    pDevExt);
-
-                    /* Map physical address of VMMDev memory into MMIO region. */
-                    void *pvMMIOBase = NULL;
-                    uint32_t cbMMIO = 0;
-                    rc = vboxguestwinMapVMMDevMemory(pDevExt,
-                                                     pDevExt->win.s.vmmDevPhysMemoryAddress,
-                                                     pDevExt->win.s.vmmDevPhysMemoryLength,
-                                                     &pvMMIOBase,
-                                                     &cbMMIO);
-                    if (NT_SUCCESS(rc))
-                    {
-                        pDevExt->pVMMDevMemory = (VMMDevMemory *)pvMMIOBase;
-
-                        Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: pvMMIOBase = 0x%p, pDevExt = 0x%p, pDevExt->pVMMDevMemory = 0x%p\n",
-                             pvMMIOBase, pDevExt, pDevExt ? pDevExt->pVMMDevMemory : NULL));
-
-                        int vrc = VBoxGuestInitDevExt(pDevExt,
-                                                      pDevExt->IOPortBase,
-                                                      pvMMIOBase, cbMMIO,
-                                                      vboxguestwinVersionToOSType(g_winVersion),
-                                                      VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
-                        if (RT_FAILURE(vrc))
-                        {
-                            Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: Could not init device extension, rc = %Rrc!\n", vrc));
-                            rc = STATUS_DEVICE_CONFIGURATION_ERROR;
-                        }
-                    }
-                    else
-                        Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: Could not map physical address of VMMDev, rc = 0x%x!\n", rc));
-
-                    if (NT_SUCCESS(rc))
-                    {
-                        int vrc = VbglGRAlloc((VMMDevRequestHeader **)&pDevExt->win.s.pPowerStateRequest,
-                                              sizeof (VMMDevPowerStateRequest), VMMDevReq_SetPowerStatus);
-                        if (RT_FAILURE(vrc))
-                        {
-                            Log(("VBoxGuest::vboxguestwinVBoxGuestPnP: START_DEVICE: Alloc for pPowerStateRequest failed, rc = %Rrc\n", vrc));
-                            rc = STATUS_UNSUCCESSFUL;
-                        }
-                    }
-
-                    if (NT_SUCCESS(rc))
-                    {
-                        /* Register DPC and ISR. */
-                        Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Initializing DPC/ISR ...\n"));
-
-                        IoInitializeDpcRequest(pDevExt->win.s.pDeviceObject, vboxguestwinDpcHandler);
-                        rc = IoConnectInterrupt(&pDevExt->win.s.pInterruptObject,          /* Out: interrupt object. */
-                                                (PKSERVICE_ROUTINE)vboxguestwinIsrHandler, /* Our ISR handler. */
-                                                pDevExt,                                   /* Device context. */
-                                                NULL,                                      /* Optional spinlock. */
-                                                pDevExt->win.s.interruptVector,            /* Interrupt vector. */
-                                                (KIRQL)pDevExt->win.s.interruptLevel,      /* Interrupt level. */
-                                                (KIRQL)pDevExt->win.s.interruptLevel,      /* Interrupt level. */
-                                                pDevExt->win.s.interruptMode,              /* LevelSensitive or Latched. */
-                                                TRUE,                                      /* Shareable interrupt. */
-                                                pDevExt->win.s.interruptAffinity,          /* CPU affinity. */
-                                                FALSE);                                    /* Don't save FPU stack. */
-                        if (NT_ERROR(rc))
-                            Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Could not connect interrupt, rc = 0x%x\n", rc));
-                    }
+                    rc = vboxguestwinInit(pDevObj, pIrp);
                 }
             }
 
-            if (NT_SUCCESS(rc))
-            {
-#ifdef VBOX_WITH_HGCM
-                /* Initialize the HGCM event notification semaphore. */
-                KeInitializeEvent(&pDevExt->win.s.hgcm.s.keventNotification, NotificationEvent, FALSE);
-
-                /* Preallocated constant timeout 250ms for HGCM async waiter. */
-                pDevExt->win.s.hgcm.s.WaitTimeout.QuadPart  = 250;
-                pDevExt->win.s.hgcm.s.WaitTimeout.QuadPart *= -10000; /* Relative in 100ns units. */
-
-                int vrc = VBoxGuestCreateKernelSession(pDevExt, &pDevExt->win.s.pKernelSession);
-                if (RT_FAILURE(vrc))
-                    Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Failed to allocated kernel session data! rc = %Rrc\n", rc));
-#endif
-
-                /* Ready to rumble! */
-                Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Device is ready!\n"));
-                pDevExt->win.s.devState = WORKING;
-            }
-            else
+            if (NT_ERROR(rc))
             {
                 Log(("VBoxGuest::vboxguestwinGuestPnp: START_DEVICE: Error: rc = 0x%x\n", rc));
@@ -304,5 +221,5 @@
             if (pDevExt->win.s.devState == PENDINGREMOVE)
             {
-                rc = vboxguestwinCleanup(pDevObj, pIrp);
+                rc = vboxguestwinCleanup(pDevObj);
                 if (NT_SUCCESS(rc))
                 {
@@ -377,5 +294,5 @@
             if (pDevExt->win.s.devState == PENDINGSTOP)
             {
-                rc = vboxguestwinCleanup(pDevObj, pIrp);
+                rc = vboxguestwinCleanup(pDevObj);
                 if (NT_SUCCESS(rc))
                 {
@@ -406,66 +323,4 @@
     Log(("VBoxGuest::vboxguestwinGuestPnp: Returning with rc = 0x%x\n", rc));
     return rc;
-}
-
-
-/**
- * Debug helper to dump a device resource list.
- *
- * @param pResourceList  list of device resources.
- */
-static VOID vboxguestwinShowDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList)
-{
-#ifdef LOG_ENABLED
-    PCM_PARTIAL_RESOURCE_DESCRIPTOR resource = pResourceList->PartialDescriptors;
-    ULONG nres = pResourceList->Count;
-    ULONG i;
-
-    for (i = 0; i < nres; ++i, ++resource)
-    {
-        ULONG uType = resource->Type;
-        static char* aszName[] =
-        {
-            "CmResourceTypeNull",
-            "CmResourceTypePort",
-            "CmResourceTypeInterrupt",
-            "CmResourceTypeMemory",
-            "CmResourceTypeDma",
-            "CmResourceTypeDeviceSpecific",
-            "CmResourceTypeBusNumber",
-            "CmResourceTypeDevicePrivate",
-            "CmResourceTypeAssignedResource",
-            "CmResourceTypeSubAllocateFrom",
-        };
-
-        Log(("VBoxGuest::vboxguestwinShowDeviceResources: Type %s",
-               uType < (sizeof(aszName) / sizeof(aszName[0]))
-             ? aszName[uType] : "Unknown"));
-
-        switch (uType)
-        {
-            case CmResourceTypePort:
-            case CmResourceTypeMemory:
-                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Start %8X%8.8lX length %X\n",
-                         resource->u.Port.Start.HighPart, resource->u.Port.Start.LowPart,
-                         resource->u.Port.Length));
-                break;
-
-            case CmResourceTypeInterrupt:
-                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Level %X, Vector %X, Affinity %X\n",
-                         resource->u.Interrupt.Level, resource->u.Interrupt.Vector,
-                         resource->u.Interrupt.Affinity));
-                break;
-
-            case CmResourceTypeDma:
-                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Channel %d, Port %X\n",
-                         resource->u.Dma.Channel, resource->u.Dma.Port));
-                break;
-
-            default:
-                Log(("\n"));
-                break;
-        }
-    }
-#endif
 }
 
@@ -591,5 +446,5 @@
 
                             /* Cleanup. */
-                            vboxguestwinCleanup(pDevObj, pIrp);
+                            vboxguestwinCleanup(pDevObj);
                             break;
                         }
Index: trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp
===================================================================
--- trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp	(revision 32317)
+++ trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp	(revision 32322)
@@ -171,5 +171,5 @@
         pDrvObj->MajorFunction[IRP_MJ_WRITE]                   = vboxguestwinNotSupportedStub;
 #ifdef TARGET_NT4
-        rc = vboxguestwinNT4CreateDevice(pDrvObj, NULL /* pDevObj */, pRegPath);
+        rc = vboxguestwinnt4CreateDevice(pDrvObj, NULL /* pDevObj */, pRegPath);
 #else
         pDrvObj->MajorFunction[IRP_MJ_PNP]                     = vboxguestwinPnP;
@@ -274,18 +274,244 @@
 
 /**
+ * Debug helper to dump a device resource list.
+ *
+ * @param pResourceList  list of device resources.
+ */
+static VOID vboxguestwinShowDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList)
+{
+#ifdef LOG_ENABLED
+    PCM_PARTIAL_RESOURCE_DESCRIPTOR resource = pResourceList->PartialDescriptors;
+    ULONG nres = pResourceList->Count;
+    ULONG i;
+
+    for (i = 0; i < nres; ++i, ++resource)
+    {
+        ULONG uType = resource->Type;
+        static char* aszName[] =
+        {
+            "CmResourceTypeNull",
+            "CmResourceTypePort",
+            "CmResourceTypeInterrupt",
+            "CmResourceTypeMemory",
+            "CmResourceTypeDma",
+            "CmResourceTypeDeviceSpecific",
+            "CmResourceTypeBusNumber",
+            "CmResourceTypeDevicePrivate",
+            "CmResourceTypeAssignedResource",
+            "CmResourceTypeSubAllocateFrom",
+        };
+
+        Log(("VBoxGuest::vboxguestwinShowDeviceResources: Type %s",
+               uType < (sizeof(aszName) / sizeof(aszName[0]))
+             ? aszName[uType] : "Unknown"));
+
+        switch (uType)
+        {
+            case CmResourceTypePort:
+            case CmResourceTypeMemory:
+                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Start %8X%8.8lX length %X\n",
+                         resource->u.Port.Start.HighPart, resource->u.Port.Start.LowPart,
+                         resource->u.Port.Length));
+                break;
+
+            case CmResourceTypeInterrupt:
+                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Level %X, Vector %X, Affinity %X\n",
+                         resource->u.Interrupt.Level, resource->u.Interrupt.Vector,
+                         resource->u.Interrupt.Affinity));
+                break;
+
+            case CmResourceTypeDma:
+                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Channel %d, Port %X\n",
+                         resource->u.Dma.Channel, resource->u.Dma.Port));
+                break;
+
+            default:
+                Log(("\n"));
+                break;
+        }
+    }
+#endif
+}
+
+
+/**
+ * Global initialisation stuff (PnP + NT4 legacy).
+ *
+ * @param  pDevObj    Device object.
+ * @param  pIrp       Request packet.
+ */
+#ifndef TARGET_NT4
+NTSTATUS vboxguestwinInit(PDEVICE_OBJECT pDevObj, PIRP pIrp)
+#else
+NTSTATUS vboxguestwinInit(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath)
+#endif
+{
+    PVBOXGUESTDEVEXT pDevExt   = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
+#ifndef TARGET_NT4
+    PIO_STACK_LOCATION pStack  = IoGetCurrentIrpStackLocation(pIrp);
+#endif
+
+    Log(("VBoxGuest::vboxguestwinInit\n"));
+
+    int rc = STATUS_SUCCESS;
+#ifdef TARGET_NT4
+    /*
+     * Let's have a look at what our PCI adapter offers.
+     */
+    Log(("VBoxGuest::vboxguestwinInit: Starting to scan PCI resources of VBoxGuest ...\n"));
+
+    /* Assign the PCI resources. */
+    PCM_RESOURCE_LIST pResourceList = NULL;
+    UNICODE_STRING classNameString;
+    RtlInitUnicodeString(&classNameString, L"VBoxGuestAdapter");
+    rc = HalAssignSlotResources(pRegPath, &classNameString,
+                                pDrvObj, pDevObj,
+                                PCIBus, pDevExt->win.s.busNumber, pDevExt->win.s.slotNumber,
+                                &pResourceList);
+    if (pResourceList && pResourceList->Count > 0)
+        vboxguestwinShowDeviceResources(&pResourceList->List[0].PartialResourceList);
+    if (NT_SUCCESS(rc))
+        rc = vboxguestwinScanPCIResourceList(pResourceList, pDevExt);
+#else
+    if (pStack->Parameters.StartDevice.AllocatedResources->Count > 0)
+        vboxguestwinShowDeviceResources(&pStack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList);
+    if (NT_SUCCESS(rc))
+        rc = vboxguestwinScanPCIResourceList(pStack->Parameters.StartDevice.AllocatedResourcesTranslated,
+                                             pDevExt);
+#endif
+    if (NT_SUCCESS(rc))
+    {
+        /*
+         * Map physical address of VMMDev memory into MMIO region
+         * and init the common device extension bits.
+         */
+        void *pvMMIOBase = NULL;
+        uint32_t cbMMIO = 0;
+        rc = vboxguestwinMapVMMDevMemory(pDevExt,
+                                         pDevExt->win.s.vmmDevPhysMemoryAddress,
+                                         pDevExt->win.s.vmmDevPhysMemoryLength,
+                                         &pvMMIOBase,
+                                         &cbMMIO);
+        if (NT_SUCCESS(rc))
+        {
+            pDevExt->pVMMDevMemory = (VMMDevMemory *)pvMMIOBase;
+
+            Log(("VBoxGuest::vboxguestwinInit: pvMMIOBase = 0x%p, pDevExt = 0x%p, pDevExt->pVMMDevMemory = 0x%p\n",
+                 pvMMIOBase, pDevExt, pDevExt ? pDevExt->pVMMDevMemory : NULL));
+
+            int vrc = VBoxGuestInitDevExt(pDevExt,
+                                          pDevExt->IOPortBase,
+                                          pvMMIOBase, cbMMIO,
+                                          vboxguestwinVersionToOSType(g_winVersion),
+                                          VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
+            if (RT_FAILURE(vrc))
+            {
+                Log(("VBoxGuest::vboxguestwinInit: Could not init device extension, rc = %Rrc!\n", vrc));
+                rc = STATUS_DEVICE_CONFIGURATION_ERROR;
+            }
+        }
+        else
+            Log(("VBoxGuest::vboxguestwinInit: Could not map physical address of VMMDev, rc = 0x%x!\n", rc));
+    }
+
+    if (NT_SUCCESS(rc))
+    {
+        int vrc = VbglGRAlloc((VMMDevRequestHeader **)&pDevExt->win.s.pPowerStateRequest,
+                              sizeof (VMMDevPowerStateRequest), VMMDevReq_SetPowerStatus);
+        if (RT_FAILURE(vrc))
+        {
+            Log(("VBoxGuest::vboxguestwinInit: Alloc for pPowerStateRequest failed, rc = %Rrc\n", vrc));
+            rc = STATUS_UNSUCCESSFUL;
+        }
+    }
+
+    if (NT_SUCCESS(rc))
+    {
+        /*
+         * Register DPC and ISR.
+         */
+        Log(("VBoxGuest::vboxguestwinInit: Initializing DPC/ISR ...\n"));
+
+        IoInitializeDpcRequest(pDevExt->win.s.pDeviceObject, vboxguestwinDpcHandler);
+#ifdef TARGET_NT4
+        /* Get an interrupt vector. */
+        /* Only proceed if the device provides an interrupt. */
+        if (   pDevExt->win.s.interruptLevel
+            || pDevExt->win.s.interruptVector)
+        {
+            pDevExt->win.s.interruptVector = HalGetInterruptVector(PCIBus,
+                                                                   pDevExt->win.s.busNumber,
+                                                                   pDevExt->win.s.interruptLevel,
+                                                                   pDevExt->win.s.interruptVector,
+                                                                   (PKIRQL)pDevExt->win.s.interruptLevel,
+                                                                   &pDevExt->win.s.interruptAffinity);
+        }
+        else
+            Log(("VBoxGuest::vboxguestwinInit: Device does not provide an interrupt!\n"));
+#endif
+        if (pDevExt->win.s.interruptVector)
+        {
+            rc = IoConnectInterrupt(&pDevExt->win.s.pInterruptObject,          /* Out: interrupt object. */
+                                    (PKSERVICE_ROUTINE)vboxguestwinIsrHandler, /* Our ISR handler. */
+                                    pDevExt,                                   /* Device context. */
+                                    NULL,                                      /* Optional spinlock. */
+                                    pDevExt->win.s.interruptVector,            /* Interrupt vector. */
+                                    (KIRQL)pDevExt->win.s.interruptLevel,      /* Interrupt level. */
+                                    (KIRQL)pDevExt->win.s.interruptLevel,      /* Interrupt level. */
+                                    pDevExt->win.s.interruptMode,              /* LevelSensitive or Latched. */
+                                    TRUE,                                      /* Shareable interrupt. */
+                                    pDevExt->win.s.interruptAffinity,          /* CPU affinity. */
+                                    FALSE);                                    /* Don't save FPU stack. */
+            if (NT_ERROR(rc))
+                Log(("VBoxGuest::vboxguestwinInit: Could not connect interrupt, rc = 0x%x\n", rc));
+        }
+        else
+            Log(("VBoxGuest::vboxguestwinInit: No interrupt vector found!\n"));
+    }
+
+
+#ifdef VBOX_WITH_HGCM
+    /* Initialize the HGCM event notification semaphore. */
+    KeInitializeEvent(&pDevExt->win.s.hgcm.s.keventNotification, NotificationEvent, FALSE);
+
+    /* Preallocated constant timeout 250ms for HGCM async waiter. */
+    pDevExt->win.s.hgcm.s.WaitTimeout.QuadPart  = 250;
+    pDevExt->win.s.hgcm.s.WaitTimeout.QuadPart *= -10000; /* Relative in 100ns units. */
+
+    int vrc = VBoxGuestCreateKernelSession(pDevExt, &pDevExt->win.s.pKernelSession);
+    if (RT_FAILURE(vrc))
+    {
+        Log(("VBoxGuest::vboxguestwinInit: Failed to allocated kernel session data! rc = %Rrc\n", rc));
+        rc = STATUS_UNSUCCESSFUL;
+    }
+#endif
+
+    if (RT_SUCCESS(rc))
+    {
+        /* Ready to rumble! */
+        Log(("VBoxGuest::vboxguestwinInit: Device is ready!\n"));
+        pDevExt->win.s.devState = WORKING;
+    }
+
+    Log(("VBoxGuest::vboxguestwinInit: Returned with rc = 0x%x\n", rc));
+    return rc;
+}
+
+
+/**
  * Cleans up all data (like device extension and guest mapping).
  *
  * @param   pDrvObj     Driver object.
- * @param   pIrp        Request packet.
- */
-NTSTATUS vboxguestwinCleanup(PDEVICE_OBJECT pDevObj, PIRP pIrp)
+ */
+NTSTATUS vboxguestwinCleanup(PDEVICE_OBJECT pDevObj)
 {
     Log(("VBoxGuest::vboxguestwinCleanup\n"));
 
-    NOREF(pIrp);
     PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
-
     if (pDevExt)
     {
+#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
+        hlpDeregisterBugCheckCallback(pDevExt); /* ignore failure! */
+#endif
         /* According to MSDN we have to unmap previously mapped memory. */
         vboxguestwinUnmapVMMDevMemory(pDevExt);
@@ -307,15 +533,5 @@
     Log(("VBoxGuest::vboxguestwinGuestUnload\n"));
 #ifdef TARGET_NT4
-    PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDrvObj->DeviceObject->DeviceExtension;
-    unreserveHypervisorMemory(pDevExt);
-
-    hlpVBoxUnmapVMMDevMemory (pDevExt);
-
-    VBoxCleanupMemBalloon(pDevExt);
-
-#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
-    hlpDeregisterBugCheckCallback(pDevExt); /* ignore failure! */
-#endif
-
+    vboxguestwinCleanup(pDrvObj->DeviceObject);
     /*
      * I don't think it's possible to unload a driver which processes have
@@ -508,46 +724,4 @@
         /* Add at least one (bogus) fall through case to shut up MSVC! */
         case 0:
-#endif
-
-#if 0
-#ifdef VBOX_WITH_MANAGEMENT
-        case VBOXGUEST_IOCTL_CHECK_BALLOON:
-        {
-            VBoxGuestCheckBalloonInfo *pInfo = (VBoxGuestCheckBalloonInfo *)pBuf;
-
-            if (pStack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(VBoxGuestCheckBalloonInfo))
-            {
-                Log(("VBoxGuest::vboxguestwinGuestDeviceControl: OutputBufferLength %d != sizeof(ULONG) %d\n",
-                         pStack->Parameters.DeviceIoControl.OutputBufferLength, sizeof(VBoxGuestCheckBalloonInfo)));
-                Status = STATUS_INVALID_PARAMETER;
-                break;
-            }
-
-            ULONG cMemoryBalloonChunks;
-            int rc = VBoxGuestQueryMemoryBalloon(pDevExt, &cMemoryBalloonChunks);
-            if (RT_FAILURE(rc))
-            {
-                Log(("VBOXGUEST_IOCTL_CHECK_BALLOON: vbox rc = %Rrc\n", rc));
-                Status = STATUS_UNSUCCESSFUL;
-            }
-            else
-            {
-                cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength;
-                pInfo->cBalloonChunks = cMemoryBalloonChunks;
-                pInfo->fHandleInR3 = false;
-            }
-            break;
-        }
-#endif
-
-        case VBOXGUEST_IOCTL_LOG(0):    /* The size isn't relevant on NT. */
-        {
-            /* Enable this only for debugging:
-            Log(("VBoxGuest::vboxguestwinGuestDeviceControl: VBOXGUEST_IOCTL_LOG %.*s\n", (int)pStack->Parameters.DeviceIoControl.InputBufferLength, pBuf));
-             */
-            LogRel(("%.*s", (int)pStack->Parameters.DeviceIoControl.InputBufferLength, pBuf));
-            cbOut = 0;
-            break;
-        }
 #endif
         default:
Index: trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.h
===================================================================
--- trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.h	(revision 32317)
+++ trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.h	(revision 32322)
@@ -174,5 +174,11 @@
 
 RT_C_DECLS_BEGIN
-NTSTATUS   vboxguestwinCleanup(PDEVICE_OBJECT pDevObj, PIRP pIrp);
+#ifdef TARGET_NT4
+NTSTATUS   vboxguestwinnt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
+NTSTATUS   vboxguestwinInit(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath);
+#else
+NTSTATUS   vboxguestwinInit(PDEVICE_OBJECT pDevObj, PIRP pIrp);
+#endif
+NTSTATUS   vboxguestwinCleanup(PDEVICE_OBJECT pDevObj);
 NTSTATUS   vboxguestwinPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp);
 VOID       vboxguestwinDpcHandler(PKDPC pDPC, PDEVICE_OBJECT pDevObj, PIRP pIrp, PVOID pContext);
@@ -186,4 +192,13 @@
 RT_C_DECLS_END
 
+#ifdef TARGET_NT4
+/*
+ * XP DDK #defines ExFreePool to ExFreePoolWithTag. The latter does not exist
+ * on NT4, so... The same for ExAllocatePool.
+ */
+#undef ExAllocatePool
+#undef ExFreePool
+#endif
+
 #endif /* ___VBoxGuest_win_h */
 
