Skip to content

Commit a325f7f

Browse files
[libc][aarch64] implement sigsetjmp
1 parent f07511a commit a325f7f

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

libc/config/linux/aarch64/entrypoints.txt

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

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct {
5454
#endif
5555
// TODO: implement sigjmp_buf related functions for other architectures
5656
// Issue: https://github.com/llvm/llvm-project/issues/136358
57-
#if defined(__i386__) || defined(__x86_64__)
57+
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
5858
// return address
5959
void *sig_retaddr;
6060
// extra register buffer to avoid indefinite stack growth in sigsetjmp
@@ -66,7 +66,7 @@ typedef struct {
6666

6767
typedef __jmp_buf jmp_buf[1];
6868

69-
#if defined(__i386__) || defined(__x86_64__)
69+
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
7070
typedef __jmp_buf sigjmp_buf[1];
7171
#endif
7272
#endif // LLVM_LIBC_TYPES_JMP_BUF_H

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)