2 * win32 specific declarations
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@redhat.com>
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
26 #ifndef QEMU_OS_WIN32_H
27 #define QEMU_OS_WIN32_H
37 * Fallback definitions of things we need in afunix.h, if not available from
38 * the used Windows SDK or MinGW headers.
40 #define UNIX_PATH_MAX 108
42 typedef struct sockaddr_un
{
43 ADDRESS_FAMILY sun_family
;
44 char sun_path
[UNIX_PATH_MAX
];
45 } SOCKADDR_UN
, *PSOCKADDR_UN
;
47 #define SIO_AF_UNIX_GETPEERPID _WSAIOR(IOC_VENDOR, 256)
54 #if defined(__aarch64__)
56 * On windows-arm64, setjmp is available in only one variant, and longjmp always
57 * does stack unwinding. This crash with generated code.
58 * Thus, we use another implementation of setjmp (not windows one), coming from
59 * mingw, which never performs stack unwinding.
64 * These functions are not declared in setjmp.h because __aarch64__ defines
65 * setjmp to _setjmpex instead. However, they are still defined in libmingwex.a,
66 * which gets linked automatically.
68 extern int __mingw_setjmp(jmp_buf);
69 extern void __attribute__((noreturn
)) __mingw_longjmp(jmp_buf, int);
70 #define setjmp(env) __mingw_setjmp(env)
71 #define longjmp(env, val) __mingw_longjmp(env, val)
74 * On windows-x64, setjmp is implemented by _setjmp which needs a second parameter.
75 * If this parameter is NULL, longjump does no stack unwinding.
76 * That is what we need for QEMU. Passing the value of register rsp (default)
77 * lets longjmp try a stack unwinding which will crash with generated code.
80 # define setjmp(env) _setjmp(env, NULL)
81 #endif /* __aarch64__ */
82 /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
83 * "longjmp and don't touch the signal masks". Since we know that the
84 * savemask parameter will always be zero we can safely define these
85 * in terms of setjmp/longjmp on Win32.
87 #define sigjmp_buf jmp_buf
88 #define sigsetjmp(env, savemask) setjmp(env)
89 #define siglongjmp(env, val) longjmp(env, val)
91 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
92 #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
94 struct tm
*gmtime_r(const time_t *timep
, struct tm
*result
);
96 struct tm
*localtime_r(const time_t *timep
, struct tm
*result
);
97 #endif /* _POSIX_THREAD_SAFE_FUNCTIONS */
99 static inline void os_setup_signal_handling(void) {}
100 static inline void os_daemonize(void) {}
101 static inline void os_setup_post(void) {}
102 static inline void os_set_proc_name(const char *dummy
) {}
103 static inline int os_parse_cmd_args(int index
, const char *optarg
) { return -1; }
104 void os_set_line_buffering(void);
105 void os_setup_early_signal_handling(void);
107 int getpagesize(void);
109 #if !defined(EPROTONOSUPPORT)
110 # define EPROTONOSUPPORT EINVAL
113 static inline int os_set_daemonize(bool d
)
121 static inline bool is_daemonized(void)
126 static inline int os_mlock(void)
131 #define fsync _commit
134 # define lseek _lseeki64
137 int qemu_ftruncate64(int, int64_t);
139 #if !defined(ftruncate)
140 # define ftruncate qemu_ftruncate64
143 static inline char *realpath(const char *path
, char *resolved_path
)
145 _fullpath(resolved_path
, path
, _MAX_PATH
);
146 return resolved_path
;
150 * Older versions of MinGW do not import _lock_file and _unlock_file properly.
151 * This was fixed for v6.0.0 with commit b48e3ac8969d.
153 static inline void qemu_flockfile(FILE *f
)
155 #ifdef HAVE__LOCK_FILE
160 static inline void qemu_funlockfile(FILE *f
)
162 #ifdef HAVE__LOCK_FILE
167 /* We wrap all the sockets functions so that we can
168 * set errno based on WSAGetLastError()
172 #define connect qemu_connect_wrap
173 int qemu_connect_wrap(int sockfd
, const struct sockaddr
*addr
,
177 #define listen qemu_listen_wrap
178 int qemu_listen_wrap(int sockfd
, int backlog
);
181 #define bind qemu_bind_wrap
182 int qemu_bind_wrap(int sockfd
, const struct sockaddr
*addr
,
186 #define socket qemu_socket_wrap
187 int qemu_socket_wrap(int domain
, int type
, int protocol
);
190 #define accept qemu_accept_wrap
191 int qemu_accept_wrap(int sockfd
, struct sockaddr
*addr
,
195 #define shutdown qemu_shutdown_wrap
196 int qemu_shutdown_wrap(int sockfd
, int how
);
199 #define ioctlsocket qemu_ioctlsocket_wrap
200 int qemu_ioctlsocket_wrap(int fd
, int req
, void *val
);
203 #define closesocket qemu_closesocket_wrap
204 int qemu_closesocket_wrap(int fd
);
207 #define getsockopt qemu_getsockopt_wrap
208 int qemu_getsockopt_wrap(int sockfd
, int level
, int optname
,
209 void *optval
, socklen_t
*optlen
);
212 #define setsockopt qemu_setsockopt_wrap
213 int qemu_setsockopt_wrap(int sockfd
, int level
, int optname
,
214 const void *optval
, socklen_t optlen
);
217 #define getpeername qemu_getpeername_wrap
218 int qemu_getpeername_wrap(int sockfd
, struct sockaddr
*addr
,
222 #define getsockname qemu_getsockname_wrap
223 int qemu_getsockname_wrap(int sockfd
, struct sockaddr
*addr
,
227 #define send qemu_send_wrap
228 ssize_t
qemu_send_wrap(int sockfd
, const void *buf
, size_t len
, int flags
);
231 #define sendto qemu_sendto_wrap
232 ssize_t
qemu_sendto_wrap(int sockfd
, const void *buf
, size_t len
, int flags
,
233 const struct sockaddr
*addr
, socklen_t addrlen
);
236 #define recv qemu_recv_wrap
237 ssize_t
qemu_recv_wrap(int sockfd
, void *buf
, size_t len
, int flags
);
240 #define recvfrom qemu_recvfrom_wrap
241 ssize_t
qemu_recvfrom_wrap(int sockfd
, void *buf
, size_t len
, int flags
,
242 struct sockaddr
*addr
, socklen_t
*addrlen
);