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