From d3bb0b2c3673055f2487a46a21fab9b94f22d6bc Mon Sep 17 00:00:00 2001 From: "jinhyung.jo" Date: Wed, 29 Jul 2015 17:30:43 +0900 Subject: [PATCH] emulator: Modified code about java path in WOW64 Use more registry keys and the environment variable in oder to find more precise 'Java Home'. Removed redundant code. Change-Id: I9ef2d3e87cd47cb31ee0c4389269cca2708fcc4d Signed-off-by: Jinhyung Jo (cherry picked from commit 6ba1131714016b47c49e79f361c66cd25d148bc0) --- include/qemu-common.h | 7 --- tizen/src/emulator_common.h | 8 ++++ util/oslib-win32.c | 109 ++++++++++++++++++++++++++++++-------------- 3 files changed, 82 insertions(+), 42 deletions(-) diff --git a/include/qemu-common.h b/include/qemu-common.h index 8ddb0cb..a998e8d 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -474,11 +474,4 @@ int parse_debug_env(const char *name, int max, int initial); const char *qemu_ether_ntoa(const MACAddr *mac); -#if defined(CONFIG_MARU) && defined(CONFIG_WIN32) -#include "../tizen/src/emulator_common.h" - -int is_wow64(void); -bool get_java_path(char **java_path); -#endif - #endif diff --git a/tizen/src/emulator_common.h b/tizen/src/emulator_common.h index 99821be..fb9d5c3 100644 --- a/tizen/src/emulator_common.h +++ b/tizen/src/emulator_common.h @@ -71,6 +71,14 @@ #ifdef CONFIG_WIN32 #define MY_KEY_WOW64_64KEY 0x0100 +#ifdef __cplusplus +extern "C" { +#endif +int is_wow64(void); +bool get_java_path(char **java_path); +#ifdef __cplusplus +} +#endif #else #define JAVA_EXEFILE_PATH "java" #endif diff --git a/util/oslib-win32.c b/util/oslib-win32.c index fed8de3..b5beed5 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -37,69 +37,108 @@ #include #ifdef CONFIG_MARU +#include "tizen/src/emulator_common.h" + typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); -LPFN_ISWOW64PROCESS fnIsWow64Process; int is_wow64(void) { 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"); + fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress( + GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); if (NULL != fnIsWow64Process) { - if (!fnIsWow64Process(GetCurrentProcess(),&result)) { - // handle error - fprintf(stderr, "Cannot find 'IsWow64Process'\n"); + if (!fnIsWow64Process(GetCurrentProcess(), &result)) { + /* No need to handle error, + just check whether is this WoW64 process */ } } return result; } -bool get_java_path(char** java_path) +static char wow64_java_path[JAVA_MAX_COMMAND_LENGTH]; +bool get_java_path(char **java_path) { - HKEY hKeyNew; - HKEY hKey; - //char strJavaRuntimePath[JAVA_MAX_COMMAND_LENGTH] = {0}; + 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}; - int index; DWORD dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH; DWORD dwBufLen = JAVA_MAX_COMMAND_LENGTH; - - RegOpenKeyEx(HKEY_LOCAL_MACHINE, + char strKeyList[4][64] = { + /* 64bit runtime */ "SOFTWARE\\JavaSoft\\Java Runtime Environment", - 0, - KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | MY_KEY_WOW64_64KEY, - &hKey); - RegEnumKeyEx(hKey, 0, (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL); - strcpy(strChoosenName, strSubKeyName); - - index = 1; - while (ERROR_SUCCESS == - RegEnumKeyEx(hKey, index, (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL)) { - if (strcmp(strChoosenName, strSubKeyName) < 0) { - strcpy(strChoosenName, strSubKeyName); + "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; + } + + 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; } - index++; } - RegOpenKeyEx(hKey, strChoosenName, 0, - KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hKeyNew); - RegQueryValueEx(hKeyNew, "JavaHome", NULL, - NULL, (LPBYTE)strJavaHome, &dwBufLen); - RegCloseKey(hKey); + if (res == ERROR_SUCCESS) { + RegEnumKeyEx(hKey, 0, (LPSTR)strSubKeyName, &dwSubKeyNameMax, + NULL, NULL, NULL, NULL); + strcpy(strChoosenName, strSubKeyName); + + index = 1; + while (ERROR_SUCCESS == + RegEnumKeyEx(hKey, index, + (LPSTR)strSubKeyName, &dwSubKeyNameMax, + NULL, NULL, NULL, NULL)) { + if (strcmp(strChoosenName, strSubKeyName) < 0) { + strcpy(strChoosenName, strSubKeyName); + } + index++; + } + + RegOpenKeyEx(hKey, strChoosenName, 0, + KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hSubKey); + RegQueryValueEx(hSubKey, "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\\java\"", strJavaHome); - //strcpy(*java_path, strJavaHome); - //strcat(*java_path, "\\bin\\java"); + sprintf(*java_path, "\"%s\\bin\\javaw.exe\"", strJavaHome); + strcpy(wow64_java_path, *java_path); } else { return false; } -- 2.7.4