From patchwork Sat Feb 26 18:07:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546184 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1376167imf; Sat, 26 Feb 2022 10:11:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzM1zfYCqHhvN8O1F4xeEuvFJupt0fdNGBPyuX91ylo8Sbqy24dMCljoWPEx86lwbg0Dt5S X-Received: by 2002:a25:d314:0:b0:624:6c1a:6f2d with SMTP id e20-20020a25d314000000b006246c1a6f2dmr12551348ybf.189.1645899113638; Sat, 26 Feb 2022 10:11:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645899113; cv=none; d=google.com; s=arc-20160816; b=M/vwyZIdHACA1/37O+JyS5XlmtVlGzk1HIzWgQI4nAOz4zOnybiGP/NgKWH6nnkxEP Sr3h1NQ1e+pTgDMLg7Wj2n40o1A2an6sT6vXT0uf5orv3HCLee9i9NQfgp0Wdd50wdYE lU4fDU2qVSA5aUMcWPaOvqkByvKHusL6CRkkrBgneh3Eu081WJzpxV9vbiyNQ885wTuq rsm+dEuSSSGChd0sQPzIEBkAw9Sr9o/A/MmZOiQyuMDZNETHif7E+wbN+8QlrmJ0aIyc RJ3KIX+zQ3SCR6j1g6WpKDmNpIPJq+4nzjOBSJLLXsgSVIhDVql+zGir8+8dFkW5ZeQz bulg== 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=uPrIPUtrD7DVBHc6YiS8HprIW42ya5uWba9xJ+v1w9U=; b=tmprmsVEsT2dv8S95uAK5o60RYIgQqiCTg3n5p2dIZ/HFWzsxPTz75ztIuJnoKfpx6 Gak8m0QHA5844JHGxNAC2QXkXRGgxF6EOtW0EOyIjwWeon83j6YW7zQgKIs0PYEp+9I1 Ppz6SEIDTtbkwHBHW6dmvw/zehr7tqb/uktVzB8fEu9Z4ZDZ6ardqlNJwwHMo/St96CZ YDSA3SsfRNX/jDu1N+w1sqiWFQMxdBsQyOIOdf4j8qMlcNgIW6PEYrs0y8HuafK35gJs niUKbIHozqNTXOzTm1gHS3ihScmr8P0JKEkIWaKQOPbYsDYp2Spj6DisX5J1au+twPG6 jAQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SAQmO2ob; 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 c82-20020a813555000000b002d693f423adsi5216136ywa.533.2022.02.26.10.11.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:11:53 -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=SAQmO2ob; 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]:38138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1Xt-0003qw-5N for patch@linaro.org; Sat, 26 Feb 2022 13:11:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Th-0005Ye-QQ for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:34 -0500 Received: from [2a00:1450:4864:20::431] (port=36642 helo=mail-wr1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nO1Tc-0004NH-OO for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:31 -0500 Received: by mail-wr1-x431.google.com with SMTP id r10so9201913wrp.3 for ; Sat, 26 Feb 2022 10:07:28 -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=uPrIPUtrD7DVBHc6YiS8HprIW42ya5uWba9xJ+v1w9U=; b=SAQmO2obJJRRwjizDWZ10WP2vySBnCuGbbC2Sv7eYjyyppe57zfWwAjNwWMIqOus19 FBVlp5hiVK58+Ygx70TtPFxlPmSXTRyWah73+kiOEl7doMohjIw+6l1FBX6mgkUAcqCc Fm6oUuHHWcCUrCoWyVYjHF2Eohl3bInT6gr+sMch+d3uQL9bDQSufcI5j7EkSN1bX5Ki UdBp7OudDNykDEU4fqCbVC025YEL4yRlOQ8qXhe6W3Hu7qmAQc47UaJJG/b0Yvk100RQ 33dj9pEiWmhEvQn/Sk6AYAz4/kJMf78MmG1gWtPCvn1gM6Y6m/4fXQb8gjNVqy6KJz5L DvXg== 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=uPrIPUtrD7DVBHc6YiS8HprIW42ya5uWba9xJ+v1w9U=; b=LmK+akDUBr+6Ogack93ylScFgDlGxvQzcDZnTDFKgCNdDG5zd+klYb4R+e+KbD8wWX Ker+tS+n5mVAFYZg3ATkHcfts6kP91WlYDOC0h5lSI4NeD11UyzWMfcY4OCBuo7v9cp9 C6yd7B0ezzF7LFw/ZD2G18FpwGifgjew26mk4soaEbGT0F6Z87SyAQqD9y2hkA7HvGkm 9u+aaolrkfM7RdD5GFKrtfPcGajJNCTFfq1xtSyWTizdZr4BokGljWvVFb+NzE6drQV/ fPNyW5DeNtZD0hYYZ9pczMqmb3lvULlMQt1loLJU5hCGEq+xbEXEDButboR35NOXtCO1 DX+A== X-Gm-Message-State: AOAM533HYKNE5Hdf+GZTHMFSfibMxsoo5GwpfTPLaHdkKPXJBXHaI9sJ +botGYT4GuBow5QPX+l36BtPeVSaWUmcBA== X-Received: by 2002:a5d:4892:0:b0:1ed:beaa:778a with SMTP id g18-20020a5d4892000000b001edbeaa778amr10095459wrq.35.1645898847282; Sat, 26 Feb 2022 10:07:27 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:26 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 1/9] hw/usb/redirect.c: Stop using qemu_oom_check() Date: Sat, 26 Feb 2022 18:07:15 +0000 Message-Id: <20220226180723.1706285-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::431 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- I have left all of these errors as fatal, since that's what they were previously. Possibly somebody with a better understanding of the usbredir code might be able to make them theoretically non-fatal, but we make malloc failures generally fatal anyway. --- 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 Sat Feb 26 18:07:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546180 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1374737imf; Sat, 26 Feb 2022 10:09:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJya5GgOXRUSl/UDLa5JSBLpaaJcfb2ZmVkhyzjgORTyXmGWWYj8ESJAs/Y3MsAwqrd/aQ12 X-Received: by 2002:a5b:70e:0:b0:623:2d43:7ee4 with SMTP id g14-20020a5b070e000000b006232d437ee4mr13061263ybq.216.1645898958610; Sat, 26 Feb 2022 10:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645898958; cv=none; d=google.com; s=arc-20160816; b=cIn4sWSppGMdcDq1WaLBWULCdAY8YaAKqW+FmKuc9bETdkXyGVzl/bmo9xKcgCSUZ8 SYjK+P01hFKwiUQ/gExyD9a6eVAux/5kH5Xt1V83e3jmX0gLPz36x8Fnd++mg2MvN/kI hxKd03qm6A7hOg+KsuRD9/8zHUS5lQ6rPX1YPor1TaHasMMDzvBflk7H4MYoDmRDoY8C HnSGkcMYB/u3YytWhvpYc9ydGsk62IusOiT5SPkz8H88c5hIxrllTJReVcpymxy7O3IA rz9O/+R30NdP2ne2b9uiUlhWEsTH96ctMTfOA9P5a4+vLLkQ/LStg/MlUgJGZAMAc7Tp sKsg== 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=MJV8tjvPH9SAltj2sE6dDyHaDvCdY4+2Q1Mk8oZJ+D0=; b=O2K/7e7oKoBx2nsdwzty2+LssnAxJkIe+ufmrFbAHnSWkMAwWOpYRrogYJ8N0LEf5/ byK2772fKsznHmzrOTS2h70kXrcxg52uDvROS4h0xtb3CcuV7aWLeN4Xt1ww/NT+hwN/ vpTYyQ+SYfO9kLJOANspKv2jEVtUJ/kJKX1+Bk+FksXAySQv8CxvRsrQiZHpSb1jDwNz w5Mq7iVKUdGNnt2rSouO2pJxaObudTTAsUgaDHiU7JY63XuayzsHhngFF3fsRm7KxetO 2SQPCp2qXxXzbvrV6PKqn0lewVslF5v4ttm71oArcvfKjrZ4eM7PXWVtW4KEJ2jTZP5z pdMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pXFm5Yqa; 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 bc12-20020a05690c000c00b002d6b95b3faesi7367827ywb.414.2022.02.26.10.09.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:09:18 -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=pXFm5Yqa; 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]:57916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1VO-0006dq-5r for patch@linaro.org; Sat, 26 Feb 2022 13:09:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Th-0005Yb-Pk for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:34 -0500 Received: from [2a00:1450:4864:20::335] (port=37499 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 1nO1Td-0004NR-EY for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:32 -0500 Received: by mail-wm1-x335.google.com with SMTP id l1-20020a7bcf01000000b0037f881182a8so3496376wmg.2 for ; Sat, 26 Feb 2022 10:07:29 -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=MJV8tjvPH9SAltj2sE6dDyHaDvCdY4+2Q1Mk8oZJ+D0=; b=pXFm5YqaI32moBpMzOa89hHYTlzO3Z7KVt0+SrelqHE6SBPX3vWMufhZ9DwpCYQhp+ 715u4jsOyhqQU2wGTJN6EAb8Bv0fbVAxl8cY2DggiIyxBB1IiHzFBnAHJbYT31/lM15I lJy1SE6kuzrb/QvBcoeW1SZDBz2BYCDQXzPlu8ctDBsaG6LqJ0n3Fkgmuzi8H5yj8F6f QEyqDMSQnbeF4V1HI6ZXoFit1KHlfyChIzUva6LKq1nrIrV8hCbxfwUmAkZ+6NaWeBM+ /kbGkE/zkgZLMXCmrp2yTmkMDtYXbhPda6OL9hXTRvrzFI2hNItG7jMmFUQ71Y4MrY5J kuXA== 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=MJV8tjvPH9SAltj2sE6dDyHaDvCdY4+2Q1Mk8oZJ+D0=; b=oFXvRweVw5APAO/re4gWOEN745FMNpxCj/iZiBsCTT0W7zE40YNPlTeoK2X8GJnSKu hPclGNsUXvF3b69EyixPpIrv4+y26Xw6eRTWfKQYgc+mGt0RL/c4AQOKV50j66kZ+KcZ b4FFfd/61IywNDl28m/7cEMKnyNXILLRoza2JsR3HW26g5mNc0qM0mdoCkN7OxAS5oSZ rdolAU6h1l46wsY45DmJL0R2VhepXbsvz9msbdoUOrX5eLYjcD1lDHEqRC8zU2jTWAhF NyYceeRzHcP/mvE0X5R+ZCDx40JUYIH7Te+/1hFLf6nSOK5cABJpkbo3dmpvfhAwcpkC L1rg== X-Gm-Message-State: AOAM530UjJtrybASNtN/RR8LHzws4rZXy+zJFDYn6SQ0XOc5ZNm5BZ8K XN0+wKz5sOf2fg6b43/MHJ8LPpaqhSGJVw== X-Received: by 2002:a05:600c:3ba0:b0:37b:b86a:5d30 with SMTP id n32-20020a05600c3ba000b0037bb86a5d30mr7266509wms.136.1645898848211; Sat, 26 Feb 2022 10:07:28 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:27 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 2/9] util: Make qemu_oom_check() a static function Date: Sat, 26 Feb 2022 18:07:16 +0000 Message-Id: <20220226180723.1706285-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::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 , 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é --- 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 Sat Feb 26 18:07:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546181 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1375849imf; Sat, 26 Feb 2022 10:11:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTpUWi4VfY/yiNrjmwSQphxziZ84GMcKQW41T+9bVn0ESJhUyIlXi13bxSzdoVFV7oM+0p X-Received: by 2002:a81:ac6:0:b0:2d6:a9db:d4bf with SMTP id 189-20020a810ac6000000b002d6a9dbd4bfmr12927225ywk.240.1645899081071; Sat, 26 Feb 2022 10:11:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645899081; cv=none; d=google.com; s=arc-20160816; b=vj9ddVFcdbKxiOQVWdcJytAr2TvZiY9KglgKOgwdaU7EuExvnPiKADu5nGvSL2Ju4r u2iN54YKe5zntsLmLycqRkrNfaKRPZh+S3buqnp4i/X5gS5LOzHvShCCo/3s3DH1z3lI B+S2v6HaR6367mSzTJw+ZBkpCX6q8U+i4n5k3wCl16KTl6/YVSMEuXUXsY8vX4SlerbV EKopW8+ccERXUjwFlA1KC/jNJEqPNI0/EKrA05+KiXWmTakUK45OTI/LIGSk4Ti41GgW OJThm+b0Mb1rVLU5L73sTbU3/wFFwXjCgv4Pzf/uFAhoYMI6S+MlVgwmaNoRgANGygbj RpRw== 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=SoDe/ziHlSXePiaHt9j8l9tH8xjpM9yfGOu5hpZpNLA=; b=EbtJqrFNmUdad+tzSTUi5mPgse3KX78HYuRS0uuYuUUQRbhWsE35fzH53wjXIbJvfr Ab/+EzDLrS3bqYCDco5XqaRKS08W2Md1/0gxE+EaMRMC9j0LbbdMn6RZrMGNd81syNJP tsKNlCEQToaoHlcLhVfzFb+Hr7pYhWOs3QEklr0ztAK9puXF4rq9n7ZxqfHH9xyv8bYT 3EArLHtQ/GLUfPjBC++RLq26vR7TZKJdBiZpTtoRUyJPIeq81sWBUAfvpqoEFhu3ftwR Jyn3b46Ntabj7cjuiz9NO0gk3PFxZa2jPNbD5wb++9srRgKnOH9DTKSQgidDovY4aISm VXJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=r0QC1Vhq; 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 p6-20020a254206000000b00620f3cb734bsi4859803yba.497.2022.02.26.10.11.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:11: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=r0QC1Vhq; 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]:36986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1XM-00034t-Fb for patch@linaro.org; Sat, 26 Feb 2022 13:11:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Ti-0005Yr-N6 for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:34 -0500 Received: from [2a00:1450:4864:20::42d] (port=45005 helo=mail-wr1-x42d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nO1Te-0004Na-DC for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:33 -0500 Received: by mail-wr1-x42d.google.com with SMTP id u1so9143481wrg.11 for ; Sat, 26 Feb 2022 10:07:29 -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=SoDe/ziHlSXePiaHt9j8l9tH8xjpM9yfGOu5hpZpNLA=; b=r0QC1VhqLpEy8UNGsu6IZsQ9Lu4XhVkqk7UcgkZyF9Dy4O5FEvY8BXDd7f/uoWQixG eHAR58m/xgADYOsL82b6vJL49UIgYWz4MbZF+t4TTTiuh4T88Ib3zCPpa2X3evaRpyol CpYRERhqYiVpOlFX9MQpfP8JZmF6kdrcwpoDlFUF2fTsBQKxyDxgVdkc/Dvjtvsy5WNl 8VRO12BSh/H1v4aMbfm/OqHaWTUZmlANt1qeIpDOLQtREHkjX9iwdKRsfH5aaza1HpH/ OwERPywNcSu+Z3rMqWqoNr+UjG3jN7IBlMb1rPW9bQMTEXyvMUrzs01hE7kxaL4PeE8l vZ7A== 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=SoDe/ziHlSXePiaHt9j8l9tH8xjpM9yfGOu5hpZpNLA=; b=Bfk2OXxPxS9y3ZNSFkRMKUZUdif0ECBkXwOdUemM/y4LnJ1jcOrzKXgeMcKtg91cfS Ku5nYaaE/AA9IzJ5LujJLid9XAi1JksR/3CmOrVhjIhAUzhtyaqjWTiJZjRYtDx4mszp 7oJKBSBr/fKw3aQUgkDJlT6ZtY2WPE5CMabYUJ6gyp7/Glc1wGfEVTj5sin9bscVlIWZ eNFN8ppaYDdXguOcNALnWjdagJuhc+HcF/nIcARPMFh8YEKtCfNbmC5DE5nsEv1l4+i8 8ilRC/M84HbQVbABFpw1yk0oplZLG3KFevfKSSH1Lqm2EeiHjiS9NxWlZvHx6KijydXz R70Q== X-Gm-Message-State: AOAM531rzCdyISHjS1e6E2cYIDDbeHQSnfk0iWNVZu7KV+cyuyDnLY6V gR1xvl1DjXDMEv1njZTjvjeHru6JZOhxnQ== X-Received: by 2002:a5d:56cd:0:b0:1ee:3248:525b with SMTP id m13-20020a5d56cd000000b001ee3248525bmr8977619wrw.124.1645898849103; Sat, 26 Feb 2022 10:07:29 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:28 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 3/9] util: Unify implementations of qemu_memalign() Date: Sat, 26 Feb 2022 18:07:17 +0000 Message-Id: <20220226180723.1706285-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42d (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 Sat Feb 26 18:07:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546177 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1374450imf; Sat, 26 Feb 2022 10:08:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGCeEmLEEq7kk/zQuaCywhwbvpWHYC3dTPa95HaWwglKdzfGb2ZY6lDVBVcVWZrQ3zSVXU X-Received: by 2002:a25:254b:0:b0:624:6353:27f1 with SMTP id l72-20020a25254b000000b00624635327f1mr12690666ybl.477.1645898930567; Sat, 26 Feb 2022 10:08:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645898930; cv=none; d=google.com; s=arc-20160816; b=hV6id6pJfSm+edC9DtB/bxK5b1ELuZIT0sCyWW8+6P8xPrA8nhqSQptW6JEKDGJFoy 1wsCwCORbfEfJKQGcJY7+9X1Jh0Ji7MnoYnnn+wDuOejzK+K0Ty1j6AqlSpAmtjbPxw4 yC5NGZZh5foH3eh2dl/Kty7/RGlfde8iPLhPmkN4Y0E4zUOwLH97oMQtqqaecBritE05 V7RV+0p929fIKBqro67MFHxlHT3tvnMvpdJMKMU4fLJvzOPi01XrQXXtoFyURSkGsCBm 87umjQeyIArjMfAP/KC2OVV/PpT/EOyoyfJgdp3mYyIWXOkvIOcLrVDXdpP4O3w8zetg /4sw== 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=do5lIaZ/npTxEx4N07G4cTOPZppTqORcQBGB7xayAeQ=; b=bV/b6cYPW50ZKrzjc+IgSjYxj73vbiezlnz0CdNy7pYqYb5lVS5uv4+4J/L0wjKyXg 3/oADu52jrQipMAHkYJbdPss/HDf0IjtaKf/yPgzfXxUAzFtOL8nxYX/dct1j3L4P+ag eYcMfzHLjFfyQY5Edd0RVSQelhXhELH8SXkMLflLYioAFJ5sl20NW2DW6FJVg9Wt7Dd8 KRIeTpYKqEaAXrqTEfPSh/IGF031+Qdb7XxFVM5uYa/PwOsE19cwEBxuqs2WYe/3r+08 5jZoB4O+ff6B9fq+kTlX44wD9qn3rmQwaDoidU4hMuAsaqHm7whocmD+bLs7mw7a+Dgr /VbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vd7fEOm7; 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 m18-20020a814052000000b002d7a75801a8si5224484ywn.435.2022.02.26.10.08.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:08:50 -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=vd7fEOm7; 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]:56564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1Uv-0005iC-PO for patch@linaro.org; Sat, 26 Feb 2022 13:08:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Tk-0005aD-04 for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:36 -0500 Received: from [2a00:1450:4864:20::329] (port=41949 helo=mail-wm1-x329.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nO1Th-0004Nr-H2 for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:35 -0500 Received: by mail-wm1-x329.google.com with SMTP id o62-20020a1ca541000000b00380e3cc26b7so3626277wme.0 for ; Sat, 26 Feb 2022 10:07:30 -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=do5lIaZ/npTxEx4N07G4cTOPZppTqORcQBGB7xayAeQ=; b=vd7fEOm7KERL1VCwiDR1WbWUzWoCfYOgI+gwn0eGVbyeg0YTV3DxGCe8a9yMWSQYX4 JLEjbn9IE3J5xSk4PyeBH8bZ5+dIHI6hfCDcgcVk/iQKZ3oiEkP/Rmw7iL006SSMPwnl zvVvPn1ouVUlEhktkzW+uqaR2MaUpurKvHnHSsQMqzJhvlc93wsoXtt7I6i4dktKSegL rGQ0cIvNS2iKJWHcw9oe0NT4k9EDQs7p8rNtUxeJz4UQRmML3rNHkGIUETJMFTW0dHEG 8dkzh86f7bCRJFx3pvq8JgSIWxfnm/kb7k2zHD5o8Vsy2WxHRnSimw+UZfi15uTNBjIQ EVCA== 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=do5lIaZ/npTxEx4N07G4cTOPZppTqORcQBGB7xayAeQ=; b=rryfXb4SHzMEguU7Z1BcJ4RY0w1dexnkO4Cjc21iV+PhgNb7uHfFZRtVtUU6Q9FBne RtbL3IM0YLcBlLIPxzZyaRdLlgx5HIqAkf7G5Rd8evO7wCpuGneKM9iDuVeDSELdi9fr zS4gsH0Gko3BJ72DvzxeaaSbutZsAOtCt+lfNgMcR+K3mUyUL6mA+oibGZ7YVk9bzRG6 hdxCV+2UMxL8ezhtTuzzI95Sr0Uoj/q+pD/a5cIt++AOlOWxbLNOoEHLRxiq7dNoAKc0 +wMOtQdyaDi5tcNZTE2z7x2YdlSer6KsWX3TximfJ9C5toUDGLYJal/WyYf7r9Igapdm SEwA== X-Gm-Message-State: AOAM533cQWdyS+M6IACQr7mD9U3fi8Y9mT+No1RSgn8aCaLZrUNU1Yhj PyE7xd/vMtV/GXzzxPx3D7R7hPLLYHihmA== X-Received: by 2002:a1c:a483:0:b0:380:c27c:225b with SMTP id n125-20020a1ca483000000b00380c27c225bmr7407547wme.121.1645898849860; Sat, 26 Feb 2022 10:07:29 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:29 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 4/9] util/oslib-win32: Return NULL on qemu_try_memalign() with zero size Date: Sat, 26 Feb 2022 18:07:18 +0000 Message-Id: <20220226180723.1706285-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::329 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently if qemu_try_memalign() is asked to allocate 0 bytes, we assert. Instead return NULL; this is in line with the posix_memalign() API, and is valid to pass to _aligned_free() (which will do nothing). This change is a preparation for sharing the qemu_try_memalign() code between Windows and POSIX -- at the moment only the Windows version has the assert that size != 0. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- util/oslib-win32.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 05857414695..8c1c64719d7 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -48,13 +48,16 @@ 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)); } - ptr = _aligned_malloc(size, alignment); + if (size) { + ptr = _aligned_malloc(size, alignment); + } else { + ptr = NULL; + } trace_qemu_memalign(alignment, size, ptr); return ptr; } From patchwork Sat Feb 26 18:07:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546179 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1374621imf; Sat, 26 Feb 2022 10:09:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDah0ILOH0+6QQGJw5e036Hb9VTWL49TIuWjl4jFdTLyuoUN/MA8FnuKWfr4fKfubzPu5R X-Received: by 2002:a81:184c:0:b0:2d7:607f:4b00 with SMTP id 73-20020a81184c000000b002d7607f4b00mr13649614ywy.499.1645898947638; Sat, 26 Feb 2022 10:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645898947; cv=none; d=google.com; s=arc-20160816; b=AhpBuFRC7st/f57kSHRGSlBASsAfAH1E4DYjajpDbyDhHex5eZCqc87zMBtSq1WN5J c80rCn9FaUqT0HttK5t2AJSaa5n9ZRbWk8K62LlHn2mhlxeQVPm4UB2fvXlRP9qNjCzG PzK1oq5ewkcY+CjU9IXrYESh9qzof9lSWi4Uh8wc5yef6Nr9h/s3mSzhf+nynAYWADdb WbhTfYvhoTezc4iFYqOjo8rwPO9SzYwxLsRe3fymMLRSKuY09irh0Lk9+PoXbgKlKcap 9d42kQpxytvMg3lZvm79LlOWhoh7frx42bxCI2cRydVOQIgVcGC80ukITihRHGslLr3V KHfQ== 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=69r6sZ1kkJxMt2KyUKfuRJlv9++qvw2nUkFmKqMYjMg=; b=mncB3scXqmYHGoxXmQ8keQQHqTCpkfak9YQtU/JHDvfUZjQ9rKqvdHWwBkW4W3WL9B va1JdtT6+lP6frswYZ4RMZiCUNgGDh4X9HL31fevQ2It7aXZkFsQmQVPGmORyW2UaSIq hEtnWg25zXwLAzPIMyGpyuYuvO4Re0hnpbizHWA7oKMnNn5x86JnnnxMh5rLCh/8vtbP M8054j9ovooxIw/Lbwmxn9YNiHSQBI6rTlyNAS4pLEo/l+585f3FjRMUl2mwxaKV/rCj MU/5eOuRK8jAUYPUwFWjnUJnCAjx51tXfglDbyjUS0+fLbwrhUc5QUDLMLRTJ04CktTW nQBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WsTKdajf; 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 i72-20020a253b4b000000b00623f8e3c9easi4132243yba.412.2022.02.26.10.09.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:09:07 -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=WsTKdajf; 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]:57252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1VC-0006D4-VY for patch@linaro.org; Sat, 26 Feb 2022 13:09:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Tk-0005aP-4y for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:36 -0500 Received: from [2a00:1450:4864:20::32d] (port=52807 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 1nO1Th-0004O0-Dk for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:35 -0500 Received: by mail-wm1-x32d.google.com with SMTP id r10so3443651wma.2 for ; Sat, 26 Feb 2022 10:07: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=69r6sZ1kkJxMt2KyUKfuRJlv9++qvw2nUkFmKqMYjMg=; b=WsTKdajfOhq4U6yLNqqzb0iBTrwBXx+hEJbZ/T5ChdoXFlSY1tSdDXJkFHLwc7I3ba 293F0R2eHc+VYyDiN3VGzB5TOjk7tg4YJUyact6G0lWyyKqhwdT4PQFUuZLCa53CEaz8 wmgbmx1BCNXEj9Ix0jyXxlIgedMpk3u/coIdcHyi0Tx8CWYWREmvLGB5vUKv5qxZQwW5 to1fcPagap5TDkBYFTTyvHyp/Bk8oLt6BKfourzCzcnwwplD8kBoP7vK/fgbYH+JvbUS W9wxEOmreG0CImCH0m2RU1JOh70i+wU/IUbH4ipUpZqCsphvMbER4kIZxhlJYPpCRicR QSxw== 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=69r6sZ1kkJxMt2KyUKfuRJlv9++qvw2nUkFmKqMYjMg=; b=j5MvmalOVu+pMVkHKXDVn2fdxoxhJXYd9VWqLB7cL4vF/y7XuKD2uDc7nxd7UQuZst z4FUaMjhIF5WOv77NjNVp/YNs0VUg+ixSkQt1llAjx621D9Ms7eYTVKd0BO+jJ71m3JI TksCJ5stY8VVghQ4dogwLQgqOke4/NK26JmRMVUfDgVPopxN8eJ9qGbKpwT5JBeVX13Y Y1ms8g3/8S5Bq7R9m4pRlJnUTCp/bBLIa1/rjyf6hmIZjiug19HJ0U1V/WQzQopIcu8v cNxiuor8HUYSXuFHc8kSurxc7ImndvaKaZFVlnd1EiCSztN0N1RMuHGz2nkUo9IwRmNj nyMw== X-Gm-Message-State: AOAM5329qisAcCc5eSGd/J/yXLIVQH3Dv5WGjqqNXxZ65jKHDFXsLniq jOIYRHGD1HYuS5oZRlIFm6O8UAdux8shcQ== X-Received: by 2002:a7b:cb83:0:b0:37e:bc50:3c6b with SMTP id m3-20020a7bcb83000000b0037ebc503c6bmr7385511wmi.67.1645898850756; Sat, 26 Feb 2022 10:07:30 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:30 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 5/9] meson.build: Don't misdetect posix_memalign() on Windows Date: Sat, 26 Feb 2022 18:07:19 +0000 Message-Id: <20220226180723.1706285-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::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 , 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 --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 8df40bfac4d..e08de177c87 100644 --- a/meson.build +++ b/meson.build @@ -1606,7 +1606,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 Sat Feb 26 18:07:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546185 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1377903imf; Sat, 26 Feb 2022 10:14:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPfm+L6KAGEs4KsMUtKVO9hNg+cNDuypL7bYWu3UcMfYCfhytU/kJY2t0kI226SQMrx4O3 X-Received: by 2002:a0d:db83:0:b0:2ca:287c:6d36 with SMTP id d125-20020a0ddb83000000b002ca287c6d36mr13367017ywe.475.1645899289698; Sat, 26 Feb 2022 10:14:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645899289; cv=none; d=google.com; s=arc-20160816; b=uFd5ns23DOJHmwWkNJtgzGXNPNALHuX9o2+TB2FUQ6JrdIuqQmpZSoXNPW+C2D4mrj zAIU9oRg7xKLvzz39egHmGvFay4YGFBmUQIUJ1aRLNpZFOGosEsOByrJCjf07QZuLcjY pX7td2pSmdmGRgDGdXJ9eLVyJ+Mb/9q/nYYwfNBMY5MHPBgRSTAOg24FaPXo6YDvjAEX /ZeFI8N30SSNTSS/Zh4+WmVRMc7YSHrsc51eCPFXfmXsXgpLEOuXGB+KaCBPvk6d2Tk+ DXJsgEyvEXl7P4pte0E/ITrRF9rl9hY2s9zCzI2ea8MG+DXf4keyJq88cXJKJTZ6UaMR JCUg== 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=wtF+98JRuxd5OjAw52Lho5GMRtdIqK6nH1UDlgPa8sQ=; b=viXvXSxWOCsca/LugDkIdtmx+3FZ+oV8hxNKl8vLjIjC5xTujJJnxDFkfIxbj4Pluz zpExyn1N+gVBcf+5KIUOxMBavfVNfvnkJ/QypcQcS/AEJd89KKt9R8MzaF5UHS5gwkTk ArEXzBUaWyrI0dPxF2VValSgfpo9PlVT6zyCOcEstb5bFnYifsEgPiQ89wYSRsHPxnTL bgdqh9N81yXKeTgBhX5RmmSR+lKQ4SThw7fJtlmsAQmW16Ch4C5J5oC4SsjjHTQZhKBg KxJD4AeWlwBXpaHfuGdIJRLBXoQM82jwnFlA2QAiCppfPGR4k3hvD//scmpdTObXAufA NMFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oc1gnn9J; 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 c129-20020a813587000000b002d8063f12basi5120555ywa.42.2022.02.26.10.14.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:14:49 -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=oc1gnn9J; 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]:46076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1aj-0000lu-78 for patch@linaro.org; Sat, 26 Feb 2022 13:14:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Tl-0005eH-Qs for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:37 -0500 Received: from [2a00:1450:4864:20::432] (port=45010 helo=mail-wr1-x432.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nO1Ti-0004OK-4n for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:37 -0500 Received: by mail-wr1-x432.google.com with SMTP id u1so9143570wrg.11 for ; Sat, 26 Feb 2022 10:07: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=wtF+98JRuxd5OjAw52Lho5GMRtdIqK6nH1UDlgPa8sQ=; b=oc1gnn9JfFBpofKSeZ4sPS81/OJJ2C6fwbIB5s7T9rtwMdy58DK44GVZYsb4Qucm9w 7Ck7P3kgXi7CUCoF6vt5LUYMJpFjqkvcDbLvXtGZP8PuzHieUoVNMjjul2MECKmq+jvG EK5ZSWuu4Ba6+VTRd3zP6hidUOdl9q3Kt61vaAweTSfQ2q8KulU2U8BxKuFchFJKRQAG CiJ2j80oA0GN1qE1ymnSkcxgvT0MDBl9RVZ9G/TvScmrcWimIFpoa4J5jwcVU4PlUdwj ayPpDBAqEmJRGNgAxEex/keLewXJvWtxADSm9s+wqxn1CsY+CTcwRmv3UnVbnEj4RLGD 0HCg== 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=wtF+98JRuxd5OjAw52Lho5GMRtdIqK6nH1UDlgPa8sQ=; b=oQ9bhJdqyeprawQXw5VC0wOVPRp1VP8rgJl1LKbC3e/rvuUZPWliZfm4TznQJYNYOB eTv/hAHcy47459YA1WvxMJL1p3ulZFunycFKAjrp97NXcfGFS0WNBCByv9hGtMwqP5vc 5pQRiMPUIKWLg7JhJzDH4Y4c+3IFgNUJRicvAWbmjoOu2evC6iTqCwRJx5mDYph4WPCy 9dzxW1QGftsRwuf1tglaejUIAynmzhs5aOTBOtWc03bifGyYmD+lCwov8N/q/EEdgo8r +stUll4UQFBlb0WbJwpyOR2F5hz4Q7SmZ5nK3eW+AZFX7jZnF7XhFkNHFf/DJICjTqSv 8S4Q== X-Gm-Message-State: AOAM53272dYtFd/e29Qh0OeZBlEvY+MwMTn5ujWYUKVcPfzxAiRuQrGR TWopm9SgA8Ws6MDj0kdMfum+le1roCwy5w== X-Received: by 2002:a5d:470a:0:b0:1ed:e403:579a with SMTP id y10-20020a5d470a000000b001ede403579amr10139761wrq.224.1645898851607; Sat, 26 Feb 2022 10:07:31 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:31 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 6/9] util: Share qemu_try_memalign() implementation between POSIX and Windows Date: Sat, 26 Feb 2022 18:07:20 +0000 Message-Id: <20220226180723.1706285-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::432 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- meson.build | 1 + util/memalign.c | 33 +++++++++++++++++++++++++++++++++ util/oslib-posix.c | 26 -------------------------- util/oslib-win32.c | 18 ------------------ 4 files changed, 34 insertions(+), 44 deletions(-) diff --git a/meson.build b/meson.build index e08de177c87..21511d4fb61 100644 --- a/meson.build +++ b/meson.build @@ -1609,6 +1609,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..ee3393cc601 100644 --- a/util/memalign.c +++ b/util/memalign.c @@ -26,6 +26,39 @@ #include "qemu/osdep.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)); + } + +#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) + /* _aligned_malloc() fails on 0 size */ + if (size) { + ptr = _aligned_malloc(size, alignment); + } else { + ptr = NULL; + } +#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) { void *p = qemu_try_memalign(alignment, size); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 0278902ee79..91798f7e504 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -199,32 +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 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 8c1c64719d7..d9768532bec 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -44,24 +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) { - ptr = _aligned_malloc(size, alignment); - } else { - ptr = NULL; - } - trace_qemu_memalign(alignment, size, ptr); - return ptr; -} - static int get_allocation_granularity(void) { SYSTEM_INFO system_info; From patchwork Sat Feb 26 18:07:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546182 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1375903imf; Sat, 26 Feb 2022 10:11:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjXkGtjcFxSCjXJec5WpnH4YG+CxeeVehBrPVEdXaKhJziuaKMXFsIMgZk9A9SUBTF/F7D X-Received: by 2002:a25:80c6:0:b0:624:4ef6:abeb with SMTP id c6-20020a2580c6000000b006244ef6abebmr12127855ybm.394.1645899087654; Sat, 26 Feb 2022 10:11:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645899087; cv=none; d=google.com; s=arc-20160816; b=NGn4/Fm+wjLKCl1e9NshCsFOk462VXU3T+6qHuhazbDpMV0KduxZnKw0B8CLO+t7At zDbYoxuusgamb1A2sAFtyBLggD3ogvFaNDtCsUnW7kKgqvHbQRAQYVEhiHnkBFzCpol9 P4xrTQijEvaeveG9ghfNVeqHMERUoSB9hgCnxQ2pGvOJ1htecJD9Bd2/J2dqQweKchbN GX3h890qRWpBPCRjrzhrv9nCpGxL8sAGb+EJlaujxlCHFDK1KSPTp+O9zlQGWU8DgBoy GHB+qagh0cuO56oJ2JTi/UOsCJS/puT2NzKxvY+KiNCrDT7VqhE51dq7CCricPt5BHw3 mX9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=WRvAwDdZz4cYnOqR7LnotomJn/XVA//9i159XJwF/QI=; b=iJdEx+/L6BzbAI0/JSoXKClojXlxJbPO6H1t/2c4PU9Ig6n43Pvj5IewBopGqHF9E/ QXb2meIvLSQP2W2eViGYeoGBxwxgjxbK/AemFOveNoJAbEQiAJVHQrcOul1DabJm3KB9 OlHBXPofjCRFpkcHs/O/pvgm/mA8nvXb2fxUHEcRHuDEigaidvpGYg4rsTQH99w2qnE2 Am+hHFIZgY1px2knMmNDItW6qdrO/ru+KY+WRz9ucbhNQ8nWgOzttoFkHVSBdhu6bKf2 6XG3RbvjeUEIVEEnytZOJeyrJinkqIjhj4OHI5RK4ZejEKx+EFaR9w+PqRx4UZ71Cnl9 lpRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xnRAsAJe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k8-20020a25bec8000000b0062107f7d9f6si4882278ybm.446.2022.02.26.10.11.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:11:27 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xnRAsAJe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1XT-0003Rm-5R for patch@linaro.org; Sat, 26 Feb 2022 13:11:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Tl-0005do-KG for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:37 -0500 Received: from [2a00:1450:4864:20::42d] (port=43906 helo=mail-wr1-x42d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nO1Ti-0004Op-C1 for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:37 -0500 Received: by mail-wr1-x42d.google.com with SMTP id s1so9148275wrg.10 for ; Sat, 26 Feb 2022 10:07:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WRvAwDdZz4cYnOqR7LnotomJn/XVA//9i159XJwF/QI=; b=xnRAsAJeeo85tyhoFFeFLFxXowGYT0B0cDkUJT1m5pl4bsVcF0szrBWMokm0PYdiTv W+q2QEeAPLQ5S7p9H0uxFUc0fub98IyuxqjIrmD8dHaG9JCUwKe7dLO0j9UOXKtkUFtt M3R4gAxOmh3rf8Z1n8Qaf2j2FBFKBAlsVJw7ezSHdhl06FF5jby4t9SmjNlyG/7aiSdd WtE6UouZzK6OLIynPwSNy7yGTB7NMJz/H5flcu7QYeP3KfBD2+1REbQKWtumej0hH4rd awItjUDrEzrKQSIr7dgkBXnFWtj7x7jL7uPRxHi1epZph4Nit1gxucgyeuy2oZH2xlHs Ns2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WRvAwDdZz4cYnOqR7LnotomJn/XVA//9i159XJwF/QI=; b=NO1YE2X8pRZpeEvdHw2v4Lp7NKOriGC5q3aMUmxmG5aHFgL9FPFro9vOW1uGekxjqt 2BYLrMNby5aidyqwxEI9opuBp5RPfjwLVOQSGP76d54pkRS8wUM4MhuNSKSgllMrsobS sXrHMQCbHRpfyw6Ls3WGYl05mnPoY598IFAdW1PHSg8PisOosBCfaqEwLJHY0utidD4J +7OWrpWIZMPltfQAiCPsTRVd6jSM/+sfZetDUcfOmKP0Y4DERra74nIXCHMGZAWvvTho quksYUiMy7edSlF0582hTICWE9eWWJP+UHZwGQBpFZCCUnx952Y6ESGmuJEcp1tLMzvj UE8A== X-Gm-Message-State: AOAM5325lPHexs6pUPxv+dkPdKfjjta1YXxpz9AnJJrd2SMTiCFQhpHF +uNI/dJn5xy0NdoRt2C4gy9UK4CuHl1EyA== X-Received: by 2002:a05:6000:18ab:b0:1e8:f67a:1518 with SMTP id b11-20020a05600018ab00b001e8f67a1518mr10143533wri.52.1645898852458; Sat, 26 Feb 2022 10:07:32 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:32 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 7/9] util: Use meson checks for valloc() and memalign() presence Date: Sat, 26 Feb 2022 18:07:21 +0000 Message-Id: <20220226180723.1706285-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42d (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Instead of assuming that all CONFIG_BSD have valloc() and anything else is memalign(), explicitly check for those functions in meson.build and use the "is the function present" define. Tests for specific functionality are better than which-OS checks; this also lets us give a helpful error message if somehow there's no usable function present. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- meson.build | 2 ++ util/memalign.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 21511d4fb61..1c44198ebda 100644 --- a/meson.build +++ b/meson.build @@ -1610,6 +1610,8 @@ config_host_data.set('CONFIG_POSIX_FALLOCATE', cc.has_function('posix_fallocate' # thinking that Windows has posix_memalign() config_host_data.set('CONFIG_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix: '#include ')) config_host_data.set('CONFIG_ALIGNED_MALLOC', cc.has_function('_aligned_malloc')) +config_host_data.set('CONFIG_VALLOC', cc.has_function('valloc')) +config_host_data.set('CONFIG_MEMALIGN', cc.has_function('memalign')) config_host_data.set('CONFIG_PPOLL', cc.has_function('ppoll')) config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include ')) config_host_data.set('CONFIG_SEM_TIMEDWAIT', cc.has_function('sem_timedwait', dependencies: threads)) diff --git a/util/memalign.c b/util/memalign.c index ee3393cc601..fc8228bffb5 100644 --- a/util/memalign.c +++ b/util/memalign.c @@ -25,6 +25,8 @@ */ #include "qemu/osdep.h" +#include "qemu/host-utils.h" +#include "trace.h" void *qemu_try_memalign(size_t alignment, size_t size) { @@ -50,10 +52,12 @@ void *qemu_try_memalign(size_t alignment, size_t size) } else { ptr = NULL; } -#elif defined(CONFIG_BSD) +#elif defined(CONFIG_VALLOC) ptr = valloc(size); -#else +#elif defined(CONFIG_MEMALIGN) ptr = memalign(alignment, size); +#else + #error No function to allocate aligned memory available #endif trace_qemu_memalign(alignment, size, ptr); return ptr; From patchwork Sat Feb 26 18:07:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546186 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1378616imf; Sat, 26 Feb 2022 10:16:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAqHaveceVO39gvGpXf5JJCsf8NC5I9djTQ+ZKOwvUltyB72zbeA63StZRz15LmHF6FGwo X-Received: by 2002:a81:4c41:0:b0:2d0:dfa3:b734 with SMTP id z62-20020a814c41000000b002d0dfa3b734mr12960761ywa.345.1645899367843; Sat, 26 Feb 2022 10:16:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645899367; cv=none; d=google.com; s=arc-20160816; b=AT0b+pm1Z5eZS2IPzKxabT5cLluZVScnBRpnLjiy+p0dMmMK6M8sE3QA69x05HWYHJ SyHm93YyaytKGbnwjt+GdddKuiuQUOfZ97dF9t8JoDswapZGwaZXHA+aySJQJSzdRkxw PXrCML01XsjN5owP7i7m0R5iwr0EAXV1eYzCFVuikhDQLEq44xV6jp81+W/E8js8oDOu VHmVoLYvHFEk0Mx83fcSmC+zEi+Iw1NHQFfwPr94irtDpM5dydwxf8vWXhVhPR1ADRXy uz7sSRdQBXqPdzf00aIYwJOli0zuOr9kDb6zRFZZHYiof3IRguDIjtSvpfWrQnYAawH1 hFJw== 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=FYsD9wqOqPxQi23fsOx0vHUCZyCrQ51hFpvnUwBsOEQ=; b=k8vfBPowA7RdXvs9BMzuyo1OKI0DMI1WQVMpw70aunPKgw+eptIek7A4t/DEm14mOt 4o51sVn6CZJc87XnY0KsQJTPz/PL+lfOj09kg/5f6fA8+8nZGt5Xgn3N5IdpYNv9uvug QLF/Wi8ia06pqCqNXeLzMBHRbrXpCxxJ0geCBnG4+2gFtXGdfhJwguTvxmPDBS5PeYZ7 5xBgofhVvnbQ7H6R8OSZTsU2odKDB/EmCf6RMsQrNtI8p+r5wFFrt7udXQeAh+uzP0uL QUkybMWen0zUdmX9swRilEE6UWIPL0XJj/CaNDVjLS73vm2RvwQIvhROit+o+QztESEP UWWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fQhaZ++D; 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 j68-20020a25d247000000b0061e132550casi4885509ybg.4.2022.02.26.10.16.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:16:07 -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=fQhaZ++D; 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]:49862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1bz-0003PG-CD for patch@linaro.org; Sat, 26 Feb 2022 13:16:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Tm-0005gS-AM for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:38 -0500 Received: from [2a00:1450:4864:20::331] (port=43821 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 1nO1Ti-0004PI-KU for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:38 -0500 Received: by mail-wm1-x331.google.com with SMTP id n25-20020a05600c3b9900b00380f41e51e6so3602453wms.2 for ; Sat, 26 Feb 2022 10:07: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=FYsD9wqOqPxQi23fsOx0vHUCZyCrQ51hFpvnUwBsOEQ=; b=fQhaZ++DHZOfBAcw/X91vp5l5OUEhve7miJL5k4v3XXlPWfdp+5kBh0oyIMHHAernU K8/37yMnuKIFRLQlkd80bUW+te9Vz/VeKXX2eBpVQvIiPCdGLgH1q7Oj29AhUb6eQKVf yh1jykfdP67LKK9ZcHU05oZZ+WcAlo1s/vteEuqaV9pgs1uMZqaBcNwFUTLemybo3R7l Z8Jy2mlrYIujDTWl8JdoHuspfy/l9REzefQ2BLqTfSwbcPijWOTnbH+A6yIPVTeofY5B 2V+Use4s6ZhPXU1PX+hUyDFVZXlm1y2JHdtBninntl06DxkqKCbhS4iTrVjlzA4WcQwN oPUQ== 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=FYsD9wqOqPxQi23fsOx0vHUCZyCrQ51hFpvnUwBsOEQ=; b=1u1WJePV9MngBD0DGQ26qM+KSTCwYNebQwD3s3Xd1AVPk1T6BP6h+ggIFsKs3LU/Jv bPBHBnJzSrzACu1tntoSSSy+H/Jq68HM1HhHP2oDsTb7iDzeBFOhR63i5I4kWqEL0gBu +WovfJNVoGFyaiYYroZgD3QrfloNL1GT8VCzbUYy5A8g5ayMUeSeMWP6zJr6b4ybdB95 8d6kgkfGaCLlSYnU4bQYk4p52NpNz8uGtFNEu+kCbkvsHZhX3vZJLZcUvDr5ddpnrQHP LOcvhFniY8rFM8ihwrV4UYPNoD/bHePvtODdnjvXGGnHrvtNwxtGiIMlqBWFa6cJ3RmG SRoQ== X-Gm-Message-State: AOAM5327v1rzYXTCF+aJQ+2yV+pP4i2gQ3E0enwkLh0sm5su9dM1LIJX 02NrVIuMogJCJ7thUFcDvWYtP6yAtOpg4Q== X-Received: by 2002:a05:600c:4b92:b0:380:e46c:c35 with SMTP id e18-20020a05600c4b9200b00380e46c0c35mr7600286wmp.15.1645898853335; Sat, 26 Feb 2022 10:07:33 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:32 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 8/9] util: Put qemu_vfree() in memalign.c Date: Sat, 26 Feb 2022 18:07:22 +0000 Message-Id: <20220226180723.1706285-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::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 , 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 --- 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 fc8228bffb5..db6cdb095f9 100644 --- a/util/memalign.c +++ b/util/memalign.c @@ -74,3 +74,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 Sat Feb 26 18:07: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: 546183 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1376111imf; Sat, 26 Feb 2022 10:11:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxrvGJ3GKTKiR5i/c40j+wTc8lbVGCNJB9AZA+M7cNhitpIyG5QZXHP+nkd/lnNpimT/7Qq X-Received: by 2002:a25:4247:0:b0:624:11c:49e2 with SMTP id p68-20020a254247000000b00624011c49e2mr12427961yba.634.1645899107914; Sat, 26 Feb 2022 10:11:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645899107; cv=none; d=google.com; s=arc-20160816; b=m1tVM7O+AlN8blDpQdm6sFsQyttdnxsVTMK01+BWW/TlywrLf/sE4OkkTjDlwME0do 4yBhyuBAdlQOvqNuYxyrwN3mkdpAxMctXKplDzpOMepJYzI8qkW6w4XwqnP5k2Kh+BIt E7wNOuWCB37KLeMvqibYcOchpeKBEt2VpfxCBQM4HpTypmzE5/vWdS74KYmtD6m0AtUE EPqu6qUMqFB07fj87DzmkzFL+at/UsuMBvUY6Cs7XxXnE3m1V3cLieNVOeuC8lnB1RGO F0X5Pwyh7adNWrDJ5OcrtW+rKWuIsLMFDqPqZYQfosKwuZHujN251tyFcR5CF6Fdd4Lk PeWg== 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=cq469k9gdaGl4SwlZjfROg2we3ed1MXX1ij/2Dyjogc=; b=yUcP1qjj/I0jiERRyDB9UXgfyXMfhslNo+dHWR1whf7pqwjjojp/TZhzgABfd1Wt8o iqBrGrAj/GdverWStk9v24wpuNb5w7P/i/0TJ7Kn/kP9OYkXuvZnXkEMwtrDZAPHzyfR ztNpO9hY9s91uZbN6UNs0gLZpViszekJcZQH2eWG+4s0wbkWOkSpl21rDobrormRS/BN EG+zN1kQez6vDLdosGGnbMUdjitzx0ykeof4zESg4+8d8juPEPevk1V7upmyZRPBz/gS sPWD4Mm0Xe9pvNIDhybOjCWpyK1lpVLGTX3vZI80zp0tyvFWOFDXW/Qpvyjdtc0c0/az wOvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="Ji5yA/yb"; 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 l6-20020a056902072600b00628223f3f17si82725ybt.392.2022.02.26.10.11.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:11:47 -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="Ji5yA/yb"; 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]:37792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1Xn-0003ck-AL for patch@linaro.org; Sat, 26 Feb 2022 13:11:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1To-0005mt-HX for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:40 -0500 Received: from [2a00:1450:4864:20::42e] (port=39863 helo=mail-wr1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nO1Tk-0004Pt-1n for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:40 -0500 Received: by mail-wr1-x42e.google.com with SMTP id s13so9176831wrb.6 for ; Sat, 26 Feb 2022 10:07: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=cq469k9gdaGl4SwlZjfROg2we3ed1MXX1ij/2Dyjogc=; b=Ji5yA/ybLN3pZNd11t8UTCC2sbUAB3KzA04SXNPhasSo2llFCZoA8/iSqEe6kBqEHm FrIsVEYpH6mYzGuDsODRnR9U9e4uAT/RdEceyvCGHYqDdgpFgtn3PcjLNU73ZJFUMGzv 2zYoMUB4lWUCETciYX41XQ8tpexxS+LWwnnCu41+BOZfdto9GglIjvDLm2yGJAdRE44u wpPH8WZReM+aRGd0E26xLnE1NUbcq/mlpEowHQz1eTsyhALaEPn6Dm3PXg3dSBRaxl6f HP3919ODfDsKDZc6VeR9/xtalIyFiiR8USwQZad6ZKK8Fy5c1HwBmDrL8DBA/CAadLxW mh8A== 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=cq469k9gdaGl4SwlZjfROg2we3ed1MXX1ij/2Dyjogc=; b=ZRvQm+jn2jPPUGtuYnbwx1HFC0WG5U3QXH1H9pWqRPxyJXDLSt6693BMcX7x17Zx3r hLZ7FdCZ9JvKE1S4ZTxY8YlfozR2plhW4jprws6ye0Wb84a+XZrrzOUxkALt99LtbKEH u7XMjx7Jz8EKVLnaZDie5sNIhuadc/OboYiSl6a6F3COMrmEASjmjvsdU4CKQDXywnxd r8HmBcud7EaFR2ZmrHhKitGUxeXQxaJkvF6qAS6tgAmu0TUKKMyhdGvCJDeuQQqpDwtH svhFV0NQiqu9sKhzoZEHirQxTq5i11qBahEtlto3xtoUDAO9Qw4JJ8gAFiP1Un0dQSbE 0Gsg== X-Gm-Message-State: AOAM530uIDqqRQL5H1K6QH4WxLgWARSY0AfMuRgyW6jaZx2Hs0bE2cyn 1JS93sh3uodT7HKDT2hybpsWY4JgGQa98g== X-Received: by 2002:a5d:5245:0:b0:1ed:9eca:cf3d with SMTP id k5-20020a5d5245000000b001ed9ecacf3dmr9970122wrc.666.1645898854597; Sat, 26 Feb 2022 10:07:34 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:34 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 9/9] osdep: Move memalign-related functions to their own header Date: Sat, 26 Feb 2022 18:07:23 +0000 Message-Id: <20220226180723.1706285-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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é --- 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 f0b75b22bb6..ae271743ed5 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 db6cdb095f9..6420f4dc037 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