|
| 1 | +//===-- Definition of type __jmp_buf --------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef LLVM_LIBC_TYPES___JMP_BUF_H |
| 10 | +#define LLVM_LIBC_TYPES___JMP_BUF_H |
| 11 | + |
| 12 | +// TODO: implement sigjmp_buf related functions for other architectures |
| 13 | +// Issue: https://github.com/llvm/llvm-project/issues/136358 |
| 14 | +#if defined(__linux__) |
| 15 | +#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \ |
| 16 | + defined(__arm__) || defined(__riscv) |
| 17 | +#define __LIBC_HAS_SIGJMP_BUF |
| 18 | +#endif |
| 19 | +#endif |
| 20 | + |
| 21 | +#if defined(__LIBC_HAS_SIGJMP_BUF) |
| 22 | +#include "sigset_t.h" |
| 23 | +#endif |
| 24 | + |
| 25 | +typedef struct { |
| 26 | +#ifdef __x86_64__ |
| 27 | + __UINT64_TYPE__ rbx; |
| 28 | + __UINT64_TYPE__ rbp; |
| 29 | + __UINT64_TYPE__ r12; |
| 30 | + __UINT64_TYPE__ r13; |
| 31 | + __UINT64_TYPE__ r14; |
| 32 | + __UINT64_TYPE__ r15; |
| 33 | + __UINTPTR_TYPE__ rsp; |
| 34 | + __UINTPTR_TYPE__ rip; |
| 35 | +#elif defined(__i386__) |
| 36 | + long ebx; |
| 37 | + long esi; |
| 38 | + long edi; |
| 39 | + long ebp; |
| 40 | + long esp; |
| 41 | + long eip; |
| 42 | +#elif defined(__riscv) |
| 43 | + /* Program counter. */ |
| 44 | + long int __pc; |
| 45 | + /* Callee-saved registers. */ |
| 46 | + long int __regs[12]; |
| 47 | + /* Stack pointer. */ |
| 48 | + long int __sp; |
| 49 | + /* Callee-saved floating point registers. */ |
| 50 | +#if __riscv_float_abi_double |
| 51 | + double __fpregs[12]; |
| 52 | +#elif defined(__riscv_float_abi_single) |
| 53 | +#error "__jmp_buf not available for your target architecture." |
| 54 | +#endif |
| 55 | +#elif defined(__arm__) |
| 56 | + // r4, r5, r6, r7, r8, r9, r10, r11, r12, lr |
| 57 | + long opaque[10]; |
| 58 | +#elif defined(__aarch64__) |
| 59 | + long opaque[14]; // x19-x29, lr, sp, optional x18 |
| 60 | +#if __ARM_FP |
| 61 | + long fopaque[8]; // d8-d15 |
| 62 | +#endif |
| 63 | +#else |
| 64 | +#error "__jmp_buf not available for your target architecture." |
| 65 | +#endif |
| 66 | +#if defined(__LIBC_HAS_SIGJMP_BUF) |
| 67 | + // return address |
| 68 | + void *sig_retaddr; |
| 69 | + // extra register buffer to avoid indefinite stack growth in sigsetjmp |
| 70 | + void *sig_extra; |
| 71 | + // signal masks |
| 72 | + sigset_t sigmask; |
| 73 | +#endif |
| 74 | +} __jmp_buf; |
| 75 | + |
| 76 | +#undef __LIBC_HAS_SIGJMP_BUF |
| 77 | + |
| 78 | +#endif // LLVM_LIBC_TYPES___JMP_BUF_H |
0 commit comments