Skip to content

Commit

Permalink
mm/mm_check_heap_corruption.c : Show pid with signed format
Browse files Browse the repository at this point in the history
For stack allocation, the pid which is in mm_allocnode_s is pid * (-1) for distinguishing it is stack allocation or normal allocation.
If we print the pid with unsigned format, then the pid of stack allocated node looks very big number because of negative value.
So it is better to print the pid with signed format when asserted.

Signed-off-by: jeongchanKim <[email protected]>
  • Loading branch information
jeongchanKim authored and sunghan-chang committed Jan 12, 2022
1 parent 6e8ea22 commit ee9bbc8
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions os/mm/mm_heap/mm_check_heap_corruption.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static void dump_node(struct mm_allocnode_s *node, node_type_t type)
{
#if defined(CONFIG_DEBUG_MM_HEAPINFO) && (CONFIG_TASK_NAME_SIZE > 0)
char myname[CONFIG_TASK_NAME_SIZE + 1];
char is_stack[9] = "'s stack";
#endif

if (type == TYPE_CORRUPTED) {
Expand All @@ -100,14 +101,23 @@ static void dump_node(struct mm_allocnode_s *node, node_type_t type)
dbg("OVERFLOWED NODE: addr = 0x%08x size = %u type = %c\n", node, node->size, IS_ALLOCATED_NODE(node) ? 'A' : 'F');
}
#ifdef CONFIG_DEBUG_MM_HEAPINFO
pid_t pid = node->pid;
if (pid < 0) {
/* For stack allocated node, pid is negative value.
* To use the pid, change it to original positive value.
*/
pid = (-1) * pid;
} else {
is_stack[0] = '\0';
}
#if CONFIG_TASK_NAME_SIZE > 0
if (prctl(PR_GET_NAME, myname, node->pid) == OK) {
dbg("Node owner pid = %u (%s), allocated by code at addr = 0x%08x\n", node->pid, myname, node->alloc_call_addr);
if (prctl(PR_GET_NAME, myname, pid) == OK) {
dbg("Node owner pid = %d (%s%s), allocated by code at addr = 0x%08x\n", node->pid, myname, is_stack, node->alloc_call_addr);
} else {
dbg("Node owner pid = %u (Exited Task), allocated by code at addr = 0x%08x\n", node->pid, node->alloc_call_addr);
dbg("Node owner pid = %d (Exited Task%s), allocated by code at addr = 0x%08x\n", node->pid, is_stack, node->alloc_call_addr);
}
#else
dbg("Node owner pid = %u, allocated by code at addr = 0x%08x\n", node->pid, node->alloc_call_addr);
dbg("Node owner pid = %d%s, allocated by code at addr = 0x%08x\n", node->pid, is_stack, node->alloc_call_addr);
#endif
#endif
}
Expand Down

0 comments on commit ee9bbc8

Please sign in to comment.