|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2025 Project CHIP Authors |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <lib/support/CHIPMem.h> |
| 20 | +#include <platform/CHIPDeviceLayer.h> |
| 21 | + |
| 22 | +#include <esp_heap_caps.h> |
| 23 | +#include <stdlib.h> |
| 24 | + |
| 25 | +namespace chip { |
| 26 | +namespace Platform { |
| 27 | + |
| 28 | +CHIP_ERROR MemoryAllocatorInit(void * buf, size_t bufSize) |
| 29 | +{ |
| 30 | + return CHIP_NO_ERROR; |
| 31 | +} |
| 32 | + |
| 33 | +void MemoryAllocatorShutdown() {} |
| 34 | + |
| 35 | +void * MemoryAlloc(size_t size) |
| 36 | +{ |
| 37 | + return heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); |
| 38 | +} |
| 39 | + |
| 40 | +void * MemoryAlloc(size_t size, bool isLongTermAlloc) |
| 41 | +{ |
| 42 | + return heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); |
| 43 | +} |
| 44 | + |
| 45 | +void * MemoryCalloc(size_t num, size_t size) |
| 46 | +{ |
| 47 | + return heap_caps_calloc(num, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); |
| 48 | +} |
| 49 | + |
| 50 | +void * MemoryRealloc(void * p, size_t size) |
| 51 | +{ |
| 52 | + return heap_caps_realloc(p, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); |
| 53 | +} |
| 54 | + |
| 55 | +void MemoryFree(void * p) |
| 56 | +{ |
| 57 | + heap_caps_free(p); |
| 58 | +} |
| 59 | + |
| 60 | +bool MemoryInternalCheckPointer(const void * p, size_t min_size) |
| 61 | +{ |
| 62 | + // We don't have a way to know if p is allocated from the heap, just do a null check here. |
| 63 | + return (p != nullptr); |
| 64 | +} |
| 65 | + |
| 66 | +} // namespace Platform |
| 67 | +} // namespace chip |
0 commit comments