I am using arm machine and segmentation handler sometimes crashes while obtaining crash context address:
void crit_err_hdlr(int sig_num, siginfo_t * info, void * ucontext)
{
uintptr_t fault_address = NULL;
struct sigcontext *ctx = &(((ucontext_t*)ucontext)->uc_mcontext);
fault_address = ctx->arm_pc;
//after reading ctx->arm_pc it crashes
}
This is how handler is setup:
struct sigaction sigact = { 0 };
sigact.sa_sigaction = crit_err_hdlr;
sigact.sa_flags = SA_SIGINFO | SA_RESTART;
if (sigaction(SIGSEGV, &sigact, (struct sigaction *)NULL) != 0)
{
//error, bail out
}
Is there any possible way to check if arm_pc filed in sigcontext is readable, so I can avoid the crash in crash handler?