Skip to content

Commit 339140c

Browse files
committed
Use umm_malloc for heap management
1 parent 2e1be32 commit 339140c

File tree

11 files changed

+2479
-16
lines changed

11 files changed

+2479
-16
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@ Espressif SDK included in this build is under Espressif MIT License.
101101
ESP8266 core files are licensed under LGPL.
102102

103103
[SPI Flash File System (SPIFFS)](https://github.com/pellepl/spiffs) written by Peter Andersson is used in this project. It is distributed under MIT license.
104+
105+
[umm_malloc](https://github.com/rhempel/umm_malloc) memory management library written by Ralph Hempel is used in this project. It is distributed under MIT license.

cores/esp8266/heap.c

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* heap.c - overrides of SDK heap handling functions
2+
* Copyright (c) 2016 Ivan Grokhotkov. All rights reserved.
3+
* This file is distributed under MIT license.
4+
*/
5+
6+
#include <stdlib.h>
7+
#include "umm_malloc/umm_malloc.h"
8+
#include <c_types.h>
9+
10+
void* ICACHE_RAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
11+
{
12+
return malloc(size);
13+
}
14+
15+
void ICACHE_RAM_ATTR vPortFree(void *ptr, const char* file, int line)
16+
{
17+
free(ptr);
18+
}
19+
20+
void* ICACHE_RAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
21+
{
22+
return calloc(count, size);
23+
}
24+
25+
void* ICACHE_RAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line)
26+
{
27+
return realloc(ptr, size);
28+
}
29+
30+
void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
31+
{
32+
return calloc(1, size);
33+
}
34+
35+
size_t ICACHE_RAM_ATTR xPortGetFreeHeapSize(void)
36+
{
37+
return umm_free_heap_size();
38+
}
39+
40+
void system_show_malloc(void)
41+
{
42+
umm_info(NULL, 1);
43+
}

cores/esp8266/libc_replacements.c

+1-15
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,8 @@
3939
#include "user_interface.h"
4040
#include "debug.h"
4141

42-
void* ICACHE_RAM_ATTR malloc(size_t size) {
43-
size = ((size + 3) & ~((size_t)0x3));
44-
return os_malloc(size);
45-
}
46-
47-
void ICACHE_RAM_ATTR free(void* ptr) {
48-
os_free(ptr);
49-
}
50-
51-
void* ICACHE_RAM_ATTR realloc(void* ptr, size_t size) {
52-
size = ((size + 3) & ~((size_t)0x3));
53-
return os_realloc(ptr, size);
54-
}
55-
5642
int ICACHE_RAM_ATTR puts(const char * str) {
57-
return os_printf("%s", str);
43+
return ets_printf("%s", str);
5844
}
5945

6046
int ICACHE_RAM_ATTR printf(const char* format, ...) {

cores/esp8266/umm_malloc/LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Ralph Hempel
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

0 commit comments

Comments
 (0)