LOG_INFO("Exit emulator...\n");
- maru_atexit();
+ handle_error_at_exit();
}
static Notifier emulator_exit = { .notify = emulator_notify_exit };
-static void print_system_info(void)
+void print_system_info(void)
{
+ static bool is_printed = false;
+
+ if (is_printed) {
+ return;
+ }
+
LOG_INFO("* Board name : %s\n", build_version);
LOG_INFO("* Package %s\n", pkginfo_version);
LOG_INFO("* Package %s\n", pkginfo_maintainer);
#endif
print_system_info_os();
+
+ is_printed = true;
}
static void set_qemu_input_mode(void)
const char *prepare_maru(const char * const kernel_cmdline)
{
emulator_add_exit_notifier(&emulator_exit);
- socket_init();
print_system_info();
- set_base_port();
- // assemble new kernel cmdline
+ // We should call socket_init() here since this function called
+ // before calling socket_init() in "vl.c".
+ // It is safe to call socket_init() multiple times.
+ socket_init();
+ init_vm_base_port();
+
+ // Assemble new kernel cmdline
maru_kernel_cmdline = g_strdup_printf("%s sdb_port=%d, "
"vm_resolution=%dx%d", kernel_cmdline, get_emul_vm_base_port(),
get_emul_resolution_width(), get_emul_resolution_height());
{
make_vm_lock_os();
set_qemu_input_mode();
- maru_device_hotplug_init();
+ init_device_hotplug();
start_ecs();
- sdb_setup(get_emul_vm_base_port() + SDB_UDP_SENSOR_INDEX);
+ init_sdb(get_emul_vm_base_port() + SDB_UDP_SENSOR_INDEX);
- // only for intent logging of essential information
+ // Only for intent logging of essential information
get_vm_name();
get_vm_data_path();
}
if (!assemble_emulator_args(&_qemu_argc, _qemu_argv)) {
return -1;
}
-#if defined(CONFIG_JAVA_UI)
+ #if defined(CONFIG_JAVA_UI)
// java skin is deprecated, it is used for only debugging...
_skin_argv[_skin_argc++] =
g_strdup_printf("skin.path=%s", get_emul_skin_path());
_skin_argv[_skin_argc++] =
g_strdup_printf("vm.path=%s/%s",
get_variable("vms_path"), get_variable("vm_name"));
-#endif
+ #endif
#endif
}
return 0;
}
-#if defined(CONFIG_DARWIN) && !defined(CONFIG_QT)
-int g_argc;
-
-static void* main_thread(void* args)
-{
- char** argv;
- int argc = g_argc;
- argv = (char**) args;
-
- emulator_main(argc, argv, NULL);
-
- thread_running = 0;
- pthread_exit(NULL);
-}
-
-int main(int argc, char *argv[])
-{
- char** args;
- QemuThread main_thread_id;
- g_argc = argc;
- args = argv;
- qemu_thread_create(&main_thread_id, "main_thread", main_thread, (void *)args, QEMU_THREAD_DETACHED);
- ns_event_loop(&thread_running);
-
- return 0;
-}
-#elif defined (CONFIG_LINUX)
+#if defined (CONFIG_LINUX)
int main(int argc, char *argv[], char **envp)
{
- maru_register_exception_handler();
+ register_exception_handler();
return emulator_main(argc, argv, envp);
}
-#else // WIN32
+#else
int main(int argc, char *argv[])
{
- #ifndef CONFIG_DARWIN
- maru_register_exception_handler();
- #endif
+ register_exception_handler();
return emulator_main(argc, argv, NULL);
}
#endif
const char *prepare_maru(const gchar * const kernel_cmdline);
void prepare_maru_after_device_init(void);
-void start_skin(void);
-
+void print_system_info(void);
void emulator_add_exit_notifier(Notifier *notify);
+#if defined(CONFIG_JAVA_UI)
+void start_skin(void);
+#endif
+
#endif /* __EMULATOR_H__ */
extern int _qemu_argc;
extern char **_qemu_argv;
-static void print_system_info(void)
+static void print_system_info_legacy(void)
{
#define DIV 1024
extract_qemu_info(_qemu_argc, _qemu_argv);
INFO("Emulator start !!!\n");
- atexit(maru_atexit);
+ atexit(handle_error_at_exit);
emulator_add_exit_notifier(&emulator_exit);
extract_skin_info(_skin_argc, _skin_argv);
/* Redirect stdout and stderr after debug_ch is initialized. */
redir_output();
- print_system_info();
+ print_system_info_legacy();
INFO("Prepare running...\n");
INFO("drive_image_flle: %s\n", get_drive_image_file());
}
}
-static void maru_device_hotplug_deinit(Notifier *notifier, void *data)
+static void deinit_maru_device_hotplug(Notifier *notifier, void *data)
{
event_notifier_cleanup(&state->notifier);
g_free(state);
}
-static Notifier maru_device_hotplug_exit = { .notify = maru_device_hotplug_deinit };
+static Notifier maru_device_hotplug_exit = { .notify = deinit_maru_device_hotplug };
-void maru_device_hotplug_init(void)
+void init_device_hotplug(void)
{
state = g_malloc0(sizeof(struct maru_device_hotplug));
DETACH_HDS,
};
-void maru_device_hotplug_init(void);
+void init_device_hotplug(void);
void do_hotplug(int command, void *opaque, size_t size);
*
*/
-#include "qemu-common.h"
-#include "emulator_common.h"
-#include "maru_err_table.h"
-#include "debug_ch.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
-
#ifdef CONFIG_WIN32
#include <windows.h>
#else
#include <execinfo.h>
#endif
+#include "qemu-common.h"
+
+#include "emulator_common.h"
+#include "emulator.h"
+#include "maru_err_table.h"
+
+#include "debug_ch.h"
MULTI_DEBUG_CHANNEL(qemu, backtrace);
+
/* This table must match the enum definition */
static char _maru_string_table[][JAVA_MAX_COMMAND_LENGTH] = {
/* 0 */ "",
maru_exit_status, maru_exit_msg);
}
-void maru_atexit(void)
-{
-
- if (maru_exit_status != MARU_EXIT_NORMAL || maru_exit_msg) {
- start_simple_client(maru_exit_msg);
- }
- g_free(maru_exit_msg);
-
- INFO("normal exit called\n");
- // dump backtrace log no matter what
- maru_dump_backtrace(NULL, 0);
-}
-
/* Print 'backtrace' */
#ifdef _WIN32
struct frame_layout {
}
#endif
-void maru_dump_backtrace(void *ptr, int depth)
+static void dump_backtrace(void *ptr, int depth)
{
#ifdef _WIN32
int nCount;
#endif
}
+void handle_error_at_exit(void)
+{
+
+ if (maru_exit_status != MARU_EXIT_NORMAL || maru_exit_msg) {
+ start_simple_client(maru_exit_msg);
+ }
+ g_free(maru_exit_msg);
+
+ // dump backtrace log no matter what
+ INFO("This is not a error.\n");
+ INFO("Stack backtrace for tracing...\n");
+ dump_backtrace(NULL, 0);
+}
+
#ifdef CONFIG_WIN32
static WINAPI LONG maru_unhandled_exception_filter(LPEXCEPTION_POINTERS pExceptionInfo){
char module_buf[1024];
+
+ // print system information again
+ print_system_info();
+
DWORD dwException = pExceptionInfo->ExceptionRecord->ExceptionCode;
ERR("%d\n ", (int)dwException);
);
pContext = pExceptionInfo->ContextRecord;
- maru_dump_backtrace(pContext, 0);
+ dump_backtrace(pContext, 0);
_exit(0);
//return EXCEPTION_CONTINUE_SEARCH;
}
#ifdef CONFIG_LINUX
void maru_sighandler(int sig)
{
+ // print system information again
+ print_system_info();
+
pthread_spin_lock(&siglock);
ERR("Got signal %d\n", sig);
- maru_dump_backtrace(NULL, 0);
+ dump_backtrace(NULL, 0);
pthread_spin_unlock(&siglock);
_exit(0);
}
#ifndef CONFIG_DARWIN
-void maru_register_exception_handler(void)
+void register_exception_handler(void)
{
-#ifdef CONFIG_WIN32
+ #ifdef CONFIG_WIN32
prevExceptionFilter = SetUnhandledExceptionFilter(maru_unhandled_exception_filter);
-#else // LINUX
+ #else // LINUX
void *trace[1];
struct sigaction sa;
// main thread only
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
-#endif
+ #endif
+}
+#else // CONFIG_DARWIN
+void register_exception_handler(void)
+{
+ // TODO: Exception handling on darwin
}
#endif
char *get_canonical_path(char const *const path);
void maru_register_exit_msg(int maru_exit_status, char const *format, ...);
-void maru_atexit(void);
+void register_exception_handler(void);
+void handle_error_at_exit(void);
-void maru_dump_backtrace(void *ptr, int depth);
-
-void maru_register_exception_handler(void);
#endif /* __EMUL_ERR_TABLE_H__ */
#define ECS_INDEX 3
#define SDB_GUEST_PORT 26101
#define GDB_GUEST_PORT 26102
-void set_base_port(void)
+void init_vm_base_port(void)
{
int tries = 10;
int success = 0;
}
static void start_sdb_noti_server(int server_port);
-void sdb_setup(int server_port)
+void init_sdb(int server_port)
{
start_sdb_noti_server(server_port);
#define SDB_TCP_OPENGL_INDEX 3 /* opengl server port */
#define SDB_UDP_SENSOR_INDEX 3 /* sensor server port */
-void sdb_setup(int server_port);
-void set_base_port(void);
+void init_sdb(int server_port);
+void init_vm_base_port(void);
int inet_strtoip(const char* str, uint32_t *ip);
int socket_send(int fd, const void* buf, int buflen);
void socket_close(int fd);
}
#endif
-#ifndef CONFIG_MARU
socket_init();
-#endif
if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
exit(1);