From 3be5125d0060806a09eab78fea93f0eb9510ca75 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sat, 17 Oct 2015 10:50:30 -0700 Subject: [PATCH] slirp: Add windows build support for MinGW --- makefile | 4 ++++ slirp/simh/README | 16 +++++++++++++++ slirp/simh/config-host.h | 4 +++- slirp/simh/glib_qemu_stubs.c | 2 ++ slirp/simh/qemu/sysemu/os-win32.h | 28 ------------------------- slirp/simh/qemu/thread-win32.h | 34 +++++++++++++++++++++++++++++++ slirp/simh/sim_slirp.c | 4 ++-- slirp/slirp.h | 3 +++ slirp/slirp_config.h | 2 +- 9 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 slirp/simh/README create mode 100644 slirp/simh/qemu/thread-win32.h diff --git a/makefile b/makefile index 70d7d746..22ddd673 100644 --- a/makefile +++ b/makefile @@ -801,6 +801,10 @@ else OS_LDFLAGS += -lpcreposix -lpcre -L../windows-build/PCRE/lib/ $(info using libpcreposix: $(abspath ../windows-build/PCRE/lib/pcreposix.a) $(abspath ../windows-build/PCRE/include/pcreposix.h)) endif + ifeq (slirp,slirp) + NETWORK_OPT += -Islirp -Islirp/simh -Islirp/simh/qemu -DHAVE_SLIRP_NETWORK slirp/*.c slirp/simh/*.c -lIphlpapi + NETWORK_LAN_FEATURES += NAT(SLiRP) + endif endif endif # Win32 (via MinGW) ifneq (,$(GIT_COMMIT_ID)) diff --git a/slirp/simh/README b/slirp/simh/README new file mode 100644 index 00000000..3a484230 --- /dev/null +++ b/slirp/simh/README @@ -0,0 +1,16 @@ +The files in and below this directory are the necessary glue and stubs +to allow the effectively unmodified qemu slirp code to be used in simh +as a network connection mechanism. + +Most of the include files here started from related files in the qemu +include directories and have been chopped up and tweaked as necessary +so that the slirp code can be used outside of qemu. + +Slirp depends on a small set of capabilities from glib (GArrays mostly). + +All of the other include files exist so that the references in the +slirp code don't have to be modified. + +- Mark Pizzolato + + diff --git a/slirp/simh/config-host.h b/slirp/simh/config-host.h index 80f235e2..67050469 100644 --- a/slirp/simh/config-host.h +++ b/slirp/simh/config-host.h @@ -4,7 +4,7 @@ #include #include #include -#ifdef _MSC_VER +#ifdef _WIN32 #include #else typedef int SOCKET; @@ -24,8 +24,10 @@ int qemu_recv (int s, void *buf, size_t len, int flags); #define snprintf _snprintf #define strcasecmp stricmp #else +#ifndef _WIN32 #define CONFIG_IOVEC 1 #endif +#endif #define register_savevm(p1, p2, p3, p4, p5, p6, p7) #define unregister_savevm(p1, p2, p3) #define qemu_put_be16(p1, p2) diff --git a/slirp/simh/glib_qemu_stubs.c b/slirp/simh/glib_qemu_stubs.c index 7f394830..f63cdf57 100644 --- a/slirp/simh/glib_qemu_stubs.c +++ b/slirp/simh/glib_qemu_stubs.c @@ -254,7 +254,9 @@ slirp_remque(void *a) ((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link; element->qh_rlink = NULL; } +#endif +#if defined(_WIN32) int inet_aton(const char *arg, struct in_addr *addr) { diff --git a/slirp/simh/qemu/sysemu/os-win32.h b/slirp/simh/qemu/sysemu/os-win32.h index 6e3a60ae..09122d6e 100644 --- a/slirp/simh/qemu/sysemu/os-win32.h +++ b/slirp/simh/qemu/sysemu/os-win32.h @@ -109,32 +109,4 @@ 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; -} - -#define fsync _commit - -#if !defined(lseek) -# define lseek _lseeki64 -#endif - -int qemu_ftruncate64(int, int64_t); - -#if !defined(ftruncate) -# define ftruncate qemu_ftruncate64 -#endif - -static inline char *realpath(const char *path, char *resolved_path) -{ - _fullpath(resolved_path, path, _MAX_PATH); - return resolved_path; -} - #endif diff --git a/slirp/simh/qemu/thread-win32.h b/slirp/simh/qemu/thread-win32.h new file mode 100644 index 00000000..385ff5f7 --- /dev/null +++ b/slirp/simh/qemu/thread-win32.h @@ -0,0 +1,34 @@ +#ifndef __QEMU_THREAD_WIN32_H +#define __QEMU_THREAD_WIN32_H 1 +#include "windows.h" + +struct QemuMutex { + CRITICAL_SECTION lock; + LONG owner; +}; + +struct QemuCond { + LONG waiters, target; + HANDLE sema; + HANDLE continue_event; +}; + +struct QemuSemaphore { + HANDLE sema; +}; + +struct QemuEvent { + int value; + HANDLE event; +}; + +typedef struct QemuThreadData QemuThreadData; +struct QemuThread { + QemuThreadData *data; + unsigned tid; +}; + +/* Only valid for joinable threads. */ +HANDLE qemu_thread_get_handle(QemuThread *thread); + +#endif diff --git a/slirp/simh/sim_slirp.c b/slirp/simh/sim_slirp.c index d89090b9..17b97f8c 100644 --- a/slirp/simh/sim_slirp.c +++ b/slirp/simh/sim_slirp.c @@ -60,7 +60,7 @@ struct redir_tcp_udp { static int _parse_redirect_port (struct redir_tcp_udp **head, char *buff, int is_udp) { -u_int32_t inaddr = 0; +uint32 inaddr = 0; int port = 0; int lport = 0; char *ipaddrstr = NULL; @@ -550,7 +550,7 @@ for (i = 0; i < pollfds->len; i++) { int sim_slirp_select (SLIRP *slirp, int ms_timeout) { int select_ret = 0; -uint32_t slirp_timeout = ms_timeout; +uint32 slirp_timeout = ms_timeout; struct timeval timeout; fd_set rfds, wfds, xfds; fd_set save_rfds, save_wfds, save_xfds; diff --git a/slirp/slirp.h b/slirp/slirp.h index 33db9f58..b9bc749a 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -5,6 +5,9 @@ #include "slirp_config.h" #ifdef _WIN32 +#ifndef _MSC_VER +# include +#endif typedef char *caddr_t; diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h index 9a72f8af..c06f80bf 100644 --- a/slirp/slirp_config.h +++ b/slirp/slirp_config.h @@ -52,7 +52,7 @@ #undef DUMMY_PPP /* Define if you have unistd.h */ -#ifndef _WIN32 +#ifndef _MSC_VER #define HAVE_UNISTD_H #endif