]> Git Repo - qemu.git/blob - include/qemu-common.h
Merge remote-tracking branch 'remotes/rth/tags/pull-dis-20171026' into staging
[qemu.git] / include / qemu-common.h
1
2 /* Common header file that is included by all of QEMU.
3  *
4  * This file is supposed to be included only by .c files. No header file should
5  * depend on qemu-common.h, as this would easily lead to circular header
6  * dependencies.
7  *
8  * If a header file uses a definition from qemu-common.h, that definition
9  * must be moved to a separate header file, and the header that uses it
10  * must include that header.
11  */
12 #ifndef QEMU_COMMON_H
13 #define QEMU_COMMON_H
14
15 #include "qemu/fprintf-fn.h"
16
17 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
18
19 #include "qemu/option.h"
20
21 /* Copyright string for -version arguments, About dialogs, etc */
22 #define QEMU_COPYRIGHT "Copyright (c) 2003-2017 " \
23     "Fabrice Bellard and the QEMU Project developers"
24
25 /* Bug reporting information for --help arguments, About dialogs, etc */
26 #define QEMU_HELP_BOTTOM \
27     "See <http://qemu.org/contribute/report-a-bug> for how to report bugs.\n" \
28     "More information on the QEMU project at <http://qemu.org>."
29
30 /* main function, renamed */
31 #if defined(CONFIG_COCOA)
32 int qemu_main(int argc, char **argv, char **envp);
33 #endif
34
35 void qemu_get_timedate(struct tm *tm, int offset);
36 int qemu_timedate_diff(struct tm *tm);
37
38 #define qemu_isalnum(c)         isalnum((unsigned char)(c))
39 #define qemu_isalpha(c)         isalpha((unsigned char)(c))
40 #define qemu_iscntrl(c)         iscntrl((unsigned char)(c))
41 #define qemu_isdigit(c)         isdigit((unsigned char)(c))
42 #define qemu_isgraph(c)         isgraph((unsigned char)(c))
43 #define qemu_islower(c)         islower((unsigned char)(c))
44 #define qemu_isprint(c)         isprint((unsigned char)(c))
45 #define qemu_ispunct(c)         ispunct((unsigned char)(c))
46 #define qemu_isspace(c)         isspace((unsigned char)(c))
47 #define qemu_isupper(c)         isupper((unsigned char)(c))
48 #define qemu_isxdigit(c)        isxdigit((unsigned char)(c))
49 #define qemu_tolower(c)         tolower((unsigned char)(c))
50 #define qemu_toupper(c)         toupper((unsigned char)(c))
51 #define qemu_isascii(c)         isascii((unsigned char)(c))
52 #define qemu_toascii(c)         toascii((unsigned char)(c))
53
54 void *qemu_oom_check(void *ptr);
55
56 ssize_t qemu_write_full(int fd, const void *buf, size_t count)
57     QEMU_WARN_UNUSED_RESULT;
58
59 #ifndef _WIN32
60 int qemu_pipe(int pipefd[2]);
61 /* like openpty() but also makes it raw; return master fd */
62 int qemu_openpty_raw(int *aslave, char *pty_name);
63 #endif
64
65 #ifdef _WIN32
66 /* MinGW needs type casts for the 'buf' and 'optval' arguments. */
67 #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
68     getsockopt(sockfd, level, optname, (void *)optval, optlen)
69 #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
70     setsockopt(sockfd, level, optname, (const void *)optval, optlen)
71 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, (void *)buf, len, flags)
72 #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
73     sendto(sockfd, (const void *)buf, len, flags, destaddr, addrlen)
74 #else
75 #define qemu_getsockopt(sockfd, level, optname, optval, optlen) \
76     getsockopt(sockfd, level, optname, optval, optlen)
77 #define qemu_setsockopt(sockfd, level, optname, optval, optlen) \
78     setsockopt(sockfd, level, optname, optval, optlen)
79 #define qemu_recv(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
80 #define qemu_sendto(sockfd, buf, len, flags, destaddr, addrlen) \
81     sendto(sockfd, buf, len, flags, destaddr, addrlen)
82 #endif
83
84 extern bool tcg_allowed;
85 void tcg_exec_init(unsigned long tb_size);
86 #ifdef CONFIG_TCG
87 #define tcg_enabled() (tcg_allowed)
88 #else
89 #define tcg_enabled() 0
90 #endif
91
92 void cpu_exec_init_all(void);
93 void cpu_exec_step_atomic(CPUState *cpu);
94
95 /**
96  * set_preferred_target_page_bits:
97  * @bits: number of bits needed to represent an address within the page
98  *
99  * Set the preferred target page size (the actual target page
100  * size may be smaller than any given CPU's preference).
101  * Returns true on success, false on failure (which can only happen
102  * if this is called after the system has already finalized its
103  * choice of page size and the requested page size is smaller than that).
104  */
105 bool set_preferred_target_page_bits(int bits);
106
107 /**
108  * Sends a (part of) iovec down a socket, yielding when the socket is full, or
109  * Receives data into a (part of) iovec from a socket,
110  * yielding when there is no data in the socket.
111  * The same interface as qemu_sendv_recvv(), with added yielding.
112  * XXX should mark these as coroutine_fn
113  */
114 ssize_t qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt,
115                             size_t offset, size_t bytes, bool do_send);
116 #define qemu_co_recvv(sockfd, iov, iov_cnt, offset, bytes) \
117   qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, false)
118 #define qemu_co_sendv(sockfd, iov, iov_cnt, offset, bytes) \
119   qemu_co_sendv_recvv(sockfd, iov, iov_cnt, offset, bytes, true)
120
121 /**
122  * The same as above, but with just a single buffer
123  */
124 ssize_t qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send);
125 #define qemu_co_recv(sockfd, buf, bytes) \
126   qemu_co_send_recv(sockfd, buf, bytes, false)
127 #define qemu_co_send(sockfd, buf, bytes) \
128   qemu_co_send_recv(sockfd, buf, bytes, true)
129
130 void qemu_progress_init(int enabled, float min_skip);
131 void qemu_progress_end(void);
132 void qemu_progress_print(float delta, int max);
133 const char *qemu_get_vm_name(void);
134
135 #define QEMU_FILE_TYPE_BIOS   0
136 #define QEMU_FILE_TYPE_KEYMAP 1
137 char *qemu_find_file(int type, const char *name);
138
139 /* OS specific functions */
140 void os_setup_early_signal_handling(void);
141 char *os_find_datadir(void);
142 void os_parse_cmd_args(int index, const char *optarg);
143
144 #include "qemu/module.h"
145
146 /*
147  * Hexdump a buffer to a file. An optional string prefix is added to every line
148  */
149
150 void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size);
151
152 /*
153  * helper to parse debug environment variables
154  */
155 int parse_debug_env(const char *name, int max, int initial);
156
157 const char *qemu_ether_ntoa(const MACAddr *mac);
158 char *size_to_str(uint64_t val);
159 void page_size_init(void);
160
161 /* returns non-zero if dump is in progress, otherwise zero is
162  * returned. */
163 bool dump_in_progress(void);
164
165 #endif
This page took 0.032227 seconds and 4 git commands to generate.