RTDECL(int) RTEnvUnsetBad(const char *pszVar) { AssertReturn(strchr(pszVar, '=') == NULL, VERR_ENV_INVALID_VAR_NAME); /* * Check that it exists first. */ if (!RTEnvExist(pszVar)) return VINF_ENV_VAR_NOT_FOUND; /* * Ok, try remove it. */ #ifdef RT_OS_WINDOWS /* Use putenv(var=) since Windows does not have unsetenv(). */ size_t cchVar = strlen(pszVar); char *pszBuf = (char *)alloca(cchVar + 2); memcpy(pszBuf, pszVar, cchVar); pszBuf[cchVar] = '='; pszBuf[cchVar + 1] = '\0'; if (!putenv(pszBuf)) return VINF_SUCCESS; #else /* This is the preferred function as putenv() like used above does neither work on Solaris nor on Darwin. */ if (!unsetenv((char*)pszVar)) return VINF_SUCCESS; #endif return RTErrConvertFromErrno(errno); }
bool RTCALL VBoxOglIs3DAccelerationSupported(void) { if (RTEnvExist("VBOX_CROGL_FORCE_SUPPORTED")) { LogRel(("VBOX_CROGL_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n")); return true; } static char pszVBoxPath[RTPATH_MAX]; const char *papszArgs[4] = { NULL, "-test", "3D", NULL}; int rc; RTPROCESS Process; RTPROCSTATUS ProcStatus; uint64_t StartTS; rc = RTPathExecDir(pszVBoxPath, RTPATH_MAX); AssertRCReturn(rc, false); #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) rc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL.exe"); #else rc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL"); #endif papszArgs[0] = pszVBoxPath; /* argv[0] */ AssertRCReturn(rc, false); rc = RTProcCreate(pszVBoxPath, papszArgs, RTENV_DEFAULT, 0, &Process); if (RT_FAILURE(rc)) return false; StartTS = RTTimeMilliTS(); while (1) { rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus); if (rc != VERR_PROCESS_RUNNING) break; #ifndef DEBUG_misha if (RTTimeMilliTS() - StartTS > 30*1000 /* 30 sec */) { RTProcTerminate(Process); RTThreadSleep(100); RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus); return false; } #endif RTThreadSleep(100); } if (RT_SUCCESS(rc)) { if ((ProcStatus.enmReason==RTPROCEXITREASON_NORMAL) && (ProcStatus.iStatus==0)) { return true; } } return false; }
RTDECL(bool) RTEnvExistEx(RTENV Env, const char *pszVar) { AssertPtrReturn(pszVar, false); bool fExists = false; if (Env == RTENV_DEFAULT) { #ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API fExists = RTEnvExistsUtf8(pszVar); #else /* * Since RTEnvExist isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary * conversions here. */ char *pszVarOtherCP; int rc = RTStrUtf8ToCurrentCP(&pszVarOtherCP, pszVar); if (RT_SUCCESS(rc)) { fExists = RTEnvExist(pszVarOtherCP); RTStrFree(pszVarOtherCP); } #endif } else { PRTENVINTERNAL pIntEnv = Env; AssertPtrReturn(pIntEnv, false); AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, false); RTENV_LOCK(pIntEnv); /* * Simple search. */ const size_t cchVar = strlen(pszVar); for (size_t iVar = 0; iVar < pIntEnv->cVars; iVar++) if (!pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar)) { if (pIntEnv->papszEnv[iVar][cchVar] == '=') { fExists = true; break; } if (pIntEnv->papszEnv[iVar][cchVar] == '\0') break; } RTENV_UNLOCK(pIntEnv); } return fExists; }
/** * Waits a little while for a debuggger to attach. * * @returns True is a debugger have attached. * @param pVM Pointer to the VM. * @param enmEvent Event. */ bool dbgfR3WaitForAttach(PVM pVM, DBGFEVENTTYPE enmEvent) { /* * First a message. */ #ifndef RT_OS_L4 # if !defined(DEBUG) || defined(DEBUG_sandervl) || defined(DEBUG_frank) || defined(IEM_VERIFICATION_MODE) int cWait = 10; # else int cWait = HWACCMIsEnabled(pVM) && ( enmEvent == DBGFEVENT_ASSERTION_HYPER || enmEvent == DBGFEVENT_FATAL_ERROR) && !RTEnvExist("VBOX_DBGF_WAIT_FOR_ATTACH") ? 10 : 150; # endif RTStrmPrintf(g_pStdErr, "DBGF: No debugger attached, waiting %d second%s for one to attach (event=%d)\n", cWait / 10, cWait != 10 ? "s" : "", enmEvent); RTStrmFlush(g_pStdErr); while (cWait > 0) { RTThreadSleep(100); if (pVM->dbgf.s.fAttached) { RTStrmPrintf(g_pStdErr, "Attached!\n"); RTStrmFlush(g_pStdErr); return true; } /* next */ if (!(cWait % 10)) { RTStrmPrintf(g_pStdErr, "%d.", cWait / 10); RTStrmFlush(g_pStdErr); } cWait--; } #endif RTStrmPrintf(g_pStdErr, "Stopping the VM!\n"); RTStrmFlush(g_pStdErr); return false; }
bool RTCALL VBoxOglIs3DAccelerationSupported() { if (RTEnvExist("VBOX_CROGL_FORCE_SUPPORTED")) { LogRel(("VBOX_CROGL_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n")); return true; } CGDirectDisplayID display = CGMainDisplayID (); CGOpenGLDisplayMask cglDisplayMask = CGDisplayIDToOpenGLDisplayMask (display); CGLPixelFormatObj pixelFormat = NULL; GLint numPixelFormats = 0; CGLError rcCgl; CGLPixelFormatAttribute attribs[] = { kCGLPFADisplayMask, (CGLPixelFormatAttribute)cglDisplayMask, kCGLPFAAccelerated, kCGLPFADoubleBuffer, VBoxOglIsOfflineRenderingAppropriate() ? kCGLPFAAllowOfflineRenderers : (CGLPixelFormatAttribute)NULL, (CGLPixelFormatAttribute)NULL }; display = CGMainDisplayID(); cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(display); rcCgl = CGLChoosePixelFormat(attribs, &pixelFormat, &numPixelFormats); if (rcCgl != kCGLNoError) { LogRel(("OpenGL Info: 3D test unable to choose pixel format (rcCgl=0x%X)\n", rcCgl)); return false; } if (pixelFormat) { CGLContextObj cglContext = 0; rcCgl = CGLCreateContext(pixelFormat, NULL, &cglContext); CGLDestroyPixelFormat(pixelFormat); if (rcCgl != kCGLNoError) { LogRel(("OpenGL Info: 3D test unable to create context (rcCgl=0x%X)\n", rcCgl)); return false; } if (cglContext) { GLboolean isSupported = GL_TRUE; #ifdef VBOX_WITH_COCOA_QT /* On the Cocoa port we depend on the GL_EXT_framebuffer_object & * the GL_EXT_texture_rectangle extension. If they are not * available, disable 3D support. */ CGLSetCurrentContext(cglContext); const GLubyte* strExt; strExt = glGetString(GL_EXTENSIONS); isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt); if (isSupported) { isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_texture_rectangle", strExt); if (!isSupported) LogRel(("OpenGL Info: 3D test found that GL_EXT_texture_rectangle extension not supported\n")); } else LogRel(("OpenGL Info: 3D test found that GL_EXT_framebuffer_object extension not supported\n")); #endif /* VBOX_WITH_COCOA_QT */ CGLDestroyContext(cglContext); LogRel(("OpenGL Info: 3D test %spassed\n", isSupported == GL_TRUE ? "" : "not ")); return isSupported == GL_TRUE ? true : false; } else LogRel(("OpenGL Info: 3D test unable to create context (internal error)\n")); } else LogRel(("OpenGL Info: 3D test unable to choose pixel format (internal error)\n")); return false; }
int main(int argc, char **argv) { /* * Init IPRT. */ int rc = RTR3InitExe(argc, &argv, 0); if (RT_FAILURE(rc)) return RTMsgInitFailure(rc); /* * Locate a native DTrace command binary. */ bool fIsNativeDTrace = false; char szDTraceCmd[RTPATH_MAX]; szDTraceCmd[0] = '\0'; #if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) /* * 1. Try native first on platforms where it's applicable. */ static const char * const s_apszNativeDTrace[] = { "/usr/sbin/dtrace", "/sbin/dtrace", "/usr/bin/dtrace", "/bin/dtrace", "/usr/local/sbin/dtrace", "/usr/local/bin/dtrace" }; if (!RTEnvExist("VBOX_DTRACE_NO_NATIVE")) for (uint32_t i = 0; i < RT_ELEMENTS(s_apszNativeDTrace); i++) if (RTFileExists(s_apszNativeDTrace[i])) { fIsNativeDTrace = true; strcpy(szDTraceCmd, s_apszNativeDTrace[i]); # ifdef RT_OS_LINUX /** @todo Warn if the dtrace modules haven't been loaded or vboxdrv isn't * compiled against them. */ # endif break; } if (szDTraceCmd[0] == '\0') #endif { /* * 2. VBoxDTrace extension pack installed? * * Note! We cannot use the COM API here because this program is usually * run thru sudo or directly as root, even if the target * VirtualBox process is running as regular user. This is due to * the privileges required to run dtrace scripts on a host. */ rc = RTPathAppPrivateArch(szDTraceCmd, sizeof(szDTraceCmd)); if (RT_SUCCESS(rc)) rc = RTPathAppend(szDTraceCmd, sizeof(szDTraceCmd), VBOX_EXTPACK_INSTALL_DIR RTPATH_SLASH_STR VBOX_EXTPACK_VBOXDTRACE_MANGLED_NAME); if (RT_SUCCESS(rc)) rc = RTPathAppend(szDTraceCmd, sizeof(szDTraceCmd), RTBldCfgTargetDotArch()); if (RT_SUCCESS(rc)) rc = RTPathAppend(szDTraceCmd, sizeof(szDTraceCmd), "VBoxDTraceCmd"); if (RT_SUCCESS(rc)) rc = RTStrCat(szDTraceCmd, sizeof(szDTraceCmd), RTLdrGetSuff()); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error constructing extension pack path: %Rrc", rc); if (!RTFileExists(szDTraceCmd)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Unable to find a DTrace implementation. VBoxDTrace Extension Pack installed?"); fIsNativeDTrace = false; } /* * Construct a new command line that includes our libary. */ char szDTraceLibDir[RTPATH_MAX]; rc = RTPathAppPrivateNoArch(szDTraceLibDir, sizeof(szDTraceLibDir)); if (RT_SUCCESS(rc)) rc = RTPathAppend(szDTraceLibDir, sizeof(szDTraceLibDir), "dtrace" RTPATH_SLASH_STR "lib"); if (RT_SUCCESS(rc)) rc = RTPathAppend(szDTraceLibDir, sizeof(szDTraceLibDir), RTBldCfgTargetArch()); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error constructing dtrace library path for VBox: %Rrc", rc); char **papszArgs = (char **)RTMemAlloc((argc + 3) * sizeof(char *)); if (!papszArgs) return RTMsgErrorExit(RTEXITCODE_FAILURE, "No memory for argument list."); int cArgs = 1; papszArgs[0] = fIsNativeDTrace ? szDTraceCmd : argv[0]; if (argc > 1) { papszArgs[cArgs++] = (char *)"-L"; papszArgs[cArgs++] = szDTraceLibDir; } for (int i = 1; i < argc; i++) papszArgs[cArgs++] = argv[i]; papszArgs[cArgs] = NULL; Assert(cArgs <= argc + 3); /* * The native DTrace we execute as a sub-process and wait for. */ RTEXITCODE rcExit; if (fIsNativeDTrace) { RTPROCESS hProc; rc = RTProcCreate(szDTraceCmd, papszArgs, RTENV_DEFAULT, 0, &hProc); if (RT_SUCCESS(rc)) { RTPROCSTATUS Status; rc = RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &Status); if (RT_SUCCESS(rc)) { if (Status.enmReason == RTPROCEXITREASON_NORMAL) rcExit = (RTEXITCODE)Status.iStatus; else rcExit = RTEXITCODE_FAILURE; } else rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error waiting for child process: %Rrc", rc); } else rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error executing '%s': %Rrc", szDTraceCmd, rc); } /* * While the VBoxDTrace we load and call the main function of. */ else { RTERRINFOSTATIC ErrInfo; RTLDRMOD hMod; rc = SUPR3HardenedLdrLoadPlugIn(szDTraceCmd, &hMod, RTErrInfoInitStatic(&ErrInfo)); if (RT_SUCCESS(rc)) { PFNVBOXDTRACEMAIN pfnVBoxDTraceMain; rc = RTLdrGetSymbol(hMod, "VBoxDTraceMain", (void **)&pfnVBoxDTraceMain); if (RT_SUCCESS(rc)) rcExit = (RTEXITCODE)pfnVBoxDTraceMain(cArgs, papszArgs); else rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error locating 'VBoxDTraceMain' in '%s': %Rrc", szDTraceCmd, rc); } else rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Error loading '%s': %Rrc (%s)", szDTraceCmd, rc, ErrInfo.szMsg); } return rcExit; }
int main(int argc, char **argv) { int rc; RTR3InitExe(argc, &argv, 0); for (int i = 1; i < argc; i++) { #ifdef VBOX_OPENGL if (strcmp(argv[i], "-gl") == 0) { gfOpenGL = 1; continue; } #endif if (strcmp(argv[i], "-loop") == 0 && ++i < argc) { guLoop = atoi(argv[i]); continue; } RTPrintf("Unrecognized option '%s'\n", argv[i]); return -1; } #ifdef RT_OS_WINDOWS /* Default to DirectX if nothing else set. "windib" would be possible. */ if (!RTEnvExist("SDL_VIDEODRIVER")) { _putenv("SDL_VIDEODRIVER=directx"); } #endif #ifdef RT_OS_WINDOWS _putenv("SDL_VIDEO_WINDOW_POS=0,0"); #else RTEnvSet("SDL_VIDEO_WINDOW_POS", "0,0"); #endif rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); if (rc != 0) { RTPrintf("Error: SDL_InitSubSystem failed with message '%s'\n", SDL_GetError()); return -1; } /* output what SDL is capable of */ const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); if (!videoInfo) { RTPrintf("No SDL video info available!\n"); return -1; } RTPrintf("SDL capabilities:\n"); RTPrintf(" Hardware surface support: %s\n", videoInfo->hw_available ? "yes" : "no"); RTPrintf(" Window manager available: %s\n", videoInfo->wm_available ? "yes" : "no"); RTPrintf(" Screen to screen blits accelerated: %s\n", videoInfo->blit_hw ? "yes" : "no"); RTPrintf(" Screen to screen colorkey blits accelerated: %s\n", videoInfo->blit_hw_CC ? "yes" : "no"); RTPrintf(" Screen to screen alpha blits accelerated: %s\n", videoInfo->blit_hw_A ? "yes" : "no"); RTPrintf(" Memory to screen blits accelerated: %s\n", videoInfo->blit_sw ? "yes" : "no"); RTPrintf(" Memory to screen colorkey blits accelerated: %s\n", videoInfo->blit_sw_CC ? "yes" : "no"); RTPrintf(" Memory to screen alpha blits accelerated: %s\n", videoInfo->blit_sw_A ? "yes" : "no"); RTPrintf(" Color fills accelerated: %s\n", videoInfo->blit_fill ? "yes" : "no"); RTPrintf(" Video memory in kilobytes: %d\n", videoInfo->video_mem); RTPrintf(" Optimal bpp mode: %d\n", videoInfo->vfmt->BitsPerPixel); char buf[256]; RTPrintf("Video driver SDL_VIDEODRIVER / active: %s/%s\n", RTEnvGet("SDL_VIDEODRIVER"), SDL_VideoDriverName(buf, sizeof(buf))); RTPrintf("\n" "Starting tests. Any key pressed inside the SDL window will abort this\n" "program at the end of the current test. Iterations = %u\n", guLoop); #ifdef VBOX_OPENGL RTPrintf("\n========== "ESC_BOLD"OpenGL is %s"ESC_NORM" ==========\n", gfOpenGL ? "ON" : "OFF"); #endif bench( 640, 480, 16); bench( 640, 480, 24); bench( 640, 480, 32); bench(1024, 768, 16); bench(1024, 768, 24); bench(1024, 768, 32); bench(1280, 1024, 16); bench(1280, 1024, 24); bench(1280, 1024, 32); RTPrintf("\nSuccess!\n"); return 0; }
static int pdmacFileInitialize(PPDMASYNCCOMPLETIONEPCLASS pClassGlobals, PCFGMNODE pCfgNode) { PPDMASYNCCOMPLETIONEPCLASSFILE pEpClassFile = (PPDMASYNCCOMPLETIONEPCLASSFILE)pClassGlobals; RTFILEAIOLIMITS AioLimits; /** < Async I/O limitations. */ int rc = RTFileAioGetLimits(&AioLimits); #ifdef DEBUG if (RT_SUCCESS(rc) && RTEnvExist("VBOX_ASYNC_IO_FAILBACK")) rc = VERR_ENV_VAR_NOT_FOUND; #endif if (RT_FAILURE(rc)) { LogRel(("AIO: Async I/O manager not supported (rc=%Rrc). Falling back to simple manager\n", rc)); pEpClassFile->enmMgrTypeOverride = PDMACEPFILEMGRTYPE_SIMPLE; pEpClassFile->enmEpBackendDefault = PDMACFILEEPBACKEND_BUFFERED; } else { pEpClassFile->uBitmaskAlignment = AioLimits.cbBufferAlignment ? ~((RTR3UINTPTR)AioLimits.cbBufferAlignment - 1) : RTR3UINTPTR_MAX; pEpClassFile->cReqsOutstandingMax = AioLimits.cReqsOutstandingMax; if (pCfgNode) { /* Query the default manager type */ char *pszVal = NULL; rc = CFGMR3QueryStringAllocDef(pCfgNode, "IoMgr", &pszVal, "Async"); AssertLogRelRCReturn(rc, rc); rc = pdmacFileMgrTypeFromName(pszVal, &pEpClassFile->enmMgrTypeOverride); MMR3HeapFree(pszVal); if (RT_FAILURE(rc)) return rc; LogRel(("AIOMgr: Default manager type is \"%s\"\n", pdmacFileMgrTypeToName(pEpClassFile->enmMgrTypeOverride))); /* Query default backend type */ rc = CFGMR3QueryStringAllocDef(pCfgNode, "FileBackend", &pszVal, "NonBuffered"); AssertLogRelRCReturn(rc, rc); rc = pdmacFileBackendTypeFromName(pszVal, &pEpClassFile->enmEpBackendDefault); MMR3HeapFree(pszVal); if (RT_FAILURE(rc)) return rc; LogRel(("AIOMgr: Default file backend is \"%s\"\n", pdmacFileBackendTypeToName(pEpClassFile->enmEpBackendDefault))); #ifdef RT_OS_LINUX if ( pEpClassFile->enmMgrTypeOverride == PDMACEPFILEMGRTYPE_ASYNC && pEpClassFile->enmEpBackendDefault == PDMACFILEEPBACKEND_BUFFERED) { LogRel(("AIOMgr: Linux does not support buffered async I/O, changing to non buffered\n")); pEpClassFile->enmEpBackendDefault = PDMACFILEEPBACKEND_NON_BUFFERED; } #endif } else { /* No configuration supplied, set defaults */ pEpClassFile->enmEpBackendDefault = PDMACFILEEPBACKEND_NON_BUFFERED; pEpClassFile->enmMgrTypeOverride = PDMACEPFILEMGRTYPE_ASYNC; } } /* Init critical section. */ rc = RTCritSectInit(&pEpClassFile->CritSect); #ifdef VBOX_WITH_DEBUGGER /* Install the error injection handler. */ if (RT_SUCCESS(rc)) { rc = DBGCRegisterCommands(&g_aCmds[0], RT_ELEMENTS(g_aCmds)); AssertRC(rc); } #ifdef PDM_ASYNC_COMPLETION_FILE_WITH_DELAY rc = TMR3TimerCreateInternal(pEpClassFile->Core.pVM, TMCLOCK_REAL, pdmacR3TimerCallback, pEpClassFile, "AC Delay", &pEpClassFile->pTimer); AssertRC(rc); pEpClassFile->cMilliesNext = UINT64_MAX; #endif #endif return rc; }