KVM: remove support for kernel-irqchip=off
[qemu.git] / tests / qtest / fuzz / qtest_wrappers.c
blob0580f8df860fe7ae229cd4eb370db578d7e08eb6
1 /*
2 * qtest function wrappers
4 * Copyright Red Hat Inc., 2019
6 * Authors:
7 * Alexander Bulekov <alxndr@bu.edu>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
15 #include "hw/core/cpu.h"
16 #include "exec/ioport.h"
18 #include "fuzz.h"
20 static bool serialize = true;
22 #define WRAP(RET_TYPE, NAME_AND_ARGS)\
23 RET_TYPE __wrap_##NAME_AND_ARGS;\
24 RET_TYPE __real_##NAME_AND_ARGS;
26 WRAP(uint8_t , qtest_inb(QTestState *s, uint16_t addr))
27 WRAP(uint16_t , qtest_inw(QTestState *s, uint16_t addr))
28 WRAP(uint32_t , qtest_inl(QTestState *s, uint16_t addr))
29 WRAP(void , qtest_outb(QTestState *s, uint16_t addr, uint8_t value))
30 WRAP(void , qtest_outw(QTestState *s, uint16_t addr, uint16_t value))
31 WRAP(void , qtest_outl(QTestState *s, uint16_t addr, uint32_t value))
32 WRAP(uint8_t , qtest_readb(QTestState *s, uint64_t addr))
33 WRAP(uint16_t , qtest_readw(QTestState *s, uint64_t addr))
34 WRAP(uint32_t , qtest_readl(QTestState *s, uint64_t addr))
35 WRAP(uint64_t , qtest_readq(QTestState *s, uint64_t addr))
36 WRAP(void , qtest_writeb(QTestState *s, uint64_t addr, uint8_t value))
37 WRAP(void , qtest_writew(QTestState *s, uint64_t addr, uint16_t value))
38 WRAP(void , qtest_writel(QTestState *s, uint64_t addr, uint32_t value))
39 WRAP(void , qtest_writeq(QTestState *s, uint64_t addr, uint64_t value))
40 WRAP(void , qtest_memread(QTestState *s, uint64_t addr,
41 void *data, size_t size))
42 WRAP(void , qtest_bufread(QTestState *s, uint64_t addr, void *data,
43 size_t size))
44 WRAP(void , qtest_memwrite(QTestState *s, uint64_t addr, const void *data,
45 size_t size))
46 WRAP(void, qtest_bufwrite(QTestState *s, uint64_t addr,
47 const void *data, size_t size))
48 WRAP(void, qtest_memset(QTestState *s, uint64_t addr,
49 uint8_t patt, size_t size))
52 uint8_t __wrap_qtest_inb(QTestState *s, uint16_t addr)
54 if (!serialize) {
55 return cpu_inb(addr);
56 } else {
57 return __real_qtest_inb(s, addr);
61 uint16_t __wrap_qtest_inw(QTestState *s, uint16_t addr)
63 if (!serialize) {
64 return cpu_inw(addr);
65 } else {
66 return __real_qtest_inw(s, addr);
70 uint32_t __wrap_qtest_inl(QTestState *s, uint16_t addr)
72 if (!serialize) {
73 return cpu_inl(addr);
74 } else {
75 return __real_qtest_inl(s, addr);
79 void __wrap_qtest_outb(QTestState *s, uint16_t addr, uint8_t value)
81 if (!serialize) {
82 cpu_outb(addr, value);
83 } else {
84 __real_qtest_outb(s, addr, value);
88 void __wrap_qtest_outw(QTestState *s, uint16_t addr, uint16_t value)
90 if (!serialize) {
91 cpu_outw(addr, value);
92 } else {
93 __real_qtest_outw(s, addr, value);
97 void __wrap_qtest_outl(QTestState *s, uint16_t addr, uint32_t value)
99 if (!serialize) {
100 cpu_outl(addr, value);
101 } else {
102 __real_qtest_outl(s, addr, value);
106 uint8_t __wrap_qtest_readb(QTestState *s, uint64_t addr)
108 uint8_t value;
109 if (!serialize) {
110 address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
111 &value, 1);
112 return value;
113 } else {
114 return __real_qtest_readb(s, addr);
118 uint16_t __wrap_qtest_readw(QTestState *s, uint64_t addr)
120 uint16_t value;
121 if (!serialize) {
122 address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
123 &value, 2);
124 return value;
125 } else {
126 return __real_qtest_readw(s, addr);
130 uint32_t __wrap_qtest_readl(QTestState *s, uint64_t addr)
132 uint32_t value;
133 if (!serialize) {
134 address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
135 &value, 4);
136 return value;
137 } else {
138 return __real_qtest_readl(s, addr);
142 uint64_t __wrap_qtest_readq(QTestState *s, uint64_t addr)
144 uint64_t value;
145 if (!serialize) {
146 address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
147 &value, 8);
148 return value;
149 } else {
150 return __real_qtest_readq(s, addr);
154 void __wrap_qtest_writeb(QTestState *s, uint64_t addr, uint8_t value)
156 if (!serialize) {
157 address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
158 &value, 1);
159 } else {
160 __real_qtest_writeb(s, addr, value);
164 void __wrap_qtest_writew(QTestState *s, uint64_t addr, uint16_t value)
166 if (!serialize) {
167 address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
168 &value, 2);
169 } else {
170 __real_qtest_writew(s, addr, value);
174 void __wrap_qtest_writel(QTestState *s, uint64_t addr, uint32_t value)
176 if (!serialize) {
177 address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
178 &value, 4);
179 } else {
180 __real_qtest_writel(s, addr, value);
184 void __wrap_qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
186 if (!serialize) {
187 address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
188 &value, 8);
189 } else {
190 __real_qtest_writeq(s, addr, value);
194 void __wrap_qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size)
196 if (!serialize) {
197 address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
198 size);
199 } else {
200 __real_qtest_memread(s, addr, data, size);
204 void __wrap_qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size)
206 if (!serialize) {
207 address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
208 size);
209 } else {
210 __real_qtest_bufread(s, addr, data, size);
214 void __wrap_qtest_memwrite(QTestState *s, uint64_t addr, const void *data,
215 size_t size)
217 if (!serialize) {
218 address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
219 data, size);
220 } else {
221 __real_qtest_memwrite(s, addr, data, size);
225 void __wrap_qtest_bufwrite(QTestState *s, uint64_t addr,
226 const void *data, size_t size)
228 if (!serialize) {
229 address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
230 data, size);
231 } else {
232 __real_qtest_bufwrite(s, addr, data, size);
235 void __wrap_qtest_memset(QTestState *s, uint64_t addr,
236 uint8_t patt, size_t size)
238 void *data;
239 if (!serialize) {
240 data = malloc(size);
241 memset(data, patt, size);
242 address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
243 data, size);
244 } else {
245 __real_qtest_memset(s, addr, patt, size);
249 void fuzz_qtest_set_serialize(bool option)
251 serialize = option;