|
19 | 19 | #include <stdlib.h> |
20 | 20 | #include <assert.h> |
21 | 21 | #include <debug.h> |
22 | | -extern "C" { |
23 | | -#include "ets_sys.h" |
24 | | -#include "os_type.h" |
25 | | -#include "osapi.h" |
26 | | -#include "mem.h" |
27 | | -} |
| 22 | +#include <Arduino.h> |
| 23 | +#include <cxxabi.h> |
28 | 24 |
|
| 25 | +using __cxxabiv1::__guard; |
29 | 26 |
|
30 | | -void *operator new(size_t size) { |
31 | | - size = ((size + 3) & ~((size_t)0x3)); |
32 | | - return os_malloc(size); |
| 27 | +void *operator new(size_t size) |
| 28 | +{ |
| 29 | + return malloc(size); |
33 | 30 | } |
34 | 31 |
|
35 | | -void *operator new[](size_t size) { |
36 | | - size = ((size + 3) & ~((size_t)0x3)); |
37 | | - return os_malloc(size); |
| 32 | +void *operator new[](size_t size) |
| 33 | +{ |
| 34 | + return malloc(size); |
38 | 35 | } |
39 | 36 |
|
40 | | -void operator delete(void * ptr) { |
41 | | - os_free(ptr); |
| 37 | +void operator delete(void * ptr) |
| 38 | +{ |
| 39 | + free(ptr); |
42 | 40 | } |
43 | 41 |
|
44 | | -void operator delete[](void * ptr) { |
45 | | - os_free(ptr); |
| 42 | +void operator delete[](void * ptr) |
| 43 | +{ |
| 44 | + free(ptr); |
46 | 45 | } |
47 | 46 |
|
48 | 47 | extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__)); |
49 | 48 | extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__)); |
50 | 49 |
|
51 | | -void __cxa_pure_virtual(void) { |
| 50 | +void __cxa_pure_virtual(void) |
| 51 | +{ |
52 | 52 | panic(); |
53 | 53 | } |
54 | 54 |
|
55 | | -void __cxa_deleted_virtual(void) { |
| 55 | +void __cxa_deleted_virtual(void) |
| 56 | +{ |
56 | 57 | panic(); |
57 | 58 | } |
58 | 59 |
|
59 | | -namespace std { |
60 | | -void __throw_bad_function_call() { |
| 60 | +typedef struct { |
| 61 | + uint8_t guard; |
| 62 | + uint8_t ps; |
| 63 | +} guard_t; |
| 64 | + |
| 65 | +extern "C" int __cxa_guard_acquire(__guard* pg) |
| 66 | +{ |
| 67 | + uint8_t ps = xt_rsil(15); |
| 68 | + if (reinterpret_cast<guard_t*>(pg)->guard) { |
| 69 | + xt_wsr_ps(ps); |
| 70 | + return 0; |
| 71 | + } |
| 72 | + reinterpret_cast<guard_t*>(pg)->ps = ps; |
| 73 | + return 1; |
| 74 | +} |
| 75 | + |
| 76 | +extern "C" void __cxa_guard_release(__guard* pg) |
| 77 | +{ |
| 78 | + reinterpret_cast<guard_t*>(pg)->guard = 1; |
| 79 | + xt_wsr_ps(reinterpret_cast<guard_t*>(pg)->ps); |
| 80 | +} |
| 81 | + |
| 82 | +extern "C" void __cxa_guard_abort(__guard* pg) |
| 83 | +{ |
| 84 | + xt_wsr_ps(reinterpret_cast<guard_t*>(pg)->ps); |
| 85 | +} |
| 86 | + |
| 87 | + |
| 88 | +namespace std |
| 89 | +{ |
| 90 | +void __throw_bad_function_call() |
| 91 | +{ |
61 | 92 | panic(); |
62 | 93 | } |
63 | 94 |
|
64 | | -void __throw_length_error(char const*) { |
| 95 | +void __throw_length_error(char const*) |
| 96 | +{ |
65 | 97 | panic(); |
66 | 98 | } |
67 | 99 |
|
68 | | -void __throw_bad_alloc() { |
| 100 | +void __throw_bad_alloc() |
| 101 | +{ |
69 | 102 | panic(); |
70 | 103 | } |
71 | 104 |
|
72 | | -void __throw_logic_error(const char* str) { |
| 105 | +void __throw_logic_error(const char* str) |
| 106 | +{ |
73 | 107 | panic(); |
74 | 108 | } |
75 | 109 | } |
|
0 commit comments