From 3ed44ce0dcba0a6ac213cb2d0fc25baf3c66f6d5 Mon Sep 17 00:00:00 2001 From: Staars Date: Sun, 27 Mar 2022 17:54:18 +0200 Subject: [PATCH 1/2] use special_malloc for external libs --- .../ESP32-HomeKit/src/hap_platform_memory.c | 39 ---------------- .../nimble/esp_port/port/src/esp_nimble_mem.c | 44 ------------------- 2 files changed, 83 deletions(-) delete mode 100644 lib/libesp32_div/ESP32-HomeKit/src/hap_platform_memory.c delete mode 100644 lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.c diff --git a/lib/libesp32_div/ESP32-HomeKit/src/hap_platform_memory.c b/lib/libesp32_div/ESP32-HomeKit/src/hap_platform_memory.c deleted file mode 100644 index 361cd3e5f..000000000 --- a/lib/libesp32_div/ESP32-HomeKit/src/hap_platform_memory.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ESPRESSIF MIT License - * - * Copyright (c) 2019 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, - * it is free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ -#include - -void * hap_platform_memory_malloc(size_t size) -{ - return malloc(size); -} - -void * hap_platform_memory_calloc(size_t count, size_t size) -{ - return calloc(count, size); -} - -void hap_platform_memory_free(void *ptr) -{ - free(ptr); -} diff --git a/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.c b/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.c deleted file mode 100644 index 7e1899db6..000000000 --- a/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef ESP_PLATFORM - -#include "esp_attr.h" -#include "esp_heap_caps.h" -#include "nimconfig.h" -#include "../include/esp_nimble_mem.h" - -IRAM_ATTR void *nimble_platform_mem_malloc(size_t size) -{ -#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL - return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL - return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); -#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT - return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#else - return malloc(size); -#endif -} - -IRAM_ATTR void *nimble_platform_mem_calloc(size_t n, size_t size) -{ -#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL - return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL - return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); -#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT - return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#else - return calloc(n, size); -#endif -} - -IRAM_ATTR void nimble_platform_mem_free(void *ptr) -{ - heap_caps_free(ptr); -} -#endif From b8fd07346750a1d6a6edd694e96a6e81ea29c182 Mon Sep 17 00:00:00 2001 From: Staars Date: Sun, 27 Mar 2022 17:57:35 +0200 Subject: [PATCH 2/2] rename .c to .cpp --- .../ESP32-HomeKit/src/hap_platform_memory.cpp | 47 ++++++++++++++++ .../esp_port/port/src/esp_nimble_mem.cpp | 53 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 lib/libesp32_div/ESP32-HomeKit/src/hap_platform_memory.cpp create mode 100644 lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.cpp diff --git a/lib/libesp32_div/ESP32-HomeKit/src/hap_platform_memory.cpp b/lib/libesp32_div/ESP32-HomeKit/src/hap_platform_memory.cpp new file mode 100644 index 000000000..ad63fc0fc --- /dev/null +++ b/lib/libesp32_div/ESP32-HomeKit/src/hap_platform_memory.cpp @@ -0,0 +1,47 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2019 + * + * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, + * it is free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include + +//Tasmota Patch +extern void *special_malloc(uint32_t size); +extern void *special_calloc(size_t num, size_t size); + +extern "C" { +void * hap_platform_memory_malloc(size_t size) +{ + return special_malloc((uint32_t)size); + // return malloc(size); +} + +void * hap_platform_memory_calloc(size_t count, size_t size) +{ + return special_calloc(count,size); + // return calloc(count, size); +} + +void hap_platform_memory_free(void *ptr) +{ + free(ptr); +} +} //extern "C" \ No newline at end of file diff --git a/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.cpp b/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.cpp new file mode 100644 index 000000000..407091c7f --- /dev/null +++ b/lib/libesp32_div/NimBLE-Arduino/src/nimble/esp_port/port/src/esp_nimble_mem.cpp @@ -0,0 +1,53 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifdef ESP_PLATFORM + +#include "esp_attr.h" +#include "esp_heap_caps.h" +#include "nimconfig.h" +#include "../include/esp_nimble_mem.h" + +//Tasmota Patch +extern void *special_malloc(uint32_t size); +extern void *special_calloc(size_t num, size_t size); + + +extern "C" { +IRAM_ATTR void *nimble_platform_mem_malloc(size_t size) +{ + return special_malloc((uint32_t)size); +// #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL +// return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL +// return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT +// return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #else +// return malloc(size); +// #endif +} + +IRAM_ATTR void *nimble_platform_mem_calloc(size_t n, size_t size) +{ + return special_calloc(n,size); +// #ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL +// return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL +// return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); +// #elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT +// return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +// #else +// return calloc(n, size); +// #endif +} + +IRAM_ATTR void nimble_platform_mem_free(void *ptr) +{ + heap_caps_free(ptr); +} +} //extern "C" +#endif