From patchwork Sat Feb 26 18:07:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546182 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1375903imf; Sat, 26 Feb 2022 10:11:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjXkGtjcFxSCjXJec5WpnH4YG+CxeeVehBrPVEdXaKhJziuaKMXFsIMgZk9A9SUBTF/F7D X-Received: by 2002:a25:80c6:0:b0:624:4ef6:abeb with SMTP id c6-20020a2580c6000000b006244ef6abebmr12127855ybm.394.1645899087654; Sat, 26 Feb 2022 10:11:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645899087; cv=none; d=google.com; s=arc-20160816; b=NGn4/Fm+wjLKCl1e9NshCsFOk462VXU3T+6qHuhazbDpMV0KduxZnKw0B8CLO+t7At zDbYoxuusgamb1A2sAFtyBLggD3ogvFaNDtCsUnW7kKgqvHbQRAQYVEhiHnkBFzCpol9 P4xrTQijEvaeveG9ghfNVeqHMERUoSB9hgCnxQ2pGvOJ1htecJD9Bd2/J2dqQweKchbN GX3h890qRWpBPCRjrzhrv9nCpGxL8sAGb+EJlaujxlCHFDK1KSPTp+O9zlQGWU8DgBoy GHB+qagh0cuO56oJ2JTi/UOsCJS/puT2NzKxvY+KiNCrDT7VqhE51dq7CCricPt5BHw3 mX9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=WRvAwDdZz4cYnOqR7LnotomJn/XVA//9i159XJwF/QI=; b=iJdEx+/L6BzbAI0/JSoXKClojXlxJbPO6H1t/2c4PU9Ig6n43Pvj5IewBopGqHF9E/ QXb2meIvLSQP2W2eViGYeoGBxwxgjxbK/AemFOveNoJAbEQiAJVHQrcOul1DabJm3KB9 OlHBXPofjCRFpkcHs/O/pvgm/mA8nvXb2fxUHEcRHuDEigaidvpGYg4rsTQH99w2qnE2 Am+hHFIZgY1px2knMmNDItW6qdrO/ru+KY+WRz9ucbhNQ8nWgOzttoFkHVSBdhu6bKf2 6XG3RbvjeUEIVEEnytZOJeyrJinkqIjhj4OHI5RK4ZejEKx+EFaR9w+PqRx4UZ71Cnl9 lpRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xnRAsAJe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k8-20020a25bec8000000b0062107f7d9f6si4882278ybm.446.2022.02.26.10.11.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:11:27 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xnRAsAJe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1XT-0003Rm-5R for patch@linaro.org; Sat, 26 Feb 2022 13:11:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Tl-0005do-KG for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:37 -0500 Received: from [2a00:1450:4864:20::42d] (port=43906 helo=mail-wr1-x42d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nO1Ti-0004Op-C1 for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:37 -0500 Received: by mail-wr1-x42d.google.com with SMTP id s1so9148275wrg.10 for ; Sat, 26 Feb 2022 10:07:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WRvAwDdZz4cYnOqR7LnotomJn/XVA//9i159XJwF/QI=; b=xnRAsAJeeo85tyhoFFeFLFxXowGYT0B0cDkUJT1m5pl4bsVcF0szrBWMokm0PYdiTv W+q2QEeAPLQ5S7p9H0uxFUc0fub98IyuxqjIrmD8dHaG9JCUwKe7dLO0j9UOXKtkUFtt M3R4gAxOmh3rf8Z1n8Qaf2j2FBFKBAlsVJw7ezSHdhl06FF5jby4t9SmjNlyG/7aiSdd WtE6UouZzK6OLIynPwSNy7yGTB7NMJz/H5flcu7QYeP3KfBD2+1REbQKWtumej0hH4rd awItjUDrEzrKQSIr7dgkBXnFWtj7x7jL7uPRxHi1epZph4Nit1gxucgyeuy2oZH2xlHs Ns2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WRvAwDdZz4cYnOqR7LnotomJn/XVA//9i159XJwF/QI=; b=NO1YE2X8pRZpeEvdHw2v4Lp7NKOriGC5q3aMUmxmG5aHFgL9FPFro9vOW1uGekxjqt 2BYLrMNby5aidyqwxEI9opuBp5RPfjwLVOQSGP76d54pkRS8wUM4MhuNSKSgllMrsobS sXrHMQCbHRpfyw6Ls3WGYl05mnPoY598IFAdW1PHSg8PisOosBCfaqEwLJHY0utidD4J +7OWrpWIZMPltfQAiCPsTRVd6jSM/+sfZetDUcfOmKP0Y4DERra74nIXCHMGZAWvvTho quksYUiMy7edSlF0582hTICWE9eWWJP+UHZwGQBpFZCCUnx952Y6ESGmuJEcp1tLMzvj UE8A== X-Gm-Message-State: AOAM5325lPHexs6pUPxv+dkPdKfjjta1YXxpz9AnJJrd2SMTiCFQhpHF +uNI/dJn5xy0NdoRt2C4gy9UK4CuHl1EyA== X-Received: by 2002:a05:6000:18ab:b0:1e8:f67a:1518 with SMTP id b11-20020a05600018ab00b001e8f67a1518mr10143533wri.52.1645898852458; Sat, 26 Feb 2022 10:07:32 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:32 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 7/9] util: Use meson checks for valloc() and memalign() presence Date: Sat, 26 Feb 2022 18:07:21 +0000 Message-Id: <20220226180723.1706285-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42d (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- meson.build | 2 ++ util/memalign.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 21511d4fb61..1c44198ebda 100644 --- a/meson.build +++ b/meson.build @@ -1610,6 +1610,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 ')) 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 ')) 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 ee3393cc601..fc8228bffb5 100644 --- a/util/memalign.c +++ b/util/memalign.c @@ -25,6 +25,8 @@ */ #include "qemu/osdep.h" +#include "qemu/host-utils.h" +#include "trace.h" void *qemu_try_memalign(size_t alignment, size_t size) { @@ -50,10 +52,12 @@ void *qemu_try_memalign(size_t alignment, size_t size) } else { ptr = NULL; } -#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;