Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2345VOR
rt-thread
提交
09f439bc
R
rt-thread
项目概览
2345VOR
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
09f439bc
编写于
1月 01, 2022
作者:
还_没_想_好
提交者:
Bernard Xiong
1月 08, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[memheap] Fix 64 bit potential risk
上级
85441c0d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
43 addition
and
37 deletion
+43
-37
components/finsh/msh.c
components/finsh/msh.c
+1
-1
include/rtdef.h
include/rtdef.h
+3
-3
include/rtthread.h
include/rtthread.h
+6
-6
src/kservice.c
src/kservice.c
+3
-3
src/memheap.c
src/memheap.c
+30
-24
未找到文件。
components/finsh/msh.c
浏览文件 @
09f439bc
...
...
@@ -71,7 +71,7 @@ MSH_CMD_EXPORT_ALIAS(cmd_ps, ps, List threads in the system.);
#ifdef RT_USING_HEAP
int
cmd_free
(
int
argc
,
char
**
argv
)
{
rt_
uint32
_t
total
=
0
,
used
=
0
,
max_used
=
0
;
rt_
size
_t
total
=
0
,
used
=
0
,
max_used
=
0
;
rt_memory_info
(
&
total
,
&
used
,
&
max_used
);
rt_kprintf
(
"total : %d
\n
"
,
total
);
...
...
include/rtdef.h
浏览文件 @
09f439bc
...
...
@@ -927,9 +927,9 @@ struct rt_memheap
void
*
start_addr
;
/**< pool start address and size */
rt_
uint32_t
pool_size
;
/**< pool size */
rt_
uint32_t
available_size
;
/**< available size */
rt_
uint32_t
max_used_size
;
/**< maximum allocated size */
rt_
size_t
pool_size
;
/**< pool size */
rt_
size_t
available_size
;
/**< available size */
rt_
size_t
max_used_size
;
/**< maximum allocated size */
struct
rt_memheap_item
*
block_list
;
/**< used block list */
...
...
include/rtthread.h
浏览文件 @
09f439bc
...
...
@@ -266,9 +266,9 @@ void *rt_calloc(rt_size_t count, rt_size_t size);
void
*
rt_malloc_align
(
rt_size_t
size
,
rt_size_t
align
);
void
rt_free_align
(
void
*
ptr
);
void
rt_memory_info
(
rt_
uint32
_t
*
total
,
rt_
uint32
_t
*
used
,
rt_
uint32
_t
*
max_used
);
void
rt_memory_info
(
rt_
size
_t
*
total
,
rt_
size
_t
*
used
,
rt_
size
_t
*
max_used
);
#if defined(RT_USING_SLAB) && defined(RT_USING_SLAB_AS_HEAP)
void
*
rt_page_alloc
(
rt_size_t
npages
);
...
...
@@ -308,9 +308,9 @@ void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size);
void
*
rt_memheap_realloc
(
struct
rt_memheap
*
heap
,
void
*
ptr
,
rt_size_t
newsize
);
void
rt_memheap_free
(
void
*
ptr
);
void
rt_memheap_info
(
struct
rt_memheap
*
heap
,
rt_
uint32
_t
*
total
,
rt_
uint32
_t
*
used
,
rt_
uint32
_t
*
max_used
);
rt_
size
_t
*
total
,
rt_
size
_t
*
used
,
rt_
size
_t
*
max_used
);
#endif
#ifdef RT_USING_SLAB
...
...
src/kservice.c
浏览文件 @
09f439bc
...
...
@@ -1558,9 +1558,9 @@ RTM_EXPORT(rt_free);
*
* @param max_used is a pointer to get the maximum memory used.
*/
RT_WEAK
void
rt_memory_info
(
rt_
uint32
_t
*
total
,
rt_
uint32
_t
*
used
,
rt_
uint32
_t
*
max_used
)
RT_WEAK
void
rt_memory_info
(
rt_
size
_t
*
total
,
rt_
size
_t
*
used
,
rt_
size
_t
*
max_used
)
{
rt_base_t
level
;
...
...
src/memheap.c
浏览文件 @
09f439bc
...
...
@@ -27,7 +27,7 @@
/* dynamic pool magic and mask */
#define RT_MEMHEAP_MAGIC 0x1ea01ea0
#define RT_MEMHEAP_MASK 0x
fffffffe
#define RT_MEMHEAP_MASK 0x
FFFFFFFE
#define RT_MEMHEAP_USED 0x01
#define RT_MEMHEAP_FREED 0x00
...
...
@@ -38,6 +38,16 @@
#define MEMITEM_SIZE(item) ((rt_ubase_t)item->next - (rt_ubase_t)item - RT_MEMHEAP_SIZE)
#define MEMITEM(ptr) (struct rt_memheap_item*)((rt_uint8_t*)ptr - RT_MEMHEAP_SIZE)
static
void
_remove_next_ptr
(
struct
rt_memheap_item
*
next_ptr
)
{
/* Fix the crash problem after opening Oz optimization on ac6 */
/* Fix IAR compiler warning */
next_ptr
->
next_free
->
prev_free
=
next_ptr
->
prev_free
;
next_ptr
->
prev_free
->
next_free
=
next_ptr
->
next_free
;
next_ptr
->
next
->
prev
=
next_ptr
->
prev
;
next_ptr
->
prev
->
next
=
next_ptr
->
next
;
}
/**
* @brief This function initializes a piece of memory called memheap.
*
...
...
@@ -173,7 +183,7 @@ RTM_EXPORT(rt_memheap_detach);
void
*
rt_memheap_alloc
(
struct
rt_memheap
*
heap
,
rt_size_t
size
)
{
rt_err_t
result
;
rt_
uint32
_t
free_size
;
rt_
size
_t
free_size
;
struct
rt_memheap_item
*
header_ptr
;
RT_ASSERT
(
heap
!=
RT_NULL
);
...
...
@@ -382,8 +392,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
if
(
newsize
>
oldsize
)
{
void
*
new_ptr
;
/* Fix the crash problem after opening Oz optimization on ac6 */
volatile
struct
rt_memheap_item
*
next_ptr
;
struct
rt_memheap_item
*
next_ptr
;
if
(
heap
->
locked
==
RT_FALSE
)
{
...
...
@@ -432,10 +441,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
next_ptr
->
next_free
,
next_ptr
->
prev_free
));
next_ptr
->
next_free
->
prev_free
=
next_ptr
->
prev_free
;
next_ptr
->
prev_free
->
next_free
=
next_ptr
->
next_free
;
next_ptr
->
next
->
prev
=
next_ptr
->
prev
;
next_ptr
->
prev
->
next
=
next_ptr
->
next
;
_remove_next_ptr
(
next_ptr
);
/* build a new one on the right place */
next_ptr
=
(
struct
rt_memheap_item
*
)((
char
*
)
ptr
+
newsize
);
...
...
@@ -593,13 +599,13 @@ void rt_memheap_free(void *ptr)
rt_err_t
result
;
struct
rt_memheap
*
heap
;
struct
rt_memheap_item
*
header_ptr
,
*
new_ptr
;
rt_
uint32
_t
insert_header
;
rt_
bool
_t
insert_header
;
/* NULL check */
if
(
ptr
==
RT_NULL
)
return
;
/* set initial status as OK */
insert_header
=
1
;
insert_header
=
RT_TRUE
;
new_ptr
=
RT_NULL
;
header_ptr
=
(
struct
rt_memheap_item
*
)
((
rt_uint8_t
*
)
ptr
-
RT_MEMHEAP_SIZE
);
...
...
@@ -657,7 +663,7 @@ void rt_memheap_free(void *ptr)
/* move header pointer to previous. */
header_ptr
=
header_ptr
->
prev
;
/* don't insert header to free list */
insert_header
=
0
;
insert_header
=
RT_FALSE
;
}
/* determine if the block can be merged with the next neighbor. */
...
...
@@ -685,10 +691,10 @@ void rt_memheap_free(void *ptr)
{
struct
rt_memheap_item
*
n
=
heap
->
free_list
->
next_free
;;
#if defined(RT_MEMHEAP_BSET_MODE)
rt_
uint32
_t
blk_size
=
MEMITEM_SIZE
(
header_ptr
);
rt_
size
_t
blk_size
=
MEMITEM_SIZE
(
header_ptr
);
for
(;
n
!=
heap
->
free_list
;
n
=
n
->
next_free
)
{
rt_
uint32
_t
m
=
MEMITEM_SIZE
(
n
);
rt_
size
_t
m
=
MEMITEM_SIZE
(
n
);
if
(
blk_size
<=
m
)
{
break
;
...
...
@@ -732,9 +738,9 @@ RTM_EXPORT(rt_memheap_free);
* @param max_used is a pointer to get the maximum memory used.
*/
void
rt_memheap_info
(
struct
rt_memheap
*
heap
,
rt_
uint32
_t
*
total
,
rt_
uint32
_t
*
used
,
rt_
uint32
_t
*
max_used
)
rt_
size
_t
*
total
,
rt_
size
_t
*
used
,
rt_
size
_t
*
max_used
)
{
rt_err_t
result
;
...
...
@@ -898,10 +904,10 @@ int memheapcheck(int argc, char *argv[])
break
;
}
/* check next and prev */
if
(
!
((
rt_u
int32_t
)
item
->
next
<=
(
rt_uint32_t
)((
rt_uint32
_t
)
heap
->
start_addr
+
heap
->
pool_size
)
&&
(
rt_u
int32_t
)
item
->
prev
>=
(
rt_uint32
_t
)
heap
->
start_addr
)
&&
(
rt_u
int32_t
)
item
->
next
==
RT_ALIGN
((
rt_uint32
_t
)
item
->
next
,
RT_ALIGN_SIZE
)
&&
(
rt_u
int32_t
)
item
->
prev
==
RT_ALIGN
((
rt_uint32
_t
)
item
->
prev
,
RT_ALIGN_SIZE
))
if
(
!
((
rt_u
base_t
)
item
->
next
<=
(
rt_ubase_t
)((
rt_ubase
_t
)
heap
->
start_addr
+
heap
->
pool_size
)
&&
(
rt_u
base_t
)
item
->
prev
>=
(
rt_ubase
_t
)
heap
->
start_addr
)
&&
(
rt_u
base_t
)
item
->
next
==
RT_ALIGN
((
rt_ubase
_t
)
item
->
next
,
RT_ALIGN_SIZE
)
&&
(
rt_u
base_t
)
item
->
prev
==
RT_ALIGN
((
rt_ubase
_t
)
item
->
prev
,
RT_ALIGN_SIZE
))
{
has_bad
=
RT_TRUE
;
break
;
...
...
@@ -919,7 +925,7 @@ int memheapcheck(int argc, char *argv[])
{
rt_kprintf
(
"Memory block wrong:
\n
"
);
rt_kprintf
(
"name: %s
\n
"
,
heap
->
parent
.
name
);
rt_kprintf
(
"item: 0x%
08x
\n
"
,
item
);
rt_kprintf
(
"item: 0x%
p
\n
"
,
item
);
}
return
0
;
}
...
...
@@ -948,7 +954,7 @@ int memheaptrace(int argc, char *argv[])
/* memheap dump */
rt_kprintf
(
"
\n
memory heap address:
\n
"
);
rt_kprintf
(
"name : %s
\n
"
,
mh
->
parent
.
name
);
rt_kprintf
(
"heap_ptr: 0x%
08x
\n
"
,
mh
->
start_addr
);
rt_kprintf
(
"heap_ptr: 0x%
p
\n
"
,
mh
->
start_addr
);
rt_kprintf
(
"free : 0x%08x
\n
"
,
mh
->
available_size
);
rt_kprintf
(
"max_used: 0x%08x
\n
"
,
mh
->
max_used_size
);
rt_kprintf
(
"size : 0x%08x
\n
"
,
mh
->
pool_size
);
...
...
@@ -960,7 +966,7 @@ int memheaptrace(int argc, char *argv[])
{
if
((
header_ptr
->
magic
&
RT_MEMHEAP_MASK
)
!=
RT_MEMHEAP_MAGIC
)
{
rt_kprintf
(
"[0x%
08x
- incorrect magic: 0x%08x
\n
"
,
rt_kprintf
(
"[0x%
p
- incorrect magic: 0x%08x
\n
"
,
header_ptr
,
header_ptr
->
magic
);
break
;
}
...
...
@@ -969,7 +975,7 @@ int memheaptrace(int argc, char *argv[])
if
(
block_size
<
0
)
break
;
rt_kprintf
(
"[0x%
08x
- "
,
header_ptr
);
rt_kprintf
(
"[0x%
p
- "
,
header_ptr
);
if
(
block_size
<
1024
)
rt_kprintf
(
"%5d"
,
block_size
);
else
if
(
block_size
<
1024
*
1024
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录