STDMETHODIMP MachineDebuggerWrap::COMGETTER(OSVersion)(BSTR *aOSVersion) { LogRelFlow(("{%p} %s: enter aOSVersion=%p\n", this, "MachineDebugger::getOSVersion", aOSVersion)); VirtualBoxBase::clearError(); HRESULT hrc; try { CheckComArgOutPointerValidThrow(aOSVersion); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) throw autoCaller.rc(); hrc = getOSVersion(BSTROutConverter(aOSVersion).str()); } catch (HRESULT hrc2) { hrc = hrc2; } catch (...) { hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS); } LogRelFlow(("{%p} %s: leave *aOSVersion=%ls hrc=%Rhrc\n", this, "MachineDebugger::getOSVersion", *aOSVersion, hrc)); return hrc; }
DWORD GpuCapabilitiesWindows::readVRAMSizeFromReg() { DWORD memSize = 0; char* devicesKey = findPrimaryDevicesKey(); if ( devicesKey == 0 ) { LERROR("Failed to determine primary graphics adapter by calling findPrimaryDevicesKey()!"); return 0; } for ( size_t i = 0; i < strlen(devicesKey); i++ ) devicesKey[i] = tolower(devicesKey[i]); char* substr = strstr(devicesKey, "\\registry\\machine\\"); if ( substr != 0 ) substr += strlen("\\registry\\machine\\"); else substr = devicesKey; LDEBUG("registry key: " << substr); HKEY hKey = NULL; LONG stat = RegOpenKeyEx(HKEY_LOCAL_MACHINE, substr, 0, KEY_READ, &hKey); if ( stat == ERROR_SUCCESS ) { DWORD type = 0; DWORD bufferSize = 4; char* data = new char[bufferSize + 1]; memset(data, 0, bufferSize + 1); stat = RegQueryValueEx(hKey, "HardwareInformation.MemorySize", NULL, &type, (BYTE*) data, &bufferSize); if ((stat == ERROR_SUCCESS) && ((type == REG_BINARY) || (getOSVersion() == GpuCapabilities::OS_WIN_VISTA && type == REG_DWORD))) { LDEBUG("read " << bufferSize << " BYTES from key 'HardwareInformation.MemorySize'..."); for ( DWORD i = (bufferSize - 1); ; i-- ) { LDEBUG("data[" << i << "]: " << static_cast<DWORD>(data[i])); memSize |= (data[i] << (i * 8)); // As DWORD is unsigned, the loop would never exit if // it would not be broken... // if ( i == 0 ) break; } LDEBUG("data converted to " << memSize << " (means " << (memSize / (1024 * 1024)) << " MByte)\n"); } RegCloseKey(hKey); hKey = NULL; delete [] data; data = 0; } else LERROR("Error opening key " << substr << ". Reason: " << stat); delete [] devicesKey; devicesKey = 0; return memSize; }
//========================================================================== // The 'main' function for the booter. Called by boot0 when booting // from a block device, or by the network booter. // // arguments: // biosdev - Value passed from boot1/NBP to specify the device // that the booter was loaded from. // // If biosdev is kBIOSDevNetwork, then this function will return if // booting was unsuccessful. This allows the PXE firmware to try the // next boot device on its list. void common_boot(int biosdev) { bool quiet; bool firstRun = true; bool instantMenu; bool rescanPrompt; int status; unsigned int allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot; unsigned int denyBVFlags = kBVFlagEFISystem; // Set reminder to unload the PXE base code. Neglect to unload // the base code will result in a hang or kernel panic. gUnloadPXEOnExit = true; // Record the device that the booter was loaded from. gBIOSDev = biosdev & kBIOSDevMask; // Initialize boot-log initBooterLog(); // Initialize boot info structure. initKernBootStruct(); // Setup VGA text mode. // Not sure if it is safe to call setVideoMode() before the // config table has been loaded. Call video_mode() instead. #if DEBUG printf("before video_mode\n"); #endif video_mode( 2 ); // 80x25 mono text mode. #if DEBUG printf("after video_mode\n"); #endif // Scan and record the system's hardware information. scan_platform(); // First get info for boot volume. scanBootVolumes(gBIOSDev, 0); bvChain = getBVChainForBIOSDev(gBIOSDev); setBootGlobals(bvChain); // Load boot.plist config file status = loadChameleonConfig(&bootInfo->chameleonConfig, bvChain); if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet) { gBootMode |= kBootModeQuiet; } // Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu) { firstRun = false; } // Loading preboot ramdisk if exists. loadPrebootRAMDisk(); // Disable rescan option by default gEnableCDROMRescan = false; // Enable it with Rescan=y in system config if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig) && gEnableCDROMRescan) { gEnableCDROMRescan = true; } // Ask the user for Rescan option by setting "Rescan Prompt"=y in system config. rescanPrompt = false; if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) { gEnableCDROMRescan = promptForRescanOption(); } // Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config. if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) && gScanSingleDrive) { gScanSingleDrive = true; } // Create a list of partitions on device(s). if (gScanSingleDrive) { scanBootVolumes(gBIOSDev, &bvCount); } else { scanDisks(gBIOSDev, &bvCount); } // Create a separated bvr chain using the specified filters. bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount); gBootVolume = selectBootVolume(bvChain); // Intialize module system init_module_system(); #if DEBUG printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags); printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags); getchar(); #endif useGUI = true; // Override useGUI default getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig); if (useGUI && initGUI()) { // initGUI() returned with an error, disabling GUI. useGUI = false; } setBootGlobals(bvChain); // Parse args, load and start kernel. while (1) { bool tryresume, tryresumedefault, forceresume; bool useKernelCache = true; // by default try to use the prelinked kernel const char *val; int len, ret = -1; long flags, sleeptime, time; void *binary = (void *)kLoadAddr; char bootFile[sizeof(bootInfo->bootFile)]; char bootFilePath[512]; char kernelCacheFile[512]; // Initialize globals. sysConfigValid = false; gErrors = false; status = getBootOptions(firstRun); firstRun = false; if (status == -1) continue; status = processBootOptions(); // Status == 1 means to chainboot if ( status == 1 ) break; // Status == -1 means that the config file couldn't be loaded or that gBootVolume is NULL if ( status == -1 ) { // gBootVolume == NULL usually means the user hit escape. if (gBootVolume == NULL) { freeFilteredBVChain(bvChain); if (gEnableCDROMRescan) rescanBIOSDevice(gBIOSDev); bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount); setBootGlobals(bvChain); setupDeviceList(&bootInfo->themeConfig); } continue; } // Other status (e.g. 0) means that we should proceed with boot. // Turn off any GUI elements if ( bootArgs->Video.v_display == GRAPHICS_MODE ) { gui.devicelist.draw = false; gui.bootprompt.draw = false; gui.menu.draw = false; gui.infobox.draw = false; gui.logo.draw = false; drawBackground(); updateVRAM(); } // Find out which version mac os we're booting. getOSVersion(); if (platformCPUFeature(CPU_FEATURE_EM64T)) { archCpuType = CPU_TYPE_X86_64; } else { archCpuType = CPU_TYPE_I386; } if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig)) { if (strncmp(val, "i386", 4) == 0) { archCpuType = CPU_TYPE_I386; } } if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig)) { if (strncmp(val, "i386", 4) == 0) { archCpuType = CPU_TYPE_I386; } } // Notify modules that we are attempting to boot execute_hook("PreBoot", NULL, NULL, NULL, NULL); if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig)) { tryresume = true; tryresumedefault = true; } else { tryresumedefault = false; } if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig)) { forceresume = false; } if (forceresume) { tryresume = true; tryresumedefault = false; } while (tryresume) { const char *tmp; BVRef bvr; if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig)) val = "/private/var/vm/sleepimage"; // Do this first to be sure that root volume is mounted ret = GetFileInfo(0, val, &flags, &sleeptime); if ((bvr = getBootVolumeRef(val, &tmp)) == NULL) break; // Can't check if it was hibernation Wake=y is required if (bvr->modTime == 0 && tryresumedefault) break; if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) break; if (!forceresume && ((sleeptime+3)<bvr->modTime)) { #if DEBUG printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n", bvr->modTime-sleeptime); #endif break; } HibernateBoot((char *)val); break; } getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig); if (useKernelCache) do { // Determine the name of the Kernel Cache if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) { if (val[0] == '\\') { len--; val++; } /* FIXME: check len vs sizeof(kernelCacheFile) */ strlcpy(kernelCacheFile, val, len + 1); } else { kernelCacheFile[0] = 0; // Use default kernel cache file } if (gOverrideKernel && kernelCacheFile[0] == 0) { DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile); useKernelCache = false; break; } if (gMKextName[0] != 0) { DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n", gMKextName); useKernelCache = false; break; } if (gBootFileType != kBlockDeviceType) useKernelCache = false; } while(0); do { if (useKernelCache) { ret = LoadKernelCache(kernelCacheFile, &binary); if (ret >= 0) break; } bool bootFileWithDevice = false; // Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel if (strncmp(bootInfo->bootFile,"bt(",3) == 0 || strncmp(bootInfo->bootFile,"hd(",3) == 0 || strncmp(bootInfo->bootFile,"rd(",3) == 0) bootFileWithDevice = true; // bootFile must start with a / if it not start with a device name if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/') { snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading / } else { strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile)); } // Try to load kernel image from alternate locations on boot helper partitions. ret = -1; if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice) { snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.P%s", bootFile); ret = GetFileInfo(NULL, bootFilePath, &flags, &time); if (ret == -1) { snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.R%s", bootFile); ret = GetFileInfo(NULL, bootFilePath, &flags, &time); if (ret == -1) { snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.S%s", bootFile); ret = GetFileInfo(NULL, bootFilePath, &flags, &time); } } } if (ret == -1) { // No alternate location found, using the original kernel image path. strlcpy(bootFilePath, bootFile, sizeof(bootFilePath)); } DBG("Loading kernel: '%s'\n", bootFilePath); ret = LoadThinFatFile(bootFilePath, &binary); if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) { archCpuType = CPU_TYPE_I386; ret = LoadThinFatFile(bootFilePath, &binary); } } while (0); clearActivityIndicator(); #if DEBUG printf("Pausing..."); sleep(8); #endif if (ret <= 0) { printf("Can't find %s\n", bootFile); sleep(1); if (gBootFileType == kNetworkDeviceType) { // Return control back to PXE. Don't unload PXE base code. gUnloadPXEOnExit = false; break; } pause(); } else { /* Won't return if successful. */ ret = ExecKernel(binary); } } // chainboot if (status == 1) { // if we are already in graphics-mode, if (getVideoMode() == GRAPHICS_MODE) { setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode. } } if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) { nbpUnloadBaseCode(); } }
/** If the configuration of this installation has not been reported for the * current version, collect the hardware statistics and send it to STK's * server. */ void reportHardwareStats() { // Version of the hw report, which is stored in the DB. If new fields // are added, increase this version. Each STK installation will report // its configuration only once (per version number). So if the version // number is increased, a new report will be sent. const int report_version = 1; if(UserConfigParams::m_last_hw_report_version>=report_version) return; while(UserConfigParams::m_random_identifier==0) { RandomGenerator rg; UserConfigParams::m_random_identifier = rg.get(1<<30); user_config->saveConfig(); } Json json; #ifdef WIN32 json.add("os_win", 1); #else json.add("os_win", 0); #endif #ifdef __APPLE__ json.add("os_macosx", 1); #else json.add("os_macosx", 0); #endif #ifdef __linux__ json.add("os_linux", 1); json.add("os_unix", 1); #else json.add("os_linux", 0); json.add("os_unix", 0); #endif #ifdef DEBUG json.add("build_debug", 1); #endif json.add("os_version", getOSVersion()); unsigned int ogl_version = irr_driver->getGLSLVersion(); unsigned int major = ogl_version/100; unsigned int minor = ogl_version - 100*major; std::string version = StringUtils::insertValues("%d.%d", major, minor); json.add("GL_SHADING_LANGUAGE_VERSION", version); std::string vendor, renderer, full_version; irr_driver->getOpenGLData(&vendor, &renderer, &full_version); json.add("GL_VENDOR", vendor ); json.add("GL_RENDERER", renderer ); json.add("GL_VERSION", full_version ); json.add("gfx_drv_ver", "OpenGL "+vendor); std::string card_name = vendor; if(StringUtils::startsWith(card_name, "ATI Technologies Inc.")) card_name="ATI"; else if (StringUtils::startsWith(card_name, "NVIDIA Corporation")) card_name="NVIDIA"; else if(StringUtils::startsWith(card_name, "S3 Graphics")) card_name="S3"; json.add("gfx_card", card_name+" "+renderer); json.add("video_xres", UserConfigParams::m_width ); json.add("video_yres", UserConfigParams::m_height); int mem = getRAM(); if(mem>0) json.add("ram_total", mem); int nr_procs = getNumProcessors(); if(nr_procs>0) json.add("cpu_numprocs", nr_procs); json.add("GL_EXTENSIONS", getGLExtensions()); getGLLimits(&json); json.finish(); // ------------------------------------------------------------------------ /** A small class which sends the HW report to the STK server. On * completion, it will either update the last-submitted-hw-report version, * or log an error message (in which case next time STK is started it * wil try again to log the report). */ class HWReportRequest : public Online::HTTPRequest { private: /** Version number of the hw report. */ int m_version; public: HWReportRequest(int version) : Online::HTTPRequest(/*manage memory*/true, 1) , m_version(version) {} // -------------------------------------------------------------------- /** Callback after the request has been executed. */ virtual void callback() { // If the request contains incorrect data, it will not have a // download error, but return an error string as return value: if(hadDownloadError() || getData()=="<h1>Bad Request (400)</h1>") { Log::error("HW report", "Error uploading the HW report."); if(hadDownloadError()) Log::error("HW report", "%s", getDownloadErrorMessage()); else Log::error("HW report", "%s", getData().c_str()); } else { Log::info("HW report", "Upload successful."); UserConfigParams::m_last_hw_report_version = m_version; // The callback is executed by the main thread, so no need // to worry about locks when writing the file. user_config->saveConfig(); } } // callback }; // HWReportRequest // ------------------------------------------------------------------------ Online::HTTPRequest *request = new HWReportRequest(report_version); request->addParameter("user_id", UserConfigParams::m_random_identifier); request->addParameter("time", StkTime::getTimeSinceEpoch()); request->addParameter("type", "hwdetect"); request->addParameter("version", report_version); request->addParameter("data", json.toString()); request->setURL((std::string)UserConfigParams::m_server_hw_report+"/upload/v1/"); //request->setURL("http://127.0.0.1:8000/upload/v1/"); request->queue(); } // reportHardwareStats
GpuCapabilitiesWindows::FileVersion GpuCapabilitiesWindows::getDriverVersion() { FileVersion fileVersion; fileVersion.versionString = ""; // Try to get driver file version if ( GpuCapabilities::getVendor() == GPU_VENDOR_NVIDIA ) { // Get fileversion of NVIDIA OpenGL dll LDEBUG("Reading file version of NVIDIA driver dll ... "); FileVersion fileVersion; //TODO: windows vista stores the name of the dll in the registry. // its better to get the name from there (cdoer) if (getOSVersion() == OS_WIN_VISTA) fileVersion = getFileVersion("nvoglv32.dll"); else fileVersion = getFileVersion(DRIVER_DLL_NVIDIA); if (fileVersion.versionString.length() == 0) { LDEBUG("Reading NVIDIA driver version failed."); } else { LDEBUG("Reading driver version successful."); return fileVersion; } } else if (getVendor() == GPU_VENDOR_ATI) { // Get fileversion of ATI OpenGL dll LDEBUG("Reading file version of ATI driver dll ... "); FileVersion fileVersion = getFileVersion(DRIVER_DLL_ATI); if ( fileVersion.versionString.length() == 0 ) { LDEBUG("Reading ATI driver version failed."); } else { LDEBUG("Reading driver version successful."); return fileVersion; } } #ifdef CGT_WITH_WMI // unknown graphics board vendor or reading NVIDIA/Ati driver version failed: // get driver version from WMI LDEBUG("Reading driver version from WMI ..."); // Win32_VideoController class: http://msdn2.microsoft.com/en-us/library/aa394512.aspx std::string version = WMIqueryStr("Win32_VideoController", "DriverVersion"); if (version.length() == 0) { LDEBUG("Failed to retrieve driver version from WMI."); LWARNING("Failed to detect driver version."); } else { fileVersion.versionString = version; // do not parse driver version string since it is not necessarily a file version string fileVersion.d1 = 0; fileVersion.d2 = 0; fileVersion.d3 = 0; fileVersion.d4 = 0; fileVersion.version = 0; LDEBUG("Successfully read driver version from WMI"); } return fileVersion; #else LDEBUG("Compiled without WMI support."); LWARNING("Failed to detect driver version."); return fileVersion; #endif }
std::string GpuCapabilitiesWindows::getDriverDate() { LDEBUG("Retrieving driver date ..."); if ( getVendor() == GPU_VENDOR_NVIDIA ) { LDEBUG("Retrieving driver date by querying file date of NVIDIA driver dll ..."); std::string result; //TODO: windows vista stores the name of the dll in the registry. // its better to get the name from there (cdoer) if (getOSVersion() == OS_WIN_VISTA) result = getFileDate("nvoglv32.dll"); else result = getFileDate(DRIVER_DLL_NVIDIA); if (result.length() == 0) { LDEBUG("Failed reading driver date from NVIDIA driver dll."); } else { LDEBUG("Reading driver date successful."); return result; } } else if (getVendor() == GPU_VENDOR_ATI) { LDEBUG("Retrieving driver date by querying file date of ATI driver dll ..."); std::string result = getFileDate(DRIVER_DLL_ATI); if (result.length() == 0) { LDEBUG("Failed reading driver date from ATI driver dll."); } else { LDEBUG("Reading driver date successful."); return result; } } #ifdef CGT_WITH_WMI // unknown vendor or reading driver date from vendor dll failed: // read driver date from WMI LDEBUG("Reading driver date from WMI ..."); if (isWMIinited()) { // Win32_VideoController class: http://msdn2.microsoft.com/en-us/library/aa394512.aspx std::string date = WMIqueryStr("Win32_VideoController", "DriverDate"); if (date.length() > 0) { LDEBUG("Reading driver date successful."); // convert to yyyy-mm-dd format. // see http://msdn2.microsoft.com/en-us/library/aa387237.aspx for specification of CIM_DATETIME std::string dateformat = ""; dateformat.append(date.substr(0,4)); dateformat.append("-"); dateformat.append(date.substr(4,2)); dateformat.append("-"); dateformat.append(date.substr(6,2)); return dateformat; } else { LDEBUG("Failed reading driver date."); LWARNING("Failed to detect driver date"); return ""; } } else { LDEBUG("Unable to read DriverDate from WMI: not inited"); } #else LDEBUG("Compiled without WMI support."); LWARNING("Failed to detect driver date"); #endif return ""; }
w_instance NativeProperties_init(JNIEnv *env, w_instance classSystem) { w_thread thread = JNIEnv2w_thread(env); char *utf8; w_string s; w_fifo fifo; w_int i; prop_hashtable = ht_create("hashtable:native system properties", 17, ht_stringHash, ht_stringCompare, 0, 0); woempa(1, "Created prop_hashtable\n"); s = cstring2String(UNICODE_SUBSETS, strlen(UNICODE_SUBSETS)); ht_write(prop_hashtable, (w_word)cstring2String("mika.unicode.subsets", 20), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.unicode.subsets", s); utf8 = getInstallationDir(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("java.home", 9), (w_word)s); woempa(1, "Set %s -> %w\n", "java.home", s); utf8 = getExtensionDir(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("java.ext.dirs", 13), (w_word)s); woempa(1, "Set %s -> %w\n", "java.ext.dirs", s); utf8 = getLibraryPath(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("java.library.path", 17), (w_word)s); woempa(1, "Set %s -> %w\n", "java.library.path", s); s = utf2String(VERSION_STRING, strlen(VERSION_STRING)); ht_write(prop_hashtable, (w_word)utf2String("mika.version", 12), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.version", s); s = utf2String(WONKA_INFO, strlen(WONKA_INFO)); ht_write(prop_hashtable, (w_word)utf2String("mika.vm.options", 15), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.vm.options", s); s = utf2String(DEFAULT_HEAP_SIZE, strlen(DEFAULT_HEAP_SIZE)); ht_write(prop_hashtable, (w_word)utf2String("mika.default.heap.size", 22), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.default.heap.size", s); s = utf2String(AWT_INFO, strlen(AWT_INFO)); ht_write(prop_hashtable, (w_word)utf2String("mika.awt.options", 16), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.awt.options", s); #ifdef O4P s = utf2String(O4P_INFO, strlen(O4P_INFO)); ht_write(prop_hashtable, (w_word)utf2String("mika.o4p.options", 16), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.o4p.options", s); #endif #ifdef OSWALD s = utf2String(OSWALD_INFO, strlen(OSWALD_INFO)); ht_write(prop_hashtable, (w_word)utf2String("mika.oswald.options", 19), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.oswald.options", s); #endif s = utf2String(BUILD_HOST, strlen(BUILD_HOST)); ht_write(prop_hashtable, (w_word)utf2String("mika.build.host", 15), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.build.host", s); utf8 = __DATE__ " " __TIME__; s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("mika.build.time", 15), (w_word)s); woempa(1, "Set %s -> %w\n", "mika.build.time", s); utf8 = getOSName(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("os.name", 7), (w_word)s); woempa(1, "Set %s -> %w\n", "os.name", s); utf8 = getOSVersion(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("os.version", 10), (w_word)s); woempa(1, "Set %s -> %w\n", "os.version", s); utf8 = getOSArch(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("os.arch", 7), (w_word)s); woempa(1, "Set %s -> %w\n", "os.arch", s); utf8 = getUserName(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("user.name", 9), (w_word)s); woempa(1, "Set %s -> %w\n", "user.name", s); utf8 = getUserHome(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("user.home", 9), (w_word)s); woempa(1, "Set %s -> %w\n", "user.home", s); utf8 = getUserDir(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("user.dir", 8), (w_word)s); woempa(1, "Set %s -> %w\n", "user.dir", s); utf8 = getUserLanguage(); s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("user.language", 13), (w_word)s); woempa(1, "Set %s -> %w\n", "user.language", s); utf8 = "Mika " VERSION_STRING; s = utf2String(utf8, strlen(utf8)); ht_write(prop_hashtable, (w_word)utf2String("java.runtime.name", 17), (w_word)s); woempa(1, "Set %s -> %w\n", "java.runtime.name", s); enterUnsafeRegion(thread); keyArray = allocArrayInstance_1d(JNIEnv2w_thread(env), clazzArrayOf_String, prop_hashtable->occupancy); enterSafeRegion(thread); fifo = ht_list_keys_no_lock(prop_hashtable); i = 0; while ((s = (w_string)getFifo(fifo))) { woempa(7, "keyArray[%d] = %w\n", i, s); setArrayReferenceField(keyArray, getStringInstance(s), i); ++i; } return keyArray; }
//========================================================================== // The 'main' function for the booter. Called by boot0 when booting // from a block device, or by the network booter. // // arguments: // biosdev - Value passed from boot1/NBP to specify the device // that the booter was loaded from. // // If biosdev is kBIOSDevNetwork, then this function will return if // booting was unsuccessful. This allows the PXE firmware to try the // next boot device on its list. void common_boot(int biosdev) { bool quiet; bool firstRun = true; bool instantMenu; bool rescanPrompt; char *bootFile; int status; unsigned int allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot; unsigned int denyBVFlags = kBVFlagEFISystem; unsigned long adler32; // Set reminder to unload the PXE base code. Neglect to unload // the base code will result in a hang or kernel panic. gUnloadPXEOnExit = true; // Record the device that the booter was loaded from. gBIOSDev = biosdev & kBIOSDevMask; // Initialize boot info structure. initKernBootStruct(); initBooterLog(); // Setup VGA text mode. // Not sure if it is safe to call setVideoMode() before the // config table has been loaded. Call video_mode() instead. #if DEBUG printf("before video_mode\n"); #endif video_mode( 2 ); // 80x25 mono text mode. #if DEBUG printf("after video_mode\n"); #endif // Scan and record the system's hardware information. scan_platform(); // First get info for boot volume. scanBootVolumes(gBIOSDev, 0); bvChain = getBVChainForBIOSDev(gBIOSDev); setBootGlobals(bvChain); // Load boot.plist config file status = loadChameleonConfig(&bootInfo->chameleonConfig); if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet) { gBootMode |= kBootModeQuiet; } // Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu) { firstRun = false; } // Loading preboot ramdisk if exists. loadPrebootRAMDisk(); // Disable rescan option by default gEnableCDROMRescan = false; // Enable it with Rescan=y in system config if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig) && gEnableCDROMRescan) { gEnableCDROMRescan = true; } // Ask the user for Rescan option by setting "Rescan Prompt"=y in system config. rescanPrompt = false; if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) { gEnableCDROMRescan = promptForRescanOption(); } // Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config. if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) && gScanSingleDrive) { gScanSingleDrive = true; } // Create a list of partitions on device(s). if (gScanSingleDrive) { scanBootVolumes(gBIOSDev, &bvCount); } else { scanDisks(gBIOSDev, &bvCount); } // Create a separated bvr chain using the specified filters. bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount); gBootVolume = selectBootVolume(bvChain); // Intialize module system init_module_system(); #if DEBUG printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags); printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags); getchar(); #endif useGUI = true; // Override useGUI default getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig); if (useGUI && initGUI()) { // initGUI() returned with an error, disabling GUI. useGUI = false; } setBootGlobals(bvChain); // Parse args, load and start kernel. while (1) { bool tryresume, tryresumedefault, forceresume; bool usecache = false;//true; const char *val; int len, trycache, ret = -1; long flags, cachetime, kerneltime, exttime, sleeptime, time; void *binary = (void *)kLoadAddr; // additional variable for testing alternate kernel image locations on boot helper partitions. char bootFileSpec[512]; // Initialize globals. sysConfigValid = false; gErrors = false; status = getBootOptions(firstRun); firstRun = false; if (status == -1) continue; status = processBootOptions(); // Status == 1 means to chainboot if ( status == 1 ) break; // Status == -1 means that the config file couldn't be loaded or that gBootVolume is NULL if ( status == -1 ) { // gBootVolume == NULL usually means the user hit escape. if (gBootVolume == NULL) { freeFilteredBVChain(bvChain); if (gEnableCDROMRescan) rescanBIOSDevice(gBIOSDev); bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount); setBootGlobals(bvChain); setupDeviceList(&bootInfo->themeConfig); } continue; } // Other status (e.g. 0) means that we should proceed with boot. // Turn off any GUI elements if ( bootArgs->Video.v_display == GRAPHICS_MODE ) { gui.devicelist.draw = false; gui.bootprompt.draw = false; gui.menu.draw = false; gui.infobox.draw = false; gui.logo.draw = false; drawBackground(); updateVRAM(); } // Find out which version mac os we're booting. getOSVersion(); if (platformCPUFeature(CPU_FEATURE_EM64T)) { archCpuType = CPU_TYPE_X86_64; } else { archCpuType = CPU_TYPE_I386; } if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig)) { if (strncmp(val, "i386", 4) == 0) { archCpuType = CPU_TYPE_I386; } } if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig)) { if (strncmp(val, "i386", 4) == 0) { archCpuType = CPU_TYPE_I386; } } // Notify modules that we are attempting to boot execute_hook("PreBoot", NULL, NULL, NULL, NULL); if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig)) { tryresume = true; tryresumedefault = true; } else { tryresumedefault = false; } if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig)) { forceresume = false; } if (forceresume) { tryresume = true; tryresumedefault = false; } while (tryresume) { const char *tmp; BVRef bvr; if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig)) val = "/private/var/vm/sleepimage"; // Do this first to be sure that root volume is mounted ret = GetFileInfo(0, val, &flags, &sleeptime); if ((bvr = getBootVolumeRef(val, &tmp)) == NULL) break; // Can't check if it was hibernation Wake=y is required if (bvr->modTime == 0 && tryresumedefault) break; if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) break; if (!forceresume && ((sleeptime+3)<bvr->modTime)) { #if DEBUG printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n", bvr->modTime-sleeptime); #endif break; } HibernateBoot((char *)val); break; } getBoolForKey(kUseKernelCache, &usecache, &bootInfo->chameleonConfig); if (usecache) { if( getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->chameleonConfig) || getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig) ) { if (val[0] == '\\') { len--; val++; } strlcpy(gBootKernelCacheFile, val, len + 1); verbose("Using kernel cache: \"%s\" \n", gBootKernelCacheFile); //sleep(5); } else { // Lion and Mountain Lion prelink kernel cache file␊ if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) { sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePathSnow); } // Snow Leopard else if (checkOSVersion("10.6")) { sprintf(gBootKernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64"); int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32 char* name; long prev_time = 0; struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow); while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0) { if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time && strstr(name, gBootKernelCacheFile) && (name[lnam] != '.')) { sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name); prev_time = time; } } } else { // Reset cache name. bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64); sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile); adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler)); sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32); } } } // Check for cache file. trycache = (usecache && ((gBootMode & kBootModeSafe) == 0) && !gOverrideKernel && (gBootFileType == kBlockDeviceType) && (gMKextName[0] == '\0') && (gBootKernelCacheFile[0] != '\0')); verbose("trycache: %d\n", trycache); verbose("Loading Darwin %s\n", gMacOSVersion); if (trycache) do { verbose("bootInfo->bootFile: \"%s\" \n", bootInfo->bootFile); ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime); if (ret != 0) kerneltime = 0; else if ((flags & kFileTypeMask) != kFileTypeFlat) { trycache = 0; verbose("trycache0 : 1\n"); break; } ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime); if ((ret != 0)) { trycache = 0; verbose("trycache0 : 2.1 \"%s\" \n", gBootKernelCacheFile); break; } else if ( ((flags & kFileTypeMask) != kFileTypeFlat) ) { trycache = 0; verbose("trycache0 : 2.2\n"); break; } else if ( (cachetime < kerneltime) ) { trycache = 0; verbose("trycache0 : 2.3\n"); break; } ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime); if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) && (cachetime < exttime)) { trycache = 0; verbose("trycache0 : 3\n"); break; } if (ret == 0 && kerneltime > exttime) { exttime = kerneltime; } if (ret == 0 && cachetime < (exttime + 1)) { trycache = 0; verbose("trycache0 : 4\n"); break; } } while (0); // sleep(5); do { if (trycache) { bootFile = gBootKernelCacheFile; verbose("Loading kernel cache %s\n", bootFile); if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) { ret = LoadThinFatFile(bootFile, &binary); } else { ret = LoadFile(bootFile); binary = (void *)kLoadAddr; } if (ret >= 0) break; verbose("Kernel cache did not load %s\n ", bootFile); } if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) { bootFile = gBootKernelCacheFile; } else { sprintf(bootFile, "\%s", bootInfo->bootFile); } // Try to load kernel image from alternate locations on boot helper partitions. sprintf(bootFileSpec, "com.apple.boot.P%s", bootFile); ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); if (ret == -1) { sprintf(bootFileSpec, "com.apple.boot.R%s", bootFile); ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); if (ret == -1) { sprintf(bootFileSpec, "com.apple.boot.S%s", bootFile); ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); if (ret == -1) { // No alternate location found, using the original kernel image path. strcpy(bootFileSpec, bootInfo->bootFile); } } } if ((checkOSVersion("10.7")) || (checkOSVersion("10.8"))) { //Lion, dont load kernel if haz cache if (!trycache) { verbose("Loading kernel %s\n", bootFileSpec); ret = LoadThinFatFile(bootFileSpec, &binary); if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) { archCpuType = CPU_TYPE_I386; ret = LoadThinFatFile(bootFileSpec, &binary); } } else ret = 1; } else { //Snow Leopard or older verbose("Loading kernel %s\n", bootFileSpec); ret = LoadThinFatFile(bootFileSpec, &binary); if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) { archCpuType = CPU_TYPE_I386; ret = LoadThinFatFile(bootFileSpec, &binary); } } } while (0); clearActivityIndicator(); #if DEBUG printf("Pausing..."); sleep(8); #endif if (ret <= 0) { printf("Can't find %s\n", bootFile); sleep(1); if (gBootFileType == kNetworkDeviceType) { // Return control back to PXE. Don't unload PXE base code. gUnloadPXEOnExit = false; break; } } else { /* Won't return if successful. */ ret = ExecKernel(binary); } } // chainboot if (status == 1) { // if we are already in graphics-mode, if (getVideoMode() == GRAPHICS_MODE) { setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode. } } if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) { nbpUnloadBaseCode(); } }
void commandLine(){ inputKey = 0; exit = 0; temp = 0; counter = 0; vgaSetup(3); vgaSetPos(0,0); vgaPrintString( getOSVersion() ); while( 1 ){ exit = 0; counter = 0; vgaPrintString( "BuenOS >" );//prompt input while( ( exit == 0 && inputKey == 0 ) || exit == 0 ){//fill input buffer inputKey = getKey(); if( isInput( inputKey ) ){ if( inputKey == 27 ){//esc cursorPos = vgaGetPos(); vgaSetPos( ( cursorPos->x - counter ), cursorPos->y ); for( temp = 0; temp < counter; temp++){ vgaPrint( ' ' ); } vgaSetPos( ( cursorPos->x - counter ), cursorPos->y ); counter = 0; inputBuffer[counter] = 0; } else if( inputKey == 13 ){//enter exit = 1;//finish buffer loop inputBuffer[counter] = 0;//null terminate string while( counter < sizeOfBuffer ){//null out remaining buffer inputBuffer[counter] = 0; counter++; } vgaPrintString( "\r\n" ); } else if( inputKey == 8 ){//backspace if( counter != 0 ){ vgaPrintString( "\b \b" ); counter--; inputBuffer[counter] = 0; } } else if( counter != sizeOfBuffer ){ vgaPrint( inputKey ); inputBuffer[counter] = inputKey; counter++; } } } stringCopy( inputBuffer, tempBuffer ); stringParseInfo = stringParse( tempBuffer ); stringParseInfo->argc++; stringUppercase( stringParseInfo->argv[0] ); if( stringLength( stringParseInfo->argv[0] ) != 0 ){ if( stringEqual( stringParseInfo->argv[0], "HELP" ) ) vgaPrintString( helpString ); else if( stringEqual( stringParseInfo->argv[0], "CLEAR" ) ) vgaSetup( 3 ); else if( stringEqual( stringParseInfo->argv[0], "VERSION" ) ) vgaPrintString( getOSVersion() ); else if( stringEqual( stringParseInfo->argv[0], "ECHO" ) ) { stringStrip( stringParseInfo->argv[1], '"' ); vgaPrintString( stringParseInfo->argv[1] ); vgaPrintString( "\r\n" ); } else if( stringEqual( stringParseInfo->argv[0], "DIR" ) ){ getFileList( tempBuffer ); stringFindAndReplace( tempBuffer, ',', ' ' ); stringParseInfo = stringParse( tempBuffer ); temp = 0; while( temp <= stringParseInfo->argc ){ vgaPrintString( stringParseInfo->argv[temp] ); cursorPos = vgaGetPos(); vgaSetPos( 12, cursorPos->y ); vgaPrintString( intToString( getFileSize( stringParseInfo->argv[temp] ) ) ); vgaPrintString( " bytes\r\n" ); temp++; } } else if( stringEqual( stringParseInfo->argv[0], "SIZEOF" ) ){ vgaPrintString( intToString( getFileSize( stringParseInfo->argv[1] ) ) ); vgaPrintString( " bytes\r\n" ); } else if( stringEqual( stringParseInfo->argv[0], "RENAME" ) ){ stringUppercase( stringParseInfo->argv[1] ); stringUppercase( stringParseInfo->argv[2] ); if( fileExists( stringParseInfo->argv[1] ) && stringLength( stringParseInfo->argv[1] ) != 0 && stringLength( stringParseInfo->argv[2] ) != 0 ){ if( stringEqual( stringParseInfo->argv[1], "KERNEL.BIN" ) ) vgaPrintString( "Nice try.\r\n" ); else if( fileExists( stringParseInfo->argv[2] ) || renameFile( stringParseInfo->argv[1], stringParseInfo->argv[2] ) ){ vgaPrintString( "File " ); vgaPrintString( stringParseInfo->argv[1] ); vgaPrintString( " could not be renamed to " ); vgaPrintString( stringParseInfo->argv[2] ); vgaPrintString( "\r\n" ); } else{ vgaPrintString( "File " ); vgaPrintString( stringParseInfo->argv[1] ); vgaPrintString( " successfully renamed to " ); vgaPrintString( stringParseInfo->argv[2] ); vgaPrintString( "\r\n" ); } } else{ vgaPrintString( "File " ); vgaPrintString( stringParseInfo->argv[1] ); vgaPrintString( " cannot be found.\r\n" ); } } else if( stringEqual( stringParseInfo->argv[0], "DELETE" ) ){ stringUppercase( stringParseInfo->argv[1] ); if( fileExists( stringParseInfo->argv[1] ) && stringLength( stringParseInfo->argv[1] ) != 0 ){ if( stringEqual( stringParseInfo->argv[1], "KERNEL.BIN" ) != 1 ){ if( removeFile( stringParseInfo->argv[1] ) ){ vgaPrintString( "File " ); vgaPrintString( stringParseInfo->argv[1] ); vgaPrintString( " could not be deleted\r\n" ); } else{ vgaPrintString( "File " ); vgaPrintString( stringParseInfo->argv[1] ); vgaPrintString( " successfully deleted\r\n" ); } } else vgaPrintString( "OMG just stop it. I NEED THAT!\r\n\nIT'S NOT FUNNY! ARGH!\r\n\n\n" ); } } else if( stringEqual( stringParseInfo->argv[0], "SHUTDOWN" ) ) shutdown(); else if( stringEqual( stringParseInfo->argv[0], "RESTART" ) ) restart(); else runApplication( stringParseInfo ); } } }