]>
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> |
082b5557 | 32 | |
415a9fb8 PM |
33 | #ifdef __cplusplus |
34 | extern "C" { | |
35 | #endif | |
36 | ||
5cf6dd51 SW |
37 | #if defined(_WIN64) |
38 | /* On w64, setjmp is implemented by _setjmp which needs a second parameter. | |
39 | * If this parameter is NULL, longjump does no stack unwinding. | |
40 | * That is what we need for QEMU. Passing the value of register rsp (default) | |
41 | * lets longjmp try a stack unwinding which will crash with generated code. */ | |
42 | # undef setjmp | |
43 | # define setjmp(env) _setjmp(env, NULL) | |
44 | #endif | |
6ab7e546 PM |
45 | /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify |
46 | * "longjmp and don't touch the signal masks". Since we know that the | |
47 | * savemask parameter will always be zero we can safely define these | |
48 | * in terms of setjmp/longjmp on Win32. | |
49 | */ | |
50 | #define sigjmp_buf jmp_buf | |
51 | #define sigsetjmp(env, savemask) setjmp(env) | |
52 | #define siglongjmp(env, val) longjmp(env, val) | |
5cf6dd51 | 53 | |
d3e8f957 | 54 | /* Missing POSIX functions. Don't use MinGW-w64 macros. */ |
7c3afc85 | 55 | #ifndef _POSIX_THREAD_SAFE_FUNCTIONS |
d3e8f957 SW |
56 | #undef gmtime_r |
57 | struct tm *gmtime_r(const time_t *timep, struct tm *result); | |
58 | #undef localtime_r | |
59 | struct tm *localtime_r(const time_t *timep, struct tm *result); | |
7c3afc85 | 60 | #endif /* _POSIX_THREAD_SAFE_FUNCTIONS */ |
d3e8f957 | 61 | |
8d963e6a | 62 | static inline void os_setup_signal_handling(void) {} |
eb505be1 JS |
63 | static inline void os_daemonize(void) {} |
64 | static inline void os_setup_post(void) {} | |
ce798cf2 | 65 | static inline void os_set_proc_name(const char *dummy) {} |
327adeec MAL |
66 | static inline int os_parse_cmd_args(int index, const char *optarg) { return -1; } |
67 | void os_set_line_buffering(void); | |
68 | void os_setup_early_signal_handling(void); | |
8d963e6a | 69 | |
a28c2f2d | 70 | int getpagesize(void); |
38183310 | 71 | |
5635efc3 SW |
72 | #if !defined(EPROTONOSUPPORT) |
73 | # define EPROTONOSUPPORT EINVAL | |
74 | #endif | |
75 | ||
f22ac472 HR |
76 | static inline int os_set_daemonize(bool d) |
77 | { | |
78 | if (d) { | |
79 | return -ENOTSUP; | |
80 | } | |
81 | return 0; | |
82 | } | |
83 | ||
995ee2bf HM |
84 | static inline bool is_daemonized(void) |
85 | { | |
86 | return false; | |
87 | } | |
88 | ||
888a6bc6 SM |
89 | static inline int os_mlock(void) |
90 | { | |
91 | return -ENOSYS; | |
92 | } | |
93 | ||
1aad8104 PM |
94 | #define fsync _commit |
95 | ||
96 | #if !defined(lseek) | |
97 | # define lseek _lseeki64 | |
98 | #endif | |
99 | ||
100 | int qemu_ftruncate64(int, int64_t); | |
101 | ||
102 | #if !defined(ftruncate) | |
103 | # define ftruncate qemu_ftruncate64 | |
104 | #endif | |
105 | ||
106 | static inline char *realpath(const char *path, char *resolved_path) | |
107 | { | |
108 | _fullpath(resolved_path, path, _MAX_PATH); | |
109 | return resolved_path; | |
110 | } | |
111 | ||
1ee73216 RH |
112 | /* ??? Mingw appears to export _lock_file and _unlock_file as the functions |
113 | * with which to lock a stdio handle. But something is wrong in the markup, | |
114 | * either in the header or the library, such that we get undefined references | |
115 | * to "_imp___lock_file" etc when linking. Since we seem to have no other | |
116 | * alternative, and the usage within the logging functions isn't critical, | |
117 | * ignore FILE locking. | |
118 | */ | |
119 | ||
120 | static inline void qemu_flockfile(FILE *f) | |
121 | { | |
122 | } | |
123 | ||
124 | static inline void qemu_funlockfile(FILE *f) | |
125 | { | |
126 | } | |
a2d96af4 DB |
127 | |
128 | /* We wrap all the sockets functions so that we can | |
129 | * set errno based on WSAGetLastError() | |
130 | */ | |
131 | ||
132 | #undef connect | |
133 | #define connect qemu_connect_wrap | |
134 | int qemu_connect_wrap(int sockfd, const struct sockaddr *addr, | |
135 | socklen_t addrlen); | |
136 | ||
137 | #undef listen | |
138 | #define listen qemu_listen_wrap | |
139 | int qemu_listen_wrap(int sockfd, int backlog); | |
140 | ||
141 | #undef bind | |
142 | #define bind qemu_bind_wrap | |
143 | int qemu_bind_wrap(int sockfd, const struct sockaddr *addr, | |
144 | socklen_t addrlen); | |
145 | ||
146 | #undef socket | |
147 | #define socket qemu_socket_wrap | |
148 | int qemu_socket_wrap(int domain, int type, int protocol); | |
149 | ||
150 | #undef accept | |
151 | #define accept qemu_accept_wrap | |
152 | int qemu_accept_wrap(int sockfd, struct sockaddr *addr, | |
153 | socklen_t *addrlen); | |
154 | ||
155 | #undef shutdown | |
156 | #define shutdown qemu_shutdown_wrap | |
157 | int qemu_shutdown_wrap(int sockfd, int how); | |
158 | ||
159 | #undef ioctlsocket | |
160 | #define ioctlsocket qemu_ioctlsocket_wrap | |
161 | int qemu_ioctlsocket_wrap(int fd, int req, void *val); | |
162 | ||
163 | #undef closesocket | |
164 | #define closesocket qemu_closesocket_wrap | |
165 | int qemu_closesocket_wrap(int fd); | |
166 | ||
167 | #undef getsockopt | |
168 | #define getsockopt qemu_getsockopt_wrap | |
169 | int qemu_getsockopt_wrap(int sockfd, int level, int optname, | |
170 | void *optval, socklen_t *optlen); | |
171 | ||
172 | #undef setsockopt | |
173 | #define setsockopt qemu_setsockopt_wrap | |
174 | int qemu_setsockopt_wrap(int sockfd, int level, int optname, | |
175 | const void *optval, socklen_t optlen); | |
176 | ||
177 | #undef getpeername | |
178 | #define getpeername qemu_getpeername_wrap | |
179 | int qemu_getpeername_wrap(int sockfd, struct sockaddr *addr, | |
180 | socklen_t *addrlen); | |
181 | ||
182 | #undef getsockname | |
183 | #define getsockname qemu_getsockname_wrap | |
184 | int qemu_getsockname_wrap(int sockfd, struct sockaddr *addr, | |
185 | socklen_t *addrlen); | |
186 | ||
187 | #undef send | |
188 | #define send qemu_send_wrap | |
189 | ssize_t qemu_send_wrap(int sockfd, const void *buf, size_t len, int flags); | |
190 | ||
191 | #undef sendto | |
192 | #define sendto qemu_sendto_wrap | |
193 | ssize_t qemu_sendto_wrap(int sockfd, const void *buf, size_t len, int flags, | |
194 | const struct sockaddr *addr, socklen_t addrlen); | |
195 | ||
196 | #undef recv | |
197 | #define recv qemu_recv_wrap | |
198 | ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags); | |
199 | ||
200 | #undef recvfrom | |
201 | #define recvfrom qemu_recvfrom_wrap | |
202 | ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags, | |
203 | struct sockaddr *addr, socklen_t *addrlen); | |
204 | ||
415a9fb8 PM |
205 | #ifdef __cplusplus |
206 | } | |
207 | #endif | |
208 | ||
39626c03 | 209 | #endif |