1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 #ifndef SAL_MEMIMPL_H 17 #define SAL_MEMIMPL_H 18 19 #include <stdint.h> 20 #include "hitls_build.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * @ingroup bsl_sal 28 * 29 * Registrable function structure for memory allocation/release. 30 */ 31 typedef struct MemCallback { 32 /** 33 * @ingroup bsl_sal 34 * @brief Allocate a memory block. 35 * 36 * Allocate a memory block. 37 * 38 * @param size [IN] Size of the allocated memory. 39 * @retval: Not NULL, The start address of the allocated memory when memory is allocated successfully. 40 * @retval NULL, Memory allocation failure. 41 */ 42 void *(*pfMalloc)(uint32_t size); 43 44 /** 45 * @ingroup bsl_sal 46 * @brief Reclaim a memory block allocated by pfMalloc. 47 * 48 * Reclaim a block of memory allocated by pfMalloc. 49 * 50 * @param addr [IN] Start address of the memory allocated by pfMalloc. 51 */ 52 void (*pfFree)(void *addr); 53 } BSL_SAL_MemCallback; 54 55 int32_t SAL_MemCallBack_Ctrl(BSL_SAL_CB_FUNC_TYPE type, void *funcCb); 56 57 #if defined(HITLS_BSL_SAL_MEM) && defined(HITLS_BSL_SAL_LINUX) 58 void *SAL_MallocImpl(uint32_t size); 59 60 void SAL_FreeImpl(void *value); 61 #endif 62 63 #ifdef __cplusplus 64 } 65 #endif 66 67 #endif // SAL_MEMIMPL_H 68