[libc-commits] [libc] [libc] Add proxy header for the jmp_buf type (PR #107712)
via libc-commits
libc-commits at lists.llvm.org
Sat Sep 7 11:41:39 PDT 2024
https://github.com/wldfngrs created https://github.com/llvm/llvm-project/pull/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
>From dfd1cabc2ea248b93d46c0603feb40e7dbe61a3e Mon Sep 17 00:00:00 2001
From: wldfngrs <wldfngrs at gmail.com>
Date: Sat, 7 Sep 2024 19:37:44 +0100
Subject: [PATCH] added proxy header of the jmp_buf type and changed all use
instances from to the typedef alias , fixed the link to LLVM in description
---
libc/hdr/types/CMakeLists.txt | 9 +++++++++
libc/hdr/types/jmp_buf.h | 22 ++++++++++++++++++++++
libc/hdr/types/stack_t.h | 2 +-
libc/src/setjmp/aarch64/longjmp.cpp | 2 +-
libc/src/setjmp/aarch64/setjmp.cpp | 2 +-
libc/src/setjmp/arm/longjmp.cpp | 4 ++--
libc/src/setjmp/arm/setjmp.cpp | 4 ++--
libc/src/setjmp/longjmp.h | 4 ++--
libc/src/setjmp/riscv/longjmp.cpp | 4 +---
libc/src/setjmp/riscv/setjmp.cpp | 4 +---
libc/src/setjmp/setjmp_impl.h | 4 ++--
libc/src/setjmp/x86_64/longjmp.cpp | 2 +-
libc/src/setjmp/x86_64/setjmp.cpp | 2 +-
13 files changed, 46 insertions(+), 19 deletions(-)
create mode 100644 libc/hdr/types/jmp_buf.h
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 8789e0c7870263..12641c4d93ffe8 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -190,3 +190,12 @@ add_proxy_header_library(
libc.include.signal
)
+add_proxy_header_library(
+ jmp_buf
+ HDRS
+ jmp_buf.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.jmp_buf
+ libc.include.setjmp
+)
+
diff --git a/libc/hdr/types/jmp_buf.h b/libc/hdr/types/jmp_buf.h
new file mode 100644
index 00000000000000..943764739f69a7
--- /dev/null
+++ b/libc/hdr/types/jmp_buf.h
@@ -0,0 +1,22 @@
+//===-- Definition of jmp_buf.h ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apahce License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_JMP_BUF_H
+#define LLVM_LIBC_HDR_JMP_BUF_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/jmp_buf.h"
+
+#else // overlay mode
+
+#include <setjmp.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_JMP_BUF_H
diff --git a/libc/hdr/types/stack_t.h b/libc/hdr/types/stack_t.h
index 8c7c37a5d814ee..9c0f707a7f6d9f 100644
--- a/libc/hdr/types/stack_t.h
+++ b/libc/hdr/types/stack_t.h
@@ -1,7 +1,7 @@
//===-- Definition of stack_t.h -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https:llvm.or/LICENSE.txt for license information.
+// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
diff --git a/libc/src/setjmp/aarch64/longjmp.cpp b/libc/src/setjmp/aarch64/longjmp.cpp
index fbb86524e39516..80c97c721cc4f6 100644
--- a/libc/src/setjmp/aarch64/longjmp.cpp
+++ b/libc/src/setjmp/aarch64/longjmp.cpp
@@ -23,7 +23,7 @@ namespace LIBC_NAMESPACE_DECL {
// them.)
[[gnu::naked]] LLVM_LIBC_FUNCTION(void, longjmp,
- ([[maybe_unused]] __jmp_buf * buf,
+ ([[maybe_unused]] jmp_buf buf,
[[maybe_unused]] int val)) {
// If BTI branch protection is in use, the compiler will automatically insert
// a BTI here, so we don't need to make any extra effort to do so.
diff --git a/libc/src/setjmp/aarch64/setjmp.cpp b/libc/src/setjmp/aarch64/setjmp.cpp
index 90e49be49a8fcc..fac249a93da07b 100644
--- a/libc/src/setjmp/aarch64/setjmp.cpp
+++ b/libc/src/setjmp/aarch64/setjmp.cpp
@@ -13,7 +13,7 @@
namespace LIBC_NAMESPACE_DECL {
[[gnu::naked]] LLVM_LIBC_FUNCTION(int, setjmp,
- ([[maybe_unused]] __jmp_buf * buf)) {
+ ([[maybe_unused]] jmp_buf buf)) {
// If BTI branch protection is in use, the compiler will automatically insert
// a BTI here, so we don't need to make any extra effort to do so.
diff --git a/libc/src/setjmp/arm/longjmp.cpp b/libc/src/setjmp/arm/longjmp.cpp
index f36c79df660641..5b8d03b167be7d 100644
--- a/libc/src/setjmp/arm/longjmp.cpp
+++ b/libc/src/setjmp/arm/longjmp.cpp
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
#if defined(__thumb__) && __ARM_ARCH_ISA_THUMB == 1
[[gnu::naked, gnu::target("thumb")]]
-LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
asm(R"(
# Reload r4, r5, r6, r7.
ldmia r0!, {r4-r7}
@@ -54,7 +54,7 @@ LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
// (d0-d16)
// TODO(https://github.com/llvm/llvm-project/issues/94062): pac+bti
[[gnu::naked]]
-LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
asm(R"(
# While sp may appear in a register list for ARM mode, it may not for
# Thumb2 mode. Just load the previous value of sp into r12 then move it
diff --git a/libc/src/setjmp/arm/setjmp.cpp b/libc/src/setjmp/arm/setjmp.cpp
index dc4252a3505096..ab8a980dd2f298 100644
--- a/libc/src/setjmp/arm/setjmp.cpp
+++ b/libc/src/setjmp/arm/setjmp.cpp
@@ -15,7 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
#if defined(__thumb__) && __ARM_ARCH_ISA_THUMB == 1
[[gnu::naked, gnu::target("thumb")]]
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
asm(R"(
# Store r4, r5, r6, and r7 into buf.
stmia r0!, {r4-r7}
@@ -45,7 +45,7 @@ LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
// (d0-d16)
// TODO(https://github.com/llvm/llvm-project/issues/94062): pac+bti
[[gnu::naked]]
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
asm(R"(
# While sp may appear in a register list for ARM mode, it may not for
# Thumb2 mode. Just move it into r12 then stm that, so that this code
diff --git a/libc/src/setjmp/longjmp.h b/libc/src/setjmp/longjmp.h
index 29c5c9e1fbc929..9f2f7ddaf06d06 100644
--- a/libc/src/setjmp/longjmp.h
+++ b/libc/src/setjmp/longjmp.h
@@ -10,11 +10,11 @@
#define LLVM_LIBC_SRC_SETJMP_LONGJMP_H
#include "src/__support/macros/config.h"
-#include <setjmp.h>
+#include "hdr/types/jmp_buf.h"
namespace LIBC_NAMESPACE_DECL {
-void longjmp(__jmp_buf *buf, int val);
+void longjmp(jmp_buf buf, int val);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/riscv/longjmp.cpp b/libc/src/setjmp/riscv/longjmp.cpp
index 0f9537ccc41510..16526a45e193e7 100644
--- a/libc/src/setjmp/riscv/longjmp.cpp
+++ b/libc/src/setjmp/riscv/longjmp.cpp
@@ -11,8 +11,6 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
-#include <setjmp.h>
-
#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
#error "Invalid file include"
#endif
@@ -30,7 +28,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
LOAD(ra, buf->__pc);
LOAD(s0, buf->__regs[0]);
LOAD(s1, buf->__regs[1]);
diff --git a/libc/src/setjmp/riscv/setjmp.cpp b/libc/src/setjmp/riscv/setjmp.cpp
index 12def578b56f34..13cb42e94867c1 100644
--- a/libc/src/setjmp/riscv/setjmp.cpp
+++ b/libc/src/setjmp/riscv/setjmp.cpp
@@ -10,8 +10,6 @@
#include "src/__support/macros/config.h"
#include "src/setjmp/setjmp_impl.h"
-#include <setjmp.h>
-
#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
#error "Invalid file include"
#endif
@@ -29,7 +27,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
STORE(ra, buf->__pc);
STORE(s0, buf->__regs[0]);
STORE(s1, buf->__regs[1]);
diff --git a/libc/src/setjmp/setjmp_impl.h b/libc/src/setjmp/setjmp_impl.h
index 50d7a6b44503b7..f2304277fe4842 100644
--- a/libc/src/setjmp/setjmp_impl.h
+++ b/libc/src/setjmp/setjmp_impl.h
@@ -12,11 +12,11 @@
// This header has the _impl prefix in its name to avoid conflict with the
// public header setjmp.h which is also included. here.
#include "src/__support/macros/config.h"
-#include <setjmp.h>
+#include "hdr/types/jmp_buf.h"
namespace LIBC_NAMESPACE_DECL {
-int setjmp(__jmp_buf *buf);
+int setjmp(jmp_buf buf);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/x86_64/longjmp.cpp b/libc/src/setjmp/x86_64/longjmp.cpp
index f479c7bc96c977..d4b55565cb2187 100644
--- a/libc/src/setjmp/x86_64/longjmp.cpp
+++ b/libc/src/setjmp/x86_64/longjmp.cpp
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
register __UINT64_TYPE__ rbx __asm__("rbx");
register __UINT64_TYPE__ rbp __asm__("rbp");
register __UINT64_TYPE__ r12 __asm__("r12");
diff --git a/libc/src/setjmp/x86_64/setjmp.cpp b/libc/src/setjmp/x86_64/setjmp.cpp
index 6a1cc7a83936a5..62d9c13c68e4b6 100644
--- a/libc/src/setjmp/x86_64/setjmp.cpp
+++ b/libc/src/setjmp/x86_64/setjmp.cpp
@@ -16,7 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
register __UINT64_TYPE__ rbx __asm__("rbx");
register __UINT64_TYPE__ r12 __asm__("r12");
register __UINT64_TYPE__ r13 __asm__("r13");
More information about the libc-commits
mailing list