135375f98Sopenharmony_ci/* ========================================== 235375f98Sopenharmony_ci * Unity Project - A Test Framework for C 335375f98Sopenharmony_ci * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 435375f98Sopenharmony_ci * [Released under MIT License. Please refer to license.txt for details] 535375f98Sopenharmony_ci * ========================================== */ 635375f98Sopenharmony_ci 735375f98Sopenharmony_ci#ifndef UNITY_MEMORY_OVERRIDES_H_ 835375f98Sopenharmony_ci#define UNITY_MEMORY_OVERRIDES_H_ 935375f98Sopenharmony_ci 1035375f98Sopenharmony_ci#ifdef __cplusplus 1135375f98Sopenharmony_ciextern "C" 1235375f98Sopenharmony_ci{ 1335375f98Sopenharmony_ci#endif 1435375f98Sopenharmony_ci 1535375f98Sopenharmony_ci#include <stddef.h> 1635375f98Sopenharmony_ci 1735375f98Sopenharmony_ci#ifdef UNITY_EXCLUDE_STDLIB_MALLOC 1835375f98Sopenharmony_ci/* Define this macro to remove the use of stdlib.h, malloc, and free. 1935375f98Sopenharmony_ci * Many embedded systems do not have a heap or malloc/free by default. 2035375f98Sopenharmony_ci * This internal unity_malloc() provides allocated memory deterministically from 2135375f98Sopenharmony_ci * the end of an array only, unity_free() only releases from end-of-array, 2235375f98Sopenharmony_ci * blocks are not coalesced, and memory not freed in LIFO order is stranded. */ 2335375f98Sopenharmony_ci #ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES 2435375f98Sopenharmony_ci #define UNITY_INTERNAL_HEAP_SIZE_BYTES 256 2535375f98Sopenharmony_ci #endif 2635375f98Sopenharmony_ci#endif 2735375f98Sopenharmony_ci 2835375f98Sopenharmony_ci/* These functions are used by Unity to allocate and release memory 2935375f98Sopenharmony_ci * on the heap and can be overridden with platform-specific implementations. 3035375f98Sopenharmony_ci * For example, when using FreeRTOS UNITY_MALLOC becomes pvPortMalloc() 3135375f98Sopenharmony_ci * and UNITY_FREE becomes vPortFree(). */ 3235375f98Sopenharmony_ci#if !defined(UNITY_MALLOC) || !defined(UNITY_FREE) 3335375f98Sopenharmony_ci #include <stdlib.h> 3435375f98Sopenharmony_ci #define UNITY_MALLOC(size) malloc(size) 3535375f98Sopenharmony_ci #define UNITY_FREE(ptr) free(ptr) 3635375f98Sopenharmony_ci#else 3735375f98Sopenharmony_ci extern void* UNITY_MALLOC(size_t size); 3835375f98Sopenharmony_ci extern void UNITY_FREE(void* ptr); 3935375f98Sopenharmony_ci#endif 4035375f98Sopenharmony_ci 4135375f98Sopenharmony_ci#define malloc unity_malloc 4235375f98Sopenharmony_ci#define calloc unity_calloc 4335375f98Sopenharmony_ci#define realloc unity_realloc 4435375f98Sopenharmony_ci#define free unity_free 4535375f98Sopenharmony_ci 4635375f98Sopenharmony_civoid* unity_malloc(size_t size); 4735375f98Sopenharmony_civoid* unity_calloc(size_t num, size_t size); 4835375f98Sopenharmony_civoid* unity_realloc(void * oldMem, size_t size); 4935375f98Sopenharmony_civoid unity_free(void * mem); 5035375f98Sopenharmony_ci 5135375f98Sopenharmony_ci/* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */ 5235375f98Sopenharmony_civoid UnityMalloc_StartTest(void); 5335375f98Sopenharmony_civoid UnityMalloc_EndTest(void); 5435375f98Sopenharmony_civoid UnityMalloc_MakeMallocFailAfterCount(int countdown); 5535375f98Sopenharmony_ci 5635375f98Sopenharmony_ci#ifdef __cplusplus 5735375f98Sopenharmony_ci} 5835375f98Sopenharmony_ci#endif 5935375f98Sopenharmony_ci 6035375f98Sopenharmony_ci#endif 61