Skip to content

Commit a95cbcc

Browse files
SchrodingerZhuGeorgeARM
authored andcommitted
[libc] implement aarch64 sigsetjmp (llvm#136706)
- **[libc][aarch64] implement sigsetjmp** On top of llvm#136072 See also llvm#137055 for remarks on naked attributes. ```c++ //===-- Implementation of setjmp ------------------------------------------===// // // 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.h" #include "hdr/offsetof_macros.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" #include "src/setjmp/setjmp_impl.h" #include "src/setjmp/sigsetjmp_epilogue.h" namespace LIBC_NAMESPACE_DECL { [[gnu::naked]] LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) { asm(R"( cbz w1, %c[setjmp] str x30, [x0, %c[retaddr]] str x19, [x0, %c[extra]] mov x19, x0 bl %c[setjmp] mov w1, w0 mov x0, x19 ldr x30, [x0, %c[retaddr]] ldr x19, [x0, %c[extra]] b %c[epilogue])" ::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)), [extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp), [epilogue] "i"(sigsetjmp_epilogue) : "x0", "x1", "x19", "x30"); } } // namespace LIBC_NAMESPACE_DECL ```
1 parent cc0f5a8 commit a95cbcc

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ if(LLVM_LIBC_FULL_BUILD)
933933
# setjmp.h entrypoints
934934
libc.src.setjmp.longjmp
935935
libc.src.setjmp.setjmp
936+
libc.src.setjmp.siglongjmp
937+
libc.src.setjmp.sigsetjmp
936938

937939
# stdio.h entrypoints
938940
libc.src.stdio.clearerr

libc/include/llvm-libc-types/jmp_buf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// TODO: implement sigjmp_buf related functions for other architectures
1313
// Issue: https://github.com/llvm/llvm-project/issues/136358
1414
#if defined(__linux__)
15-
#if defined(__i386__) || defined(__x86_64__)
15+
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
1616
#define __LIBC_HAS_SIGJMP_BUF
1717
#endif
1818
#endif

libc/src/setjmp/aarch64/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ add_entrypoint_object(
2626
libc.hdr.types.jmp_buf
2727
${setjmp_config_options}
2828
)
29+
30+
add_entrypoint_object(
31+
sigsetjmp
32+
SRCS
33+
sigsetjmp.cpp
34+
HDRS
35+
../sigsetjmp.h
36+
DEPENDS
37+
libc.hdr.types.jmp_buf
38+
libc.hdr.types.sigset_t
39+
libc.hdr.offsetof_macros
40+
libc.src.setjmp.sigsetjmp_epilogue
41+
libc.src.setjmp.setjmp
42+
)

libc/src/setjmp/aarch64/sigsetjmp.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- Implementation of sigsetjmp ---------------------------------------===//
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.h"
10+
#include "hdr/offsetof_macros.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
#include "src/setjmp/setjmp_impl.h"
14+
#include "src/setjmp/sigsetjmp_epilogue.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
[[gnu::naked]]
18+
LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf, int)) {
19+
asm(R"(
20+
cbz w1, %c[setjmp]
21+
22+
str x30, [x0, %c[retaddr]]
23+
str x19, [x0, %c[extra]]
24+
mov x19, x0
25+
bl %c[setjmp]
26+
27+
mov w1, w0
28+
mov x0, x19
29+
ldr x30, [x0, %c[retaddr]]
30+
ldr x19, [x0, %c[extra]]
31+
b %c[epilogue])" ::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
32+
[extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
33+
[epilogue] "i"(sigsetjmp_epilogue)
34+
: "x0", "x1", "x19", "x30");
35+
}
36+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)