From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id D01C6386EC1B; Wed, 26 Oct 2022 15:18:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D01C6386EC1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666797522; bh=LyS4fbsDs8pt3tMYSsBdDwsWPsXJFmSqTzr7zJL4y8Y=; h=From:To:Subject:Date:From; b=y0D/7wD7h2u0gz+C5Wzd9Pel2YfSKNfzzJcXpRJqhrLNM5hA0DvO76hISLETrVtJ1 JTTxge802JGKSV/HDveVW3qtsaw4JmKjoqCmP7vxVmBIEFy3Zwdn8VQEjmBLh10omB 2EBUeSJLDW+4glWTUIAftz48ZC0MNbNNipvmGzbQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] aarch64: morello: add purecap setjmp/longjmp X-Act-Checkin: glibc X-Git-Author: Carlos Eduardo Seo X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: c892e3eded6fa01b8adcfc837a1bdeb3efcea0c7 X-Git-Newrev: e0a35da9eb4561722a1968a955fea9e05706551f Message-Id: <20221026151842.D01C6386EC1B@sourceware.org> Date: Wed, 26 Oct 2022 15:18:42 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e0a35da9eb4561722a1968a955fea9e05706551f commit e0a35da9eb4561722a1968a955fea9e05706551f Author: Carlos Eduardo Seo Date: Mon Apr 5 17:01:09 2021 -0300 aarch64: morello: add purecap setjmp/longjmp Similar to lp64 setjmp/longjmp, but handles capability registers. Save q regs instead of d regs to simplify the offset computation. Diff: --- sysdeps/aarch64/bits/setjmp.h | 5 +- sysdeps/aarch64/morello/__longjmp.S | 108 ++++++++++++++++++++++++++++++++++++ sysdeps/aarch64/morello/setjmp.S | 64 +++++++++++++++++++++ 3 files changed, 176 insertions(+), 1 deletion(-) diff --git a/sysdeps/aarch64/bits/setjmp.h b/sysdeps/aarch64/bits/setjmp.h index ba3f49246d..9c117fc5ad 100644 --- a/sysdeps/aarch64/bits/setjmp.h +++ b/sysdeps/aarch64/bits/setjmp.h @@ -27,7 +27,10 @@ /* Jump buffer contains: x19-x28, x29(fp), x30(lr), (x31)sp, d8-d15. Other registers are not saved. */ +# ifndef __CHERI_PURE_CAPABILITY__ __extension__ typedef unsigned long long __jmp_buf [22]; - +# else +__extension__ typedef __uintcap_t __jmp_buf [22]; +# endif #endif #endif diff --git a/sysdeps/aarch64/morello/__longjmp.S b/sysdeps/aarch64/morello/__longjmp.S new file mode 100644 index 0000000000..0c1fcb66a4 --- /dev/null +++ b/sysdeps/aarch64/morello/__longjmp.S @@ -0,0 +1,108 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include + +/* __longjmp(jmpbuf, val) */ + +ENTRY (__longjmp) + cfi_def_cfa(c0, 0) + cfi_offset(c19, JB_X19<<4) + cfi_offset(c20, JB_X20<<4) + cfi_offset(c21, JB_X21<<4) + cfi_offset(c22, JB_X22<<4) + cfi_offset(c23, JB_X23<<4) + cfi_offset(c24, JB_X24<<4) + cfi_offset(c25, JB_X25<<4) + cfi_offset(c26, JB_X26<<4) + cfi_offset(c27, JB_X27<<4) + cfi_offset(c28, JB_X28<<4) + cfi_offset(c29, JB_X29<<4) + cfi_offset(c30, JB_LR<<4) + + cfi_offset(q8, JB_D8<<4) + cfi_offset(q9, JB_D9<<4) + cfi_offset(q10, JB_D10<<4) + cfi_offset(q11, JB_D11<<4) + cfi_offset(q12, JB_D12<<4) + cfi_offset(q13, JB_D13<<4) + cfi_offset(q14, JB_D14<<4) + cfi_offset(q15, JB_D15<<4) + + ldp c19, c20, [c0, #JB_X19<<4] + ldp c21, c22, [c0, #JB_X21<<4] + ldp c23, c24, [c0, #JB_X23<<4] + ldp c25, c26, [c0, #JB_X25<<4] + ldp c27, c28, [c0, #JB_X27<<4] + ldp c29, c30, [c0, #JB_X29<<4] + + /* longjmp probe takes 3 arguments, address of jump buffer as + first argument (8@x0), return value as second argument (-4@x1), + and target address (8@x30), respectively. */ + LIBC_PROBE (longjmp, 3, 8@c0, -4@c1, 8@c30) + ldp q8, q9, [c0, #JB_D8<<4] + ldp q10, q11, [c0, #JB_D10<<4] + ldp q12, q13, [c0, #JB_D12<<4] + ldp q14, q15, [c0, #JB_D14<<4] + + /* Originally this was implemented with a series of + .cfi_restore() directives. + + The theory was that cfi_restore should revert to previous + frame value is the same as the current value. In practice + this doesn't work, even after cfi_restore() gdb continues + to try to recover a previous frame value offset from x0, + which gets stuffed after a few more instructions. The + cfi_same_value() mechanism appears to work fine. */ + + cfi_same_value(c19) + cfi_same_value(c20) + cfi_same_value(c21) + cfi_same_value(c22) + cfi_same_value(c23) + cfi_same_value(c24) + cfi_same_value(c25) + cfi_same_value(c26) + cfi_same_value(c27) + cfi_same_value(c28) + cfi_same_value(c29) + cfi_same_value(c30) + cfi_same_value(q8) + cfi_same_value(q9) + cfi_same_value(q10) + cfi_same_value(q11) + cfi_same_value(q12) + cfi_same_value(q13) + cfi_same_value(q14) + cfi_same_value(q15) + + ldr c5, [c0, #JB_SP<<4] + mov csp, c5 + + /* longjmp_target probe takes 3 arguments, address of jump buffer + as first argument (8@x0), return value as second argument (-4@x1), + and target address (8@x30), respectively. */ + LIBC_PROBE (longjmp_target, 3, 8@c0, -4@c1, 8@c30) + cmp x1, #0 + mov x0, #1 + csel x0, x1, x0, ne + /* Use br instead of ret because ret is guaranteed to mispredict */ + br c30 +END (__longjmp) diff --git a/sysdeps/aarch64/morello/setjmp.S b/sysdeps/aarch64/morello/setjmp.S new file mode 100644 index 0000000000..649b428fb2 --- /dev/null +++ b/sysdeps/aarch64/morello/setjmp.S @@ -0,0 +1,64 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include + + /* Keep traditional entry points in with sigsetjmp(). */ +ENTRY (setjmp) + mov x1, #1 + b 1f +END (setjmp) + +ENTRY (_setjmp) + mov x1, #0 + b 1f +END (_setjmp) +libc_hidden_def (_setjmp) + +ENTRY (__sigsetjmp) +1: + stp c19, c20, [c0, #JB_X19<<4] + stp c21, c22, [c0, #JB_X21<<4] + stp c23, c24, [c0, #JB_X23<<4] + stp c25, c26, [c0, #JB_X25<<4] + stp c27, c28, [c0, #JB_X27<<4] + stp c29, c30, [c0, #JB_X29<<4] + + /* setjmp probe takes 3 arguments, address of jump buffer + first argument (8@x0), return value second argument (-4@x1), + and target address (8@x30), respectively. */ + LIBC_PROBE (setjmp, 3, 8@c0, -4@c1, 8@c30) + stp q8, q9, [c0, #JB_D8<<4] + stp q10, q11, [c0, #JB_D10<<4] + stp q12, q13, [c0, #JB_D12<<4] + stp q14, q15, [c0, #JB_D14<<4] + + mov c2, csp + str c2, [c0, #JB_SP<<4] + +#if IS_IN (rtld) + /* In ld.so we never save the signal mask */ + mov w0, #0 + RET +#else + b C_SYMBOL_NAME(__sigjmp_save) +#endif +END (__sigsetjmp) +hidden_def (__sigsetjmp)