Skip to content

Commit 6fc1417

Browse files
committed
Implement static initialization guards (#500)
1 parent b5684b4 commit 6fc1417

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

cores/esp8266/abi.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ extern "C" {
2525
#include "osapi.h"
2626
#include "mem.h"
2727
}
28+
#include <Arduino.h>
29+
#include <cxxabi.h>
2830

31+
using __cxxabiv1::__guard;
2932

3033
void *operator new(size_t size) {
3134
size = ((size + 3) & ~((size_t)0x3));
@@ -56,6 +59,34 @@ void __cxa_deleted_virtual(void) {
5659
panic();
5760
}
5861

62+
typedef struct {
63+
uint8_t guard;
64+
uint8_t ps;
65+
} guard_t;
66+
67+
extern "C" int __cxa_guard_acquire(__guard* pg)
68+
{
69+
uint8_t ps = xt_rsil(15);
70+
if (reinterpret_cast<guard_t*>(pg)->guard) {
71+
xt_wsr_ps(ps);
72+
return 0;
73+
}
74+
reinterpret_cast<guard_t*>(pg)->ps = ps;
75+
return 1;
76+
}
77+
78+
extern "C" void __cxa_guard_release(__guard* pg)
79+
{
80+
reinterpret_cast<guard_t*>(pg)->guard = 1;
81+
xt_wsr_ps(reinterpret_cast<guard_t*>(pg)->ps);
82+
}
83+
84+
extern "C" void __cxa_guard_abort(__guard* pg)
85+
{
86+
xt_wsr_ps(reinterpret_cast<guard_t*>(pg)->ps);
87+
}
88+
89+
5990
namespace std {
6091
void __throw_bad_function_call() {
6192
panic();

0 commit comments

Comments
 (0)