diff --git a/libc/config/darwin/aarch64/config.json b/libc/config/darwin/aarch64/config.json new file mode 100644 index 0000000000000..c82f13e5cbf79 --- /dev/null +++ b/libc/config/darwin/aarch64/config.json @@ -0,0 +1,8 @@ +{ + "setjmp": { + "LIBC_CONF_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER": { + "value": false, + "doc": "Avoid setjmp saving the value of x18, and longjmp restoring it. The Apple AArch64 ABI specifies that this register is reserved and should not be used" + } + } +} diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt index 308fc49d681d7..437eca79a76f6 100644 --- a/libc/config/darwin/aarch64/entrypoints.txt +++ b/libc/config/darwin/aarch64/entrypoints.txt @@ -101,6 +101,17 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdlib.free ) +if(LLVM_LIBC_FULL_BUILD) + list(APPEND TARGET_LIBC_ENTRYPOINTS + # setjmp.h entrypoints + libc.src.setjmp.longjmp + libc.src.setjmp.setjmp + libc.src.setjmp.siglongjmp + libc.src.setjmp.sigsetjmp + ) +endif() + + set(TARGET_LIBM_ENTRYPOINTS # complex.h entrypoints libc.src.complex.creal diff --git a/libc/config/darwin/aarch64/headers.txt b/libc/config/darwin/aarch64/headers.txt index 86e7145972324..8f3d6029c9b6a 100644 --- a/libc/config/darwin/aarch64/headers.txt +++ b/libc/config/darwin/aarch64/headers.txt @@ -7,6 +7,7 @@ set(TARGET_PUBLIC_HEADERS libc.include.inttypes libc.include.limits libc.include.math + libc.include.setjmp libc.include.stdlib libc.include.string libc.include.strings diff --git a/libc/src/setjmp/CMakeLists.txt b/libc/src/setjmp/CMakeLists.txt index 239254fa57dc6..50c827254da65 100644 --- a/libc/src/setjmp/CMakeLists.txt +++ b/libc/src/setjmp/CMakeLists.txt @@ -1,3 +1,9 @@ +# Process architecture-specific subdirectory FIRST to avoid missing targets. +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) +endif() + +# Then process OS-specific subdirectory if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) add_object_library( @@ -8,10 +14,6 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) ) endif() -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) -endif() - add_entrypoint_object( setjmp ALIAS diff --git a/libc/src/setjmp/darwin/CMakeLists.txt b/libc/src/setjmp/darwin/CMakeLists.txt new file mode 100644 index 0000000000000..b844c8c5ee55a --- /dev/null +++ b/libc/src/setjmp/darwin/CMakeLists.txt @@ -0,0 +1,12 @@ +add_object_library( + sigsetjmp_epilogue + HDRS + ../sigsetjmp_epilogue.h + SRCS + sigsetjmp_epilogue.cpp + DEPENDS + libc.src.__support.common + libc.src.__support.OSUtil.osutil + libc.hdr.types.jmp_buf + libc.hdr.types.sigset_t +) diff --git a/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp b/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp new file mode 100644 index 0000000000000..b2ca4d99ed82b --- /dev/null +++ b/libc/src/setjmp/darwin/sigsetjmp_epilogue.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of sigsetjmp_epilogue ------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/setjmp/sigsetjmp_epilogue.h" +#include "src/__support/OSUtil/syscall.h" +#include "src/__support/common.h" +#include "src/signal/sigprocmask.h" + +namespace LIBC_NAMESPACE_DECL { +[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval) { + syscall_impl(sigprocmask, SIG_SETMASK, + /* set= */ retval ? &buffer->sigmask : nullptr, + /* old_set= */ retval ? nullptr : &buffer->sigmask); + return retval; +} +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt index b7c145788c0cd..6dca47b5343e6 100644 --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -62,6 +62,7 @@ add_subdirectory(errno) add_subdirectory(fenv) add_subdirectory(math) add_subdirectory(search) +add_subdirectory(setjmp) add_subdirectory(stdbit) add_subdirectory(stdfix) add_subdirectory(stdio) @@ -92,7 +93,6 @@ add_subdirectory(assert) add_subdirectory(compiler) add_subdirectory(dirent) add_subdirectory(locale) -add_subdirectory(setjmp) add_subdirectory(signal) add_subdirectory(spawn)