[PATCH v3 14/16] riscv/cfi: Add __ssp_sigset_arch_t and use it for both ucontext/jmpbuf

Jesse Huang jesse.huang@sifive.com
Mon Oct 27 04:26:32 GMT 2025


---
 .../sysv/linux/riscv/bits/types/__sigset_t.h  | 43 +++++++++++++++++++
 sysdeps/unix/sysv/linux/riscv/setjmpP.h       | 31 +------------
 sysdeps/unix/sysv/linux/riscv/sys/ucontext.h  |  6 +--
 3 files changed, 47 insertions(+), 33 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/riscv/bits/types/__sigset_t.h

diff --git a/sysdeps/unix/sysv/linux/riscv/bits/types/__sigset_t.h b/sysdeps/unix/sysv/linux/riscv/bits/types/__sigset_t.h
new file mode 100644
index 0000000000..ff04596c3e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/bits/types/__sigset_t.h
@@ -0,0 +1,43 @@
+/* Architecture-specific __sigset_t definition.  RISC-V version.  */
+#ifndef ____sigset_t_defined
+#define ____sigset_t_defined
+
+#define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
+typedef struct
+{
+  unsigned long int __val[_SIGSET_NWORDS];
+} __sigset_t;
+
+#define ALIGN_DOWN(base, size)	((base) & -((__typeof__ (base)) (size)))
+#define ALIGN_UP(base, size)	ALIGN_DOWN ((base) + (size) - 1, (size))
+
+/* Number of bits per long.  */
+#define _SSP_SIGSET_BITS_PER_WORD (8 * sizeof (unsigned long int))
+/* This holds the number of signals, 512 should be sufficient for future.
+   expansion  */
+#define _SSP_SIGSET_NSIG	512
+/* Number of longs to hold all signals.  */
+#define _SSP_SIGSET_NWORDS \
+  (ALIGN_UP (_SSP_SIGSET_NSIG, _SSP_SIGSET_BITS_PER_WORD) \
+   / _SSP_SIGSET_BITS_PER_WORD)
+
+typedef struct
+  {
+    unsigned long int __val[_SSP_SIGSET_NWORDS];
+  } __ssp_sigset_t;
+
+typedef union
+  {
+    __sigset_t __saved_mask_compat;
+    struct
+      {
+	__ssp_sigset_t __saved_mask;
+	/* Used for shadow stack pointer.  NB: Shadow stack pointer
+	   must have the same alignment as __saved_mask.  Otherwise
+	   offset of __saved_mask will be changed.  */
+	unsigned long int __ssp;
+	unsigned long int __ssp_base;
+      } __saved;
+  } __ssp_sigset_arch_t;
+
+#endif
diff --git a/sysdeps/unix/sysv/linux/riscv/setjmpP.h b/sysdeps/unix/sysv/linux/riscv/setjmpP.h
index 3c3d1d4c03..c4dfa7e6db 100644
--- a/sysdeps/unix/sysv/linux/riscv/setjmpP.h
+++ b/sysdeps/unix/sysv/linux/riscv/setjmpP.h
@@ -23,42 +23,13 @@
 #include <libc-pointer-arith.h>
 #include <sigsetops.h>
 
-/* Number of bits per long.  */
-#define _JUMP_BUF_SIGSET_BITS_PER_WORD (8 * sizeof (unsigned long int))
-/* This holds the number of signals, 512 should be sufficient for future.
-   expansion  */
-#define _JUMP_BUF_SIGSET_NSIG	512
-/* Number of longs to hold all signals.  */
-#define _JUMP_BUF_SIGSET_NWORDS \
-  (ALIGN_UP (_JUMP_BUF_SIGSET_NSIG, _JUMP_BUF_SIGSET_BITS_PER_WORD) \
-   / _JUMP_BUF_SIGSET_BITS_PER_WORD)
-
-typedef struct
-  {
-    unsigned long int __val[_JUMP_BUF_SIGSET_NWORDS];
-  } __jmp_buf_sigset_t;
-
-typedef union
-  {
-    __sigset_t __saved_mask_compat;
-    struct
-      {
-	__jmp_buf_sigset_t __saved_mask;
-	/* Used for shadow stack pointer.  NB: Shadow stack pointer
-	   must have the same alignment as __saved_mask.  Otherwise
-	   offset of __saved_mask will be changed.  */
-	unsigned long int __ssp;
-	unsigned long int __ssp_base;
-      } __saved;
-  } __jmpbuf_arch_t;
-
 /* <setjmp/setjmp.h> has
 
    NB: We use setjmp in thread cancellation and this saves the shadow
    stack register, but __libc_unwind_longjmp doesn't restore the shadow
    stack register since cancellation never returns after longjmp.  */
 #undef __sigset_t
-#define __sigset_t __jmpbuf_arch_t
+#define __sigset_t __ssp_sigset_arch_t
 #include <setjmp.h>
 #undef __saved_mask
 #define __saved_mask __saved_mask.__saved.__saved_mask
diff --git a/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h b/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h
index a572ec62ee..fb514c3be2 100644
--- a/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h
+++ b/sysdeps/unix/sysv/linux/riscv/sys/ucontext.h
@@ -23,7 +23,7 @@
 
 #include <features.h>
 
-#include <bits/types/sigset_t.h>
+#include <bits/types/__sigset_t.h>
 #include <bits/types/stack_t.h>
 
 typedef unsigned long int __riscv_mc_gp_state[32];
@@ -90,12 +90,12 @@ typedef struct ucontext_t
     unsigned long int  __uc_flags;
     struct ucontext_t *uc_link;
     stack_t            uc_stack;
-    sigset_t           uc_sigmask;
+    __ssp_sigset_arch_t           uc_sigmask;
     /* There's some padding here to allow sigset_t to be expanded in the
        future.  Though this is unlikely, other architectures put uc_sigmask
        at the end of this structure and explicitly state it can be
        expanded, so we didn't want to box ourselves in here.  */
-    char               __glibc_reserved[1024 / 8 - sizeof (sigset_t)];
+    char               __glibc_reserved[1024 / 8 - sizeof (__ssp_sigset_t)];
     /* We can't put uc_sigmask at the end of this structure because we need
        to be able to expand sigcontext in the future.  For example, the
        vector ISA extension will almost certainly add ISA state.  We want
-- 
2.39.3



More information about the Libc-alpha mailing list