]> Git Repo - qemu.git/blob - qemu-common.h
Introduce qemu_write_full()
[qemu.git] / qemu-common.h
1 /* Common header file that is included by all of qemu.  */
2 #ifndef QEMU_COMMON_H
3 #define QEMU_COMMON_H
4
5 #include "config-host.h"
6
7 #define QEMU_NORETURN __attribute__ ((__noreturn__))
8 #ifdef CONFIG_GCC_ATTRIBUTE_WARN_UNUSED_RESULT
9 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
10 #else
11 #define QEMU_WARN_UNUSED_RESULT
12 #endif
13
14 /* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
15    cannot include the following headers without conflicts. This condition has
16    to be removed once dyngen is gone. */
17 #ifndef __DYNGEN_EXEC_H__
18
19 /* we put basic includes here to avoid repeating them in device drivers */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <strings.h>
25 #include <inttypes.h>
26 #include <limits.h>
27 #include <time.h>
28 #include <ctype.h>
29 #include <errno.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <sys/stat.h>
33 #include <assert.h>
34
35 #ifndef O_LARGEFILE
36 #define O_LARGEFILE 0
37 #endif
38 #ifndef O_BINARY
39 #define O_BINARY 0
40 #endif
41 #ifndef MAP_ANONYMOUS
42 #define MAP_ANONYMOUS MAP_ANON
43 #endif
44 #ifndef ENOMEDIUM
45 #define ENOMEDIUM ENODEV
46 #endif
47 #if !defined(ENOTSUP)
48 #define ENOTSUP 4096
49 #endif
50
51 #ifndef CONFIG_IOVEC
52 #define CONFIG_IOVEC
53 struct iovec {
54     void *iov_base;
55     size_t iov_len;
56 };
57 #else
58 #include <sys/uio.h>
59 #endif
60
61 #ifdef _WIN32
62 #define fsync _commit
63 #define lseek _lseeki64
64 extern int qemu_ftruncate64(int, int64_t);
65 #define ftruncate qemu_ftruncate64
66
67 static inline char *realpath(const char *path, char *resolved_path)
68 {
69     _fullpath(resolved_path, path, _MAX_PATH);
70     return resolved_path;
71 }
72
73 #define PRId64 "I64d"
74 #define PRIx64 "I64x"
75 #define PRIu64 "I64u"
76 #define PRIo64 "I64o"
77 #endif
78
79 /* FIXME: Remove NEED_CPU_H.  */
80 #ifndef NEED_CPU_H
81
82 #include <setjmp.h>
83 #include "osdep.h"
84 #include "bswap.h"
85
86 #else
87
88 #include "cpu.h"
89
90 #endif /* !defined(NEED_CPU_H) */
91
92 /* bottom halves */
93 typedef struct QEMUBH QEMUBH;
94
95 typedef void QEMUBHFunc(void *opaque);
96
97 void async_context_push(void);
98 void async_context_pop(void);
99 int get_async_context_id(void);
100
101 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
102 void qemu_bh_schedule(QEMUBH *bh);
103 /* Bottom halfs that are scheduled from a bottom half handler are instantly
104  * invoked.  This can create an infinite loop if a bottom half handler
105  * schedules itself.  qemu_bh_schedule_idle() avoids this infinite loop by
106  * ensuring that the bottom half isn't executed until the next main loop
107  * iteration.
108  */
109 void qemu_bh_schedule_idle(QEMUBH *bh);
110 void qemu_bh_cancel(QEMUBH *bh);
111 void qemu_bh_delete(QEMUBH *bh);
112 int qemu_bh_poll(void);
113 void qemu_bh_update_timeout(int *timeout);
114
115 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
116
117 void qemu_get_timedate(struct tm *tm, int offset);
118 int qemu_timedate_diff(struct tm *tm);
119
120 /* cutils.c */
121 void pstrcpy(char *buf, int buf_size, const char *str);
122 char *pstrcat(char *buf, int buf_size, const char *s);
123 int strstart(const char *str, const char *val, const char **ptr);
124 int stristart(const char *str, const char *val, const char **ptr);
125 int qemu_strnlen(const char *s, int max_len);
126 time_t mktimegm(struct tm *tm);
127 int qemu_fls(int i);
128 int qemu_fdatasync(int fd);
129
130 /* path.c */
131 void init_paths(const char *prefix);
132 const char *path(const char *pathname);
133
134 #define qemu_isalnum(c)         isalnum((unsigned char)(c))
135 #define qemu_isalpha(c)         isalpha((unsigned char)(c))
136 #define qemu_iscntrl(c)         iscntrl((unsigned char)(c))
137 #define qemu_isdigit(c)         isdigit((unsigned char)(c))
138 #define qemu_isgraph(c)         isgraph((unsigned char)(c))
139 #define qemu_islower(c)         islower((unsigned char)(c))
140 #define qemu_isprint(c)         isprint((unsigned char)(c))
141 #define qemu_ispunct(c)         ispunct((unsigned char)(c))
142 #define qemu_isspace(c)         isspace((unsigned char)(c))
143 #define qemu_isupper(c)         isupper((unsigned char)(c))
144 #define qemu_isxdigit(c)        isxdigit((unsigned char)(c))
145 #define qemu_tolower(c)         tolower((unsigned char)(c))
146 #define qemu_toupper(c)         toupper((unsigned char)(c))
147 #define qemu_isascii(c)         isascii((unsigned char)(c))
148 #define qemu_toascii(c)         toascii((unsigned char)(c))
149
150 void *qemu_malloc(size_t size);
151 void *qemu_realloc(void *ptr, size_t size);
152 void *qemu_mallocz(size_t size);
153 void qemu_free(void *ptr);
154 char *qemu_strdup(const char *str);
155 char *qemu_strndup(const char *str, size_t size);
156
157 void *get_mmap_addr(unsigned long size);
158
159
160 void qemu_mutex_lock_iothread(void);
161 void qemu_mutex_unlock_iothread(void);
162
163 int qemu_open(const char *name, int flags, ...);
164 ssize_t qemu_write_full(int fd, const void *buf, size_t count);
165 void qemu_set_cloexec(int fd);
166
167 #ifndef _WIN32
168 int qemu_pipe(int pipefd[2]);
169 #endif
170
171 /* Error handling.  */
172
173 void QEMU_NORETURN hw_error(const char *fmt, ...)
174     __attribute__ ((__format__ (__printf__, 1, 2)));
175
176 /* IO callbacks.  */
177 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
178 typedef int IOCanRWHandler(void *opaque);
179 typedef void IOHandler(void *opaque);
180
181 struct ParallelIOArg {
182     void *buffer;
183     int count;
184 };
185
186 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
187
188 /* A load of opaque types so that device init declarations don't have to
189    pull in all the real definitions.  */
190 typedef struct NICInfo NICInfo;
191 typedef struct HCIInfo HCIInfo;
192 typedef struct AudioState AudioState;
193 typedef struct BlockDriverState BlockDriverState;
194 typedef struct DisplayState DisplayState;
195 typedef struct DisplayChangeListener DisplayChangeListener;
196 typedef struct DisplaySurface DisplaySurface;
197 typedef struct DisplayAllocator DisplayAllocator;
198 typedef struct PixelFormat PixelFormat;
199 typedef struct TextConsole TextConsole;
200 typedef TextConsole QEMUConsole;
201 typedef struct CharDriverState CharDriverState;
202 typedef struct MACAddr MACAddr;
203 typedef struct VLANState VLANState;
204 typedef struct VLANClientState VLANClientState;
205 typedef struct QEMUFile QEMUFile;
206 typedef struct i2c_bus i2c_bus;
207 typedef struct i2c_slave i2c_slave;
208 typedef struct SMBusDevice SMBusDevice;
209 typedef struct QEMUTimer QEMUTimer;
210 typedef struct PCIHostState PCIHostState;
211 typedef struct PCIExpressHost PCIExpressHost;
212 typedef struct PCIBus PCIBus;
213 typedef struct PCIDevice PCIDevice;
214 typedef struct SerialState SerialState;
215 typedef struct IRQState *qemu_irq;
216 typedef struct PCMCIACardState PCMCIACardState;
217 typedef struct MouseTransformInfo MouseTransformInfo;
218 typedef struct uWireSlave uWireSlave;
219 typedef struct I2SCodec I2SCodec;
220 typedef struct DeviceState DeviceState;
221 typedef struct SSIBus SSIBus;
222
223 /* CPU save/load.  */
224 void cpu_save(QEMUFile *f, void *opaque);
225 int cpu_load(QEMUFile *f, void *opaque, int version_id);
226
227 /* Force QEMU to stop what it's doing and service IO */
228 void qemu_service_io(void);
229
230 /* Force QEMU to process pending events */
231 void qemu_notify_event(void);
232
233 /* Unblock cpu */
234 void qemu_cpu_kick(void *env);
235 int qemu_cpu_self(void *env);
236
237 #ifdef CONFIG_USER_ONLY
238 #define qemu_init_vcpu(env) do { } while (0)
239 #else
240 void qemu_init_vcpu(void *env);
241 #endif
242
243 typedef struct QEMUIOVector {
244     struct iovec *iov;
245     int niov;
246     int nalloc;
247     size_t size;
248 } QEMUIOVector;
249
250 void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
251 void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
252 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
253 void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
254 void qemu_iovec_destroy(QEMUIOVector *qiov);
255 void qemu_iovec_reset(QEMUIOVector *qiov);
256 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
257 void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
258
259 struct Monitor;
260 typedef struct Monitor Monitor;
261
262 /* Convert a byte between binary and BCD.  */
263 static inline uint8_t to_bcd(uint8_t val)
264 {
265     return ((val / 10) << 4) | (val % 10);
266 }
267
268 static inline uint8_t from_bcd(uint8_t val)
269 {
270     return ((val >> 4) * 10) + (val & 0x0f);
271 }
272
273 #include "module.h"
274
275 #endif /* dyngen-exec.h hack */
276
277 #endif
This page took 0.039146 seconds and 4 git commands to generate.