From d7ead1135d70db3bd0097d7c4d5c1435201f593b Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Mon, 9 Jan 2017 13:28:28 +0800 Subject: [PATCH] cleanup --- qemu/aarch64.h | 12 -- qemu/arm.h | 12 -- qemu/header_gen.py | 12 -- qemu/include/qemu/osdep.h | 1 - qemu/include/qemu/thread.h | 12 -- qemu/include/sysemu/os-posix.h | 3 - qemu/include/sysemu/os-win32.h | 6 - qemu/m68k.h | 12 -- qemu/main-loop.c | 142 ----------------- qemu/mips.h | 12 -- qemu/mips64.h | 12 -- qemu/mips64el.h | 12 -- qemu/mipsel.h | 12 -- qemu/powerpc.h | 12 -- qemu/qemu-timer.c | 3 - qemu/sparc.h | 12 -- qemu/sparc64.h | 12 -- qemu/util/oslib-posix.c | 14 -- qemu/util/qemu-thread-posix.c | 281 +-------------------------------- qemu/util/qemu-thread-win32.c | 109 ------------- qemu/x86_64.h | 12 -- 21 files changed, 1 insertion(+), 714 deletions(-) delete mode 100644 qemu/main-loop.c diff --git a/qemu/aarch64.h b/qemu/aarch64.h index 67adc0c2..5c30dcb7 100644 --- a/qemu/aarch64.h +++ b/qemu/aarch64.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_aarch64 #define qemu_clock_ptr qemu_clock_ptr_aarch64 #define qemu_clocks qemu_clocks_aarch64 -#define qemu_daemon qemu_daemon_aarch64 -#define qemu_event_destroy qemu_event_destroy_aarch64 -#define qemu_event_init qemu_event_init_aarch64 -#define qemu_event_reset qemu_event_reset_aarch64 -#define qemu_event_set qemu_event_set_aarch64 -#define qemu_event_wait qemu_event_wait_aarch64 #define qemu_fdatasync qemu_fdatasync_aarch64 #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_aarch64 #define qemu_get_cpu qemu_get_cpu_aarch64 @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_aarch64 #define qemu_log_vprintf qemu_log_vprintf_aarch64 #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_aarch64 -#define qemu_mutex_trylock qemu_mutex_trylock_aarch64 #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_aarch64 #define qemu_oom_check qemu_oom_check_aarch64 #define qemu_opt_del qemu_opt_del_aarch64 @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_aarch64 #define qemu_ram_unset_idstr qemu_ram_unset_idstr_aarch64 #define qemu_real_host_page_size qemu_real_host_page_size_aarch64 -#define qemu_sem_destroy qemu_sem_destroy_aarch64 -#define qemu_sem_init qemu_sem_init_aarch64 -#define qemu_sem_post qemu_sem_post_aarch64 -#define qemu_sem_timedwait qemu_sem_timedwait_aarch64 -#define qemu_sem_wait qemu_sem_wait_aarch64 #define qemu_set_cloexec qemu_set_cloexec_aarch64 #define qemu_set_tty_echo qemu_set_tty_echo_aarch64 #define qemu_st_helpers qemu_st_helpers_aarch64 diff --git a/qemu/arm.h b/qemu/arm.h index 818f7acd..c63f2e6a 100644 --- a/qemu/arm.h +++ b/qemu/arm.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_arm #define qemu_clock_ptr qemu_clock_ptr_arm #define qemu_clocks qemu_clocks_arm -#define qemu_daemon qemu_daemon_arm -#define qemu_event_destroy qemu_event_destroy_arm -#define qemu_event_init qemu_event_init_arm -#define qemu_event_reset qemu_event_reset_arm -#define qemu_event_set qemu_event_set_arm -#define qemu_event_wait qemu_event_wait_arm #define qemu_fdatasync qemu_fdatasync_arm #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_arm #define qemu_get_cpu qemu_get_cpu_arm @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_arm #define qemu_log_vprintf qemu_log_vprintf_arm #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_arm -#define qemu_mutex_trylock qemu_mutex_trylock_arm #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_arm #define qemu_oom_check qemu_oom_check_arm #define qemu_opt_del qemu_opt_del_arm @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_arm #define qemu_ram_unset_idstr qemu_ram_unset_idstr_arm #define qemu_real_host_page_size qemu_real_host_page_size_arm -#define qemu_sem_destroy qemu_sem_destroy_arm -#define qemu_sem_init qemu_sem_init_arm -#define qemu_sem_post qemu_sem_post_arm -#define qemu_sem_timedwait qemu_sem_timedwait_arm -#define qemu_sem_wait qemu_sem_wait_arm #define qemu_set_cloexec qemu_set_cloexec_arm #define qemu_set_tty_echo qemu_set_tty_echo_arm #define qemu_st_helpers qemu_st_helpers_arm diff --git a/qemu/header_gen.py b/qemu/header_gen.py index 30b7fd0e..99dfde23 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -2419,12 +2419,6 @@ symbols = ( 'qemu_clock_get_us', 'qemu_clock_ptr', 'qemu_clocks', - 'qemu_daemon', - 'qemu_event_destroy', - 'qemu_event_init', - 'qemu_event_reset', - 'qemu_event_set', - 'qemu_event_wait', 'qemu_fdatasync', 'qemu_flush_coalesced_mmio_buffer', 'qemu_get_cpu', @@ -2444,7 +2438,6 @@ symbols = ( 'qemu_loglevel_mask', 'qemu_log_vprintf', 'qemu_mutex_lock_ramlist', - 'qemu_mutex_trylock', 'qemu_mutex_unlock_ramlist', 'qemu_oom_check', 'qemu_opt_del', @@ -2503,11 +2496,6 @@ symbols = ( 'qemu_ram_setup_dump', 'qemu_ram_unset_idstr', 'qemu_real_host_page_size', - 'qemu_sem_destroy', - 'qemu_sem_init', - 'qemu_sem_post', - 'qemu_sem_timedwait', - 'qemu_sem_wait', 'qemu_set_cloexec', 'qemu_set_tty_echo', 'qemu_st_helpers', diff --git a/qemu/include/qemu/osdep.h b/qemu/include/qemu/osdep.h index c593826e..981ac5f1 100644 --- a/qemu/include/qemu/osdep.h +++ b/qemu/include/qemu/osdep.h @@ -101,7 +101,6 @@ typedef signed int int_fast16_t; #define qemu_printf printf -int qemu_daemon(int nochdir, int noclose); void *qemu_try_memalign(size_t alignment, size_t size); void *qemu_memalign(size_t alignment, size_t size); void *qemu_anon_ram_alloc(size_t size, uint64_t *align); diff --git a/qemu/include/qemu/thread.h b/qemu/include/qemu/thread.h index 67e893e1..52054716 100644 --- a/qemu/include/qemu/thread.h +++ b/qemu/include/qemu/thread.h @@ -40,18 +40,6 @@ void qemu_cond_signal(QemuCond *cond); void qemu_cond_broadcast(QemuCond *cond); void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex); -void qemu_sem_init(QemuSemaphore *sem, int init); -void qemu_sem_post(QemuSemaphore *sem); -void qemu_sem_wait(QemuSemaphore *sem); -int qemu_sem_timedwait(QemuSemaphore *sem, int ms); -void qemu_sem_destroy(QemuSemaphore *sem); - -void qemu_event_init(QemuEvent *ev, bool init); -void qemu_event_set(QemuEvent *ev); -void qemu_event_reset(QemuEvent *ev); -void qemu_event_wait(QemuEvent *ev); -void qemu_event_destroy(QemuEvent *ev); - struct uc_struct; // return -1 on error, 0 on success int qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name, diff --git a/qemu/include/sysemu/os-posix.h b/qemu/include/sysemu/os-posix.h index 2e86fd4b..03555df0 100644 --- a/qemu/include/sysemu/os-posix.h +++ b/qemu/include/sysemu/os-posix.h @@ -31,7 +31,6 @@ void os_set_line_buffering(void); void os_set_proc_name(const char *s); void os_setup_signal_handling(void); -void os_daemonize(void); void os_setup_post(void); int os_mlock(void); @@ -48,6 +47,4 @@ typedef struct timeval qemu_timeval; #endif typedef struct timespec qemu_timespec; -bool is_daemonized(void); - #endif diff --git a/qemu/include/sysemu/os-win32.h b/qemu/include/sysemu/os-win32.h index 3049cd6a..89f53631 100644 --- a/qemu/include/sysemu/os-win32.h +++ b/qemu/include/sysemu/os-win32.h @@ -85,7 +85,6 @@ struct tm *localtime_r(const time_t *timep, struct tm *result); // char *strtok_r(char *str, const char *delim, char **saveptr); static inline void os_setup_signal_handling(void) {} -static inline void os_daemonize(void) {} static inline void os_setup_post(void) {} void os_set_line_buffering(void); static inline void os_set_proc_name(const char *dummy) {} @@ -104,11 +103,6 @@ typedef struct { } qemu_timeval; int qemu_gettimeofday(qemu_timeval *tp); -static inline bool is_daemonized(void) -{ - return false; -} - static inline int os_mlock(void) { return -ENOSYS; diff --git a/qemu/m68k.h b/qemu/m68k.h index 24e2e737..61094793 100644 --- a/qemu/m68k.h +++ b/qemu/m68k.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_m68k #define qemu_clock_ptr qemu_clock_ptr_m68k #define qemu_clocks qemu_clocks_m68k -#define qemu_daemon qemu_daemon_m68k -#define qemu_event_destroy qemu_event_destroy_m68k -#define qemu_event_init qemu_event_init_m68k -#define qemu_event_reset qemu_event_reset_m68k -#define qemu_event_set qemu_event_set_m68k -#define qemu_event_wait qemu_event_wait_m68k #define qemu_fdatasync qemu_fdatasync_m68k #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_m68k #define qemu_get_cpu qemu_get_cpu_m68k @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_m68k #define qemu_log_vprintf qemu_log_vprintf_m68k #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_m68k -#define qemu_mutex_trylock qemu_mutex_trylock_m68k #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_m68k #define qemu_oom_check qemu_oom_check_m68k #define qemu_opt_del qemu_opt_del_m68k @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_m68k #define qemu_ram_unset_idstr qemu_ram_unset_idstr_m68k #define qemu_real_host_page_size qemu_real_host_page_size_m68k -#define qemu_sem_destroy qemu_sem_destroy_m68k -#define qemu_sem_init qemu_sem_init_m68k -#define qemu_sem_post qemu_sem_post_m68k -#define qemu_sem_timedwait qemu_sem_timedwait_m68k -#define qemu_sem_wait qemu_sem_wait_m68k #define qemu_set_cloexec qemu_set_cloexec_m68k #define qemu_set_tty_echo qemu_set_tty_echo_m68k #define qemu_st_helpers qemu_st_helpers_m68k diff --git a/qemu/main-loop.c b/qemu/main-loop.c deleted file mode 100644 index 821058d5..00000000 --- a/qemu/main-loop.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * QEMU System Emulator - * - * Copyright (c) 2003-2008 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/* Modified for Unicorn Engine by Nguyen Anh Quynh, 2015 */ - -#include "qemu-common.h" -#include "qemu/timer.h" -#include "qemu/main-loop.h" -#include "qemu/thread.h" -#include "qom/cpu.h" - -#include "uc_priv.h" - -#ifndef _WIN32 -#endif - -static void qemu_cpu_kick_thread(CPUState *cpu); - -void qemu_mutex_lock_iothread(struct uc_struct* uc) -{ - if (!uc->tcg_enabled(uc)) { // arch-dependent - qemu_mutex_lock(&uc->qemu_global_mutex); - } else { - if (qemu_mutex_trylock(&uc->qemu_global_mutex)) { - qemu_cpu_kick_thread(uc->cpu); - qemu_mutex_lock(&uc->qemu_global_mutex); - } - } -} - -void qemu_mutex_unlock_iothread(struct uc_struct* uc) -{ - qemu_mutex_unlock(&uc->qemu_global_mutex); -} - -static void qemu_cpu_kick_thread(CPUState *cpu) -{ -#ifndef _WIN32 - int err; - - err = pthread_kill(cpu->thread->thread, SIG_IPI); - if (err) { - fprintf(stderr, "qemu:%s: %s", __func__, strerror(err)); - exit(1); - } -#else /* _WIN32 */ - if (!qemu_thread_is_self(cpu->thread)) { - CONTEXT tcgContext; - - if (SuspendThread(cpu->hThread) == (DWORD)-1) { - fprintf(stderr, "qemu:%s: GetLastError:%lu\n", __func__, - GetLastError()); - exit(1); - } - - /* On multi-core systems, we are not sure that the thread is actually - * suspended until we can get the context. - */ - tcgContext.ContextFlags = CONTEXT_CONTROL; - while (GetThreadContext(cpu->hThread, &tcgContext) != 0) { - continue; - } - - // FIXME(danghvu): anysignal ? - // cpu_signal(0); - - if (ResumeThread(cpu->hThread) == (DWORD)-1) { - fprintf(stderr, "qemu:%s: GetLastError:%lu\n", __func__, - GetLastError()); - exit(1); - } - - CloseHandle(cpu->hThread); - cpu->hThread = 0; - } -#endif -} - - -#if 0 -static int qemu_signal_init(void) -{ - sigset_t set; - - /* - * SIG_IPI must be blocked in the main thread and must not be caught - * by sigwait() in the signal thread. Otherwise, the cpu thread will - * not catch it reliably. - */ - sigemptyset(&set); - sigaddset(&set, SIG_IPI); - sigaddset(&set, SIGIO); - sigaddset(&set, SIGALRM); - sigaddset(&set, SIGBUS); - /* SIGINT cannot be handled via signalfd, so that ^C can be used - * to interrupt QEMU when it is being run under gdb. SIGHUP and - * SIGTERM are also handled asynchronously, even though it is not - * strictly necessary, because they use the same handler as SIGINT. - */ - pthread_sigmask(SIG_BLOCK, &set, NULL); - - sigdelset(&set, SIG_IPI); - return 0; -} -#endif - -/* -static int qemu_signal_init(void) -{ - return 0; -}*/ - -/* -static int qemu_init_main_loop(void) -{ - init_clocks(); - - return qemu_signal_init(); -}*/ - - diff --git a/qemu/mips.h b/qemu/mips.h index 5913685c..367efada 100644 --- a/qemu/mips.h +++ b/qemu/mips.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_mips #define qemu_clock_ptr qemu_clock_ptr_mips #define qemu_clocks qemu_clocks_mips -#define qemu_daemon qemu_daemon_mips -#define qemu_event_destroy qemu_event_destroy_mips -#define qemu_event_init qemu_event_init_mips -#define qemu_event_reset qemu_event_reset_mips -#define qemu_event_set qemu_event_set_mips -#define qemu_event_wait qemu_event_wait_mips #define qemu_fdatasync qemu_fdatasync_mips #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_mips #define qemu_get_cpu qemu_get_cpu_mips @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_mips #define qemu_log_vprintf qemu_log_vprintf_mips #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_mips -#define qemu_mutex_trylock qemu_mutex_trylock_mips #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_mips #define qemu_oom_check qemu_oom_check_mips #define qemu_opt_del qemu_opt_del_mips @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_mips #define qemu_ram_unset_idstr qemu_ram_unset_idstr_mips #define qemu_real_host_page_size qemu_real_host_page_size_mips -#define qemu_sem_destroy qemu_sem_destroy_mips -#define qemu_sem_init qemu_sem_init_mips -#define qemu_sem_post qemu_sem_post_mips -#define qemu_sem_timedwait qemu_sem_timedwait_mips -#define qemu_sem_wait qemu_sem_wait_mips #define qemu_set_cloexec qemu_set_cloexec_mips #define qemu_set_tty_echo qemu_set_tty_echo_mips #define qemu_st_helpers qemu_st_helpers_mips diff --git a/qemu/mips64.h b/qemu/mips64.h index 0348d4b6..68c3bbd3 100644 --- a/qemu/mips64.h +++ b/qemu/mips64.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_mips64 #define qemu_clock_ptr qemu_clock_ptr_mips64 #define qemu_clocks qemu_clocks_mips64 -#define qemu_daemon qemu_daemon_mips64 -#define qemu_event_destroy qemu_event_destroy_mips64 -#define qemu_event_init qemu_event_init_mips64 -#define qemu_event_reset qemu_event_reset_mips64 -#define qemu_event_set qemu_event_set_mips64 -#define qemu_event_wait qemu_event_wait_mips64 #define qemu_fdatasync qemu_fdatasync_mips64 #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_mips64 #define qemu_get_cpu qemu_get_cpu_mips64 @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_mips64 #define qemu_log_vprintf qemu_log_vprintf_mips64 #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_mips64 -#define qemu_mutex_trylock qemu_mutex_trylock_mips64 #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_mips64 #define qemu_oom_check qemu_oom_check_mips64 #define qemu_opt_del qemu_opt_del_mips64 @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_mips64 #define qemu_ram_unset_idstr qemu_ram_unset_idstr_mips64 #define qemu_real_host_page_size qemu_real_host_page_size_mips64 -#define qemu_sem_destroy qemu_sem_destroy_mips64 -#define qemu_sem_init qemu_sem_init_mips64 -#define qemu_sem_post qemu_sem_post_mips64 -#define qemu_sem_timedwait qemu_sem_timedwait_mips64 -#define qemu_sem_wait qemu_sem_wait_mips64 #define qemu_set_cloexec qemu_set_cloexec_mips64 #define qemu_set_tty_echo qemu_set_tty_echo_mips64 #define qemu_st_helpers qemu_st_helpers_mips64 diff --git a/qemu/mips64el.h b/qemu/mips64el.h index 7ad248a8..df264f69 100644 --- a/qemu/mips64el.h +++ b/qemu/mips64el.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_mips64el #define qemu_clock_ptr qemu_clock_ptr_mips64el #define qemu_clocks qemu_clocks_mips64el -#define qemu_daemon qemu_daemon_mips64el -#define qemu_event_destroy qemu_event_destroy_mips64el -#define qemu_event_init qemu_event_init_mips64el -#define qemu_event_reset qemu_event_reset_mips64el -#define qemu_event_set qemu_event_set_mips64el -#define qemu_event_wait qemu_event_wait_mips64el #define qemu_fdatasync qemu_fdatasync_mips64el #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_mips64el #define qemu_get_cpu qemu_get_cpu_mips64el @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_mips64el #define qemu_log_vprintf qemu_log_vprintf_mips64el #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_mips64el -#define qemu_mutex_trylock qemu_mutex_trylock_mips64el #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_mips64el #define qemu_oom_check qemu_oom_check_mips64el #define qemu_opt_del qemu_opt_del_mips64el @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_mips64el #define qemu_ram_unset_idstr qemu_ram_unset_idstr_mips64el #define qemu_real_host_page_size qemu_real_host_page_size_mips64el -#define qemu_sem_destroy qemu_sem_destroy_mips64el -#define qemu_sem_init qemu_sem_init_mips64el -#define qemu_sem_post qemu_sem_post_mips64el -#define qemu_sem_timedwait qemu_sem_timedwait_mips64el -#define qemu_sem_wait qemu_sem_wait_mips64el #define qemu_set_cloexec qemu_set_cloexec_mips64el #define qemu_set_tty_echo qemu_set_tty_echo_mips64el #define qemu_st_helpers qemu_st_helpers_mips64el diff --git a/qemu/mipsel.h b/qemu/mipsel.h index c9ad269e..5f7fb03b 100644 --- a/qemu/mipsel.h +++ b/qemu/mipsel.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_mipsel #define qemu_clock_ptr qemu_clock_ptr_mipsel #define qemu_clocks qemu_clocks_mipsel -#define qemu_daemon qemu_daemon_mipsel -#define qemu_event_destroy qemu_event_destroy_mipsel -#define qemu_event_init qemu_event_init_mipsel -#define qemu_event_reset qemu_event_reset_mipsel -#define qemu_event_set qemu_event_set_mipsel -#define qemu_event_wait qemu_event_wait_mipsel #define qemu_fdatasync qemu_fdatasync_mipsel #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_mipsel #define qemu_get_cpu qemu_get_cpu_mipsel @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_mipsel #define qemu_log_vprintf qemu_log_vprintf_mipsel #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_mipsel -#define qemu_mutex_trylock qemu_mutex_trylock_mipsel #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_mipsel #define qemu_oom_check qemu_oom_check_mipsel #define qemu_opt_del qemu_opt_del_mipsel @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_mipsel #define qemu_ram_unset_idstr qemu_ram_unset_idstr_mipsel #define qemu_real_host_page_size qemu_real_host_page_size_mipsel -#define qemu_sem_destroy qemu_sem_destroy_mipsel -#define qemu_sem_init qemu_sem_init_mipsel -#define qemu_sem_post qemu_sem_post_mipsel -#define qemu_sem_timedwait qemu_sem_timedwait_mipsel -#define qemu_sem_wait qemu_sem_wait_mipsel #define qemu_set_cloexec qemu_set_cloexec_mipsel #define qemu_set_tty_echo qemu_set_tty_echo_mipsel #define qemu_st_helpers qemu_st_helpers_mipsel diff --git a/qemu/powerpc.h b/qemu/powerpc.h index 2a63de7b..5eaf6565 100644 --- a/qemu/powerpc.h +++ b/qemu/powerpc.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_powerpc #define qemu_clock_ptr qemu_clock_ptr_powerpc #define qemu_clocks qemu_clocks_powerpc -#define qemu_daemon qemu_daemon_powerpc -#define qemu_event_destroy qemu_event_destroy_powerpc -#define qemu_event_init qemu_event_init_powerpc -#define qemu_event_reset qemu_event_reset_powerpc -#define qemu_event_set qemu_event_set_powerpc -#define qemu_event_wait qemu_event_wait_powerpc #define qemu_fdatasync qemu_fdatasync_powerpc #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_powerpc #define qemu_get_cpu qemu_get_cpu_powerpc @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_powerpc #define qemu_log_vprintf qemu_log_vprintf_powerpc #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_powerpc -#define qemu_mutex_trylock qemu_mutex_trylock_powerpc #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_powerpc #define qemu_oom_check qemu_oom_check_powerpc #define qemu_opt_del qemu_opt_del_powerpc @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_powerpc #define qemu_ram_unset_idstr qemu_ram_unset_idstr_powerpc #define qemu_real_host_page_size qemu_real_host_page_size_powerpc -#define qemu_sem_destroy qemu_sem_destroy_powerpc -#define qemu_sem_init qemu_sem_init_powerpc -#define qemu_sem_post qemu_sem_post_powerpc -#define qemu_sem_timedwait qemu_sem_timedwait_powerpc -#define qemu_sem_wait qemu_sem_wait_powerpc #define qemu_set_cloexec qemu_set_cloexec_powerpc #define qemu_set_tty_echo qemu_set_tty_echo_powerpc #define qemu_st_helpers qemu_st_helpers_powerpc diff --git a/qemu/qemu-timer.c b/qemu/qemu-timer.c index a4e8eb17..80e79c67 100644 --- a/qemu/qemu-timer.c +++ b/qemu/qemu-timer.c @@ -29,9 +29,6 @@ #include "hw/hw.h" #include "qemu/timer.h" -#ifdef CONFIG_POSIX -#include -#endif #ifdef CONFIG_PPOLL #include diff --git a/qemu/sparc.h b/qemu/sparc.h index 80e9b34f..0b3fceed 100644 --- a/qemu/sparc.h +++ b/qemu/sparc.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_sparc #define qemu_clock_ptr qemu_clock_ptr_sparc #define qemu_clocks qemu_clocks_sparc -#define qemu_daemon qemu_daemon_sparc -#define qemu_event_destroy qemu_event_destroy_sparc -#define qemu_event_init qemu_event_init_sparc -#define qemu_event_reset qemu_event_reset_sparc -#define qemu_event_set qemu_event_set_sparc -#define qemu_event_wait qemu_event_wait_sparc #define qemu_fdatasync qemu_fdatasync_sparc #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_sparc #define qemu_get_cpu qemu_get_cpu_sparc @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_sparc #define qemu_log_vprintf qemu_log_vprintf_sparc #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_sparc -#define qemu_mutex_trylock qemu_mutex_trylock_sparc #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_sparc #define qemu_oom_check qemu_oom_check_sparc #define qemu_opt_del qemu_opt_del_sparc @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_sparc #define qemu_ram_unset_idstr qemu_ram_unset_idstr_sparc #define qemu_real_host_page_size qemu_real_host_page_size_sparc -#define qemu_sem_destroy qemu_sem_destroy_sparc -#define qemu_sem_init qemu_sem_init_sparc -#define qemu_sem_post qemu_sem_post_sparc -#define qemu_sem_timedwait qemu_sem_timedwait_sparc -#define qemu_sem_wait qemu_sem_wait_sparc #define qemu_set_cloexec qemu_set_cloexec_sparc #define qemu_set_tty_echo qemu_set_tty_echo_sparc #define qemu_st_helpers qemu_st_helpers_sparc diff --git a/qemu/sparc64.h b/qemu/sparc64.h index 733b59dc..a601c6c0 100644 --- a/qemu/sparc64.h +++ b/qemu/sparc64.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_sparc64 #define qemu_clock_ptr qemu_clock_ptr_sparc64 #define qemu_clocks qemu_clocks_sparc64 -#define qemu_daemon qemu_daemon_sparc64 -#define qemu_event_destroy qemu_event_destroy_sparc64 -#define qemu_event_init qemu_event_init_sparc64 -#define qemu_event_reset qemu_event_reset_sparc64 -#define qemu_event_set qemu_event_set_sparc64 -#define qemu_event_wait qemu_event_wait_sparc64 #define qemu_fdatasync qemu_fdatasync_sparc64 #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_sparc64 #define qemu_get_cpu qemu_get_cpu_sparc64 @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_sparc64 #define qemu_log_vprintf qemu_log_vprintf_sparc64 #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_sparc64 -#define qemu_mutex_trylock qemu_mutex_trylock_sparc64 #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_sparc64 #define qemu_oom_check qemu_oom_check_sparc64 #define qemu_opt_del qemu_opt_del_sparc64 @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_sparc64 #define qemu_ram_unset_idstr qemu_ram_unset_idstr_sparc64 #define qemu_real_host_page_size qemu_real_host_page_size_sparc64 -#define qemu_sem_destroy qemu_sem_destroy_sparc64 -#define qemu_sem_init qemu_sem_init_sparc64 -#define qemu_sem_post qemu_sem_post_sparc64 -#define qemu_sem_timedwait qemu_sem_timedwait_sparc64 -#define qemu_sem_wait qemu_sem_wait_sparc64 #define qemu_set_cloexec qemu_set_cloexec_sparc64 #define qemu_set_tty_echo qemu_set_tty_echo_sparc64 #define qemu_st_helpers qemu_st_helpers_sparc64 diff --git a/qemu/util/oslib-posix.c b/qemu/util/oslib-posix.c index 47e8c984..14dfb358 100644 --- a/qemu/util/oslib-posix.c +++ b/qemu/util/oslib-posix.c @@ -26,15 +26,6 @@ * THE SOFTWARE. */ -/* The following block of code temporarily renames the daemon() function so the - compiler does not see the warning associated with it in stdlib.h on OSX */ -#ifdef __APPLE__ -#define daemon qemu_fake_daemon_function -#include -#undef daemon -extern int daemon(int, int); -#endif - #if defined(__linux__) && (defined(__x86_64__) || defined(__arm__)) /* Use 2 MiB alignment so transparent hugepages can be used by KVM. Valgrind does not support alignments larger than 1 MiB, @@ -69,11 +60,6 @@ extern int daemon(int, int); #include #endif -int qemu_daemon(int nochdir, int noclose) -{ - return daemon(nochdir, noclose); -} - void *qemu_oom_check(void *ptr) { if (ptr == NULL) { diff --git a/qemu/util/qemu-thread-posix.c b/qemu/util/qemu-thread-posix.c index 78bbb75c..b77209f6 100644 --- a/qemu/util/qemu-thread-posix.c +++ b/qemu/util/qemu-thread-posix.c @@ -55,6 +55,7 @@ void qemu_mutex_destroy(QemuMutex *mutex) error_exit(err, __func__); } + void qemu_mutex_lock(QemuMutex *mutex) { int err; @@ -64,11 +65,6 @@ void qemu_mutex_lock(QemuMutex *mutex) error_exit(err, __func__); } -int qemu_mutex_trylock(QemuMutex *mutex) -{ - return pthread_mutex_trylock(&mutex->lock); -} - void qemu_mutex_unlock(QemuMutex *mutex) { int err; @@ -114,281 +110,6 @@ void qemu_cond_broadcast(QemuCond *cond) error_exit(err, __func__); } -void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) -{ - int err; - - err = pthread_cond_wait(&cond->cond, &mutex->lock); - if (err) - error_exit(err, __func__); -} - -void qemu_sem_init(QemuSemaphore *sem, int init) -{ - int rc; - -#if defined(__APPLE__) || defined(__NetBSD__) - rc = pthread_mutex_init(&sem->lock, NULL); - if (rc != 0) { - error_exit(rc, __func__); - } - rc = pthread_cond_init(&sem->cond, NULL); - if (rc != 0) { - error_exit(rc, __func__); - } - if (init < 0) { - error_exit(EINVAL, __func__); - } - sem->count = init; -#else - rc = sem_init(&sem->sem, 0, init); - if (rc < 0) { - error_exit(errno, __func__); - } -#endif -} - -void qemu_sem_destroy(QemuSemaphore *sem) -{ - int rc; - -#if defined(__APPLE__) || defined(__NetBSD__) - rc = pthread_cond_destroy(&sem->cond); - if (rc < 0) { - error_exit(rc, __func__); - } - rc = pthread_mutex_destroy(&sem->lock); - if (rc < 0) { - error_exit(rc, __func__); - } -#else - rc = sem_destroy(&sem->sem); - if (rc < 0) { - error_exit(errno, __func__); - } -#endif -} - -void qemu_sem_post(QemuSemaphore *sem) -{ - int rc; - -#if defined(__APPLE__) || defined(__NetBSD__) - pthread_mutex_lock(&sem->lock); - if (sem->count == UINT_MAX) { - rc = EINVAL; - } else { - sem->count++; - rc = pthread_cond_signal(&sem->cond); - } - pthread_mutex_unlock(&sem->lock); - if (rc != 0) { - error_exit(rc, __func__); - } -#else - rc = sem_post(&sem->sem); - if (rc < 0) { - error_exit(errno, __func__); - } -#endif -} - -static void compute_abs_deadline(struct timespec *ts, int ms) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - ts->tv_nsec = tv.tv_usec * 1000 + (ms % 1000) * 1000000; - ts->tv_sec = tv.tv_sec + ms / 1000; - if (ts->tv_nsec >= 1000000000) { - ts->tv_sec++; - ts->tv_nsec -= 1000000000; - } -} - -int qemu_sem_timedwait(QemuSemaphore *sem, int ms) -{ - int rc; - struct timespec ts; - -#if defined(__APPLE__) || defined(__NetBSD__) - rc = 0; - compute_abs_deadline(&ts, ms); - pthread_mutex_lock(&sem->lock); - while (sem->count == 0) { - rc = pthread_cond_timedwait(&sem->cond, &sem->lock, &ts); - if (rc == ETIMEDOUT) { - break; - } - if (rc != 0) { - error_exit(rc, __func__); - } - } - if (rc != ETIMEDOUT) { - --sem->count; - } - pthread_mutex_unlock(&sem->lock); - return (rc == ETIMEDOUT ? -1 : 0); -#else - if (ms <= 0) { - /* This is cheaper than sem_timedwait. */ - do { - rc = sem_trywait(&sem->sem); - } while (rc == -1 && errno == EINTR); - if (rc == -1 && errno == EAGAIN) { - return -1; - } - } else { - compute_abs_deadline(&ts, ms); - do { - rc = sem_timedwait(&sem->sem, &ts); - } while (rc == -1 && errno == EINTR); - if (rc == -1 && errno == ETIMEDOUT) { - return -1; - } - } - if (rc < 0) { - error_exit(errno, __func__); - } - return 0; -#endif -} - -void qemu_sem_wait(QemuSemaphore *sem) -{ - int rc; - -#if defined(__APPLE__) || defined(__NetBSD__) - pthread_mutex_lock(&sem->lock); - while (sem->count == 0) { - rc = pthread_cond_wait(&sem->cond, &sem->lock); - if (rc != 0) { - error_exit(rc, __func__); - } - } - --sem->count; - pthread_mutex_unlock(&sem->lock); -#else - do { - rc = sem_wait(&sem->sem); - } while (rc == -1 && errno == EINTR); - if (rc < 0) { - error_exit(errno, __func__); - } -#endif -} - -#ifdef __linux__ -#define futex(...) syscall(__NR_futex, __VA_ARGS__) - -static inline void futex_wake(QemuEvent *ev, int n) -{ - futex(ev, FUTEX_WAKE, n, NULL, NULL, 0); -} - -static inline void futex_wait(QemuEvent *ev, unsigned val) -{ - futex(ev, FUTEX_WAIT, (int) val, NULL, NULL, 0); -} -#else -static inline void futex_wake(QemuEvent *ev, int n) -{ - pthread_mutex_lock(&ev->lock); - if (n == 1) { - pthread_cond_signal(&ev->cond); - } else { - pthread_cond_broadcast(&ev->cond); - } - pthread_mutex_unlock(&ev->lock); -} - -static inline void futex_wait(QemuEvent *ev, unsigned val) -{ - pthread_mutex_lock(&ev->lock); - if (ev->value == val) { - pthread_cond_wait(&ev->cond, &ev->lock); - } - pthread_mutex_unlock(&ev->lock); -} -#endif - -/* Valid transitions: - * - free->set, when setting the event - * - busy->set, when setting the event, followed by futex_wake - * - set->free, when resetting the event - * - free->busy, when waiting - * - * set->busy does not happen (it can be observed from the outside but - * it really is set->free->busy). - * - * busy->free provably cannot happen; to enforce it, the set->free transition - * is done with an OR, which becomes a no-op if the event has concurrently - * transitioned to free or busy. - */ - -#define EV_SET 0 -#define EV_FREE 1 -#define EV_BUSY -1 - -void qemu_event_init(QemuEvent *ev, bool init) -{ -#ifndef __linux__ - pthread_mutex_init(&ev->lock, NULL); - pthread_cond_init(&ev->cond, NULL); -#endif - - ev->value = (init ? EV_SET : EV_FREE); -} - -void qemu_event_destroy(QemuEvent *ev) -{ -#ifndef __linux__ - pthread_mutex_destroy(&ev->lock); - pthread_cond_destroy(&ev->cond); -#endif -} - -void qemu_event_set(QemuEvent *ev) -{ - if (atomic_mb_read(&ev->value) != EV_SET) { - if (atomic_xchg(&ev->value, EV_SET) == EV_BUSY) { - /* There were waiters, wake them up. */ - futex_wake(ev, INT_MAX); - } - } -} - -void qemu_event_reset(QemuEvent *ev) -{ - if (atomic_mb_read(&ev->value) == EV_SET) { - /* - * If there was a concurrent reset (or even reset+wait), - * do nothing. Otherwise change EV_SET->EV_FREE. - */ - atomic_or(&ev->value, EV_FREE); - } -} - -void qemu_event_wait(QemuEvent *ev) -{ - unsigned value; - - value = atomic_mb_read(&ev->value); - if (value != EV_SET) { - if (value == EV_FREE) { - /* - * Leave the event reset and tell qemu_event_set that there - * are waiters. No need to retry, because there cannot be - * a concurent busy->free transition. After the CAS, the - * event will be either set or busy. - */ - if (atomic_cmpxchg(&ev->value, EV_FREE, EV_BUSY) == EV_SET) { - return; - } - } - futex_wait(ev, EV_BUSY); - } -} - int qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name, void *(*start_routine)(void*), void *arg, int mode) diff --git a/qemu/util/qemu-thread-win32.c b/qemu/util/qemu-thread-win32.c index 97ba69c6..472eadef 100644 --- a/qemu/util/qemu-thread-win32.c +++ b/qemu/util/qemu-thread-win32.c @@ -53,18 +53,6 @@ void qemu_mutex_lock(QemuMutex *mutex) mutex->owner = GetCurrentThreadId(); } -int qemu_mutex_trylock(QemuMutex *mutex) -{ - int owned; - - owned = TryEnterCriticalSection(&mutex->lock); - if (owned) { - assert(mutex->owner == 0); - mutex->owner = GetCurrentThreadId(); - } - return !owned; -} - void qemu_mutex_unlock(QemuMutex *mutex) { assert(mutex->owner == GetCurrentThreadId()); @@ -159,103 +147,6 @@ void qemu_cond_broadcast(QemuCond *cond) WaitForSingleObject(cond->continue_event, INFINITE); } -void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) -{ - /* - * This access is protected under the mutex. - */ - cond->waiters++; - - /* - * Unlock external mutex and wait for signal. - * NOTE: we've held mutex locked long enough to increment - * waiters count above, so there's no problem with - * leaving mutex unlocked before we wait on semaphore. - */ - qemu_mutex_unlock(mutex); - WaitForSingleObject(cond->sema, INFINITE); - - /* Now waiters must rendez-vous with the signaling thread and - * let it continue. For cond_broadcast this has heavy contention - * and triggers thundering herd. So goes life. - * - * Decrease waiters count. The mutex is not taken, so we have - * to do this atomically. - * - * All waiters contend for the mutex at the end of this function - * until the signaling thread relinquishes it. To ensure - * each waiter consumes exactly one slice of the semaphore, - * the signaling thread stops until it is told by the last - * waiter that it can go on. - */ - if (InterlockedDecrement(&cond->waiters) == cond->target) { - SetEvent(cond->continue_event); - } - - qemu_mutex_lock(mutex); -} - -void qemu_sem_init(QemuSemaphore *sem, int init) -{ - /* Manual reset. */ - sem->sema = CreateSemaphore(NULL, init, LONG_MAX, NULL); -} - -void qemu_sem_destroy(QemuSemaphore *sem) -{ - CloseHandle(sem->sema); -} - -void qemu_sem_post(QemuSemaphore *sem) -{ - ReleaseSemaphore(sem->sema, 1, NULL); -} - -int qemu_sem_timedwait(QemuSemaphore *sem, int ms) -{ - int rc = WaitForSingleObject(sem->sema, ms); - if (rc == WAIT_OBJECT_0) { - return 0; - } - if (rc != WAIT_TIMEOUT) { - error_exit(GetLastError(), __func__); - } - return -1; -} - -void qemu_sem_wait(QemuSemaphore *sem) -{ - if (WaitForSingleObject(sem->sema, INFINITE) != WAIT_OBJECT_0) { - error_exit(GetLastError(), __func__); - } -} - -void qemu_event_init(QemuEvent *ev, bool init) -{ - /* Manual reset. */ - ev->event = CreateEvent(NULL, TRUE, init, NULL); -} - -void qemu_event_destroy(QemuEvent *ev) -{ - CloseHandle(ev->event); -} - -void qemu_event_set(QemuEvent *ev) -{ - SetEvent(ev->event); -} - -void qemu_event_reset(QemuEvent *ev) -{ - ResetEvent(ev->event); -} - -void qemu_event_wait(QemuEvent *ev) -{ - WaitForSingleObject(ev->event, INFINITE); -} - struct QemuThreadData { /* Passed to win32_start_routine. */ void *(*start_routine)(void *); diff --git a/qemu/x86_64.h b/qemu/x86_64.h index 7e5c9580..0ae4de7e 100644 --- a/qemu/x86_64.h +++ b/qemu/x86_64.h @@ -2413,12 +2413,6 @@ #define qemu_clock_get_us qemu_clock_get_us_x86_64 #define qemu_clock_ptr qemu_clock_ptr_x86_64 #define qemu_clocks qemu_clocks_x86_64 -#define qemu_daemon qemu_daemon_x86_64 -#define qemu_event_destroy qemu_event_destroy_x86_64 -#define qemu_event_init qemu_event_init_x86_64 -#define qemu_event_reset qemu_event_reset_x86_64 -#define qemu_event_set qemu_event_set_x86_64 -#define qemu_event_wait qemu_event_wait_x86_64 #define qemu_fdatasync qemu_fdatasync_x86_64 #define qemu_flush_coalesced_mmio_buffer qemu_flush_coalesced_mmio_buffer_x86_64 #define qemu_get_cpu qemu_get_cpu_x86_64 @@ -2438,7 +2432,6 @@ #define qemu_loglevel_mask qemu_loglevel_mask_x86_64 #define qemu_log_vprintf qemu_log_vprintf_x86_64 #define qemu_mutex_lock_ramlist qemu_mutex_lock_ramlist_x86_64 -#define qemu_mutex_trylock qemu_mutex_trylock_x86_64 #define qemu_mutex_unlock_ramlist qemu_mutex_unlock_ramlist_x86_64 #define qemu_oom_check qemu_oom_check_x86_64 #define qemu_opt_del qemu_opt_del_x86_64 @@ -2497,11 +2490,6 @@ #define qemu_ram_setup_dump qemu_ram_setup_dump_x86_64 #define qemu_ram_unset_idstr qemu_ram_unset_idstr_x86_64 #define qemu_real_host_page_size qemu_real_host_page_size_x86_64 -#define qemu_sem_destroy qemu_sem_destroy_x86_64 -#define qemu_sem_init qemu_sem_init_x86_64 -#define qemu_sem_post qemu_sem_post_x86_64 -#define qemu_sem_timedwait qemu_sem_timedwait_x86_64 -#define qemu_sem_wait qemu_sem_wait_x86_64 #define qemu_set_cloexec qemu_set_cloexec_x86_64 #define qemu_set_tty_echo qemu_set_tty_echo_x86_64 #define qemu_st_helpers qemu_st_helpers_x86_64