0

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?

Ulterior
  • 2,786
  • 3
  • 30
  • 58
  • Handling `SIGSEGV` is critical, as more or less everything of the process's memory management might already be trashed, in the moment the handler is called. – alk Jun 15 '13 at 15:17
  • What OS are you talking about? Linux, Posix, etc.? See [isbadreadptr on Unix](http://stackoverflow.com/questions/4611776/isbadreadptr-analogue-on-unix) or [IsBadReadPtr search](http://stackoverflow.com/search?q=IsBadReadptr+is%3Aquestion). – artless noise Jun 17 '13 at 01:18

1 Answers1

1

The problem was the memory corruption performing operations inside the handler

Ulterior
  • 2,786
  • 3
  • 30
  • 58