diff options
author | Jinhyung Jo <jinhyung.jo@samsung.com> | 2016-01-27 14:51:17 +0900 |
---|---|---|
committer | Jinhyung Jo <jinhyung.jo@samsung.com> | 2016-01-27 15:47:43 +0900 |
commit | 62425a158ab5382ad75674b7a5906da3fa75b0a6 (patch) | |
tree | 06c71343313197191fdc9efb0d3d1ad1dd1a314d /util | |
parent | 7e2b271221dd7922e74b10b47b4516e29699ceda (diff) | |
download | qemu-62425a158ab5382ad75674b7a5906da3fa75b0a6.tar.gz qemu-62425a158ab5382ad75674b7a5906da3fa75b0a6.tar.bz2 qemu-62425a158ab5382ad75674b7a5906da3fa75b0a6.zip |
oslib-win32: always get java path from registry
Regardless of the architecture of the emulator(32bit or 64bit),
always gets the java execution path from Windows registry.
This commit would be helpful to reduce the java execution failure.
Change-Id: I890bfa67ffdde36bbbd28678e196d7a50bce65a8
Signed-off-by: Jinhyung Jo <jinhyung.jo@samsung.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/oslib-posix.c | 7 | ||||
-rw-r--r-- | util/oslib-win32.c | 192 |
2 files changed, 84 insertions, 115 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c index f7a8325459..0c37eea295 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -90,13 +90,15 @@ void *qemu_oom_check(void *ptr) #ifdef CONFIG_MARU const char _msg[] = "Failed to allocate memory in qemu."; char cmd[JAVA_MAX_COMMAND_LENGTH] = { 0, }; + const char *java_exefile_path = NULL; int len; #endif if (ptr == NULL) { fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno)); #ifdef CONFIG_MARU - len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + + get_java_path(&java_exefile_path); + len = strlen(java_exefile_path) + strlen(JAVA_EXEOPTION) + strlen(JAR_SKINFILE) + strlen(JAVA_SIMPLEMODE_OPTION) + strlen(_msg) + 7; if (len > JAVA_MAX_COMMAND_LENGTH) { @@ -104,10 +106,11 @@ void *qemu_oom_check(void *ptr) } snprintf(cmd, len, "%s %s %s %s=\"%s\"", - JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE, JAVA_SIMPLEMODE_OPTION, _msg); + java_exefile_path, JAVA_EXEOPTION, JAR_SKINFILE, JAVA_SIMPLEMODE_OPTION, _msg); if (system(cmd) == -1) { fprintf(stderr, "failed to execute this command: %s\n", cmd); } + java_exefile_path = NULL; #endif abort(); } diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 22bdb0b212..abf00a3100 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -38,110 +38,92 @@ #ifdef CONFIG_MARU #include "tizen/src/emulator_common.h" - -typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); - -int is_wow64(void) +/* Gets the JavaHome path from the windows registry. + Must call the RegOpenKeyEx by using the following flag. + For details, "http://stackoverflow.com/questions/10533421/ + accessing-64-bit-registry-from-32-bit-application" */ +#define MY_KEY_WOW64_64KEY 0x0100 +void get_java_path_win32(const char **java_path) { - int result = 0; - LPFN_ISWOW64PROCESS fnIsWow64Process; - - /* IsWow64Process is not available on all supported versions of Windows. - Use GetModuleHandle to get a handle to the DLL that contains the function - and GetProcAddress to get a pointer to the function if available. */ - - fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress( - GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); - - if (NULL != fnIsWow64Process) { - if (!fnIsWow64Process(GetCurrentProcess(), &result)) { - /* No need to handle error, - just check whether is this WoW64 process */ - } + LONG res; + HKEY hKey; + char strKey[PATH_MAX] = {0}; + char strVersion[PATH_MAX] = {0}; + char strJavaHome[PATH_MAX] = {0}; + DWORD dwBufLen = PATH_MAX; + static char current_java_path[PATH_MAX]; + + if (current_java_path[0] != '\0') { + *java_path = current_java_path; + return; } - return result; -} -static char wow64_java_path[JAVA_MAX_COMMAND_LENGTH]; -bool get_java_path(char **java_path) -{ - int index; - LONG res; - HKEY hKey, hSubKey; - char strChoosenName[JAVA_MAX_COMMAND_LENGTH] = {0}; - char strSubKeyName[JAVA_MAX_COMMAND_LENGTH] = {0}; - char strJavaHome[JAVA_MAX_COMMAND_LENGTH] = {0}; - DWORD dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH; - DWORD dwBufLen = JAVA_MAX_COMMAND_LENGTH; - char strKeyList[4][64] = { - /* 64bit runtime */ - "SOFTWARE\\JavaSoft\\Java Runtime Environment", - "SOFTWARE\\JavaSoft\\Java Development Kit", - /* 32bit runtime */ - "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment", - "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Development Kit" - }; - - if (wow64_java_path[0] != '\0') { - strcpy(*java_path, wow64_java_path); - return true; + g_strlcpy(strKey, + "SOFTWARE\\JavaSoft\\Java Runtime Environment", + PATH_MAX); + + /* Opens above key to query the current version */ + res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + strKey, + 0, + KEY_QUERY_VALUE | + MY_KEY_WOW64_64KEY, + &hKey); + if (res != ERROR_SUCCESS) { + fprintf(stderr, + "oslib-win32: Java Runtime Environment key not found\n"); + goto javahome_not_found; } - for (index = 0; index < ARRAY_SIZE(strKeyList); index++) { - res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, - strKeyList[index], - 0, - KEY_QUERY_VALUE | - KEY_ENUMERATE_SUB_KEYS | - MY_KEY_WOW64_64KEY, - &hKey); - if (res == ERROR_SUCCESS) { - break; - } + /* Queries for the current version */ + res = RegQueryValueEx(hKey, + "CurrentVersion", + NULL, + NULL, + (LPBYTE)strVersion, + &dwBufLen); + RegCloseKey(hKey); + if (res != ERROR_SUCCESS) { + fprintf(stderr, "oslib-win32: JRE CurrentVersion not found\n"); + goto javahome_not_found; } + /* Adds the current version to the key */ + g_strlcat(strKey, "\\", PATH_MAX); + g_strlcat(strKey, strVersion, PATH_MAX); + + /* Opens above key to query the JavaHome */ + res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + strKey, + 0, + KEY_QUERY_VALUE | + MY_KEY_WOW64_64KEY, + &hKey); if (res == ERROR_SUCCESS) { - index = 0; - do { - dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH; - res = RegEnumKeyEx(hKey, - index++, - (LPSTR)strSubKeyName, - &dwSubKeyNameMax, - NULL, NULL, NULL, NULL); - if (strcmp(strChoosenName, strSubKeyName) < 0) { - strcpy(strChoosenName, strSubKeyName); - } - } while (res == ERROR_SUCCESS); - - RegOpenKeyEx(hKey, strChoosenName, 0, - KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hSubKey); - RegQueryValueEx(hSubKey, "JavaHome", NULL, + /* Queries for the JavaHome */ + dwBufLen = PATH_MAX; + RegQueryValueEx(hKey, "JavaHome", NULL, NULL, (LPBYTE)strJavaHome, &dwBufLen); - RegCloseKey(hSubKey); - RegCloseKey(hKey); - } else { - /* TODO: - get from %winDir%\System32 - but, is this really needed? - */ - DWORD dwRet = 0; - char strJavaHomeVar[JAVA_MAX_COMMAND_LENGTH] = {0,}; - dwRet = GetEnvironmentVariable("JAVA_HOME", - strJavaHomeVar, - JAVA_MAX_COMMAND_LENGTH); - if (dwRet != 0 && dwRet < JAVA_MAX_COMMAND_LENGTH) { - strcpy(strJavaHome, strJavaHomeVar); - } } - if (strJavaHome[0] != '\0') { - sprintf(*java_path, "\"%s\\bin\\javaw.exe\"", strJavaHome); - strcpy(wow64_java_path, *java_path); - } else { - return false; + RegCloseKey(hKey); + +javahome_not_found: + if (strJavaHome[0] == '\0') { + dwBufLen = GetEnvironmentVariable("JAVA_HOME", + strJavaHome, + PATH_MAX); + if (dwBufLen == 0) { + fprintf(stderr, "oslib-win32: There is no JavaHome\n"); + /* try it with "javaw.exe" */ + *java_path = "javaw.exe"; + return; + } } + g_sprintf(current_java_path, "\"%s\\bin\\javaw.exe\"", strJavaHome); + fprintf(stderr, "oslib-win32: CurrentVersion JavaHome path: %s\n", + current_java_path); - return true; + *java_path = current_java_path; } #endif @@ -150,28 +132,15 @@ void *qemu_oom_check(void *ptr) #ifdef CONFIG_MARU const char _msg[] = "Failed to allocate memory in qemu."; char cmd[JAVA_MAX_COMMAND_LENGTH] = { 0, }; - char *JAVA_EXEFILE_PATH = NULL; + const char *java_exefile_path = NULL; int len, ret; #endif if (ptr == NULL) { fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError()); #ifdef CONFIG_MARU - JAVA_EXEFILE_PATH = malloc(JAVA_MAX_COMMAND_LENGTH); - if (!JAVA_EXEFILE_PATH) { - // TODO: print error message. - return ptr; - } - - memset(JAVA_EXEFILE_PATH, 0, JAVA_MAX_COMMAND_LENGTH); - if (is_wow64()) { - if (!get_java_path(&JAVA_EXEFILE_PATH)) { - strcpy(JAVA_EXEFILE_PATH, "java"); - } - } else { - strcpy(JAVA_EXEFILE_PATH, "java"); - } - len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + + get_java_path(&java_exefile_path); + len = strlen(java_exefile_path) + strlen(JAVA_EXEOPTION) + strlen(JAR_SKINFILE) + strlen(JAVA_SIMPLEMODE_OPTION) + strlen(_msg) + 7; if (len > JAVA_MAX_COMMAND_LENGTH) { @@ -179,16 +148,13 @@ void *qemu_oom_check(void *ptr) } snprintf(cmd, len, "%s %s %s %s=\"%s\"", - JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE, + java_exefile_path, JAVA_EXEOPTION, JAR_SKINFILE, JAVA_SIMPLEMODE_OPTION, _msg); ret = WinExec(cmd, SW_SHOW); if (ret < 32) { // TODO: error handling... } - - /* for 64bit windows */ - free(JAVA_EXEFILE_PATH); - JAVA_EXEFILE_PATH=0; + java_exefile_path = NULL; #endif abort(); } |