From 53dd82a7ca24f1353d2eeaba0fc684ef4f8b558c Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Thu, 8 Mar 2018 08:55:22 -0500 Subject: [PATCH] oslib-posix: check for posix_memalign in configure script Check for the presence of posix_memalign() in the configure script, not using "defined(_POSIX_C_SOURCE) && !defined(__sun__)". This lets qemu use posix_memalign() on NetBSD versions that have it, instead of falling back to valloc() which is wasteful when the required alignment is smaller than a page. Backports commit 9bc5a7193fb422ee53187601eba577ee5d195522 from qemu --- qemu/configure | 15 +++++++++++++++ qemu/util/oslib-posix.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/qemu/configure b/qemu/configure index 33e7c224..1b169131 100755 --- a/qemu/configure +++ b/qemu/configure @@ -1196,6 +1196,21 @@ if test "$sanitizers" = "yes" ; then fi fi +########################################## +# check if we have posix_memalign() + +posix_memalign=no +cat > $TMPC << EOF +#include +int main(void) { + void *p; + return posix_memalign(&p, 8, 8); +} +EOF +if compile_prog "" "" ; then + posix_memalign=yes +fi + ########################################## # End of CC checks # After here, no more $cc or $ld runs diff --git a/qemu/util/oslib-posix.c b/qemu/util/oslib-posix.c index c86c7ff4..762bcb31 100644 --- a/qemu/util/oslib-posix.c +++ b/qemu/util/oslib-posix.c @@ -84,7 +84,7 @@ void *qemu_try_memalign(size_t alignment, size_t size) alignment = sizeof(void*); } -#if defined(_POSIX_C_SOURCE) && !defined(__sun__) +#if defined(CONFIG_POSIX_MEMALIGN) int ret; ret = posix_memalign(&ptr, alignment, size); if (ret != 0) {