]>
Commit | Line | Data |
---|---|---|
39626c03 JS |
1 | /* |
2 | * win32 specific declarations | |
3 | * | |
4 | * Copyright (c) 2003-2008 Fabrice Bellard | |
5 | * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@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 | ||
082b5557 | 29 | #include <winsock2.h> |
1834ed3a | 30 | #include <windows.h> |
a2d96af4 | 31 | #include <ws2tcpip.h> |
f5fd677a | 32 | #include "qemu/typedefs.h" |
082b5557 | 33 | |
d409373b BM |
34 | #ifdef HAVE_AFUNIX_H |
35 | #include <afunix.h> | |
36 | #else | |
37 | /* | |
38 | * Fallback definitions of things we need in afunix.h, if not available from | |
39 | * the used Windows SDK or MinGW headers. | |
40 | */ | |
41 | #define UNIX_PATH_MAX 108 | |
42 | ||
43 | typedef struct sockaddr_un { | |
44 | ADDRESS_FAMILY sun_family; | |
45 | char sun_path[UNIX_PATH_MAX]; | |
46 | } SOCKADDR_UN, *PSOCKADDR_UN; | |
47 | ||
48 | #define SIO_AF_UNIX_GETPEERPID _WSAIOR(IOC_VENDOR, 256) | |
49 | #endif | |
50 | ||
415a9fb8 PM |
51 | #ifdef __cplusplus |
52 | extern "C" { | |
53 | #endif | |
54 | ||
dbd672c8 PB |
55 | #if defined(__aarch64__) |
56 | /* | |
57 | * On windows-arm64, setjmp is available in only one variant, and longjmp always | |
58 | * does stack unwinding. This crash with generated code. | |
59 | * Thus, we use another implementation of setjmp (not windows one), coming from | |
60 | * mingw, which never performs stack unwinding. | |
61 | */ | |
62 | #undef setjmp | |
63 | #undef longjmp | |
64 | /* | |
65 | * These functions are not declared in setjmp.h because __aarch64__ defines | |
66 | * setjmp to _setjmpex instead. However, they are still defined in libmingwex.a, | |
67 | * which gets linked automatically. | |
68 | */ | |
69 | extern int __mingw_setjmp(jmp_buf); | |
70 | extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int); | |
71 | #define setjmp(env) __mingw_setjmp(env) | |
72 | #define longjmp(env, val) __mingw_longjmp(env, val) | |
73 | #elif defined(_WIN64) | |
74 | /* | |
75 | * On windows-x64, setjmp is implemented by _setjmp which needs a second parameter. | |
5cf6dd51 SW |
76 | * If this parameter is NULL, longjump does no stack unwinding. |
77 | * That is what we need for QEMU. Passing the value of register rsp (default) | |
dbd672c8 PB |
78 | * lets longjmp try a stack unwinding which will crash with generated code. |
79 | */ | |
5cf6dd51 SW |
80 | # undef setjmp |
81 | # define setjmp(env) _setjmp(env, NULL) | |
dbd672c8 | 82 | #endif /* __aarch64__ */ |
6ab7e546 PM |
83 | /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify |
84 | * "longjmp and don't touch the signal masks". Since we know that the | |
85 | * savemask parameter will always be zero we can safely define these | |
86 | * in terms of setjmp/longjmp on Win32. | |
87 | */ | |
88 | #define sigjmp_buf jmp_buf | |
89 | #define sigsetjmp(env, savemask) setjmp(env) | |
90 | #define siglongjmp(env, val) longjmp(env, val) | |
5cf6dd51 | 91 | |
d3e8f957 | 92 | /* Missing POSIX functions. Don't use MinGW-w64 macros. */ |
7c3afc85 | 93 | #ifndef _POSIX_THREAD_SAFE_FUNCTIONS |
d3e8f957 SW |
94 | #undef gmtime_r |
95 | struct tm *gmtime_r(const time_t *timep, struct tm *result); | |
96 | #undef localtime_r | |
97 | struct tm *localtime_r(const time_t *timep, struct tm *result); | |
7c3afc85 | 98 | #endif /* _POSIX_THREAD_SAFE_FUNCTIONS */ |
d3e8f957 | 99 | |
8d963e6a | 100 | static inline void os_setup_signal_handling(void) {} |
eb505be1 JS |
101 | static inline void os_daemonize(void) {} |
102 | static inline void os_setup_post(void) {} | |
ce798cf2 | 103 | static inline void os_set_proc_name(const char *dummy) {} |
327adeec MAL |
104 | static inline int os_parse_cmd_args(int index, const char *optarg) { return -1; } |
105 | void os_set_line_buffering(void); | |
106 | void os_setup_early_signal_handling(void); | |
8d963e6a | 107 | |
a28c2f2d | 108 | int getpagesize(void); |
38183310 | 109 | |
5635efc3 SW |
110 | #if !defined(EPROTONOSUPPORT) |
111 | # define EPROTONOSUPPORT EINVAL | |
112 | #endif | |
113 | ||
f22ac472 HR |
114 | static inline int os_set_daemonize(bool d) |
115 | { | |
116 | if (d) { | |
117 | return -ENOTSUP; | |
118 | } | |
119 | return 0; | |
120 | } | |
121 | ||
995ee2bf HM |
122 | static inline bool is_daemonized(void) |
123 | { | |
124 | return false; | |
125 | } | |
126 | ||
888a6bc6 SM |
127 | static inline int os_mlock(void) |
128 | { | |
129 | return -ENOSYS; | |
130 | } | |
131 | ||
1aad8104 PM |
132 | #define fsync _commit |
133 | ||
134 | #if !defined(lseek) | |
135 | # define lseek _lseeki64 | |
136 | #endif | |
137 | ||
138 | int qemu_ftruncate64(int, int64_t); | |
139 | ||
140 | #if !defined(ftruncate) | |
141 | # define ftruncate qemu_ftruncate64 | |
142 | #endif | |
143 | ||
144 | static inline char *realpath(const char *path, char *resolved_path) | |
145 | { | |
146 | _fullpath(resolved_path, path, _MAX_PATH); | |
147 | return resolved_path; | |
148 | } | |
149 | ||
6391c772 RH |
150 | /* |
151 | * Older versions of MinGW do not import _lock_file and _unlock_file properly. | |
152 | * This was fixed for v6.0.0 with commit b48e3ac8969d. | |
1ee73216 | 153 | */ |
1ee73216 RH |
154 | static inline void qemu_flockfile(FILE *f) |
155 | { | |
6391c772 RH |
156 | #ifdef HAVE__LOCK_FILE |
157 | _lock_file(f); | |
158 | #endif | |
1ee73216 RH |
159 | } |
160 | ||
161 | static inline void qemu_funlockfile(FILE *f) | |
162 | { | |
6391c772 RH |
163 | #ifdef HAVE__LOCK_FILE |
164 | _unlock_file(f); | |
165 | #endif | |
1ee73216 | 166 | } |
a2d96af4 | 167 | |
f5fd677a | 168 | /* Helper for WSAEventSelect, to report errors */ |
abe34282 | 169 | bool qemu_socket_select(int sockfd, WSAEVENT hEventObject, |
f5fd677a MAL |
170 | long lNetworkEvents, Error **errp); |
171 | ||
abe34282 | 172 | bool qemu_socket_unselect(int sockfd, Error **errp); |
a4aafea2 | 173 | |
a2d96af4 DB |
174 | /* We wrap all the sockets functions so that we can |
175 | * set errno based on WSAGetLastError() | |
176 | */ | |
177 | ||
25657fc6 MAL |
178 | #undef close |
179 | #define close qemu_close_wrap | |
180 | int qemu_close_wrap(int fd); | |
181 | ||
a2d96af4 DB |
182 | #undef connect |
183 | #define connect qemu_connect_wrap | |
184 | int qemu_connect_wrap(int sockfd, const struct sockaddr *addr, | |
185 | socklen_t addrlen); | |
186 | ||
187 | #undef listen | |
188 | #define listen qemu_listen_wrap | |
189 | int qemu_listen_wrap(int sockfd, int backlog); | |
190 | ||
191 | #undef bind | |
192 | #define bind qemu_bind_wrap | |
193 | int qemu_bind_wrap(int sockfd, const struct sockaddr *addr, | |
194 | socklen_t addrlen); | |
195 | ||
196 | #undef socket | |
197 | #define socket qemu_socket_wrap | |
198 | int qemu_socket_wrap(int domain, int type, int protocol); | |
199 | ||
200 | #undef accept | |
201 | #define accept qemu_accept_wrap | |
202 | int qemu_accept_wrap(int sockfd, struct sockaddr *addr, | |
203 | socklen_t *addrlen); | |
204 | ||
205 | #undef shutdown | |
206 | #define shutdown qemu_shutdown_wrap | |
207 | int qemu_shutdown_wrap(int sockfd, int how); | |
208 | ||
209 | #undef ioctlsocket | |
210 | #define ioctlsocket qemu_ioctlsocket_wrap | |
211 | int qemu_ioctlsocket_wrap(int fd, int req, void *val); | |
212 | ||
a2d96af4 DB |
213 | #undef getsockopt |
214 | #define getsockopt qemu_getsockopt_wrap | |
215 | int qemu_getsockopt_wrap(int sockfd, int level, int optname, | |
216 | void *optval, socklen_t *optlen); | |
217 | ||
218 | #undef setsockopt | |
219 | #define setsockopt qemu_setsockopt_wrap | |
220 | int qemu_setsockopt_wrap(int sockfd, int level, int optname, | |
221 | const void *optval, socklen_t optlen); | |
222 | ||
223 | #undef getpeername | |
224 | #define getpeername qemu_getpeername_wrap | |
225 | int qemu_getpeername_wrap(int sockfd, struct sockaddr *addr, | |
226 | socklen_t *addrlen); | |
227 | ||
228 | #undef getsockname | |
229 | #define getsockname qemu_getsockname_wrap | |
230 | int qemu_getsockname_wrap(int sockfd, struct sockaddr *addr, | |
231 | socklen_t *addrlen); | |
232 | ||
233 | #undef send | |
234 | #define send qemu_send_wrap | |
235 | ssize_t qemu_send_wrap(int sockfd, const void *buf, size_t len, int flags); | |
236 | ||
237 | #undef sendto | |
238 | #define sendto qemu_sendto_wrap | |
239 | ssize_t qemu_sendto_wrap(int sockfd, const void *buf, size_t len, int flags, | |
240 | const struct sockaddr *addr, socklen_t addrlen); | |
241 | ||
242 | #undef recv | |
243 | #define recv qemu_recv_wrap | |
244 | ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags); | |
245 | ||
246 | #undef recvfrom | |
247 | #define recvfrom qemu_recvfrom_wrap | |
248 | ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags, | |
249 | struct sockaddr *addr, socklen_t *addrlen); | |
250 | ||
415a9fb8 PM |
251 | #ifdef __cplusplus |
252 | } | |
253 | #endif | |
254 | ||
39626c03 | 255 | #endif |