-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathstdlib.c
More file actions
108 lines (87 loc) · 2.19 KB
/
stdlib.c
File metadata and controls
108 lines (87 loc) · 2.19 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <stdlib.h>
#include <string.h>
#include <FreeRTOS.h>
#include <sys/stat.h>
#include <unistd.h>
// Override malloc() and free() to use the memory manager from FreeRTOS.
// According to the documentation of libc, we also need to override
// calloc and realloc.
// See https://www.gnu.org/software/libc/manual/html_node/Replacing-malloc.html
void* malloc(size_t size) {
return pvPortMalloc(size);
}
void* __wrap_malloc(size_t size) {
return malloc(size);
}
void* __wrap__malloc_r(struct _reent* reent, size_t size) {
(void) reent;
return malloc(size);
}
void free(void* ptr) {
vPortFree(ptr);
}
void __wrap_free(void* ptr) {
free(ptr);
}
void* calloc(size_t num, size_t size) {
void* ptr = malloc(num * size);
if (ptr) {
memset(ptr, 0, num * size);
}
return ptr;
}
void* __wrap_calloc(size_t num, size_t size) {
return calloc(num, size);
}
void* pvPortRealloc(void* ptr, size_t xWantedSize);
void* realloc(void* ptr, size_t newSize) {
return pvPortRealloc(ptr, newSize);
}
void* __wrap_realloc(void* ptr, size_t newSize) {
return realloc(ptr, newSize);
}
// Implement functions required by libc as stubs
// These functions aren't linked into the final binary
__attribute__((error("stub"))) void _close(int fp) {
__builtin_trap();
(void) fp;
}
__attribute__((error("stub"))) void _fstat(int fildes, struct stat* buf) {
__builtin_trap();
(void) fildes;
(void) buf;
}
__attribute__((error("stub"))) pid_t _getpid() {
__builtin_trap();
}
__attribute__((error("stub"))) int _isatty(int fd) {
__builtin_trap();
(void) fd;
}
__attribute__((error("stub"))) int _kill(pid_t pid, int sig) {
__builtin_trap();
(void) pid;
(void) sig;
}
__attribute__((error("stub"))) off_t _lseek(int fd, off_t offset, int whence) {
__builtin_trap();
(void) fd;
(void) offset;
(void) whence;
}
__attribute__((error("stub"))) ssize_t _read(int fd, void* buf, size_t count) {
__builtin_trap();
(void) fd;
(void) buf;
(void) count;
}
__attribute__((error("stub"))) ssize_t _write(int fd, void* buf, size_t count) {
__builtin_trap();
(void) fd;
(void) buf;
(void) count;
}
__attribute__((error("stub"))) void _exit(int status) {
__builtin_trap();
(void) status;
}