extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char ** /*envp*/) { /* Start logging: */ LogFlowFuncEnter(); /* Failed result initially: */ int iResultCode = 1; #ifdef Q_WS_X11 if (!VBoxXInitThreads()) return 1; #endif /* Simulate try-catch block: */ do { #ifdef RT_OS_DARWIN ShutUpAppKit(); #endif /* RT_OS_DARWIN */ /* Console help preprocessing: */ bool fHelpShown = false; for (int i = 0; i < argc; ++i) { if ( !strcmp(argv[i], "-h") || !strcmp(argv[i], "-?") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) { showHelp(); fHelpShown = true; break; } } if (fHelpShown) { iResultCode = 0; break; } #if defined(DEBUG) && defined(Q_WS_X11) && defined(RT_OS_LINUX) /* Install our signal handler to backtrace the call stack: */ struct sigaction sa; sa.sa_sigaction = bt_sighandler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); sigaction(SIGUSR1, &sa, NULL); #endif #ifdef Q_WS_MAC /* Mavericks font fix: */ if (VBoxGlobal::osRelease() == MacOSXRelease_Mavericks) QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); # ifdef QT_MAC_USE_COCOA /* Instantiate our NSApplication derivative before QApplication * forces NSApplication to be instantiated. */ UICocoaApplication::instance(); # endif /* QT_MAC_USE_COCOA */ #endif /* Q_WS_MAC */ /* Install Qt console message handler: */ qInstallMsgHandler(QtMessageOutput); #ifdef Q_WS_X11 /* Qt has a complex algorithm for selecting the right visual which * doesn't always seem to work. So we naively choose a visual - the * default one - ourselves and pass that to Qt. This means that we * also have to open the display ourselves. * We check the Qt parameter list and handle Qt's -display argument * ourselves, since we open the display connection. We also check the * to see if the user has passed Qt's -visual parameter, and if so we * assume that the user wants Qt to handle visual selection after all, * and don't supply a visual. */ char *pszDisplay = NULL; bool useDefaultVisual = true; for (int i = 0; i < argc; ++i) { if (!::strcmp(argv[i], "-display") && (i + 1 < argc)) /* What if it isn't? Rely on QApplication to complain? */ { pszDisplay = argv[i + 1]; ++i; } else if (!::strcmp(argv[i], "-visual")) useDefaultVisual = false; } Display *pDisplay = XOpenDisplay(pszDisplay); if (!pDisplay) { RTPrintf(pszDisplay ? "Failed to open the X11 display \"%s\"!\n" : "Failed to open the X11 display!\n", pszDisplay); break; } Visual *pVisual = useDefaultVisual ? DefaultVisual(pDisplay, DefaultScreen(pDisplay)) : NULL; /* Now create the application object: */ QApplication a(pDisplay, argc, argv, (Qt::HANDLE)pVisual); #else /* Q_WS_X11 */ QApplication a(argc, argv); #endif /* Q_WS_X11 */ #ifdef Q_OS_SOLARIS /* Use plastique look&feel for Solaris instead of the default motif (Qt 4.7.x): */ QApplication::setStyle(new QPlastiqueStyle); #endif /* Q_OS_SOLARIS */ #ifdef Q_WS_X11 /* This patch is not used for now on Solaris & OpenSolaris because * there is no anti-aliasing enabled by default, Qt4 to be rebuilt. */ # ifndef Q_OS_SOLARIS /* Cause Qt4 has the conflict with fontconfig application as a result * sometimes substituting some fonts with non scaleable-anti-aliased * bitmap font we are reseting substitutes for the current application * font family if it is non scaleable-anti-aliased. */ QFontDatabase fontDataBase; QString currentFamily(QApplication::font().family()); bool isCurrentScaleable = fontDataBase.isScalable(currentFamily); QString subFamily(QFont::substitute(currentFamily)); bool isSubScaleable = fontDataBase.isScalable(subFamily); if (isCurrentScaleable && !isSubScaleable) QFont::removeSubstitution(currentFamily); # endif /* Q_OS_SOLARIS */ #endif /* Q_WS_X11 */ #ifdef Q_WS_WIN /* Drag in the sound drivers and DLLs early to get rid of the delay taking * place when the main menu bar (or any action from that menu bar) is * activated for the first time. This delay is especially annoying if it * happens when the VM is executing in real mode (which gives 100% CPU * load and slows down the load process that happens on the main GUI * thread to several seconds). */ PlaySound(NULL, NULL, 0); #endif /* Q_WS_WIN */ #ifdef Q_WS_MAC /* Disable menu icons on MacOS X host: */ ::darwinDisableIconsInMenus(); #endif /* Q_WS_MAC */ #ifdef Q_WS_X11 /* Qt version check (major.minor are sensitive, fix number is ignored): */ if (VBoxGlobal::qtRTVersion() < (VBoxGlobal::qtCTVersion() & 0xFFFF00)) { QString strMsg = QApplication::tr("Executable <b>%1</b> requires Qt %2.x, found Qt %3.") .arg(qAppName()) .arg(VBoxGlobal::qtCTVersionString().section('.', 0, 1)) .arg(VBoxGlobal::qtRTVersionString()); QMessageBox::critical(0, QApplication::tr("Incompatible Qt Library Error"), strMsg, QMessageBox::Abort, 0); qFatal("%s", strMsg.toAscii().constData()); break; } #endif /* Q_WS_X11 */ /* Create modal-window manager: */ UIModalWindowManager::create(); /* Create global UI instance: */ VBoxGlobal::create(); /* Simulate try-catch block: */ do { /* Exit if VBoxGlobal is not valid: */ if (!vboxGlobal().isValid()) break; /* Exit if VBoxGlobal was able to pre-process arguments: */ if (vboxGlobal().processArgs()) break; #ifdef RT_OS_LINUX /* Make sure no wrong USB mounted: */ VBoxGlobal::checkForWrongUSBMounted(); #endif /* RT_OS_LINUX */ /* Load application settings: */ VBoxGlobalSettings settings = vboxGlobal().settings(); /* VM console process: */ if (vboxGlobal().isVMConsoleProcess()) { /* Make sure VM is started: */ if (!vboxGlobal().startMachine(vboxGlobal().managedVMUuid())) break; /* Start application: */ iResultCode = a.exec(); } /* VM selector process: */ else { /* Make sure VM selector is permitted: */ if (settings.isFeatureActive("noSelector")) { msgCenter().cannotStartSelector(); break; } #ifdef VBOX_BLEEDING_EDGE msgCenter().showBEBWarning(); #else /* VBOX_BLEEDING_EDGE */ # ifndef DEBUG /* Check for BETA version: */ QString vboxVersion(vboxGlobal().virtualBox().GetVersion()); if (vboxVersion.contains("BETA")) { /* Allow to prevent this message: */ QString str = vboxGlobal().virtualBox().GetExtraData(GUI_PreventBetaWarning); if (str != vboxVersion) msgCenter().showBETAWarning(); } # endif /* !DEBUG */ #endif /* !VBOX_BLEEDING_EDGE*/ /* Create/show selector window: */ vboxGlobal().selectorWnd().show(); /* Start application: */ iResultCode = a.exec(); } } while (0); /* Destroy global UI instance: */ VBoxGlobal::destroy(); /* Destroy modal-window manager: */ UIModalWindowManager::destroy(); } while (0); /* Finish logging: */ LogFlowFunc(("rc=%d\n", iResultCode)); LogFlowFuncLeave(); /* Return result: */ return iResultCode; }
int main(int argc, char **argv, char **envp) { /* Initialize VBox Runtime. * Initialize the SUPLib as well only if we are really about to start a VM. * Don't do this if we are only starting the selector window. */ bool fInitSUPLib = false; #ifdef Q_WS_X11 if (!VBoxXInitThreads()) return 1; #endif for (int i = 1; i < argc; ++i) { /* NOTE: the check here must match the corresponding check for the * options to start a VM in hardenedmain.cpp and VBoxGlobal.cpp exactly, * otherwise there will be weird error messages. */ if ( !::strcmp(argv[i], "--startvm") || !::strcmp(argv[i], "-startvm")) { fInitSUPLib = true; break; } } int rc = RTR3InitExe(argc, &argv, fInitSUPLib ? RTR3INIT_FLAGS_SUPLIB : 0); /* Initialization failed: */ if (RT_FAILURE(rc)) { /* We have to create QApplication anyway * just to show the only one error-message: */ QApplication a(argc, &argv[0]); #ifdef Q_OS_SOLARIS /* Use plastique look&feel for Solaris instead of the default motif (Qt 4.7.x): */ QApplication::setStyle(new QPlastiqueStyle); #endif /* Q_OS_SOLARIS */ /* Prepare the error-message: */ QString strTitle = QApplication::tr("VirtualBox - Runtime Error"); QString strText = "<html>"; switch (rc) { case VERR_VM_DRIVER_NOT_INSTALLED: case VERR_VM_DRIVER_LOAD_ERROR: strText += QApplication::tr("<b>Cannot access the kernel driver!</b><br/><br/>"); # ifdef RT_OS_LINUX strText += g_QStrHintLinuxNoDriver; # else /* RT_OS_LINUX */ strText += g_QStrHintOtherNoDriver; # endif /* !RT_OS_LINUX */ break; # ifdef RT_OS_LINUX case VERR_NO_MEMORY: strText += g_QStrHintLinuxNoMemory; break; # endif /* RT_OS_LINUX */ case VERR_VM_DRIVER_NOT_ACCESSIBLE: strText += QApplication::tr("Kernel driver not accessible"); break; case VERR_VM_DRIVER_VERSION_MISMATCH: # ifdef RT_OS_LINUX strText += g_QStrHintLinuxWrongDriverVersion; # else /* RT_OS_LINUX */ strText += g_QStrHintOtherWrongDriverVersion; # endif /* !RT_OS_LINUX */ break; default: strText += QApplication::tr("Unknown error %2 during initialization of the Runtime").arg(rc); break; } strText += "</html>"; /* Show the error-message: */ QMessageBox::critical(0 /* parent */, strTitle, strText, QMessageBox::Abort /* 1st button */, 0 /* 2nd button */); /* Default error-result: */ return 1; } /* Actual main function: */ return TrustedMain(argc, argv, envp); }
extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char ** /*envp*/) { /* Start logging: */ LogFlowFuncEnter(); /* Failed result initially: */ int iResultCode = 1; #ifdef Q_WS_X11 if (!VBoxXInitThreads()) return 1; #endif /* Q_WS_X11 */ /* Simulate try-catch block: */ do { #ifdef RT_OS_DARWIN ShutUpAppKit(); #endif /* RT_OS_DARWIN */ /* Console help preprocessing: */ bool fHelpShown = false; for (int i = 0; i < argc; ++i) { if ( !strcmp(argv[i], "-h") || !strcmp(argv[i], "-?") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) { showHelp(); fHelpShown = true; break; } } if (fHelpShown) { iResultCode = 0; break; } #if defined(DEBUG) && defined(Q_WS_X11) && defined(RT_OS_LINUX) /* Install our signal handler to backtrace the call stack: */ struct sigaction sa; sa.sa_sigaction = bt_sighandler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); sigaction(SIGUSR1, &sa, NULL); #endif #ifdef VBOX_WITH_HARDENING /* Make sure the image verification code works (VBoxDbg.dll and other plugins). */ SUPR3HardenedVerifyInit(); #endif #ifdef Q_WS_MAC /* Font fixes: */ switch (VBoxGlobal::osRelease()) { case MacOSXRelease_Mavericks: QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); break; case MacOSXRelease_Yosemite: QFont::insertSubstitution(".Helvetica Neue DeskInterface", "Helvetica Neue"); break; default: break; } # ifdef QT_MAC_USE_COCOA /* Instantiate our NSApplication derivative before QApplication * forces NSApplication to be instantiated. */ UICocoaApplication::instance(); # endif /* QT_MAC_USE_COCOA */ #endif /* Q_WS_MAC */ /* Install Qt console message handler: */ qInstallMsgHandler(QtMessageOutput); /* Create application: */ QApplication a(argc, argv); #ifdef Q_WS_X11 /* To avoid various Qt crashes * when testing widget attributes or acquiring winIds * we decided to make our widgets native under x11 hosts. * Yes, we aware of note that alien widgets faster to draw * but the only widget we need to be fast - viewport of VM * was always native since we are using his id for 3d service needs. */ a.setAttribute(Qt::AA_NativeWindows); #endif /* Q_WS_X11 */ #ifdef Q_WS_MAC # ifdef VBOX_GUI_WITH_HIDPI /* Enable HiDPI icons. For this we require a patched version of Qt 4.x with * the changes from https://codereview.qt-project.org/#change,54636 applied. */ qApp->setAttribute(Qt::AA_UseHighDpiPixmaps); # endif /* VBOX_GUI_WITH_HIDPI */ #endif /* Q_WS_MAC */ #ifdef Q_OS_SOLARIS /* Use plastique look&feel for Solaris instead of the default motif (Qt 4.7.x): */ QApplication::setStyle(new QPlastiqueStyle); #endif /* Q_OS_SOLARIS */ #ifdef Q_WS_X11 /* This patch is not used for now on Solaris & OpenSolaris because * there is no anti-aliasing enabled by default, Qt4 to be rebuilt. */ # ifndef Q_OS_SOLARIS /* Cause Qt4 has the conflict with fontconfig application as a result * sometimes substituting some fonts with non scaleable-anti-aliased * bitmap font we are reseting substitutes for the current application * font family if it is non scaleable-anti-aliased. */ QFontDatabase fontDataBase; QString currentFamily(QApplication::font().family()); bool isCurrentScaleable = fontDataBase.isScalable(currentFamily); QString subFamily(QFont::substitute(currentFamily)); bool isSubScaleable = fontDataBase.isScalable(subFamily); if (isCurrentScaleable && !isSubScaleable) QFont::removeSubstitution(currentFamily); # endif /* Q_OS_SOLARIS */ #endif /* Q_WS_X11 */ #ifdef Q_WS_WIN /* Drag in the sound drivers and DLLs early to get rid of the delay taking * place when the main menu bar (or any action from that menu bar) is * activated for the first time. This delay is especially annoying if it * happens when the VM is executing in real mode (which gives 100% CPU * load and slows down the load process that happens on the main GUI * thread to several seconds). */ PlaySound(NULL, NULL, 0); #endif /* Q_WS_WIN */ #ifdef Q_WS_MAC /* Disable menu icons on MacOS X host: */ ::darwinDisableIconsInMenus(); #endif /* Q_WS_MAC */ #ifdef Q_WS_X11 /* Qt version check (major.minor are sensitive, fix number is ignored): */ if (VBoxGlobal::qtRTVersion() < (VBoxGlobal::qtCTVersion() & 0xFFFF00)) { QString strMsg = QApplication::tr("Executable <b>%1</b> requires Qt %2.x, found Qt %3.") .arg(qAppName()) .arg(VBoxGlobal::qtCTVersionString().section('.', 0, 1)) .arg(VBoxGlobal::qtRTVersionString()); QMessageBox::critical(0, QApplication::tr("Incompatible Qt Library Error"), strMsg, QMessageBox::Abort, 0); qFatal("%s", strMsg.toUtf8().constData()); break; } #endif /* Q_WS_X11 */ /* Create modal-window manager: */ UIModalWindowManager::create(); /* Create global UI instance: */ VBoxGlobal::create(); /* Simulate try-catch block: */ do { /* Exit if VBoxGlobal is not valid: */ if (!vboxGlobal().isValid()) break; /* Exit if VBoxGlobal was able to pre-process arguments: */ if (vboxGlobal().processArgs()) break; #ifdef RT_OS_LINUX /* Make sure no wrong USB mounted: */ VBoxGlobal::checkForWrongUSBMounted(); #endif /* RT_OS_LINUX */ /* Load application settings: */ VBoxGlobalSettings settings = vboxGlobal().settings(); /* VM console process: */ if (vboxGlobal().isVMConsoleProcess()) { /* Make sure VM is started: */ if (!UIMachine::startMachine(vboxGlobal().managedVMUuid())) break; /* Start application: */ iResultCode = a.exec(); } /* VM selector process: */ else { /* Make sure VM selector is permitted: */ if (settings.isFeatureActive("noSelector")) { msgCenter().cannotStartSelector(); break; } #ifdef VBOX_BLEEDING_EDGE msgCenter().showExperimentalBuildWarning(); #else /* VBOX_BLEEDING_EDGE */ # ifndef DEBUG /* Check for BETA version: */ const QString vboxVersion(vboxGlobal().virtualBox().GetVersion()); if ( vboxVersion.contains("BETA") && gEDataManager->preventBetaBuildWarningForVersion() != vboxVersion) msgCenter().showBetaBuildWarning(); # endif /* !DEBUG */ #endif /* !VBOX_BLEEDING_EDGE*/ /* Create/show selector window: */ vboxGlobal().selectorWnd().show(); /* Start application: */ iResultCode = a.exec(); } } while (0); /* Destroy global UI instance: */ VBoxGlobal::destroy(); /* Destroy modal-window manager: */ UIModalWindowManager::destroy(); } while (0); /* Finish logging: */ LogFlowFunc(("rc=%d\n", iResultCode)); LogFlowFuncLeave(); /* Return result: */ return iResultCode; }