2021-10-29 04:39:53 +00:00
|
|
|
/*
|
2022-03-03 04:04:39 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
2021-10-29 04:39:53 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2018-09-19 09:59:20 +00:00
|
|
|
|
|
|
|
#include <esp_attr.h>
|
|
|
|
#include <esp_heap_caps.h>
|
|
|
|
#include <sdkconfig.h>
|
2018-11-11 07:44:54 +00:00
|
|
|
#include "esp_mem.h"
|
2018-09-19 09:59:20 +00:00
|
|
|
|
|
|
|
#ifndef CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC
|
|
|
|
|
2023-08-10 08:35:22 +00:00
|
|
|
void *esp_mbedtls_mem_calloc(size_t n, size_t size)
|
2018-09-19 09:59:20 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC
|
|
|
|
return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
|
|
|
#elif CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC
|
|
|
|
return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT);
|
2020-02-26 12:21:59 +00:00
|
|
|
#elif CONFIG_MBEDTLS_IRAM_8BIT_MEM_ALLOC
|
|
|
|
#ifdef CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN
|
|
|
|
if ((n*size) >= CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN || (n*size) >= CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN) {
|
|
|
|
#else
|
|
|
|
if ((n*size) >= CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN) {
|
|
|
|
#endif
|
|
|
|
return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
|
|
|
} else {
|
|
|
|
return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
|
|
|
}
|
|
|
|
|
2018-09-19 09:59:20 +00:00
|
|
|
#else
|
|
|
|
return calloc(n, size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-08-10 08:35:22 +00:00
|
|
|
void esp_mbedtls_mem_free(void *ptr)
|
2018-09-19 09:59:20 +00:00
|
|
|
{
|
|
|
|
return heap_caps_free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC */
|