Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/libcxxabi/src/cxa_noexception.cpp
6173 views
1
//===----------------------------------------------------------------------===//
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
// This file implements the "Exception Handling APIs"
9
// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
10
//
11
//===----------------------------------------------------------------------===//
12
13
// Support functions for the no-exceptions libc++ library
14
15
#include "cxxabi.h"
16
17
#include <exception> // for std::terminate
18
#include "cxa_exception.h"
19
#include "cxa_handlers.h"
20
21
namespace __cxxabiv1 {
22
23
extern "C" {
24
25
void
26
__cxa_increment_exception_refcount(void *thrown_object) throw() {
27
if (thrown_object != nullptr)
28
std::terminate();
29
}
30
31
void
32
__cxa_decrement_exception_refcount(void *thrown_object) throw() {
33
if (thrown_object != nullptr)
34
std::terminate();
35
}
36
37
38
void *__cxa_current_primary_exception() throw() { return nullptr; }
39
40
void
41
__cxa_rethrow_primary_exception(void* thrown_object) {
42
if (thrown_object != nullptr)
43
std::terminate();
44
}
45
46
bool
47
__cxa_uncaught_exception() throw() { return false; }
48
49
unsigned int
50
__cxa_uncaught_exceptions() throw() { return 0; }
51
52
#if __EMSCRIPTEN__
53
// Under emscripten this code is also linked when building when
54
// DISABLE_EXCEPTION_CATCHING is set but DISABLE_EXCEPTION_THROWING is not.
55
// TODO(sbc): Perhaps just call std::terminate here. It could
56
// just be some test code that needs updating.
57
void *__cxa_allocate_exception(size_t thrown_size) throw() {
58
char* allocation = (char*)malloc(thrown_size + sizeof(__cxa_exception));
59
return allocation + sizeof(__cxa_exception);
60
}
61
62
static
63
inline
64
__cxa_exception*
65
cxa_exception_from_thrown_object(void* thrown_object)
66
{
67
return static_cast<__cxa_exception*>(thrown_object) - 1;
68
}
69
70
// Free a __cxa_exception object allocated with __cxa_allocate_exception.
71
void __cxa_free_exception(void *thrown_object) throw() {
72
// Compute the size of the padding before the header.
73
char *raw_buffer =
74
((char *)cxa_exception_from_thrown_object(thrown_object));
75
free((void *)raw_buffer);
76
}
77
78
// This function is called from make_exception_ptr in libcxx unless
79
// -fno-exceptions is not given. We have definitions of this function in
80
// cxa_exception.cpp and cxa_exception_emscripten.cpp, but unlike other
81
// platforms, we use those files only when one of Emscripten EH or Wasm EH is
82
// used, and we use this cxa_noexceptions.cpp in case of -fignore-exceptions,
83
// which is our default. So we add a definition here to prevent a link failure.
84
__cxa_exception*
85
__cxa_init_primary_exception(void* object,
86
std::type_info* tinfo,
87
void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {
88
__cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
89
return exception_header;
90
}
91
#endif
92
93
} // extern "C"
94
95
// provide dummy implementations for the 'no exceptions' case.
96
uint64_t __getExceptionClass (const _Unwind_Exception*) { return 0; }
97
void __setExceptionClass ( _Unwind_Exception*, uint64_t) {}
98
bool __isOurExceptionClass(const _Unwind_Exception*) { return false; }
99
100
} // abi
101
102