From patchwork Thu Feb 16 13:49:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 654035 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp360639wrr; Thu, 16 Feb 2023 05:49:59 -0800 (PST) X-Google-Smtp-Source: AK7set81q5vVVjnlc/j9lGXqgO6hrE3sOZuDlkH8lKxmaw0Wj/haIinPlUKs58BdyzZ42PvrHynz X-Received: by 2002:a05:6214:226b:b0:56e:bdd8:75d0 with SMTP id gs11-20020a056214226b00b0056ebdd875d0mr12051135qvb.15.1676555399188; Thu, 16 Feb 2023 05:49:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676555399; cv=none; d=google.com; s=arc-20160816; b=YyF9xNHQuEB1Mk7qiO/BQhNoU6WsSDd1Z/wvT7VvFAJvR+ufYuM9fHdYYjp2NwY6QX knYNzFVMh3pgH5ZvdvTi+708nQYAYGIGBZ9x9YNbU+5f1MZf2DThitOVp5PDffepQJW7 boZYxDvOHKjOen/PAQTf2xhjXEO50PIeeQwVfNKSnCxdg7oZs/BZYecewki2hwyORetY GZYqruPtl/GPYvMZSYgVOKb4lK8VCVt7fLr7irmb3xdfvSy8FVFETYu7fhmxOsh7GKfC gFBsY2YG+e0pZ8Hc5kMyzJvBqY8fVIT48sFoZ6EdyisZ4+bUjUAchYDYqk0MdG9mC8PZ CtgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=OmRSGsOLRR4SdMYF46j6nl7BWaAZNtQ19hvx9YK2z9A=; b=UEGMG/OSjc4j/r8AMn+SuxsLJ8K9K7QLE4Q5CYiuZb+PXKV52CrfmAlmJcruTp4lZX JczqPst8nKAodlv8KnT1YQa03NwtOQzQJX/l9N0VF9jXstKKxU05DEqBqxea49XeVHIX agOoiRlulIKUGRE8RvxPHDq9lNwCvgzv1CXFRBGiBnD1BKM9STqBK8H/NZu7DsI4t3hd 4XYbY6kiW636aSbswKbuTMM/mFW4b9ob+m/hdsmo64rnMR+F6A/69erFxx5z3aXT1HnN DsL8bdykK1gp6nNUsgq1G2EqsBPtchh5zynEc9k9MSPpDXgYs3SakTbIMwixPm91HkUN YSUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EHuUmuwe; 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=pass (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 az11-20020a05620a170b00b0071c5429ce79si1558030qkb.743.2023.02.16.05.49.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Feb 2023 05:49:59 -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=pass header.i=@linaro.org header.s=google header.b=EHuUmuwe; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSedU-0001eg-Le; Thu, 16 Feb 2023 08:49:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSedT-0001YZ-HS for qemu-devel@nongnu.org; Thu, 16 Feb 2023 08:49:19 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSedR-0001aK-Mh for qemu-devel@nongnu.org; Thu, 16 Feb 2023 08:49:19 -0500 Received: by mail-wm1-x332.google.com with SMTP id s13-20020a05600c45cd00b003ddca7a2bcbso1691204wmo.3 for ; Thu, 16 Feb 2023 05:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OmRSGsOLRR4SdMYF46j6nl7BWaAZNtQ19hvx9YK2z9A=; b=EHuUmuwedH1kFD/MC9J4nW8K4T+HDmmWh7yNfdfG99bvLzuU0jeBf2II8nXtUhj8pZ idO2kOFBczCsTu3ipHVkzQRmU2q6uzLy7V+PFKjR0UnO2Wdw3QBoK5DUoetCnshS89Kc XI3e/TjIx0H27FRF3YflXb3MG1hPHhtiUHsHxHRTLPC77yXX6dyl1ngg+pXMzcMnY71C EPd6pt4CLTkEdo92UWcQHVW3DwcrQupWFsZxn8Y3XvjIoLJSaCz3WE1SngXGNXdKhd5e NKmcPfRhZYlorkZmr+2JUF6cg6dhd3Av7QVLYde5jQ6t/N3n3aVXMOfiA20liFtsNRuz aN6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OmRSGsOLRR4SdMYF46j6nl7BWaAZNtQ19hvx9YK2z9A=; b=YPJwYOOyiusNsH24tv4XxMi6vHf65Wruf3GOMOsCSCjS25mnI1TDjP+YaYl/4HJR9H AKF0w7NHgbb1G6DRBdeOHQVP5eAJL+uDcu0c9/SoeaqDn3RvenfHnFeVZIqh5dmR1v/9 7NQHLxzmkwOszO79BB6fpabWYf8pEmT26lSLAVF1LJadkdqUt1Net2jBBcHnBLJ7WfDy 8RI0JxMXjCvBLwKrtBbjYW05BFREBor/5fyMbDO41pTIYbKmyxQ86QlrPKr4ZxRxHNWD R8feSlgOd0Km9uS3B1fj4ViH87SWNVxMkhPgJtxUDVzHahYsOibTfTMmh1VM4ik8Ev3t D6tA== X-Gm-Message-State: AO0yUKXBDUjpCdpDrm8S35W3Gg9VQxX/G5iXVh3p/KHNFEnQePm10L9e PdYPpdF2F7yn613Da/UADEyQdH4dKG+tpnfRP9E= X-Received: by 2002:a05:600c:1c10:b0:3dc:3f51:c697 with SMTP id j16-20020a05600c1c1000b003dc3f51c697mr1934793wms.18.1676555355652; Thu, 16 Feb 2023 05:49:15 -0800 (PST) Received: from volterra.localdomain ([2a01:e0a:5cc:caa0:c49d:d14a:e6ed:555a]) by smtp.gmail.com with ESMTPSA id y11-20020a05600c364b00b003dc0cb5e3f1sm1557933wmq.46.2023.02.16.05.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 05:49:15 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: sw@weilnetz.de, kkostiuk@redhat.com, clg@kaod.org, richard.henderson@linaro.org, alex.bennee@linaro.org, peter.maydell@linaro.org, Pierrick Bouvier Subject: [PATCH v2 2/4] sysemu/os-win32: fix setjmp/longjmp on windows-arm64 Date: Thu, 16 Feb 2023 14:49:09 +0100 Message-Id: <20230216134911.6803-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230216134911.6803-1-pierrick.bouvier@linaro.org> References: <20230216134911.6803-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Windows implementation of setjmp/longjmp is done in C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always* perform stack unwinding, which crashes from generated code. By using alternative implementation built in mingw, we avoid doing stack unwinding and this fixes crash when calling longjmp. Signed-off-by: Pierrick Bouvier Acked-by: Richard Henderson --- include/sysemu/os-win32.h | 21 +++++++++++++++++++-- meson.build | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 5b38c7bd04..634931a387 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -51,14 +51,31 @@ typedef struct sockaddr_un { extern "C" { #endif -#if defined(_WIN64) +#if defined(__aarch64__) +#ifndef CONFIG_MINGW64_HAS_SETJMP_LONGJMP +#error mingw must provide setjmp/longjmp for windows-arm64 +#endif +/* On windows-arm64, setjmp is available in only one variant, and longjmp always + * does stack unwinding. This crash with generated code. + * Thus, we use another implementation of setjmp (not windows one), coming from + * mingw, which never performs stack unwinding. */ +#undef setjmp +#undef longjmp +/* These functions are not declared in setjmp.h because __aarch64__ defines + * setjmp to _setjmpex instead. However, they are still defined in libmingwex.a, + * which gets linked automatically. */ +extern int __mingw_setjmp(jmp_buf); +extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int); +#define setjmp(env) __mingw_setjmp(env) +#define longjmp(env, val) __mingw_longjmp(env, val) +#elif defined(_WIN64) /* On w64, setjmp is implemented by _setjmp which needs a second parameter. * If this parameter is NULL, longjump does no stack unwinding. * That is what we need for QEMU. Passing the value of register rsp (default) * lets longjmp try a stack unwinding which will crash with generated code. */ # undef setjmp # define setjmp(env) _setjmp(env, NULL) -#endif +#endif /* __aarch64__ */ /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify * "longjmp and don't touch the signal masks". Since we know that the * savemask parameter will always be zero we can safely define these diff --git a/meson.build b/meson.build index 4ba3bf3431..7f55205437 100644 --- a/meson.build +++ b/meson.build @@ -2450,6 +2450,28 @@ if targetos == 'windows' }''', name: '_lock_file and _unlock_file')) endif +if targetos == 'windows' + mingw_has_setjmp_longjmp = cc.links(''' + #include + int main(void) { + // these functions are not available in setjmp header, but may be + // available at link time, from libmingwex.a + extern int __mingw_setjmp(jmp_buf); + extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int); + jmp_buf env; + __mingw_setjmp(env); + __mingw_longjmp(env, 0); + } + ''', name: 'mingw setjmp and longjmp') + + config_host_data.set('CONFIG_MINGW64_HAS_SETJMP_LONGJMP', + mingw_has_setjmp_longjmp) + + if cpu == 'aarch64' and not mingw_has_setjmp_longjmp + error('mingw must provide setjmp/longjmp for windows-arm64') + endif +endif + ######################## # Target configuration # ########################