File tree 6 files changed +28
-25
lines changed
6 files changed +28
-25
lines changed Original file line number Diff line number Diff line change @@ -31,11 +31,11 @@ static void free_wrap(void * p) {
31
31
32
32
void init_malloc_wrapper () {
33
33
malloc_sem = xSemaphoreCreateRecursiveMutex ();
34
- old_malloc = malloc ;
35
- old_realloc = realloc ;
36
- old_free = free ;
37
- malloc = malloc_wrap ;
38
- realloc = realloc_wrap ;
39
- free = free_wrap ;
34
+ old_malloc = malloc_ptr ;
35
+ old_realloc = realloc_ptr ;
36
+ old_free = free_ptr ;
37
+ malloc_ptr = malloc_wrap ;
38
+ realloc_ptr = realloc_wrap ;
39
+ free_ptr = free_wrap ;
40
40
}
41
41
Original file line number Diff line number Diff line change 7
7
8
8
BEGIN_DECL
9
9
10
- // Due to chicken-and-egg issues, we may need to call this from other modules.
11
- // Only call it from global constructors however.
12
- void _uc_sdk_ensure_malloc_exists ();
13
-
14
10
typedef void * (* malloc_t )(size_t size );
15
11
typedef void (* free_t )(void * ptr );
16
12
typedef void * (* realloc_t )(void * ptr , size_t size );
@@ -19,9 +15,13 @@ void * base_malloc(size_t size);
19
15
void base_free (void * ptr );
20
16
void * base_realloc (void * ptr , size_t size );
21
17
22
- extern malloc_t malloc ;
23
- extern free_t free ;
24
- extern realloc_t realloc ;
18
+ void * malloc (size_t size );
19
+ void free (void * ptr );
20
+ void * realloc (void * ptr , size_t size );
21
+
22
+ extern malloc_t malloc_ptr ;
23
+ extern free_t free_ptr ;
24
+ extern realloc_t realloc_ptr ;
25
25
26
26
static __inline__ void * calloc (size_t nmemb , size_t size ) {
27
27
uint8_t * r = (uint8_t * )malloc (nmemb * size );
Original file line number Diff line number Diff line change @@ -81,6 +81,6 @@ void exit(int return_code) {
81
81
}
82
82
83
83
void libc_init () {
84
- __sinit (_impure_ptr );
85
84
__libc_init_array ();
85
+ __sinit (_impure_ptr );
86
86
}
Original file line number Diff line number Diff line change @@ -199,14 +199,18 @@ void base_free(void * ptr) {
199
199
cur -> prev -> next = cur -> next ;
200
200
}
201
201
202
- malloc_t malloc = base_malloc ;
203
- free_t free = base_free ;
204
- realloc_t realloc = base_realloc ;
202
+ malloc_t malloc_ptr = NULL ;
203
+ free_t free_ptr = NULL ;
204
+ realloc_t realloc_ptr = NULL ;
205
205
206
- // Due to chicken-and-egg issues, we may need to call this from other modules.
207
- // Only call it from global constructors however.
208
- void _uc_sdk_ensure_malloc_exists () {
209
- malloc = base_malloc ;
210
- free = base_free ;
211
- realloc = base_realloc ;
206
+ void * malloc (size_t size ) {
207
+ return malloc_ptr ? malloc_ptr (size ) : base_malloc (size );
208
+ }
209
+
210
+ void free (void * ptr ) {
211
+ free_ptr ? free_ptr (ptr ) : base_free (ptr );
212
+ }
213
+
214
+ void * realloc (void * ptr , size_t size ) {
215
+ return realloc_ptr ? realloc_ptr (size ) : base_realloc (ptr , size );
212
216
}
Original file line number Diff line number Diff line change @@ -41,7 +41,6 @@ __attribute__((constructor)) static void fio_init() {
41
41
fio_fds [0 ].fdread = stdin_read ;
42
42
fio_fds [1 ].fdwrite = stdout_write ;
43
43
fio_fds [2 ].fdwrite = stdout_write ;
44
- _uc_sdk_ensure_malloc_exists ();
45
44
fio_sem = xSemaphoreCreateMutex ();
46
45
}
47
46
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ void * sbrk(ptrdiff_t incr) {
21
21
prev_heap_end = heap_end ? heap_end : (void * ) & __heap_start ;
22
22
23
23
/* Align to always be on 8-byte boundaries */
24
- next_heap_end = (void * )((((uintptr_t )heap_end + incr ) + 7 ) & ~7 );
24
+ next_heap_end = (void * )((((uintptr_t )prev_heap_end + incr ) + 7 ) & ~7 );
25
25
26
26
/* Check if this allocation would exceed the end of the ram - would probably get into the stack first however */
27
27
if (next_heap_end > stack_min ) {
You can’t perform that action at this time.
0 commit comments