1 /* struct ucontext definition, RISC-V version. 2 Copyright (C) 1997-2022 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 4 5 The GNU C Library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 The GNU C Library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library. If not, see 17 <https://www.gnu.org/licenses/>. */ 18 19 /* Don't rely on this, the interface is currently messed up and may need to 20 be broken to be fixed. */ 21 #ifndef _SYS_UCONTEXT_H 22 #define _SYS_UCONTEXT_H 1 23 24 #include <features.h> 25 26 #include <bits/types/sigset_t.h> 27 #include <bits/types/stack_t.h> 28 29 typedef unsigned long int __riscv_mc_gp_state[32]; 30 31 #ifdef __USE_MISC 32 # define NGREG 32 33 34 # define REG_PC 0 35 # define REG_RA 1 36 # define REG_SP 2 37 # define REG_TP 4 38 # define REG_S0 8 39 # define REG_S1 9 40 # define REG_A0 10 41 # define REG_S2 18 42 # define REG_NARGS 8 43 44 typedef unsigned long int greg_t; 45 46 /* Container for all general registers. */ 47 typedef __riscv_mc_gp_state gregset_t; 48 49 /* Container for floating-point state. */ 50 typedef union __riscv_mc_fp_state fpregset_t; 51 #endif 52 53 struct __riscv_mc_f_ext_state 54 { 55 unsigned int __f[32]; 56 unsigned int __fcsr; 57 }; 58 59 struct __riscv_mc_d_ext_state 60 { 61 unsigned long long int __f[32]; 62 unsigned int __fcsr; 63 }; 64 65 struct __riscv_mc_q_ext_state 66 { 67 unsigned long long int __f[64] __attribute__ ((__aligned__ (16))); 68 unsigned int __fcsr; 69 /* Reserved for expansion of sigcontext structure. Currently zeroed 70 upon signal, and must be zero upon sigreturn. */ 71 unsigned int __glibc_reserved[3]; 72 }; 73 74 union __riscv_mc_fp_state 75 { 76 struct __riscv_mc_f_ext_state __f; 77 struct __riscv_mc_d_ext_state __d; 78 struct __riscv_mc_q_ext_state __q; 79 }; 80 81 typedef struct mcontext_t 82 { 83 __riscv_mc_gp_state __gregs; 84 union __riscv_mc_fp_state __fpregs; 85 } mcontext_t; 86 87 /* Userlevel context. */ 88 typedef struct ucontext_t 89 { 90 unsigned long int __uc_flags; 91 struct ucontext_t *uc_link; 92 stack_t uc_stack; 93 sigset_t uc_sigmask; 94 /* There's some padding here to allow sigset_t to be expanded in the 95 future. Though this is unlikely, other architectures put uc_sigmask 96 at the end of this structure and explicitly state it can be 97 expanded, so we didn't want to box ourselves in here. */ 98 char __glibc_reserved[1024 / 8 - sizeof (sigset_t)]; 99 /* We can't put uc_sigmask at the end of this structure because we need 100 to be able to expand sigcontext in the future. For example, the 101 vector ISA extension will almost certainly add ISA state. We want 102 to ensure all user-visible ISA state can be saved and restored via a 103 ucontext, so we're putting this at the end in order to allow for 104 infinite extensibility. Since we know this will be extended and we 105 assume sigset_t won't be extended an extreme amount, we're 106 prioritizing this. */ 107 mcontext_t uc_mcontext; 108 } ucontext_t; 109 110 #endif /* sys/ucontext.h */ 111