qemu/include/sysemu/os-win32.h
<<
>>
Prefs
   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
  29#include <winsock2.h>
  30#include <windows.h>
  31#include <ws2tcpip.h>
  32
  33#ifdef HAVE_AFUNIX_H
  34#include <afunix.h>
  35#else
  36/*
  37 * Fallback definitions of things we need in afunix.h, if not available from
  38 * the used Windows SDK or MinGW headers.
  39 */
  40#define UNIX_PATH_MAX 108
  41
  42typedef struct sockaddr_un {
  43    ADDRESS_FAMILY sun_family;
  44    char sun_path[UNIX_PATH_MAX];
  45} SOCKADDR_UN, *PSOCKADDR_UN;
  46
  47#define SIO_AF_UNIX_GETPEERPID _WSAIOR(IOC_VENDOR, 256)
  48#endif
  49
  50#ifdef __cplusplus
  51extern "C" {
  52#endif
  53
  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.
  66 */
  67#define sigjmp_buf jmp_buf
  68#define sigsetjmp(env, savemask) setjmp(env)
  69#define siglongjmp(env, val) longjmp(env, val)
  70
  71/* Missing POSIX functions. Don't use MinGW-w64 macros. */
  72#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
  73#undef gmtime_r
  74struct tm *gmtime_r(const time_t *timep, struct tm *result);
  75#undef localtime_r
  76struct tm *localtime_r(const time_t *timep, struct tm *result);
  77#endif /* _POSIX_THREAD_SAFE_FUNCTIONS */
  78
  79static inline void os_setup_signal_handling(void) {}
  80static inline void os_daemonize(void) {}
  81static inline void os_setup_post(void) {}
  82static inline void os_set_proc_name(const char *dummy) {}
  83static inline int os_parse_cmd_args(int index, const char *optarg) { return -1; }
  84void os_set_line_buffering(void);
  85void os_setup_early_signal_handling(void);
  86
  87int getpagesize(void);
  88
  89#if !defined(EPROTONOSUPPORT)
  90# define EPROTONOSUPPORT EINVAL
  91#endif
  92
  93static inline int os_set_daemonize(bool d)
  94{
  95    if (d) {
  96        return -ENOTSUP;
  97    }
  98    return 0;
  99}
 100
 101static inline bool is_daemonized(void)
 102{
 103    return false;
 104}
 105
 106static inline int os_mlock(void)
 107{
 108    return -ENOSYS;
 109}
 110
 111#define fsync _commit
 112
 113#if !defined(lseek)
 114# define lseek _lseeki64
 115#endif
 116
 117int qemu_ftruncate64(int, int64_t);
 118
 119#if !defined(ftruncate)
 120# define ftruncate qemu_ftruncate64
 121#endif
 122
 123static inline char *realpath(const char *path, char *resolved_path)
 124{
 125    _fullpath(resolved_path, path, _MAX_PATH);
 126    return resolved_path;
 127}
 128
 129/*
 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.
 132 */
 133static inline void qemu_flockfile(FILE *f)
 134{
 135#ifdef HAVE__LOCK_FILE
 136    _lock_file(f);
 137#endif
 138}
 139
 140static inline void qemu_funlockfile(FILE *f)
 141{
 142#ifdef HAVE__LOCK_FILE
 143    _unlock_file(f);
 144#endif
 145}
 146
 147/* We wrap all the sockets functions so that we can
 148 * set errno based on WSAGetLastError()
 149 */
 150
 151#undef connect
 152#define connect qemu_connect_wrap
 153int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
 154                      socklen_t addrlen);
 155
 156#undef listen
 157#define listen qemu_listen_wrap
 158int qemu_listen_wrap(int sockfd, int backlog);
 159
 160#undef bind
 161#define bind qemu_bind_wrap
 162int qemu_bind_wrap(int sockfd, const struct sockaddr *addr,
 163                   socklen_t addrlen);
 164
 165#undef socket
 166#define socket qemu_socket_wrap
 167int qemu_socket_wrap(int domain, int type, int protocol);
 168
 169#undef accept
 170#define accept qemu_accept_wrap
 171int qemu_accept_wrap(int sockfd, struct sockaddr *addr,
 172                     socklen_t *addrlen);
 173
 174#undef shutdown
 175#define shutdown qemu_shutdown_wrap
 176int qemu_shutdown_wrap(int sockfd, int how);
 177
 178#undef ioctlsocket
 179#define ioctlsocket qemu_ioctlsocket_wrap
 180int qemu_ioctlsocket_wrap(int fd, int req, void *val);
 181
 182#undef closesocket
 183#define closesocket qemu_closesocket_wrap
 184int qemu_closesocket_wrap(int fd);
 185
 186#undef getsockopt
 187#define getsockopt qemu_getsockopt_wrap
 188int qemu_getsockopt_wrap(int sockfd, int level, int optname,
 189                         void *optval, socklen_t *optlen);
 190
 191#undef setsockopt
 192#define setsockopt qemu_setsockopt_wrap
 193int qemu_setsockopt_wrap(int sockfd, int level, int optname,
 194                         const void *optval, socklen_t optlen);
 195
 196#undef getpeername
 197#define getpeername qemu_getpeername_wrap
 198int qemu_getpeername_wrap(int sockfd, struct sockaddr *addr,
 199                          socklen_t *addrlen);
 200
 201#undef getsockname
 202#define getsockname qemu_getsockname_wrap
 203int qemu_getsockname_wrap(int sockfd, struct sockaddr *addr,
 204                          socklen_t *addrlen);
 205
 206#undef send
 207#define send qemu_send_wrap
 208ssize_t qemu_send_wrap(int sockfd, const void *buf, size_t len, int flags);
 209
 210#undef sendto
 211#define sendto qemu_sendto_wrap
 212ssize_t qemu_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
 213                         const struct sockaddr *addr, socklen_t addrlen);
 214
 215#undef recv
 216#define recv qemu_recv_wrap
 217ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
 218
 219#undef recvfrom
 220#define recvfrom qemu_recvfrom_wrap
 221ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
 222                           struct sockaddr *addr, socklen_t *addrlen);
 223
 224#ifdef __cplusplus
 225}
 226#endif
 227
 228#endif
 229