emulator: Cleans up code and introduce osutil
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 22 Jan 2013 07:35:28 +0000 (16:35 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 22 Jan 2013 07:35:28 +0000 (16:35 +0900)
Suppress warnings.
Introduce osutil - collection of os dependant utils
Eliminate some duplicate global variables

Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
16 files changed:
tizen/src/Makefile.tizen
tizen/src/debug_ch.c
tizen/src/debug_ch.h
tizen/src/emulator.c
tizen/src/emulator.h
tizen/src/maru_common.h
tizen/src/maru_display.h
tizen/src/mloop_event.c
tizen/src/osutil-darwin.c [new file with mode: 0644]
tizen/src/osutil-linux.c [new file with mode: 0644]
tizen/src/osutil-win32.c [new file with mode: 0644]
tizen/src/osutil.h [new file with mode: 0644]
tizen/src/sdb.c
tizen/src/sdb.h
tizen/src/skin/maruskin_client.c
tizen/src/skin/maruskin_operation.c

index c38fd42..de40722 100755 (executable)
@@ -71,6 +71,17 @@ endif #CONFIG_GL
 # maru loader
 obj-y += emulator.o emul_state.o option.o maru_err_table.o
 
+# osutil
+ifdef CONFIG_LINUX
+obj-y += osutil-linux.o
+endif
+ifdef CONFIG_WIN32
+obj-y += osutil-win32.o
+endif
+ifdef CONFIG_DARWIN
+obj-y += osutil-darwin.o
+endif
+
 # maru display
 obj-y += maru_display.o maru_shm.o
 ifndef CONFIG_DARWIN
index 77ff0e8..3008803 100644 (file)
 #include "emulator.h"
 #include "debug_ch.h"
 
-// DEBUGCH file is located in binary directory.
-char bin_dir[1024] = {0,};
-
-static char logpath[512] = {0,};
 static char debugchfile[512] = {0, };
 #ifdef _WIN32
 static HANDLE handle;
 #endif
 
-void set_log_path(char *path)
-{
-    strcpy(logpath, path);
-}
-
-char *get_log_path(void)
-{
-    return logpath;
-}
-
 static inline int interlocked_xchg_add( int *dest, int incr )
 {
        int ret;
@@ -289,10 +275,10 @@ static void debug_init(void)
        strcat(debugchfile, "/DEBUGCH");
 #endif
 
-    if (0 == strlen(bin_dir)) {
+    if (0 == strlen(bin_path)) {
         strcpy(debugchfile, "DEBUGCH");
     } else {
-        strcat(debugchfile, bin_dir);
+        strcat(debugchfile, bin_path);
         strcat(debugchfile, "DEBUGCH");
     }
 
@@ -326,9 +312,9 @@ static void debug_init(void)
        }
        
        open_flags = O_BINARY | O_RDWR | O_CREAT | O_TRUNC;
-       fd = qemu_open(logpath, open_flags, 0666);
+       fd = qemu_open(log_path, open_flags, 0666);
     if(fd < 0) {
-        fprintf(stderr, "Can't open logfile: %s\n", logpath);
+        fprintf(stderr, "Can't open logfile: %s\n", log_path);
        exit(1);
     }
     close(fd);
@@ -375,7 +361,7 @@ static int dbg_vprintf( const char *format, va_list args )
        sprintf(txt, "%s", tmp);
 
        // unlock
-       if ((fp = fopen(logpath, "a+")) == NULL) {
+       if ((fp = fopen(log_path, "a+")) == NULL) {
                fprintf(stdout, "Emulator can't open.\n"
                                "Please check if "
                                "this binary file is running on the right path.\n");
@@ -455,9 +441,9 @@ int dbg_log( enum _debug_class cls, struct _debug_channel *channel,
        va_end(valist);
    
     open_flags = O_RDWR | O_APPEND | O_BINARY ;
-       fd = qemu_open(logpath, open_flags, 0666);
+       fd = qemu_open(log_path, open_flags, 0666);
        if(fd < 0) {
-        fprintf(stderr, "Can't open logfile: %s\n", logpath);
+        fprintf(stderr, "Can't open logfile: %s\n", log_path);
        exit(1);
     }
     ret_write = qemu_write_full(fd, buf, ret);
index 1788592..e1c193b 100644 (file)
@@ -57,9 +57,6 @@ struct _debug_channel
        char multiname[15];
 };
 
-void set_log_path(char *path);
-char *get_log_path(void);
-
 #ifndef NO_DEBUG
 #define MSGSIZE_MAX 2048
 #define __GET_DEBUGGING_FIXME(dbch) ((dbch)->flags & (1 << __DBCL_FIXME))
@@ -97,8 +94,6 @@ char *get_log_path(void);
 (void)0 : (void)dbg_printf
 */
 
-extern char bin_dir[1024];
-
 extern unsigned char _dbg_get_channel_flags( struct _debug_channel *channel );
 extern int _dbg_set_channel_flags( struct _debug_channel *channel,
                unsigned char set, unsigned char clear );
index ca5b881..7aad6c3 100644 (file)
 
 
 #include "maru_common.h"
-#include <stdlib.h>
-#ifdef CONFIG_SDL
-#include <SDL.h>
-#endif
 #include "emulator.h"
+#include "osutil.h"
 #include "guest_debug.h"
 #include "sdb.h"
 #include "string.h"
 #include "skin/maruskin_server.h"
 #include "skin/maruskin_client.h"
 #include "guest_server.h"
-#include "debug_ch.h"
 #include "option.h"
 #include "emul_state.h"
 #include "qemu_socket.h"
 #include "build_info.h"
 #include "maru_err_table.h"
-#include <glib/gstdio.h>
+#include "maru_display.h"
 #include "qemu-config.h"
+#include "mloop_event.h"
+#include "hw/maru_camera_common.h"
+#include "hw/gloffscreen_test.h"
+#include "debug_ch.h"
+
+#include <stdlib.h>
+#ifdef CONFIG_SDL
+#include <SDL.h>
+#endif
 
 #if defined(CONFIG_WIN32)
 #include <windows.h>
 #elif defined(CONFIG_LINUX)
-#include <linux/version.h>
-#include <sys/utsname.h>
-#include <sys/sysinfo.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#endif
-
-#if defined(CONFIG_DARWIN)
-#include <sys/param.h>
+#elif defined(CONFIG_DARWIN)
 #include <sys/sysctl.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include "tizen/src/ns_event.h"
+#include "ns_event.h"
 #endif
 
-#include "mloop_event.h"
-#include "hw/maru_camera_common.h"
-#include "hw/gloffscreen_test.h"
-
 MULTI_DEBUG_CHANNEL(qemu, main);
 
 #define QEMU_ARGS_PREFIX "--qemu-args"
@@ -89,10 +79,12 @@ MULTI_DEBUG_CHANNEL(qemu, main);
 
 #define MIDBUF  128
 
+gchar bin_path[PATH_MAX] = { 0, };
+gchar log_path[PATH_MAX] = { 0, };
+
 int tizen_base_port;
-char tizen_target_path[MAXLEN];
-char tizen_target_img_path[MAXLEN];
-char logpath[MAXLEN];
+char tizen_target_path[PATH_MAX];
+char tizen_target_img_path[PATH_MAX];
 
 int enable_gl = 0;
 int enable_yagl = 0;
@@ -111,11 +103,9 @@ static char **_qemu_argv;
 int thread_running = 1; /* Check if we need exit main */
 #endif
 
-void maru_display_fini(void);
-
-char *get_logpath(void)
+const gchar *get_log_path(void)
 {
-    return logpath;
+    return log_path;
 }
 
 void exit_emulator(void)
@@ -127,157 +117,6 @@ void exit_emulator(void)
     maru_display_fini();
 }
 
-void check_shdmem(void)
-{
-#if defined(CONFIG_LINUX)
-    int shm_id;
-    void *shm_addr;
-    u_int port;
-    int val;
-    struct shmid_ds shm_info;
-
-    for (port = 26100; port < 26200; port += 10) {
-        shm_id = shmget((key_t)port, 0, 0);
-        if (shm_id != -1) {
-            shm_addr = shmat(shm_id, (void *)0, 0);
-            if ((void *)-1 == shm_addr) {
-                ERR("error occured at shmat()\n");
-                break;
-            }
-
-            val = shmctl(shm_id, IPC_STAT, &shm_info);
-            if (val != -1) {
-                INFO("count of process that use shared memory : %d\n",
-                    shm_info.shm_nattch);
-                if ((shm_info.shm_nattch > 0) &&
-                    strcmp(tizen_target_img_path, (char *)shm_addr) == 0) {
-                    if (check_port_bind_listen(port + 1) > 0) {
-                        shmdt(shm_addr);
-                        continue;
-                    }
-                    shmdt(shm_addr);
-                    maru_register_exit_msg(MARU_EXIT_UNKNOWN,
-                                        "Can not execute this VM.\n"
-                                        "The same name is running now.");
-                    exit(0);
-                } else {
-                    shmdt(shm_addr);
-                }
-            }
-        }
-    }
-
-#elif defined(CONFIG_WIN32)
-    u_int port;
-    char *base_port = NULL;
-    char *pBuf;
-    HANDLE hMapFile;
-    for (port = 26100; port < 26200; port += 10) {
-        base_port = g_strdup_printf("%d", port);
-        hMapFile = OpenFileMapping(FILE_MAP_READ, TRUE, base_port);
-        if (hMapFile == NULL) {
-            INFO("port %s is not used.\n", base_port);
-            continue;
-        } else {
-             pBuf = (char *)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 50);
-            if (pBuf == NULL) {
-                ERR("Could not map view of file (%d).\n", GetLastError());
-                CloseHandle(hMapFile);
-            }
-
-            if (strcmp(pBuf, tizen_target_img_path) == 0) {
-                maru_register_exit_msg(MARU_EXIT_UNKNOWN,
-                    "Can not execute this VM.\n"
-                    "The same name is running now.");
-                UnmapViewOfFile(pBuf);
-                CloseHandle(hMapFile);
-                free(base_port);
-                exit(0);
-            } else {
-                UnmapViewOfFile(pBuf);
-            }
-        }
-
-        CloseHandle(hMapFile);
-        free(base_port);
-    }
-#elif defined(CONFIG_DARWIN)
-    /* TODO: */
-#endif
-}
-
-void make_shdmem(void)
-{
-#if defined(CONFIG_LINUX)
-    int shmid;
-    char *shared_memory;
-
-    shmid = shmget((key_t)tizen_base_port, MAXLEN, 0666|IPC_CREAT);
-    if (shmid == -1) {
-        ERR("shmget failed\n");
-        return;
-    }
-
-    shared_memory = shmat(shmid, (char *)0x00, 0);
-    if (shared_memory == (void *)-1) {
-        ERR("shmat failed\n");
-        return;
-    }
-    sprintf(shared_memory, "%s", tizen_target_img_path);
-    INFO("shared memory key: %d value: %s\n",
-        tizen_base_port, (char *)shared_memory);
-#elif defined(CONFIG_WIN32)
-    HANDLE hMapFile;
-    char *pBuf;
-    char *port_in_use;
-    char *shared_memory;
-
-    shared_memory = g_strdup_printf("%s", tizen_target_img_path);
-    port_in_use =  g_strdup_printf("%d", tizen_base_port);
-    hMapFile = CreateFileMapping(
-                 INVALID_HANDLE_VALUE, /* use paging file */
-                 NULL,                 /* default security */
-                 PAGE_READWRITE,       /* read/write access */
-                 0,                /* maximum object size (high-order DWORD) */
-                 50,               /* maximum object size (low-order DWORD) */
-                 port_in_use);         /* name of mapping object */
-    if (hMapFile == NULL) {
-        ERR("Could not create file mapping object (%d).\n", GetLastError());
-        return;
-    }
-    pBuf = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 50);
-
-    if (pBuf == NULL) {
-        ERR("Could not map view of file (%d).\n", GetLastError());
-        CloseHandle(hMapFile);
-        return;
-    }
-
-    CopyMemory((PVOID)pBuf, shared_memory, strlen(shared_memory));
-    free(port_in_use);
-    free(shared_memory);
-#elif defined(CONFIG_DARWIN)
-    /* TODO: */
-    int shmid;
-    char *shared_memory;
-
-    shmid = shmget((key_t)SHMKEY, MAXLEN, 0666|IPC_CREAT);
-    if (shmid == -1) {
-        ERR("shmget failed\n");
-        return;
-    }
-    shared_memory = shmat(shmid, (char *)0x00, 0);
-    if (shared_memory == (void *)-1) {
-        ERR("shmat failed\n");
-        return;
-    }
-    sprintf(shared_memory, "%d", tizen_base_port + 2);
-    INFO("shared memory key: %d, value: %s\n", SHMKEY, (char *)shared_memory);
-    shmdt(shared_memory);
-#endif
-    return;
-}
-
 static void construct_main_window(int skin_argc, char *skin_argv[],
                                 int qemu_argc, char *qemu_argv[])
 {
@@ -329,77 +168,34 @@ static void parse_options(int argc, char *argv[], int *skin_argc,
     }
 }
 
-static char *set_bin_dir(char *exec_argv)
+static void set_bin_path(gchar * exec_argv)
 {
-#ifndef CONFIG_DARWIN
-    char link_path[1024] = { 0, };
-#endif
-    char *file_name = NULL;
-
-#if defined(CONFIG_WIN32)
-    if (!GetModuleFileName(NULL, link_path, 1024)) {
-        return NULL;
-    }
-
-    file_name = strrchr(link_path, '\\');
-    strncpy(bin_dir, link_path, strlen(link_path) - strlen(file_name));
-
-    strcat(bin_dir, "\\");
-
-#elif defined(CONFIG_LINUX)
-    ssize_t len = readlink("/proc/self/exe", link_path, sizeof(link_path) - 1);
-
-    if (len < 0 || len > sizeof(link_path)) {
-        perror("get_bin_dir error : ");
-        return NULL;
-    }
-
-    link_path[len] = '\0';
-
-    file_name = strrchr(link_path, '/');
-    strncpy(bin_dir, link_path, strlen(link_path) - strlen(file_name));
-
-    strcat(bin_dir, "/");
-
-#else
-    if (!exec_argv) {
-        return NULL;
-    }
-
-    char *data = strdup(exec_argv);
-    if (!data) {
-        fprintf(stderr, "Fail to strdup for paring a binary directory.\n");
-        return NULL;
-    }
-
-    file_name = strrchr(data, '/');
-    if (!file_name) {
-        free(data);
-        return NULL;
-    }
-
-    strncpy(bin_dir, data, strlen(data) - strlen(file_name));
+    set_bin_path_os(exec_argv);
+}
 
-    strcat(bin_dir, "/");
-    free(data);
-#endif
+gchar * get_bin_path(void)
+{
+    return bin_path;
+}
 
-    return bin_dir;
+static void check_vm_lock(void)
+{
+    check_vm_lock_os();
 }
 
-char *get_bin_path(void)
+static void make_vm_lock(void)
 {
-    return bin_dir;
+    make_vm_lock_os();
 }
 
-void set_image_and_log_path(char *qemu_argv)
+static void set_image_and_log_path(char *qemu_argv)
 {
     int i, j = 0;
     int name_len = 0;
     int prefix_len = 0;
     int suffix_len = 0;
     int max = 0;
-    char *path = malloc(MAXLEN);
+    char *path = malloc(PATH_MAX);
     name_len = strlen(qemu_argv);
     prefix_len = strlen(IMAGE_PATH_PREFIX);
     suffix_len = strlen(IMAGE_PATH_SUFFIX);
@@ -417,31 +213,30 @@ void set_image_and_log_path(char *qemu_argv)
     strcpy(tizen_target_img_path, path);
     free(path);
 
-    strcpy(logpath, tizen_target_path);
-    strcat(logpath, LOGS_SUFFIX);
+    strcpy(log_path, tizen_target_path);
+    strcat(log_path, LOGS_SUFFIX);
 #ifdef CONFIG_WIN32
-    if (access(g_win32_locale_filename_from_utf8(logpath), R_OK) != 0) {
-        g_mkdir(g_win32_locale_filename_from_utf8(logpath), 0755);
+    if (access(g_win32_locale_filename_from_utf8(log_path), R_OK) != 0) {
+        g_mkdir(g_win32_locale_filename_from_utf8(log_path), 0755);
     }
 #else
-    if (access(logpath, R_OK) != 0) {
-        g_mkdir(logpath, 0755);
+    if (access(log_path, R_OK) != 0) {
+        g_mkdir(log_path, 0755);
     }
 #endif
-    strcat(logpath, LOGFILE);
-    set_log_path(logpath);
+    strcat(log_path, LOGFILE);
 }
 
-void redir_output(void)
+static void redir_output(void)
 {
     FILE *fp;
 
-    fp = freopen(logpath, "a+", stdout);
+    fp = freopen(log_path, "a+", stdout);
     if (fp == NULL) {
         fprintf(stderr, "log file open error\n");
     }
 
-    fp = freopen(logpath, "a+", stderr);
+    fp = freopen(log_path, "a+", stderr);
     if (fp == NULL) {
         fprintf(stderr, "log file open error\n");
     }
@@ -449,7 +244,7 @@ void redir_output(void)
     setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
 }
 
-void extract_qemu_info(int qemu_argc, char **qemu_argv)
+static void extract_qemu_info(int qemu_argc, char **qemu_argv)
 {
     int i = 0;
 
@@ -462,7 +257,7 @@ void extract_qemu_info(int qemu_argc, char **qemu_argv)
 
 }
 
-void extract_skin_info(int skin_argc, char **skin_argv)
+static void extract_skin_info(int skin_argc, char **skin_argv)
 {
     int i = 0;
     int w = 0, h = 0;
@@ -488,7 +283,7 @@ void extract_skin_info(int skin_argc, char **skin_argv)
 }
 
 
-static void system_info(void)
+static void print_system_info(void)
 {
 #define DIV 1024
 
@@ -518,85 +313,13 @@ static void system_info(void)
         SDL_Linked_Version()->patch);
 #endif
 
-#if defined(CONFIG_WIN32)
-    INFO("* Windows\n");
-
-    /* Retrieves information about the current os */
-    OSVERSIONINFO osvi;
-    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
-    if (GetVersionEx(&osvi)) {
-        INFO("* MajorVersion : %d, MinorVersion : %d, BuildNumber : %d, \
-            PlatformId : %d, CSDVersion : %s\n", osvi.dwMajorVersion,
-            osvi.dwMinorVersion, osvi.dwBuildNumber,
-            osvi.dwPlatformId, osvi.szCSDVersion);
-    }
-
-    /* Retrieves information about the current system */
-    SYSTEM_INFO sysi;
-    ZeroMemory(&sysi, sizeof(SYSTEM_INFO));
-
-    GetSystemInfo(&sysi);
-    INFO("* Processor type : %d, Number of processors : %d\n",
-            sysi.dwProcessorType, sysi.dwNumberOfProcessors);
-
-    MEMORYSTATUSEX memInfo;
-    memInfo.dwLength = sizeof(MEMORYSTATUSEX);
-    GlobalMemoryStatusEx(&memInfo);
-    INFO("* Total Ram : %llu kB, Free: %lld kB\n",
-            memInfo.ullTotalPhys / DIV, memInfo.ullAvailPhys / DIV);
-
-#elif defined(CONFIG_LINUX)
-    INFO("* Linux\n");
-
-    /* depends on building */
-    INFO("* QEMU build machine linux kernel version : (%d, %d, %d)\n",
-            LINUX_VERSION_CODE >> 16,
-            (LINUX_VERSION_CODE >> 8) & 0xff,
-            LINUX_VERSION_CODE & 0xff);
-
-     /* depends on launching */
-    struct utsname host_uname_buf;
-    if (uname(&host_uname_buf) == 0) {
-        INFO("* Host machine uname : %s %s %s %s %s\n",
-            host_uname_buf.sysname, host_uname_buf.nodename,
-            host_uname_buf.release, host_uname_buf.version,
-            host_uname_buf.machine);
-    }
-
-    struct sysinfo sys_info;
-    if (sysinfo(&sys_info) == 0) {
-        INFO("* Total Ram : %llu kB, Free: %llu kB\n",
-            sys_info.totalram * (unsigned long long)sys_info.mem_unit / DIV,
-            sys_info.freeram * (unsigned long long)sys_info.mem_unit / DIV);
-    }
-
-    /* get linux distribution information */
-    INFO("* Linux distribution infomation :\n");
-    char lsb_release_cmd[MAXLEN] = "lsb_release -d -r -c >> ";
-    strcat(lsb_release_cmd, logpath);
-    if(system(lsb_release_cmd) < 0) {
-        INFO("system function command '%s' \
-            returns error !", lsb_release_cmd);
-    }
-
-    /* pci device description */
-    INFO("* PCI devices :\n");
-    char lspci_cmd[MAXLEN] = "lspci >> ";
-    strcat(lspci_cmd, logpath);
-    if(system(lspci_cmd) < 0) {
-        INFO("system function command '%s' \
-            returns error !", lspci_cmd);
-    }
-
-#elif defined(CONFIG_DARWIN)
+#if defined(CONFIG_DARWIN)
     INFO("* Mac\n");
 
     /* uname */
     INFO("* Host machine uname :\n");
     char uname_cmd[MAXLEN] = "uname -a >> ";
-    strcat(uname_cmd, logpath);
+    strcat(uname_cmd, log_path);
     if(system(uname_cmd) < 0) {
         INFO("system function command '%s' \
             returns error !", uname_cmd);
@@ -639,7 +362,8 @@ static void system_info(void)
     if (sysctl(mib, 2, &sys_num, &len, NULL, 0) >= 0) {
         INFO("* Total memory : %llu bytes\n", sys_num);
     }
-
+#else
+    print_system_info_os();
 #endif
 
     INFO("\n");
@@ -677,9 +401,9 @@ static void prepare_basic_features(void)
     // using "DNS" provided by default QEMU
     g_strlcpy(dns, DEFAULT_QEMU_DNS_IP, strlen(DEFAULT_QEMU_DNS_IP) + 1);
 
-    check_shdmem();
+    check_vm_lock();
     socket_init();
-    make_shdmem();
+    make_vm_lock();
 
     sdb_setup();
 
@@ -826,7 +550,7 @@ static int emulator_main(int argc, char *argv[])
 {
     parse_options(argc, argv, &_skin_argc,
                 &_skin_argv, &_qemu_argc, &_qemu_argv);
-    set_bin_dir(_qemu_argv[0]);
+    set_bin_path(_qemu_argv[0]);
     extract_qemu_info(_qemu_argc, _qemu_argv);
 
     INFO("Emulator start !!!\n");
@@ -834,7 +558,7 @@ static int emulator_main(int argc, char *argv[])
 
     extract_skin_info(_skin_argc, _skin_argv);
 
-    system_info();
+    print_system_info();
 
     INFO("Prepare running...\n");
     /* Redirect stdout and stderr after debug_ch is initialized. */
index 69da953..4ac9b62 100644 (file)
 #define MAXPACKETLEN 60
 #define SHMKEY 26099
 
+extern gchar bin_path[];
+extern gchar log_path[];
+
 void exit_emulator(void);
 char *get_bin_path(void);
-void set_image_and_log_path(char *qemu_argv);
-void redir_output(void);
-void extract_qemu_info(int qemu_argc, char **qemu_argv);
-void extract_skin_info(int skin_argc, char **skin_argv);
 void prepare_maru(void);
-void check_shdmem(void);
-void make_shdmem(void);
 
+const gchar * get_log_path(void);
 const gchar * prepare_maru_devices(const gchar * kernel_cmdline);
 // FIXME: Necessary declaration of functions but produces error difficult to solve now
 //int maru_device_check(QemuOpts *opts);
index e40fd69..63dc8c0 100644 (file)
 #ifndef __MARU_COMMON_H__
 #define __MARU_COMMON_H__
 
-#include "config-host.h"
 #include <stddef.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <stdlib.h>
+
 #include <glib.h>
+#include <glib/gstdio.h>
+#include <glib/gprintf.h>
+
+#include "config-host.h"
+
+#ifndef PATH_MAX
+#define PATH_MAX    256
+#endif
 
 // W/A for preserve larger continuous heap for RAM.
 extern void *preallocated_ptr;
index 617330b..e8ae696 100644 (file)
@@ -28,8 +28,8 @@
  */
 
 
-#ifndef MARU_DISPLAY_H_
-#define MARU_DISPLAY_H_
+#ifndef __MARU_DISPLAY_H__
+#define __MARU_DISPLAY_H__
 
 #include "console.h"
 
@@ -44,4 +44,4 @@ void maruskin_init(uint64 swt_handle, int lcd_size_width, int lcd_size_height, b
 DisplaySurface* get_qemu_display_surface(void);
 MaruScreenshot* get_maru_screenshot(void);
 
-#endif /* MARU_DISPLAY_H_ */
+#endif /* __MARU_DISPLAY_H__ */
index 9561408..1bdb225 100644 (file)
@@ -385,7 +385,7 @@ static void mloop_evhandle_ramdump(struct mloop_evpack* pack)
     char dump_fullpath[MAX_PATH];
     char dump_filename[MAX_PATH];
 
-    char* dump_path = g_path_get_dirname(get_logpath());
+    char* dump_path = g_path_get_dirname(get_log_path());
 
     sprintf(dump_filename, "0x%08x%s0x%08x%s", rm->ram_addr, "-",
         rm->ram_addr + size, "_RAM.dump");
diff --git a/tizen/src/osutil-darwin.c b/tizen/src/osutil-darwin.c
new file mode 100644 (file)
index 0000000..2b04ca7
--- /dev/null
@@ -0,0 +1,99 @@
+/* 
+ * Emulator
+ *
+ * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * MunKyu Im <munkyu.im@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+/**
+  @file     osutil-darwin.c
+  @brief    Collection of utilities for darwin
+ */
+
+#include "osutil.h"
+#include "emulator.h"
+#include "debug_ch.h"
+#include "maru_err_table.h"
+#include "sdb.h"
+
+#include <string.h>
+#include <sys/shm.h>
+
+MULTI_DEBUG_CHANNEL(qemu, osutil);
+
+extern int tizen_base_port;
+
+void check_vm_lock_os(void)
+{
+    /* TODO: */
+}
+
+void make_vm_lock_os(void)
+{
+    int shmid;
+    char *shared_memory;
+
+    shmid = shmget((key_t)SHMKEY, MAXLEN, 0666|IPC_CREAT);
+    if (shmid == -1) {
+        ERR("shmget failed\n");
+        return;
+    }
+    shared_memory = shmat(shmid, (char *)0x00, 0);
+    if (shared_memory == (void *)-1) {
+        ERR("shmat failed\n");
+        return;
+    }
+    sprintf(shared_memory, "%d", tizen_base_port + 2);
+    INFO("shared memory key: %d, value: %s\n", SHMKEY, (char *)shared_memory);
+    shmdt(shared_memory);
+}
+
+void set_bin_path_os(gchar * exec_argv)
+{
+    gchar *file_name = NULL;
+
+    if (!exec_argv) {
+        return;
+    }
+
+    char *data = g_strdup(exec_argv);
+    if (!data) {
+        ERR("Fail to strdup for paring a binary directory.\n");
+        return;
+    }
+
+    file_name = g_strrstr(data, "/");
+    if (!file_name) {
+        free(data);
+        return;
+    }
+
+    g_strlcpy(bin_path, data, strlen(data) - strlen(file_name) + 1);
+
+    g_strlcat(bin_path, "/", PATH_MAX);
+    free(data);
+}
diff --git a/tizen/src/osutil-linux.c b/tizen/src/osutil-linux.c
new file mode 100644 (file)
index 0000000..03b8f97
--- /dev/null
@@ -0,0 +1,181 @@
+/* 
+ * Emulator
+ *
+ * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * MunKyu Im <munkyu.im@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+/**
+  @file     osutil-linux.c
+  @brief    Collection of utilities for linux
+ */
+
+#include "maru_common.h"
+#include "osutil.h"
+#include "emulator.h"
+#include "debug_ch.h"
+#include "maru_err_table.h"
+#include "sdb.h"
+
+#include <string.h>
+#include <unistd.h>
+#include <sys/shm.h>
+#include <sys/ipc.h>
+#include <linux/version.h>
+#include <sys/utsname.h>
+#include <sys/sysinfo.h>
+
+MULTI_DEBUG_CHANNEL(emulator, osutil);
+
+extern char tizen_target_img_path[];
+extern int tizen_base_port;
+
+void check_vm_lock_os(void)
+{
+    int shm_id;
+    void *shm_addr;
+    uint32_t port;
+    int val;
+    struct shmid_ds shm_info;
+
+    for (port = 26100; port < 26200; port += 10) {
+        shm_id = shmget((key_t)port, 0, 0);
+        if (shm_id != -1) {
+            shm_addr = shmat(shm_id, (void *)0, 0);
+            if ((void *)-1 == shm_addr) {
+                ERR("error occured at shmat()\n");
+                break;
+            }
+
+            val = shmctl(shm_id, IPC_STAT, &shm_info);
+            if (val != -1) {
+                INFO("count of process that use shared memory : %d\n",
+                    shm_info.shm_nattch);
+                if ((shm_info.shm_nattch > 0) &&
+                    g_strcmp0(tizen_target_img_path, (char *)shm_addr) == 0) {
+                    if (check_port_bind_listen(port + 1) > 0) {
+                        shmdt(shm_addr);
+                        continue;
+                    }
+                    shmdt(shm_addr);
+                    maru_register_exit_msg(MARU_EXIT_UNKNOWN,
+                                        "Can not execute this VM.\n"
+                                        "The same name is running now.");
+                    exit(0);
+                } else {
+                    shmdt(shm_addr);
+                }
+            }
+        }
+    }
+}
+
+void make_vm_lock_os(void)
+{
+    int shmid;
+    char *shared_memory;
+
+    shmid = shmget((key_t)tizen_base_port, MAXLEN, 0666|IPC_CREAT);
+    if (shmid == -1) {
+        ERR("shmget failed\n");
+        return;
+    }
+
+    shared_memory = shmat(shmid, (char *)0x00, 0);
+    if (shared_memory == (void *)-1) {
+        ERR("shmat failed\n");
+        return;
+    }
+    g_sprintf(shared_memory, "%s", tizen_target_img_path);
+    INFO("shared memory key: %d value: %s\n",
+        tizen_base_port, (char *)shared_memory);
+}
+
+void set_bin_path_os(gchar * exec_argv)
+{
+    gchar link_path[PATH_MAX] = { 0, };
+    char *file_name = NULL;
+
+    ssize_t len = readlink("/proc/self/exe", link_path, sizeof(link_path) - 1);
+
+    if (len < 0 || len > sizeof(link_path)) {
+        perror("set_bin_path error : ");
+        return;
+    }
+
+    link_path[len] = '\0';
+
+    file_name = g_strrstr(link_path, "/");
+    g_strlcpy(bin_path, link_path, strlen(link_path) - strlen(file_name) + 1);
+
+    g_strlcat(bin_path, "/", PATH_MAX);
+}
+
+void print_system_info_os(void)
+{
+    INFO("* Linux\n");
+
+    /* depends on building */
+    INFO("* QEMU build machine linux kernel version : (%d, %d, %d)\n",
+            LINUX_VERSION_CODE >> 16,
+            (LINUX_VERSION_CODE >> 8) & 0xff,
+            LINUX_VERSION_CODE & 0xff);
+
+     /* depends on launching */
+    struct utsname host_uname_buf;
+    if (uname(&host_uname_buf) == 0) {
+        INFO("* Host machine uname : %s %s %s %s %s\n",
+            host_uname_buf.sysname, host_uname_buf.nodename,
+            host_uname_buf.release, host_uname_buf.version,
+            host_uname_buf.machine);
+    }
+
+    struct sysinfo sys_info;
+    if (sysinfo(&sys_info) == 0) {
+        INFO("* Total Ram : %llu kB, Free: %llu kB\n",
+            sys_info.totalram * (unsigned long long)sys_info.mem_unit / 1024,
+            sys_info.freeram * (unsigned long long)sys_info.mem_unit / 1024);
+    }
+
+    /* get linux distribution information */
+    INFO("* Linux distribution infomation :\n");
+    char lsb_release_cmd[MAXLEN] = "lsb_release -d -r -c >> ";
+    strcat(lsb_release_cmd, log_path);
+    if(system(lsb_release_cmd) < 0) {
+        INFO("system function command '%s' \
+            returns error !", lsb_release_cmd);
+    }
+
+    /* pci device description */
+    INFO("* PCI devices :\n");
+    char lspci_cmd[MAXLEN] = "lspci >> ";
+    strcat(lspci_cmd, log_path);
+    if(system(lspci_cmd) < 0) {
+        INFO("system function command '%s' \
+            returns error !", lspci_cmd);
+    }
+}
diff --git a/tizen/src/osutil-win32.c b/tizen/src/osutil-win32.c
new file mode 100644 (file)
index 0000000..65b4731
--- /dev/null
@@ -0,0 +1,165 @@
+/* 
+ * Emulator
+ *
+ * Copyright (C) 2012, 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * MunKyu Im <munkyu.im@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+/**
+  @file     osutil-win32.c
+  @brief    Collection of utilities for win32
+ */
+
+#include "maru_common.h"
+#include "osutil.h"
+#include "emulator.h"
+#include "debug_ch.h"
+#include "maru_err_table.h"
+#include "sdb.h"
+
+#include <windows.h>
+
+MULTI_DEBUG_CHANNEL (emulator, osutil);
+
+extern char tizen_target_img_path[];
+extern int tizen_base_port;
+
+void check_vm_lock_os(void)
+{
+    uint32_t port;
+    char *base_port = NULL;
+    char *pBuf;
+    HANDLE hMapFile;
+    for (port = 26100; port < 26200; port += 10) {
+        base_port = g_strdup_printf("%d", port);
+        hMapFile = OpenFileMapping(FILE_MAP_READ, TRUE, base_port);
+        if (hMapFile == NULL) {
+            INFO("port %s is not used.\n", base_port);
+            continue;
+        } else {
+             pBuf = (char *)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 50);
+            if (pBuf == NULL) {
+                ERR("Could not map view of file (%d).\n", GetLastError());
+                CloseHandle(hMapFile);
+            }
+
+            if (strcmp(pBuf, tizen_target_img_path) == 0) {
+                maru_register_exit_msg(MARU_EXIT_UNKNOWN,
+                    "Can not execute this VM.\n"
+                    "The same name is running now.");
+                UnmapViewOfFile(pBuf);
+                CloseHandle(hMapFile);
+                free(base_port);
+                exit(0);
+            } else {
+                UnmapViewOfFile(pBuf);
+            }
+        }
+
+        CloseHandle(hMapFile);
+        free(base_port);
+    }
+}
+
+void make_vm_lock_os(void)
+{
+    HANDLE hMapFile;
+    char *pBuf;
+    char *port_in_use;
+    char *shared_memory;
+
+    shared_memory = g_strdup_printf("%s", tizen_target_img_path);
+    port_in_use =  g_strdup_printf("%d", tizen_base_port);
+    hMapFile = CreateFileMapping(
+                 INVALID_HANDLE_VALUE, /* use paging file */
+                 NULL,                 /* default security */
+                 PAGE_READWRITE,       /* read/write access */
+                 0,                /* maximum object size (high-order DWORD) */
+                 50,               /* maximum object size (low-order DWORD) */
+                 port_in_use);         /* name of mapping object */
+    if (hMapFile == NULL) {
+        ERR("Could not create file mapping object (%d).\n", GetLastError());
+        return;
+    }
+    pBuf = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 50);
+
+    if (pBuf == NULL) {
+        ERR("Could not map view of file (%d).\n", GetLastError());
+        CloseHandle(hMapFile);
+        return;
+    }
+
+    CopyMemory((PVOID)pBuf, shared_memory, strlen(shared_memory));
+    free(port_in_use);
+    free(shared_memory);
+}
+
+void set_bin_path_os(gchar * exec_argv)
+{
+    gchar link_path[PATH_MAX] = { 0, };
+    gchar *file_name = NULL;
+
+    if (!GetModuleFileName(NULL, link_path, PATH_MAX)) {
+        return;
+    }
+
+    file_name = g_strrstr(link_path, "\\");
+    g_strlcpy(bin_path, link_path, strlen(link_path) - strlen(file_name) + 1);
+
+    g_strlcat(bin_path, "\\", PATH_MAX);
+}
+
+void print_system_info_os(void)
+{
+    INFO("* Windows\n");
+
+    /* Retrieves information about the current os */
+    OSVERSIONINFO osvi;
+    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+    if (GetVersionEx(&osvi)) {
+        INFO("* MajorVersion : %d, MinorVersion : %d, BuildNumber : %d, \
+            PlatformId : %d, CSDVersion : %s\n", osvi.dwMajorVersion,
+            osvi.dwMinorVersion, osvi.dwBuildNumber,
+            osvi.dwPlatformId, osvi.szCSDVersion);
+    }
+
+    /* Retrieves information about the current system */
+    SYSTEM_INFO sysi;
+    ZeroMemory(&sysi, sizeof(SYSTEM_INFO));
+
+    GetSystemInfo(&sysi);
+    INFO("* Processor type : %d, Number of processors : %d\n",
+            sysi.dwProcessorType, sysi.dwNumberOfProcessors);
+
+    MEMORYSTATUSEX memInfo;
+    memInfo.dwLength = sizeof(MEMORYSTATUSEX);
+    GlobalMemoryStatusEx(&memInfo);
+    INFO("* Total Ram : %llu kB, Free: %lld kB\n",
+            memInfo.ullTotalPhys / DIV, memInfo.ullAvailPhys / DIV);
+}
diff --git a/tizen/src/osutil.h b/tizen/src/osutil.h
new file mode 100644 (file)
index 0000000..3bd9474
--- /dev/null
@@ -0,0 +1,45 @@
+/* 
+ * Emulator
+ *
+ * Copyright (C) 2011, 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * MunKyu Im <munkyu.im@samsung.com>
+ * GiWoong Kim <giwoong.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * HyunJun Son
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef __OSUTIL_H__
+#define __OSUTIL_H__
+
+#include "maru_common.h"
+
+void check_vm_lock_os(void);
+void make_vm_lock_os(void);
+
+void set_bin_path_os(gchar *);
+
+void print_system_info_os(void);
+
+#endif // __OS_UTIL_H__
+
index fa51d18..568a32b 100644 (file)
@@ -34,6 +34,7 @@
 MULTI_DEBUG_CHANNEL(qemu, sdb);\r
 \r
 extern char tizen_target_path[];\r
+extern int tizen_base_port;\r
 \r
 /* QSOCKET_CALL is used to deal with the fact that EINTR happens pretty\r
  * easily in QEMU since we use SIGALRM to implement periodic timers\r
index 8c0e719..91575d7 100644 (file)
 #define SDB_TCP_OPENGL_INDEX  4   /* opengl server port */
 #define SDB_UDP_SENSOR_INDEX  3   /* sensor server port */
 
-extern int tizen_base_port;
-
 void sdb_setup(void);
 int get_sdb_base_port(void);
 int inet_strtoip(const char*  str, uint32_t  *ip);
index 4dacfe7..a89c26f 100644 (file)
@@ -60,6 +60,7 @@ MULTI_DEBUG_CHANNEL(qemu, skin_client);
 #define OPT_MAX_TOUCHPOINT "max.touchpoint"
 
 extern char tizen_target_path[];
+extern int tizen_base_port;
 
 static int skin_argc;
 static char** skin_argv;
index 16cee98..66839b2 100644 (file)
@@ -71,6 +71,8 @@ static int pressing_origin_x = -1, pressing_origin_y = -1;
 extern pthread_mutex_t mutex_screenshot;
 extern pthread_cond_t cond_screenshot;
 
+extern int tizen_base_port;
+
 static void* run_timed_shutdown_thread(void* args);
 static void send_to_emuld(const char* request_type, int request_size, const char* send_buf, int buf_size);