root / include / qemu-common.h @ 6ab7e546
History | View | Annotate | Download (12.1 kB)
1 | 9fb26641 | Orit Wasserman | |
---|---|---|---|
2 | 04509ad9 | Eduardo Habkost | /* Common header file that is included by all of QEMU.
|
3 | 04509ad9 | Eduardo Habkost | *
|
4 | 04509ad9 | Eduardo Habkost | * This file is supposed to be included only by .c files. No header file should
|
5 | 04509ad9 | Eduardo Habkost | * depend on qemu-common.h, as this would easily lead to circular header
|
6 | 04509ad9 | Eduardo Habkost | * dependencies.
|
7 | 04509ad9 | Eduardo Habkost | *
|
8 | 04509ad9 | Eduardo Habkost | * If a header file uses a definition from qemu-common.h, that definition
|
9 | 04509ad9 | Eduardo Habkost | * must be moved to a separate header file, and the header that uses it
|
10 | 04509ad9 | Eduardo Habkost | * must include that header.
|
11 | 04509ad9 | Eduardo Habkost | */
|
12 | faf07963 | pbrook | #ifndef QEMU_COMMON_H
|
13 | faf07963 | pbrook | #define QEMU_COMMON_H
|
14 | faf07963 | pbrook | |
15 | 1de7afc9 | Paolo Bonzini | #include "qemu/compiler.h" |
16 | beb6f0de | Kevin Wolf | #include "config-host.h" |
17 | 1de7afc9 | Paolo Bonzini | #include "qemu/typedefs.h" |
18 | beb6f0de | Kevin Wolf | |
19 | 332ae28d | Paolo Bonzini | #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
|
20 | 332ae28d | Paolo Bonzini | #define WORDS_ALIGNED
|
21 | 332ae28d | Paolo Bonzini | #endif
|
22 | 332ae28d | Paolo Bonzini | |
23 | 082b5557 | Blue Swirl | #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) |
24 | 24ebf5f3 | Paolo Bonzini | |
25 | faf07963 | pbrook | /* we put basic includes here to avoid repeating them in device drivers */
|
26 | faf07963 | pbrook | #include <stdlib.h> |
27 | faf07963 | pbrook | #include <stdio.h> |
28 | faf07963 | pbrook | #include <stdarg.h> |
29 | 11165820 | Paul Brook | #include <stdbool.h> |
30 | faf07963 | pbrook | #include <string.h> |
31 | c8906845 | balrog | #include <strings.h> |
32 | faf07963 | pbrook | #include <inttypes.h> |
33 | faf07963 | pbrook | #include <limits.h> |
34 | faf07963 | pbrook | #include <time.h> |
35 | faf07963 | pbrook | #include <ctype.h> |
36 | faf07963 | pbrook | #include <errno.h> |
37 | faf07963 | pbrook | #include <unistd.h> |
38 | faf07963 | pbrook | #include <fcntl.h> |
39 | faf07963 | pbrook | #include <sys/stat.h> |
40 | dcfd0865 | Hervé Poussineau | #include <sys/time.h> |
41 | 55616505 | Paul Brook | #include <assert.h> |
42 | 86f69a92 | Alexandre Raymond | #include <signal.h> |
43 | 14015304 | Anthony Liguori | #include <glib.h> |
44 | faf07963 | pbrook | |
45 | 082b5557 | Blue Swirl | #ifdef _WIN32
|
46 | 9c17d615 | Paolo Bonzini | #include "sysemu/os-win32.h" |
47 | 082b5557 | Blue Swirl | #endif
|
48 | 082b5557 | Blue Swirl | |
49 | 082b5557 | Blue Swirl | #ifdef CONFIG_POSIX
|
50 | 9c17d615 | Paolo Bonzini | #include "sysemu/os-posix.h" |
51 | 082b5557 | Blue Swirl | #endif
|
52 | 082b5557 | Blue Swirl | |
53 | faf07963 | pbrook | #ifndef O_LARGEFILE
|
54 | faf07963 | pbrook | #define O_LARGEFILE 0 |
55 | faf07963 | pbrook | #endif
|
56 | faf07963 | pbrook | #ifndef O_BINARY
|
57 | faf07963 | pbrook | #define O_BINARY 0 |
58 | faf07963 | pbrook | #endif
|
59 | 0e74e66b | Juan Quintela | #ifndef MAP_ANONYMOUS
|
60 | 0e74e66b | Juan Quintela | #define MAP_ANONYMOUS MAP_ANON
|
61 | 0e74e66b | Juan Quintela | #endif
|
62 | faf07963 | pbrook | #ifndef ENOMEDIUM
|
63 | faf07963 | pbrook | #define ENOMEDIUM ENODEV
|
64 | faf07963 | pbrook | #endif
|
65 | 4c955388 | Anthony Liguori | #if !defined(ENOTSUP)
|
66 | 2880bc32 | Juan Quintela | #define ENOTSUP 4096 |
67 | 2880bc32 | Juan Quintela | #endif
|
68 | 2084a8e3 | Paolo Bonzini | #if !defined(ECANCELED)
|
69 | 2084a8e3 | Paolo Bonzini | #define ECANCELED 4097 |
70 | 2084a8e3 | Paolo Bonzini | #endif
|
71 | 02582abd | Stefan Weil | #if !defined(EMEDIUMTYPE)
|
72 | 02582abd | Stefan Weil | #define EMEDIUMTYPE 4098 |
73 | 02582abd | Stefan Weil | #endif
|
74 | 3c9405a0 | Gerd Hoffmann | #ifndef TIME_MAX
|
75 | 3c9405a0 | Gerd Hoffmann | #define TIME_MAX LONG_MAX
|
76 | 3c9405a0 | Gerd Hoffmann | #endif
|
77 | faf07963 | pbrook | |
78 | c0fd260e | Stefan Weil | /* HOST_LONG_BITS is the size of a native pointer in bits. */
|
79 | c0fd260e | Stefan Weil | #if UINTPTR_MAX == UINT32_MAX
|
80 | c0fd260e | Stefan Weil | # define HOST_LONG_BITS 32 |
81 | c0fd260e | Stefan Weil | #elif UINTPTR_MAX == UINT64_MAX
|
82 | c0fd260e | Stefan Weil | # define HOST_LONG_BITS 64 |
83 | c0fd260e | Stefan Weil | #else
|
84 | c0fd260e | Stefan Weil | # error Unknown pointer size
|
85 | c0fd260e | Stefan Weil | #endif
|
86 | c0fd260e | Stefan Weil | |
87 | 6114fdb0 | Juan Quintela | #ifndef CONFIG_IOVEC
|
88 | 6114fdb0 | Juan Quintela | #define CONFIG_IOVEC
|
89 | bf9298b9 | aliguori | struct iovec {
|
90 | bf9298b9 | aliguori | void *iov_base;
|
91 | bf9298b9 | aliguori | size_t iov_len; |
92 | bf9298b9 | aliguori | }; |
93 | e2a305fb | Christoph Hellwig | /*
|
94 | e2a305fb | Christoph Hellwig | * Use the same value as Linux for now.
|
95 | e2a305fb | Christoph Hellwig | */
|
96 | e2a305fb | Christoph Hellwig | #define IOV_MAX 1024 |
97 | 331dadde | blueswir1 | #else
|
98 | 331dadde | blueswir1 | #include <sys/uio.h> |
99 | bf9298b9 | aliguori | #endif
|
100 | bf9298b9 | aliguori | |
101 | f868445a | Stefan Weil | typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) |
102 | f868445a | Stefan Weil | GCC_FMT_ATTR(2, 3); |
103 | f868445a | Stefan Weil | |
104 | faf07963 | pbrook | #ifdef _WIN32
|
105 | faf07963 | pbrook | #define fsync _commit
|
106 | 371c6489 | Stefan Weil | #if !defined(lseek)
|
107 | 371c6489 | Stefan Weil | # define lseek _lseeki64
|
108 | 371c6489 | Stefan Weil | #endif
|
109 | 64b85a8f | Blue Swirl | int qemu_ftruncate64(int, int64_t); |
110 | 371c6489 | Stefan Weil | #if !defined(ftruncate)
|
111 | 371c6489 | Stefan Weil | # define ftruncate qemu_ftruncate64
|
112 | 371c6489 | Stefan Weil | #endif
|
113 | faf07963 | pbrook | |
114 | faf07963 | pbrook | static inline char *realpath(const char *path, char *resolved_path) |
115 | faf07963 | pbrook | { |
116 | faf07963 | pbrook | _fullpath(resolved_path, path, _MAX_PATH); |
117 | faf07963 | pbrook | return resolved_path;
|
118 | faf07963 | pbrook | } |
119 | faf07963 | pbrook | #endif
|
120 | faf07963 | pbrook | |
121 | 946fb27c | Paolo Bonzini | /* icount */
|
122 | 946fb27c | Paolo Bonzini | void configure_icount(const char *option); |
123 | 946fb27c | Paolo Bonzini | extern int use_icount; |
124 | 946fb27c | Paolo Bonzini | |
125 | faf07963 | pbrook | /* FIXME: Remove NEED_CPU_H. */
|
126 | faf07963 | pbrook | #ifndef NEED_CPU_H
|
127 | faf07963 | pbrook | |
128 | 1de7afc9 | Paolo Bonzini | #include "qemu/osdep.h" |
129 | 1de7afc9 | Paolo Bonzini | #include "qemu/bswap.h" |
130 | faf07963 | pbrook | |
131 | faf07963 | pbrook | #else
|
132 | faf07963 | pbrook | |
133 | faf07963 | pbrook | #include "cpu.h" |
134 | faf07963 | pbrook | |
135 | faf07963 | pbrook | #endif /* !defined(NEED_CPU_H) */ |
136 | faf07963 | pbrook | |
137 | 3bbbee18 | Andreas Färber | /* main function, renamed */
|
138 | 3bbbee18 | Andreas Färber | #if defined(CONFIG_COCOA)
|
139 | 3bbbee18 | Andreas Färber | int qemu_main(int argc, char **argv, char **envp); |
140 | 3bbbee18 | Andreas Färber | #endif
|
141 | 3bbbee18 | Andreas Färber | |
142 | f6503059 | balrog | void qemu_get_timedate(struct tm *tm, int offset); |
143 | f6503059 | balrog | int qemu_timedate_diff(struct tm *tm); |
144 | f6503059 | balrog | |
145 | c8057f95 | Peter Maydell | /**
|
146 | c8057f95 | Peter Maydell | * is_help_option:
|
147 | c8057f95 | Peter Maydell | * @s: string to test
|
148 | c8057f95 | Peter Maydell | *
|
149 | c8057f95 | Peter Maydell | * Check whether @s is one of the standard strings which indicate
|
150 | c8057f95 | Peter Maydell | * that the user is asking for a list of the valid values for a
|
151 | c8057f95 | Peter Maydell | * command option like -cpu or -M. The current accepted strings
|
152 | c8057f95 | Peter Maydell | * are 'help' and '?'. '?' is deprecated (it is a shell wildcard
|
153 | c8057f95 | Peter Maydell | * which makes it annoying to use in a reliable way) but provided
|
154 | c8057f95 | Peter Maydell | * for backwards compatibility.
|
155 | c8057f95 | Peter Maydell | *
|
156 | c8057f95 | Peter Maydell | * Returns: true if @s is a request for a list.
|
157 | c8057f95 | Peter Maydell | */
|
158 | c8057f95 | Peter Maydell | static inline bool is_help_option(const char *s) |
159 | c8057f95 | Peter Maydell | { |
160 | c8057f95 | Peter Maydell | return !strcmp(s, "?") || !strcmp(s, "help"); |
161 | c8057f95 | Peter Maydell | } |
162 | c8057f95 | Peter Maydell | |
163 | faf07963 | pbrook | /* cutils.c */
|
164 | faf07963 | pbrook | void pstrcpy(char *buf, int buf_size, const char *str); |
165 | 2a025ae4 | Dmitry Fleytman | void strpadcpy(char *buf, int buf_size, const char *str, char pad); |
166 | faf07963 | pbrook | char *pstrcat(char *buf, int buf_size, const char *s); |
167 | faf07963 | pbrook | int strstart(const char *str, const char *val, const char **ptr); |
168 | faf07963 | pbrook | int stristart(const char *str, const char *val, const char **ptr); |
169 | d43277c5 | Blue Swirl | int qemu_strnlen(const char *s, int max_len); |
170 | faf07963 | pbrook | time_t mktimegm(struct tm *tm);
|
171 | ad46db9a | blueswir1 | int qemu_fls(int i); |
172 | 6f1953c4 | Christoph Hellwig | int qemu_fdatasync(int fd); |
173 | db1a4972 | Paolo Bonzini | int fcntl_setfl(int fd, int flag); |
174 | 443916d1 | Stefan Berger | int qemu_parse_fd(const char *param); |
175 | d8427002 | Jes Sorensen | |
176 | e3f9fe2d | Eduardo Habkost | int parse_uint(const char *s, unsigned long long *value, char **endptr, |
177 | e3f9fe2d | Eduardo Habkost | int base);
|
178 | e3f9fe2d | Eduardo Habkost | int parse_uint_full(const char *s, unsigned long long *value, int base); |
179 | e3f9fe2d | Eduardo Habkost | |
180 | d7142456 | Jes Sorensen | /*
|
181 | d7142456 | Jes Sorensen | * strtosz() suffixes used to specify the default treatment of an
|
182 | d7142456 | Jes Sorensen | * argument passed to strtosz() without an explicit suffix.
|
183 | d7142456 | Jes Sorensen | * These should be defined using upper case characters in the range
|
184 | d7142456 | Jes Sorensen | * A-Z, as strtosz() will use qemu_toupper() on the given argument
|
185 | d7142456 | Jes Sorensen | * prior to comparison.
|
186 | d7142456 | Jes Sorensen | */
|
187 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_TB 'T' |
188 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_GB 'G' |
189 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_MB 'M' |
190 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_KB 'K' |
191 | d8427002 | Jes Sorensen | #define STRTOSZ_DEFSUFFIX_B 'B' |
192 | 70b4f4bb | Jes Sorensen | int64_t strtosz(const char *nptr, char **end); |
193 | 70b4f4bb | Jes Sorensen | int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix); |
194 | a732e1ba | Joerg Roedel | int64_t strtosz_suffix_unit(const char *nptr, char **end, |
195 | a732e1ba | Joerg Roedel | const char default_suffix, int64_t unit); |
196 | faf07963 | pbrook | |
197 | 37022086 | Blue Swirl | /* path.c */
|
198 | 37022086 | Blue Swirl | void init_paths(const char *prefix); |
199 | 37022086 | Blue Swirl | const char *path(const char *pathname); |
200 | 37022086 | Blue Swirl | |
201 | cd390083 | blueswir1 | #define qemu_isalnum(c) isalnum((unsigned char)(c)) |
202 | cd390083 | blueswir1 | #define qemu_isalpha(c) isalpha((unsigned char)(c)) |
203 | cd390083 | blueswir1 | #define qemu_iscntrl(c) iscntrl((unsigned char)(c)) |
204 | cd390083 | blueswir1 | #define qemu_isdigit(c) isdigit((unsigned char)(c)) |
205 | cd390083 | blueswir1 | #define qemu_isgraph(c) isgraph((unsigned char)(c)) |
206 | cd390083 | blueswir1 | #define qemu_islower(c) islower((unsigned char)(c)) |
207 | cd390083 | blueswir1 | #define qemu_isprint(c) isprint((unsigned char)(c)) |
208 | cd390083 | blueswir1 | #define qemu_ispunct(c) ispunct((unsigned char)(c)) |
209 | cd390083 | blueswir1 | #define qemu_isspace(c) isspace((unsigned char)(c)) |
210 | cd390083 | blueswir1 | #define qemu_isupper(c) isupper((unsigned char)(c)) |
211 | cd390083 | blueswir1 | #define qemu_isxdigit(c) isxdigit((unsigned char)(c)) |
212 | cd390083 | blueswir1 | #define qemu_tolower(c) tolower((unsigned char)(c)) |
213 | cd390083 | blueswir1 | #define qemu_toupper(c) toupper((unsigned char)(c)) |
214 | cd390083 | blueswir1 | #define qemu_isascii(c) isascii((unsigned char)(c)) |
215 | cd390083 | blueswir1 | #define qemu_toascii(c) toascii((unsigned char)(c)) |
216 | cd390083 | blueswir1 | |
217 | b152aa84 | Jes Sorensen | void *qemu_oom_check(void *ptr); |
218 | ca10f867 | aurel32 | |
219 | 7c7c0629 | Juan Quintela | ssize_t qemu_write_full(int fd, const void *buf, size_t count) |
220 | 7c7c0629 | Juan Quintela | QEMU_WARN_UNUSED_RESULT; |
221 | 993295fe | Paolo Bonzini | ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags) |
222 | 993295fe | Paolo Bonzini | QEMU_WARN_UNUSED_RESULT; |
223 | 8c5135f9 | Paolo Bonzini | ssize_t qemu_recv_full(int fd, void *buf, size_t count, int flags) |
224 | 993295fe | Paolo Bonzini | QEMU_WARN_UNUSED_RESULT; |
225 | 40ff6d7e | Kevin Wolf | |
226 | 40ff6d7e | Kevin Wolf | #ifndef _WIN32
|
227 | 40ff6d7e | Kevin Wolf | int qemu_pipe(int pipefd[2]); |
228 | 40ff6d7e | Kevin Wolf | #endif
|
229 | 40ff6d7e | Kevin Wolf | |
230 | 00aa0040 | Blue Swirl | #ifdef _WIN32
|
231 | 58455eb9 | Stefan Weil | /* MinGW needs type casts for the 'buf' and 'optval' arguments. */
|
232 | 58455eb9 | Stefan Weil | #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
|
233 | 58455eb9 | Stefan Weil | getsockopt(sockfd, level, optname, (void *)optval, optlen)
|
234 | 58455eb9 | Stefan Weil | #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
|
235 | 58455eb9 | Stefan Weil | setsockopt(sockfd, level, optname, (const void *)optval, optlen) |
236 | 00aa0040 | Blue Swirl | #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags) |
237 | 73062dfe | Stefan Weil | #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
|
238 | 73062dfe | Stefan Weil | sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen) |
239 | 00aa0040 | Blue Swirl | #else
|
240 | 58455eb9 | Stefan Weil | #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
|
241 | 58455eb9 | Stefan Weil | getsockopt(sockfd, level, optname, optval, optlen) |
242 | 58455eb9 | Stefan Weil | #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
|
243 | 58455eb9 | Stefan Weil | setsockopt(sockfd, level, optname, optval, optlen) |
244 | 00aa0040 | Blue Swirl | #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
|
245 | 73062dfe | Stefan Weil | #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
|
246 | 73062dfe | Stefan Weil | sendto(sockfd, buf, len, flags, destaddr, addrlen) |
247 | 00aa0040 | Blue Swirl | #endif
|
248 | 00aa0040 | Blue Swirl | |
249 | 87ecb68b | pbrook | /* Error handling. */
|
250 | 87ecb68b | pbrook | |
251 | e5924d89 | Stefan Weil | void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2); |
252 | 87ecb68b | pbrook | |
253 | 87ecb68b | pbrook | struct ParallelIOArg {
|
254 | 87ecb68b | pbrook | void *buffer;
|
255 | 87ecb68b | pbrook | int count;
|
256 | 87ecb68b | pbrook | }; |
257 | 87ecb68b | pbrook | |
258 | 87ecb68b | pbrook | typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size); |
259 | 87ecb68b | pbrook | |
260 | 186993ee | Michael S. Tsirkin | typedef uint64_t pcibus_t;
|
261 | 186993ee | Michael S. Tsirkin | |
262 | 4e4fa398 | Jan Kiszka | typedef enum LostTickPolicy { |
263 | 4e4fa398 | Jan Kiszka | LOST_TICK_DISCARD, |
264 | 4e4fa398 | Jan Kiszka | LOST_TICK_DELAY, |
265 | 4e4fa398 | Jan Kiszka | LOST_TICK_MERGE, |
266 | 4e4fa398 | Jan Kiszka | LOST_TICK_SLEW, |
267 | 1ce05125 | Paolo Bonzini | LOST_TICK_MAX |
268 | 4e4fa398 | Jan Kiszka | } LostTickPolicy; |
269 | 4e4fa398 | Jan Kiszka | |
270 | 679042f0 | Anthony PERARD | typedef struct PCIHostDeviceAddress { |
271 | 679042f0 | Anthony PERARD | unsigned int domain; |
272 | 679042f0 | Anthony PERARD | unsigned int bus; |
273 | 679042f0 | Anthony PERARD | unsigned int slot; |
274 | 679042f0 | Anthony PERARD | unsigned int function; |
275 | 679042f0 | Anthony PERARD | } PCIHostDeviceAddress; |
276 | 679042f0 | Anthony PERARD | |
277 | d5ab9713 | Jan Kiszka | void tcg_exec_init(unsigned long tb_size); |
278 | d5ab9713 | Jan Kiszka | bool tcg_enabled(void); |
279 | d5ab9713 | Jan Kiszka | |
280 | d5ab9713 | Jan Kiszka | void cpu_exec_init_all(void); |
281 | d2053c3c | Blue Swirl | |
282 | b3c7724c | pbrook | /* CPU save/load. */
|
283 | b3c7724c | pbrook | void cpu_save(QEMUFile *f, void *opaque); |
284 | b3c7724c | pbrook | int cpu_load(QEMUFile *f, void *opaque, int version_id); |
285 | b3c7724c | pbrook | |
286 | 8edac960 | aliguori | /* Unblock cpu */
|
287 | 46d62fac | Jan Kiszka | void qemu_cpu_kick_self(void); |
288 | 8edac960 | aliguori | |
289 | e82bcec2 | Marcelo Tosatti | /* work queue */
|
290 | e82bcec2 | Marcelo Tosatti | struct qemu_work_item {
|
291 | e82bcec2 | Marcelo Tosatti | struct qemu_work_item *next;
|
292 | e82bcec2 | Marcelo Tosatti | void (*func)(void *data); |
293 | e82bcec2 | Marcelo Tosatti | void *data;
|
294 | e82bcec2 | Marcelo Tosatti | int done;
|
295 | e82bcec2 | Marcelo Tosatti | }; |
296 | e82bcec2 | Marcelo Tosatti | |
297 | 0bf46a40 | aliguori | #ifdef CONFIG_USER_ONLY
|
298 | 75a192aa | Andreas Färber | static inline void qemu_init_vcpu(void *env) |
299 | 75a192aa | Andreas Färber | { |
300 | 75a192aa | Andreas Färber | } |
301 | 0bf46a40 | aliguori | #else
|
302 | 0bf46a40 | aliguori | void qemu_init_vcpu(void *env); |
303 | 0bf46a40 | aliguori | #endif
|
304 | 0bf46a40 | aliguori | |
305 | 8c5135f9 | Paolo Bonzini | |
306 | 8c5135f9 | Paolo Bonzini | /**
|
307 | 2fc8ae1d | Michael Tokarev | * Sends a (part of) iovec down a socket, yielding when the socket is full, or
|
308 | 2fc8ae1d | Michael Tokarev | * Receives data into a (part of) iovec from a socket,
|
309 | 2fc8ae1d | Michael Tokarev | * yielding when there is no data in the socket.
|
310 | 2fc8ae1d | Michael Tokarev | * The same interface as qemu_sendv_recvv(), with added yielding.
|
311 | 2fc8ae1d | Michael Tokarev | * XXX should mark these as coroutine_fn
|
312 | 8c5135f9 | Paolo Bonzini | */
|
313 | 2fc8ae1d | Michael Tokarev | ssize_t qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt, |
314 | 2fc8ae1d | Michael Tokarev | size_t offset, size_t bytes, bool do_send);
|
315 | 2fc8ae1d | Michael Tokarev | #define qemu_co_recvv(sockfd, iov, iov_cnt, offset, bytes) \
|
316 | 2fc8ae1d | Michael Tokarev | qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, false)
|
317 | 2fc8ae1d | Michael Tokarev | #define qemu_co_sendv(sockfd, iov, iov_cnt, offset, bytes) \
|
318 | 2fc8ae1d | Michael Tokarev | qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, true)
|
319 | 8c5135f9 | Paolo Bonzini | |
320 | 8c5135f9 | Paolo Bonzini | /**
|
321 | 2fc8ae1d | Michael Tokarev | * The same as above, but with just a single buffer
|
322 | 8c5135f9 | Paolo Bonzini | */
|
323 | 2fc8ae1d | Michael Tokarev | ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send); |
324 | 2fc8ae1d | Michael Tokarev | #define qemu_co_recv(sockfd, buf, bytes) \
|
325 | 2fc8ae1d | Michael Tokarev | qemu_co_send_recv(sockfd, buf, bytes, false)
|
326 | 2fc8ae1d | Michael Tokarev | #define qemu_co_send(sockfd, buf, bytes) \
|
327 | 2fc8ae1d | Michael Tokarev | qemu_co_send_recv(sockfd, buf, bytes, true)
|
328 | 8c5135f9 | Paolo Bonzini | |
329 | 44e3ee8a | aliguori | typedef struct QEMUIOVector { |
330 | 44e3ee8a | aliguori | struct iovec *iov;
|
331 | 44e3ee8a | aliguori | int niov;
|
332 | 44e3ee8a | aliguori | int nalloc;
|
333 | 249aa745 | aliguori | size_t size; |
334 | 44e3ee8a | aliguori | } QEMUIOVector; |
335 | 44e3ee8a | aliguori | |
336 | 44e3ee8a | aliguori | void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); |
337 | 522584a5 | aliguori | void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov); |
338 | 44e3ee8a | aliguori | void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len); |
339 | 1b093c48 | Michael Tokarev | void qemu_iovec_concat(QEMUIOVector *dst,
|
340 | 1b093c48 | Michael Tokarev | QEMUIOVector *src, size_t soffset, size_t sbytes); |
341 | 530c0bbd | Stefan Hajnoczi | void qemu_iovec_concat_iov(QEMUIOVector *dst,
|
342 | 530c0bbd | Stefan Hajnoczi | struct iovec *src_iov, unsigned int src_cnt, |
343 | 530c0bbd | Stefan Hajnoczi | size_t soffset, size_t sbytes); |
344 | 44e3ee8a | aliguori | void qemu_iovec_destroy(QEMUIOVector *qiov);
|
345 | be959463 | aliguori | void qemu_iovec_reset(QEMUIOVector *qiov);
|
346 | d5e6b161 | Michael Tokarev | size_t qemu_iovec_to_buf(QEMUIOVector *qiov, size_t offset, |
347 | d5e6b161 | Michael Tokarev | void *buf, size_t bytes);
|
348 | 03396148 | Michael Tokarev | size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset, |
349 | 03396148 | Michael Tokarev | const void *buf, size_t bytes); |
350 | 3d9b4925 | Michael Tokarev | size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset, |
351 | 3d9b4925 | Michael Tokarev | int fillc, size_t bytes);
|
352 | 44e3ee8a | aliguori | |
353 | 1a6d39fd | Stefan Hajnoczi | bool buffer_is_zero(const void *buf, size_t len); |
354 | 1a6d39fd | Stefan Hajnoczi | |
355 | 6b837bc4 | Jes Sorensen | void qemu_progress_init(int enabled, float min_skip); |
356 | 6b837bc4 | Jes Sorensen | void qemu_progress_end(void); |
357 | 3bfe4dbf | Jes Sorensen | void qemu_progress_print(float delta, int max); |
358 | 31459f46 | Ronnie Sahlberg | const char *qemu_get_vm_name(void); |
359 | 6b837bc4 | Jes Sorensen | |
360 | 082b5557 | Blue Swirl | #define QEMU_FILE_TYPE_BIOS 0 |
361 | 082b5557 | Blue Swirl | #define QEMU_FILE_TYPE_KEYMAP 1 |
362 | 082b5557 | Blue Swirl | char *qemu_find_file(int type, const char *name); |
363 | 082b5557 | Blue Swirl | |
364 | 082b5557 | Blue Swirl | /* OS specific functions */
|
365 | 082b5557 | Blue Swirl | void os_setup_early_signal_handling(void); |
366 | 082b5557 | Blue Swirl | char *os_find_datadir(const char *argv0); |
367 | 082b5557 | Blue Swirl | void os_parse_cmd_args(int index, const char *optarg); |
368 | 082b5557 | Blue Swirl | void os_pidfile_error(void); |
369 | 082b5557 | Blue Swirl | |
370 | abd0c6bd | Paul Brook | /* Convert a byte between binary and BCD. */
|
371 | abd0c6bd | Paul Brook | static inline uint8_t to_bcd(uint8_t val) |
372 | abd0c6bd | Paul Brook | { |
373 | abd0c6bd | Paul Brook | return ((val / 10) << 4) | (val % 10); |
374 | abd0c6bd | Paul Brook | } |
375 | abd0c6bd | Paul Brook | |
376 | abd0c6bd | Paul Brook | static inline uint8_t from_bcd(uint8_t val) |
377 | abd0c6bd | Paul Brook | { |
378 | abd0c6bd | Paul Brook | return ((val >> 4) * 10) + (val & 0x0f); |
379 | abd0c6bd | Paul Brook | } |
380 | abd0c6bd | Paul Brook | |
381 | 338b922e | malc | /* compute with 96 bit intermediate result: (a*b)/c */
|
382 | 338b922e | malc | static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) |
383 | 338b922e | malc | { |
384 | 338b922e | malc | union {
|
385 | 338b922e | malc | uint64_t ll; |
386 | 338b922e | malc | struct {
|
387 | 338b922e | malc | #ifdef HOST_WORDS_BIGENDIAN
|
388 | 338b922e | malc | uint32_t high, low; |
389 | 338b922e | malc | #else
|
390 | 338b922e | malc | uint32_t low, high; |
391 | 338b922e | malc | #endif
|
392 | 338b922e | malc | } l; |
393 | 338b922e | malc | } u, res; |
394 | 338b922e | malc | uint64_t rl, rh; |
395 | 338b922e | malc | |
396 | 338b922e | malc | u.ll = a; |
397 | 338b922e | malc | rl = (uint64_t)u.l.low * (uint64_t)b; |
398 | 338b922e | malc | rh = (uint64_t)u.l.high * (uint64_t)b; |
399 | 338b922e | malc | rh += (rl >> 32);
|
400 | 338b922e | malc | res.l.high = rh / c; |
401 | 338b922e | malc | res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; |
402 | 338b922e | malc | return res.ll;
|
403 | 338b922e | malc | } |
404 | 338b922e | malc | |
405 | 3951690a | Stefan Hajnoczi | /* Round number down to multiple */
|
406 | 3951690a | Stefan Hajnoczi | #define QEMU_ALIGN_DOWN(n, m) ((n) / (m) * (m))
|
407 | 3951690a | Stefan Hajnoczi | |
408 | 3951690a | Stefan Hajnoczi | /* Round number up to multiple */
|
409 | 3951690a | Stefan Hajnoczi | #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m)) |
410 | 3951690a | Stefan Hajnoczi | |
411 | 9fb26641 | Orit Wasserman | static inline bool is_power_of_2(uint64_t value) |
412 | 9fb26641 | Orit Wasserman | { |
413 | 9fb26641 | Orit Wasserman | if (!value) {
|
414 | 9fb26641 | Orit Wasserman | return 0; |
415 | 9fb26641 | Orit Wasserman | } |
416 | 9fb26641 | Orit Wasserman | |
417 | 9fb26641 | Orit Wasserman | return !(value & (value - 1)); |
418 | 9fb26641 | Orit Wasserman | } |
419 | 9fb26641 | Orit Wasserman | |
420 | 9fb26641 | Orit Wasserman | /* round down to the nearest power of 2*/
|
421 | 9fb26641 | Orit Wasserman | int64_t pow2floor(int64_t value); |
422 | 9fb26641 | Orit Wasserman | |
423 | 1de7afc9 | Paolo Bonzini | #include "qemu/module.h" |
424 | 0bfe3ca5 | Anthony Liguori | |
425 | e6546bb9 | Orit Wasserman | /*
|
426 | e6546bb9 | Orit Wasserman | * Implementation of ULEB128 (http://en.wikipedia.org/wiki/LEB128)
|
427 | e6546bb9 | Orit Wasserman | * Input is limited to 14-bit numbers
|
428 | e6546bb9 | Orit Wasserman | */
|
429 | e6546bb9 | Orit Wasserman | |
430 | e6546bb9 | Orit Wasserman | int uleb128_encode_small(uint8_t *out, uint32_t n);
|
431 | e6546bb9 | Orit Wasserman | int uleb128_decode_small(const uint8_t *in, uint32_t *n); |
432 | e6546bb9 | Orit Wasserman | |
433 | faf07963 | pbrook | #endif |