diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt index bf85bf69425e..c21236307a91 100644 --- a/libc/hdr/types/CMakeLists.txt +++ b/libc/hdr/types/CMakeLists.txt @@ -319,6 +319,15 @@ add_proxy_header_library( libc.include.setjmp ) +add_proxy_header_library( + sigjmp_buf + HDRS + sigjmp_buf.h + FULL_BUILD_DEPENDS + libc.include.llvm-libc-types.sigjmp_buf + libc.include.setjmp +) + add_proxy_header_library( struct_msghdr HDRS diff --git a/libc/hdr/types/jmp_buf.h b/libc/hdr/types/jmp_buf.h index 3fa1de816d70..b242f84f221f 100644 --- a/libc/hdr/types/jmp_buf.h +++ b/libc/hdr/types/jmp_buf.h @@ -1,4 +1,4 @@ -//===-- Definition of jmp_buf.h ------------------------------------------===// +//===-- Definition of jmp_buf.h -------------------------------------------===// // // Part of the LLVM Project, under the Apahce License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/libc/hdr/types/sigjmp_buf.h b/libc/hdr/types/sigjmp_buf.h new file mode 100644 index 000000000000..5da52435dcb6 --- /dev/null +++ b/libc/hdr/types/sigjmp_buf.h @@ -0,0 +1,22 @@ +//===-- Definition of sigjmp_buf.h ----------------------------------------===// +// +// Part of the LLVM Project, under the Apahce License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_HDR_TYPES_SIGJMP_BUF_H +#define LLVM_LIBC_HDR_TYPES_SIGJMP_BUF_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-types/sigjmp_buf.h" + +#else // overlay mode + +#include + +#endif // LLVM_LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_TYPES_SIGJMP_BUF_H diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt index fafc1377926c..120f3850b5ce 100644 --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -215,6 +215,7 @@ add_header_macro( DEPENDS .llvm_libc_common_h .llvm-libc-types.jmp_buf + .llvm-libc-types.sigjmp_buf ) add_header_macro( diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt index b24c97301668..4ccdde619a39 100644 --- a/libc/include/llvm-libc-types/CMakeLists.txt +++ b/libc/include/llvm-libc-types/CMakeLists.txt @@ -82,7 +82,9 @@ add_header(union_sigval HDR union_sigval.h) add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t .clock_t) add_header(sig_atomic_t HDR sig_atomic_t.h) add_header(sigset_t HDR sigset_t.h DEPENDS libc.include.llvm-libc-macros.signal_macros) -add_header(jmp_buf HDR jmp_buf.h DEPENDS .sigset_t) +add_header(__jmp_buf HDR __jmp_buf.h DEPENDS .sigset_t) +add_header(jmp_buf HDR jmp_buf.h DEPENDS .__jmp_buf) +add_header(sigjmp_buf HDR sigjmp_buf.h DEPENDS .__jmp_buf) add_header(struct_sigaction HDR struct_sigaction.h DEPENDS .sigset_t .siginfo_t) add_header(struct_timespec HDR struct_timespec.h DEPENDS .time_t) add_header( diff --git a/libc/include/llvm-libc-types/__jmp_buf.h b/libc/include/llvm-libc-types/__jmp_buf.h new file mode 100644 index 000000000000..a80afa2e6b81 --- /dev/null +++ b/libc/include/llvm-libc-types/__jmp_buf.h @@ -0,0 +1,78 @@ +//===-- Definition of type __jmp_buf --------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TYPES___JMP_BUF_H +#define LLVM_LIBC_TYPES___JMP_BUF_H + +// TODO: implement sigjmp_buf related functions for other architectures +// Issue: https://github.com/llvm/llvm-project/issues/136358 +#if defined(__linux__) +#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \ + defined(__arm__) || defined(__riscv) +#define __LIBC_HAS_SIGJMP_BUF +#endif +#endif + +#if defined(__LIBC_HAS_SIGJMP_BUF) +#include "sigset_t.h" +#endif + +typedef struct { +#ifdef __x86_64__ + __UINT64_TYPE__ rbx; + __UINT64_TYPE__ rbp; + __UINT64_TYPE__ r12; + __UINT64_TYPE__ r13; + __UINT64_TYPE__ r14; + __UINT64_TYPE__ r15; + __UINTPTR_TYPE__ rsp; + __UINTPTR_TYPE__ rip; +#elif defined(__i386__) + long ebx; + long esi; + long edi; + long ebp; + long esp; + long eip; +#elif defined(__riscv) + /* Program counter. */ + long int __pc; + /* Callee-saved registers. */ + long int __regs[12]; + /* Stack pointer. */ + long int __sp; + /* Callee-saved floating point registers. */ +#if __riscv_float_abi_double + double __fpregs[12]; +#elif defined(__riscv_float_abi_single) +#error "__jmp_buf not available for your target architecture." +#endif +#elif defined(__arm__) + // r4, r5, r6, r7, r8, r9, r10, r11, r12, lr + long opaque[10]; +#elif defined(__aarch64__) + long opaque[14]; // x19-x29, lr, sp, optional x18 +#if __ARM_FP + long fopaque[8]; // d8-d15 +#endif +#else +#error "__jmp_buf not available for your target architecture." +#endif +#if defined(__LIBC_HAS_SIGJMP_BUF) + // return address + void *sig_retaddr; + // extra register buffer to avoid indefinite stack growth in sigsetjmp + void *sig_extra; + // signal masks + sigset_t sigmask; +#endif +} __jmp_buf; + +#undef __LIBC_HAS_SIGJMP_BUF + +#endif // LLVM_LIBC_TYPES___JMP_BUF_H diff --git a/libc/include/llvm-libc-types/jmp_buf.h b/libc/include/llvm-libc-types/jmp_buf.h index 8a7d2839e21d..599310f95b3c 100644 --- a/libc/include/llvm-libc-types/jmp_buf.h +++ b/libc/include/llvm-libc-types/jmp_buf.h @@ -9,76 +9,8 @@ #ifndef LLVM_LIBC_TYPES_JMP_BUF_H #define LLVM_LIBC_TYPES_JMP_BUF_H -// TODO: implement sigjmp_buf related functions for other architectures -// Issue: https://github.com/llvm/llvm-project/issues/136358 -#if defined(__linux__) -#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \ - defined(__arm__) || defined(__riscv) -#define __LIBC_HAS_SIGJMP_BUF -#endif -#endif - -#if defined(__LIBC_HAS_SIGJMP_BUF) -#include "sigset_t.h" -#endif - -typedef struct { -#ifdef __x86_64__ - __UINT64_TYPE__ rbx; - __UINT64_TYPE__ rbp; - __UINT64_TYPE__ r12; - __UINT64_TYPE__ r13; - __UINT64_TYPE__ r14; - __UINT64_TYPE__ r15; - __UINTPTR_TYPE__ rsp; - __UINTPTR_TYPE__ rip; -#elif defined(__i386__) - long ebx; - long esi; - long edi; - long ebp; - long esp; - long eip; -#elif defined(__riscv) - /* Program counter. */ - long int __pc; - /* Callee-saved registers. */ - long int __regs[12]; - /* Stack pointer. */ - long int __sp; - /* Callee-saved floating point registers. */ -#if __riscv_float_abi_double - double __fpregs[12]; -#elif defined(__riscv_float_abi_single) -#error "__jmp_buf not available for your target architecture." -#endif -#elif defined(__arm__) - // r4, r5, r6, r7, r8, r9, r10, r11, r12, lr - long opaque[10]; -#elif defined(__aarch64__) - long opaque[14]; // x19-x29, lr, sp, optional x18 -#if __ARM_FP - long fopaque[8]; // d8-d15 -#endif -#else -#error "__jmp_buf not available for your target architecture." -#endif -#if defined(__LIBC_HAS_SIGJMP_BUF) - // return address - void *sig_retaddr; - // extra register buffer to avoid indefinite stack growth in sigsetjmp - void *sig_extra; - // signal masks - sigset_t sigmask; -#endif -} __jmp_buf; +#include "__jmp_buf.h" typedef __jmp_buf jmp_buf[1]; -#if defined(__LIBC_HAS_SIGJMP_BUF) -typedef __jmp_buf sigjmp_buf[1]; -#endif - -#undef __LIBC_HAS_SIGJMP_BUF - #endif // LLVM_LIBC_TYPES_JMP_BUF_H diff --git a/libc/include/llvm-libc-types/sigjmp_buf.h b/libc/include/llvm-libc-types/sigjmp_buf.h new file mode 100644 index 000000000000..ae9028b188f1 --- /dev/null +++ b/libc/include/llvm-libc-types/sigjmp_buf.h @@ -0,0 +1,16 @@ +//===-- Definition of type sigjmp_buf -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TYPES_SIGJMP_BUF_H +#define LLVM_LIBC_TYPES_SIGJMP_BUF_H + +#include "__jmp_buf.h" + +typedef __jmp_buf sigjmp_buf[1]; + +#endif // LLVM_LIBC_TYPES_SIGJMP_BUF_H diff --git a/libc/src/setjmp/aarch64/CMakeLists.txt b/libc/src/setjmp/aarch64/CMakeLists.txt index 1078af8ce04f..12991101b0fd 100644 --- a/libc/src/setjmp/aarch64/CMakeLists.txt +++ b/libc/src/setjmp/aarch64/CMakeLists.txt @@ -34,7 +34,7 @@ add_entrypoint_object( HDRS ../sigsetjmp.h DEPENDS - libc.hdr.types.jmp_buf + libc.hdr.types.sigjmp_buf libc.hdr.types.sigset_t libc.hdr.offsetof_macros libc.src.setjmp.sigsetjmp_epilogue diff --git a/libc/src/setjmp/arm/CMakeLists.txt b/libc/src/setjmp/arm/CMakeLists.txt index 77f8471c06bb..7a48da3d29e0 100644 --- a/libc/src/setjmp/arm/CMakeLists.txt +++ b/libc/src/setjmp/arm/CMakeLists.txt @@ -16,7 +16,7 @@ if (TARGET libc.src.setjmp.sigsetjmp_epilogue) HDRS ../sigsetjmp.h DEPENDS - libc.hdr.types.jmp_buf + libc.hdr.types.sigjmp_buf libc.hdr.types.sigset_t libc.hdr.offsetof_macros libc.src.setjmp.sigsetjmp_epilogue diff --git a/libc/src/setjmp/darwin/CMakeLists.txt b/libc/src/setjmp/darwin/CMakeLists.txt index b844c8c5ee55..62acec0fa7fd 100644 --- a/libc/src/setjmp/darwin/CMakeLists.txt +++ b/libc/src/setjmp/darwin/CMakeLists.txt @@ -7,6 +7,6 @@ add_object_library( DEPENDS libc.src.__support.common libc.src.__support.OSUtil.osutil - libc.hdr.types.jmp_buf + libc.hdr.types.sigjmp_buf libc.hdr.types.sigset_t ) diff --git a/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp b/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp index b2ca4d99ed82..568545a20c50 100644 --- a/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp +++ b/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp @@ -12,7 +12,7 @@ #include "src/signal/sigprocmask.h" namespace LIBC_NAMESPACE_DECL { -[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval) { +[[gnu::returns_twice]] int sigsetjmp_epilogue(sigjmp_buf buffer, int retval) { syscall_impl(sigprocmask, SIG_SETMASK, /* set= */ retval ? &buffer->sigmask : nullptr, /* old_set= */ retval ? nullptr : &buffer->sigmask); diff --git a/libc/src/setjmp/linux/CMakeLists.txt b/libc/src/setjmp/linux/CMakeLists.txt index b844c8c5ee55..62acec0fa7fd 100644 --- a/libc/src/setjmp/linux/CMakeLists.txt +++ b/libc/src/setjmp/linux/CMakeLists.txt @@ -7,6 +7,6 @@ add_object_library( DEPENDS libc.src.__support.common libc.src.__support.OSUtil.osutil - libc.hdr.types.jmp_buf + libc.hdr.types.sigjmp_buf libc.hdr.types.sigset_t ) diff --git a/libc/src/setjmp/linux/sigsetjmp_epilogue.cpp b/libc/src/setjmp/linux/sigsetjmp_epilogue.cpp index 4718623c488e..7e1431229745 100644 --- a/libc/src/setjmp/linux/sigsetjmp_epilogue.cpp +++ b/libc/src/setjmp/linux/sigsetjmp_epilogue.cpp @@ -12,7 +12,7 @@ #include // For syscall numbers. namespace LIBC_NAMESPACE_DECL { -[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval) { +[[gnu::returns_twice]] int sigsetjmp_epilogue(sigjmp_buf buffer, int retval) { // If set is NULL, then the signal mask is unchanged (i.e., how is // ignored), but the current value of the signal mask is nevertheless // returned in oldset (if it is not NULL). diff --git a/libc/src/setjmp/riscv/CMakeLists.txt b/libc/src/setjmp/riscv/CMakeLists.txt index 1959e9c905e2..ee3ea28c47a0 100644 --- a/libc/src/setjmp/riscv/CMakeLists.txt +++ b/libc/src/setjmp/riscv/CMakeLists.txt @@ -19,7 +19,7 @@ if (TARGET libc.src.setjmp.sigsetjmp_epilogue) HDRS ../sigsetjmp.h DEPENDS - libc.hdr.types.jmp_buf + libc.hdr.types.sigjmp_buf libc.hdr.types.sigset_t libc.hdr.offsetof_macros libc.src.setjmp.sigsetjmp_epilogue diff --git a/libc/src/setjmp/sigsetjmp.h b/libc/src/setjmp/sigsetjmp.h index ef060c8b344a..6e08bd6a11e8 100644 --- a/libc/src/setjmp/sigsetjmp.h +++ b/libc/src/setjmp/sigsetjmp.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H #define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H -#include "hdr/types/jmp_buf.h" +#include "hdr/types/sigjmp_buf.h" #include "src/__support/macros/config.h" #include "src/__support/macros/properties/compiler.h" diff --git a/libc/src/setjmp/sigsetjmp_epilogue.h b/libc/src/setjmp/sigsetjmp_epilogue.h index 88702b743940..7508d4a1ec03 100644 --- a/libc/src/setjmp/sigsetjmp_epilogue.h +++ b/libc/src/setjmp/sigsetjmp_epilogue.h @@ -9,11 +9,11 @@ #ifndef LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H #define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H -#include "hdr/types/jmp_buf.h" +#include "hdr/types/sigjmp_buf.h" #include "src/__support/common.h" namespace LIBC_NAMESPACE_DECL { -[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval); +[[gnu::returns_twice]] int sigsetjmp_epilogue(sigjmp_buf buffer, int retval); } // namespace LIBC_NAMESPACE_DECL #endif // LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H diff --git a/libc/src/setjmp/x86_64/CMakeLists.txt b/libc/src/setjmp/x86_64/CMakeLists.txt index 03ed5fb64708..5f87bc6cbbbf 100644 --- a/libc/src/setjmp/x86_64/CMakeLists.txt +++ b/libc/src/setjmp/x86_64/CMakeLists.txt @@ -16,7 +16,7 @@ if (TARGET libc.src.setjmp.sigsetjmp_epilogue) HDRS ../sigsetjmp.h DEPENDS - libc.hdr.types.jmp_buf + libc.hdr.types.sigjmp_buf libc.hdr.types.sigset_t libc.hdr.offsetof_macros libc.src.setjmp.sigsetjmp_epilogue