public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/arm/morello/main] aarch64: morello: add purecap setjmp/longjmp
Date: Fri,  5 Aug 2022 19:36:00 +0000 (GMT)	[thread overview]
Message-ID: <20220805193600.A9FCD3857363@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=89ab8ac121e965114df668dadd79ac731a3c0a78

commit 89ab8ac121e965114df668dadd79ac731a3c0a78
Author: Carlos Eduardo Seo <carlos.seo@arm.com>
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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <jmpbuf-offsets.h>
+#include <stap-probe.h>
+
+/* __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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <jmpbuf-offsets.h>
+#include <stap-probe.h>
+
+        /* 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)


             reply	other threads:[~2022-08-05 19:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 19:36 Szabolcs Nagy [this message]
2022-10-26 15:18 Szabolcs Nagy
2022-10-27 13:57 Szabolcs Nagy
2022-11-23 14:47 Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220805193600.A9FCD3857363@sourceware.org \
    --to=nsz@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).