2
0

qemu-common.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* Common header file that is included by all of qemu. */
  2. #ifndef QEMU_COMMON_H
  3. #define QEMU_COMMON_H
  4. #ifdef _WIN32
  5. #define WIN32_LEAN_AND_MEAN
  6. #define WINVER 0x0501 /* needed for ipv6 bits */
  7. #include <windows.h>
  8. #endif
  9. #define QEMU_NORETURN __attribute__ ((__noreturn__))
  10. /* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
  11. cannot include the following headers without conflicts. This condition has
  12. to be removed once dyngen is gone. */
  13. #ifndef __DYNGEN_EXEC_H__
  14. /* we put basic includes here to avoid repeating them in device drivers */
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <stdarg.h>
  18. #include <string.h>
  19. #include <strings.h>
  20. #include <inttypes.h>
  21. #include <limits.h>
  22. #include <time.h>
  23. #include <ctype.h>
  24. #include <errno.h>
  25. #include <unistd.h>
  26. #include <fcntl.h>
  27. #include <sys/stat.h>
  28. #include "config-host.h"
  29. #ifndef O_LARGEFILE
  30. #define O_LARGEFILE 0
  31. #endif
  32. #ifndef O_BINARY
  33. #define O_BINARY 0
  34. #endif
  35. #ifndef ENOMEDIUM
  36. #define ENOMEDIUM ENODEV
  37. #endif
  38. #ifndef HAVE_IOVEC
  39. #define HAVE_IOVEC
  40. struct iovec {
  41. void *iov_base;
  42. size_t iov_len;
  43. };
  44. #else
  45. #include <sys/uio.h>
  46. #endif
  47. #ifdef _WIN32
  48. #define fsync _commit
  49. #define lseek _lseeki64
  50. #define ENOTSUP 4096
  51. extern int qemu_ftruncate64(int, int64_t);
  52. #define ftruncate qemu_ftruncate64
  53. static inline char *realpath(const char *path, char *resolved_path)
  54. {
  55. _fullpath(resolved_path, path, _MAX_PATH);
  56. return resolved_path;
  57. }
  58. #define PRId64 "I64d"
  59. #define PRIx64 "I64x"
  60. #define PRIu64 "I64u"
  61. #define PRIo64 "I64o"
  62. #endif
  63. /* FIXME: Remove NEED_CPU_H. */
  64. #ifndef NEED_CPU_H
  65. #include <setjmp.h>
  66. #include "osdep.h"
  67. #include "bswap.h"
  68. #else
  69. #include "cpu.h"
  70. #endif /* !defined(NEED_CPU_H) */
  71. /* bottom halves */
  72. typedef struct QEMUBH QEMUBH;
  73. typedef void QEMUBHFunc(void *opaque);
  74. QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
  75. void qemu_bh_schedule(QEMUBH *bh);
  76. /* Bottom halfs that are scheduled from a bottom half handler are instantly
  77. * invoked. This can create an infinite loop if a bottom half handler
  78. * schedules itself. qemu_bh_schedule_idle() avoids this infinite loop by
  79. * ensuring that the bottom half isn't executed until the next main loop
  80. * iteration.
  81. */
  82. void qemu_bh_schedule_idle(QEMUBH *bh);
  83. void qemu_bh_cancel(QEMUBH *bh);
  84. void qemu_bh_delete(QEMUBH *bh);
  85. int qemu_bh_poll(void);
  86. uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
  87. void qemu_get_timedate(struct tm *tm, int offset);
  88. int qemu_timedate_diff(struct tm *tm);
  89. /* cutils.c */
  90. void pstrcpy(char *buf, int buf_size, const char *str);
  91. char *pstrcat(char *buf, int buf_size, const char *s);
  92. int strstart(const char *str, const char *val, const char **ptr);
  93. int stristart(const char *str, const char *val, const char **ptr);
  94. time_t mktimegm(struct tm *tm);
  95. int qemu_fls(int i);
  96. #define qemu_isalnum(c) isalnum((unsigned char)(c))
  97. #define qemu_isalpha(c) isalpha((unsigned char)(c))
  98. #define qemu_iscntrl(c) iscntrl((unsigned char)(c))
  99. #define qemu_isdigit(c) isdigit((unsigned char)(c))
  100. #define qemu_isgraph(c) isgraph((unsigned char)(c))
  101. #define qemu_islower(c) islower((unsigned char)(c))
  102. #define qemu_isprint(c) isprint((unsigned char)(c))
  103. #define qemu_ispunct(c) ispunct((unsigned char)(c))
  104. #define qemu_isspace(c) isspace((unsigned char)(c))
  105. #define qemu_isupper(c) isupper((unsigned char)(c))
  106. #define qemu_isxdigit(c) isxdigit((unsigned char)(c))
  107. #define qemu_tolower(c) tolower((unsigned char)(c))
  108. #define qemu_toupper(c) toupper((unsigned char)(c))
  109. #define qemu_isascii(c) isascii((unsigned char)(c))
  110. #define qemu_toascii(c) toascii((unsigned char)(c))
  111. void *qemu_malloc(size_t size);
  112. void *qemu_realloc(void *ptr, size_t size);
  113. void *qemu_mallocz(size_t size);
  114. void qemu_free(void *ptr);
  115. char *qemu_strdup(const char *str);
  116. char *qemu_strndup(const char *str, size_t size);
  117. void *get_mmap_addr(unsigned long size);
  118. /* Error handling. */
  119. void QEMU_NORETURN hw_error(const char *fmt, ...)
  120. __attribute__ ((__format__ (__printf__, 1, 2)));
  121. /* IO callbacks. */
  122. typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
  123. typedef int IOCanRWHandler(void *opaque);
  124. typedef void IOHandler(void *opaque);
  125. struct ParallelIOArg {
  126. void *buffer;
  127. int count;
  128. };
  129. typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
  130. /* A load of opaque types so that device init declarations don't have to
  131. pull in all the real definitions. */
  132. typedef struct NICInfo NICInfo;
  133. typedef struct HCIInfo HCIInfo;
  134. typedef struct AudioState AudioState;
  135. typedef struct BlockDriverState BlockDriverState;
  136. typedef struct DisplayState DisplayState;
  137. typedef struct DisplayChangeListener DisplayChangeListener;
  138. typedef struct DisplaySurface DisplaySurface;
  139. typedef struct PixelFormat PixelFormat;
  140. typedef struct TextConsole TextConsole;
  141. typedef TextConsole QEMUConsole;
  142. typedef struct CharDriverState CharDriverState;
  143. typedef struct VLANState VLANState;
  144. typedef struct QEMUFile QEMUFile;
  145. typedef struct i2c_bus i2c_bus;
  146. typedef struct i2c_slave i2c_slave;
  147. typedef struct SMBusDevice SMBusDevice;
  148. typedef struct QEMUTimer QEMUTimer;
  149. typedef struct PCIBus PCIBus;
  150. typedef struct PCIDevice PCIDevice;
  151. typedef struct SerialState SerialState;
  152. typedef struct IRQState *qemu_irq;
  153. struct pcmcia_card_s;
  154. /* CPU save/load. */
  155. void cpu_save(QEMUFile *f, void *opaque);
  156. int cpu_load(QEMUFile *f, void *opaque, int version_id);
  157. /* Force QEMU to stop what it's doing and service IO */
  158. void qemu_service_io(void);
  159. typedef struct QEMUIOVector {
  160. struct iovec *iov;
  161. int niov;
  162. int nalloc;
  163. size_t size;
  164. } QEMUIOVector;
  165. void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
  166. void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
  167. void qemu_iovec_destroy(QEMUIOVector *qiov);
  168. void qemu_iovec_reset(QEMUIOVector *qiov);
  169. void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
  170. void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
  171. #endif /* dyngen-exec.h hack */
  172. #endif