qtest/meson.build: check CONFIG_TCG for prom-env-test in qtests_ppc
[qemu.git] / include / sysemu / os-win32.h
blob770752222ae39f7ec205a4f877a581f37a32daa3
1 /*
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
23 * THE SOFTWARE.
26 #ifndef QEMU_OS_WIN32_H
27 #define QEMU_OS_WIN32_H
29 #include <winsock2.h>
30 #include <windows.h>
31 #include <ws2tcpip.h>
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
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
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.
50 #define sigjmp_buf jmp_buf
51 #define sigsetjmp(env, savemask) setjmp(env)
52 #define siglongjmp(env, val) longjmp(env, val)
54 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
55 #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
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);
60 #endif /* _POSIX_THREAD_SAFE_FUNCTIONS */
62 static inline void os_setup_signal_handling(void) {}
63 static inline void os_daemonize(void) {}
64 static inline void os_setup_post(void) {}
65 void os_set_line_buffering(void);
66 static inline void os_set_proc_name(const char *dummy) {}
68 int getpagesize(void);
70 #if !defined(EPROTONOSUPPORT)
71 # define EPROTONOSUPPORT EINVAL
72 #endif
74 typedef struct {
75 long tv_sec;
76 long tv_usec;
77 } qemu_timeval;
78 int qemu_gettimeofday(qemu_timeval *tp);
80 static inline int os_set_daemonize(bool d)
82 if (d) {
83 return -ENOTSUP;
85 return 0;
88 static inline bool is_daemonized(void)
90 return false;
93 static inline int os_mlock(void)
95 return -ENOSYS;
98 #define fsync _commit
100 #if !defined(lseek)
101 # define lseek _lseeki64
102 #endif
104 int qemu_ftruncate64(int, int64_t);
106 #if !defined(ftruncate)
107 # define ftruncate qemu_ftruncate64
108 #endif
110 static inline char *realpath(const char *path, char *resolved_path)
112 _fullpath(resolved_path, path, _MAX_PATH);
113 return resolved_path;
116 /* ??? Mingw appears to export _lock_file and _unlock_file as the functions
117 * with which to lock a stdio handle. But something is wrong in the markup,
118 * either in the header or the library, such that we get undefined references
119 * to "_imp___lock_file" etc when linking. Since we seem to have no other
120 * alternative, and the usage within the logging functions isn't critical,
121 * ignore FILE locking.
124 static inline void qemu_flockfile(FILE *f)
128 static inline void qemu_funlockfile(FILE *f)
132 /* We wrap all the sockets functions so that we can
133 * set errno based on WSAGetLastError()
136 #undef connect
137 #define connect qemu_connect_wrap
138 int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
139 socklen_t addrlen);
141 #undef listen
142 #define listen qemu_listen_wrap
143 int qemu_listen_wrap(int sockfd, int backlog);
145 #undef bind
146 #define bind qemu_bind_wrap
147 int qemu_bind_wrap(int sockfd, const struct sockaddr *addr,
148 socklen_t addrlen);
150 #undef socket
151 #define socket qemu_socket_wrap
152 int qemu_socket_wrap(int domain, int type, int protocol);
154 #undef accept
155 #define accept qemu_accept_wrap
156 int qemu_accept_wrap(int sockfd, struct sockaddr *addr,
157 socklen_t *addrlen);
159 #undef shutdown
160 #define shutdown qemu_shutdown_wrap
161 int qemu_shutdown_wrap(int sockfd, int how);
163 #undef ioctlsocket
164 #define ioctlsocket qemu_ioctlsocket_wrap
165 int qemu_ioctlsocket_wrap(int fd, int req, void *val);
167 #undef closesocket
168 #define closesocket qemu_closesocket_wrap
169 int qemu_closesocket_wrap(int fd);
171 #undef getsockopt
172 #define getsockopt qemu_getsockopt_wrap
173 int qemu_getsockopt_wrap(int sockfd, int level, int optname,
174 void *optval, socklen_t *optlen);
176 #undef setsockopt
177 #define setsockopt qemu_setsockopt_wrap
178 int qemu_setsockopt_wrap(int sockfd, int level, int optname,
179 const void *optval, socklen_t optlen);
181 #undef getpeername
182 #define getpeername qemu_getpeername_wrap
183 int qemu_getpeername_wrap(int sockfd, struct sockaddr *addr,
184 socklen_t *addrlen);
186 #undef getsockname
187 #define getsockname qemu_getsockname_wrap
188 int qemu_getsockname_wrap(int sockfd, struct sockaddr *addr,
189 socklen_t *addrlen);
191 #undef send
192 #define send qemu_send_wrap
193 ssize_t qemu_send_wrap(int sockfd, const void *buf, size_t len, int flags);
195 #undef sendto
196 #define sendto qemu_sendto_wrap
197 ssize_t qemu_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
198 const struct sockaddr *addr, socklen_t addrlen);
200 #undef recv
201 #define recv qemu_recv_wrap
202 ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
204 #undef recvfrom
205 #define recvfrom qemu_recvfrom_wrap
206 ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
207 struct sockaddr *addr, socklen_t *addrlen);
209 #ifdef __cplusplus
211 #endif
213 #endif