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)
55 /* On w64, setjmp is implemented by _setjmp which needs a second parameter.
56 * If this parameter is NULL, longjump does no stack unwinding.
57 * That is what we need for QEMU. Passing the value of register rsp (default)
58 * lets longjmp try a stack unwinding which will crash with generated code. */
60 # define setjmp(env) _setjmp(env, NULL)
62 /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
63 * "longjmp and don't touch the signal masks". Since we know that the
64 * savemask parameter will always be zero we can safely define these
65 * in terms of setjmp/longjmp on Win32.
67 #define sigjmp_buf jmp_buf
68 #define sigsetjmp(env, savemask) setjmp(env)
69 #define siglongjmp(env, val) longjmp(env, val)
71 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
72 #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
74 struct tm
*gmtime_r(const time_t *timep
, struct tm
*result
);
76 struct tm
*localtime_r(const time_t *timep
, struct tm
*result
);
77 #endif /* _POSIX_THREAD_SAFE_FUNCTIONS */
79 static inline void os_setup_signal_handling(void) {}
80 static inline void os_daemonize(void) {}
81 static inline void os_setup_post(void) {}
82 static inline void os_set_proc_name(const char *dummy
) {}
83 static inline int os_parse_cmd_args(int index
, const char *optarg
) { return -1; }
84 void os_set_line_buffering(void);
85 void os_setup_early_signal_handling(void);
87 int getpagesize(void);
89 #if !defined(EPROTONOSUPPORT)
90 # define EPROTONOSUPPORT EINVAL
93 static inline int os_set_daemonize(bool d
)
101 static inline bool is_daemonized(void)
106 static inline int os_mlock(void)
111 #define fsync _commit
114 # define lseek _lseeki64
117 int qemu_ftruncate64(int, int64_t);
119 #if !defined(ftruncate)
120 # define ftruncate qemu_ftruncate64
123 static inline char *realpath(const char *path
, char *resolved_path
)
125 _fullpath(resolved_path
, path
, _MAX_PATH
);
126 return resolved_path
;
130 * Older versions of MinGW do not import _lock_file and _unlock_file properly.
131 * This was fixed for v6.0.0 with commit b48e3ac8969d.
133 static inline void qemu_flockfile(FILE *f
)
135 #ifdef HAVE__LOCK_FILE
140 static inline void qemu_funlockfile(FILE *f
)
142 #ifdef HAVE__LOCK_FILE
147 /* We wrap all the sockets functions so that we can
148 * set errno based on WSAGetLastError()
152 #define connect qemu_connect_wrap
153 int qemu_connect_wrap(int sockfd
, const struct sockaddr
*addr
,
157 #define listen qemu_listen_wrap
158 int qemu_listen_wrap(int sockfd
, int backlog
);
161 #define bind qemu_bind_wrap
162 int qemu_bind_wrap(int sockfd
, const struct sockaddr
*addr
,
166 #define socket qemu_socket_wrap
167 int qemu_socket_wrap(int domain
, int type
, int protocol
);
170 #define accept qemu_accept_wrap
171 int qemu_accept_wrap(int sockfd
, struct sockaddr
*addr
,
175 #define shutdown qemu_shutdown_wrap
176 int qemu_shutdown_wrap(int sockfd
, int how
);
179 #define ioctlsocket qemu_ioctlsocket_wrap
180 int qemu_ioctlsocket_wrap(int fd
, int req
, void *val
);
183 #define closesocket qemu_closesocket_wrap
184 int qemu_closesocket_wrap(int fd
);
187 #define getsockopt qemu_getsockopt_wrap
188 int qemu_getsockopt_wrap(int sockfd
, int level
, int optname
,
189 void *optval
, socklen_t
*optlen
);
192 #define setsockopt qemu_setsockopt_wrap
193 int qemu_setsockopt_wrap(int sockfd
, int level
, int optname
,
194 const void *optval
, socklen_t optlen
);
197 #define getpeername qemu_getpeername_wrap
198 int qemu_getpeername_wrap(int sockfd
, struct sockaddr
*addr
,
202 #define getsockname qemu_getsockname_wrap
203 int qemu_getsockname_wrap(int sockfd
, struct sockaddr
*addr
,
207 #define send qemu_send_wrap
208 ssize_t
qemu_send_wrap(int sockfd
, const void *buf
, size_t len
, int flags
);
211 #define sendto qemu_sendto_wrap
212 ssize_t
qemu_sendto_wrap(int sockfd
, const void *buf
, size_t len
, int flags
,
213 const struct sockaddr
*addr
, socklen_t addrlen
);
216 #define recv qemu_recv_wrap
217 ssize_t
qemu_recv_wrap(int sockfd
, void *buf
, size_t len
, int flags
);
220 #define recvfrom qemu_recvfrom_wrap
221 ssize_t
qemu_recvfrom_wrap(int sockfd
, void *buf
, size_t len
, int flags
,
222 struct sockaddr
*addr
, socklen_t
*addrlen
);