Skip to content

Commit 0af682e

Browse files
[llvm-libc] Import setjmp from llvm-libc (emscripten-core#24765)
Defined a wasm-specific wasm/sigsetjmp.cpp that just fowards the call to setjmp. Defines in the musl header don't quite work with llvm-libc's setjmp.
1 parent be3fe6b commit 0af682e

File tree

12 files changed

+190
-2
lines changed

12 files changed

+190
-2
lines changed

system/lib/libc/musl/include/setjmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct __jmp_buf_tag {
2626
|| defined(_BSD_SOURCE)
2727
typedef jmp_buf sigjmp_buf;
2828
/* XXX EMSCRIPTEN: No signals support, alias sigsetjmp and siglongjmp to their non-signals counterparts. */
29-
#if __EMSCRIPTEN__
29+
#if __EMSCRIPTEN__ && !defined(LLVM_LIBC)
3030
#define sigsetjmp(buf, x) setjmp((buf))
3131
#define siglongjmp(buf, val) longjmp(buf, val)
3232
#else
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifdef __EMSCRIPTEN__
2+
#define sigsetjmp(buf, x) setjmp((buf))
3+
#endif
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifdef __EMSCRIPTEN__
2+
#define siglongjmp(buf, val) longjmp(buf, val)
3+
#endif
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- Implementation header for longjmp -----------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_SETJMP_LONGJMP_H
10+
#define LLVM_LIBC_SRC_SETJMP_LONGJMP_H
11+
12+
#include "hdr/types/jmp_buf.h"
13+
#include "src/__support/macros/config.h"
14+
#include "src/__support/macros/properties/compiler.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
// TODO(https://github.com/llvm/llvm-project/issues/112427)
19+
// Some of the architecture-specific definitions are marked `naked`, which in
20+
// GCC implies `nothrow`.
21+
//
22+
// Right now, our aliases aren't marked `nothrow`, so we wind up in a situation
23+
// where clang will emit -Wmissing-exception-spec if we add `nothrow` here, but
24+
// GCC will emit -Wmissing-attributes here without `nothrow`. We need to update
25+
// LLVM_LIBC_FUNCTION to denote when a function throws or not.
26+
27+
#ifdef LIBC_COMPILER_IS_GCC
28+
[[gnu::nothrow]]
29+
#endif
30+
void longjmp(jmp_buf buf, int val);
31+
32+
} // namespace LIBC_NAMESPACE_DECL
33+
34+
#endif // LLVM_LIBC_SRC_SETJMP_LONGJMP_H
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===-- Implementation header for setjmp ------------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_SETJMP_SETJMP_IMPL_H
10+
#define LLVM_LIBC_SRC_SETJMP_SETJMP_IMPL_H
11+
12+
// This header has the _impl prefix in its name to avoid conflict with the
13+
// public header setjmp.h which is also included. here.
14+
#include "hdr/types/jmp_buf.h"
15+
#include "src/__support/macros/config.h"
16+
#include "src/__support/macros/properties/compiler.h"
17+
18+
namespace LIBC_NAMESPACE_DECL {
19+
20+
// TODO(https://github.com/llvm/llvm-project/issues/112427)
21+
// Some of the architecture-specific definitions are marked `naked`, which in
22+
// GCC implies `nothrow`.
23+
//
24+
// Right now, our aliases aren't marked `nothrow`, so we wind up in a situation
25+
// where clang will emit -Wmissing-exception-spec if we add `nothrow` here, but
26+
// GCC will emit -Wmissing-attributes here without `nothrow`. We need to update
27+
// LLVM_LIBC_FUNCTION to denote when a function throws or not.
28+
29+
#ifdef LIBC_COMPILER_IS_GCC
30+
[[gnu::nothrow]]
31+
#endif
32+
[[gnu::returns_twice]] int
33+
setjmp(jmp_buf buf);
34+
35+
} // namespace LIBC_NAMESPACE_DECL
36+
37+
#endif // LLVM_LIBC_SRC_SETJMP_SETJMP_IMPL_H
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Implementation of siglongjmp --------------------------------------===//
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/siglongjmp.h"
10+
#include "src/__support/common.h"
11+
#include "src/setjmp/longjmp.h"
12+
13+
namespace LIBC_NAMESPACE_DECL {
14+
15+
// siglongjmp is the same as longjmp. The additional recovery work is done in
16+
// the epilogue of the sigsetjmp function.
17+
// TODO: move this inside the TU of longjmp and making it an alias after
18+
// sigsetjmp is implemented for all architectures.
19+
LLVM_LIBC_FUNCTION(void, siglongjmp, (jmp_buf buf, int val)) {
20+
return LIBC_NAMESPACE::longjmp(buf, val);
21+
}
22+
23+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Implementation header for siglongjmp --------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_SETJMP_SIGLONGJMP_H
10+
#define LLVM_LIBC_SRC_SETJMP_SIGLONGJMP_H
11+
12+
#include "hdr/types/jmp_buf.h"
13+
#include "src/__support/macros/config.h"
14+
#include "src/__support/macros/properties/compiler.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
#ifdef LIBC_COMPILER_IS_GCC
19+
[[gnu::nothrow]]
20+
#endif
21+
void siglongjmp(jmp_buf buf, int val);
22+
23+
} // namespace LIBC_NAMESPACE_DECL
24+
25+
#endif // LLVM_LIBC_SRC_SETJMP_SIGLONGJMP_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Implementation header for sigsetjmp ---------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H
10+
#define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H
11+
12+
#include "hdr/types/jmp_buf.h"
13+
#include "src/__support/macros/config.h"
14+
#include "src/__support/macros/properties/compiler.h"
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
#ifdef LIBC_COMPILER_IS_GCC
19+
[[gnu::nothrow]]
20+
#endif
21+
[[gnu::returns_twice]] int
22+
sigsetjmp(sigjmp_buf buf, int savesigs);
23+
24+
} // namespace LIBC_NAMESPACE_DECL
25+
26+
#endif // LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation header for sigsetjmp epilogue ------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H
10+
#define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H
11+
12+
#include "hdr/types/jmp_buf.h"
13+
#include "src/__support/common.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval);
17+
} // namespace LIBC_NAMESPACE_DECL
18+
19+
#endif // LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "src/setjmp/sigsetjmp.h"
2+
#include "hdr/offsetof_macros.h"
3+
#include "src/__support/common.h"
4+
#include "src/__support/macros/config.h"
5+
6+
#if !defined(LIBC_TARGET_ARCH_IS_WASM)
7+
#error "Invalid file include"
8+
#endif
9+
10+
namespace LIBC_NAMESPACE_DECL {
11+
[[gnu::returns_twice]] int sigsetjmp(jmp_buf sigjmp_buf, int savesigs) {
12+
return setjmp(sigjmp_buf);
13+
}
14+
}

0 commit comments

Comments
 (0)