qemu-common.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * This file is supposed to be included only by .c files. No header file should
  3. * depend on qemu-common.h, as this would easily lead to circular header
  4. * dependencies.
  5. *
  6. * If a header file uses a definition from qemu-common.h, that definition
  7. * must be moved to a separate header file, and the header that uses it
  8. * must include that header.
  9. */
  10. #ifndef QEMU_COMMON_H
  11. #define QEMU_COMMON_H
  12. #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
  13. /* Copyright string for -version arguments, About dialogs, etc */
  14. #define QEMU_COPYRIGHT "Copyright (c) 2003-2020 " \
  15. "Fabrice Bellard and the QEMU Project developers"
  16. /* Bug reporting information for --help arguments, About dialogs, etc */
  17. #define QEMU_HELP_BOTTOM \
  18. "See <https://qemu.org/contribute/report-a-bug> for how to report bugs.\n" \
  19. "More information on the QEMU project at <https://qemu.org>."
  20. /* main function, renamed */
  21. #if defined(CONFIG_COCOA)
  22. int qemu_main(int argc, char **argv, char **envp);
  23. #endif
  24. void qemu_get_timedate(struct tm *tm, int offset);
  25. int qemu_timedate_diff(struct tm *tm);
  26. void *qemu_oom_check(void *ptr);
  27. ssize_t qemu_write_full(int fd, const void *buf, size_t count)
  28. QEMU_WARN_UNUSED_RESULT;
  29. #ifndef _WIN32
  30. int qemu_pipe(int pipefd[2]);
  31. /* like openpty() but also makes it raw; return master fd */
  32. int qemu_openpty_raw(int *aslave, char *pty_name);
  33. #endif
  34. #ifdef _WIN32
  35. /* MinGW needs type casts for the 'buf' and 'optval' arguments. */
  36. #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
  37. getsockopt(sockfd, level, optname, (void *)optval, optlen)
  38. #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
  39. setsockopt(sockfd, level, optname, (const void *)optval, optlen)
  40. #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
  41. #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
  42. sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen)
  43. #else
  44. #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
  45. getsockopt(sockfd, level, optname, optval, optlen)
  46. #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
  47. setsockopt(sockfd, level, optname, optval, optlen)
  48. #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
  49. #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
  50. sendto(sockfd, buf, len, flags, destaddr, addrlen)
  51. #endif
  52. void cpu_exec_init_all(void);
  53. void cpu_exec_step_atomic(CPUState *cpu);
  54. /**
  55. * set_preferred_target_page_bits:
  56. * @bits: number of bits needed to represent an address within the page
  57. *
  58. * Set the preferred target page size (the actual target page
  59. * size may be smaller than any given CPU's preference).
  60. * Returns true on success, false on failure (which can only happen
  61. * if this is called after the system has already finalized its
  62. * choice of page size and the requested page size is smaller than that).
  63. */
  64. bool set_preferred_target_page_bits(int bits);
  65. /**
  66. * finalize_target_page_bits:
  67. * Commit the final value set by set_preferred_target_page_bits.
  68. */
  69. void finalize_target_page_bits(void);
  70. /**
  71. * Sends a (part of) iovec down a socket, yielding when the socket is full, or
  72. * Receives data into a (part of) iovec from a socket,
  73. * yielding when there is no data in the socket.
  74. * The same interface as qemu_sendv_recvv(), with added yielding.
  75. * XXX should mark these as coroutine_fn
  76. */
  77. ssize_t qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt,
  78. size_t offset, size_t bytes, bool do_send);
  79. #define qemu_co_recvv(sockfd, iov, iov_cnt, offset, bytes) \
  80. qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, false)
  81. #define qemu_co_sendv(sockfd, iov, iov_cnt, offset, bytes) \
  82. qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, true)
  83. /**
  84. * The same as above, but with just a single buffer
  85. */
  86. ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send);
  87. #define qemu_co_recv(sockfd, buf, bytes) \
  88. qemu_co_send_recv(sockfd, buf, bytes, false)
  89. #define qemu_co_send(sockfd, buf, bytes) \
  90. qemu_co_send_recv(sockfd, buf, bytes, true)
  91. void qemu_progress_init(int enabled, float min_skip);
  92. void qemu_progress_end(void);
  93. void qemu_progress_print(float delta, int max);
  94. const char *qemu_get_vm_name(void);
  95. #define QEMU_FILE_TYPE_BIOS 0
  96. #define QEMU_FILE_TYPE_KEYMAP 1
  97. /**
  98. * qemu_find_file:
  99. * @type: QEMU_FILE_TYPE_BIOS (for BIOS, VGA BIOS)
  100. * or QEMU_FILE_TYPE_KEYMAP (for keymaps).
  101. * @name: Relative or absolute file name
  102. *
  103. * If @name exists on disk as an absolute path, or a path relative
  104. * to the current directory, then returns @name unchanged.
  105. * Otherwise searches for @name file in the data directories, either
  106. * configured at build time (DATADIR) or registered with the -L command
  107. * line option.
  108. *
  109. * The caller must use g_free() to free the returned data when it is
  110. * no longer required.
  111. *
  112. * Returns: a path that can access @name, or NULL if no matching file exists.
  113. */
  114. char *qemu_find_file(int type, const char *name);
  115. /* OS specific functions */
  116. void os_setup_early_signal_handling(void);
  117. int os_parse_cmd_args(int index, const char *optarg);
  118. /*
  119. * Hexdump a line of a byte buffer into a hexadecimal/ASCII buffer
  120. */
  121. #define QEMU_HEXDUMP_LINE_BYTES 16 /* Number of bytes to dump */
  122. #define QEMU_HEXDUMP_LINE_LEN 75 /* Number of characters in line */
  123. void qemu_hexdump_line(char *line, unsigned int b, const void *bufptr,
  124. unsigned int len, bool ascii);
  125. /*
  126. * Hexdump a buffer to a file. An optional string prefix is added to every line
  127. */
  128. void qemu_hexdump(FILE *fp, const char *prefix,
  129. const void *bufptr, size_t size);
  130. /*
  131. * helper to parse debug environment variables
  132. */
  133. int parse_debug_env(const char *name, int max, int initial);
  134. const char *qemu_ether_ntoa(const MACAddr *mac);
  135. void page_size_init(void);
  136. /* returns non-zero if dump is in progress, otherwise zero is
  137. * returned. */
  138. bool dump_in_progress(void);
  139. #endif