From nobody Mon Jan 09 18:45:33 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NrNDd3RKZz2pG06 for ; Mon, 9 Jan 2023 18:45:37 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NrNDc3h9Zz4LFZ for ; Mon, 9 Jan 2023 18:45:36 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com; dmarc=none Received: by mail-wm1-f54.google.com with SMTP id p3-20020a05600c1d8300b003d9ee5f125bso3351564wms.4 for ; Mon, 09 Jan 2023 10:45:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:in-reply-to:to:references:date:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zR9NwC1o+wo3fO7p1iN1mvDjyHREpx55khqHOtuRwG0=; b=cxinL6eJn1DZPZlTYQRqeZrQcA7PPw+hD8Ner7I92BHpQSGls+PZVT2cTrvzS+YOkh 9UFgRawij0PnuZWJHsIpPb2ORaB6k9hcRfg1M3Alnq61hhFRD7ICMbqhCWgSdCY4P3A5 LOCPx9oKbdDJiaBARgVhNjablhV8I89XnGirbuwz5joPQFNgka9U37zFALAvI2ZotW7C Lo7e8riWw8n+wY6AJzTcxgFeQJZn03UWP6LIowzgvLByqV8z/l1rFWLPb5Api0YCWMBb w0fZz3OgVkz9BL2Kl1E6JE0WlN7f55IeSWtlKM6hd7+PZ4fkhz70LI3KeDfQWFfCc9xf 0/5Q== X-Gm-Message-State: AFqh2kryppgaR44nXtmPaZ48RbDQpnxNjr8jXk/NII7cMjE2GCjRkkcu z538EK/yVUd1SKdQwFhEd5vwobgTetxI/yzZPBE= X-Google-Smtp-Source: AMrXdXtTUZL2XmicsbRWgIK7E491nnpvmZnWeROxXet4k7EKEQwRyT087gNOCouSXP0OiOYi2qCU5w== X-Received: by 2002:a7b:c7c8:0:b0:3d7:889:7496 with SMTP id z8-20020a7bc7c8000000b003d708897496mr46828218wmk.17.1673289934678; Mon, 09 Jan 2023 10:45:34 -0800 (PST) Received: from smtpclient.apple (global-5-143.n-2.net.cam.ac.uk. [131.111.5.143]) by smtp.gmail.com with ESMTPSA id x7-20020a05600c188700b003c701c12a17sm16027698wmp.12.2023.01.09.10.45.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jan 2023 10:45:33 -0800 (PST) From: Jessica Clarke Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: git: 9fb118bebced - main - libc: Fix longjmp/_longjmp(buf, 0) for AArch64 and RISC-V Date: Mon, 9 Jan 2023 18:45:33 +0000 References: <202301091835.309IZLck039260@gitrepo.freebsd.org> To: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" In-Reply-To: <202301091835.309IZLck039260@gitrepo.freebsd.org> Message-Id: <0B085CFE-D71D-486D-9367-885417F9A8C5@freebsd.org> X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spamd-Result: default: False [-2.50 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-main@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; DMARC_NA(0.00)[freebsd.org]; TO_DN_EQ_ADDR_ALL(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.128.54:from]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-main@freebsd.org]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; FREEFALL_USER(0.00)[jrtc27]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.128.54:from] X-Rspamd-Queue-Id: 4NrNDc3h9Zz4LFZ X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N On 9 Jan 2023, at 18:35, Jessica Clarke wrote: >=20 > The branch main has been updated by jrtc27: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3D9fb118bebced1452a46756a13be01610= 21b10905 >=20 > commit 9fb118bebced1452a46756a13be0161021b10905 > Author: Jessica Clarke > AuthorDate: 2023-01-09 18:34:43 +0000 > Commit: Jessica Clarke > CommitDate: 2023-01-09 18:34:43 +0000 >=20 > libc: Fix longjmp/_longjmp(buf, 0) for AArch64 and RISC-V >=20 > These architectures fail to handle this special case, and will = cause the > corresponding setjmp/_setjmp to return 0 rather than 1. Fix this = and add > regression tests (also committed upstream). >=20 > PR: 268684 Also PR: 268521 Jess > Reviewed by: arichardson, jhb > MFC after: 1 week > Differential Revision: https://reviews.freebsd.org/D29363 > --- > contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c | 50 = ++++++++++++++++++++++--- > lib/libc/aarch64/gen/_setjmp.S | 3 +- > lib/libc/aarch64/gen/setjmp.S | 3 +- > lib/libc/riscv/gen/_setjmp.S | 3 ++ > lib/libc/riscv/gen/setjmp.S | 3 ++ > 5 files changed, 55 insertions(+), 7 deletions(-) >=20 > diff --git a/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c = b/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c > index 1f0f1ed5ea89..1b1baa584468 100644 > --- a/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c > +++ b/contrib/netbsd-tests/lib/libc/setjmp/t_setjmp.c > @@ -70,6 +70,7 @@ __RCSID("$NetBSD: t_setjmp.c,v 1.2 2017/01/14 = 21:08:17 christos Exp $"); > #include > #include > #include > +#include > #include > #include > #include > @@ -83,6 +84,8 @@ __RCSID("$NetBSD: t_setjmp.c,v 1.2 2017/01/14 = 21:08:17 christos Exp $"); > #define TEST_U_SETJMP 1 > #define TEST_SIGSETJMP_SAVE 2 > #define TEST_SIGSETJMP_NOSAVE 3 > +#define TEST_LONGJMP_ZERO 4 > +#define TEST_U_LONGJMP_ZERO 5 >=20 > static int expectsignal; >=20 > @@ -101,12 +104,16 @@ h_check(int test) > sigjmp_buf sjb; > sigset_t ss; > int i, x; > + volatile bool did_longjmp; >=20 > i =3D getpid(); > + did_longjmp =3D false; >=20 > - if (test =3D=3D TEST_SETJMP || test =3D=3D TEST_SIGSETJMP_SAVE) > + if (test =3D=3D TEST_SETJMP || test =3D=3D TEST_SIGSETJMP_SAVE = || > + test =3D=3D TEST_LONGJMP_ZERO) > expectsignal =3D 0; > - else if (test =3D=3D TEST_U_SETJMP || test =3D=3D = TEST_SIGSETJMP_NOSAVE) > + else if (test =3D=3D TEST_U_SETJMP || test =3D=3D = TEST_SIGSETJMP_NOSAVE || > + test =3D=3D TEST_U_LONGJMP_ZERO) > expectsignal =3D 1; > else > atf_tc_fail("unknown test"); > @@ -119,26 +126,37 @@ h_check(int test) > REQUIRE_ERRNO(sigaddset(&ss, SIGABRT) !=3D -1); > REQUIRE_ERRNO(sigprocmask(SIG_BLOCK, &ss, NULL) !=3D -1); >=20 > - if (test =3D=3D TEST_SETJMP) > + if (test =3D=3D TEST_SETJMP || test =3D=3D TEST_LONGJMP_ZERO) > x =3D setjmp(jb); > - else if (test =3D=3D TEST_U_SETJMP) > + else if (test =3D=3D TEST_U_SETJMP || test =3D=3D = TEST_U_LONGJMP_ZERO) > x =3D _setjmp(jb); > else=20 > x =3D sigsetjmp(sjb, !expectsignal); >=20 > if (x !=3D 0) { > - ATF_REQUIRE_MSG(x =3D=3D i, "setjmp returned wrong = value"); > + if (test =3D=3D TEST_LONGJMP_ZERO || test =3D=3D = TEST_U_LONGJMP_ZERO) > + ATF_REQUIRE_MSG(x =3D=3D 1, "setjmp returned = wrong value"); > + else > + ATF_REQUIRE_MSG(x =3D=3D i, "setjmp returned = wrong value"); > + > kill(i, SIGABRT); > ATF_REQUIRE_MSG(!expectsignal, "kill(SIGABRT) failed"); > atf_tc_pass(); > + } else if (did_longjmp) { > + atf_tc_fail("setjmp returned zero after longjmp"); > } >=20 > REQUIRE_ERRNO(sigprocmask(SIG_UNBLOCK, &ss, NULL) !=3D -1); >=20 > + did_longjmp =3D true; > if (test =3D=3D TEST_SETJMP) > longjmp(jb, i); > + else if (test =3D=3D TEST_LONGJMP_ZERO) > + longjmp(jb, 0); > else if (test =3D=3D TEST_U_SETJMP) > _longjmp(jb, i); > + else if (test =3D=3D TEST_U_LONGJMP_ZERO) > + _longjmp(jb, 0); > else=20 > siglongjmp(sjb, i); >=20 > @@ -185,12 +203,34 @@ ATF_TC_BODY(sigsetjmp_nosave, tc) > h_check(TEST_SIGSETJMP_NOSAVE); > } >=20 > +ATF_TC(longjmp_zero); > +ATF_TC_HEAD(longjmp_zero, tc) > +{ > + atf_tc_set_md_var(tc, "descr", "Checks longjmp(3) with a zero = value"); > +} > +ATF_TC_BODY(longjmp_zero, tc) > +{ > + h_check(TEST_LONGJMP_ZERO); > +} > + > +ATF_TC(_longjmp_zero); > +ATF_TC_HEAD(_longjmp_zero, tc) > +{ > + atf_tc_set_md_var(tc, "descr", "Checks _longjmp(3) with a zero = value"); > +} > +ATF_TC_BODY(_longjmp_zero, tc) > +{ > + h_check(TEST_U_LONGJMP_ZERO); > +} > + > ATF_TP_ADD_TCS(tp) > { > ATF_TP_ADD_TC(tp, setjmp); > ATF_TP_ADD_TC(tp, _setjmp); > ATF_TP_ADD_TC(tp, sigsetjmp_save); > ATF_TP_ADD_TC(tp, sigsetjmp_nosave); > + ATF_TP_ADD_TC(tp, longjmp_zero); > + ATF_TP_ADD_TC(tp, _longjmp_zero); >=20 > return atf_no_error(); > } > diff --git a/lib/libc/aarch64/gen/_setjmp.S = b/lib/libc/aarch64/gen/_setjmp.S > index 49bf4df4f524..94a58d774f2b 100644 > --- a/lib/libc/aarch64/gen/_setjmp.S > +++ b/lib/libc/aarch64/gen/_setjmp.S > @@ -91,7 +91,8 @@ ENTRY(_longjmp) > #endif >=20 > /* Load the return value */ > - mov x0, x1 > + cmp x1, #0 > + csinc x0, x1, xzr, ne > ret >=20 > botch: > diff --git a/lib/libc/aarch64/gen/setjmp.S = b/lib/libc/aarch64/gen/setjmp.S > index b302594ff549..e6cdba801e19 100644 > --- a/lib/libc/aarch64/gen/setjmp.S > +++ b/lib/libc/aarch64/gen/setjmp.S > @@ -113,7 +113,8 @@ ENTRY(longjmp) > ldp d14, d15, [x0] >=20 > /* Load the return value */ > - mov x0, x1 > + cmp x1, #0 > + csinc x0, x1, xzr, ne > ret >=20 > botch: > diff --git a/lib/libc/riscv/gen/_setjmp.S = b/lib/libc/riscv/gen/_setjmp.S > index ded6705ef7ee..94b4e90b6f42 100644 > --- a/lib/libc/riscv/gen/_setjmp.S > +++ b/lib/libc/riscv/gen/_setjmp.S > @@ -131,6 +131,9 @@ ENTRY(_longjmp) >=20 > /* Load the return value */ > mv a0, a1 > + bnez a1, 1f > + li a0, 1 > +1: > ret >=20 > botch: > diff --git a/lib/libc/riscv/gen/setjmp.S b/lib/libc/riscv/gen/setjmp.S > index c0458e907ce0..1d5b4d5fc0ca 100644 > --- a/lib/libc/riscv/gen/setjmp.S > +++ b/lib/libc/riscv/gen/setjmp.S > @@ -161,6 +161,9 @@ ENTRY(longjmp) >=20 > /* Load the return value */ > mv a0, a1 > + bnez a1, 1f > + li a0, 1 > +1: > ret >=20 > botch: