From 1c975959fb8dff563a82409152f50f54eff03f76 Mon Sep 17 00:00:00 2001
From: dongheng <Dong Heng>
Date: Wed, 6 Mar 2019 10:26:11 +0800
Subject: [PATCH] feat(heap): Link heap to IRAM

---
 components/esp8266/ld/esp8266.common.ld         |  2 ++
 components/esp8266/source/esp_wifi_os_adapter.c | 10 +++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/components/esp8266/ld/esp8266.common.ld b/components/esp8266/ld/esp8266.common.ld
index f35ca08a..2894f55e 100644
--- a/components/esp8266/ld/esp8266.common.ld
+++ b/components/esp8266/ld/esp8266.common.ld
@@ -133,6 +133,8 @@ SECTIONS
     *libesp8266.a:ets_printf.o(.literal .text .literal.* .text.* .rodata.* .rodata)
 #endif
 
+    *libheap.a:(.literal .text .literal.* .text.*)
+
     _text_end = ABSOLUTE(.);
     _etext = .;
   } >iram1_0_seg :iram1_0_phdr
diff --git a/components/esp8266/source/esp_wifi_os_adapter.c b/components/esp8266/source/esp_wifi_os_adapter.c
index 25aecacd..001b0b32 100644
--- a/components/esp8266/source/esp_wifi_os_adapter.c
+++ b/components/esp8266/source/esp_wifi_os_adapter.c
@@ -272,7 +272,7 @@ static bool timer_delete_wrapper(void *timer, uint32_t ticks)
     return xTimerDelete(timer, ticks);
 }
 
-static void *malloc_wrapper(uint32_t s, uint32_t cap, const char *file, size_t line)
+static void IRAM_ATTR *malloc_wrapper(uint32_t s, uint32_t cap, const char *file, size_t line)
 {
     uint32_t os_caps;
 
@@ -284,7 +284,7 @@ static void *malloc_wrapper(uint32_t s, uint32_t cap, const char *file, size_t l
     return _heap_caps_malloc(s, os_caps, file, line);
 }
 
-static void *zalloc_wrapper(uint32_t s, uint32_t cap, const char *file, size_t line)
+static void IRAM_ATTR *zalloc_wrapper(uint32_t s, uint32_t cap, const char *file, size_t line)
 {
     uint32_t os_caps;
 
@@ -296,7 +296,7 @@ static void *zalloc_wrapper(uint32_t s, uint32_t cap, const char *file, size_t l
     return _heap_caps_zalloc(s, os_caps, file, line);
 }
 
-static void *realloc_wrapper(void *ptr, uint32_t s, uint32_t cap, const char *file, size_t line)
+static void IRAM_ATTR *realloc_wrapper(void *ptr, uint32_t s, uint32_t cap, const char *file, size_t line)
 {
     uint32_t os_caps;
 
@@ -308,7 +308,7 @@ static void *realloc_wrapper(void *ptr, uint32_t s, uint32_t cap, const char *fi
     return _heap_caps_realloc(ptr, s, os_caps, file, line);
 }
 
-static void *calloc_wrapper(uint32_t cnt, uint32_t s, uint32_t cap, const char *file, size_t line)
+static void IRAM_ATTR *calloc_wrapper(uint32_t cnt, uint32_t s, uint32_t cap, const char *file, size_t line)
 {
     uint32_t os_caps;
 
@@ -320,7 +320,7 @@ static void *calloc_wrapper(uint32_t cnt, uint32_t s, uint32_t cap, const char *
     return _heap_caps_calloc(cnt , s, os_caps, file, line);
 }
 
-static void free_wrapper(void *ptr, const char *file, size_t line)
+static void IRAM_ATTR free_wrapper(void *ptr, const char *file, size_t line)
 {
     _heap_caps_free(ptr, file, line);
 }