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 char *shm_path
= g_strdup_printf("/qemu-fuzz-cntrs.%d", getpid());
21 int fd
= shm_open(shm_path
, O_CREAT
| O_RDWR
, S_IRUSR
| S_IWUSR
);
28 if (ftruncate(fd
, &__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
) == -1) {
32 /* Copy what's in the counter region to the shm.. */
33 void *rptr
= mmap(NULL
,
34 &__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
,
35 PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
37 &__FUZZ_COUNTERS_START
,
38 &__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
);
40 munmap(rptr
, &__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
);
42 /* And map the shm over the counter region */
43 rptr
= mmap(&__FUZZ_COUNTERS_START
,
44 &__FUZZ_COUNTERS_END
- &__FUZZ_COUNTERS_START
,
45 PROT_READ
| PROT_WRITE
, MAP_SHARED
| MAP_FIXED
, fd
, 0);