From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 06/18] util: Use meson checks for valloc() and memalign() presence
Date: Mon, 7 Mar 2022 16:46:57 +0000 [thread overview]
Message-ID: <20220307164709.2503250-7-peter.maydell@linaro.org> (raw)
In-Reply-To: <20220307164709.2503250-1-peter.maydell@linaro.org>
Instead of assuming that all CONFIG_BSD have valloc() and anything
else is memalign(), explicitly check for those functions in
meson.build and use the "is the function present" define. Tests for
specific functionality are better than which-OS checks; this also
lets us give a helpful error message if somehow there's no usable
function present.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20220226180723.1706285-8-peter.maydell@linaro.org
---
meson.build | 2 ++
util/memalign.c | 6 ++++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/meson.build b/meson.build
index bc0ac931e1a..774d0248a62 100644
--- a/meson.build
+++ b/meson.build
@@ -1623,6 +1623,8 @@ config_host_data.set('CONFIG_POSIX_FALLOCATE', cc.has_function('posix_fallocate'
# thinking that Windows has posix_memalign()
config_host_data.set('CONFIG_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix: '#include <stdlib.h>'))
config_host_data.set('CONFIG_ALIGNED_MALLOC', cc.has_function('_aligned_malloc'))
+config_host_data.set('CONFIG_VALLOC', cc.has_function('valloc'))
+config_host_data.set('CONFIG_MEMALIGN', cc.has_function('memalign'))
config_host_data.set('CONFIG_PPOLL', cc.has_function('ppoll'))
config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include <sys/uio.h>'))
config_host_data.set('CONFIG_SEM_TIMEDWAIT', cc.has_function('sem_timedwait', dependencies: threads))
diff --git a/util/memalign.c b/util/memalign.c
index 22b405700e3..083aaae619c 100644
--- a/util/memalign.c
+++ b/util/memalign.c
@@ -56,10 +56,12 @@ void *qemu_try_memalign(size_t alignment, size_t size)
}
#elif defined(CONFIG_ALIGNED_MALLOC)
ptr = _aligned_malloc(size, alignment);
-#elif defined(CONFIG_BSD)
+#elif defined(CONFIG_VALLOC)
ptr = valloc(size);
-#else
+#elif defined(CONFIG_MEMALIGN)
ptr = memalign(alignment, size);
+#else
+ #error No function to allocate aligned memory available
#endif
trace_qemu_memalign(alignment, size, ptr);
return ptr;
--
2.25.1
next prev parent reply other threads:[~2022-03-07 16:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-07 16:46 [PULL 00/18] target-arm queue Peter Maydell
2022-03-07 16:46 ` [PULL 01/18] util: Make qemu_oom_check() a static function Peter Maydell
2022-03-07 16:46 ` [PULL 02/18] util: Unify implementations of qemu_memalign() Peter Maydell
2022-03-07 16:46 ` [PULL 03/18] util: Return valid allocation for qemu_try_memalign() with zero size Peter Maydell
2022-03-07 16:46 ` [PULL 04/18] meson.build: Don't misdetect posix_memalign() on Windows Peter Maydell
2022-03-07 16:46 ` [PULL 05/18] util: Share qemu_try_memalign() implementation between POSIX and Windows Peter Maydell
2022-03-07 16:46 ` Peter Maydell [this message]
2022-03-07 16:46 ` [PULL 07/18] util: Put qemu_vfree() in memalign.c Peter Maydell
2022-03-07 16:46 ` [PULL 08/18] osdep: Move memalign-related functions to their own header Peter Maydell
2022-03-07 16:47 ` [PULL 09/18] target/arm/translate-neon: UNDEF if VLD1/VST1 stride bits are non-zero Peter Maydell
2022-03-07 16:47 ` [PULL 10/18] target/arm/translate-neon: Simplify align field check for VLD3 Peter Maydell
2022-03-07 16:47 ` [PULL 11/18] hw/intc/arm_gicv3_its: Add trace events for commands Peter Maydell
2022-03-07 16:47 ` [PULL 12/18] hw/intc/arm_gicv3_its: Add trace events for table reads and writes Peter Maydell
2022-03-07 16:47 ` [PULL 13/18] hw/intc/arm_gicv3: Specify valid and impl in MemoryRegionOps Peter Maydell
2022-03-07 16:47 ` [PULL 14/18] hw/intc/arm_gicv3: Fix missing spaces in error log messages Peter Maydell
2022-03-07 16:47 ` [PULL 15/18] hw/intc/arm_gicv3_cpuif: Fix register names in ICV_HPPIR read trace event Peter Maydell
2022-03-07 16:47 ` [PULL 16/18] ui/cocoa: Use the standard about panel Peter Maydell
2022-03-07 16:47 ` [PULL 17/18] target/arm: Provide cpu property for controling FEAT_LPA2 Peter Maydell
2022-03-07 16:47 ` [PULL 18/18] hw/arm/virt: Disable LPA2 for -machine virt-6.2 Peter Maydell
2022-03-08 17:08 ` [PULL 00/18] target-arm queue Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220307164709.2503250-7-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).