From patchwork Fri Mar 4 11:21:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 548101 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1208imq; Fri, 4 Mar 2022 03:23:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwd+OG6GJ46HClW2sn5r4ML+KvKj0Puq712LmHtGihSoGLX8BKTUv4RHIBDCMpfosMXupvJ X-Received: by 2002:a25:4052:0:b0:628:cdca:afb7 with SMTP id n79-20020a254052000000b00628cdcaafb7mr5799908yba.81.1646392996114; Fri, 04 Mar 2022 03:23:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646392996; cv=none; d=google.com; s=arc-20160816; b=oVMewswv3D5ITFKg1zA9K+JDe5KSCfpL8AlyTdM8BnlncGFh+828WnpclfTJ1RLnJ1 VkyxG3EmF6YGylpzR2whh4yM8xC71fB78Wn0CTDD7cC3HCcntzjRM4+Lq73wqLTXPpaO STlJBKt4tnQKO0vCoHOSHpg6gHqW3jq2K2ByOlKaVFrn8VcJHbFm00lhgQ49f5OjoAVj bAgwC6Qywfjplm1RIruSzMQ7fLrqLfMk5s6FqDc5S5HLgE+9VyUNtajGyJDiLaJmm/sv zCzGer64klj15l6l/dk3xWH0U9HmPlGz+iBZr7/izN9GRd2gleQ6n4HWW58SQJ4ZIIE3 nAzA== 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=ZNZZHp62CxnlLWVTnJBVL309n4Twf4DbK/QyJ2gwLqA=; b=K6in9XrYth2/oJeqaUHe9oIEp28UlCm7coYHA9KgpKn3sQbAktjw6h1iyVpD0zLHsW EbVqKS23tOrlX/GwVzr7a+qyJygDhSBBxBb6TIKqAc6ObIyYtjTW5pCNrX9c4/JMr5cL upSUnfzwZcf0MaMkELJ+gxGjGZ2z39wyPQlzG1G7oELnTc3htx56CB9h0PgaJiMruBeL qokGDZLbTt1RXAbi60eWQSvXD9y/rAPbrinbgv55BDGF/DJNUv1xGNgq1nYDeCdcYqkN kRXbd527HbcVmQHsTjm5uYG5vbJ5aSL97yrNZ+e2ZoDI+du6LO0r83H68YuCMwSDql4e KtQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LjxK+GVm; 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 b18-20020a25fa12000000b0061def015f08si3866919ybe.97.2022.03.04.03.23.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:23:16 -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=LjxK+GVm; 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]:53594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ61j-0002Xu-Jx for patch@linaro.org; Fri, 04 Mar 2022 06:23:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ606-0002VK-C2 for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:34 -0500 Received: from [2a00:1450:4864:20::32d] (port=35643 helo=mail-wm1-x32d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ603-0004dv-H2 for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:34 -0500 Received: by mail-wm1-x32d.google.com with SMTP id v2-20020a7bcb42000000b0037b9d960079so7030832wmj.0 for ; Fri, 04 Mar 2022 03:21:31 -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=ZNZZHp62CxnlLWVTnJBVL309n4Twf4DbK/QyJ2gwLqA=; b=LjxK+GVmazJ8aWmC6+Xnh7J1XDLp+Pw6wKRVdWhqsEr7kh6W22e62CCGnhxJSM47vr Q4F2KqsQHmdJ+WuleYR3Tiqenod7iy4NaFtZ80MHhTkU/PxDC8WrD9GvJdSgEokXMwmJ lKvlOhm4LH/3WMmzHWGPsIA8+bt7NHdKoLIF1md4Awy74jWw1UsdDOYwtxEn+r0AVExK KkLoemUqOpJS8yewVxZGNfvXrQxdTkaMtrBe1qbeJRTGU0JLrRc4of6Rs5f/MxVlud0U T+NMmkF44qqFJNyHlEMQm024hQpnAAJBu1Owtdhha4bC+dYSKnn0RLMI+dNkQAnEoFA/ kxYQ== 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=ZNZZHp62CxnlLWVTnJBVL309n4Twf4DbK/QyJ2gwLqA=; b=4QUodWv+p9ehR128V2DOkz1IR4FwSsRu5Jv8F6e0tRztJvJTKGD16PyrI/3eAbU8KF ck4L+3Z8bvogrtSMXScmpbzjhG4kMLfhaD11Fz3B/iMQwzg3cq2ZClxoERQwv5cZi0ot BRKZ6y5f6MN/yrPwUK1whgTQ57BPaXID+ti9qQeNRkgWH0n1VwBD4oBHbCDGyVFGGzMP lVqFvInSRXxPdiEmt56hKbqsRv9zkDs9RGWxJHvMHP4kfigrV9+5f2MgHsU1auUzNRHs 22BH4ZViSHDCqItrWdNt87TALI5WlJDFlUy22n+7VMWIoOVZ3NK53KgICgIJ2J6v+p4Q BY+g== X-Gm-Message-State: AOAM533l2yh8QLRTITFev3hzOuVuhFBl+JIgaWlxLaINRVfdaj57d7m7 78lp3sCgeDPU8/1hMqAty+GlTB50IZxviA== X-Received: by 2002:a05:600c:4f85:b0:382:e2bf:5fd2 with SMTP id n5-20020a05600c4f8500b00382e2bf5fd2mr7354132wmq.30.1646392890257; Fri, 04 Mar 2022 03:21:30 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:29 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 1/9] hw/usb/redirect.c: Stop using qemu_oom_check() Date: Fri, 4 Mar 2022 11:21:18 +0000 Message-Id: <20220304112126.2261039-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32d (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.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 , Richard Henderson , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" qemu_oom_check() is a function which essentially says "if you pass me a NULL pointer then print a message then abort()". On POSIX systems the message includes strerror(errno); on Windows it includes the GetLastError() error value printed as an integer. Other than in the implementation of qemu_memalign(), we use this function only in hw/usb/redirect.c, for three checks: * on a call to usbredirparser_create() * on a call to usberedirparser_serialize() * on a call to malloc() The usbredir library API functions make no guarantees that they will set errno on errors, let alone that they might set the Windows-specific GetLastError string. malloc() is documented as setting errno, not GetLastError -- and in any case the only thing it might set errno to is ENOMEM. So qemu_oom_check() isn't the right thing for any of these. Replace them with straightforward error-checking code. This will allow us to get rid of qemu_oom_check(). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Eric Blake Message-id: 20220226180723.1706285-2-peter.maydell@linaro.org --- hw/usb/redirect.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 5f0ef9cb3b0..8692ea25610 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -1239,7 +1239,11 @@ static void usbredir_create_parser(USBRedirDevice *dev) DPRINTF("creating usbredirparser\n"); - dev->parser = qemu_oom_check(usbredirparser_create()); + dev->parser = usbredirparser_create(); + if (!dev->parser) { + error_report("usbredirparser_create() failed"); + exit(1); + } dev->parser->priv = dev; dev->parser->log_func = usbredir_log; dev->parser->read_func = usbredir_read; @@ -2239,7 +2243,10 @@ static int usbredir_put_parser(QEMUFile *f, void *priv, size_t unused, } usbredirparser_serialize(dev->parser, &data, &len); - qemu_oom_check(data); + if (!data) { + error_report("usbredirparser_serialize failed"); + exit(1); + } qemu_put_be32(f, len); qemu_put_buffer(f, data, len); @@ -2330,7 +2337,11 @@ static int usbredir_get_bufpq(QEMUFile *f, void *priv, size_t unused, bufp->len = qemu_get_be32(f); bufp->status = qemu_get_be32(f); bufp->offset = 0; - bufp->data = qemu_oom_check(malloc(bufp->len)); /* regular malloc! */ + bufp->data = malloc(bufp->len); /* regular malloc! */ + if (!bufp->data) { + error_report("usbredir_get_bufpq: out of memory"); + exit(1); + } bufp->free_on_destroy = bufp->data; qemu_get_buffer(f, bufp->data, bufp->len); QTAILQ_INSERT_TAIL(&endp->bufpq, bufp, next); From patchwork Fri Mar 4 11:21:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 548104 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1220imq; Fri, 4 Mar 2022 03:23:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2/xx1eRybl4tumU06T+VEo6MDRsxgAEBPRqk0hmSN6dHMJs7hAoicmmTHABVM3xVGXiL5 X-Received: by 2002:a81:9210:0:b0:2dc:27d2:292e with SMTP id j16-20020a819210000000b002dc27d2292emr10316995ywg.20.1646393024774; Fri, 04 Mar 2022 03:23:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646393024; cv=none; d=google.com; s=arc-20160816; b=F5n+wbxGNFEsJhXJmvOgBhc8cUfLbjmgfTW3yOu+H5RAtXS5FDQvFjGThqPEA0hbZB 82X7LUfLu6e91ohNjVhVa6FL5m5rTPB6b1kIuc34UoBFqeiJyQJhtdapHHxxkkrhrz0L fLx+qb71vmMi9Qao4M5Yu2Q4sYncqrxZJ8torQ/1QJ7HQ3I2Eaeh6FrDpXJZaAYhykN1 QxnPz8UsBnRdZVz1oUHpaFYQTboattoN93rqILsQdNQhswOgI0+Fbh01SZhYxIrDS8WK 50ttdOuoAY0fnOV+0LrilI0ksu/ncO8M/X8TQ4jFvqycwZlUdcYPfcBuZKiAXJhjLw/9 eMCQ== 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=khb2dSFPApkPaahIP5O1Jg4lPgEuKg6KdJgWB44Ysm4=; b=uAzLNHtULPILMINchtgJLeMLrj1CwXjdS9pJgnXv3z52P7jZ0XpydJmkh5tNfNbUTD NpcCydDJnuKi0qqkdS6WL6hmmvGijed87UUJrCWNIZGEZm9qe7DcHir7WQuVPd4fBTbd g4A+LcfiuOGlrcn06hz1ZUTrPeXKCvL6gQJ2rJScFsbLn+tHPGhQbGq7panoWs5vtSWN bWUI3hk1E2TwuxrqBi++naGS6Rmr84q57+JpD4c3xmDHGv1uBaqnPGPp9cbvpoASLj7Z qBDCZ+DYxDtjbcKrXGYdSa4IzA8wYPl0POQL33LQaqepRv52JWip2VGJcTDJzEQbV0At 7leA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D9lD8OG5; 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 r6-20020a0de806000000b002dc39774779si3515432ywe.85.2022.03.04.03.23.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:23:44 -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=D9lD8OG5; 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]:54942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ62C-0003V3-7I for patch@linaro.org; Fri, 04 Mar 2022 06:23:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ606-0002VQ-Fk for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:34 -0500 Received: from [2a00:1450:4864:20::331] (port=42562 helo=mail-wm1-x331.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ604-0004e6-EG for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:34 -0500 Received: by mail-wm1-x331.google.com with SMTP id r187-20020a1c2bc4000000b003810e6b192aso4920332wmr.1 for ; Fri, 04 Mar 2022 03:21:32 -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=khb2dSFPApkPaahIP5O1Jg4lPgEuKg6KdJgWB44Ysm4=; b=D9lD8OG5HGPwrcRa9aTTnCMhLk2rm3gvXNJZ+0kbAdsx8PElSbOjcCZmTJfxMBwvKL WwvA/GSOs7maPZxp+kNaW2bAde9wUUTXo622qu4RfvrAMI3w0FvMBnQhk0Lp7eCh3Rpr xbTuS0BaT5b/OS1NyxtlnwA2hJg+e913ZteY6s1xXiiZ+JsXvOKLj/xbbCeIId57zHqb eRqkaXWQlNY0Qjujs1wpCQW8gAk7r333MzRYj1dNJkXiKMAMPc96on219pF2i0npphYD RZ58CSoMiV6khScQpJzDbzJSQx0ENV7dPE+QyeKPKRM3YyUGQnXDN+dLF46i/JbEeyQ2 Jebg== 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=khb2dSFPApkPaahIP5O1Jg4lPgEuKg6KdJgWB44Ysm4=; b=fKs84N/5md15VNPHEMzh+bR0PozsmkOjC+TlCwu512PkFlznjDbOWLlZ5bzIStmKCy Ibct7j8pnLqD9PpKr7HautVWNAO21QQfJGLOOWwxacvFnpH0KpUdA4bBlOR3XDUsxGIW kHyaPEFBOGRegiL4x/6Bro9EvxUpBZWkq+V/2X0p6LLc8MuAqQ/Xv4E5lZSHFbyDOyp8 JfnHxaCQJmTNayIKk6vaCI5tSkBTgytlhS8D6Izpo1V7W9m2v020linEDJq+taqcvVu9 xpRFD65BZ1aL5A4rOdaq6tSTHZqwcecUkVHLqOtJ2qhpiPQwn5Vb7dHuBLh9ONB4d6FL lELQ== X-Gm-Message-State: AOAM530P2BiDP3L/PVZBwyEU8ahAkU+ZqAYB/eG0sg7ikFG16h9CnvRo udL4/Fjc33zS6EOPUb6qo6EWNx1gFEwRTQ== X-Received: by 2002:a05:600c:4e93:b0:382:b7fb:80b3 with SMTP id f19-20020a05600c4e9300b00382b7fb80b3mr7320293wmq.0.1646392891163; Fri, 04 Mar 2022 03:21:31 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:30 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 2/9] util: Make qemu_oom_check() a static function Date: Fri, 4 Mar 2022 11:21:19 +0000 Message-Id: <20220304112126.2261039-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::331 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x331.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 , Richard Henderson , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The qemu_oom_check() function, which we define in both oslib-posix.c and oslib-win32.c, is now used only locally in that file; make it static. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-id: 20220226180723.1706285-3-peter.maydell@linaro.org --- include/qemu-common.h | 2 -- util/oslib-posix.c | 2 +- util/oslib-win32.c | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/qemu-common.h b/include/qemu-common.h index 68b2e3bc109..8c0d9ab0f77 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -26,8 +26,6 @@ int qemu_main(int argc, char **argv, char **envp); #endif -void *qemu_oom_check(void *ptr); - ssize_t qemu_write_full(int fd, const void *buf, size_t count) QEMU_WARN_UNUSED_RESULT; diff --git a/util/oslib-posix.c b/util/oslib-posix.c index f2be7321c59..ed5974d3845 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -199,7 +199,7 @@ fail_close: return false; } -void *qemu_oom_check(void *ptr) +static void *qemu_oom_check(void *ptr) { if (ptr == NULL) { fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno)); diff --git a/util/oslib-win32.c b/util/oslib-win32.c index af559ef3398..c87e6977246 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -44,7 +44,7 @@ /* this must come after including "trace.h" */ #include -void *qemu_oom_check(void *ptr) +static void *qemu_oom_check(void *ptr) { if (ptr == NULL) { fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError()); From patchwork Fri Mar 4 11:21:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 548105 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1249imq; Fri, 4 Mar 2022 03:27:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrqvWWrz+fZBKLchtcQhbVVmhNF0JqJHeuGsrjMnwKIGX5cke2yMqxFg47yy0Ty46Wb3Vw X-Received: by 2002:a81:90d:0:b0:2db:fc82:ef40 with SMTP id 13-20020a81090d000000b002dbfc82ef40mr15376562ywj.384.1646393271720; Fri, 04 Mar 2022 03:27:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646393271; cv=none; d=google.com; s=arc-20160816; b=cLsthxC6txsJsk+4hCSkQsWUTdoBal+qgX39DQ2I+z7BWeb2Imp2c+xgVGdS2PC25B qzVQ6TMVw17aM1mzijIEb9rUrRDMBMkMRbeDB1h7S9+x6QQBD4Edi/HoJSmiDWlWh9YO vBy9g1OoRcdipgnqRiGBLJK7HHJrDBRLeE24NlwVwVKfUuinrB7f7Tekkoay8DWlCvpZ kYLZcTW7+biHa8meSfGhWig4zzPeMKZ0bnOZTSYdIIc9ipE6V3g6LgwlKTsAxZ81aMIn nW726KQRWS/sqS+uJRof+GPzm+mxISTd9tnMjfw6bJgzIi92a44GVA5RGMV+CT9n/baF VvQQ== 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=voFkZRHY5biQKFztGkfghmVhAahSUzLcgZ5Jwso4n1w=; b=xO2Onbo94g2c/5IgclKwVAWcxmrhVsgF6j3/paBkrCb3I9MI0PSdRQxmJf2W9s2EqD sySXSRb7JT2X0b2UBskz/hbcdYJ6iNX0AktbvGI0y5NUhx+qDwaR5uWr4pLUzEbKRLB0 pGtzabmA2S5JiK/94zXO2wJgmJHd/bmhcdNEef88EJh9hSncDrHMLkB/BRNXmLg0cfZR NEPIrR6egj/X5alu0PgCwh0sIsuL4NNqf93ptzshKmL/TVAWSC6DizsFNrZTbyTvIrXR QdnTa6tdRlioh0pdUESEUWxTDY8IvvNeUTFF+Dqe3QWdfiXrHHo5/GAXXJs5IcGUywP8 BOgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="I6s/sjLi"; 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 b7-20020a81db47000000b002d035ccf9e6si4159113ywn.138.2022.03.04.03.27.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:27:51 -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="I6s/sjLi"; 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]:33972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ66B-0008U2-3C for patch@linaro.org; Fri, 04 Mar 2022 06:27:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ607-0002YP-V3 for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:36 -0500 Received: from [2a00:1450:4864:20::435] (port=42999 helo=mail-wr1-x435.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ605-0004eI-Oh for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:35 -0500 Received: by mail-wr1-x435.google.com with SMTP id u10so10546501wra.9 for ; Fri, 04 Mar 2022 03:21: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=voFkZRHY5biQKFztGkfghmVhAahSUzLcgZ5Jwso4n1w=; b=I6s/sjLicrm2r7DzqEkqnSS5rBx45qb9IS45PZFp5i1nxWmfm95eDyUC9fdJ5BdDhM qbyiddMAD4BgatMByRgp5WA77JiyOn9S8tR5OkwHupBJqYRS/ZjeZAApwLoIJvDD3G1d LVqvHBK6xcQ9GFTNmibpCsrQ5189cKzYHjvBKJ1UPvQAtVM9ONNhAq1dVP+DzPU7zdoM MU3ogwFQDoXZ8yWU2IDLpZvAOxOeDltLnXcKJWgUOlbUR3kTga3yy3HD5CP9imI5MnzS IihRd3AIjkhriHjXzSsVCiDmGG4+kttDcotjpMEAjHsv+26EOcmtfKIDV7YG0hrrWWld EweQ== 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=voFkZRHY5biQKFztGkfghmVhAahSUzLcgZ5Jwso4n1w=; b=FxJVWgMV89oIQPtX9HqtWOqcJVFt8CnUp/a1uwpq2/Avhh1/ZhZlgdLM8Mq/ylu6j9 9wVT6uKfemMgd81LgEDxNp2on+ZA/nWdDyhOsm8+02xB9Wwu1P5C5uyGhfYuaYBnnGE4 hHCA97l+F8YdiqT7K3/LN6od6SoiUg2nl2UqIegjBeya+zK6GYD5npTZyNmRmdMKCEr8 u0OnWPLyxMCEAxU2yhms++vOA3K/baPFdx/Rh14JHtCwyWuGFj5YPoXhzjb4unBqGNIn beTh0ME2apmjZwBMgfZY5pOq+RV82Ae8P/20UhL7pxet2Jj+s+6AAexuFI4DPX0GI5eZ n87g== X-Gm-Message-State: AOAM533jDc2tnBTzn6v5T6JOEFbgmoQExv46EwXPr068E9eJ1jJ1K1do /Gk5cyZy+HwMnm+hyjHhokKoW0N+1pO0vQ== X-Received: by 2002:a05:6000:154e:b0:1f0:4747:5536 with SMTP id 14-20020a056000154e00b001f047475536mr7678886wry.76.1646392892378; Fri, 04 Mar 2022 03:21:32 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:31 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 3/9] util: Unify implementations of qemu_memalign() Date: Fri, 4 Mar 2022 11:21:20 +0000 Message-Id: <20220304112126.2261039-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::435 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x435.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 , Richard Henderson , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We implement qemu_memalign() in both oslib-posix.c and oslib-win32.c, but the two versions are essentially the same: they call qemu_try_memalign(), and abort() after printing an error message if it fails. The only difference is that the win32 version prints the GetLastError() value whereas the POSIX version prints strerror(errno). However, this is a bug in the win32 version: in commit dfbd0b873a85021 in 2020 we changed the implementation of qemu_try_memalign() from using VirtualAlloc() (which sets the GetLastError() value) to using _aligned_malloc() (which sets errno), but didn't update the error message to match. Replace the two separate functions with a single version in a new memalign.c file, which drops the unnecessary extra qemu_oom_check() function and instead prints a more useful message including the requested size and alignment as well as the errno string. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220226180723.1706285-4-peter.maydell@linaro.org Reviewed-by: Philippe Mathieu-Daudé --- util/memalign.c | 39 +++++++++++++++++++++++++++++++++++++++ util/oslib-posix.c | 14 -------------- util/oslib-win32.c | 14 -------------- util/meson.build | 1 + 4 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 util/memalign.c diff --git a/util/memalign.c b/util/memalign.c new file mode 100644 index 00000000000..6dfc20abbb1 --- /dev/null +++ b/util/memalign.c @@ -0,0 +1,39 @@ +/* + * memalign.c: Allocate an aligned memory region + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2010-2016 Red Hat, Inc. + * Copyright (c) 2022 Linaro Ltd + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" + +void *qemu_memalign(size_t alignment, size_t size) +{ + void *p = qemu_try_memalign(alignment, size); + if (p) { + return p; + } + fprintf(stderr, + "qemu_memalign: failed to allocate %zu bytes at alignment %zu: %s\n", + size, alignment, strerror(errno)); + abort(); +} diff --git a/util/oslib-posix.c b/util/oslib-posix.c index ed5974d3845..0278902ee79 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -199,15 +199,6 @@ fail_close: return false; } -static void *qemu_oom_check(void *ptr) -{ - if (ptr == NULL) { - fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno)); - abort(); - } - return ptr; -} - void *qemu_try_memalign(size_t alignment, size_t size) { void *ptr; @@ -234,11 +225,6 @@ void *qemu_try_memalign(size_t alignment, size_t size) return ptr; } -void *qemu_memalign(size_t alignment, size_t size) -{ - return qemu_oom_check(qemu_try_memalign(alignment, size)); -} - /* alloc shared memory pages */ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared, bool noreserve) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index c87e6977246..05857414695 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -44,15 +44,6 @@ /* this must come after including "trace.h" */ #include -static void *qemu_oom_check(void *ptr) -{ - if (ptr == NULL) { - fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError()); - abort(); - } - return ptr; -} - void *qemu_try_memalign(size_t alignment, size_t size) { void *ptr; @@ -68,11 +59,6 @@ void *qemu_try_memalign(size_t alignment, size_t size) return ptr; } -void *qemu_memalign(size_t alignment, size_t size) -{ - return qemu_oom_check(qemu_try_memalign(alignment, size)); -} - static int get_allocation_granularity(void) { SYSTEM_INFO system_info; diff --git a/util/meson.build b/util/meson.build index 3736988b9f6..f6ee74ad0c8 100644 --- a/util/meson.build +++ b/util/meson.build @@ -51,6 +51,7 @@ util_ss.add(when: 'CONFIG_POSIX', if_true: files('drm.c')) util_ss.add(files('guest-random.c')) util_ss.add(files('yank.c')) util_ss.add(files('int128.c')) +util_ss.add(files('memalign.c')) if have_user util_ss.add(files('selfmap.c')) From patchwork Fri Mar 4 11:21: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: 548103 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1216imq; Fri, 4 Mar 2022 03:23:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLudYAyGLGIq/j3b0KdqDx2Ol+yZ/0DCNafhHuqBDHfl9zffRjOO3ATE74KcfQHdrXKRyc X-Received: by 2002:a81:25c7:0:b0:2d0:9d5c:2463 with SMTP id l190-20020a8125c7000000b002d09d5c2463mr40615895ywl.164.1646393004016; Fri, 04 Mar 2022 03:23:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646393004; cv=none; d=google.com; s=arc-20160816; b=kD+5tc+tfVP8V+T1556g/5IgoJS5BuYx0Sj5N8gpU89Ki3ezIWltxyVcYzo1A7WpBa nobfMa/gKG2STVLDFi/UmikeUnJrh8VHUKcLnA1J3Qiu5KP/Yrr+wNNSofVrPIPavzYh 1BpYu+SA2n5HdrT2lu5gDKDePDzohId1nhxUndHeLee8i105aZnMRUJlQoVN7U1ZrKbn wD6tigCv5X+sg0QZnJPX6UC1nBYaVhDff7+S4lXnW5A0x1KFZt+VAbaEeA8ouLTMjfU4 nFkF9TMSF20NT38aNf4zDskacGhNKj7T/MBuesOrkwQswcP31TiYensbB5ylDf/YjQN2 n75w== 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=aw1khmsL1b3jjSBXuTHlqqORQZf6pcNTAPrzcIvj+hU=; b=dqup646jERiEHPyjulVl0dY0ItOZcgembHgSnSGUfLV6v+b/2f3i5l9FNX2gLqbqQV oJqQk7zCOAphorWd4ZijMfEFRRtg/T/VjZkt7sXR3oCWLVJt6OjspnQUfSk7z8+sJmw3 OEc7f7buB9uYhWFFi1lJpaV1ZwlgTUlVjr4/7fIEjv0KjQkLnF6JCe/UTlcnCnGcoKFv /Ho3YY/+r9Y9+nOqr/EP5nI5SYCE0ihe0v/O6F7TSA8etkOIX5GX/0JvNKng+qmz0oFd Yn2H2CRocRFR+iKlw0gDWzohekKDa5kxw7e4w0Lt0ADWGre8nDBRO6Rqm/+DD4dbHFo4 0R/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ft5D32Nt; 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 k5-20020a815605000000b002dbfd8c6c80si3828002ywb.540.2022.03.04.03.23.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:23:24 -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=ft5D32Nt; 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]:54328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ61r-00034b-GO for patch@linaro.org; Fri, 04 Mar 2022 06:23:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ608-0002Zv-GJ for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:36 -0500 Received: from [2a00:1450:4864:20::335] (port=36822 helo=mail-wm1-x335.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ606-0004f3-T7 for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:36 -0500 Received: by mail-wm1-x335.google.com with SMTP id r7-20020a1c4407000000b00380f6f473b0so255645wma.1 for ; Fri, 04 Mar 2022 03:21:34 -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=aw1khmsL1b3jjSBXuTHlqqORQZf6pcNTAPrzcIvj+hU=; b=ft5D32Nt5+dR1fEuly+ia2zINtI6Zy15tDDF3gsU+SsCwlgXdERaxwbCm/poOjHx6q mylHzrAts9pCQJGd9rDC1Fd57wt7G68/iNFmcJoBDUfNXnJOvcrO2Tm2XhTV/3FYdJe3 hWqNv7qdC+A74JpuktqyJYTL9YVvXNEPGJZY3SgaLCTXuqKBNGUZWtJnKf5DXOlNRa9P OfvZyB7JkfbBzSDqX2ZeIRDboUXOTuvgR+8rIiyF3xa3urHuvD5kY6NP2ExL+cn8MSRH WpdX6wDYURGWETz30iQAJFBGppyowRj0fCANMF6wywzCZ3tiPff8scliVvWHKKkT+ntH 0Y+A== 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=aw1khmsL1b3jjSBXuTHlqqORQZf6pcNTAPrzcIvj+hU=; b=CxtcLPiaH8b9UY6SRSYWEtZ9tU005BywYXzsVlaP77a0ELvSFjS1ERVB/HWibVGPHm S/VaD0L2nTD00DtOmfImMe/Ia1fRxzpw/xDyp/8SN1Tdo9vnVviOtHSsnB7ioxCiNDb5 iNijcw562DBSZLVlsFNcYrf6SqgsnNeMpJoUtoOWOcPN0dS77f7RYal9/7+t0JLHiO+X VsE/29Wsbt8Vby2+s3vm3pISxRgp8QhjIa2hep7ZT9QVI7q6KIYkNSSvYyF1GY5KIHCp 3XhmiLWiKsvVSgkHGt/pkIenuKq0hVDKgWdTlKMMPHyKfk7SuSj1kUxPKzDtzPWrVfAR 3fcQ== X-Gm-Message-State: AOAM530XZKtB9ery62VpXCmsMuGPTuRh7zPEvBE1t4em/e/TzhFz4TIQ 2QWlzjPT3ZXQFx1EIp6xwpPkb3DDkwWFPg== X-Received: by 2002:a1c:ed1a:0:b0:37f:a539:5d5e with SMTP id l26-20020a1ced1a000000b0037fa5395d5emr7412175wmh.37.1646392893522; Fri, 04 Mar 2022 03:21:33 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:32 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 4/9] util: Return valid allocation for qemu_try_memalign() with zero size Date: Fri, 4 Mar 2022 11:21:21 +0000 Message-Id: <20220304112126.2261039-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::335 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.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 , Richard Henderson , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently qemu_try_memalign()'s behaviour if asked to allocate 0 bytes is rather variable: * on Windows, we will assert * on POSIX platforms, we get the underlying behaviour of the posix_memalign() or equivalent function, which may be either "return a valid non-NULL pointer" or "return NULL" Explictly check for 0 byte allocations, so we get consistent behaviour across platforms. We handle them by incrementing the size so that we return a valid non-NULL pointer that can later be passed to qemu_vfree(). This is permitted behaviour for the posix_memalign() API and is the most usual way that underlying malloc() etc implementations handle a zero-sized allocation request, because it won't trip up calling code that assumes NULL means an error. (This includes our own qemu_memalign(), which will abort on NULL.) This change is a preparation for sharing the qemu_try_memalign() code between Windows and POSIX. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- util/oslib-posix.c | 3 +++ util/oslib-win32.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 0278902ee79..f7e22f4ff9b 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -209,6 +209,9 @@ void *qemu_try_memalign(size_t alignment, size_t size) g_assert(is_power_of_2(alignment)); } + if (size == 0) { + size++; + } #if defined(CONFIG_POSIX_MEMALIGN) int ret; ret = posix_memalign(&ptr, alignment, size); diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 05857414695..8c28d70904d 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -48,12 +48,14 @@ void *qemu_try_memalign(size_t alignment, size_t size) { void *ptr; - g_assert(size != 0); if (alignment < sizeof(void *)) { alignment = sizeof(void *); } else { g_assert(is_power_of_2(alignment)); } + if (size == 0) { + size++; + } ptr = _aligned_malloc(size, alignment); trace_qemu_memalign(alignment, size, ptr); return ptr; From patchwork Fri Mar 4 11:21:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 548108 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1275imq; Fri, 4 Mar 2022 03:32:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxviHPcFRjA8QDkXs7ycxkf4zenbajZWjNoRMdtvXq8eL6C5aw32uvGIUyu+MafrCtHA1Wm X-Received: by 2002:a25:585:0:b0:628:9860:39da with SMTP id 127-20020a250585000000b00628986039damr13134101ybf.383.1646393531859; Fri, 04 Mar 2022 03:32:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646393531; cv=none; d=google.com; s=arc-20160816; b=MLwkOF0FurW5dzPD+BaSPZsYYEKIANk9GIA9tapgZfkQLICapudxUgBglZtPTWN2O3 tn+l2waP7Rt0USmlbizmKlrly5jMvjTEsz9QMSY+Y/8gGO3CXTmBjKLRQkatrSs0kGf3 nVXwabHVWDrIamarRX21/wz7dL9m1sWm+Q5vCQ8V4n13TVjpjZM8KrbMe6C0MnUeCP9e U+svLqODpLwYze98fRhwgP+XEtlMQ1jprtLHDTaorkchzSxOFo7xEpMDwAEAKTZBUfV/ IM7M2JeE3ZmY/bDLGCoBb6MSu7AHMjh0OobA3jLavWhHZwhqixfqFFWItMjIzhB5Alvc H9Ow== 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=mcsPtmWVkD2iOC6zuv9lO7mH5DMh4k1zBSF/wMzprBs=; b=0MyNf/Ti5J3KGbQCFC67OT+ORyvIrmckhpuULcnz6j/zLZfwDp1UlBfbVoWP3hLxDw mEMTeVxlEea1u4O0HntXMJWs0G5Y9okEaJpk3blxJm6MM4iGOM8xRhc5iua8ZirnDrfW eJxj9D94ocxhJvVFrlP5KtTbnnia6ktn4ayCOEZTr/QGp+5jRuWnwNmCSANhoiIRK4up 8BRrN63ud6LSLSujrwONXG0LfU2gCcU6s2LBDSQi8HC0EKtsaaDvfWH3O6l9ngBAiCe+ Ppg+2Wja0wl5nkfmE6pzqbDO0n6WOHAFyexw8UotsfQfx3d2FoT/I2pEG/TkchwEhtzV D6rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Sm6UdJ83; 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 135-20020a81038d000000b002dc1590a287si3979194ywd.249.2022.03.04.03.32.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:32:11 -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=Sm6UdJ83; 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]:41788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ6AN-0005kO-63 for patch@linaro.org; Fri, 04 Mar 2022 06:32:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ609-0002dQ-K0 for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:37 -0500 Received: from [2a00:1450:4864:20::330] (port=39804 helo=mail-wm1-x330.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ607-0004fd-S6 for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:37 -0500 Received: by mail-wm1-x330.google.com with SMTP id o18-20020a05600c4fd200b003826701f847so6417499wmq.4 for ; Fri, 04 Mar 2022 03:21:35 -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=mcsPtmWVkD2iOC6zuv9lO7mH5DMh4k1zBSF/wMzprBs=; b=Sm6UdJ83Sqx8eMJ48iUyUo3ay0OTyiZullh8e7t/vxyzPHHbbOx4MCjN3DahoehJNq UxgWyb8ScdT2TokckQz63IU70kJ3jx0PlpcBsl448xET7Q4fJ9LtNYJbHBTolc3cTDy5 BmUYAqL4cqtgZie8scApN879/oH8lgf/Xq37DzCAG7R/YJgkqw1OlKrnhaCo6LsBjuOo zttu1kuaYjvGd/isR2lc2JJqG2xoozQezJsILg2CSmY/zF2DrjILTmqsLL5thL7uEEOi XYzjMKrdKDVu2d3sRb+AsWe52wiZGiq5/eaf8ACRhL2Pd1JUkNeFxpnQ+VSX4LJxNjrv Enyw== 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=mcsPtmWVkD2iOC6zuv9lO7mH5DMh4k1zBSF/wMzprBs=; b=RJDOmhUSvktt3ygcCYwfLlR8ms2ol1O5oQOVBo6J5/YrLpvfMkJdwOBLv/N4HnQ6IK sauEBkGED5yVI/i8WC875xulLYZA/CU1ebwcop0qKmK2RYi/6fS7yZlZJDYI8IFshyTQ 7AaftOEPAXt+mcQqAwJuvYHVhmxtNvHk+8NHPKBuja9JiJxsPrpAZCvu9V1/hNilcQHV VwT/SrWS0bOhzosgCckoNET3Rr/fAzF7vJ9SENrxemkEJTBucA+Cq5qS8DbH/wIi2VqO AjufrLGJeKgYCXa4up2MOmN5yr1KzQoFube/aIS+284HRvxvoxImpH1raHY1aMipgk9N rwPg== X-Gm-Message-State: AOAM532aXyADBIz1q/RldOwHMPmxwwPOehh+YKxtefAE8aBcrRUFmr9d bzV2BKc037MTepT69Z31NIMtE+xDgchChg== X-Received: by 2002:a05:600c:264e:b0:389:802e:c7fa with SMTP id 14-20020a05600c264e00b00389802ec7famr1813725wmy.93.1646392894532; Fri, 04 Mar 2022 03:21:34 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:34 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 5/9] meson.build: Don't misdetect posix_memalign() on Windows Date: Fri, 4 Mar 2022 11:21:22 +0000 Message-Id: <20220304112126.2261039-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::330 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x330.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 , Richard Henderson , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently we incorrectly think that posix_memalign() exists on Windows. This is because of a combination of: * the msys2/mingw toolchain/libc claim to have a __builtin_posix_memalign when there isn't a builtin of that name * meson will assume that if you have a __builtin_foo that counts for has_function('foo') Specifying a specific include file via prefix: causes meson to not treat builtins as sufficient and actually look for the function itself; see this meson pull request which added that as the official way to get the right answer: https://github.com/mesonbuild/meson/pull/1150 Currently this misdectection doesn't cause problems because we only use CONFIG_POSIX_MEMALIGN in oslib-posix.c; however that will change in a following commit. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220226180723.1706285-6-peter.maydell@linaro.org Reviewed-by: Philippe Mathieu-Daudé --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index a5b63e62cdc..73fd17a0523 100644 --- a/meson.build +++ b/meson.build @@ -1619,7 +1619,9 @@ config_host_data.set('CONFIG_CLOCK_ADJTIME', cc.has_function('clock_adjtime')) config_host_data.set('CONFIG_DUP3', cc.has_function('dup3')) config_host_data.set('CONFIG_FALLOCATE', cc.has_function('fallocate')) config_host_data.set('CONFIG_POSIX_FALLOCATE', cc.has_function('posix_fallocate')) -config_host_data.set('CONFIG_POSIX_MEMALIGN', cc.has_function('posix_memalign')) +# Note that we need to specify prefix: here to avoid incorrectly +# 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_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)) From patchwork Fri Mar 4 11:21:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 548102 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1214imq; Fri, 4 Mar 2022 03:23:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHjgpgRRZxWNGxzSkiNT9tVHPo9Vx7O7jtlze4FXPfIagvwrkoDhGU3uOP191l60JjTkO5 X-Received: by 2002:a25:6608:0:b0:628:d9bd:6245 with SMTP id a8-20020a256608000000b00628d9bd6245mr4523723ybc.560.1646393001378; Fri, 04 Mar 2022 03:23:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646393001; cv=none; d=google.com; s=arc-20160816; b=bWIUHdRDpRlaG4O6ULgS0woHnvCJxUzb4vbsiHimEbDd3KzP+nxmiqNst+Txf2jNye wryj/JOWqmjRsO/nXZk7b+Az0cRhr/DI4ur/fQs6Sc16T5fLP6z0D2JFs1pVWH1Q2T3l vcDwNH/M7x0m9PKBkPFHN8qCiQFLzf9kmlc+XelAiQ1qodrxmx+fgXPaIO1NrLkaRGNL 2yyvfhWr9hg57guw/xGPyJUtWE3GIG1LvnI0vnqpe8CZAF7Xm7dpkETaDhlmLzCBzmwF PsgH8AAekNtkhd36xgYzXPKF8ULV4pIU9lKvKPAHbzRyFQN+o9ImeTvUTLlKGCbSt4sY UXVw== 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=3IoHncrKvkRkJHPBCTp7M3clrurRATuEJ8R1LK7s9II=; b=mtkP8XiYKLnkiptRvOMhV51RjeE6nd7ZV0/s4OYW2JDWIuCWwQAe61xFZ7kMwkzJYE xuiEQ6USrt5QNZqwJyFr4TFXLAofdebY70YQ67dkzOJPDd9oNiO2G95XuPk6IHgYPwDw qsd40YzRjgv3lvs/daAR8My/QxkvPGh1mxncgIY8Nlu0+zmgIFzMPo5r5UARY8kC/Wpg +XGFA3yS0sBvSAJSidqC0zK0lqeZWHU4TZGvMGAn3GMaG9EhO0299ga5XKiTzb/PCfGZ OJalqFDdFicSGzAavk2kFHo9lW/VKUczsRPO3pVVuLYfxg3KJLmM1wxRIJ4sPKwkzB1h l59g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Gfz0cqsh; 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 17-20020a250d11000000b00628bb2b47a9si3919681ybn.329.2022.03.04.03.23.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:23:21 -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=Gfz0cqsh; 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]:54026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ61o-0002pX-RO for patch@linaro.org; Fri, 04 Mar 2022 06:23:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ60A-0002h3-Rm for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:38 -0500 Received: from [2a00:1450:4864:20::32e] (port=34062 helo=mail-wm1-x32e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ609-0004g5-1I for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:38 -0500 Received: by mail-wm1-x32e.google.com with SMTP id l2-20020a7bc342000000b0037fa585de26so5142670wmj.1 for ; Fri, 04 Mar 2022 03:21:36 -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=3IoHncrKvkRkJHPBCTp7M3clrurRATuEJ8R1LK7s9II=; b=Gfz0cqsh6OEZOF/xvs43pK5q2ueuEUwHi7NGoDbibXWSpdF4WSlMuitBdmrOiC3Lfw XFBckkVJ350GO2xLFiibCoNApVs1QkPGvicmmDJRpa/AOfyN02GJyeF91SaHfRVhiA0k 9Hxpv6nXOwmoR6wmGS9ycCYycnS8eoirTz5OYx1DJRDROAjF8CfNqAtFuvY+It272wyc rbOOBUv6OxFBIrRwz3M6kvEbcSC4ezxflUKtoBmGAEghrkryBPwOs0SgHL5qFO/7RGP4 aRTLvES0uiNlYYiWmi8+gcI3NuOv9K99D8DzzkpuYPeb/P/ejcFvYiGjMr0YmaM7hj1X jlCg== 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=3IoHncrKvkRkJHPBCTp7M3clrurRATuEJ8R1LK7s9II=; b=rCVRynB6eVTBxkuA5TzDOmeUK4LfLGirLoeoEvGtnd+jLZs+cNPTfB07LaJpWRjjWO CrFLq74DXd8+FpJcciNBCSf20uvG32mK+6f5+vbC32GE9Bqwf1pwMKetdShjla6LgjBN TsipSqSVKIs0iWCdgSGk3SxovJuWt+VNS68zBih3AU02WMY/YPGLd3jsCFvqtdDb0S2s xQy6bN/r8xBgqY7Ta3mTliyW3TxLs8ylJaKIVDs9RFxza0lM+Z/gBodcvhCchEqhhM3y Qy9lvgkOAIXB3Elcaq0EfVyHzW2cwJ/7ImxiTHiade+L+sTgik0aDZjf5kl0unyqq1hq j+rQ== X-Gm-Message-State: AOAM530c8uBryKliZzU+TTf71zsXGd7iYR4sd0B9Qu7zlEsYwMDrjzVL ZNExT1FFQSNlna/Pm2Kvpbjgs2Y0ZdmjsQ== X-Received: by 2002:a05:600c:350f:b0:381:738e:d678 with SMTP id h15-20020a05600c350f00b00381738ed678mr7285640wmq.124.1646392895725; Fri, 04 Mar 2022 03:21:35 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:35 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 6/9] util: Share qemu_try_memalign() implementation between POSIX and Windows Date: Fri, 4 Mar 2022 11:21:23 +0000 Message-Id: <20220304112126.2261039-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.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 , Richard Henderson , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The qemu_try_memalign() functions for POSIX and Windows used to be significantly different, but these days they are identical except for the actual allocation function called, and the POSIX version already has to have ifdeffery for different allocation functions. Move to a single implementation in memalign.c, which uses the Windows _aligned_malloc if we detect that function in meson. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220226180723.1706285-7-peter.maydell@linaro.org Reviewed-by: Philippe Mathieu-Daudé --- meson.build | 1 + util/memalign.c | 39 +++++++++++++++++++++++++++++++++++++++ util/oslib-posix.c | 29 ----------------------------- util/oslib-win32.c | 17 ----------------- 4 files changed, 40 insertions(+), 46 deletions(-) diff --git a/meson.build b/meson.build index 73fd17a0523..eae0e4febb3 100644 --- a/meson.build +++ b/meson.build @@ -1622,6 +1622,7 @@ config_host_data.set('CONFIG_POSIX_FALLOCATE', cc.has_function('posix_fallocate' # Note that we need to specify prefix: here to avoid incorrectly # 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_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 6dfc20abbb1..c3280528d24 100644 --- a/util/memalign.c +++ b/util/memalign.c @@ -25,6 +25,45 @@ */ #include "qemu/osdep.h" +#include "qemu/host-utils.h" +#include "trace.h" + +void *qemu_try_memalign(size_t alignment, size_t size) +{ + void *ptr; + + if (alignment < sizeof(void*)) { + alignment = sizeof(void*); + } else { + g_assert(is_power_of_2(alignment)); + } + + /* + * Handling of 0 allocations varies among the different + * platform APIs (for instance _alligned_malloc() will + * fail) -- ensure that we always return a valid non-NULL + * pointer that can be freed by qemu_vfree(). + */ + if (size == 0) { + size++; + } +#if defined(CONFIG_POSIX_MEMALIGN) + int ret; + ret = posix_memalign(&ptr, alignment, size); + if (ret != 0) { + errno = ret; + ptr = NULL; + } +#elif defined(CONFIG_ALIGNED_MALLOC) + ptr = _aligned_malloc(size, alignment); +#elif defined(CONFIG_BSD) + ptr = valloc(size); +#else + ptr = memalign(alignment, size); +#endif + trace_qemu_memalign(alignment, size, ptr); + return ptr; +} void *qemu_memalign(size_t alignment, size_t size) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index f7e22f4ff9b..91798f7e504 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -199,35 +199,6 @@ fail_close: return false; } -void *qemu_try_memalign(size_t alignment, size_t size) -{ - void *ptr; - - if (alignment < sizeof(void*)) { - alignment = sizeof(void*); - } else { - g_assert(is_power_of_2(alignment)); - } - - if (size == 0) { - size++; - } -#if defined(CONFIG_POSIX_MEMALIGN) - int ret; - ret = posix_memalign(&ptr, alignment, size); - if (ret != 0) { - errno = ret; - ptr = NULL; - } -#elif defined(CONFIG_BSD) - ptr = valloc(size); -#else - ptr = memalign(alignment, size); -#endif - trace_qemu_memalign(alignment, size, ptr); - return ptr; -} - /* alloc shared memory pages */ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared, bool noreserve) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 8c28d70904d..d9768532bec 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -44,23 +44,6 @@ /* this must come after including "trace.h" */ #include -void *qemu_try_memalign(size_t alignment, size_t size) -{ - void *ptr; - - if (alignment < sizeof(void *)) { - alignment = sizeof(void *); - } else { - g_assert(is_power_of_2(alignment)); - } - if (size == 0) { - size++; - } - ptr = _aligned_malloc(size, alignment); - trace_qemu_memalign(alignment, size, ptr); - return ptr; -} - static int get_allocation_granularity(void) { SYSTEM_INFO system_info; From patchwork Fri Mar 4 11:21:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 548106 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1251imq; Fri, 4 Mar 2022 03:28:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjIc7Np4jddLI0sIbhddq0HOr4P0cnL5fV+L+b3VVdMLpDn5ZgQyEYUuxVunDEl5ID0hK5 X-Received: by 2002:a25:f306:0:b0:628:9a03:9ab8 with SMTP id c6-20020a25f306000000b006289a039ab8mr12329214ybs.622.1646393285784; Fri, 04 Mar 2022 03:28:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646393285; cv=none; d=google.com; s=arc-20160816; b=mEn7VjOEsR5TKvQ0D7Q8RtKwN6jLBeWyt5/WgMIh4SY9Vql89HElNotX5eQm5bp/lm f0HBIlVs8KJEl4yehlj9WxBptNh/vRka22C4XKObW8L2mdcZNL1mZAORYxeiRsnK8gUk bGA5soAhfj2bbdW4fEvyp8c8YzFRWPU4jy991pOls25xxZXEC3C/Lq+BH0Kbq8kqYEmk lt01DDuv1jEZuBtjLmCAcsyYMCKv/+aEWQBKD8il8MImwsgVnNs3vKWOeXAwQFmT6v4A 0iJowRPmXcdYYYwhe62ckSswzv6it4bVQyuBoD4GNu2qzP8eCSdsMnHiAyQQ/DXjs6r1 uO4Q== 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=G4AbYvV6pM/kHUjvkC09aZIGxcMx4nP3w1jg109SqVs=; b=T3KPPyhfutCEiU/ZWzOKkGujYpF12m35zGy+sryKe1E0gll/iuzBqSOCxoXrrek+ex L6QNIlPzc4GWvNmI1z9Wuc/VsC2P2XnPeJQKOmnOh3rS/D9Kvvyk99wYQeoJUE0WcRX3 wlvPc9Lp2SQFqk+8/7Ckrcw8tWB5t8NBULoPCnb3hOi8+230C7Yk17d40O+SPhJoetRX Y9y95HPnvpJEfUM+RgtFIoxzYHT07jWJmoYHLoGgOz3cxGFXDEHaGUqL4PRfHrAmXsi0 E81B1HzN0AStECM8sCiWT17IFFWvXiAoFUl5/cnAtg1uwmDpoyF+HbKIFU7wRnyVnUys 2fpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="P+/pcj2o"; 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 o62-20020a0dfe41000000b002d6fa4d2e52si3559608ywf.335.2022.03.04.03.28.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:28:05 -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="P+/pcj2o"; 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]:34752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ66O-0000k1-Qm for patch@linaro.org; Fri, 04 Mar 2022 06:28:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ60B-0002jq-HM for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:39 -0500 Received: from [2a00:1450:4864:20::32e] (port=40662 helo=mail-wm1-x32e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ60A-0004gV-0F for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:39 -0500 Received: by mail-wm1-x32e.google.com with SMTP id bi14-20020a05600c3d8e00b00386f2897400so1249366wmb.5 for ; Fri, 04 Mar 2022 03:21:37 -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=G4AbYvV6pM/kHUjvkC09aZIGxcMx4nP3w1jg109SqVs=; b=P+/pcj2oHiPJDuXoicx3lK81eT2PqAkzr6VG2BQZOb3ZVzj1DxDhTsHlArijviaU8B 6pKfqsNYp+yZYKKn7fgQIDIlTmRv1k9yY1ySbcFJFoEg1Ogif3z2FkCBC2dJqfXSusq3 urxo+lVfkw26yyb7LjinazNALrB8/N3+e+q2OixCFuNrW1LHV16335wltPxtJqLyZiCw nuFNhnMeEhIEHmr/MOAyhGePyvofFBLMo2Hk5obcZoDXsUMJNqsfTAXs7G5bpaRMS14O EeTTrXOkpAQ4Xtv8SHTtXi8U0HZJamB5Krjj//G5NELbt5+iTA73n6XT+y/lvJjEgc6x a9sA== 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=G4AbYvV6pM/kHUjvkC09aZIGxcMx4nP3w1jg109SqVs=; b=gw4Ox8V4gkOx8b1mVw3KhhZKyonI8jCC3ge/zPRPjxTwYek1eLtnx/voBreIV1Q04d r1k/z30amXMV36g5kWEcR4IHzw7idLh2XJ6Gyalhel/7lYYnh9KRqk/ixSjBWVbTKKfi aGw7NobFJkuDQgQRmt0AgUNutqCrtnAGqfxufR8mqjqoc9SE59ZVtuUXutis2XcO3jDR WDHDicXWFg3uKZpuzi6AYL/mXKCi0pY7DR6oKxWnADBA3O6lt0VLU1VSde3tHUXjDN/+ M5VqKYOq0y1/Jt+GcS2mecNYKBdT3MxqLlAalW0bWnfRdqQHiGVgFy/zgseRU1o8qXl/ FU7Q== X-Gm-Message-State: AOAM533liE2bhrRBJ+LZrwFqYWJy4xr1BLpYYIRIRH6iT2SNp3Csei8M Okpdvq1DjjODDGA3ZtN2QGketNjyviY9Ow== X-Received: by 2002:a05:600c:3596:b0:381:751a:f0a6 with SMTP id p22-20020a05600c359600b00381751af0a6mr7344601wmq.168.1646392896779; Fri, 04 Mar 2022 03:21:36 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:36 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 7/9] util: Use meson checks for valloc() and memalign() presence Date: Fri, 4 Mar 2022 11:21:24 +0000 Message-Id: <20220304112126.2261039-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.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 , Richard Henderson , 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é 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 eae0e4febb3..74f4e05c82b 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 ')) 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 c3280528d24..2a139a5695d 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; From patchwork Fri Mar 4 11:21:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 548109 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1279imq; Fri, 4 Mar 2022 03:32:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVLpxj5XZpF4J+DzbTDPurxtyz8b665SfniEK4++5TAEdek8oNtFN8wV5TPGADECxoTTFb X-Received: by 2002:a81:346:0:b0:2dc:5363:ed9c with SMTP id 67-20020a810346000000b002dc5363ed9cmr5045912ywd.378.1646393554708; Fri, 04 Mar 2022 03:32:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646393554; cv=none; d=google.com; s=arc-20160816; b=wD9ctnVSTqgbytG49/jFUGAkaQTGxQl/scN0wbFMuRuEU+1Db2r6l9byItK6vim8mP lxfr6hmFEdUkgOj0gEy0GEbnXyjGxi3ozmFaJgp7u7HaUoqIeWzT0uVGM96/3d5+Mzx7 CTTijnqRPYgsJ4+gnv6lRr5YC/ikp47Tme4kQo9jKZ6kK0AEp/s7oXm0HWXEaJ7Q+5D2 m3WhfrAKC2iEDriVPFprEsdlJIlGBmOZL0x6kIA75U7u+DNOwM7pXFgTgQdTWx4Gk81U 6K3eAZLZMdGYrPm6AtCIJkAzPPoydxWZcMWRIUsdyPbLmfLpPSWi+JD1yYONICcnbBhc suGQ== 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=1CcE3kkf6U7pzs8VKX54OJnlAyPVjTkRvkvMzX4xcmU=; b=USCsyUqY33m86Py1BmkP8qecakbwH6p7oM3GYtauAx7eHxzS7V1h91FLk7mRedqBBK UFRet85Mh8KLerf5kjyTtflFbxGfT8QT6fvVH3mnCEukQp4VJSE2v4oVlAjCWDV3EMvj dmw6226LZd8f9wGZ8wJJXxkZP779bYXDHYHoeoG09nGV3WR+62F2J/TD4vTK5gQlYEnC uFFfwT0t13ZZIE1Ga+6A34Taw1ga2TidBbHs7slb5+OX1c53YjFbCz/OdbQ/MKGNuvMp 6hM/MoRNUm8X5t+sKApTi988M/pd+8RgQRXQd1eBR480JKtrKREQ2x6AquZ+Xe5OGsyi 47Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="tAA+/lJ5"; 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 u136-20020a812e8e000000b002dbfe4b1048si4018193ywu.539.2022.03.04.03.32.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:32:34 -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="tAA+/lJ5"; 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]:42966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ6Ak-0006ff-4a for patch@linaro.org; Fri, 04 Mar 2022 06:32:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ60C-0002o5-Nm for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:40 -0500 Received: from [2a00:1450:4864:20::430] (port=37824 helo=mail-wr1-x430.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ60B-0004gs-2P for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:40 -0500 Received: by mail-wr1-x430.google.com with SMTP id bk29so12205421wrb.4 for ; Fri, 04 Mar 2022 03:21:38 -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=1CcE3kkf6U7pzs8VKX54OJnlAyPVjTkRvkvMzX4xcmU=; b=tAA+/lJ5ClrHgjKwn6A6QuJVFVYG/1mig7U4ZdU9py/wDZ8gZNsJh9zytvf5JaN7NK GbaQLL9dsGDSsW3ao4OAqB2uXA/M1KPLj7S9lktecSJ0M5EaOERlQltohVIcAsJ0plJ1 5djHnVVJVZc438SyQjxqfviTURYPjgU58WO8ArSgR2VoO9nwlZYy7fIZx8074srpiwKJ Z9kh+eP1Hu49q8d4SAQxYdVlIYFen/TxrZsoEmWNkI5JtelBpGKORDUrWuexcPG5Nyso saMeBgSeYqMbCUxwQBhiUOlKLopZ24mq3fgKy7F1AYM5vwFYEpSzLC6Y+1jd3gi91Zl0 4BqQ== 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=1CcE3kkf6U7pzs8VKX54OJnlAyPVjTkRvkvMzX4xcmU=; b=740zy2UUNBYFGqVFqotPHzkZUxTebXXcJPiG/vrE9fUR/iVHnXsSt+ST4FtlDiYrXC q1attHqKjhqzNMoigJvZw+TPwbvLG8z8UtYn/q+VgSkl6wQ3FJdLGKp3GjWKfwhusmAA 20S6lfNKSX76cJqS/iEdRTqzMSCSSmvwSmcOaq7BpjIRzIXpgW1CuysicRZmcjUvj7F6 aZ8tOBUnByMlF7SMo1bzPNRBKGOpxT8ZvxrLTPSNoVlMIdMOGsDwrRYcCjgIxyQMk1Vs 5l4L8xfF2EBeB9XgH+/2NTfTl0LxXsR3DE0B8QcoRwFq/YjdMlec3Ioo1Uw+59CYoAn3 rIZw== X-Gm-Message-State: AOAM532IB+G1KwtkXTeQ4j7Wk40bUHU2a+P9MfSv+yCwaezqAZEncLQi uAc5eaVox2W6JIwYy2hCzAnH09wEWDluZA== X-Received: by 2002:adf:ed0c:0:b0:1f0:4a32:4d0d with SMTP id a12-20020adfed0c000000b001f04a324d0dmr6223874wro.136.1646392897704; Fri, 04 Mar 2022 03:21:37 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:37 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 8/9] util: Put qemu_vfree() in memalign.c Date: Fri, 4 Mar 2022 11:21:25 +0000 Message-Id: <20220304112126.2261039-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::430 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.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 , Richard Henderson , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" qemu_vfree() is the companion free function to qemu_memalign(); put it in memalign.c so the allocation and free functions are together. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220226180723.1706285-9-peter.maydell@linaro.org Reviewed-by: Philippe Mathieu-Daudé --- util/memalign.c | 11 +++++++++++ util/oslib-posix.c | 6 ------ util/oslib-win32.c | 6 ------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/util/memalign.c b/util/memalign.c index 2a139a5695d..5b812bc11fe 100644 --- a/util/memalign.c +++ b/util/memalign.c @@ -78,3 +78,14 @@ void *qemu_memalign(size_t alignment, size_t size) size, alignment, strerror(errno)); abort(); } + +void qemu_vfree(void *ptr) +{ + trace_qemu_vfree(ptr); +#if !defined(CONFIG_POSIX_MEMALIGN) && defined(CONFIG_ALIGNED_MALLOC) + /* Only Windows _aligned_malloc needs a special free function */ + _aligned_free(ptr); +#else + free(ptr); +#endif +} diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 91798f7e504..2ebfb750578 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -220,12 +220,6 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared, return ptr; } -void qemu_vfree(void *ptr) -{ - trace_qemu_vfree(ptr); - free(ptr); -} - void qemu_anon_ram_free(void *ptr, size_t size) { trace_qemu_anon_ram_free(ptr, size); diff --git a/util/oslib-win32.c b/util/oslib-win32.c index d9768532bec..4b1ce0be4b0 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -75,12 +75,6 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared, return ptr; } -void qemu_vfree(void *ptr) -{ - trace_qemu_vfree(ptr); - _aligned_free(ptr); -} - void qemu_anon_ram_free(void *ptr, size_t size) { trace_qemu_anon_ram_free(ptr, size); From patchwork Fri Mar 4 11:21:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 548110 Delivered-To: patch@linaro.org Received: by 2002:ac0:f585:0:0:0:0:0 with SMTP id s5csp1296imq; Fri, 4 Mar 2022 03:35:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxb9VqMGGMP+8GEk5VejXYogRQTCykT6PSqaEysnufmN7txyloNdb1Jo/EHoTB+vtqUIMtl X-Received: by 2002:a25:e68b:0:b0:628:8f4d:c66 with SMTP id d133-20020a25e68b000000b006288f4d0c66mr15113226ybh.131.1646393715745; Fri, 04 Mar 2022 03:35:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646393715; cv=none; d=google.com; s=arc-20160816; b=YSttUbDqWJT7jZfFUWWb7qrsJOBVaLJcAlK8DrAVzZc30P2oIVRoLCbGZiVMkNRe6f 638dei13Z2vCabIOStLCrB9um3D3tT0D6YizCKo1xMm8rTH3vSy/6f4k45o72nXh+9yo 6bonGfmhMF/86XiJAOltytGXpk2u2Xl06+tPnluB5Ct2wDtKwc7yr1xi+wxhM4eg2aEg /0BB6c+JP/N6sISEbXqN2PSemJNCRWG37H7t6bKc8uW9LcnERaz0zD6D7qu4ia1h056u v5ivGZLS20F85WHXchIFZCJ0K/DzYAIBy/AxXxCgrHPdTejzdl/DZROGl6tzEJv4knbL J6/Q== 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=XpI7U/Z7YuUSbxrmvdXZMZ7ZmB00HTLK4QziPXSo8Kk=; b=O3lrgN3ojUBAjKH5I0QyXV+LFsmOKT4EgviNrVBQMdrgviPQGct2nIdUYqwORoIQyN kvOW2M+tiKuID50u4PumlVOmmsudRcNwfd62klt5FB62mI04cVvq/isBRErowH4at+SH aqZPS/D0K+tLYdSqAmBm5BEfPXSsmAMMeyN6bxTgz7sfzwOWKRVP92qUniuRwFubXUW7 2CLcDMSViGEMf9zCBDAeRL8fuTJDqKsxle2o4eF4sGZCjTVBP0KGKF3r4kzXVHnXZFYS Zgx8NZqE9tQZ9dAn0i/GRN7QKtC40tYQdZgc41iBprfwvArIb10rgb6Y57LwJSblH0uH kjpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=T1b7Vu8B; 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 bd30-20020a05690c011e00b002d668cdce9bsi4869750ywb.116.2022.03.04.03.35.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 03:35:15 -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=T1b7Vu8B; 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]:48664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ6DL-0002DP-6x for patch@linaro.org; Fri, 04 Mar 2022 06:35:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ60F-0002zP-Je for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:43 -0500 Received: from [2a00:1450:4864:20::335] (port=39809 helo=mail-wm1-x335.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nQ60C-0004iE-MV for qemu-devel@nongnu.org; Fri, 04 Mar 2022 06:21:43 -0500 Received: by mail-wm1-x335.google.com with SMTP id o18-20020a05600c4fd200b003826701f847so6417636wmq.4 for ; Fri, 04 Mar 2022 03:21:40 -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=XpI7U/Z7YuUSbxrmvdXZMZ7ZmB00HTLK4QziPXSo8Kk=; b=T1b7Vu8B1CJN42f71lGFN/mtLZPeGpzmXHORYOjo5pM0owVECrv6xejDp5fgKZh0kO RLsISzipRNWC/0DL50grJn1Nlx1tBKxFxgeEEkKnvzTWB/9odtD+4nGyQpnvStFsvYI+ kM4QZk23uq44ZTqdWZOf1Ke3xa69BnOwRd6lvJKAX6UAXaNDBl6gbwMHE2eN4MKKiIwJ /xQcUgONDHMIYhldNJ/qcudfVALkFKVtTUnsdpieOfbH+cDPD09ODrsWynNg4BB2GKPK nJNDrgR7AITP0nfpV63FKvZmTlLYGZqotf3DKJG+xpI72tBf0urpZqksW+1pcymewjkp WF2w== 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=XpI7U/Z7YuUSbxrmvdXZMZ7ZmB00HTLK4QziPXSo8Kk=; b=HFnpMb5MnXJduoSPvYVhiAC1GhvnwteApmUKK0VTkFHQOF2zlBLaJmcEI3dlpPENZk khe8st9Sw3wWsKE5Y+K5yLfEqaG25U+/Xw/r55CV2vFY1oK5Ytn0VkHCgX8LoqgzgVxi 401Wdfeo1M6l4v4rh0Qbp4rZARsFlrO1tt9I1vbyPB68xg2BRBmwiBhJfvyGHawvGJPs yOG0e+RNjZSJ/sSlEKkFJFKzEojqvY3/QAhAoYbIA2Y1gKFizIB/nxzy4wHw/3VvjzOu +jRufQM/dQqAB7p68hi8jn0ZMY7GWVCAGCrnEFa9vSdmEP+sFvDkARtIXfSDnnqyxG50 E+iA== X-Gm-Message-State: AOAM530dhUKglCjXVro9KSQ9MCuEfhhMoKAR0rlMDXIj7R3Cxf9amNVt i5LiiQOwjrIXaDU8xEaiw97lUi3PU/o5OA== X-Received: by 2002:a7b:c5d1:0:b0:37f:a8a3:9e17 with SMTP id n17-20020a7bc5d1000000b0037fa8a39e17mr7341775wmk.109.1646392899201; Fri, 04 Mar 2022 03:21:39 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id u14-20020adfed4e000000b001e3323611e5sm4148651wro.26.2022.03.04.03.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 03:21:38 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v2 9/9] osdep: Move memalign-related functions to their own header Date: Fri, 4 Mar 2022 11:21:26 +0000 Message-Id: <20220304112126.2261039-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304112126.2261039-1-peter.maydell@linaro.org> References: <20220304112126.2261039-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::335 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.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 , Richard Henderson , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Move the various memalign-related functions out of osdep.h and into their own header, which we include only where they are used. While we're doing this, add some brief documentation comments. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-id: 20220226180723.1706285-10-peter.maydell@linaro.org --- include/qemu/memalign.h | 61 ++++++++++++++++++++++++++++++++++ include/qemu/osdep.h | 18 ---------- block/blkverify.c | 1 + block/block-copy.c | 1 + block/commit.c | 1 + block/crypto.c | 1 + block/dmg.c | 1 + block/export/fuse.c | 1 + block/file-posix.c | 1 + block/io.c | 1 + block/mirror.c | 1 + block/nvme.c | 1 + block/parallels-ext.c | 1 + block/parallels.c | 1 + block/qcow.c | 1 + block/qcow2-cache.c | 1 + block/qcow2-cluster.c | 1 + block/qcow2-refcount.c | 1 + block/qcow2-snapshot.c | 1 + block/qcow2.c | 1 + block/qed-l2-cache.c | 1 + block/qed-table.c | 1 + block/qed.c | 1 + block/quorum.c | 1 + block/raw-format.c | 1 + block/vdi.c | 1 + block/vhdx-log.c | 1 + block/vhdx.c | 1 + block/vmdk.c | 1 + block/vpc.c | 1 + block/win32-aio.c | 1 + hw/block/dataplane/xen-block.c | 1 + hw/block/fdc.c | 1 + hw/ide/core.c | 1 + hw/ppc/spapr.c | 1 + hw/ppc/spapr_softmmu.c | 1 + hw/scsi/scsi-disk.c | 1 + hw/tpm/tpm_ppi.c | 2 +- nbd/server.c | 1 + net/l2tpv3.c | 2 +- plugins/loader.c | 1 + qemu-img.c | 1 + qemu-io-cmds.c | 1 + qom/object.c | 1 + softmmu/physmem.c | 1 + target/i386/hvf/hvf.c | 1 + target/i386/kvm/kvm.c | 1 + tcg/region.c | 1 + tests/bench/atomic_add-bench.c | 1 + tests/bench/qht-bench.c | 1 + util/atomic64.c | 1 + util/memalign.c | 1 + util/qht.c | 1 + 53 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 include/qemu/memalign.h diff --git a/include/qemu/memalign.h b/include/qemu/memalign.h new file mode 100644 index 00000000000..fa299f3bf67 --- /dev/null +++ b/include/qemu/memalign.h @@ -0,0 +1,61 @@ +/* + * Allocation and free functions for aligned memory + * + * 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_MEMALIGN_H +#define QEMU_MEMALIGN_H + +/** + * qemu_try_memalign: Allocate aligned memory + * @alignment: required alignment, in bytes + * @size: size of allocation, in bytes + * + * Allocate memory on an aligned boundary (i.e. the returned + * address will be an exact multiple of @alignment). + * @alignment must be a power of 2, or the function will assert(). + * On success, returns allocated memory; on failure, returns NULL. + * + * The memory allocated through this function must be freed via + * qemu_vfree() (and not via free()). + */ +void *qemu_try_memalign(size_t alignment, size_t size); +/** + * qemu_memalign: Allocate aligned memory, without failing + * @alignment: required alignment, in bytes + * @size: size of allocation, in bytes + * + * Allocate memory in the same way as qemu_try_memalign(), but + * abort() with an error message if the memory allocation fails. + * + * The memory allocated through this function must be freed via + * qemu_vfree() (and not via free()). + */ +void *qemu_memalign(size_t alignment, size_t size); +/** + * qemu_vfree: Free memory allocated through qemu_memalign + * @ptr: memory to free + * + * This function must be used to free memory allocated via qemu_memalign() + * or qemu_try_memalign(). (Using the wrong free function will cause + * subtle bugs on Windows hosts.) + */ +void qemu_vfree(void *ptr); +/* + * It's an analog of GLIB's g_autoptr_cleanup_generic_gfree(), used to define + * g_autofree macro. + */ +static inline void qemu_cleanup_generic_vfree(void *p) +{ + void **pp = (void **)p; + qemu_vfree(*pp); +} + +/* + * Analog of g_autofree, but qemu_vfree is called on cleanup instead of g_free. + */ +#define QEMU_AUTO_VFREE __attribute__((cleanup(qemu_cleanup_generic_vfree))) + +#endif diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 7bcce3bceb0..bc3df26da36 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -379,28 +379,10 @@ extern "C" { #endif int qemu_daemon(int nochdir, int noclose); -void *qemu_try_memalign(size_t alignment, size_t size); -void *qemu_memalign(size_t alignment, size_t size); void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared, bool noreserve); -void qemu_vfree(void *ptr); void qemu_anon_ram_free(void *ptr, size_t size); -/* - * It's an analog of GLIB's g_autoptr_cleanup_generic_gfree(), used to define - * g_autofree macro. - */ -static inline void qemu_cleanup_generic_vfree(void *p) -{ - void **pp = (void **)p; - qemu_vfree(*pp); -} - -/* - * Analog of g_autofree, but qemu_vfree is called on cleanup instead of g_free. - */ -#define QEMU_AUTO_VFREE __attribute__((cleanup(qemu_cleanup_generic_vfree))) - #ifdef _WIN32 #define HAVE_CHARDEV_SERIAL 1 #elif defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ diff --git a/block/blkverify.c b/block/blkverify.c index d1facf5ba90..53ba1c91957 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -16,6 +16,7 @@ #include "qemu/cutils.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu/memalign.h" typedef struct { BdrvChild *test_file; diff --git a/block/block-copy.c b/block/block-copy.c index ce116318b57..619e5580faf 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -22,6 +22,7 @@ #include "qemu/coroutine.h" #include "block/aio_task.h" #include "qemu/error-report.h" +#include "qemu/memalign.h" #define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB) #define BLOCK_COPY_MAX_BUFFER (1 * MiB) diff --git a/block/commit.c b/block/commit.c index b1fc7b908b2..a1292bb17ed 100644 --- a/block/commit.c +++ b/block/commit.c @@ -20,6 +20,7 @@ #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "qemu/ratelimit.h" +#include "qemu/memalign.h" #include "sysemu/block-backend.h" enum { diff --git a/block/crypto.c b/block/crypto.c index c8ba4681e20..a586dd040de 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -31,6 +31,7 @@ #include "qemu/module.h" #include "qemu/option.h" #include "qemu/cutils.h" +#include "qemu/memalign.h" #include "crypto.h" typedef struct BlockCrypto BlockCrypto; diff --git a/block/dmg.c b/block/dmg.c index 447901fbb87..c626587f9c5 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -27,6 +27,7 @@ #include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/module.h" +#include "qemu/memalign.h" #include "dmg.h" int (*dmg_uncompress_bz2)(char *next_in, unsigned int avail_in, diff --git a/block/export/fuse.c b/block/export/fuse.c index fdda8e3c818..4a3bb5a1b8f 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -19,6 +19,7 @@ #define FUSE_USE_VERSION 31 #include "qemu/osdep.h" +#include "qemu/memalign.h" #include "block/aio.h" #include "block/block.h" #include "block/export.h" diff --git a/block/file-posix.c b/block/file-posix.c index 1f1756e192a..c000a61db29 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -31,6 +31,7 @@ #include "qemu/module.h" #include "qemu/option.h" #include "qemu/units.h" +#include "qemu/memalign.h" #include "trace.h" #include "block/thread-pool.h" #include "qemu/iov.h" diff --git a/block/io.c b/block/io.c index 4e4cb556c58..ea031d39601 100644 --- a/block/io.c +++ b/block/io.c @@ -32,6 +32,7 @@ #include "block/coroutines.h" #include "block/write-threshold.h" #include "qemu/cutils.h" +#include "qemu/memalign.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" diff --git a/block/mirror.c b/block/mirror.c index 69b2c1c697e..eda8aab0eb8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -23,6 +23,7 @@ #include "qapi/qmp/qerror.h" #include "qemu/ratelimit.h" #include "qemu/bitmap.h" +#include "qemu/memalign.h" #define MAX_IN_FLIGHT 16 #define MAX_IO_BYTES (1 << 20) /* 1 Mb */ diff --git a/block/nvme.c b/block/nvme.c index dd20de3865b..552029931d5 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -21,6 +21,7 @@ #include "qemu/module.h" #include "qemu/cutils.h" #include "qemu/option.h" +#include "qemu/memalign.h" #include "qemu/vfio-helpers.h" #include "block/block_int.h" #include "sysemu/replay.h" diff --git a/block/parallels-ext.c b/block/parallels-ext.c index e0dd0975c6f..cb22a427d72 100644 --- a/block/parallels-ext.c +++ b/block/parallels-ext.c @@ -29,6 +29,7 @@ #include "parallels.h" #include "crypto/hash.h" #include "qemu/uuid.h" +#include "qemu/memalign.h" #define PARALLELS_FORMAT_EXTENSION_MAGIC 0xAB234CEF23DCEA87ULL diff --git a/block/parallels.c b/block/parallels.c index 6ebad2a2bbc..5a3487537b4 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -41,6 +41,7 @@ #include "qapi/qapi-visit-block-core.h" #include "qemu/bswap.h" #include "qemu/bitmap.h" +#include "qemu/memalign.h" #include "migration/blocker.h" #include "parallels.h" diff --git a/block/qcow.c b/block/qcow.c index c39940f33eb..4fba1b9e364 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -32,6 +32,7 @@ #include "qemu/option.h" #include "qemu/bswap.h" #include "qemu/cutils.h" +#include "qemu/memalign.h" #include #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c index 7444b9c4ab0..8a0105911f7 100644 --- a/block/qcow2-cache.c +++ b/block/qcow2-cache.c @@ -23,6 +23,7 @@ */ #include "qemu/osdep.h" +#include "qemu/memalign.h" #include "qcow2.h" #include "trace.h" diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 21884a1ab9a..20a16ba6ee0 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -28,6 +28,7 @@ #include "qapi/error.h" #include "qcow2.h" #include "qemu/bswap.h" +#include "qemu/memalign.h" #include "trace.h" int qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t exact_size) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 46145722527..94033972bed 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -28,6 +28,7 @@ #include "qemu/range.h" #include "qemu/bswap.h" #include "qemu/cutils.h" +#include "qemu/memalign.h" #include "trace.h" static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size, diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 71ddb08c212..075269a0237 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -29,6 +29,7 @@ #include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/cutils.h" +#include "qemu/memalign.h" static void qcow2_free_single_snapshot(BlockDriverState *bs, int i) { diff --git a/block/qcow2.c b/block/qcow2.c index c8115e1cba0..b5c47931ef4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -38,6 +38,7 @@ #include "qemu/option_int.h" #include "qemu/cutils.h" #include "qemu/bswap.h" +#include "qemu/memalign.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qapi-visit-block-core.h" #include "crypto.h" diff --git a/block/qed-l2-cache.c b/block/qed-l2-cache.c index b5483623989..caf2c024c2d 100644 --- a/block/qed-l2-cache.c +++ b/block/qed-l2-cache.c @@ -51,6 +51,7 @@ */ #include "qemu/osdep.h" +#include "qemu/memalign.h" #include "trace.h" #include "qed.h" diff --git a/block/qed-table.c b/block/qed-table.c index 405d446cbe7..1cc844b1a5f 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -17,6 +17,7 @@ #include "qemu/sockets.h" /* for EINPROGRESS on Windows */ #include "qed.h" #include "qemu/bswap.h" +#include "qemu/memalign.h" /* Called with table_lock held. */ static int coroutine_fn qed_read_table(BDRVQEDState *s, uint64_t offset, diff --git a/block/qed.c b/block/qed.c index 558d3646c4b..f34d9a3ac1a 100644 --- a/block/qed.c +++ b/block/qed.c @@ -20,6 +20,7 @@ #include "qemu/main-loop.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu/memalign.h" #include "trace.h" #include "qed.h" #include "sysemu/block-backend.h" diff --git a/block/quorum.c b/block/quorum.c index c28dda7baac..f33f30d36b8 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -17,6 +17,7 @@ #include "qemu/cutils.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu/memalign.h" #include "block/block_int.h" #include "block/coroutines.h" #include "block/qdict.h" diff --git a/block/raw-format.c b/block/raw-format.c index bda757fd195..69fd650eaf7 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -31,6 +31,7 @@ #include "qapi/error.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu/memalign.h" typedef struct BDRVRawState { uint64_t offset; diff --git a/block/vdi.c b/block/vdi.c index bdc58d726ee..cca3a3a3567 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -64,6 +64,7 @@ #include "qemu/coroutine.h" #include "qemu/cutils.h" #include "qemu/uuid.h" +#include "qemu/memalign.h" /* Code configuration options. */ diff --git a/block/vhdx-log.c b/block/vhdx-log.c index 7672161d955..ff0d4e0da05 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -23,6 +23,7 @@ #include "block/block_int.h" #include "qemu/error-report.h" #include "qemu/bswap.h" +#include "qemu/memalign.h" #include "vhdx.h" diff --git a/block/vhdx.c b/block/vhdx.c index 356ec4c455a..410c6f96101 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -25,6 +25,7 @@ #include "qemu/crc32c.h" #include "qemu/bswap.h" #include "qemu/error-report.h" +#include "qemu/memalign.h" #include "vhdx.h" #include "migration/blocker.h" #include "qemu/uuid.h" diff --git a/block/vmdk.c b/block/vmdk.c index 0dfab6e9413..37c0946066e 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -33,6 +33,7 @@ #include "qemu/module.h" #include "qemu/option.h" #include "qemu/bswap.h" +#include "qemu/memalign.h" #include "migration/blocker.h" #include "qemu/cutils.h" #include diff --git a/block/vpc.c b/block/vpc.c index 297a26262ab..4d8f16e1990 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -33,6 +33,7 @@ #include "migration/blocker.h" #include "qemu/bswap.h" #include "qemu/uuid.h" +#include "qemu/memalign.h" #include "qapi/qmp/qdict.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qapi-visit-block-core.h" diff --git a/block/win32-aio.c b/block/win32-aio.c index c57e10c9979..aadc7b1bc3c 100644 --- a/block/win32-aio.c +++ b/block/win32-aio.c @@ -29,6 +29,7 @@ #include "block/raw-aio.h" #include "qemu/event_notifier.h" #include "qemu/iov.h" +#include "qemu/memalign.h" #include #include diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 860787580a3..2785b9e8497 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" +#include "qemu/memalign.h" #include "qapi/error.h" #include "hw/xen/xen_common.h" #include "hw/block/xen_blkif.h" diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 21d18ac2e36..347875a0cda 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -32,6 +32,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/memalign.h" #include "hw/irq.h" #include "hw/isa/isa.h" #include "hw/qdev-properties.h" diff --git a/hw/ide/core.c b/hw/ide/core.c index 33463d9b8f2..a7ac4de18ad 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -30,6 +30,7 @@ #include "qemu/main-loop.h" #include "qemu/timer.h" #include "qemu/hw-version.h" +#include "qemu/memalign.h" #include "sysemu/sysemu.h" #include "sysemu/blockdev.h" #include "sysemu/dma.h" diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 4cc204f90df..953fc65fa86 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -27,6 +27,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/datadir.h" +#include "qemu/memalign.h" #include "qapi/error.h" #include "qapi/qapi-events-machine.h" #include "qapi/qapi-events-qdev.h" diff --git a/hw/ppc/spapr_softmmu.c b/hw/ppc/spapr_softmmu.c index 4ee03c83e48..5170a33369e 100644 --- a/hw/ppc/spapr_softmmu.c +++ b/hw/ppc/spapr_softmmu.c @@ -1,5 +1,6 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" +#include "qemu/memalign.h" #include "cpu.h" #include "helper_regs.h" #include "hw/ppc/spapr.h" diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 3666b8d9468..072686ed58f 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -26,6 +26,7 @@ #include "qemu/main-loop.h" #include "qemu/module.h" #include "qemu/hw-version.h" +#include "qemu/memalign.h" #include "hw/scsi/scsi.h" #include "migration/qemu-file-types.h" #include "migration/vmstate.h" diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c index 6dbb9f41e40..c89ac53e65e 100644 --- a/hw/tpm/tpm_ppi.c +++ b/hw/tpm/tpm_ppi.c @@ -12,7 +12,7 @@ */ #include "qemu/osdep.h" - +#include "qemu/memalign.h" #include "qapi/error.h" #include "sysemu/memory_mapping.h" #include "migration/vmstate.h" diff --git a/nbd/server.c b/nbd/server.c index 9fb2f264023..53e68cf027f 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -25,6 +25,7 @@ #include "trace.h" #include "nbd-internal.h" #include "qemu/units.h" +#include "qemu/memalign.h" #define NBD_META_ID_BASE_ALLOCATION 0 #define NBD_META_ID_ALLOCATION_DEPTH 1 diff --git a/net/l2tpv3.c b/net/l2tpv3.c index e4d4218db69..b8faa8796c8 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -34,7 +34,7 @@ #include "qemu/sockets.h" #include "qemu/iov.h" #include "qemu/main-loop.h" - +#include "qemu/memalign.h" /* The buffer size needs to be investigated for optimum numbers and * optimum means of paging in on different systems. This size is diff --git a/plugins/loader.c b/plugins/loader.c index 4883b0a1cbc..88c30bde2d6 100644 --- a/plugins/loader.c +++ b/plugins/loader.c @@ -27,6 +27,7 @@ #include "qemu/cacheinfo.h" #include "qemu/xxhash.h" #include "qemu/plugin.h" +#include "qemu/memalign.h" #include "hw/core/cpu.h" #include "exec/exec-all.h" #ifndef CONFIG_USER_ONLY diff --git a/qemu-img.c b/qemu-img.c index 6fe2466032f..5dffb3e6160 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -42,6 +42,7 @@ #include "qemu/module.h" #include "qemu/sockets.h" #include "qemu/units.h" +#include "qemu/memalign.h" #include "qom/object_interfaces.h" #include "sysemu/block-backend.h" #include "block/block_int.h" diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 46593d632d8..633b46cdb25 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -21,6 +21,7 @@ #include "qemu/option.h" #include "qemu/timer.h" #include "qemu/cutils.h" +#include "qemu/memalign.h" #define CMD_NOFILE_OK 0x01 diff --git a/qom/object.c b/qom/object.c index 9f7a33139d4..4048a2fef1e 100644 --- a/qom/object.c +++ b/qom/object.c @@ -16,6 +16,7 @@ #include "qom/object.h" #include "qom/object_interfaces.h" #include "qemu/cutils.h" +#include "qemu/memalign.h" #include "qapi/visitor.h" #include "qapi/string-input-visitor.h" #include "qapi/string-output-visitor.h" diff --git a/softmmu/physmem.c b/softmmu/physmem.c index a13289a594a..59dcf13faf4 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -42,6 +42,7 @@ #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qemu/qemu-print.h" +#include "qemu/memalign.h" #include "exec/memory.h" #include "exec/ioport.h" #include "sysemu/dma.h" diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 4ba6e82fab3..fc12c02fb21 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -49,6 +49,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/error-report.h" +#include "qemu/memalign.h" #include "sysemu/hvf.h" #include "sysemu/hvf_int.h" diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 2c8feb4a6f7..83d09883020 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -37,6 +37,7 @@ #include "qemu/main-loop.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/memalign.h" #include "hw/i386/x86.h" #include "hw/i386/apic.h" #include "hw/i386/apic_internal.h" diff --git a/tcg/region.c b/tcg/region.c index 72afb357389..97ca5291d52 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -26,6 +26,7 @@ #include "qemu/units.h" #include "qemu/madvise.h" #include "qemu/mprotect.h" +#include "qemu/memalign.h" #include "qemu/cacheinfo.h" #include "qapi/error.h" #include "exec/exec-all.h" diff --git a/tests/bench/atomic_add-bench.c b/tests/bench/atomic_add-bench.c index f05471ab45c..8a6faad6ece 100644 --- a/tests/bench/atomic_add-bench.c +++ b/tests/bench/atomic_add-bench.c @@ -2,6 +2,7 @@ #include "qemu/thread.h" #include "qemu/host-utils.h" #include "qemu/processor.h" +#include "qemu/memalign.h" struct thread_info { uint64_t r; diff --git a/tests/bench/qht-bench.c b/tests/bench/qht-bench.c index 2e5b70ccd04..8afe161d106 100644 --- a/tests/bench/qht-bench.c +++ b/tests/bench/qht-bench.c @@ -10,6 +10,7 @@ #include "qemu/qht.h" #include "qemu/rcu.h" #include "qemu/xxhash.h" +#include "qemu/memalign.h" struct thread_stats { size_t rd; diff --git a/util/atomic64.c b/util/atomic64.c index 22983a970f1..c20d071d8e5 100644 --- a/util/atomic64.c +++ b/util/atomic64.c @@ -8,6 +8,7 @@ #include "qemu/atomic.h" #include "qemu/thread.h" #include "qemu/cacheinfo.h" +#include "qemu/memalign.h" #ifdef CONFIG_ATOMIC64 #error This file must only be compiled if !CONFIG_ATOMIC64 diff --git a/util/memalign.c b/util/memalign.c index 5b812bc11fe..a9d0536bb72 100644 --- a/util/memalign.c +++ b/util/memalign.c @@ -26,6 +26,7 @@ #include "qemu/osdep.h" #include "qemu/host-utils.h" +#include "qemu/memalign.h" #include "trace.h" void *qemu_try_memalign(size_t alignment, size_t size) diff --git a/util/qht.c b/util/qht.c index 079605121b1..065fc501f44 100644 --- a/util/qht.c +++ b/util/qht.c @@ -69,6 +69,7 @@ #include "qemu/qht.h" #include "qemu/atomic.h" #include "qemu/rcu.h" +#include "qemu/memalign.h" //#define QHT_DEBUG