diff --git a/common/mbed_alloc_wrappers.cpp b/common/mbed_alloc_wrappers.cpp new file mode 100644 index 0000000..2f17200 --- /dev/null +++ b/common/mbed_alloc_wrappers.cpp @@ -0,0 +1,64 @@ +#include 






 +#include 



 +#include 



 +#include + +/******************************************************************************/ +/* GCC memory allocation wrappers */ +/******************************************************************************/ + +#if defined(TOOLCHAIN_GCC) + +extern "C" { + void *__real__malloc_r(struct _reent *r, size_t size); + void *__real__memalign_r(struct _reent *r, size_t alignment, size_t bytes); + void *__real__realloc_r(struct _reent *r, void *ptr, size_t size); + void __real__free_r(struct _reent *r, void *ptr); + void *__real__calloc_r(struct _reent *r, size_t nmemb, size_t size); + void *malloc_wrapper(struct _reent *r, size_t size, void *caller); + void free_wrapper(struct _reent *r, void *ptr, void *caller); +} + + +extern "C" void *__wrap__malloc_r(struct _reent *r, size_t size) +{ + return malloc_wrapper(r, size, __builtin_extract_return_addr(__builtin_return_address(0))); +} + +extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller) +{ + void *ptr = NULL; + ptr = __real__malloc_r(r, size); + return ptr; +} + +extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size) +{ + void *new_ptr = NULL; + new_ptr = __real__realloc_r(r, ptr, size); + return new_ptr; +} + +extern "C" void __wrap__free_r(struct _reent *r, void *ptr) +{ + free_wrapper(r, ptr, __builtin_extract_return_addr(__builtin_return_address(0))); +} + +extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller) +{ + __real__free_r(r, ptr); +} + +extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size) +{ + void *ptr = NULL; + ptr = __real__calloc_r(r, nmemb, size); + return ptr; +} + +extern "C" void *__wrap__memalign_r(struct _reent *r, size_t alignment, size_t bytes) +{ + return __real__memalign_r(r, alignment, bytes); +} + +#endif // #if defined(TOOLCHAIN_GCC) diff --git a/common/retarget.cpp b/common/retarget.cpp index 82411ab..13f2ace 100644 --- a/common/retarget.cpp +++ b/common/retarget.cpp @@ -524,6 +524,40 @@ extern "C" void exit(int return_code) { } //namespace std #endif +#if defined(TOOLCHAIN_GCC) + +/* + * Depending on how newlib is configured, it is often not enough to define + * __aeabi_atexit, __cxa_atexit and __cxa_finalize in order to override the + * behavior regarding the registration of handlers with atexit. + * + * To overcome this limitation, exit and atexit are overriden here. + */ +extern "C" { + + /** + * @brief Retarget of exit for GCC. + * @details Unlike the standard version, this function doesn't call any function + * registered with atexit before calling _exit. + */ + void __wrap_exit(int return_code) + { + _exit(return_code); + } + + /** + * @brief Retarget atexit from GCC. + * @details This function will always fail and never register any handler to be + * called at exit. + */ + int __wrap_atexit(void (*func)()) + { + return 1; + } + +} + +#endif namespace mbed { diff --git a/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_ARM_STD/sys.cpp b/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_ARM_STD/sys.cpp index 2f1024a..ac6a153 100644 --- a/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_ARM_STD/sys.cpp +++ b/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_ARM_STD/sys.cpp @@ -12,6 +12,11 @@ extern "C" { #include #include +#if __ARMCC_VERSION >= 6000000 +#include +#endif + + extern char Image$$RW_IRAM1$$ZI$$Limit[]; extern __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) { diff --git a/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S110/NRF51822.ld b/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S110/NRF51822.ld index 43e0ac8..cb472e5 100644 --- a/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S110/NRF51822.ld +++ b/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_GCC_ARM/TARGET_MCU_NRF51_16K_S110/NRF51822.ld @@ -2,7 +2,7 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x00016000, LENGTH = 0x2A000 + FLASH (rx) : ORIGIN = 0x00018000, LENGTH = 0x28000 RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 }