util/qemu-sockets: Enable unix socket support on Windows
[qemu/ar7.git] / include / sysemu / os-win32.h
blob5b38c7bd0451ae9d9c3a058a2b30762d52bc89da
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 HAVE_AFUNIX_H
34 #include <afunix.h>
35 #else
37 * Fallback definitions of things we need in afunix.h, if not available from
38 * the used Windows SDK or MinGW headers.
40 #define UNIX_PATH_MAX 108
42 typedef struct sockaddr_un {
43 ADDRESS_FAMILY sun_family;
44 char sun_path[UNIX_PATH_MAX];
45 } SOCKADDR_UN, *PSOCKADDR_UN;
47 #define SIO_AF_UNIX_GETPEERPID _WSAIOR(IOC_VENDOR, 256)
48 #endif
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
54 #if defined(_WIN64)
55 /* On w64, setjmp is implemented by _setjmp which needs a second parameter.
56 * If this parameter is NULL, longjump does no stack unwinding.
57 * That is what we need for QEMU. Passing the value of register rsp (default)
58 * lets longjmp try a stack unwinding which will crash with generated code. */
59 # undef setjmp
60 # define setjmp(env) _setjmp(env, NULL)
61 #endif
62 /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
63 * "longjmp and don't touch the signal masks". Since we know that the
64 * savemask parameter will always be zero we can safely define these
65 * in terms of setjmp/longjmp on Win32.
67 #define sigjmp_buf jmp_buf
68 #define sigsetjmp(env, savemask) setjmp(env)
69 #define siglongjmp(env, val) longjmp(env, val)
71 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
72 #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
73 #undef gmtime_r
74 struct tm *gmtime_r(const time_t *timep, struct tm *result);
75 #undef localtime_r
76 struct tm *localtime_r(const time_t *timep, struct tm *result);
77 #endif /* _POSIX_THREAD_SAFE_FUNCTIONS */
79 static inline void os_setup_signal_handling(void) {}
80 static inline void os_daemonize(void) {}
81 static inline void os_setup_post(void) {}
82 static inline void os_set_proc_name(const char *dummy) {}
83 static inline int os_parse_cmd_args(int index, const char *optarg) { return -1; }
84 void os_set_line_buffering(void);
85 void os_setup_early_signal_handling(void);
87 int getpagesize(void);
89 #if !defined(EPROTONOSUPPORT)
90 # define EPROTONOSUPPORT EINVAL
91 #endif
93 static inline int os_set_daemonize(bool d)
95 if (d) {
96 return -ENOTSUP;
98 return 0;
101 static inline bool is_daemonized(void)
103 return false;
106 static inline int os_mlock(void)
108 return -ENOSYS;
111 #define fsync _commit
113 #if !defined(lseek)
114 # define lseek _lseeki64
115 #endif
117 int qemu_ftruncate64(int, int64_t);
119 #if !defined(ftruncate)
120 # define ftruncate qemu_ftruncate64
121 #endif
123 static inline char *realpath(const char *path, char *resolved_path)
125 _fullpath(resolved_path, path, _MAX_PATH);
126 return resolved_path;
130 * Older versions of MinGW do not import _lock_file and _unlock_file properly.
131 * This was fixed for v6.0.0 with commit b48e3ac8969d.
133 static inline void qemu_flockfile(FILE *f)
135 #ifdef HAVE__LOCK_FILE
136 _lock_file(f);
137 #endif
140 static inline void qemu_funlockfile(FILE *f)
142 #ifdef HAVE__LOCK_FILE
143 _unlock_file(f);
144 #endif
147 /* We wrap all the sockets functions so that we can
148 * set errno based on WSAGetLastError()
151 #undef connect
152 #define connect qemu_connect_wrap
153 int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
154 socklen_t addrlen);
156 #undef listen
157 #define listen qemu_listen_wrap
158 int qemu_listen_wrap(int sockfd, int backlog);
160 #undef bind
161 #define bind qemu_bind_wrap
162 int qemu_bind_wrap(int sockfd, const struct sockaddr *addr,
163 socklen_t addrlen);
165 #undef socket
166 #define socket qemu_socket_wrap
167 int qemu_socket_wrap(int domain, int type, int protocol);
169 #undef accept
170 #define accept qemu_accept_wrap
171 int qemu_accept_wrap(int sockfd, struct sockaddr *addr,
172 socklen_t *addrlen);
174 #undef shutdown
175 #define shutdown qemu_shutdown_wrap
176 int qemu_shutdown_wrap(int sockfd, int how);
178 #undef ioctlsocket
179 #define ioctlsocket qemu_ioctlsocket_wrap
180 int qemu_ioctlsocket_wrap(int fd, int req, void *val);
182 #undef closesocket
183 #define closesocket qemu_closesocket_wrap
184 int qemu_closesocket_wrap(int fd);
186 #undef getsockopt
187 #define getsockopt qemu_getsockopt_wrap
188 int qemu_getsockopt_wrap(int sockfd, int level, int optname,
189 void *optval, socklen_t *optlen);
191 #undef setsockopt
192 #define setsockopt qemu_setsockopt_wrap
193 int qemu_setsockopt_wrap(int sockfd, int level, int optname,
194 const void *optval, socklen_t optlen);
196 #undef getpeername
197 #define getpeername qemu_getpeername_wrap
198 int qemu_getpeername_wrap(int sockfd, struct sockaddr *addr,
199 socklen_t *addrlen);
201 #undef getsockname
202 #define getsockname qemu_getsockname_wrap
203 int qemu_getsockname_wrap(int sockfd, struct sockaddr *addr,
204 socklen_t *addrlen);
206 #undef send
207 #define send qemu_send_wrap
208 ssize_t qemu_send_wrap(int sockfd, const void *buf, size_t len, int flags);
210 #undef sendto
211 #define sendto qemu_sendto_wrap
212 ssize_t qemu_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
213 const struct sockaddr *addr, socklen_t addrlen);
215 #undef recv
216 #define recv qemu_recv_wrap
217 ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
219 #undef recvfrom
220 #define recvfrom qemu_recvfrom_wrap
221 ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
222 struct sockaddr *addr, socklen_t *addrlen);
224 #ifdef __cplusplus
226 #endif
228 #endif