Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86-64 coredump support #15638

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions arch/x86_64/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,42 @@

#define EF_FLAG 0

/* Segment register layout in coredumps. */

struct user_regs_struct
{
uint64_t r15;
uint64_t r14;
uint64_t r13;
uint64_t r12;
uint64_t bp;
uint64_t bx;
uint64_t r11;
uint64_t r10;
uint64_t r9;
uint64_t r8;
uint64_t ax;
uint64_t cx;
uint64_t dx;
uint64_t si;
uint64_t di;
uint64_t orig_ax;
uint64_t ip;
uint64_t cs;
uint64_t flags;
uint64_t sp;
uint64_t ss;
uint64_t fs_base;
uint64_t gs_base;
uint64_t ds;
uint64_t es;
uint64_t fs;
uint64_t gs;
};

typedef uint64_t elf_greg_t;

#define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t))
typedef elf_greg_t elf_gregset_t[ELF_NGREG];

#endif /* __ARCH_X86_64_INCLUDE_ELF_H */
28 changes: 16 additions & 12 deletions arch/x86_64/src/common/x86_64_tcbinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,33 @@

static const uint16_t g_reg_offs[] =
{
TCB_REG_OFF(REG_RAX), /* RAX */
TCB_REG_OFF(REG_R15), /* R15 */
TCB_REG_OFF(REG_R14), /* R14 */
TCB_REG_OFF(REG_R13), /* R13 */
TCB_REG_OFF(REG_R12), /* R12 */
TCB_REG_OFF(REG_RBP), /* RBP */
TCB_REG_OFF(REG_RBX), /* RBX */
TCB_REG_OFF(REG_R11), /* R11 */
TCB_REG_OFF(REG_R10), /* R10 */
TCB_REG_OFF(REG_R9), /* R9 */
TCB_REG_OFF(REG_R8), /* R8 */
TCB_REG_OFF(REG_RAX), /* RAX */
TCB_REG_OFF(REG_RCX), /* RCX */
TCB_REG_OFF(REG_RDX), /* RDX */
TCB_REG_OFF(REG_RSI), /* RSI */
TCB_REG_OFF(REG_RDI), /* RDI */
TCB_REG_OFF(REG_RBP), /* RBP */
TCB_REG_OFF(REG_RSP), /* RSP */
TCB_REG_OFF(REG_R8), /* R8 */
TCB_REG_OFF(REG_R9), /* R9 */
TCB_REG_OFF(REG_R10), /* R10 */
TCB_REG_OFF(REG_R11), /* R11 */
TCB_REG_OFF(REG_R12), /* R12 */
TCB_REG_OFF(REG_R13), /* R13 */
TCB_REG_OFF(REG_R14), /* R14 */
TCB_REG_OFF(REG_R15), /* R15 */
TCB_REG_OFF(REG_RAX), /* RAX */
TCB_REG_OFF(REG_RIP), /* RIP */
TCB_REG_OFF(REG_RFLAGS), /* EFLAGS */
TCB_REG_OFF(REG_CS), /* CS */
TCB_REG_OFF(REG_RFLAGS), /* RFLAGS */
TCB_REG_OFF(REG_RSP), /* RSP */
TCB_REG_OFF(REG_SS), /* SS */
TCB_REG_OFF(REG_FS), /* FS_BASE */
TCB_REG_OFF(REG_GS), /* GS_BASE */
TCB_REG_OFF(REG_DS), /* DS */
TCB_REG_OFF(REG_ES), /* ES */
TCB_REG_OFF(REG_FS), /* FS */
TCB_REG_OFF(REG_GS), /* GS */
};

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion libs/libc/machine/x86_64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ add_subdirectory(gnu)
set(SRCS)

if(CONFIG_LIBC_ARCH_ELF)
list(APPEND SRCS arch_elf.c)
list(APPEND SRCS arch_elf64.c)
endif()

if(CONFIG_ARCH_SETJMP_H)
Expand Down
9 changes: 8 additions & 1 deletion sched/misc/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@

#define PROGRAM_ALIGNMENT 64

/* Architecture can overwrite the default XCPTCONTEXT alignment */

#ifndef XCPTCONTEXT_ALIGN
# define XCPTCONTEXT_ALIGN 16
#endif

/****************************************************************************
* Private Types
****************************************************************************/
Expand All @@ -74,7 +80,8 @@ struct elf_dumpinfo_s
* Private Data
****************************************************************************/

static uint8_t g_running_regs[XCPTCONTEXT_SIZE] aligned_data(16);
static uint8_t g_running_regs[XCPTCONTEXT_SIZE]
aligned_data(XCPTCONTEXT_ALIGN);

#ifdef CONFIG_BOARD_COREDUMP_COMPRESSION
static struct lib_lzfoutstream_s g_lzfstream;
Expand Down
Loading