elf/coredump: alignment stack buffer to 64 to match gdb request

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an 2023-05-25 14:51:24 +08:00 committed by Xiang Xiao
parent 589d4a9f8e
commit 090a52c5fb

View file

@ -50,7 +50,10 @@
# define ELF_PAGESIZE 1024
#endif
#define ROUNDUP(x, y) ((x + (y - 1)) / (y)) * (y)
#define PROGRAM_ALIGNMENT 64
#define ROUNDUP(x, y) ((x + (y - 1)) / (y)) * (y)
#define ROUNDDOWN(x ,y) (((x) / (y)) * (y))
/****************************************************************************
* Private Data
@ -335,7 +338,7 @@ static void elf_emit_note(FAR struct elf_dumpinfo_s *cinfo)
static void elf_emit_tcb_stack(FAR struct elf_dumpinfo_s *cinfo,
FAR struct tcb_s *tcb)
{
FAR void *buf = NULL;
uintptr_t buf = 0;
uintptr_t sp;
size_t len;
@ -348,26 +351,30 @@ static void elf_emit_tcb_stack(FAR struct elf_dumpinfo_s *cinfo,
{
len = ((uintptr_t)tcb->stack_base_ptr +
tcb->adj_stack_size) - sp;
buf = (FAR void *)sp;
buf = sp;
}
#ifdef CONFIG_STACK_COLORATION
else
{
len = up_check_tcbstack(tcb);
buf = (FAR void *)((uintptr_t)tcb->stack_base_ptr +
(tcb->adj_stack_size - len));
buf = (uintptr_t)tcb->stack_base_ptr +
(tcb->adj_stack_size - len);
}
#endif
}
if (buf == NULL)
if (buf == 0)
{
buf = (FAR void *)tcb->stack_alloc_ptr;
buf = (uintptr_t)tcb->stack_alloc_ptr;
len = tcb->adj_stack_size +
(tcb->stack_base_ptr - tcb->stack_alloc_ptr);
}
elf_emit(cinfo, buf, len);
sp = ROUNDDOWN(buf, PROGRAM_ALIGNMENT);
len = ROUNDUP(len + (buf - sp), PROGRAM_ALIGNMENT);
buf = sp;
elf_emit(cinfo, (FAR void *)buf, len);
/* Align to page */
@ -470,6 +477,11 @@ static void elf_emit_tcb_phdr(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr);
}
sp = ROUNDDOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT);
phdr->p_filesz = ROUNDUP(phdr->p_filesz +
(phdr->p_vaddr - sp), PROGRAM_ALIGNMENT);
phdr->p_vaddr = sp;
phdr->p_type = PT_LOAD;
phdr->p_offset = ROUNDUP(*offset, ELF_PAGESIZE);
phdr->p_paddr = phdr->p_vaddr;