From 2f3f2ae092ca54d2b6d23bfff1446e1dd50ffbfe Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Wed, 14 Feb 2018 08:41:09 -0500 Subject: [PATCH] Stop including qemu-common.h in memory.h Including qemu-common.h from other header files is generally a bad idea, because it means it's very easy to end up with a circular dependency. For instance, if we wanted to include memory.h from qom/cpu.h we'd end up with this loop: memory.h -> qemu-common.h -> cpu.h -> cpu-qom.h -> qom/cpu.h -> memory.h Remove the include from memory.h. This requires us to fix up a few other files which were inadvertently getting declarations indirectly through memory.h. The biggest change is splitting the fprintf_function typedef out into its own header so other headers can get at it without having to include qemu-common.h. Backports commit fba0a593b2809ecdda68650952cf3d3332ac1990 from qemu --- qemu/include/exec/cpu-common.h | 2 ++ qemu/include/exec/memory.h | 1 - qemu/include/hw/arm/arm.h | 1 + qemu/include/qemu-common.h | 4 +--- qemu/include/qemu/fprintf-fn.h | 17 +++++++++++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 qemu/include/qemu/fprintf-fn.h diff --git a/qemu/include/exec/cpu-common.h b/qemu/include/exec/cpu-common.h index 40664d77..f47ce42c 100644 --- a/qemu/include/exec/cpu-common.h +++ b/qemu/include/exec/cpu-common.h @@ -11,6 +11,8 @@ struct uc_struct; #include "qemu/bswap.h" #include "qemu/queue.h" +#include "qemu/fprintf-fn.h" +#include "qemu/typedefs.h" typedef enum MMUAccessType { MMU_DATA_LOAD = 0, diff --git a/qemu/include/exec/memory.h b/qemu/include/exec/memory.h index 74fbadee..2fb86034 100644 --- a/qemu/include/exec/memory.h +++ b/qemu/include/exec/memory.h @@ -20,7 +20,6 @@ #define DIRTY_MEMORY_NUM 1 /* num of dirty bits */ #include "unicorn/platform.h" -#include "qemu-common.h" #include "exec/cpu-common.h" #include "exec/hwaddr.h" #include "exec/memattrs.h" diff --git a/qemu/include/hw/arm/arm.h b/qemu/include/hw/arm/arm.h index 159c5cf9..48109027 100644 --- a/qemu/include/hw/arm/arm.h +++ b/qemu/include/hw/arm/arm.h @@ -12,6 +12,7 @@ #define ARM_MISC_H #include "exec/memory.h" +#include "cpu.h" void tosa_machine_init(struct uc_struct *uc); void machvirt_machine_init(struct uc_struct *uc); // ARM64 diff --git a/qemu/include/qemu-common.h b/qemu/include/qemu-common.h index 940ee79e..e2c3e3b1 100644 --- a/qemu/include/qemu-common.h +++ b/qemu/include/qemu-common.h @@ -15,6 +15,7 @@ #include "qemu/compiler.h" #include "config-host.h" #include "qemu/typedefs.h" +#include "qemu/fprintf-fn.h" #include "exec/cpu-common.h" #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__) @@ -76,9 +77,6 @@ # error Unknown pointer size #endif -typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) - GCC_FMT_ATTR(2, 3); - #ifdef _WIN32 #define fsync _commit #if !defined(lseek) diff --git a/qemu/include/qemu/fprintf-fn.h b/qemu/include/qemu/fprintf-fn.h new file mode 100644 index 00000000..9ddc90f1 --- /dev/null +++ b/qemu/include/qemu/fprintf-fn.h @@ -0,0 +1,17 @@ +/* + * Typedef for fprintf-alike function pointers. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_FPRINTF_FN_H +#define QEMU_FPRINTF_FN_H 1 + +#include "qemu/compiler.h" +#include + +typedef int (*fprintf_function)(FILE *f, const char *fmt, ...) + GCC_FMT_ATTR(2, 3); + +#endif