Skip to content

Commit a712918

Browse files
committed
[libcxx] added cxa_guard functions
1 parent 0e354c9 commit a712918

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/libcxx/cxa.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <stdint.h>
2+
#include "abort_message.h"
3+
4+
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#dso-dtor-runtime-api
5+
6+
// __int64_t
7+
typedef int64_t __guard;
8+
9+
extern "C" {
10+
[[gnu::cold]] int __cxa_guard_acquire(__guard *);
11+
[[gnu::cold]] void __cxa_guard_release(__guard *);
12+
[[noreturn, gnu::cold]] void __cxa_guard_abort(__guard *);
13+
}
14+
15+
int __cxa_guard_acquire(__guard *guard_object) {
16+
unsigned char const *flag = (unsigned char const *)guard_object;
17+
if (*flag == 0) {
18+
// initialization not yet complete
19+
return 1;
20+
}
21+
// otherwise
22+
return 0;
23+
}
24+
25+
void __cxa_guard_release(__guard *guard_object) {
26+
unsigned char *flag = (unsigned char *)guard_object;
27+
// set to a non-zero value
28+
*flag = 1;
29+
}
30+
31+
void __cxa_guard_abort([[maybe_unused]] __guard *guard_object) {
32+
std::__abort_message("__cxa_guard_abort");
33+
}

0 commit comments

Comments
 (0)