Skip to content

Commit 5645d67

Browse files
authored
Implement sigsetjmp and siglongjmp for darwin/aarch64 (#139555)
1 parent 83381ba commit 5645d67

File tree

7 files changed

+60
-5
lines changed

7 files changed

+60
-5
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"setjmp": {
3+
"LIBC_CONF_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER": {
4+
"value": false,
5+
"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"
6+
}
7+
}
8+
}

libc/config/darwin/aarch64/entrypoints.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ set(TARGET_LIBC_ENTRYPOINTS
101101
libc.src.stdlib.free
102102
)
103103

104+
if(LLVM_LIBC_FULL_BUILD)
105+
list(APPEND TARGET_LIBC_ENTRYPOINTS
106+
# setjmp.h entrypoints
107+
libc.src.setjmp.longjmp
108+
libc.src.setjmp.setjmp
109+
libc.src.setjmp.siglongjmp
110+
libc.src.setjmp.sigsetjmp
111+
)
112+
endif()
113+
114+
104115
set(TARGET_LIBM_ENTRYPOINTS
105116
# complex.h entrypoints
106117
libc.src.complex.creal

libc/config/darwin/aarch64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(TARGET_PUBLIC_HEADERS
77
libc.include.inttypes
88
libc.include.limits
99
libc.include.math
10+
libc.include.setjmp
1011
libc.include.stdlib
1112
libc.include.string
1213
libc.include.strings

libc/src/setjmp/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Process architecture-specific subdirectory FIRST to avoid missing targets.
2+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
3+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
4+
endif()
5+
6+
# Then process OS-specific subdirectory
17
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
28
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
39
add_object_library(
@@ -8,10 +14,6 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
814
)
915
endif()
1016

11-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
12-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
13-
endif()
14-
1517
add_entrypoint_object(
1618
setjmp
1719
ALIAS

libc/src/setjmp/darwin/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_object_library(
2+
sigsetjmp_epilogue
3+
HDRS
4+
../sigsetjmp_epilogue.h
5+
SRCS
6+
sigsetjmp_epilogue.cpp
7+
DEPENDS
8+
libc.src.__support.common
9+
libc.src.__support.OSUtil.osutil
10+
libc.hdr.types.jmp_buf
11+
libc.hdr.types.sigset_t
12+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of sigsetjmp_epilogue ------------------------------===//
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+
#include "src/setjmp/sigsetjmp_epilogue.h"
10+
#include "src/__support/OSUtil/syscall.h"
11+
#include "src/__support/common.h"
12+
#include "src/signal/sigprocmask.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval) {
16+
syscall_impl<long>(sigprocmask, SIG_SETMASK,
17+
/* set= */ retval ? &buffer->sigmask : nullptr,
18+
/* old_set= */ retval ? nullptr : &buffer->sigmask);
19+
return retval;
20+
}
21+
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ add_subdirectory(errno)
6262
add_subdirectory(fenv)
6363
add_subdirectory(math)
6464
add_subdirectory(search)
65+
add_subdirectory(setjmp)
6566
add_subdirectory(stdbit)
6667
add_subdirectory(stdfix)
6768
add_subdirectory(stdio)
@@ -92,7 +93,6 @@ add_subdirectory(assert)
9293
add_subdirectory(compiler)
9394
add_subdirectory(dirent)
9495
add_subdirectory(locale)
95-
add_subdirectory(setjmp)
9696
add_subdirectory(signal)
9797
add_subdirectory(spawn)
9898

0 commit comments

Comments
 (0)