mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: platform/mbed_alloc_wrappers.cpp
- Revision:
- 189:f392fc9709a3
- Parent:
- 188:bcfe06ba3d64
diff -r bcfe06ba3d64 -r f392fc9709a3 platform/mbed_alloc_wrappers.cpp --- a/platform/mbed_alloc_wrappers.cpp Thu Nov 08 11:46:34 2018 +0000 +++ b/platform/mbed_alloc_wrappers.cpp Wed Feb 20 22:31:08 2019 +0000 @@ -1,5 +1,6 @@ /* mbed Microcontroller Library * Copyright (c) 2006-2016 ARM Limited + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +28,7 @@ /* There are two memory tracers in mbed OS: - the first can be used to detect the maximum heap usage at runtime. It is - activated by defining the MBED_HEAP_STATS_ENABLED macro. + activated by setting the configuration option MBED_HEAP_STATS_ENABLED to true. - the second can be used to trace each memory call by automatically invoking a callback on each memory operation (see hal/api/mbed_mem_trace.h). It is activated by setting the configuration option MBED_MEM_TRACING_ENABLED to true. @@ -53,7 +54,7 @@ typedef struct { size_t size; -}mbed_heap_overhead_t; +} mbed_heap_overhead_t; #define MALLOC_HEADER_SIZE (sizeof(mbed_heap_overhead_t)) #define MALLOC_HEADER_PTR(p) (mbed_heap_overhead_t *)((char *)(p) - MALLOC_HEADER_SIZE) @@ -99,7 +100,7 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller) { void *ptr = NULL; -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_lock(); #endif #ifdef MBED_HEAP_STATS_ENABLED @@ -123,17 +124,17 @@ #else // #ifdef MBED_HEAP_STATS_ENABLED ptr = __real__malloc_r(r, size); #endif // #ifdef MBED_HEAP_STATS_ENABLED -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_malloc(ptr, size, caller); mbed_mem_trace_unlock(); -#endif // #if MBED_MEM_TRACING_ENABLED +#endif // #ifdef MBED_MEM_TRACING_ENABLED return ptr; } extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size) { void *new_ptr = NULL; -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_lock(); #endif #ifdef MBED_HEAP_STATS_ENABLED @@ -166,10 +167,10 @@ #else // #ifdef MBED_HEAP_STATS_ENABLED new_ptr = __real__realloc_r(r, ptr, size); #endif // #ifdef MBED_HEAP_STATS_ENABLED -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR()); mbed_mem_trace_unlock(); -#endif // #if MBED_MEM_TRACING_ENABLED +#endif // #ifdef MBED_MEM_TRACING_ENABLED return new_ptr; } @@ -180,7 +181,7 @@ extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller) { -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_lock(); #endif #ifdef MBED_HEAP_STATS_ENABLED @@ -205,16 +206,16 @@ #else // #ifdef MBED_HEAP_STATS_ENABLED __real__free_r(r, ptr); #endif // #ifdef MBED_HEAP_STATS_ENABLED -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_free(ptr, caller); mbed_mem_trace_unlock(); -#endif // #if MBED_MEM_TRACING_ENABLED +#endif // #ifdef MBED_MEM_TRACING_ENABLED } extern "C" void *__wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size) { void *ptr = NULL; -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_lock(); #endif #ifdef MBED_HEAP_STATS_ENABLED @@ -227,10 +228,10 @@ #else // #ifdef MBED_HEAP_STATS_ENABLED ptr = __real__calloc_r(r, nmemb, size); #endif // #ifdef MBED_HEAP_STATS_ENABLED -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR()); mbed_mem_trace_unlock(); -#endif // #if MBED_MEM_TRACING_ENABLED +#endif // #ifdef MBED_MEM_TRACING_ENABLED return ptr; } @@ -286,7 +287,7 @@ extern "C" void *malloc_wrapper(size_t size, void *caller) { void *ptr = NULL; -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_lock(); #endif #ifdef MBED_HEAP_STATS_ENABLED @@ -310,10 +311,10 @@ #else // #ifdef MBED_HEAP_STATS_ENABLED ptr = SUPER_MALLOC(size); #endif // #ifdef MBED_HEAP_STATS_ENABLED -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_malloc(ptr, size, caller); mbed_mem_trace_unlock(); -#endif // #if MBED_MEM_TRACING_ENABLED +#endif // #ifdef MBED_MEM_TRACING_ENABLED return ptr; } @@ -321,7 +322,7 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size) { void *new_ptr = NULL; -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_lock(); #endif #ifdef MBED_HEAP_STATS_ENABLED @@ -349,17 +350,17 @@ #else // #ifdef MBED_HEAP_STATS_ENABLED new_ptr = SUPER_REALLOC(ptr, size); #endif // #ifdef MBED_HEAP_STATS_ENABLED -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR()); mbed_mem_trace_unlock(); -#endif // #if MBED_MEM_TRACING_ENABLED +#endif // #ifdef MBED_MEM_TRACING_ENABLED return new_ptr; } extern "C" void *SUB_CALLOC(size_t nmemb, size_t size) { void *ptr = NULL; -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_lock(); #endif #ifdef MBED_HEAP_STATS_ENABLED @@ -371,10 +372,10 @@ #else // #ifdef MBED_HEAP_STATS_ENABLED ptr = SUPER_CALLOC(nmemb, size); #endif // #ifdef MBED_HEAP_STATS_ENABLED -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_calloc(ptr, nmemb, size, MBED_CALLER_ADDR()); mbed_mem_trace_unlock(); -#endif // #if MBED_MEM_TRACING_ENABLED +#endif // #ifdef MBED_MEM_TRACING_ENABLED return ptr; } @@ -385,7 +386,7 @@ extern "C" void free_wrapper(void *ptr, void *caller) { -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_lock(); #endif #ifdef MBED_HEAP_STATS_ENABLED @@ -410,10 +411,10 @@ #else // #ifdef MBED_HEAP_STATS_ENABLED SUPER_FREE(ptr); #endif // #ifdef MBED_HEAP_STATS_ENABLED -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED mbed_mem_trace_free(ptr, caller); mbed_mem_trace_unlock(); -#endif // #if MBED_MEM_TRACING_ENABLED +#endif // #ifdef MBED_MEM_TRACING_ENABLED } #endif // #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED) @@ -424,7 +425,7 @@ #else -#if MBED_MEM_TRACING_ENABLED +#ifdef MBED_MEM_TRACING_ENABLED #error Memory tracing is not supported with the current toolchain. #endif