util: move declarations out of qemu-common.h
[qemu/ar7.git] / include / qemu-common.h
blob163bcbb861b7026b74e272b5bfd7fdaa10117086
2 /* Common header file that is included by all of QEMU.
4 * This file is supposed to be included only by .c files. No header file should
5 * depend on qemu-common.h, as this would easily lead to circular header
6 * dependencies.
8 * If a header file uses a definition from qemu-common.h, that definition
9 * must be moved to a separate header file, and the header that uses it
10 * must include that header.
12 #ifndef QEMU_COMMON_H
13 #define QEMU_COMMON_H
15 #include "qemu/fprintf-fn.h"
17 #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
18 #define WORDS_ALIGNED
19 #endif
21 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
23 #include "qemu/option.h"
24 #include "qemu/host-utils.h"
26 void cpu_ticks_init(void);
28 /* icount */
29 void configure_icount(QemuOpts *opts, Error **errp);
30 extern int use_icount;
31 extern int icount_align_option;
32 /* drift information for info jit command */
33 extern int64_t max_delay;
34 extern int64_t max_advance;
35 void dump_drift_info(FILE *f, fprintf_function cpu_fprintf);
37 #include "qemu/bswap.h"
39 /* FIXME: Remove NEED_CPU_H. */
40 #ifdef NEED_CPU_H
41 #include "cpu.h"
42 #endif /* !defined(NEED_CPU_H) */
44 /* main function, renamed */
45 #if defined(CONFIG_COCOA)
46 int qemu_main(int argc, char **argv, char **envp);
47 #endif
49 void qemu_get_timedate(struct tm *tm, int offset);
50 int qemu_timedate_diff(struct tm *tm);
52 #define qemu_isalnum(c) isalnum((unsigned char)(c))
53 #define qemu_isalpha(c) isalpha((unsigned char)(c))
54 #define qemu_iscntrl(c) iscntrl((unsigned char)(c))
55 #define qemu_isdigit(c) isdigit((unsigned char)(c))
56 #define qemu_isgraph(c) isgraph((unsigned char)(c))
57 #define qemu_islower(c) islower((unsigned char)(c))
58 #define qemu_isprint(c) isprint((unsigned char)(c))
59 #define qemu_ispunct(c) ispunct((unsigned char)(c))
60 #define qemu_isspace(c) isspace((unsigned char)(c))
61 #define qemu_isupper(c) isupper((unsigned char)(c))
62 #define qemu_isxdigit(c) isxdigit((unsigned char)(c))
63 #define qemu_tolower(c) tolower((unsigned char)(c))
64 #define qemu_toupper(c) toupper((unsigned char)(c))
65 #define qemu_isascii(c) isascii((unsigned char)(c))
66 #define qemu_toascii(c) toascii((unsigned char)(c))
68 void *qemu_oom_check(void *ptr);
70 ssize_t qemu_write_full(int fd, const void *buf, size_t count)
71 QEMU_WARN_UNUSED_RESULT;
73 #ifndef _WIN32
74 int qemu_pipe(int pipefd[2]);
75 /* like openpty() but also makes it raw; return master fd */
76 int qemu_openpty_raw(int *aslave, char *pty_name);
77 #endif
79 #ifdef _WIN32
80 /* MinGW needs type casts for the 'buf' and 'optval' arguments. */
81 #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
82 getsockopt(sockfd, level, optname, (void *)optval, optlen)
83 #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
84 setsockopt(sockfd, level, optname, (const void *)optval, optlen)
85 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
86 #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
87 sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen)
88 #else
89 #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
90 getsockopt(sockfd, level, optname, optval, optlen)
91 #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
92 setsockopt(sockfd, level, optname, optval, optlen)
93 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
94 #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
95 sendto(sockfd, buf, len, flags, destaddr, addrlen)
96 #endif
98 void tcg_exec_init(unsigned long tb_size);
99 bool tcg_enabled(void);
101 void cpu_exec_init_all(void);
103 /* Unblock cpu */
104 void qemu_cpu_kick_self(void);
106 /* work queue */
107 struct qemu_work_item {
108 struct qemu_work_item *next;
109 void (*func)(void *data);
110 void *data;
111 int done;
112 bool free;
117 * Sends a (part of) iovec down a socket, yielding when the socket is full, or
118 * Receives data into a (part of) iovec from a socket,
119 * yielding when there is no data in the socket.
120 * The same interface as qemu_sendv_recvv(), with added yielding.
121 * XXX should mark these as coroutine_fn
123 ssize_t qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt,
124 size_t offset, size_t bytes, bool do_send);
125 #define qemu_co_recvv(sockfd, iov, iov_cnt, offset, bytes) \
126 qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, false)
127 #define qemu_co_sendv(sockfd, iov, iov_cnt, offset, bytes) \
128 qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, true)
131 * The same as above, but with just a single buffer
133 ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send);
134 #define qemu_co_recv(sockfd, buf, bytes) \
135 qemu_co_send_recv(sockfd, buf, bytes, false)
136 #define qemu_co_send(sockfd, buf, bytes) \
137 qemu_co_send_recv(sockfd, buf, bytes, true)
139 void qemu_progress_init(int enabled, float min_skip);
140 void qemu_progress_end(void);
141 void qemu_progress_print(float delta, int max);
142 const char *qemu_get_vm_name(void);
144 #define QEMU_FILE_TYPE_BIOS 0
145 #define QEMU_FILE_TYPE_KEYMAP 1
146 char *qemu_find_file(int type, const char *name);
148 /* OS specific functions */
149 void os_setup_early_signal_handling(void);
150 char *os_find_datadir(void);
151 void os_parse_cmd_args(int index, const char *optarg);
153 #include "qemu/module.h"
156 * Hexdump a buffer to a file. An optional string prefix is added to every line
159 void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size);
162 * helper to parse debug environment variables
164 int parse_debug_env(const char *name, int max, int initial);
166 const char *qemu_ether_ntoa(const MACAddr *mac);
167 void page_size_init(void);
169 /* returns non-zero if dump is in progress, otherwise zero is
170 * returned. */
171 bool dump_in_progress(void);
173 #endif