[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/21] util/osdep: Avoid madvise proto on modern Solaris
From: |
Peter Maydell |
Subject: |
[PULL 19/21] util/osdep: Avoid madvise proto on modern Solaris |
Date: |
Fri, 18 Mar 2022 13:23:04 +0000 |
From: Andrew Deason <adeason@sinenomine.net>
On older Solaris releases (before Solaris 11), we didn't get a
prototype for madvise, and so util/osdep.c provides its own prototype.
Some time between the public Solaris 11.4 release and Solaris 11.4.42
CBE, we started getting an madvise prototype that looks like this:
extern int madvise(void *, size_t, int);
which conflicts with the prototype in util/osdeps.c. Instead of always
declaring this prototype, check if we're missing the madvise()
prototype, and only declare it ourselves if the prototype is missing.
Move the prototype to include/qemu/osdep.h, the normal place to handle
platform-specific header quirks.
The 'missing_madvise_proto' meson check contains an obviously wrong
prototype for madvise. So if that code compiles and links, we must be
missing the actual prototype for madvise.
Signed-off-by: Andrew Deason <adeason@sinenomine.net>
Message-id: 20220316035227.3702-2-adeason@sinenomine.net
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
meson.build | 23 +++++++++++++++++++++--
include/qemu/osdep.h | 8 ++++++++
util/osdep.c | 3 ---
3 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/meson.build b/meson.build
index bae62efc9c3..282e7c46505 100644
--- a/meson.build
+++ b/meson.build
@@ -1715,11 +1715,30 @@ config_host_data.set('CONFIG_FDATASYNC',
cc.links(gnu_source_prefix + '''
#error Not supported
#endif
}'''))
-config_host_data.set('CONFIG_MADVISE', cc.links(gnu_source_prefix + '''
+
+has_madvise = cc.links(gnu_source_prefix + '''
#include <sys/types.h>
#include <sys/mman.h>
#include <stddef.h>
- int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }'''))
+ int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }''')
+missing_madvise_proto = false
+if has_madvise
+ # Some platforms (illumos and Solaris before Solaris 11) provide madvise()
+ # but forget to prototype it. In this case, has_madvise will be true (the
+ # test program links despite a compile warning). To detect the
+ # missing-prototype case, we try again with a definitely-bogus prototype.
+ # This will only compile if the system headers don't provide the prototype;
+ # otherwise the conflicting prototypes will cause a compiler error.
+ missing_madvise_proto = cc.links(gnu_source_prefix + '''
+ #include <sys/types.h>
+ #include <sys/mman.h>
+ #include <stddef.h>
+ extern int madvise(int);
+ int main(void) { return madvise(0); }''')
+endif
+config_host_data.set('CONFIG_MADVISE', has_madvise)
+config_host_data.set('HAVE_MADVISE_WITHOUT_PROTOTYPE', missing_madvise_proto)
+
config_host_data.set('CONFIG_MEMFD', cc.links(gnu_source_prefix + '''
#include <sys/mman.h>
int main(void) { return memfd_create("foo", MFD_ALLOW_SEALING); }'''))
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 322103aadbd..f2274b24cbf 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -400,6 +400,14 @@ void qemu_anon_ram_free(void *ptr, size_t size);
#define SIGIO SIGPOLL
#endif
+#ifdef HAVE_MADVISE_WITHOUT_PROTOTYPE
+/*
+ * See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for discussion
+ * about Solaris missing the madvise() prototype.
+ */
+extern int madvise(char *, size_t, int);
+#endif
+
#if defined(CONFIG_LINUX)
#ifndef BUS_MCEERR_AR
#define BUS_MCEERR_AR 4
diff --git a/util/osdep.c b/util/osdep.c
index 7c4deda6feb..1825399bcf5 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -28,9 +28,6 @@
#ifdef CONFIG_SOLARIS
#include <sys/statvfs.h>
-/* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
- discussion about Solaris header problems */
-extern int madvise(char *, size_t, int);
#endif
#include "qemu-common.h"
--
2.25.1
- [PULL 09/21] hw/intc: Rename CONFIG_ARM_GIC_TCG into CONFIG_ARM_GICV3_TCG, (continued)
- [PULL 09/21] hw/intc: Rename CONFIG_ARM_GIC_TCG into CONFIG_ARM_GICV3_TCG, Peter Maydell, 2022/03/18
- [PULL 11/21] target/arm: Log M-profile vector table accesses, Peter Maydell, 2022/03/18
- [PULL 13/21] hw/arm/xlnx-zynqmp: Add an unimplemented SERDES area, Peter Maydell, 2022/03/18
- [PULL 10/21] hw/arm/virt: Fix gic-version=max when CONFIG_ARM_GICV3_TCG is unset, Peter Maydell, 2022/03/18
- [PULL 12/21] target/arm: Log fault address for M-profile faults, Peter Maydell, 2022/03/18
- [PULL 14/21] target/arm: Make rvbar settable after realize, Peter Maydell, 2022/03/18
- [PULL 15/21] hw/misc: Add a model of the Xilinx ZynqMP CRF, Peter Maydell, 2022/03/18
- [PULL 16/21] hw/arm/xlnx-zynqmp: Connect the ZynqMP CRF, Peter Maydell, 2022/03/18
- [PULL 18/21] hw/arm/xlnx-zynqmp: Connect the ZynqMP APU Control, Peter Maydell, 2022/03/18
- [PULL 17/21] hw/misc: Add a model of the Xilinx ZynqMP APU Control, Peter Maydell, 2022/03/18
- [PULL 19/21] util/osdep: Avoid madvise proto on modern Solaris,
Peter Maydell <=
- [PULL 20/21] hw/i386/acpi-build: Avoid 'sun' identifier, Peter Maydell, 2022/03/18
- [PULL 21/21] util/osdep: Remove some early cruft, Peter Maydell, 2022/03/18
- Re: [PULL 00/21] target-arm queue, Peter Maydell, 2022/03/19