Merge remote-tracking branch 'remotes/palmer/tags/riscv-for-master-4.1-sf1-v3' into...
[qemu/ar7.git] / include / sysemu / os-win32.h
blobff18b23db148fbb74bd370d83aae8aaefe6b2227
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 #if defined(_WIN64)
34 /* On w64, setjmp is implemented by _setjmp which needs a second parameter.
35 * If this parameter is NULL, longjump does no stack unwinding.
36 * That is what we need for QEMU. Passing the value of register rsp (default)
37 * lets longjmp try a stack unwinding which will crash with generated code. */
38 # undef setjmp
39 # define setjmp(env) _setjmp(env, NULL)
40 #endif
41 /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
42 * "longjmp and don't touch the signal masks". Since we know that the
43 * savemask parameter will always be zero we can safely define these
44 * in terms of setjmp/longjmp on Win32.
46 #define sigjmp_buf jmp_buf
47 #define sigsetjmp(env, savemask) setjmp(env)
48 #define siglongjmp(env, val) longjmp(env, val)
50 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
51 #ifndef CONFIG_LOCALTIME_R
52 #undef gmtime_r
53 struct tm *gmtime_r(const time_t *timep, struct tm *result);
54 #undef localtime_r
55 struct tm *localtime_r(const time_t *timep, struct tm *result);
56 #endif /* CONFIG_LOCALTIME_R */
58 static inline void os_setup_signal_handling(void) {}
59 static inline void os_daemonize(void) {}
60 static inline void os_setup_post(void) {}
61 void os_set_line_buffering(void);
62 static inline void os_set_proc_name(const char *dummy) {}
64 int getpagesize(void);
66 #if !defined(EPROTONOSUPPORT)
67 # define EPROTONOSUPPORT EINVAL
68 #endif
70 int setenv(const char *name, const char *value, int overwrite);
72 typedef struct {
73 long tv_sec;
74 long tv_usec;
75 } qemu_timeval;
76 int qemu_gettimeofday(qemu_timeval *tp);
78 static inline bool is_daemonized(void)
80 return false;
83 static inline int os_mlock(void)
85 return -ENOSYS;
88 #define fsync _commit
90 #if !defined(lseek)
91 # define lseek _lseeki64
92 #endif
94 int qemu_ftruncate64(int, int64_t);
96 #if !defined(ftruncate)
97 # define ftruncate qemu_ftruncate64
98 #endif
100 static inline char *realpath(const char *path, char *resolved_path)
102 _fullpath(resolved_path, path, _MAX_PATH);
103 return resolved_path;
106 /* ??? Mingw appears to export _lock_file and _unlock_file as the functions
107 * with which to lock a stdio handle. But something is wrong in the markup,
108 * either in the header or the library, such that we get undefined references
109 * to "_imp___lock_file" etc when linking. Since we seem to have no other
110 * alternative, and the usage within the logging functions isn't critical,
111 * ignore FILE locking.
114 static inline void qemu_flockfile(FILE *f)
118 static inline void qemu_funlockfile(FILE *f)
122 /* We wrap all the sockets functions so that we can
123 * set errno based on WSAGetLastError()
126 #undef connect
127 #define connect qemu_connect_wrap
128 int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
129 socklen_t addrlen);
131 #undef listen
132 #define listen qemu_listen_wrap
133 int qemu_listen_wrap(int sockfd, int backlog);
135 #undef bind
136 #define bind qemu_bind_wrap
137 int qemu_bind_wrap(int sockfd, const struct sockaddr *addr,
138 socklen_t addrlen);
140 #undef socket
141 #define socket qemu_socket_wrap
142 int qemu_socket_wrap(int domain, int type, int protocol);
144 #undef accept
145 #define accept qemu_accept_wrap
146 int qemu_accept_wrap(int sockfd, struct sockaddr *addr,
147 socklen_t *addrlen);
149 #undef shutdown
150 #define shutdown qemu_shutdown_wrap
151 int qemu_shutdown_wrap(int sockfd, int how);
153 #undef ioctlsocket
154 #define ioctlsocket qemu_ioctlsocket_wrap
155 int qemu_ioctlsocket_wrap(int fd, int req, void *val);
157 #undef closesocket
158 #define closesocket qemu_closesocket_wrap
159 int qemu_closesocket_wrap(int fd);
161 #undef getsockopt
162 #define getsockopt qemu_getsockopt_wrap
163 int qemu_getsockopt_wrap(int sockfd, int level, int optname,
164 void *optval, socklen_t *optlen);
166 #undef setsockopt
167 #define setsockopt qemu_setsockopt_wrap
168 int qemu_setsockopt_wrap(int sockfd, int level, int optname,
169 const void *optval, socklen_t optlen);
171 #undef getpeername
172 #define getpeername qemu_getpeername_wrap
173 int qemu_getpeername_wrap(int sockfd, struct sockaddr *addr,
174 socklen_t *addrlen);
176 #undef getsockname
177 #define getsockname qemu_getsockname_wrap
178 int qemu_getsockname_wrap(int sockfd, struct sockaddr *addr,
179 socklen_t *addrlen);
181 #undef send
182 #define send qemu_send_wrap
183 ssize_t qemu_send_wrap(int sockfd, const void *buf, size_t len, int flags);
185 #undef sendto
186 #define sendto qemu_sendto_wrap
187 ssize_t qemu_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
188 const struct sockaddr *addr, socklen_t addrlen);
190 #undef recv
191 #define recv qemu_recv_wrap
192 ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
194 #undef recvfrom
195 #define recvfrom qemu_recvfrom_wrap
196 ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
197 struct sockaddr *addr, socklen_t *addrlen);
199 #endif