bsp,am,integrate-am-apps: fix heap smash

* now pass microbench
This commit is contained in:
Zihao Yu 2024-01-12 20:18:37 +08:00
parent f08882db2c
commit 9c8b8c3289
2 changed files with 10 additions and 0 deletions

View file

@ -52,6 +52,7 @@ def integrate(app_dir):
os.remove(redefine_sym_file) os.remove(redefine_sym_file)
am_app_c_fp.write(f"""extern int __am_{app_name}_main(const char *); am_app_c_fp.write(f"""extern int __am_{app_name}_main(const char *);
static void am_{app_name}(int argc, char *argv[]) {{ static void am_{app_name}(int argc, char *argv[]) {{
heap = am_apps_heap;
__am_{app_name}_main(argc >= 2 ? argv[1] : ""); __am_{app_name}_main(argc >= 2 ? argv[1] : "");
}} }}
MSH_CMD_EXPORT(am_{app_name}, AM {app_name});""") MSH_CMD_EXPORT(am_{app_name}, AM {app_name});""")
@ -62,6 +63,7 @@ read_lib_symbols("klib")
am_app_mk_fp.write("SRCS += build/am-apps.c\n") am_app_mk_fp.write("SRCS += build/am-apps.c\n")
am_app_c_fp.write("""#include <am.h> am_app_c_fp.write("""#include <am.h>
#include <rtthread.h> #include <rtthread.h>
extern Area am_apps_heap;
bool __dummy_ioe_init() { return true; } bool __dummy_ioe_init() { return true; }
bool __dummy_cte_init(Context *(*handler)(Event ev, Context *ctx)) { return true; } bool __dummy_cte_init(Context *(*handler)(Event ev, Context *ctx)) { return true; }
bool __dummy_vme_init(void *(*pgalloc)(int), void (*pgfree)(void *)) { return true; } bool __dummy_vme_init(void *(*pgalloc)(int), void (*pgfree)(void *)) { return true; }

View file

@ -2,9 +2,12 @@
#include <rtthread.h> #include <rtthread.h>
#include <klib-macros.h> #include <klib-macros.h>
#define AM_APPS_HEAP_SIZE 0x2000000
#define RT_HW_HEAP_BEGIN heap.start #define RT_HW_HEAP_BEGIN heap.start
#define RT_HW_HEAP_END heap.end #define RT_HW_HEAP_END heap.end
Area am_apps_heap;
void rt_hw_board_init() { void rt_hw_board_init() {
int rt_hw_uart_init(void); int rt_hw_uart_init(void);
rt_hw_uart_init(); rt_hw_uart_init();
@ -14,6 +17,11 @@ void rt_hw_board_init() {
rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END); rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
#endif #endif
uint32_t size = AM_APPS_HEAP_SIZE;
void *p = NULL;
for (; p == NULL && size != 0; size /= 2) { p = rt_malloc(size); }
am_apps_heap = (Area) { .start = p, .end = p + size };
#ifdef RT_USING_CONSOLE #ifdef RT_USING_CONSOLE
/* set console device */ /* set console device */
rt_console_set_device("uart"); rt_console_set_device("uart");