-
Notifications
You must be signed in to change notification settings - Fork 5
/
cxxglue.cc
60 lines (47 loc) · 1.18 KB
/
cxxglue.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Thin wrappers for using C++ without newlib or other heavy libraries. */
extern "C"
{
#include "ds203_io.h"
void __cxa_pure_virtual() {
// Pure virtual function was called
crash_with_message("C++: pure virtual", __builtin_return_address(0));
}
}
namespace std {
void __throw_out_of_range(const char*) {
// Vector .at() with argument out of range
crash_with_message("C++: out of range", __builtin_return_address(0));
}
void __throw_length_error(const char*) {
// Vector resize to excessive length
crash_with_message("C++: length error", __builtin_return_address(0));
}
void __throw_bad_alloc() {
crash_with_message("C++: bad alloc", __builtin_return_address(0));
}
}
void abort(void)
{
crash_with_message("abort", __builtin_return_address(0));
while(1);
}
#include <stdlib.h>
void * operator new(size_t n)
{
void * const p = malloc(n);
if (p == 0)
crash_with_message("out of memory", __builtin_return_address(0));
return p;
}
void operator delete(void * p)
{
free(p);
}
void * operator new[](size_t n)
{
return ::operator new(n);
}
void operator delete[](void * p)
{
free(p);
}