Annotation of qemu/qemu-common.h, revision 1.1.1.9

1.1       root        1: /* Common header file that is included by all of qemu.  */
                      2: #ifndef QEMU_COMMON_H
                      3: #define QEMU_COMMON_H
                      4: 
1.1.1.9 ! root        5: #include "compiler.h"
1.1.1.5   root        6: #include "config-host.h"
                      7: 
1.1.1.9 ! root        8: #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
1.1.1.7   root        9: 
                     10: typedef struct QEMUTimer QEMUTimer;
                     11: typedef struct QEMUFile QEMUFile;
                     12: typedef struct QEMUBH QEMUBH;
                     13: typedef struct DeviceState DeviceState;
                     14: 
1.1.1.9 ! root       15: struct Monitor;
        !            16: typedef struct Monitor Monitor;
        !            17: 
1.1       root       18: /* we put basic includes here to avoid repeating them in device drivers */
                     19: #include <stdlib.h>
                     20: #include <stdio.h>
                     21: #include <stdarg.h>
1.1.1.7   root       22: #include <stdbool.h>
1.1       root       23: #include <string.h>
1.1.1.2   root       24: #include <strings.h>
1.1       root       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>
1.1.1.9 ! root       33: #include <sys/time.h>
1.1.1.3   root       34: #include <assert.h>
1.1.1.9 ! root       35: #include <signal.h>
        !            36: 
        !            37: #ifdef _WIN32
        !            38: #include "qemu-os-win32.h"
        !            39: #endif
        !            40: 
        !            41: #ifdef CONFIG_POSIX
        !            42: #include "qemu-os-posix.h"
        !            43: #endif
1.1       root       44: 
                     45: #ifndef O_LARGEFILE
                     46: #define O_LARGEFILE 0
                     47: #endif
                     48: #ifndef O_BINARY
                     49: #define O_BINARY 0
                     50: #endif
1.1.1.4   root       51: #ifndef MAP_ANONYMOUS
                     52: #define MAP_ANONYMOUS MAP_ANON
                     53: #endif
1.1       root       54: #ifndef ENOMEDIUM
                     55: #define ENOMEDIUM ENODEV
                     56: #endif
1.1.1.4   root       57: #if !defined(ENOTSUP)
                     58: #define ENOTSUP 4096
                     59: #endif
1.1.1.8   root       60: #ifndef TIME_MAX
                     61: #define TIME_MAX LONG_MAX
                     62: #endif
1.1       root       63: 
1.1.1.4   root       64: #ifndef CONFIG_IOVEC
                     65: #define CONFIG_IOVEC
1.1.1.2   root       66: struct iovec {
                     67:     void *iov_base;
                     68:     size_t iov_len;
                     69: };
1.1.1.6   root       70: /*
                     71:  * Use the same value as Linux for now.
                     72:  */
                     73: #define IOV_MAX                1024
1.1.1.2   root       74: #else
                     75: #include <sys/uio.h>
                     76: #endif
                     77: 
1.1.1.8   root       78: typedef int (*fprintf_function)(FILE *f, const char *fmt, ...)
                     79:     GCC_FMT_ATTR(2, 3);
                     80: 
1.1       root       81: #ifdef _WIN32
                     82: #define fsync _commit
                     83: #define lseek _lseeki64
1.1.1.8   root       84: int qemu_ftruncate64(int, int64_t);
1.1       root       85: #define ftruncate qemu_ftruncate64
                     86: 
                     87: static inline char *realpath(const char *path, char *resolved_path)
                     88: {
                     89:     _fullpath(resolved_path, path, _MAX_PATH);
                     90:     return resolved_path;
                     91: }
                     92: #endif
                     93: 
                     94: /* FIXME: Remove NEED_CPU_H.  */
                     95: #ifndef NEED_CPU_H
                     96: 
                     97: #include "osdep.h"
                     98: #include "bswap.h"
                     99: 
                    100: #else
                    101: 
                    102: #include "cpu.h"
                    103: 
                    104: #endif /* !defined(NEED_CPU_H) */
                    105: 
1.1.1.9 ! root      106: /* main function, renamed */
        !           107: #if defined(CONFIG_COCOA)
        !           108: int qemu_main(int argc, char **argv, char **envp);
        !           109: #endif
        !           110: 
1.1       root      111: /* bottom halves */
                    112: typedef void QEMUBHFunc(void *opaque);
                    113: 
1.1.1.4   root      114: void async_context_push(void);
                    115: void async_context_pop(void);
                    116: int get_async_context_id(void);
                    117: 
1.1       root      118: QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
                    119: void qemu_bh_schedule(QEMUBH *bh);
1.1.1.2   root      120: /* Bottom halfs that are scheduled from a bottom half handler are instantly
                    121:  * invoked.  This can create an infinite loop if a bottom half handler
                    122:  * schedules itself.  qemu_bh_schedule_idle() avoids this infinite loop by
                    123:  * ensuring that the bottom half isn't executed until the next main loop
                    124:  * iteration.
                    125:  */
                    126: void qemu_bh_schedule_idle(QEMUBH *bh);
1.1       root      127: void qemu_bh_cancel(QEMUBH *bh);
                    128: void qemu_bh_delete(QEMUBH *bh);
                    129: int qemu_bh_poll(void);
1.1.1.4   root      130: void qemu_bh_update_timeout(int *timeout);
1.1       root      131: 
1.1.1.2   root      132: void qemu_get_timedate(struct tm *tm, int offset);
                    133: int qemu_timedate_diff(struct tm *tm);
                    134: 
1.1       root      135: /* cutils.c */
                    136: void pstrcpy(char *buf, int buf_size, const char *str);
                    137: char *pstrcat(char *buf, int buf_size, const char *s);
                    138: int strstart(const char *str, const char *val, const char **ptr);
                    139: int stristart(const char *str, const char *val, const char **ptr);
1.1.1.3   root      140: int qemu_strnlen(const char *s, int max_len);
1.1       root      141: time_t mktimegm(struct tm *tm);
1.1.1.2   root      142: int qemu_fls(int i);
1.1.1.4   root      143: int qemu_fdatasync(int fd);
1.1.1.7   root      144: int fcntl_setfl(int fd, int flag);
1.1.1.4   root      145: 
1.1.1.8   root      146: /*
                    147:  * strtosz() suffixes used to specify the default treatment of an
                    148:  * argument passed to strtosz() without an explicit suffix.
                    149:  * These should be defined using upper case characters in the range
                    150:  * A-Z, as strtosz() will use qemu_toupper() on the given argument
                    151:  * prior to comparison.
                    152:  */
                    153: #define STRTOSZ_DEFSUFFIX_TB   'T'
                    154: #define STRTOSZ_DEFSUFFIX_GB   'G'
                    155: #define STRTOSZ_DEFSUFFIX_MB   'M'
                    156: #define STRTOSZ_DEFSUFFIX_KB   'K'
                    157: #define STRTOSZ_DEFSUFFIX_B    'B'
                    158: int64_t strtosz(const char *nptr, char **end);
                    159: int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
                    160: 
1.1.1.4   root      161: /* path.c */
                    162: void init_paths(const char *prefix);
                    163: const char *path(const char *pathname);
1.1.1.2   root      164: 
                    165: #define qemu_isalnum(c)                isalnum((unsigned char)(c))
                    166: #define qemu_isalpha(c)                isalpha((unsigned char)(c))
                    167: #define qemu_iscntrl(c)                iscntrl((unsigned char)(c))
                    168: #define qemu_isdigit(c)                isdigit((unsigned char)(c))
                    169: #define qemu_isgraph(c)                isgraph((unsigned char)(c))
                    170: #define qemu_islower(c)                islower((unsigned char)(c))
                    171: #define qemu_isprint(c)                isprint((unsigned char)(c))
                    172: #define qemu_ispunct(c)                ispunct((unsigned char)(c))
                    173: #define qemu_isspace(c)                isspace((unsigned char)(c))
                    174: #define qemu_isupper(c)                isupper((unsigned char)(c))
                    175: #define qemu_isxdigit(c)       isxdigit((unsigned char)(c))
                    176: #define qemu_tolower(c)                tolower((unsigned char)(c))
                    177: #define qemu_toupper(c)                toupper((unsigned char)(c))
                    178: #define qemu_isascii(c)                isascii((unsigned char)(c))
                    179: #define qemu_toascii(c)                toascii((unsigned char)(c))
                    180: 
1.1.1.8   root      181: void *qemu_oom_check(void *ptr);
1.1.1.2   root      182: void *qemu_malloc(size_t size);
                    183: void *qemu_realloc(void *ptr, size_t size);
                    184: void *qemu_mallocz(size_t size);
                    185: void qemu_free(void *ptr);
                    186: char *qemu_strdup(const char *str);
                    187: char *qemu_strndup(const char *str, size_t size);
                    188: 
1.1.1.4   root      189: void qemu_mutex_lock_iothread(void);
                    190: void qemu_mutex_unlock_iothread(void);
                    191: 
                    192: int qemu_open(const char *name, int flags, ...);
1.1.1.7   root      193: ssize_t qemu_write_full(int fd, const void *buf, size_t count)
                    194:     QEMU_WARN_UNUSED_RESULT;
1.1.1.4   root      195: void qemu_set_cloexec(int fd);
                    196: 
                    197: #ifndef _WIN32
1.1.1.9 ! root      198: int qemu_add_child_watch(pid_t pid);
1.1.1.7   root      199: int qemu_eventfd(int pipefd[2]);
1.1.1.4   root      200: int qemu_pipe(int pipefd[2]);
                    201: #endif
                    202: 
1.1.1.9 ! root      203: #ifdef _WIN32
        !           204: #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
        !           205: #else
        !           206: #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
        !           207: #endif
        !           208: 
1.1       root      209: /* Error handling.  */
                    210: 
1.1.1.8   root      211: void QEMU_NORETURN hw_error(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
1.1       root      212: 
                    213: /* IO callbacks.  */
                    214: typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
1.1.1.7   root      215: typedef int IOCanReadHandler(void *opaque);
1.1       root      216: typedef void IOHandler(void *opaque);
                    217: 
1.1.1.9 ! root      218: void qemu_iohandler_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set *xfds);
        !           219: void qemu_iohandler_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds, int rc);
        !           220: 
1.1       root      221: struct ParallelIOArg {
                    222:     void *buffer;
                    223:     int count;
                    224: };
                    225: 
                    226: typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
                    227: 
                    228: /* A load of opaque types so that device init declarations don't have to
                    229:    pull in all the real definitions.  */
                    230: typedef struct NICInfo NICInfo;
1.1.1.2   root      231: typedef struct HCIInfo HCIInfo;
1.1       root      232: typedef struct AudioState AudioState;
                    233: typedef struct BlockDriverState BlockDriverState;
1.1.1.8   root      234: typedef struct DriveInfo DriveInfo;
1.1       root      235: typedef struct DisplayState DisplayState;
1.1.1.2   root      236: typedef struct DisplayChangeListener DisplayChangeListener;
                    237: typedef struct DisplaySurface DisplaySurface;
1.1.1.3   root      238: typedef struct DisplayAllocator DisplayAllocator;
1.1.1.2   root      239: typedef struct PixelFormat PixelFormat;
1.1       root      240: typedef struct TextConsole TextConsole;
1.1.1.2   root      241: typedef TextConsole QEMUConsole;
1.1       root      242: typedef struct CharDriverState CharDriverState;
1.1.1.4   root      243: typedef struct MACAddr MACAddr;
1.1       root      244: typedef struct VLANState VLANState;
1.1.1.4   root      245: typedef struct VLANClientState VLANClientState;
1.1       root      246: typedef struct i2c_bus i2c_bus;
                    247: typedef struct i2c_slave i2c_slave;
                    248: typedef struct SMBusDevice SMBusDevice;
1.1.1.4   root      249: typedef struct PCIHostState PCIHostState;
                    250: typedef struct PCIExpressHost PCIExpressHost;
1.1       root      251: typedef struct PCIBus PCIBus;
                    252: typedef struct PCIDevice PCIDevice;
1.1.1.8   root      253: typedef struct PCIExpressDevice PCIExpressDevice;
                    254: typedef struct PCIBridge PCIBridge;
                    255: typedef struct PCIEAERMsg PCIEAERMsg;
                    256: typedef struct PCIEAERLog PCIEAERLog;
                    257: typedef struct PCIEAERErr PCIEAERErr;
                    258: typedef struct PCIEPort PCIEPort;
                    259: typedef struct PCIESlot PCIESlot;
1.1       root      260: typedef struct SerialState SerialState;
                    261: typedef struct IRQState *qemu_irq;
1.1.1.3   root      262: typedef struct PCMCIACardState PCMCIACardState;
                    263: typedef struct MouseTransformInfo MouseTransformInfo;
                    264: typedef struct uWireSlave uWireSlave;
                    265: typedef struct I2SCodec I2SCodec;
                    266: typedef struct SSIBus SSIBus;
1.1.1.7   root      267: typedef struct EventNotifier EventNotifier;
                    268: typedef struct VirtIODevice VirtIODevice;
                    269: 
                    270: typedef uint64_t pcibus_t;
                    271: 
                    272: void cpu_exec_init_all(unsigned long tb_size);
1.1       root      273: 
1.1.1.2   root      274: /* CPU save/load.  */
                    275: void cpu_save(QEMUFile *f, void *opaque);
                    276: int cpu_load(QEMUFile *f, void *opaque, int version_id);
                    277: 
                    278: /* Force QEMU to stop what it's doing and service IO */
                    279: void qemu_service_io(void);
                    280: 
1.1.1.3   root      281: /* Force QEMU to process pending events */
                    282: void qemu_notify_event(void);
                    283: 
                    284: /* Unblock cpu */
                    285: void qemu_cpu_kick(void *env);
1.1.1.9 ! root      286: void qemu_cpu_kick_self(void);
        !           287: int qemu_cpu_is_self(void *env);
        !           288: bool all_cpu_threads_idle(void);
1.1.1.3   root      289: 
1.1.1.7   root      290: /* work queue */
                    291: struct qemu_work_item {
                    292:     struct qemu_work_item *next;
                    293:     void (*func)(void *data);
                    294:     void *data;
                    295:     int done;
                    296: };
                    297: 
1.1.1.3   root      298: #ifdef CONFIG_USER_ONLY
                    299: #define qemu_init_vcpu(env) do { } while (0)
                    300: #else
                    301: void qemu_init_vcpu(void *env);
                    302: #endif
                    303: 
1.1.1.2   root      304: typedef struct QEMUIOVector {
                    305:     struct iovec *iov;
                    306:     int niov;
                    307:     int nalloc;
                    308:     size_t size;
                    309: } QEMUIOVector;
                    310: 
                    311: void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
1.1.1.3   root      312: void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
1.1.1.2   root      313: void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
1.1.1.8   root      314: void qemu_iovec_copy(QEMUIOVector *dst, QEMUIOVector *src, uint64_t skip,
                    315:     size_t size);
1.1.1.4   root      316: void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size);
1.1.1.2   root      317: void qemu_iovec_destroy(QEMUIOVector *qiov);
                    318: void qemu_iovec_reset(QEMUIOVector *qiov);
                    319: void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
                    320: void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
1.1.1.8   root      321: void qemu_iovec_memset(QEMUIOVector *qiov, int c, size_t count);
                    322: void qemu_iovec_memset_skip(QEMUIOVector *qiov, int c, size_t count,
                    323:                             size_t skip);
1.1.1.2   root      324: 
1.1.1.9 ! root      325: void qemu_progress_init(int enabled, float min_skip);
        !           326: void qemu_progress_end(void);
        !           327: void qemu_progress_print(float delta, int max);
        !           328: 
        !           329: #define QEMU_FILE_TYPE_BIOS   0
        !           330: #define QEMU_FILE_TYPE_KEYMAP 1
        !           331: char *qemu_find_file(int type, const char *name);
        !           332: 
        !           333: /* OS specific functions */
        !           334: void os_setup_early_signal_handling(void);
        !           335: char *os_find_datadir(const char *argv0);
        !           336: void os_parse_cmd_args(int index, const char *optarg);
        !           337: void os_pidfile_error(void);
1.1.1.3   root      338: 
1.1.1.4   root      339: /* Convert a byte between binary and BCD.  */
                    340: static inline uint8_t to_bcd(uint8_t val)
                    341: {
                    342:     return ((val / 10) << 4) | (val % 10);
                    343: }
                    344: 
                    345: static inline uint8_t from_bcd(uint8_t val)
                    346: {
                    347:     return ((val >> 4) * 10) + (val & 0x0f);
                    348: }
                    349: 
1.1.1.8   root      350: /* compute with 96 bit intermediate result: (a*b)/c */
                    351: static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
                    352: {
                    353:     union {
                    354:         uint64_t ll;
                    355:         struct {
                    356: #ifdef HOST_WORDS_BIGENDIAN
                    357:             uint32_t high, low;
                    358: #else
                    359:             uint32_t low, high;
                    360: #endif
                    361:         } l;
                    362:     } u, res;
                    363:     uint64_t rl, rh;
                    364: 
                    365:     u.ll = a;
                    366:     rl = (uint64_t)u.l.low * (uint64_t)b;
                    367:     rh = (uint64_t)u.l.high * (uint64_t)b;
                    368:     rh += (rl >> 32);
                    369:     res.l.high = rh / c;
                    370:     res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c;
                    371:     return res.ll;
                    372: }
1.1.1.3   root      373: 
1.1.1.8   root      374: #include "module.h"
1.1.1.2   root      375: 
1.1       root      376: #endif

unix.superglobalmegacorp.com