Index: /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 35829)
+++ /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 35830)
@@ -224,29 +224,18 @@
 };
 
-/*
- * VC++ 8 / amd64 has some serious trouble with this function.
- * As a temporary measure, we'll drop global optimizations.
- */
-#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
-# pragma optimize("g", off)
-#endif
-
-static int findEfiRom(IVirtualBox* vbox, FirmwareType_T aFirmwareType, Utf8Str& aEfiRomFile)
+static int findEfiRom(IVirtualBox* vbox, FirmwareType_T aFirmwareType, Utf8Str *pEfiRomFile)
 {
-    int rc;
+    Bstr aFilePath, empty;
     BOOL fPresent = FALSE;
-    Bstr aFilePath, empty;
-
-    rc = vbox->CheckFirmwarePresent(aFirmwareType, empty.raw(),
-                                    empty.asOutParam(), aFilePath.asOutParam(), &fPresent);
-    if (RT_FAILURE(rc))
-        AssertComRCReturn(rc, VERR_FILE_NOT_FOUND);
+    HRESULT hrc = vbox->CheckFirmwarePresent(aFirmwareType, empty.raw(),
+                                             empty.asOutParam(), aFilePath.asOutParam(), &fPresent);
+    AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc));
 
     if (!fPresent)
         return VERR_FILE_NOT_FOUND;
 
-    aEfiRomFile = Utf8Str(aFilePath);
-
-    return S_OK;
+    *pEfiRomFile = Utf8Str(aFilePath);
+
+    return VINF_SUCCESS;
 }
 
@@ -318,4 +307,14 @@
 }
 
+
+/*
+ * VC++ 8 / amd64 has some serious trouble with the next functions.
+ * As a temporary measure, we'll drop global optimizations.
+ */
+#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
+# pragma optimize("g", off)
+#endif
+
+
 class ConfigError : public iprt::Error
 {
@@ -533,7 +532,4 @@
 {
     LogFlowFuncEnter();
-    PciBusAddress         PciAddr;
-    bool fFdcEnabled = false;
-    BOOL fIs64BitGuest = false;
 
 #if !defined(VBOX_WITH_XPCOM)
@@ -589,5 +585,5 @@
     RTUUID HardwareUuid;
     rc = RTUuidFromUtf16(&HardwareUuid, bstr.raw());
-    AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
+    AssertRCReturn(rc, rc);
 
     ULONG cRamMBs;
@@ -597,8 +593,8 @@
         cRamMBs = RTStrToUInt64(RTEnvGet("VBOX_RAM_SIZE"));
 #endif
-    uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
-    uint32_t cbRamHole = MM_RAM_HOLE_SIZE_DEFAULT;
-    uint64_t u64McfgBase   = 0;
-    uint32_t u32McfgLength = 0;
+    uint64_t const cbRam   = cRamMBs * (uint64_t)_1M;
+    uint32_t cbRamHole     = MM_RAM_HOLE_SIZE_DEFAULT;
+    uint64_t uMcfgBase     = 0;
+    uint32_t cbMcfgLength  = 0;
 
     ChipsetType_T chipsetType;
@@ -608,7 +604,7 @@
         /* We'd better have 0x10000000 region, to cover 256 buses
            but this put too much load on hypervisor heap */
-        u32McfgLength = 0x4000000; //0x10000000;
-        cbRamHole += u32McfgLength;
-        u64McfgBase = _4G - cbRamHole;
+        cbMcfgLength = 0x4000000; //0x10000000;
+        cbRamHole += cbMcfgLength;
+        uMcfgBase = _4G - cbRamHole;
     }
 
@@ -649,5 +645,5 @@
          */
         hrc = pMachine->COMGETTER(Name)(bstr.asOutParam());                                 H();
-        InsertConfigString(pRoot, "Name",                 bstr);
+        InsertConfigString(pRoot,  "Name",                 bstr);
         InsertConfigBytes(pRoot,   "UUID", &HardwareUuid, sizeof(HardwareUuid));
         InsertConfigInteger(pRoot, "RamSize",              cbRam);
@@ -756,5 +752,6 @@
          * Hardware virtualization settings.
          */
-        PCFGMNODE pHWVirtExt;
+        BOOL        fIsGuest64Bit = false;
+        PCFGMNODE   pHWVirtExt;
         InsertConfigNode(pRoot, "HWVirtExt", &pHWVirtExt);
         if (fHWVirtExEnabled)
@@ -769,7 +766,7 @@
             hrc = host->GetProcessorFeature(ProcessorFeature_LongMode,
                                             &fSupportsLongMode);                            H();
-            hrc = guestOSType->COMGETTER(Is64Bit)(&fIs64BitGuest);                          H();
-
-            if (fSupportsLongMode && fIs64BitGuest)
+            hrc = guestOSType->COMGETTER(Is64Bit)(&fIsGuest64Bit);                          H();
+
+            if (fSupportsLongMode && fIsGuest64Bit)
             {
                 InsertConfigInteger(pHWVirtExt, "64bitEnabled", 1);
@@ -788,5 +785,5 @@
 
             /** @todo Not exactly pretty to check strings; VBOXOSTYPE would be better, but that requires quite a bit of API change in Main. */
-            if (    !fIs64BitGuest
+            if (    !fIsGuest64Bit
                 &&  fIOAPIC
                 &&  (   osTypeId == "WindowsNT4"
@@ -947,5 +944,5 @@
          * PCI buses.
          */
-        uint32_t u32IocPciAddress, u32HbcPciAddress;
+        uint32_t uIocPciAddress, uHbcPciAddress;
         switch (chipsetType)
         {
@@ -954,11 +951,11 @@
             case ChipsetType_PIIX3:
                 InsertConfigNode(pDevices, "pci", &pDev);
-                u32HbcPciAddress = (0x0 << 16) | 0;
-                u32IocPciAddress = (0x1 << 16) | 0; // ISA controller
+                uHbcPciAddress = (0x0 << 16) | 0;
+                uIocPciAddress = (0x1 << 16) | 0; // ISA controller
                 break;
             case ChipsetType_ICH9:
                 InsertConfigNode(pDevices, "ich9pci", &pDev);
-                u32HbcPciAddress = (0x1e << 16) | 0;
-                u32IocPciAddress = (0x1f << 16) | 0; // LPC controller
+                uHbcPciAddress = (0x1e << 16) | 0;
+                uIocPciAddress = (0x1f << 16) | 0; // LPC controller
                 break;
         }
@@ -970,6 +967,6 @@
         {
             /* Provide MCFG info */
-            InsertConfigInteger(pCfg,  "McfgBase",   u64McfgBase);
-            InsertConfigInteger(pCfg,  "McfgLength", u32McfgLength);
+            InsertConfigInteger(pCfg,  "McfgBase",   uMcfgBase);
+            InsertConfigInteger(pCfg,  "McfgLength", cbMcfgLength);
 
 
@@ -1024,5 +1021,5 @@
             Bstr bstrKey;
             rc = getSmcDeviceKey(pMachine, bstrKey.asOutParam(), &fGetKeyFromRealSMC);
-            AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
+            AssertRCReturn(rc, rc);
 
             InsertConfigString(pCfg,   "DeviceKey", bstrKey);
@@ -1242,6 +1239,6 @@
             InsertConfigBytes(pBiosCfg,    "UUID", &HardwareUuid,sizeof(HardwareUuid));
             InsertConfigNode(pBiosCfg,     "NetBoot", &pNetBootCfg);
-            InsertConfigInteger(pBiosCfg,  "McfgBase",   u64McfgBase);
-            InsertConfigInteger(pBiosCfg,  "McfgLength", u32McfgLength);
+            InsertConfigInteger(pBiosCfg,  "McfgBase",   uMcfgBase);
+            InsertConfigInteger(pBiosCfg,  "McfgLength", cbMcfgLength);
 
             DeviceType_T bootDevice;
@@ -1288,19 +1285,16 @@
         else
         {
-            Utf8Str efiRomFile;
-
             /* Autodetect firmware type, basing on guest type */
             if (eFwType == FirmwareType_EFI)
             {
-                eFwType =
-                        fIs64BitGuest ?
-                        (FirmwareType_T)FirmwareType_EFI64
-                        :
-                        (FirmwareType_T)FirmwareType_EFI32;
-            }
-            bool f64BitEntry = eFwType == FirmwareType_EFI64;
-
-            rc = findEfiRom(virtualBox, eFwType, efiRomFile);
-            AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
+                eFwType = fIsGuest64Bit
+                        ? (FirmwareType_T)FirmwareType_EFI64
+                        : (FirmwareType_T)FirmwareType_EFI32;
+            }
+            bool const f64BitEntry = eFwType == FirmwareType_EFI64;
+
+            Utf8Str efiRomFile;
+            rc = findEfiRom(virtualBox, eFwType, &efiRomFile);
+            AssertRCReturn(rc, rc);
 
             /* Get boot args */
@@ -1311,4 +1305,5 @@
             Bstr deviceProps;
             hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiDeviceProps").raw(), deviceProps.asOutParam()); H();
+
             /* Get GOP mode settings */
             uint32_t u32GopMode = UINT32_MAX;
@@ -1363,4 +1358,5 @@
         hrc = pMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(ctrls));       H();
 
+        bool fFdcEnabled = false;
         for (size_t i = 0; i < ctrls.size(); ++i)
         {
@@ -1461,7 +1457,7 @@
                         {
                             static const char * const s_apszConfig[4] =
-                                    { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
+                            { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
                             static const char * const s_apszBiosConfig[4] =
-                                    { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
+                            { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
 
                             LONG lPortNumber = -1;
@@ -1687,5 +1683,5 @@
                 iPciDeviceNo = 3;
 #endif
-            PciAddr = PciBusAddress(0, iPciDeviceNo, 0);
+            PciBusAddress PciAddr = PciBusAddress(0, iPciDeviceNo, 0);
             hrc = BusMgr->assignPciDevice(pszAdapterName, pInst, PciAddr);                               H();
 
@@ -2453,11 +2449,11 @@
                 }
             }
-            InsertConfigInteger(pCfg,  "IocPciAddress", u32IocPciAddress);
+            InsertConfigInteger(pCfg,  "IocPciAddress", uIocPciAddress);
             if (chipsetType == ChipsetType_ICH9)
             {
-                InsertConfigInteger(pCfg,  "McfgBase",   u64McfgBase);
-                InsertConfigInteger(pCfg,  "McfgLength", u32McfgLength);
-            }
-            InsertConfigInteger(pCfg,  "HostBusPciAddress", u32HbcPciAddress);
+                InsertConfigInteger(pCfg,  "McfgBase",   uMcfgBase);
+                InsertConfigInteger(pCfg,  "McfgLength", cbMcfgLength);
+            }
+            InsertConfigInteger(pCfg,  "HostBusPciAddress", uHbcPciAddress);
             InsertConfigInteger(pCfg,  "ShowCpu", fShowCpu);
             InsertConfigInteger(pCfg,  "CpuHotPlug", fCpuHotPlug);
@@ -2803,5 +2799,5 @@
                 if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
                     rc = VINF_SUCCESS;
-                AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
+                AssertRCReturn(rc, rc);
 
                 CFGMR3RemoveNode(pLunL0);
@@ -3040,5 +3036,5 @@
             rc = PDMR3DeviceAttach(pVM, pcszDevice, 0, uLUN,
                                 PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
-            AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
+            AssertRCReturn(rc, rc);
 
             /* There is no need to handle removable medium mounting, as we
@@ -3080,9 +3076,10 @@
         HRESULT hrc;
         Bstr bstr;
-
-#define H()         AssertMsgReturnStmt(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), if (phrc) *phrc = hrc, VERR_GENERAL_FAILURE)
-
         PCFGMNODE pLunL1 = NULL;
         PCFGMNODE pCfg = NULL;
+
+#define H() \
+    AssertMsgReturnStmt(SUCCEEDED(hrc), ("hrc=%Rhrc\n", hrc), if (phrc) *phrc = hrc, Global::vboxStatusCodeFromCOM(hrc))
+
 
         BOOL fHostDrive = FALSE;
@@ -3138,6 +3135,6 @@
             if (    pMedium
                 && (   enmType == DeviceType_DVD
-                    || enmType == DeviceType_Floppy
-            ))
+                    || enmType == DeviceType_Floppy)
+               )
             {
                 // if this medium represents an ISO image and this image is inaccessible,
@@ -3148,13 +3145,9 @@
                 // would be to discard the VM state...
                 MediumState_T mediumState;
-                rc = pMedium->RefreshState(&mediumState);
-                AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
-
+                hrc = pMedium->RefreshState(&mediumState);                              H();
                 if (mediumState == MediumState_Inaccessible)
                 {
                     Bstr loc;
-                    rc = pMedium->COMGETTER(Location)(loc.asOutParam());
-                    if (FAILED(rc)) return rc;
-
+                    hrc = pMedium->COMGETTER(Location)(loc.asOutParam());               H();
                     setVMRuntimeErrorCallbackF(mpVM,
                                             this,
@@ -3200,11 +3193,7 @@
 
                 if (mediumType == MediumType_Readonly)
-                {
                     InsertConfigInteger(pCfg, "ReadOnly", 1);
-                }
                 else if (enmType == DeviceType_Floppy)
-                {
                     InsertConfigInteger(pCfg, "MaybeReadOnly", 1);
-                }
 
                 /* Start without exclusive write access to the images. */
@@ -3220,7 +3209,5 @@
                     && (   aMachineState == MachineState_TeleportingIn
                         || aMachineState == MachineState_FaultTolerantSyncing))
-                {
                     InsertConfigInteger(pCfg, "TempReadOnly", 1);
-                }
 
                 /* Flag for opening the medium for sharing between VMs. This
@@ -3228,7 +3215,5 @@
                  * in the chain, as shared media can have no diffs. */
                 if (mediumType == MediumType_Shareable)
-                {
                     InsertConfigInteger(pCfg, "Shareable", 1);
-                }
 
                 if (!fUseHostIOCache)
@@ -3249,11 +3234,7 @@
                     InsertConfigInteger(pCfg, "SetupMerge", 1);
                     if (uImage == uMergeSource)
-                    {
                         InsertConfigInteger(pCfg, "MergeSource", 1);
-                    }
                     else if (uImage == uMergeTarget)
-                    {
                         InsertConfigInteger(pCfg, "MergeTarget", 1);
-                    }
                 }
 
@@ -3320,11 +3301,7 @@
                     {
                         if (uImage == uMergeSource)
-                        {
                             InsertConfigInteger(pCur, "MergeSource", 1);
-                        }
                         else if (uImage == uMergeTarget)
-                        {
                             InsertConfigInteger(pCur, "MergeTarget", 1);
-                        }
                     }
 
@@ -3357,7 +3334,5 @@
                      * configuration node. Simplifies life of DrvVD a bit. */
                     if (!fHostIP)
-                    {
                         InsertConfigInteger(pCfg, "HostIPStack", 0);
-                    }
 
                     /* next */
@@ -3367,4 +3342,5 @@
             }
         }
+#undef H
     }
     catch (ConfigError &x)
@@ -3373,6 +3349,4 @@
         return x.m_vrc;
     }
-
-#undef H
 
     return VINF_SUCCESS;
