Skip to content

Commit 3d7af09

Browse files
authored
[libc] Add proxy header for the jmp_buf type (#107712)
Added proxy header for the jmp_buf type and changed all use instances from __jmp_buf * to the typedef alias jmp_buf , fixed the link to LLVM in stack_t.h description
1 parent 1cc4c87 commit 3d7af09

File tree

18 files changed

+57
-33
lines changed

18 files changed

+57
-33
lines changed

libc/hdr/types/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,12 @@ add_proxy_header_library(
190190
libc.include.signal
191191
)
192192

193+
add_proxy_header_library(
194+
jmp_buf
195+
HDRS
196+
jmp_buf.h
197+
FULL_BUILD_DEPENDS
198+
libc.include.llvm-libc-types.jmp_buf
199+
libc.include.setjmp
200+
)
201+

libc/hdr/types/jmp_buf.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of jmp_buf.h ------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apahce 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+
#ifndef LLVM_LIBC_HDR_JMP_BUF_H
10+
#define LLVM_LIBC_HDR_JMP_BUF_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/jmp_buf.h"
15+
16+
#else // overlay mode
17+
18+
#include <setjmp.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_TYPES_JMP_BUF_H

libc/hdr/types/stack_t.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//===-- Definition of stack_t.h -------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4-
// See https:llvm.or/LICENSE.txt for license information.
4+
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//

libc/src/setjmp/aarch64/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ add_entrypoint_object(
1212
HDRS
1313
../setjmp_impl.h
1414
DEPENDS
15-
libc.include.setjmp
15+
libc.hdr.types.jmp_buf
1616
${setjmp_config_options}
1717
)
1818

@@ -23,6 +23,6 @@ add_entrypoint_object(
2323
HDRS
2424
../longjmp.h
2525
DEPENDS
26-
libc.include.setjmp
26+
libc.hdr.types.jmp_buf
2727
${setjmp_config_options}
2828
)

libc/src/setjmp/aarch64/longjmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace LIBC_NAMESPACE_DECL {
2323
// them.)
2424

2525
[[gnu::naked]] LLVM_LIBC_FUNCTION(void, longjmp,
26-
([[maybe_unused]] __jmp_buf * buf,
26+
([[maybe_unused]] jmp_buf buf,
2727
[[maybe_unused]] int val)) {
2828
// If BTI branch protection is in use, the compiler will automatically insert
2929
// a BTI here, so we don't need to make any extra effort to do so.

libc/src/setjmp/aarch64/setjmp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
namespace LIBC_NAMESPACE_DECL {
1414

15-
[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp,
16-
([[maybe_unused]] __jmp_buf * buf)) {
15+
[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp, ([[maybe_unused]] jmp_buf buf)) {
1716
// If BTI branch protection is in use, the compiler will automatically insert
1817
// a BTI here, so we don't need to make any extra effort to do so.
1918

libc/src/setjmp/arm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_entrypoint_object(
55
HDRS
66
../setjmp_impl.h
77
DEPENDS
8-
libc.include.setjmp
8+
libc.hdr.types.jmp_buf
99
)
1010

1111
add_entrypoint_object(
@@ -15,5 +15,5 @@ add_entrypoint_object(
1515
HDRS
1616
../longjmp.h
1717
DEPENDS
18-
libc.include.setjmp
18+
libc.hdr.types.jmp_buf
1919
)

libc/src/setjmp/arm/longjmp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ namespace LIBC_NAMESPACE_DECL {
1515

1616
#if defined(__thumb__) && __ARM_ARCH_ISA_THUMB == 1
1717

18-
[[gnu::naked, gnu::target("thumb")]]
19-
LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
18+
[[gnu::naked, gnu::target("thumb")]] LLVM_LIBC_FUNCTION(void, longjmp,
19+
(jmp_buf buf,
20+
int val)) {
2021
asm(R"(
2122
# Reload r4, r5, r6, r7.
2223
ldmia r0!, {r4-r7}
@@ -53,8 +54,7 @@ LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
5354
// TODO(https://github.com/llvm/llvm-project/issues/94061): fp registers
5455
// (d0-d16)
5556
// TODO(https://github.com/llvm/llvm-project/issues/94062): pac+bti
56-
[[gnu::naked]]
57-
LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
57+
[[gnu::naked]] LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
5858
asm(R"(
5959
# While sp may appear in a register list for ARM mode, it may not for
6060
# Thumb2 mode. Just load the previous value of sp into r12 then move it

libc/src/setjmp/arm/setjmp.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace LIBC_NAMESPACE_DECL {
1414

1515
#if defined(__thumb__) && __ARM_ARCH_ISA_THUMB == 1
1616

17-
[[gnu::naked, gnu::target("thumb")]]
18-
LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
17+
[[gnu::naked, gnu::target("thumb")]] LLVM_LIBC_FUNCTION(int, setjmp,
18+
(jmp_buf buf)) {
1919
asm(R"(
2020
# Store r4, r5, r6, and r7 into buf.
2121
stmia r0!, {r4-r7}
@@ -44,8 +44,7 @@ LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
4444
// TODO(https://github.com/llvm/llvm-project/issues/94061): fp registers
4545
// (d0-d16)
4646
// TODO(https://github.com/llvm/llvm-project/issues/94062): pac+bti
47-
[[gnu::naked]]
48-
LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
47+
[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
4948
asm(R"(
5049
# While sp may appear in a register list for ARM mode, it may not for
5150
# Thumb2 mode. Just move it into r12 then stm that, so that this code

libc/src/setjmp/longjmp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#ifndef LLVM_LIBC_SRC_SETJMP_LONGJMP_H
1010
#define LLVM_LIBC_SRC_SETJMP_LONGJMP_H
1111

12+
#include "hdr/types/jmp_buf.h"
1213
#include "src/__support/macros/config.h"
13-
#include <setjmp.h>
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

17-
void longjmp(__jmp_buf *buf, int val);
17+
void longjmp(jmp_buf buf, int val);
1818

1919
} // namespace LIBC_NAMESPACE_DECL
2020

libc/src/setjmp/riscv/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_entrypoint_object(
55
HDRS
66
../setjmp_impl.h
77
DEPENDS
8-
libc.include.setjmp
8+
libc.hdr.types.jmp_buf
99
COMPILE_OPTIONS
1010
-O3
1111
-fomit-frame-pointer
@@ -18,7 +18,7 @@ add_entrypoint_object(
1818
HDRS
1919
../longjmp.h
2020
DEPENDS
21-
libc.include.setjmp
21+
libc.hdr.types.jmp_buf
2222
COMPILE_OPTIONS
2323
-O3
2424
-fomit-frame-pointer

libc/src/setjmp/riscv/longjmp.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "src/__support/macros/config.h"
1212
#include "src/__support/macros/properties/architectures.h"
1313

14-
#include <setjmp.h>
15-
1614
#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
1715
#error "Invalid file include"
1816
#endif
@@ -30,7 +28,7 @@
3028

3129
namespace LIBC_NAMESPACE_DECL {
3230

33-
LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
31+
LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
3432
LOAD(ra, buf->__pc);
3533
LOAD(s0, buf->__regs[0]);
3634
LOAD(s1, buf->__regs[1]);

libc/src/setjmp/riscv/setjmp.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include "src/__support/macros/config.h"
1111
#include "src/setjmp/setjmp_impl.h"
1212

13-
#include <setjmp.h>
14-
1513
#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
1614
#error "Invalid file include"
1715
#endif
@@ -29,7 +27,7 @@
2927

3028
namespace LIBC_NAMESPACE_DECL {
3129

32-
LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
30+
LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
3331
STORE(ra, buf->__pc);
3432
STORE(s0, buf->__regs[0]);
3533
STORE(s1, buf->__regs[1]);

libc/src/setjmp/setjmp_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
// This header has the _impl prefix in its name to avoid conflict with the
1313
// public header setjmp.h which is also included. here.
14+
#include "hdr/types/jmp_buf.h"
1415
#include "src/__support/macros/config.h"
15-
#include <setjmp.h>
1616

1717
namespace LIBC_NAMESPACE_DECL {
1818

19-
int setjmp(__jmp_buf *buf);
19+
int setjmp(jmp_buf buf);
2020

2121
} // namespace LIBC_NAMESPACE_DECL
2222

libc/src/setjmp/x86_64/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_entrypoint_object(
55
HDRS
66
../setjmp_impl.h
77
DEPENDS
8-
libc.include.setjmp
8+
libc.hdr.types.jmp_buf
99
COMPILE_OPTIONS
1010
-O3
1111
-fno-omit-frame-pointer
@@ -23,7 +23,7 @@ add_entrypoint_object(
2323
HDRS
2424
../longjmp.h
2525
DEPENDS
26-
libc.include.setjmp
26+
libc.hdr.types.jmp_buf
2727
COMPILE_OPTIONS
2828
-O3
2929
-fomit-frame-pointer

libc/src/setjmp/x86_64/longjmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace LIBC_NAMESPACE_DECL {
1818

19-
LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
19+
LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
2020
register __UINT64_TYPE__ rbx __asm__("rbx");
2121
register __UINT64_TYPE__ rbp __asm__("rbp");
2222
register __UINT64_TYPE__ r12 __asm__("r12");

libc/src/setjmp/x86_64/setjmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace LIBC_NAMESPACE_DECL {
1818

19-
LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
19+
LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
2020
register __UINT64_TYPE__ rbx __asm__("rbx");
2121
register __UINT64_TYPE__ r12 __asm__("r12");
2222
register __UINT64_TYPE__ r13 __asm__("r13");

libc/test/src/setjmp/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ add_libc_unittest(
1212
SRCS
1313
setjmp_test.cpp
1414
DEPENDS
15-
libc.include.setjmp
1615
libc.src.setjmp.longjmp
1716
libc.src.setjmp.setjmp
1817
)

0 commit comments

Comments
 (0)