Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom heap #1745

Merged
merged 3 commits into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sming/Arch/Esp8266/Components/custom_heap/component.mk
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# umm_malloc (custom heap allocation)

COMPONENT_SUBMODULES := umm_malloc
COMPONENT_SRCDIRS := . umm_malloc/src
COMPONENT_SRCDIRS :=
COMPONENT_SRCFILES := heap.c umm_malloc/src/umm_malloc.c
COMPONENT_INCDIRS := umm_malloc/src umm_malloc/includes/c-helper-macros

LIBMAIN = mainmm
LIBMAIN_SRC = $(COMPONENT_LIBDIR)/libmainmm.a
COMPONENT_TARGETS += $(LIBMAIN_SRC)

COMPONENT_VARS += UMM_POISON_CHECK
ifeq ($(UMM_POISON_CHECK),1)
GLOBAL_CFLAGS += -DUMM_POISON_CHECK
endif

# Make copy of libmain and remove mem_manager.o module
$(COMPONENT_RULE)$(LIBMAIN_SRC): $(SDK_LIBDIR)/libmain.a
$(info Enabling custom heap implementation)
Expand Down
17 changes: 12 additions & 5 deletions Sming/Arch/Esp8266/Components/custom_heap/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,36 @@

#define IRAM_ATTR __attribute__((section(".iram.text")))

#ifdef UMM_POISON_CHECK
#define UMM_FUNC(f) umm_poison_##f
#else
#define UMM_FUNC(f) umm_##f
#endif


void* IRAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
{
return malloc(size);
return UMM_FUNC(malloc)(size);
}

void IRAM_ATTR vPortFree(void *ptr, const char* file, int line)
{
free(ptr);
UMM_FUNC(free)(ptr);
}

void* IRAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
{
return calloc(count, size);
return UMM_FUNC(calloc)(count, size);
}

void* IRAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line)
{
return realloc(ptr, size);
return UMM_FUNC(realloc)(ptr, size);
}

void* IRAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
{
return calloc(1, size);
return UMM_FUNC(calloc)(1, size);
}

void* IRAM_ATTR pvPortZallocIram(size_t size, const char* file, int line) __attribute__ ((weak, alias("pvPortZalloc")));
Expand Down
33 changes: 18 additions & 15 deletions Sming/Arch/Esp8266/Components/custom_heap/umm_malloc.patch
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
diff --git a/src/umm_malloc_cfg.h b/src/umm_malloc_cfg.h
index fcc4fb1..661b94a 100644
index 6a5a7fc..a581100 100644
--- a/src/umm_malloc_cfg.h
+++ b/src/umm_malloc_cfg.h
@@ -5,6 +5,25 @@
@@ -5,6 +5,24 @@
#ifndef _UMM_MALLOC_CFG_H
#define _UMM_MALLOC_CFG_H

+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <c_types.h>
+#include <m_printf.h>
+
+#ifdef __cplusplus
+}
+extern "C" {
+#endif
+
+#ifdef __ets__
+// ESP specific code
+extern void ets_intr_lock();
+extern void ets_intr_unlock();
+extern void ets_printf(const char*, ...);
+
+#define printf ets_printf
+#define puts(...) ets_printf("%s",...)
+#define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text")))
+#ifdef UMM_MALLOC_H
+#define printf m_printf
+#define puts m_puts
+#endif
+
+#define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text")))
+
/*
* There are a number of defines you can set at compile time that affect how
* the memory allocator will operate.
@@ -51,11 +70,11 @@
@@ -39,11 +57,11 @@
* ----------------------------------------------------------------------------
*/

Expand All @@ -43,7 +42,7 @@ index fcc4fb1..661b94a 100644

/* A couple of macros to make packing structures less compiler dependent */

@@ -107,8 +126,8 @@ extern char test_umm_heap[];
@@ -95,8 +113,8 @@ extern char test_umm_heap[];
* called from within umm_malloc()
*/

Expand All @@ -54,7 +53,7 @@ index fcc4fb1..661b94a 100644

/*
* -D UMM_INTEGRITY_CHECK :
@@ -163,11 +182,11 @@ extern char test_umm_heap[];
@@ -151,11 +169,11 @@ extern char test_umm_heap[];
* callback is called: `UMM_HEAP_CORRUPTION_CB()`
*/

Expand All @@ -68,10 +67,14 @@ index fcc4fb1..661b94a 100644

#ifdef UMM_POISON_CHECK
void *umm_poison_malloc( size_t size );
@@ -180,4 +199,6 @@ extern char test_umm_heap[];
@@ -168,4 +186,10 @@ extern char test_umm_heap[];
# define POISON_CHECK() 0
#endif

+// #define UMM_HEAP_CORRUPTION_CB() panic()
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _UMM_MALLOC_CFG_H */