2

I'm registering SIGSEGV (for Segmentation fault) Using sigaction() function. It working in all cases but except one case i.e. when stack is overflowing.I searched to resolve this problem. Then I get the answer, we have to assign alternate Stack. But I don't know how to assign altrenate stack for signal registration. Please help me to allocate alternate stack for segmenaion fault step by step.

gangadhars
  • 2,584
  • 7
  • 41
  • 68

2 Answers2

2

You can do it with sigaltstack.

stack_t stack = {
    .ss_sp = malloc(SIGSTKSZ),
    .ss_size = SIGSTKSZ,
    .ss_flags = 0
};

if (sigaltstack(&stack, NULL))
    perror("sigaltstack");

At this point just establish your signal handler with sigaction and use sa_flags = SA_ONSTACK.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
-1

First establish an alternative stack with sigaltstack()

Secondly, when installing the signal handler, use sigaction() and set the SA_ONSTACK in the sa_flags member of the struct sigaction.

nos
  • 223,662
  • 58
  • 417
  • 506