-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLibraryHacks.cpp
95 lines (68 loc) · 1.48 KB
/
LibraryHacks.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* LibraryHacks.cpp
*
* Created on: 23 Jan 2011
* Author: Andy
*/
#include <cstdlib>
#include <sys/types.h>
/*
* The default pulls in 70K of garbage
*/
namespace __gnu_cxx {
void __verbose_terminate_handler() {
for(;;);
}
}
/*
* The default pulls in about 12K of garbage
*/
extern "C" void __cxa_pure_virtual() {
for(;;);
}
/*
* Implement C++ new/delete operators using the heap
*/
void *operator new(size_t size) {
return malloc(size);
}
void *operator new(size_t,void *ptr) {
return ptr;
}
void *operator new[](size_t size) {
return malloc(size);
}
void *operator new[](size_t,void *ptr) {
return ptr;
}
void operator delete(void *p) {
free(p);
}
void operator delete[](void *p) {
free(p);
}
/*
* EABI builds can generate reams of stack unwind code for system generated exceptions
* e.g. (divide-by-zero). Since we don't support exceptions we'll wrap out these
* symbols and save a lot of flash space.
*/
extern "C" void __wrap___aeabi_unwind_cpp_pr0() {}
extern "C" void __wrap___aeabi_unwind_cpp_pr1() {}
extern "C" void __wrap___aeabi_unwind_cpp_pr2() {}
/*
* sbrk function for getting space for malloc and friends
*/
extern int _end;
extern "C" {
caddr_t _sbrk ( int incr ) {
static unsigned char *heap = NULL;
unsigned char *prev_heap;
if (heap == NULL) {
heap = (unsigned char *)&_end;
}
prev_heap = heap;
/* check removed to show basic approach */
heap += incr;
return (caddr_t) prev_heap;
}
}