oslib-win32: separate heler functions from maruskin_client.
authorKitae Kim <kt920.kim@samsung.com>
Thu, 18 Jul 2013 02:35:07 +0000 (11:35 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Thu, 18 Jul 2013 06:29:30 +0000 (15:29 +0900)
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 <kt920.kim@samsung.com>
include/qemu-common.h
tizen/src/maru_common.h
tizen/src/maru_err_table.c
tizen/src/skin/maruskin_client.c
tizen/src/skin/maruskin_client.h
util/oslib-posix.c
util/oslib-win32.c

index 3b1ca8ed63a298765ff86b74a542eb246f7d238b..db541241d5e4c99891625ef549e6aa7bd097410a 100644 (file)
@@ -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
index 3aacef95c77b0562332e820647a5daa8c01c4c7c..2bfd57a15bd690972a2d6fb1179d04c74324943d 100644 (file)
@@ -42,7 +42,6 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <stdlib.h>
-
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <glib/gprintf.h>
 #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;
 
index ed73a227682877ac514f1dde42d501179d188ff1..29c5ea9f39cb51380e300444f04c908a6db0b7b3 100644 (file)
  *
  */
 
-
 #include "qemu-common.h"
+#include "maru_common.h"
 #include "maru_err_table.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
 
-#ifdef _WIN32
+#ifdef CONFIG_WIN32
 #include <windows.h>
 #else
 #include <execinfo.h>
index c79503385eea3c7522aabd5efff33103f2bcdace..b4c700157cc02f471a81c987c6f6e3f304ac6007 100644 (file)
  *
  */
 
-
-#include "maru_common.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <pthread.h>
+
+#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 <windows.h>
+#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
index 4c42cc6d647ebf0183bb7fab5946485057c54415..34321467286c0b227bc1ab002f11cecdc1479022 100644 (file)
 #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);
 
index 8303b16fe37beaa32c00f1ebd92343ceafc5172f..54a8616b50c25d781cf63843a1bf25b778e5b238 100644 (file)
@@ -53,14 +53,14 @@ extern int daemon(int, int);
 #include "qemu/sockets.h"
 #include <sys/mman.h>
 
-#ifdef CONFIG_MARU
-#include "../../tizen/src/skin/maruskin_client.h"
-#endif
-
 #ifdef CONFIG_LINUX
 #include <sys/syscall.h>
 #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();
index 1be8208c5d2781808f9b331a6ea409b18ca07921..2603a53f5eda1cae45539ac127d31623b49498d4 100644 (file)
 #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...
         }