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 @@ -1,196 +1,236 @@ /* $NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * Copyright (c) 1994 Christopher G. Demetriou * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed for the * NetBSD Project. See http://www.NetBSD.org/ for * information about NetBSD. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * <> */ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); __RCSID("$NetBSD: t_setjmp.c,v 1.2 2017/01/14 21:08:17 christos Exp $"); #include #include #include #include +#include #include #include #include #include #include #define REQUIRE_ERRNO(x) ATF_REQUIRE_MSG(x, "%s", strerror(errno)) #define TEST_SETJMP 0 #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 static int expectsignal; static void aborthandler(int signo __unused) { ATF_REQUIRE_MSG(expectsignal, "kill(SIGABRT) succeeded"); atf_tc_pass(); } static void h_check(int test) { struct sigaction sa; jmp_buf jb; sigjmp_buf sjb; sigset_t ss; int i, x; + volatile bool did_longjmp; i = getpid(); + did_longjmp = false; - if (test == TEST_SETJMP || test == TEST_SIGSETJMP_SAVE) + if (test == TEST_SETJMP || test == TEST_SIGSETJMP_SAVE || + test == TEST_LONGJMP_ZERO) expectsignal = 0; - else if (test == TEST_U_SETJMP || test == TEST_SIGSETJMP_NOSAVE) + else if (test == TEST_U_SETJMP || test == TEST_SIGSETJMP_NOSAVE || + test == TEST_U_LONGJMP_ZERO) expectsignal = 1; else atf_tc_fail("unknown test"); sa.sa_handler = aborthandler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; REQUIRE_ERRNO(sigaction(SIGABRT, &sa, NULL) != -1); REQUIRE_ERRNO(sigemptyset(&ss) != -1); REQUIRE_ERRNO(sigaddset(&ss, SIGABRT) != -1); REQUIRE_ERRNO(sigprocmask(SIG_BLOCK, &ss, NULL) != -1); - if (test == TEST_SETJMP) + if (test == TEST_SETJMP || test == TEST_LONGJMP_ZERO) x = setjmp(jb); - else if (test == TEST_U_SETJMP) + else if (test == TEST_U_SETJMP || test == TEST_U_LONGJMP_ZERO) x = _setjmp(jb); else x = sigsetjmp(sjb, !expectsignal); if (x != 0) { - ATF_REQUIRE_MSG(x == i, "setjmp returned wrong value"); + if (test == TEST_LONGJMP_ZERO || test == TEST_U_LONGJMP_ZERO) + ATF_REQUIRE_MSG(x == 1, "setjmp returned wrong value"); + else + ATF_REQUIRE_MSG(x == 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"); } REQUIRE_ERRNO(sigprocmask(SIG_UNBLOCK, &ss, NULL) != -1); + did_longjmp = true; if (test == TEST_SETJMP) longjmp(jb, i); + else if (test == TEST_LONGJMP_ZERO) + longjmp(jb, 0); else if (test == TEST_U_SETJMP) _longjmp(jb, i); + else if (test == TEST_U_LONGJMP_ZERO) + _longjmp(jb, 0); else siglongjmp(sjb, i); atf_tc_fail("jmp failed"); } ATF_TC(setjmp); ATF_TC_HEAD(setjmp, tc) { atf_tc_set_md_var(tc, "descr", "Checks setjmp(3)"); } ATF_TC_BODY(setjmp, tc) { h_check(TEST_SETJMP); } ATF_TC(_setjmp); ATF_TC_HEAD(_setjmp, tc) { atf_tc_set_md_var(tc, "descr", "Checks _setjmp(3)"); } ATF_TC_BODY(_setjmp, tc) { h_check(TEST_U_SETJMP); } ATF_TC(sigsetjmp_save); ATF_TC_HEAD(sigsetjmp_save, tc) { atf_tc_set_md_var(tc, "descr", "Checks sigsetjmp(3) with savemask enabled"); } ATF_TC_BODY(sigsetjmp_save, tc) { h_check(TEST_SIGSETJMP_SAVE); } ATF_TC(sigsetjmp_nosave); ATF_TC_HEAD(sigsetjmp_nosave, tc) { atf_tc_set_md_var(tc, "descr", "Checks sigsetjmp(3) with savemask disabled"); } ATF_TC_BODY(sigsetjmp_nosave, tc) { h_check(TEST_SIGSETJMP_NOSAVE); } +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); 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 @@ -1,104 +1,105 @@ /*- * Copyright (c) 2014 Andrew Turner * Copyright (c) 2014 The FreeBSD Foundation * * Portions of this software were developed by Andrew Turner * under sponsorship from the FreeBSD Foundation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include __FBSDID("$FreeBSD$"); #include ENTRY(_setjmp) /* Store the magic value and stack pointer */ ldr x8, .Lmagic mov x9, sp stp x8, x9, [x0], #16 /* Store the general purpose registers and lr */ stp x19, x20, [x0], #16 stp x21, x22, [x0], #16 stp x23, x24, [x0], #16 stp x25, x26, [x0], #16 stp x27, x28, [x0], #16 stp x29, lr, [x0], #16 #ifndef _STANDALONE /* Store the vfp registers */ stp d8, d9, [x0], #16 stp d10, d11, [x0], #16 stp d12, d13, [x0], #16 stp d14, d15, [x0] #endif /* Return value */ mov x0, #0 ret .align 3 .Lmagic: .quad _JB_MAGIC__SETJMP END(_setjmp) ENTRY(_longjmp) /* Check the magic value */ ldr x8, [x0], #8 ldr x9, .Lmagic cmp x8, x9 b.ne botch /* Restore the stack pointer */ ldr x8, [x0], #8 mov sp, x8 /* Restore the general purpose registers and lr */ ldp x19, x20, [x0], #16 ldp x21, x22, [x0], #16 ldp x23, x24, [x0], #16 ldp x25, x26, [x0], #16 ldp x27, x28, [x0], #16 ldp x29, lr, [x0], #16 #ifndef _STANDALONE /* Restore the vfp registers */ ldp d8, d9, [x0], #16 ldp d10, d11, [x0], #16 ldp d12, d13, [x0], #16 ldp d14, d15, [x0] #endif /* Load the return value */ - mov x0, x1 + cmp x1, #0 + csinc x0, x1, xzr, ne ret botch: #ifdef _STANDALONE b botch #else bl _C_LABEL(longjmperror) bl _C_LABEL(abort) #endif END(_longjmp) 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 @@ -1,122 +1,123 @@ /*- * Copyright (c) 2014 Andrew Turner * Copyright (c) 2014 The FreeBSD Foundation * * Portions of this software were developed by Andrew Turner * under sponsorship from the FreeBSD Foundation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include __FBSDID("$FreeBSD$"); #include ENTRY(setjmp) sub sp, sp, #16 stp x0, lr, [sp] /* Store the signal mask */ add x2, x0, #(_JB_SIGMASK * 8) /* oset */ mov x1, #0 /* set */ mov x0, #1 /* SIG_BLOCK */ bl sigprocmask ldp x0, lr, [sp] add sp, sp, #16 /* Store the magic value and stack pointer */ ldr x8, .Lmagic mov x9, sp stp x8, x9, [x0], #16 /* Store the general purpose registers and lr */ stp x19, x20, [x0], #16 stp x21, x22, [x0], #16 stp x23, x24, [x0], #16 stp x25, x26, [x0], #16 stp x27, x28, [x0], #16 stp x29, lr, [x0], #16 /* Store the vfp registers */ stp d8, d9, [x0], #16 stp d10, d11, [x0], #16 stp d12, d13, [x0], #16 stp d14, d15, [x0] /* Return value */ mov x0, #0 ret .align 3 .Lmagic: .quad _JB_MAGIC_SETJMP END(setjmp) ENTRY(longjmp) sub sp, sp, #32 stp x0, lr, [sp] str x1, [sp, #16] /* Restore the signal mask */ mov x2, #0 /* oset */ add x1, x0, #(_JB_SIGMASK * 8) /* set */ mov x0, #3 /* SIG_SETMASK */ bl sigprocmask ldr x1, [sp, #16] ldp x0, lr, [sp] add sp, sp, #32 /* Check the magic value */ ldr x8, [x0], #8 ldr x9, .Lmagic cmp x8, x9 b.ne botch /* Restore the stack pointer */ ldr x8, [x0], #8 mov sp, x8 /* Restore the general purpose registers and lr */ ldp x19, x20, [x0], #16 ldp x21, x22, [x0], #16 ldp x23, x24, [x0], #16 ldp x25, x26, [x0], #16 ldp x27, x28, [x0], #16 ldp x29, lr, [x0], #16 /* Restore the vfp registers */ ldp d8, d9, [x0], #16 ldp d10, d11, [x0], #16 ldp d12, d13, [x0], #16 ldp d14, d15, [x0] /* Load the return value */ - mov x0, x1 + cmp x1, #0 + csinc x0, x1, xzr, ne ret botch: bl _C_LABEL(longjmperror) bl _C_LABEL(abort) END(longjmp) 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 @@ -1,143 +1,146 @@ /*- * Copyright (c) 2015-2016 Ruslan Bukin * All rights reserved. * * Portions of this software were developed by SRI International and the * University of Cambridge Computer Laboratory under DARPA/AFRL contract * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. * * Portions of this software were developed by the University of Cambridge * Computer Laboratory as part of the CTSRD Project, with support from the * UK Higher Education Innovation Fund (HEIF). * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include ENTRY(_setjmp) /* Store the magic value and stack pointer */ ld t0, .Lmagic sd t0, (0 * 8)(a0) sd sp, (1 * 8)(a0) addi a0, a0, (2 * 8) /* Store the general purpose registers and ra */ sd s0, (0 * 8)(a0) sd s1, (1 * 8)(a0) sd s2, (2 * 8)(a0) sd s3, (3 * 8)(a0) sd s4, (4 * 8)(a0) sd s5, (5 * 8)(a0) sd s6, (6 * 8)(a0) sd s7, (7 * 8)(a0) sd s8, (8 * 8)(a0) sd s9, (9 * 8)(a0) sd s10, (10 * 8)(a0) sd s11, (11 * 8)(a0) sd ra, (12 * 8)(a0) addi a0, a0, (13 * 8) #if !defined(_STANDALONE) && defined(__riscv_float_abi_double) /* Store the fpe registers */ fsd fs0, (0 * 8)(a0) fsd fs1, (1 * 8)(a0) fsd fs2, (2 * 8)(a0) fsd fs3, (3 * 8)(a0) fsd fs4, (4 * 8)(a0) fsd fs5, (5 * 8)(a0) fsd fs6, (6 * 8)(a0) fsd fs7, (7 * 8)(a0) fsd fs8, (8 * 8)(a0) fsd fs9, (9 * 8)(a0) fsd fs10, (10 * 8)(a0) fsd fs11, (11 * 8)(a0) addi a0, a0, (12 * 8) #endif /* Return value */ li a0, 0 ret .align 3 .Lmagic: .quad _JB_MAGIC__SETJMP END(_setjmp) ENTRY(_longjmp) /* Check the magic value */ ld t0, 0(a0) ld t1, .Lmagic bne t0, t1, botch /* Restore the stack pointer */ ld t0, 8(a0) mv sp, t0 addi a0, a0, (2 * 8) /* Restore the general purpose registers and ra */ ld s0, (0 * 8)(a0) ld s1, (1 * 8)(a0) ld s2, (2 * 8)(a0) ld s3, (3 * 8)(a0) ld s4, (4 * 8)(a0) ld s5, (5 * 8)(a0) ld s6, (6 * 8)(a0) ld s7, (7 * 8)(a0) ld s8, (8 * 8)(a0) ld s9, (9 * 8)(a0) ld s10, (10 * 8)(a0) ld s11, (11 * 8)(a0) ld ra, (12 * 8)(a0) addi a0, a0, (13 * 8) #if !defined(_STANDALONE) && defined(__riscv_float_abi_double) /* Restore the fpe registers */ fld fs0, (0 * 8)(a0) fld fs1, (1 * 8)(a0) fld fs2, (2 * 8)(a0) fld fs3, (3 * 8)(a0) fld fs4, (4 * 8)(a0) fld fs5, (5 * 8)(a0) fld fs6, (6 * 8)(a0) fld fs7, (7 * 8)(a0) fld fs8, (8 * 8)(a0) fld fs9, (9 * 8)(a0) fld fs10, (10 * 8)(a0) fld fs11, (11 * 8)(a0) addi a0, a0, (12 * 8) #endif /* Load the return value */ mv a0, a1 + bnez a1, 1f + li a0, 1 +1: ret botch: #ifdef _STANDALONE j botch #else call _C_LABEL(longjmperror) call _C_LABEL(abort) #endif END(_longjmp) 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 @@ -1,169 +1,172 @@ /*- * Copyright (c) 2015-2016 Ruslan Bukin * All rights reserved. * * Portions of this software were developed by SRI International and the * University of Cambridge Computer Laboratory under DARPA/AFRL contract * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. * * Portions of this software were developed by the University of Cambridge * Computer Laboratory as part of the CTSRD Project, with support from the * UK Higher Education Innovation Fund (HEIF). * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include ENTRY(setjmp) addi sp, sp, -(2 * 8) sd a0, 0(sp) sd ra, 8(sp) /* Store the signal mask */ addi a2, a0, (_JB_SIGMASK * 8) /* oset */ li a1, 0 /* set */ li a0, 1 /* SIG_BLOCK */ call _C_LABEL(sigprocmask) ld a0, 0(sp) ld ra, 8(sp) addi sp, sp, (2 * 8) /* Store the magic value and stack pointer */ ld t0, .Lmagic sd t0, (0 * 8)(a0) sd sp, (1 * 8)(a0) addi a0, a0, (2 * 8) /* Store the general purpose registers and ra */ sd s0, (0 * 8)(a0) sd s1, (1 * 8)(a0) sd s2, (2 * 8)(a0) sd s3, (3 * 8)(a0) sd s4, (4 * 8)(a0) sd s5, (5 * 8)(a0) sd s6, (6 * 8)(a0) sd s7, (7 * 8)(a0) sd s8, (8 * 8)(a0) sd s9, (9 * 8)(a0) sd s10, (10 * 8)(a0) sd s11, (11 * 8)(a0) sd ra, (12 * 8)(a0) addi a0, a0, (13 * 8) #ifdef __riscv_float_abi_double /* Store the fpe registers */ fsd fs0, (0 * 8)(a0) fsd fs1, (1 * 8)(a0) fsd fs2, (2 * 8)(a0) fsd fs3, (3 * 8)(a0) fsd fs4, (4 * 8)(a0) fsd fs5, (5 * 8)(a0) fsd fs6, (6 * 8)(a0) fsd fs7, (7 * 8)(a0) fsd fs8, (8 * 8)(a0) fsd fs9, (9 * 8)(a0) fsd fs10, (10 * 8)(a0) fsd fs11, (11 * 8)(a0) addi a0, a0, (12 * 8) #endif /* Return value */ li a0, 0 ret .align 3 .Lmagic: .quad _JB_MAGIC_SETJMP END(setjmp) ENTRY(longjmp) /* Check the magic value */ ld t0, 0(a0) ld t1, .Lmagic bne t0, t1, botch addi sp, sp, -(4 * 8) sd a0, (0 * 8)(sp) sd ra, (1 * 8)(sp) sd a1, (2 * 8)(sp) /* Restore the signal mask */ li a2, 0 /* oset */ addi a1, a0, (_JB_SIGMASK * 8) /* set */ li a0, 3 /* SIG_BLOCK */ call _C_LABEL(sigprocmask) ld a1, (2 * 8)(sp) ld ra, (1 * 8)(sp) ld a0, (0 * 8)(sp) addi sp, sp, (4 * 8) /* Restore the stack pointer */ ld t0, 8(a0) mv sp, t0 addi a0, a0, (2 * 8) /* Restore the general purpose registers and ra */ ld s0, (0 * 8)(a0) ld s1, (1 * 8)(a0) ld s2, (2 * 8)(a0) ld s3, (3 * 8)(a0) ld s4, (4 * 8)(a0) ld s5, (5 * 8)(a0) ld s6, (6 * 8)(a0) ld s7, (7 * 8)(a0) ld s8, (8 * 8)(a0) ld s9, (9 * 8)(a0) ld s10, (10 * 8)(a0) ld s11, (11 * 8)(a0) ld ra, (12 * 8)(a0) addi a0, a0, (13 * 8) #ifdef __riscv_float_abi_double /* Restore the fpe registers */ fld fs0, (0 * 8)(a0) fld fs1, (1 * 8)(a0) fld fs2, (2 * 8)(a0) fld fs3, (3 * 8)(a0) fld fs4, (4 * 8)(a0) fld fs5, (5 * 8)(a0) fld fs6, (6 * 8)(a0) fld fs7, (7 * 8)(a0) fld fs8, (8 * 8)(a0) fld fs9, (9 * 8)(a0) fld fs10, (10 * 8)(a0) fld fs11, (11 * 8)(a0) addi a0, a0, (12 * 8) #endif /* Load the return value */ mv a0, a1 + bnez a1, 1f + li a0, 1 +1: ret botch: call _C_LABEL(longjmperror) call _C_LABEL(abort) END(longjmp)