PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/include/sysemu/os-win32.h

https://gitlab.com/paelzer/qemu
C Header | 213 lines | 130 code | 39 blank | 44 comment | 1 complexity | bf81c5641a488a729960d9681125a89b MD5 | raw file
  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. #ifndef QEMU_OS_WIN32_H
  26. #define QEMU_OS_WIN32_H
  27. #include <winsock2.h>
  28. #include <windows.h>
  29. #include <ws2tcpip.h>
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  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.
  45. */
  46. #define sigjmp_buf jmp_buf
  47. #define sigsetjmp(env, savemask) setjmp(env)
  48. #define siglongjmp(env, val) longjmp(env, val)
  49. /* Missing POSIX functions. Don't use MinGW-w64 macros. */
  50. #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
  51. #undef gmtime_r
  52. struct tm *gmtime_r(const time_t *timep, struct tm *result);
  53. #undef localtime_r
  54. struct tm *localtime_r(const time_t *timep, struct tm *result);
  55. #endif /* _POSIX_THREAD_SAFE_FUNCTIONS */
  56. static inline void os_setup_signal_handling(void) {}
  57. static inline void os_daemonize(void) {}
  58. static inline void os_setup_post(void) {}
  59. void os_set_line_buffering(void);
  60. static inline void os_set_proc_name(const char *dummy) {}
  61. int getpagesize(void);
  62. #if !defined(EPROTONOSUPPORT)
  63. # define EPROTONOSUPPORT EINVAL
  64. #endif
  65. typedef struct {
  66. long tv_sec;
  67. long tv_usec;
  68. } qemu_timeval;
  69. int qemu_gettimeofday(qemu_timeval *tp);
  70. static inline int os_set_daemonize(bool d)
  71. {
  72. if (d) {
  73. return -ENOTSUP;
  74. }
  75. return 0;
  76. }
  77. static inline bool is_daemonized(void)
  78. {
  79. return false;
  80. }
  81. static inline int os_mlock(void)
  82. {
  83. return -ENOSYS;
  84. }
  85. #define fsync _commit
  86. #if !defined(lseek)
  87. # define lseek _lseeki64
  88. #endif
  89. int qemu_ftruncate64(int, int64_t);
  90. #if !defined(ftruncate)
  91. # define ftruncate qemu_ftruncate64
  92. #endif
  93. static inline char *realpath(const char *path, char *resolved_path)
  94. {
  95. _fullpath(resolved_path, path, _MAX_PATH);
  96. return resolved_path;
  97. }
  98. /* ??? Mingw appears to export _lock_file and _unlock_file as the functions
  99. * with which to lock a stdio handle. But something is wrong in the markup,
  100. * either in the header or the library, such that we get undefined references
  101. * to "_imp___lock_file" etc when linking. Since we seem to have no other
  102. * alternative, and the usage within the logging functions isn't critical,
  103. * ignore FILE locking.
  104. */
  105. static inline void qemu_flockfile(FILE *f)
  106. {
  107. }
  108. static inline void qemu_funlockfile(FILE *f)
  109. {
  110. }
  111. /* We wrap all the sockets functions so that we can
  112. * set errno based on WSAGetLastError()
  113. */
  114. #undef connect
  115. #define connect qemu_connect_wrap
  116. int qemu_connect_wrap(int sockfd, const struct sockaddr *addr,
  117. socklen_t addrlen);
  118. #undef listen
  119. #define listen qemu_listen_wrap
  120. int qemu_listen_wrap(int sockfd, int backlog);
  121. #undef bind
  122. #define bind qemu_bind_wrap
  123. int qemu_bind_wrap(int sockfd, const struct sockaddr *addr,
  124. socklen_t addrlen);
  125. #undef socket
  126. #define socket qemu_socket_wrap
  127. int qemu_socket_wrap(int domain, int type, int protocol);
  128. #undef accept
  129. #define accept qemu_accept_wrap
  130. int qemu_accept_wrap(int sockfd, struct sockaddr *addr,
  131. socklen_t *addrlen);
  132. #undef shutdown
  133. #define shutdown qemu_shutdown_wrap
  134. int qemu_shutdown_wrap(int sockfd, int how);
  135. #undef ioctlsocket
  136. #define ioctlsocket qemu_ioctlsocket_wrap
  137. int qemu_ioctlsocket_wrap(int fd, int req, void *val);
  138. #undef closesocket
  139. #define closesocket qemu_closesocket_wrap
  140. int qemu_closesocket_wrap(int fd);
  141. #undef getsockopt
  142. #define getsockopt qemu_getsockopt_wrap
  143. int qemu_getsockopt_wrap(int sockfd, int level, int optname,
  144. void *optval, socklen_t *optlen);
  145. #undef setsockopt
  146. #define setsockopt qemu_setsockopt_wrap
  147. int qemu_setsockopt_wrap(int sockfd, int level, int optname,
  148. const void *optval, socklen_t optlen);
  149. #undef getpeername
  150. #define getpeername qemu_getpeername_wrap
  151. int qemu_getpeername_wrap(int sockfd, struct sockaddr *addr,
  152. socklen_t *addrlen);
  153. #undef getsockname
  154. #define getsockname qemu_getsockname_wrap
  155. int qemu_getsockname_wrap(int sockfd, struct sockaddr *addr,
  156. socklen_t *addrlen);
  157. #undef send
  158. #define send qemu_send_wrap
  159. ssize_t qemu_send_wrap(int sockfd, const void *buf, size_t len, int flags);
  160. #undef sendto
  161. #define sendto qemu_sendto_wrap
  162. ssize_t qemu_sendto_wrap(int sockfd, const void *buf, size_t len, int flags,
  163. const struct sockaddr *addr, socklen_t addrlen);
  164. #undef recv
  165. #define recv qemu_recv_wrap
  166. ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
  167. #undef recvfrom
  168. #define recvfrom qemu_recvfrom_wrap
  169. ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
  170. struct sockaddr *addr, socklen_t *addrlen);
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif