2 * Fork-based fuzzing helpers
4 * Copyright Red Hat Inc., 2019
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 "fork_fuzz.h"
18 void counter_shm_init(void)
20 /* Copy what's in the counter region to a temporary buffer.. */
21 void *copy
= malloc(&__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
);
23 &__FUZZ_COUNTERS_START
,
24 &__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
);
26 /* Map a shared region over the counter region */
27 if (mmap(&__FUZZ_COUNTERS_START
,
28 &__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
,
29 PROT_READ
| PROT_WRITE
, MAP_SHARED
| MAP_FIXED
| MAP_ANONYMOUS
,
30 0, 0) == MAP_FAILED
) {
35 /* Copy the original data back to the counter-region */
36 memcpy(&__FUZZ_COUNTERS_START
, copy
,
37 &__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
);