From ac9a9981d7dea9fc92d0c931f9ff85dbbb1b65a6 Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Thu, 18 Jul 2013 11:35:07 +0900 Subject: [PATCH] oslib-win32: separate heler functions from maruskin_client. Those functions were duplicated into oslib-win32 module since qemu builds a module under util directory as a static library. That's why the functions are separated from maruskin_client module. Change-Id: I3103bb7c80209f22bc7dd712c137421ad073613e Signed-off-by: Kitae Kim --- include/qemu-common.h | 7 ++++ tizen/src/maru_common.h | 20 ++++++++++- tizen/src/maru_err_table.c | 5 +-- tizen/src/skin/maruskin_client.c | 74 +++------------------------------------- tizen/src/skin/maruskin_client.h | 22 ------------ util/oslib-posix.c | 26 ++++++++------ util/oslib-win32.c | 72 +++++++++++++++++++++----------------- 7 files changed, 90 insertions(+), 136 deletions(-) diff --git a/include/qemu-common.h b/include/qemu-common.h index 3b1ca8e..db54124 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -477,4 +477,11 @@ size_t buffer_find_nonzero_offset(const void *buf, size_t len); */ int parse_debug_env(const char *name, int max, int initial); +#if defined(CONFIG_MARU) && defined(CONFIG_WIN32) +#include "../tizen/src/maru_common.h" + +int is_wow64(void); +bool get_java_path(char **java_path); +#endif + #endif diff --git a/tizen/src/maru_common.h b/tizen/src/maru_common.h index 3aacef9..2bfd57a 100644 --- a/tizen/src/maru_common.h +++ b/tizen/src/maru_common.h @@ -42,7 +42,6 @@ #include #include #include - #include #include #include @@ -57,6 +56,25 @@ #endif #endif +#define JAVA_MAX_COMMAND_LENGTH 1024 + +#define JAR_SKINFILE "emulator-skin.jar" +#define JAVA_LIBRARY_PATH "-Djava.library.path" + +#ifndef CONFIG_DARWIN +#define JAVA_EXEOPTION "-jar" +#else +#define JAVA_EXEOPTION "-XstartOnFirstThread -jar" // Must start the Java window on the first thread on Mac +#endif +#define JAVA_SIMPLEMODE_OPTION "simple.msg" + +#ifdef CONFIG_WIN32 +#define MY_KEY_WOW64_64KEY 0x0100 +#else +#define JAVA_EXEFILE_PATH "java" +#endif + + // W/A for preserve larger continuous heap for RAM. extern void *preallocated_ptr; diff --git a/tizen/src/maru_err_table.c b/tizen/src/maru_err_table.c index ed73a22..29c5ea9 100644 --- a/tizen/src/maru_err_table.c +++ b/tizen/src/maru_err_table.c @@ -28,15 +28,16 @@ * */ - #include "qemu-common.h" +#include "maru_common.h" #include "maru_err_table.h" + #include #include #include #include -#ifdef _WIN32 +#ifdef CONFIG_WIN32 #include #else #include diff --git a/tizen/src/skin/maruskin_client.c b/tizen/src/skin/maruskin_client.c index c795033..b4c7001 100644 --- a/tizen/src/skin/maruskin_client.c +++ b/tizen/src/skin/maruskin_client.c @@ -27,13 +27,15 @@ * */ - -#include "maru_common.h" #include #include #include #include #include + +#include "qemu-common.h" + +#include "maru_common.h" #include "maruskin_client.h" #include "maruskin_server.h" #include "emulator.h" @@ -43,8 +45,8 @@ #include "maruskin_operation.h" #ifdef CONFIG_WIN32 -#include "maru_err_table.h" #include +#include "maru_err_table.h" #endif MULTI_DEBUG_CHANNEL(qemu, skin_client); @@ -352,69 +354,3 @@ int start_simple_client(char* msg) return 1; } - -#ifdef CONFIG_WIN32 -typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); -LPFN_ISWOW64PROCESS fnIsWow64Process; - -int is_wow64(void) -{ - int result = 0; - - //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)) - { - //handle error - INFO("Can not find 'IsWow64Process'\n"); - } - } - return result; -} - -int get_java_path(char** java_path) -{ - HKEY hKeyNew; - HKEY hKey; - //char strJavaRuntimePath[JAVA_MAX_COMMAND_LENGTH] = {0}; - 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, "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); - } - index++; - } - - RegOpenKeyEx(hKey, strChoosenName, 0, KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hKeyNew); - RegQueryValueEx(hKeyNew, "JavaHome", NULL, NULL, (LPBYTE)strJavaHome, &dwBufLen); - RegCloseKey(hKey); - if (strJavaHome[0] != '\0') { - sprintf(*java_path, "\"%s\\bin\\java\"", strJavaHome); - //strcpy(*java_path, strJavaHome); - //strcat(*java_path, "\\bin\\java"); - } else { - return 0; - } - return 1; -} -#endif diff --git a/tizen/src/skin/maruskin_client.h b/tizen/src/skin/maruskin_client.h index 4c42cc6..3432146 100644 --- a/tizen/src/skin/maruskin_client.h +++ b/tizen/src/skin/maruskin_client.h @@ -31,28 +31,6 @@ #ifndef MARUSKIN_CLIENT_H_ #define MARUSKIN_CLIENT_H_ -#include "../maru_common.h" - -#define JAVA_MAX_COMMAND_LENGTH 1024 - -#define JAR_SKINFILE "emulator-skin.jar" -#define JAVA_LIBRARY_PATH "-Djava.library.path" - -#ifndef CONFIG_DARWIN -#define JAVA_EXEOPTION "-jar" -#else -#define JAVA_EXEOPTION "-XstartOnFirstThread -jar" // Must start the Java window on the first thread on Mac -#endif -#define JAVA_SIMPLEMODE_OPTION "simple.msg" - -#ifdef CONFIG_WIN32 -#define MY_KEY_WOW64_64KEY 0x0100 -int is_wow64(void); -int get_java_path(char**); -#else -#define JAVA_EXEFILE_PATH "java" -#endif - int start_skin_client(int argc, char* argv[]); int start_simple_client(char* msg); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 8303b16..54a8616 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -53,14 +53,14 @@ extern int daemon(int, int); #include "qemu/sockets.h" #include -#ifdef CONFIG_MARU -#include "../../tizen/src/skin/maruskin_client.h" -#endif - #ifdef CONFIG_LINUX #include #endif +#ifdef CONFIG_MARU +#include "../../tizen/src/maru_common.h" +#endif + int qemu_get_thread_id(void) { #if defined(__linux__) @@ -77,22 +77,26 @@ int qemu_daemon(int nochdir, int noclose) 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, }; + int len; +#endif + if (ptr == NULL) { fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno)); #ifdef CONFIG_MARU - char _msg[] = "Failed to allocate memory in qemu."; - char cmd[JAVA_MAX_COMMAND_LENGTH] = { 0, }; - - int len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + strlen(JAR_SKINFILE) + - strlen(JAVA_SIMPLEMODE_OPTION) + strlen(_msg) + 7; + len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + + strlen(JAR_SKINFILE) + strlen(JAVA_SIMPLEMODE_OPTION) + + strlen(_msg) + 7; if (len > JAVA_MAX_COMMAND_LENGTH) { len = JAVA_MAX_COMMAND_LENGTH; } snprintf(cmd, len, "%s %s %s %s=\"%s\"", JAVA_EXEFILE_PATH, JAVA_EXEOPTION, JAR_SKINFILE, JAVA_SIMPLEMODE_OPTION, _msg); - if(system(cmd) == -1) { - // TODO: Handle error...~ + if (system(cmd) == -1) { + fprintf(stderr, "failed to execute this command: %s\n", cmd); } #endif abort(); diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 1be8208..2603a53 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -33,33 +33,30 @@ #include "qemu/sockets.h" #ifdef CONFIG_MARU -#include "../../tizen/src/skin/maruskin_client.h" - typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); LPFN_ISWOW64PROCESS fnIsWow64Process; -static int is_wow64_temp(void) +int is_wow64(void) { int result = 0; /* 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. */ + 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 */ - /* INFO("Can not find 'IsWow64Process'\n"); */ + // handle error + fprintf(stderr, "Cannot find 'IsWow64Process'\n"); } } return result; } -static int get_java_path_temp(char** java_path) +bool get_java_path(char** java_path) { HKEY hKeyNew; HKEY hKey; @@ -71,55 +68,69 @@ static int get_java_path_temp(char** java_path) DWORD dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH; DWORD dwBufLen = JAVA_MAX_COMMAND_LENGTH; - RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\JavaSoft\\Java Runtime Environment", 0, - KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | MY_KEY_WOW64_64KEY, &hKey); + RegOpenKeyEx(HKEY_LOCAL_MACHINE, + "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); + NULL, NULL, NULL, NULL); strcpy(strChoosenName, strSubKeyName); index = 1; - while (ERROR_SUCCESS == RegEnumKeyEx(hKey, index, - (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL)) { + 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, - &hKeyNew); - RegQueryValueEx(hKeyNew, "JavaHome", NULL, NULL, (LPBYTE)strJavaHome, &dwBufLen); + RegOpenKeyEx(hKey, strChoosenName, 0, + KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hKeyNew); + RegQueryValueEx(hKeyNew, "JavaHome", NULL, + NULL, (LPBYTE)strJavaHome, &dwBufLen); RegCloseKey(hKey); - if (strJavaHome[0] != '\0') { sprintf(*java_path, "\"%s\\bin\\java\"", strJavaHome); //strcpy(*java_path, strJavaHome); //strcat(*java_path, "\\bin\\java"); } else { - return 0; + return false; } - return 1; + + return true; } #endif 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; + int len, ret; +#endif + if (ptr == NULL) { fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError()); #ifdef CONFIG_MARU - char _msg[] = "Failed to allocate memory in qemu."; - char cmd[JAVA_MAX_COMMAND_LENGTH] = { 0, }; - char *JAVA_EXEFILE_PATH = malloc(JAVA_MAX_COMMAND_LENGTH); + 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_temp()) { - if (!get_java_path_temp(&JAVA_EXEFILE_PATH)) { + if (is_wow64()) { + if (!get_java_path(&JAVA_EXEFILE_PATH)) { strcpy(JAVA_EXEFILE_PATH, "java"); } } else { strcpy(JAVA_EXEFILE_PATH, "java"); } - int len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + + len = strlen(JAVA_EXEFILE_PATH) + strlen(JAVA_EXEOPTION) + strlen(JAR_SKINFILE) + strlen(JAVA_SIMPLEMODE_OPTION) + strlen(_msg) + 7; if (len > JAVA_MAX_COMMAND_LENGTH) { @@ -129,8 +140,7 @@ 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); - int ret = WinExec(cmd, SW_SHOW); - + ret = WinExec(cmd, SW_SHOW); if (ret < 32) { // TODO: error handling... } -- 2.7.4