diff options
Diffstat (limited to 'src/core_dump_handler/dlt_cdh_crashid.c')
-rw-r--r-- | src/core_dump_handler/dlt_cdh_crashid.c | 108 |
1 files changed, 50 insertions, 58 deletions
diff --git a/src/core_dump_handler/dlt_cdh_crashid.c b/src/core_dump_handler/dlt_cdh_crashid.c index 905ba8b..ffd2aba 100644 --- a/src/core_dump_handler/dlt_cdh_crashid.c +++ b/src/core_dump_handler/dlt_cdh_crashid.c @@ -39,21 +39,21 @@ #include "dlt_cdh_cpuinfo.h" #ifdef HAS_CITYHASH_C -#include "city_c.h" +# include "city_c.h" #endif -//ARM32 specific -//#define REG_FRAME_POINTER 11 -//#define REG_INSTR_POINTER 12 -//#define REG_STACK_POINTER 13 -//#define REG_LINK_REGISTER 14 -//#define REG_PROC_COUNTER 15 +/*ARM32 specific */ +/*#define REG_FRAME_POINTER 11 */ +/*#define REG_INSTR_POINTER 12 */ +/*#define REG_STACK_POINTER 13 */ +/*#define REG_LINK_REGISTER 14 */ +/*#define REG_PROC_COUNTER 15 */ #ifdef HAS_CITYHASH_C -static cdh_status_t crashid_cityhash(proc_info_t* p_proc); +static cdh_status_t crashid_cityhash(proc_info_t *p_proc); #endif -cdh_status_t get_phdr_num(proc_info_t* p_proc, unsigned int p_address, int *phdr_num) +cdh_status_t get_phdr_num(proc_info_t *p_proc, unsigned int p_address, int *phdr_num) { int i = 0; @@ -61,40 +61,35 @@ cdh_status_t get_phdr_num(proc_info_t* p_proc, unsigned int p_address, int *phdr return CDH_NOK; for (i = 0; i < p_proc->m_Ehdr.e_phnum; i++) - { - if (p_proc->m_pPhdr[i].p_vaddr < p_address - && p_proc->m_pPhdr[i].p_vaddr + p_proc->m_pPhdr[i].p_memsz > p_address) - { + if ((p_proc->m_pPhdr[i].p_vaddr < p_address) + && (p_proc->m_pPhdr[i].p_vaddr + p_proc->m_pPhdr[i].p_memsz > p_address)) { *phdr_num = i; return CDH_OK; } - } *phdr_num = -1; return CDH_NOK; } -// Thanks to libunwind for the following definitions, which helps to -#define ALIGN(x,a) (((x)+(a)-1UL)&~((a)-1UL)) +/* Thanks to libunwind for the following definitions, which helps to */ +#define ALIGN(x, a) (((x) + (a) - 1UL) & ~((a) - 1UL)) #define NOTE_SIZE(_hdr) (sizeof (_hdr) + ALIGN((_hdr).n_namesz, 4) + (_hdr).n_descsz) -cdh_status_t get_crashed_registers(proc_info_t* p_proc) +cdh_status_t get_crashed_registers(proc_info_t *p_proc) { - int found = CDH_NOK; // CDH_OK, when we find the page note associated to PID of crashed process + int found = CDH_NOK; /* CDH_OK, when we find the page note associated to PID of crashed process */ unsigned int offset = 0; - // TODO: if no notes were found m_note_page_size was not set to 0 which leads to a crash in this loop because it is then used - // uninitialised here => this is an x86_64 issue - while (found != CDH_OK && offset < p_proc->m_note_page_size) - { - // Crash mentioned in TODO dlt_cdh_coredump.c line 163 - ELF_Nhdr* ptr_note = (ELF_Nhdr*) (p_proc->m_Nhdr + offset); + /* TODO: if no notes were found m_note_page_size was not set to 0 which leads to a crash in this loop because it is then used */ + /* uninitialised here => this is an x86_64 issue */ + while (found != CDH_OK && offset < p_proc->m_note_page_size) { + /* Crash mentioned in TODO dlt_cdh_coredump.c line 163 */ + ELF_Nhdr *ptr_note = (ELF_Nhdr *)(p_proc->m_Nhdr + offset); - if (ptr_note->n_type == NT_PRSTATUS) - { - // The first PRSTATUS note is the one of the crashed thread - prstatus_t* prstatus = (prstatus_t*) ((char*) ptr_note + sizeof(ELF_Nhdr) + ALIGN(ptr_note->n_namesz, 4)); + if (ptr_note->n_type == NT_PRSTATUS) { + /* The first PRSTATUS note is the one of the crashed thread */ + prstatus_t *prstatus = (prstatus_t *)((char *)ptr_note + sizeof(ELF_Nhdr) + ALIGN(ptr_note->n_namesz, 4)); p_proc->m_crashed_pid = prstatus->pr_pid; @@ -110,35 +105,35 @@ cdh_status_t get_crashed_registers(proc_info_t* p_proc) #ifdef HAS_CITYHASH_C -cdh_status_t crashid_cityhash(proc_info_t* p_proc) +cdh_status_t crashid_cityhash(proc_info_t *p_proc) { -#define CRASHID_BUF_SIZE MAX_PROC_NAME_LENGTH+sizeof(uint64_t) +# define CRASHID_BUF_SIZE MAX_PROC_NAME_LENGTH + sizeof(uint64_t) char cityhash_in[CRASHID_BUF_SIZE]; - uint64_t cityhash_result=0; + uint64_t cityhash_result = 0; memcpy(cityhash_in, p_proc->name, MAX_PROC_NAME_LENGTH); - memcpy(cityhash_in+MAX_PROC_NAME_LENGTH, &p_proc->m_crashid_phase1, sizeof(uint64_t)); + memcpy(cityhash_in + MAX_PROC_NAME_LENGTH, &p_proc->m_crashid_phase1, sizeof(uint64_t)); cityhash_result = CityHash64(cityhash_in, CRASHID_BUF_SIZE); memcpy(p_proc->m_crashid, &cityhash_result, sizeof(uint64_t)); return CDH_OK; -#undef CRASHID_BUF_SIZE +# undef CRASHID_BUF_SIZE } -#endif // HAS_CITYHASH_C +#endif /* HAS_CITYHASH_C */ -cdh_status_t create_crashid(proc_info_t* p_proc) +cdh_status_t create_crashid(proc_info_t *p_proc) { uint32_t final_lr = 0; uint32_t final_pc = 0; int pc_phnum = 0; int lr_phnum = 0; - // translate address from virtual address (process point of view) to offset in the stack memory page + /* translate address from virtual address (process point of view) to offset in the stack memory page */ #define ADDRESS_REBASE(__x, __phdr_num) (__x - p_proc->m_pPhdr[__phdr_num].p_vaddr) - // read value in the stack at position offset: +/- sizeof(), depends on stack growing upward or downward -#define READ_STACK_VALUE(__offset, __type) (*(__type*)(stack_page+__offset-sizeof(__type))) + /* read value in the stack at position offset: +/- sizeof(), depends on stack growing upward or downward */ +#define READ_STACK_VALUE(__offset, __type) (*(__type *)(stack_page + __offset - sizeof(__type))) get_phdr_num(p_proc, p_proc->m_registers.pc, &pc_phnum); final_pc = ADDRESS_REBASE(p_proc->m_registers.pc, pc_phnum); @@ -149,9 +144,9 @@ cdh_status_t create_crashid(proc_info_t* p_proc) final_lr = ADDRESS_REBASE(p_proc->m_registers.lr, lr_phnum); p_proc->m_crashid_phase1 = p_proc->signal << 24; - p_proc->m_crashid_phase1 |= (uint64_t) final_lr; + p_proc->m_crashid_phase1 |= (uint64_t)final_lr; p_proc->m_crashid_phase1 <<= 32; - p_proc->m_crashid_phase1 |= (uint64_t) final_pc; + p_proc->m_crashid_phase1 |= (uint64_t)final_pc; #ifdef HAS_CITYHASH_C crashid_cityhash(p_proc); @@ -160,44 +155,41 @@ cdh_status_t create_crashid(proc_info_t* p_proc) #endif syslog(LOG_INFO, - "Crash in \"%s\", thread=\"%s\", pid=%d, crashID=%"PRIx64", based on signal=%d, PC=0x%x, caller=0x%x", - p_proc->name, - p_proc->threadname, - p_proc->pid, - *((uint64_t*) p_proc->m_crashid), - p_proc->signal, - final_pc, final_lr - ); + "Crash in \"%s\", thread=\"%s\", pid=%d, crashID=%" PRIx64 ", based on signal=%d, PC=0x%x, caller=0x%x", + p_proc->name, + p_proc->threadname, + p_proc->pid, + *((uint64_t *)p_proc->m_crashid), + p_proc->signal, + final_pc, final_lr + ); return CDH_OK; } -int write_crashid_to_filesystem(proc_info_t* p_proc) +int write_crashid_to_filesystem(proc_info_t *p_proc) { - FILE* crashid_file = NULL; + FILE *crashid_file = NULL; - if ((crashid_file = fopen(CRASHID_FILE, "wt")) == NULL) - { + if ((crashid_file = fopen(CRASHID_FILE, "wt")) == NULL) { syslog(LOG_ERR, "(pid=%d) cannot write crashid to %s: %s", p_proc->pid, CRASHID_FILE, strerror(errno)); return CDH_NOK; } - fprintf(crashid_file, "%"PRIx64, *(uint64_t*) p_proc->m_crashid); + fprintf(crashid_file, "%" PRIx64, *(uint64_t *)p_proc->m_crashid); fclose(crashid_file); return CDH_OK; } -cdh_status_t treat_crash_data(proc_info_t* p_proc) +cdh_status_t treat_crash_data(proc_info_t *p_proc) { - if (get_crashed_registers(p_proc) != CDH_OK) - { + if (get_crashed_registers(p_proc) != CDH_OK) { syslog(LOG_ERR, "registers not found in notes"); return CDH_NOK; } - if (create_crashid(p_proc) != CDH_OK) - { + if (create_crashid(p_proc) != CDH_OK) { syslog(LOG_ERR, "crashid not generated"); return CDH_NOK; } |