1 /* 2 * win32 specific declarations 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen (at) redhat.com> 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal 9 * in the Software without restriction, including without limitation the rights 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 * THE SOFTWARE. 24 */ 25 26 #ifndef QEMU_OS_WIN32_H 27 #define QEMU_OS_WIN32_H 28 29 #define socket_close winsock2_socket_close3 30 31 #include <winsock2.h> 32 #include <windows.h> 33 34 #undef socket_close 35 36 /* Workaround for older versions of MinGW. */ 37 #ifndef ECONNREFUSED 38 # define ECONNREFUSED WSAECONNREFUSED 39 #endif 40 #ifndef EINPROGRESS 41 # define EINPROGRESS WSAEINPROGRESS 42 #endif 43 #ifndef EHOSTUNREACH 44 # define EHOSTUNREACH WSAEHOSTUNREACH 45 #endif 46 #ifndef EINTR 47 # define EINTR WSAEINTR 48 #endif 49 #ifndef EINPROGRESS 50 # define EINPROGRESS WSAEINPROGRESS 51 #endif 52 #ifndef ENETUNREACH 53 # define ENETUNREACH WSAENETUNREACH 54 #endif 55 #ifndef ENOTCONN 56 # define ENOTCONN WSAENOTCONN 57 #endif 58 #ifndef EWOULDBLOCK 59 # define EWOULDBLOCK WSAEWOULDBLOCK 60 #endif 61 62 #if defined(_WIN64) 63 /* On w64, setjmp is implemented by _setjmp which needs a second parameter. 64 * If this parameter is NULL, longjump does no stack unwinding. 65 * That is what we need for QEMU. Passing the value of register rsp (default) 66 * lets longjmp try a stack unwinding which will crash with generated code. */ 67 # undef setjmp 68 # define setjmp(env) _setjmp(env, NULL) 69 #endif 70 /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify 71 * "longjmp and don't touch the signal masks". Since we know that the 72 * savemask parameter will always be zero we can safely define these 73 * in terms of setjmp/longjmp on Win32. 74 */ 75 #define sigjmp_buf jmp_buf 76 #define sigsetjmp(env, savemask) setjmp(env) 77 #define siglongjmp(env, val) longjmp(env, val) 78 79 /* Declaration of ffs() is missing in MinGW's strings.h. */ 80 int ffs(int i); 81 82 /* Missing POSIX functions. Don't use MinGW-w64 macros. */ 83 #undef gmtime_r 84 struct tm *gmtime_r(const time_t *timep, struct tm *result); 85 #undef localtime_r 86 struct tm *localtime_r(const time_t *timep, struct tm *result); 87 88 char *strtok_r(char *str, const char *delim, char **saveptr); 89 90 /* Polling handling */ 91 92 /* return TRUE if no sleep should be done afterwards */ 93 typedef int PollingFunc(void *opaque); 94 95 int qemu_add_polling_cb(PollingFunc *func, void *opaque); 96 void qemu_del_polling_cb(PollingFunc *func, void *opaque); 97 98 /* Wait objects handling */ 99 typedef void WaitObjectFunc(void *opaque); 100 101 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); 102 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); 103 104 void os_host_main_loop_wait(int *timeout); 105 106 static inline void os_setup_signal_handling(void) {} 107 static inline void os_daemonize(void) {} 108 static inline void os_setup_post(void) {} 109 void os_set_line_buffering(void); 110 static inline void os_set_proc_name(const char *dummy) {} 111 112 #if !defined(EPROTONOSUPPORT) 113 # define EPROTONOSUPPORT EINVAL 114 #endif 115 116 int setenv(const char *name, const char *value, int overwrite); 117 118 typedef struct { 119 long tv_sec; 120 long tv_usec; 121 } qemu_timeval; 122 int qemu_gettimeofday(qemu_timeval *tp); 123 124 static inline bool is_daemonized(void) 125 { 126 return false; 127 } 128 129 static inline int os_mlock(void) 130 { 131 return -ENOSYS; 132 } 133 134 #endif 135