From patchwork Mon Feb 13 16:13:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 653227 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp2639228wrr; Mon, 13 Feb 2023 12:50:35 -0800 (PST) X-Google-Smtp-Source: AK7set9+wURxTyHCdTSK3KIkTRfwzxnhwGBGbj6F/DFRJRPQrOo/qTUup2B8eE3F7UsgR3iCwdbQ X-Received: by 2002:a05:622a:c2:b0:3b7:fafc:73e3 with SMTP id p2-20020a05622a00c200b003b7fafc73e3mr44846015qtw.41.1676321434971; Mon, 13 Feb 2023 12:50:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676321434; cv=none; d=google.com; s=arc-20160816; b=h2l+daSDHgMS4IuXl6ZRoOHV5bd1hDQd8VfSrBZ+2ByslNxkAAqhDwfQk4baiFj1xC wWwejVGKIsbmWpS9G8fzbw2Xt5b+SMz7e4FlKyke80fNle2mmt+VxZ4H0VRHvMNSlipJ 558Sm+n2Mx/aFw2Q3QqO0LEx1vrQZXS2FB5yLgCUx7kmGWqU+RbfuscULRHIVtYg9Svt rOfJK2JTip0oxVUKr0iVSXrAlwsnIJWdKQJG+ZAomBaDiTwF0Uoc7Znl7VVdNrQy+OwL alzJgoCjE1FB4QreSFOMGyxnRGSwyfBAIY5KPKMz6rHK801aSawXQktdoscar5B/30hy XkfA== 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=vGXouOChIYjl8AkJ3HhGb5U80hOl0zPVyYzc37vy0jM=; b=yHsPEb2WzYO35mi3rmX6/wSLnYfdYTWCokGdEICFvZxZV3QnWrKrPrz85bvuDa4jMF Zcv8PP6sigrB6g7Jf31afm7ZYJx9XJSHKjE7VvCGXjZ8UCfy1/iBhYDDvwO428j7F65Q F6s1PkI79eOs/UqKf8jtd2b6xy6Cz/YZ1aVoeTajuNMFfBGtwvIlGzMlBfOnnX6VihS8 X7cvxFG83SFYgIv4/a6tpYRm/c8qoMzEObvkxOQOwH7d413nWpYwg9i5UiacG3mQSy3m xpNzqmJ9vIXm1QtfRIdQNRX/RcJrQgZSi8wI8E8F6h06I0G143jPmcfbGteaJArnPdfC NsTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WCllbPTY; 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 y7-20020a05622a120700b003ba03ca1174si10102246qtx.711.2023.02.13.12.50.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Feb 2023 12:50:34 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WCllbPTY; 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 1pRfku-0000qO-Bs; Mon, 13 Feb 2023 15:48:56 -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 1pRbT1-00083I-3c for qemu-devel@nongnu.org; Mon, 13 Feb 2023 11:14:11 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pRbSz-0005jr-FQ for qemu-devel@nongnu.org; Mon, 13 Feb 2023 11:14:10 -0500 Received: by mail-wm1-x32e.google.com with SMTP id j29-20020a05600c1c1d00b003dc52fed235so9448003wms.1 for ; Mon, 13 Feb 2023 08:14:08 -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=vGXouOChIYjl8AkJ3HhGb5U80hOl0zPVyYzc37vy0jM=; b=WCllbPTYj7Vud2F7vQj3yhg1D6dziLwm9+gftTJRayUZkPCwHjUJJ/oW2/3I7ekMmn WNA9xORPbErgpzxxDiJmdL43ghuPBPo6t1Tc9zjrZ5cLj0+Cwi8pcz0VZQ5J/R5LJX7H 7HH9N03LgWjwJCtix/BKouIEBsBQpaUWRApqsdwfghCYw1d9TmRX2wNZsE3SiCCoiKoQ SUx8oeY/aCkfvkEyvgKRi4IgkXdsVjItfaiQqdJmOqBhXe3HByQBQ2VfEofERucQIaoW qPe+dWcXHRk0j3Df89KzAT+7mFDpVkhIekoiBNipFvUyliFHjnwH9wuWV6JL6upcMhYA 1qWA== 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=vGXouOChIYjl8AkJ3HhGb5U80hOl0zPVyYzc37vy0jM=; b=VmUqJJECDnyIizQMTmfm7VKEKdBw6R6vfcV6ybo/pbxzE1s9M9bufxNX6KZnw6QOFk UQ+wv1pE57f3tfHHVSTZg/aRU0c5HoHaMQI12yXM6DpDfTOYHuO32Ylae+tsEKLWSDEH kCPp6JetYVd1s3hxjca2IQvld0vfNU+seEPK3bc6ndBUPCkbcNUPRL/7vj4Td4KXETxi CCEi4MkFGiwhNyTfGhUqqA0xF+f//tq1Ljj5vHpNaTDMeqIsAFy8eiZscXCY9zf0Aegq 8KUi1H/TraAKGZn+wZ7bNsfSuVnjkTebfU/wdpAU7yQ8jQFFomUkg3CbFkJ0vQFmC1vw H0Lg== X-Gm-Message-State: AO0yUKUntrigNgjyEVmYarkLpqpI1BoBvsOWd2wp0iiAQ9GUCSSsj26w 2y5HRsESVelYVghwcfTnfGocjNfyd6ULeziKK5M= X-Received: by 2002:a05:600c:4da4:b0:3dc:443e:420e with SMTP id v36-20020a05600c4da400b003dc443e420emr18549209wmp.2.1676304847598; Mon, 13 Feb 2023 08:14:07 -0800 (PST) Received: from volterra.localdomain ([2a01:e0a:5cc:caa0:8df5:e191:f2b0:5825]) by smtp.gmail.com with ESMTPSA id t13-20020adfe44d000000b002c557f82e27sm3582882wrm.99.2023.02.13.08.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:14:07 -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, Pierrick Bouvier Subject: [PATCH 2/4] sysemu/os-win32: fix setjmp/longjmp on windows-arm64 Date: Mon, 13 Feb 2023 17:13:50 +0100 Message-Id: <20230213161352.17199-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230213161352.17199-1-pierrick.bouvier@linaro.org> References: <20230213161352.17199-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x32e.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-Mailman-Approved-At: Mon, 13 Feb 2023 15:48:53 -0500 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 --- include/sysemu/os-win32.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 5b38c7bd04..84f62d0a17 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -51,14 +51,28 @@ typedef struct sockaddr_un { extern "C" { #endif -#if defined(_WIN64) +#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 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