glibc (2.38)

(root)/
include/
sys/
ucontext.h
       1  /* Copyright (C) 2001-2023 Free Software Foundation, Inc.
       2     This file is part of the GNU C Library.
       3  
       4     The GNU C Library is free software; you can redistribute it and/or
       5     modify it under the terms of the GNU Lesser General Public
       6     License as published by the Free Software Foundation; either
       7     version 2.1 of the License, or (at your option) any later version.
       8  
       9     The GNU C Library is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12     Lesser General Public License for more details.
      13  
      14     You should have received a copy of the GNU Lesser General Public
      15     License along with the GNU C Library; if not, see
      16     <https://www.gnu.org/licenses/>.  */
      17  
      18  #ifndef _SYS_UCONTEXT_H
      19  #define _SYS_UCONTEXT_H	1
      20  
      21  #include <features.h>
      22  
      23  #include <bits/types.h>
      24  #include <bits/types/sigset_t.h>
      25  #include <bits/types/stack_t.h>
      26  
      27  
      28  #ifdef __USE_MISC
      29  # define __ctx(fld) fld
      30  #else
      31  # define __ctx(fld) __ ## fld
      32  #endif
      33  
      34  #ifdef __x86_64__
      35  
      36  /* Type for general register.  */
      37  __extension__ typedef long long int greg_t;
      38  
      39  /* Number of general registers.  */
      40  #define __NGREG	23
      41  #ifdef __USE_MISC
      42  # define NGREG	__NGREG
      43  #endif
      44  
      45  /* Container for all general registers.  */
      46  typedef greg_t gregset_t[__NGREG];
      47  
      48  #ifdef __USE_GNU
      49  /* Number of each register in the `gregset_t' array.  */
      50  enum
      51  {
      52    REG_R8 = 0,
      53  # define REG_R8		REG_R8
      54    REG_R9,
      55  # define REG_R9		REG_R9
      56    REG_R10,
      57  # define REG_R10	REG_R10
      58    REG_R11,
      59  # define REG_R11	REG_R11
      60    REG_R12,
      61  # define REG_R12	REG_R12
      62    REG_R13,
      63  # define REG_R13	REG_R13
      64    REG_R14,
      65  # define REG_R14	REG_R14
      66    REG_R15,
      67  # define REG_R15	REG_R15
      68    REG_RDI,
      69  # define REG_RDI	REG_RDI
      70    REG_RSI,
      71  # define REG_RSI	REG_RSI
      72    REG_RBP,
      73  # define REG_RBP	REG_RBP
      74    REG_RBX,
      75  # define REG_RBX	REG_RBX
      76    REG_RDX,
      77  # define REG_RDX	REG_RDX
      78    REG_RAX,
      79  # define REG_RAX	REG_RAX
      80    REG_RCX,
      81  # define REG_RCX	REG_RCX
      82    REG_RSP,
      83  # define REG_RSP	REG_RSP
      84    REG_RIP,
      85  # define REG_RIP	REG_RIP
      86    REG_EFL,
      87  # define REG_EFL	REG_EFL
      88    REG_CSGSFS,		/* Actually short cs, gs, fs, __pad0.  */
      89  # define REG_CSGSFS	REG_CSGSFS
      90    REG_ERR,
      91  # define REG_ERR	REG_ERR
      92    REG_TRAPNO,
      93  # define REG_TRAPNO	REG_TRAPNO
      94    REG_OLDMASK,
      95  # define REG_OLDMASK	REG_OLDMASK
      96    REG_CR2
      97  # define REG_CR2	REG_CR2
      98  };
      99  #endif
     100  
     101  struct _libc_fpxreg
     102  {
     103    unsigned short int __ctx(significand)[4];
     104    unsigned short int __ctx(exponent);
     105    unsigned short int __glibc_reserved1[3];
     106  };
     107  
     108  struct _libc_xmmreg
     109  {
     110    __uint32_t	__ctx(element)[4];
     111  };
     112  
     113  struct _libc_fpstate
     114  {
     115    /* 64-bit FXSAVE format.  */
     116    __uint16_t		__ctx(cwd);
     117    __uint16_t		__ctx(swd);
     118    __uint16_t		__ctx(ftw);
     119    __uint16_t		__ctx(fop);
     120    __uint64_t		__ctx(rip);
     121    __uint64_t		__ctx(rdp);
     122    __uint32_t		__ctx(mxcsr);
     123    __uint32_t		__ctx(mxcr_mask);
     124    struct _libc_fpxreg	_st[8];
     125    struct _libc_xmmreg	_xmm[16];
     126    __uint32_t		__glibc_reserved1[24];
     127  };
     128  
     129  /* Structure to describe FPU registers.  */
     130  typedef struct _libc_fpstate *fpregset_t;
     131  
     132  /* Context to describe whole processor state.  */
     133  typedef struct
     134    {
     135      gregset_t __ctx(gregs);
     136      /* Note that fpregs is a pointer.  */
     137      fpregset_t __ctx(fpregs);
     138      __extension__ unsigned long long __reserved1 [8];
     139  } mcontext_t;
     140  
     141  /* Userlevel context.  */
     142  typedef struct ucontext_t
     143    {
     144      unsigned long int __ctx(uc_flags);
     145      struct ucontext_t *uc_link;
     146      stack_t uc_stack;
     147      mcontext_t uc_mcontext;
     148      sigset_t uc_sigmask;
     149      struct _libc_fpstate __fpregs_mem;
     150      __extension__ unsigned long long int __ssp[4];
     151    } ucontext_t;
     152  
     153  #else /* !__x86_64__ */
     154  
     155  /* Type for general register.  */
     156  typedef int greg_t;
     157  
     158  /* Number of general registers.  */
     159  #define __NGREG	19
     160  #ifdef __USE_MISC
     161  # define NGREG	__NGREG
     162  #endif
     163  
     164  /* Container for all general registers.  */
     165  typedef greg_t gregset_t[__NGREG];
     166  
     167  #ifdef __USE_GNU
     168  /* Number of each register is the `gregset_t' array.  */
     169  enum
     170  {
     171    REG_GS = 0,
     172  # define REG_GS		REG_GS
     173    REG_FS,
     174  # define REG_FS		REG_FS
     175    REG_ES,
     176  # define REG_ES		REG_ES
     177    REG_DS,
     178  # define REG_DS		REG_DS
     179    REG_EDI,
     180  # define REG_EDI	REG_EDI
     181    REG_ESI,
     182  # define REG_ESI	REG_ESI
     183    REG_EBP,
     184  # define REG_EBP	REG_EBP
     185    REG_ESP,
     186  # define REG_ESP	REG_ESP
     187    REG_EBX,
     188  # define REG_EBX	REG_EBX
     189    REG_EDX,
     190  # define REG_EDX	REG_EDX
     191    REG_ECX,
     192  # define REG_ECX	REG_ECX
     193    REG_EAX,
     194  # define REG_EAX	REG_EAX
     195    REG_TRAPNO,
     196  # define REG_TRAPNO	REG_TRAPNO
     197    REG_ERR,
     198  # define REG_ERR	REG_ERR
     199    REG_EIP,
     200  # define REG_EIP	REG_EIP
     201    REG_CS,
     202  # define REG_CS		REG_CS
     203    REG_EFL,
     204  # define REG_EFL	REG_EFL
     205    REG_UESP,
     206  # define REG_UESP	REG_UESP
     207    REG_SS
     208  # define REG_SS	REG_SS
     209  };
     210  #endif
     211  
     212  /* Definitions taken from the kernel headers.  */
     213  struct _libc_fpreg
     214  {
     215    unsigned short int __ctx(significand)[4];
     216    unsigned short int __ctx(exponent);
     217  };
     218  
     219  struct _libc_fpstate
     220  {
     221    unsigned long int __ctx(cw);
     222    unsigned long int __ctx(sw);
     223    unsigned long int __ctx(tag);
     224    unsigned long int __ctx(ipoff);
     225    unsigned long int __ctx(cssel);
     226    unsigned long int __ctx(dataoff);
     227    unsigned long int __ctx(datasel);
     228    struct _libc_fpreg _st[8];
     229    unsigned long int __ctx(status);
     230  };
     231  
     232  /* Structure to describe FPU registers.  */
     233  typedef struct _libc_fpstate *fpregset_t;
     234  
     235  /* Context to describe whole processor state.  */
     236  typedef struct
     237    {
     238      gregset_t __ctx(gregs);
     239      /* Due to Linux's history we have to use a pointer here.  The SysV/i386
     240         ABI requires a struct with the values.  */
     241      fpregset_t __ctx(fpregs);
     242      unsigned long int __ctx(oldmask);
     243      unsigned long int __ctx(cr2);
     244    } mcontext_t;
     245  
     246  /* Userlevel context.  */
     247  typedef struct ucontext_t
     248    {
     249      unsigned long int __ctx(uc_flags);
     250      struct ucontext_t *uc_link;
     251      stack_t uc_stack;
     252      mcontext_t uc_mcontext;
     253      sigset_t uc_sigmask;
     254      struct _libc_fpstate __fpregs_mem;
     255      unsigned long int __ssp[4];
     256    } ucontext_t;
     257  
     258  #endif /* !__x86_64__ */
     259  
     260  #undef __ctx
     261  
     262  #endif /* sys/ucontext.h */