Skip to content

Commit f81cf5d

Browse files
Niklas Hausermeriac
authored andcommitted
Add default implementation of malloc wrapping
For GCC malloc is always wrapped, but only used for FEATURE_UVISOR. Otherwise we have to simply forward the wrappers.
1 parent 5d48984 commit f81cf5d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

hal/common/retarget.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,23 @@ extern "C" WEAK void __cxa_pure_virtual(void) {
417417
#include "uvisor-lib/uvisor-lib.h"
418418
#endif/* FEATURE_UVISOR */
419419

420+
#ifndef FEATURE_UVISOR
421+
extern "C" {
422+
void * __wrap__malloc_r(struct _reent * r, size_t size) {
423+
extern void * __real__malloc_r(struct _reent * r, size_t size);
424+
return __real__malloc_r(r, size);
425+
}
426+
void * __wrap__realloc_r(struct _reent * r, void * ptr, size_t size) {
427+
extern void * __real__realloc_r(struct _reent * r, void * ptr, size_t size);
428+
return __real__realloc_r(r, ptr, size);
429+
}
430+
void __wrap__free_r(struct _reent * r, void * ptr) {
431+
extern void __real__free_r(struct _reent * r, void * ptr);
432+
__real__free_r(r, ptr);
433+
}
434+
}
435+
#endif/* FEATURE_UVISOR */
436+
420437
extern "C" WEAK void software_init_hook_rtos(void)
421438
{
422439
// Do nothing by default.

0 commit comments

Comments
 (0)