icount: Take iothread lock when running QEMU timers
[qemu/ar7.git] / include / sysemu / os-win32.h
blobedc3b38a576b621c90add0dba08763fdf5ecc145
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 static inline void os_set_proc_name(const char *dummy) {}
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);
70 int getpagesize(void);
72 #if !defined(EPROTONOSUPPORT)
73 # define EPROTONOSUPPORT EINVAL
74 #endif
76 static inline int os_set_daemonize(bool d)
78 if (d) {
79 return -ENOTSUP;
81 return 0;
84 static inline bool is_daemonized(void)
86 return false;
89 static inline int os_mlock(void)
91 return -ENOSYS;
94 #define fsync _commit
96 #if !defined(lseek)
97 # define lseek _lseeki64
98 #endif
100 int qemu_ftruncate64(int, int64_t);
102 #if !defined(ftruncate)
103 # define ftruncate qemu_ftruncate64
104 #endif
106 static inline char *realpath(const char *path, char *resolved_path)
108 _fullpath(resolved_path, path, _MAX_PATH);
109 return resolved_path;
113 * Older versions of MinGW do not import _lock_file and _unlock_file properly.
114 * This was fixed for v6.0.0 with commit b48e3ac8969d.
116 static inline void qemu_flockfile(FILE *f)
118 #ifdef HAVE__LOCK_FILE
119 _lock_file(f);
120 #endif
123 static inline void qemu_funlockfile(FILE *f)
125 #ifdef HAVE__LOCK_FILE
126 _unlock_file(f);
127 #endif
130 /* We wrap all the sockets functions so that we can
131 * set errno based on WSAGetLastError()
134 #undef connect
135 #define connect qemu_connect_wrap
136 int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
137 socklen_t addrlen);
139 #undef listen
140 #define listen qemu_listen_wrap
141 int qemu_listen_wrap(int sockfd, int backlog);
143 #undef bind
144 #define bind qemu_bind_wrap
145 int qemu_bind_wrap(int sockfd, const struct sockaddr *addr,
146 socklen_t addrlen);
148 #undef socket
149 #define socket qemu_socket_wrap
150 int qemu_socket_wrap(int domain, int type, int protocol);
152 #undef accept
153 #define accept qemu_accept_wrap
154 int qemu_accept_wrap(int sockfd, struct sockaddr *addr,
155 socklen_t *addrlen);
157 #undef shutdown
158 #define shutdown qemu_shutdown_wrap
159 int qemu_shutdown_wrap(int sockfd, int how);
161 #undef ioctlsocket
162 #define ioctlsocket qemu_ioctlsocket_wrap
163 int qemu_ioctlsocket_wrap(int fd, int req, void *val);
165 #undef closesocket
166 #define closesocket qemu_closesocket_wrap
167 int qemu_closesocket_wrap(int fd);
169 #undef getsockopt
170 #define getsockopt qemu_getsockopt_wrap
171 int qemu_getsockopt_wrap(int sockfd, int level, int optname,
172 void *optval, socklen_t *optlen);
174 #undef setsockopt
175 #define setsockopt qemu_setsockopt_wrap
176 int qemu_setsockopt_wrap(int sockfd, int level, int optname,
177 const void *optval, socklen_t optlen);
179 #undef getpeername
180 #define getpeername qemu_getpeername_wrap
181 int qemu_getpeername_wrap(int sockfd, struct sockaddr *addr,
182 socklen_t *addrlen);
184 #undef getsockname
185 #define getsockname qemu_getsockname_wrap
186 int qemu_getsockname_wrap(int sockfd, struct sockaddr *addr,
187 socklen_t *addrlen);
189 #undef send
190 #define send qemu_send_wrap
191 ssize_t qemu_send_wrap(int sockfd, const void *buf, size_t len, int flags);
193 #undef sendto
194 #define sendto qemu_sendto_wrap
195 ssize_t qemu_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
196 const struct sockaddr *addr, socklen_t addrlen);
198 #undef recv
199 #define recv qemu_recv_wrap
200 ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
202 #undef recvfrom
203 #define recvfrom qemu_recvfrom_wrap
204 ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
205 struct sockaddr *addr, socklen_t *addrlen);
207 #ifdef __cplusplus
209 #endif
211 #endif