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