]> git.proxmox.com Git - qemu.git/blame - qemu-common.h
vnc_refresh: calling vnc_update_client might free vs
[qemu.git] / qemu-common.h
CommitLineData
faf07963
PB
1/* Common header file that is included by all of qemu. */
2#ifndef QEMU_COMMON_H
3#define QEMU_COMMON_H
4
beb6f0de
KW
5#include "config-host.h"
6
a5e50b26 7#define QEMU_NORETURN __attribute__ ((__noreturn__))
747bbdf7
BS
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
7d99a001 13
a5e50b26 14/* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
7d99a001
BS
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
faf07963
PB
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>
c8906845 24#include <strings.h>
faf07963
PB
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>
55616505 33#include <assert.h>
faf07963
PB
34
35#ifndef O_LARGEFILE
36#define O_LARGEFILE 0
37#endif
38#ifndef O_BINARY
39#define O_BINARY 0
40#endif
0e74e66b
JQ
41#ifndef MAP_ANONYMOUS
42#define MAP_ANONYMOUS MAP_ANON
43#endif
faf07963
PB
44#ifndef ENOMEDIUM
45#define ENOMEDIUM ENODEV
46#endif
4c955388 47#if !defined(ENOTSUP)
2880bc32
JQ
48#define ENOTSUP 4096
49#endif
faf07963 50
6114fdb0
JQ
51#ifndef CONFIG_IOVEC
52#define CONFIG_IOVEC
bf9298b9
AL
53struct iovec {
54 void *iov_base;
55 size_t iov_len;
56};
331dadde
BS
57#else
58#include <sys/uio.h>
bf9298b9
AL
59#endif
60
faf07963 61#ifdef _WIN32
faf07963
PB
62#define fsync _commit
63#define lseek _lseeki64
faf07963
PB
64extern int qemu_ftruncate64(int, int64_t);
65#define ftruncate qemu_ftruncate64
66
faf07963
PB
67static 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
faf07963
PB
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 */
93typedef struct QEMUBH QEMUBH;
94
95typedef void QEMUBHFunc(void *opaque);
96
9a1e9481
KW
97void async_context_push(void);
98void async_context_pop(void);
99int get_async_context_id(void);
100
faf07963
PB
101QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
102void qemu_bh_schedule(QEMUBH *bh);
80d3580b
AL
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 */
1b435b10 109void qemu_bh_schedule_idle(QEMUBH *bh);
faf07963
PB
110void qemu_bh_cancel(QEMUBH *bh);
111void qemu_bh_delete(QEMUBH *bh);
112int qemu_bh_poll(void);
4f999d05 113void qemu_bh_update_timeout(int *timeout);
faf07963 114
87ecb68b
PB
115uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
116
f6503059
AZ
117void qemu_get_timedate(struct tm *tm, int offset);
118int qemu_timedate_diff(struct tm *tm);
119
faf07963
PB
120/* cutils.c */
121void pstrcpy(char *buf, int buf_size, const char *str);
122char *pstrcat(char *buf, int buf_size, const char *s);
123int strstart(const char *str, const char *val, const char **ptr);
124int stristart(const char *str, const char *val, const char **ptr);
d43277c5 125int qemu_strnlen(const char *s, int max_len);
faf07963 126time_t mktimegm(struct tm *tm);
ad46db9a 127int qemu_fls(int i);
6f1953c4 128int qemu_fdatasync(int fd);
faf07963 129
37022086
BS
130/* path.c */
131void init_paths(const char *prefix);
132const char *path(const char *pathname);
133
cd390083
BS
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
ca10f867 150void *qemu_malloc(size_t size);
2137b4cc 151void *qemu_realloc(void *ptr, size_t size);
ca10f867
AJ
152void *qemu_mallocz(size_t size);
153void qemu_free(void *ptr);
154char *qemu_strdup(const char *str);
ac4b0d0c 155char *qemu_strndup(const char *str, size_t size);
ca10f867
AJ
156
157void *get_mmap_addr(unsigned long size);
158
159
d549db5a
GC
160void qemu_mutex_lock_iothread(void);
161void qemu_mutex_unlock_iothread(void);
162
40ff6d7e 163int qemu_open(const char *name, int flags, ...);
7c7c0629
JQ
164ssize_t qemu_write_full(int fd, const void *buf, size_t count)
165 QEMU_WARN_UNUSED_RESULT;
40ff6d7e
KW
166void qemu_set_cloexec(int fd);
167
168#ifndef _WIN32
169int qemu_pipe(int pipefd[2]);
170#endif
171
87ecb68b
PB
172/* Error handling. */
173
a5e50b26 174void QEMU_NORETURN hw_error(const char *fmt, ...)
7d99a001 175 __attribute__ ((__format__ (__printf__, 1, 2)));
87ecb68b
PB
176
177/* IO callbacks. */
178typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
179typedef int IOCanRWHandler(void *opaque);
180typedef void IOHandler(void *opaque);
181
182struct ParallelIOArg {
183 void *buffer;
184 int count;
185};
186
187typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
188
189/* A load of opaque types so that device init declarations don't have to
190 pull in all the real definitions. */
191typedef struct NICInfo NICInfo;
1ae26a18 192typedef struct HCIInfo HCIInfo;
87ecb68b
PB
193typedef struct AudioState AudioState;
194typedef struct BlockDriverState BlockDriverState;
195typedef struct DisplayState DisplayState;
7d957bd8
AL
196typedef struct DisplayChangeListener DisplayChangeListener;
197typedef struct DisplaySurface DisplaySurface;
7b5d76da 198typedef struct DisplayAllocator DisplayAllocator;
7d957bd8 199typedef struct PixelFormat PixelFormat;
87ecb68b 200typedef struct TextConsole TextConsole;
c60e08d9 201typedef TextConsole QEMUConsole;
87ecb68b 202typedef struct CharDriverState CharDriverState;
76d32cba 203typedef struct MACAddr MACAddr;
87ecb68b 204typedef struct VLANState VLANState;
f7105843 205typedef struct VLANClientState VLANClientState;
87ecb68b
PB
206typedef struct QEMUFile QEMUFile;
207typedef struct i2c_bus i2c_bus;
208typedef struct i2c_slave i2c_slave;
209typedef struct SMBusDevice SMBusDevice;
210typedef struct QEMUTimer QEMUTimer;
fb47a2e9
IY
211typedef struct PCIHostState PCIHostState;
212typedef struct PCIExpressHost PCIExpressHost;
87ecb68b
PB
213typedef struct PCIBus PCIBus;
214typedef struct PCIDevice PCIDevice;
215typedef struct SerialState SerialState;
216typedef struct IRQState *qemu_irq;
bc24a225
PB
217typedef struct PCMCIACardState PCMCIACardState;
218typedef struct MouseTransformInfo MouseTransformInfo;
219typedef struct uWireSlave uWireSlave;
220typedef struct I2SCodec I2SCodec;
aae9460e 221typedef struct DeviceState DeviceState;
90d37239 222typedef struct SSIBus SSIBus;
87ecb68b 223
b3c7724c
PB
224/* CPU save/load. */
225void cpu_save(QEMUFile *f, void *opaque);
226int cpu_load(QEMUFile *f, void *opaque, int version_id);
227
9e472e10
AL
228/* Force QEMU to stop what it's doing and service IO */
229void qemu_service_io(void);
230
d9f75a4e
AL
231/* Force QEMU to process pending events */
232void qemu_notify_event(void);
233
8edac960
AL
234/* Unblock cpu */
235void qemu_cpu_kick(void *env);
236int qemu_cpu_self(void *env);
237
0bf46a40
AL
238#ifdef CONFIG_USER_ONLY
239#define qemu_init_vcpu(env) do { } while (0)
240#else
241void qemu_init_vcpu(void *env);
242#endif
243
44e3ee8a
AL
244typedef struct QEMUIOVector {
245 struct iovec *iov;
246 int niov;
247 int nalloc;
249aa745 248 size_t size;
44e3ee8a
AL
249} QEMUIOVector;
250
251void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
522584a5 252void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
44e3ee8a 253void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
40b4f539 254void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
44e3ee8a 255void qemu_iovec_destroy(QEMUIOVector *qiov);
be959463 256void qemu_iovec_reset(QEMUIOVector *qiov);
44e3ee8a 257void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
249aa745 258void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
44e3ee8a 259
376253ec
AL
260struct Monitor;
261typedef struct Monitor Monitor;
262
abd0c6bd
PB
263/* Convert a byte between binary and BCD. */
264static inline uint8_t to_bcd(uint8_t val)
265{
266 return ((val / 10) << 4) | (val % 10);
267}
268
269static inline uint8_t from_bcd(uint8_t val)
270{
271 return ((val >> 4) * 10) + (val & 0x0f);
272}
273
0bfe3ca5
AL
274#include "module.h"
275
7d99a001
BS
276#endif /* dyngen-exec.h hack */
277
faf07963 278#endif