From patchwork Wed Feb 22 02:00:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655653 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp444327wrb; Tue, 21 Feb 2023 18:02:05 -0800 (PST) X-Google-Smtp-Source: AK7set8pAEoL3Fi13/JmkuAXCksjpQh26haCTWSh7lP8Kz7/tE8iYzP3Wfx1jpDxs2hbteMP2vxW X-Received: by 2002:ac2:4bd3:0:b0:4b6:fddc:1fcd with SMTP id o19-20020ac24bd3000000b004b6fddc1fcdmr2364699lfq.23.1677031325663; Tue, 21 Feb 2023 18:02:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677031325; cv=none; d=google.com; s=arc-20160816; b=hJYk5bvNTzJpAglblSoHPSEVQ5pqqeQTsUqJWF+a48YNzimUQF6Eklqfo8xGaF9d8j y2xxACOHh3+sp8otmzir5tYAVg5x8eByOS2yjQy/gIu/HWj1joayQyzwcpH9P9nVWSlI Ff3mxmNzgtw2ox/ZUeybtrbSR2Swhu+W2m0/govDZtFK/tHpMnzAPAkLkHfRC6SLoLm5 Cw5w5o/VnNOcboDOCf1L7pKsFxQdtzUD22konGB1JDvjikhxh0Bs6/5x6OGiEY0lu8Gw SwRUVpBNxwUd5TmOXCJLzKEYfwHlh8Fiwr97tOhO7FVYHctK0iNngriDmQNel4V2zTrc dRSQ== 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=65HRmCDkLuuur1UpqMIRZDfCJCF1ZUxrkWbM7vUK1aI=; b=icD7cdS3fBjHi8UX0DYilFRaKJ3qjwD0FGn1fL1WpirmMx2lZbdwYU2RpeRRMCo8cF eFwK24GZSwIRVTtTSVpMfMbOhKeEW8swRTXq0pVkRkymt7p/RhMgtOUIfdbxwdwf0DNG r+rlnZjb8Zi6wbxsTp5bW9R5kZiV0WJmOFKORCTfZLHVqo9O+twbS7BZrINB9St6h+dM 65zC2vR6GwjTfiCZam6J91pP/SPPLDTOAT+oQ+YKUbYdKNAdIkl1PWRHfVN3CrCvpGPl Z31E+cxLjR5VrQpbOrXmU141oVlZYgpLEKi1BZ5QHHOCPK1v0i3KX+AEKGF/tZVsIU7g q1sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pjrQaHse; 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 c19-20020ac25313000000b004daf436d41dsi596847lfh.530.2023.02.21.18.02.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Feb 2023 18:02:05 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pjrQaHse; 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 1pUeRA-0003Cl-NC; Tue, 21 Feb 2023 21:00:52 -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 1pUeR0-00037J-7X for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:43 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQy-00015S-EX for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:41 -0500 Received: by mail-pj1-x102b.google.com with SMTP id c23so2310361pjo.4 for ; Tue, 21 Feb 2023 18:00:40 -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=65HRmCDkLuuur1UpqMIRZDfCJCF1ZUxrkWbM7vUK1aI=; b=pjrQaHseri1q4CL5gVJIWmZ1kBqPVGiL5DWP18cRyHRB8oviGCOGoXwgypU2JP4BgH sB9SgVwaC2N3hfT+CPykUjJOeTX8kxSk2IJ5q+LrKoXXB1x41iG1c3uHJwMI35VCxxKn A+pHGZjSfnewj22J8YXmhDL7ANbiffzV7Fw7xSagWl5mr0Eo94qNG71v+SrO/of0RBdh Wcx7H3+PV8zBCdPoaMWnwz0r1soKm1RJIJCKbXVPwYKXVVQevd9Mmo+BEze+JUcc2xD8 E3J++vHO0oLhbMHkELcdOb8rKTZRa3dJJzgjBLfdge4C2zOmB0T4DhSoHhwwci1RgrBV gjjQ== 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=65HRmCDkLuuur1UpqMIRZDfCJCF1ZUxrkWbM7vUK1aI=; b=2zdlP8qmbVc16oi5V7gfF91ZW86/eF7FfSkG0O7t27exhn8elOL5TWpdkxmQhTlNu7 UoWrnjSc9PZa/HTs04OVYnC3B1kbw7Xs4la/mMhvFgdNBELGhNXEvHa8z6wxadAbpzmp ZnsTj5G6Ta7h8Vok8dO72WA0Fg/LiYXtIx8n6tGI6lMylBRWZf/I7rY4QKG+YJBOTPn2 OHnNst+g0LfQo6u3aqPih5eqKuc46B4ff9z89uS5sVNnlDMmOQkpgMTAxJOzC4R59wrN DJPNa84weYR2eUk/WFRyY2mK/oX6FYmbJpFEoRXvwHPvHLfSbG3peUbWV4EHgRrDT9ko NRfA== X-Gm-Message-State: AO0yUKUeQD+r9RmNNgP0UIzLVYdVkE/NNmXmVMy4es0cztQRnvCoDYNw x5O15ZQQfFAmxoisQqnYaoSwDf6TQ3MT8C+gsys= X-Received: by 2002:a17:902:76c9:b0:19c:a6d6:7d25 with SMTP id j9-20020a17090276c900b0019ca6d67d25mr1031515plt.37.1677031239018; Tue, 21 Feb 2023 18:00:39 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL v2 8/8] sysemu/os-win32: fix setjmp/longjmp on windows-arm64 Date: Tue, 21 Feb 2023 16:00:23 -1000 Message-Id: <20230222020023.904232-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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 From: Pierrick Bouvier 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. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Pierrick Bouvier Acked-by: Richard Henderson Message-Id: <20230221153006.20300-3-pierrick.bouvier@linaro.org> Signed-off-by: Richard Henderson --- include/sysemu/os-win32.h | 28 ++++++++++++++++++++++++---- meson.build | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 5b38c7bd04..97d0243aee 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -51,14 +51,34 @@ typedef struct sockaddr_un { extern "C" { #endif -#if defined(_WIN64) -/* On w64, setjmp is implemented by _setjmp which needs a second parameter. +#if defined(__aarch64__) +/* + * 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 windows-x64, 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. */ + * 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 bc7e5b1d15..6a139e7085 100644 --- a/meson.build +++ b/meson.build @@ -2466,6 +2466,27 @@ 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') + + if cpu == 'aarch64' and not mingw_has_setjmp_longjmp + error('mingw must provide setjmp/longjmp for windows-arm64') + endif +endif + ######################## # Target configuration # ########################