sockets: helper functions for qemu (Gerd Hoffman)
[qemu] / 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 /* we put basic includes here to avoid repeating them in device drivers */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <stdarg.h>
9 #include <string.h>
10 #include <inttypes.h>
11 #include <limits.h>
12 #include <time.h>
13 #include <ctype.h>
14 #include <errno.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 #include <sys/stat.h>
18
19 #ifndef O_LARGEFILE
20 #define O_LARGEFILE 0
21 #endif
22 #ifndef O_BINARY
23 #define O_BINARY 0
24 #endif
25
26 #ifndef ENOMEDIUM
27 #define ENOMEDIUM ENODEV
28 #endif
29
30 #ifdef _WIN32
31 #define WIN32_LEAN_AND_MEAN
32 #define WINVER 0x0501  /* needed for ipv6 bits */
33 #include <windows.h>
34 #define fsync _commit
35 #define lseek _lseeki64
36 #define ENOTSUP 4096
37 extern int qemu_ftruncate64(int, int64_t);
38 #define ftruncate qemu_ftruncate64
39
40
41 static inline char *realpath(const char *path, char *resolved_path)
42 {
43     _fullpath(resolved_path, path, _MAX_PATH);
44     return resolved_path;
45 }
46
47 #define PRId64 "I64d"
48 #define PRIx64 "I64x"
49 #define PRIu64 "I64u"
50 #define PRIo64 "I64o"
51 #endif
52
53 /* FIXME: Remove NEED_CPU_H.  */
54 #ifndef NEED_CPU_H
55
56 #include "config-host.h"
57 #include <setjmp.h>
58 #include "osdep.h"
59 #include "bswap.h"
60
61 #else
62
63 #include "cpu.h"
64
65 #endif /* !defined(NEED_CPU_H) */
66
67 /* bottom halves */
68 typedef struct QEMUBH QEMUBH;
69
70 typedef void QEMUBHFunc(void *opaque);
71
72 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
73 void qemu_bh_schedule(QEMUBH *bh);
74 /* Bottom halfs that are scheduled from a bottom half handler are instantly
75  * invoked.  This can create an infinite loop if a bottom half handler
76  * schedules itself.  qemu_bh_schedule_idle() avoids this infinite loop by
77  * ensuring that the bottom half isn't executed until the next main loop
78  * iteration.
79  */
80 void qemu_bh_schedule_idle(QEMUBH *bh);
81 void qemu_bh_cancel(QEMUBH *bh);
82 void qemu_bh_delete(QEMUBH *bh);
83 int qemu_bh_poll(void);
84
85 uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
86
87 void qemu_get_timedate(struct tm *tm, int offset);
88 int qemu_timedate_diff(struct tm *tm);
89
90 /* cutils.c */
91 void pstrcpy(char *buf, int buf_size, const char *str);
92 char *pstrcat(char *buf, int buf_size, const char *s);
93 int strstart(const char *str, const char *val, const char **ptr);
94 int stristart(const char *str, const char *val, const char **ptr);
95 time_t mktimegm(struct tm *tm);
96
97 void *qemu_malloc(size_t size);
98 void *qemu_realloc(void *ptr, size_t size);
99 void *qemu_mallocz(size_t size);
100 void qemu_free(void *ptr);
101 char *qemu_strdup(const char *str);
102 char *qemu_strndup(const char *str, size_t size);
103
104 void *get_mmap_addr(unsigned long size);
105
106
107 /* Error handling.  */
108
109 void hw_error(const char *fmt, ...)
110     __attribute__ ((__format__ (__printf__, 1, 2)))
111     __attribute__ ((__noreturn__));
112
113 /* IO callbacks.  */
114 typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
115 typedef int IOCanRWHandler(void *opaque);
116 typedef void IOHandler(void *opaque);
117
118 struct ParallelIOArg {
119     void *buffer;
120     int count;
121 };
122
123 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
124
125 /* A load of opaque types so that device init declarations don't have to
126    pull in all the real definitions.  */
127 typedef struct NICInfo NICInfo;
128 typedef struct HCIInfo HCIInfo;
129 typedef struct AudioState AudioState;
130 typedef struct BlockDriverState BlockDriverState;
131 typedef struct DisplayState DisplayState;
132 typedef struct TextConsole TextConsole;
133 typedef TextConsole QEMUConsole;
134 typedef struct CharDriverState CharDriverState;
135 typedef struct VLANState VLANState;
136 typedef struct QEMUFile QEMUFile;
137 typedef struct i2c_bus i2c_bus;
138 typedef struct i2c_slave i2c_slave;
139 typedef struct SMBusDevice SMBusDevice;
140 typedef struct QEMUTimer QEMUTimer;
141 typedef struct PCIBus PCIBus;
142 typedef struct PCIDevice PCIDevice;
143 typedef struct SerialState SerialState;
144 typedef struct IRQState *qemu_irq;
145 struct pcmcia_card_s;
146
147 /* CPU save/load.  */
148 void cpu_save(QEMUFile *f, void *opaque);
149 int cpu_load(QEMUFile *f, void *opaque, int version_id);
150
151 /* Force QEMU to stop what it's doing and service IO */
152 void qemu_service_io(void);
153
154 #endif