1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CHRE_EXTERNAL_MBEDTLS_MEMORY_H_ 18 #define CHRE_EXTERNAL_MBEDTLS_MEMORY_H_ 19 20 /** 21 * This header file provides wrappers around the CHRE memory allocation 22 * function @ref chreMemoryAlloc for use within the MbedTLS library. 23 */ 24 25 #include <stddef.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /** 32 * Allocates a contiguous zeroed out array with each element having the given 33 * item size. 34 * 35 * @param nItems Number of items to allocate. 36 * @param itemSize Size of an individual item. 37 * 38 * @return A pointer to the allocated memory if successful, nullptr otherwise. 39 */ 40 void *mbedtlsMemoryCalloc(size_t nItems, size_t itemSize); 41 42 /** 43 * Frees a previously allocated memory. 44 * 45 * @param ptr Pointer to be freed. 46 */ 47 void mbedtlsMemoryFree(void *ptr); 48 49 #ifdef __cplusplus 50 } // extern "C" 51 #endif 52 53 #endif // CHRE_EXTERNAL_MBEDTLS_MEMORY_H_