Jelajahi Sumber

revert: 回退内存管理到原有的方式,因为新的方式总不时会崩, 还原因未知, 保险期间还是回退吧

Wendal Chen 2 tahun lalu
induk
melakukan
d644d7494f

+ 4 - 7
app/port/luat_malloc_air101.c

@@ -126,24 +126,21 @@ void* luat_heap_calloc(size_t count, size_t _size) {
 }
 #else
 void* luat_heap_malloc(size_t len) {
-    if (len == 212) {
-        printf("luat_heap_malloc %d\n", len);
-    }
-    return __wrap_malloc(len);
+    return malloc(len);
 }
 
 void luat_heap_free(void* ptr) {
     if (ptr == NULL)
         return;
-    __wrap_free(ptr);
+    free(ptr);
 }
 
 void* luat_heap_realloc(void* ptr, size_t len) {
-    return __wrap_realloc(ptr, len);
+    return realloc(ptr, len);
 }
 
 void* luat_heap_calloc(size_t count, size_t _size) {
-    return __wrap_calloc(count, _size);
+    return calloc(count, _size);
 }
 #endif
 

+ 1 - 1
platform/common/mem/wm_mem.c

@@ -17,7 +17,7 @@
 #include "list.h"
 #include <string.h>
 
-#if 0
+#if 1
 
 extern u8 tls_get_isr_count(void);
 /**

+ 39 - 0
platform/common/mem/wm_mem2.c

@@ -3,12 +3,48 @@
 #include "list.h"
 #include <string.h>
 #include "FreeRTOS.h"
+#include "task.h"
 #include "stdio.h"
 
+#include "luat_conf_bsp.h"
+#if 0
+
+#ifdef LUAT_USE_PROFILER_XXX
+void * mem_alloc_debug(u32 size) {
+    void* ptr = malloc(size);
+    printf("mem_alloc_debug %p %d\n", ptr, size);
+    return ptr;
+}
+void mem_free_debug(void *ptr) {
+    printf("mem_free_debug %p\n", ptr);
+    free(ptr);
+}
+void * mem_realloc_debug(void *mem_address, u32 size) {
+    void* ptr = realloc(mem_address, size);
+    printf("mem_realloc_debug %p %d %p\n", mem_address, size, ptr);
+    return ptr;
+}
+
+void *mem_calloc_debug(u32 length, u32 size) {
+    void* ptr = calloc(length, size);
+    printf("mem_calloc_debug %p %d\n", ptr, size * length);
+    return ptr;
+}
+#else
+TaskStatus_t stat;
 void * mem_alloc_debug(u32 size) {
+    if (size == 16) {
+        printf("mem_alloc_debug %d\n", size);
+        TaskHandle_t t = xTaskGetCurrentTaskHandle();
+        if (t != NULL) {
+            vTaskGetInfo(t, &stat, pdFALSE, eInvalid);
+            printf("task %s %d\n", stat.pcTaskName, stat.xTaskNumber);
+        }
+    }
     return malloc(size);
 }
 void mem_free_debug(void *p) {
+    // printf("free %p\n", p);
     free(p);
 }
 void * mem_realloc_debug(void *mem_address, u32 size) {
@@ -18,3 +54,6 @@ void * mem_realloc_debug(void *mem_address, u32 size) {
 void *mem_calloc_debug(u32 length, u32 size) {
     return calloc(length, size);
 }
+#endif
+
+#endif

+ 2 - 2
src/os/rtos/include/FreeRTOSConfig.h

@@ -77,13 +77,13 @@
 #define configTICK_RATE_HZ			( ( portTickType ) 1000u )	
 #define configMAX_PRIORITIES		(63)
 #define configMINIMAL_STACK_SIZE	( ( unsigned short ) 256 )	
-#define configTOTAL_HEAP_SIZE		( ( size_t ) 24 * 1024 )	
+#define configTOTAL_HEAP_SIZE		( ( size_t ) 12 * 1024 )	
 #define configMAX_TASK_NAME_LEN		( 10 )	//创建任务名称最大允许长度
 #define configUSE_TRACE_FACILITY	1		
 #define configUSE_16_BIT_TICKS		0	
 #define configIDLE_SHOULD_YIELD		1	
 #define configUSE_HEAP3				0
-#define configUSE_HEAP4				1
+#define configUSE_HEAP4				0
 
 #define configQUEUE_REGISTRY_SIZE 	0
 #define configSEMAPHORE_INIT_VALUE	5	

+ 5 - 5
xmake.lua

@@ -106,11 +106,11 @@ add_includedirs("include/arch/xt804/csi_dsp")
 add_includedirs("platform/sys")
 add_includedirs("src/app/mbedtls/ports")
 
-add_ldflags(" -Wl,--wrap=malloc ",{force = true})
-add_ldflags(" -Wl,--wrap=free ",{force = true})
-add_ldflags(" -Wl,--wrap=zalloc ",{force = true})
-add_ldflags(" -Wl,--wrap=calloc ",{force = true})
-add_ldflags(" -Wl,--wrap=realloc ",{force = true})
+-- add_ldflags(" -Wl,--wrap=malloc ",{force = true})
+-- add_ldflags(" -Wl,--wrap=free ",{force = true})
+-- add_ldflags(" -Wl,--wrap=zalloc ",{force = true})
+-- add_ldflags(" -Wl,--wrap=calloc ",{force = true})
+-- add_ldflags(" -Wl,--wrap=realloc ",{force = true})
 add_ldflags(" -Wl,--wrap=localtime ",{force = true})
 add_ldflags(" -Wl,--wrap=gmtime ",{force = true})
 add_ldflags(" -Wl,--wrap=mktime ",{force = true})