修复了一个malloc的问题

This commit is contained in:
2026-09-18 17:46:46 +08:00
parent 2553f30fb8
commit acd29d76d9
9 changed files with 941 additions and 37 deletions
+34
View File
@@ -8,10 +8,13 @@
* 创建日期:2026-09-14
* 修改记录:
* v1.0 2026-09-14 王建锋 创建初始版本
* v1.1 2026-09-18 王建锋 增 cfg_store_alloc / cfg_store_free / cfg_store_heap_free
* (宿主 CRT 堆实现,对齐 MCU 端 FreeRTOS 堆语义,P0-1)
*/
/* 头文件包含区 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@@ -149,3 +152,34 @@ const char *cfg_store_tmp_path(void) {
const char *cfg_store_legacy_path(void) {
return s_path_legacy;
}
/*
* 函数功能:分配共享核心临时缓冲(宿主 CRT 堆)
* 入口参数:size - 字节数 size_t
* 返回值:缓冲指针(内容未清零);失败返回 NULL void *
* 限定条件:释放必须用 cfg_store_free
* 函数说明:模拟器进程堆以 MB 计,直接 malloc;与 MCU 端差异仅在本后端
*/
void *cfg_store_alloc(size_t size) {
return malloc(size);
}
/*
* 函数功能:释放 cfg_store_alloc 分配的临时缓冲
* 入口参数:p_buf - 缓冲指针(NULL 安全) void *
* 返回值:无
* 限定条件:p_buf 必须来自 cfg_store_alloc
*/
void cfg_store_free(void *p_buf) {
free(p_buf);
}
/*
* 函数功能:空闲堆字节数(诊断用)
* 入口参数:无
* 返回值:恒 0(宿主 CRT 不提供可移植的空闲堆查询) uint32_t
* 限定条件:无
*/
uint32_t cfg_store_heap_free(void) {
return 0u;
}