signals catch in another stack

Hi,

if sigsegv occured by reason of stack overflow –
how can i process it with another stack?

AFAIU sigwaitinfo() (in another thread) does not trap sigsegv.
or may be i wrong?

vasa

“Operating System Tech Support” <os@qnx.com> wrote in message
news:9tgk87$l7a$1@nntp.qnx.com

“vasa” <> vv40in@rambler.ru> > wrote in message
news:9tg69d$9cq$> 1@inn.qnx.com> …
if sigsegv occured by reason of stack overflow –
how can i process it with another stack?

I’m not sure that doing what you want to do is that straight forward. But
here is some example code I mocked up to show you how you might handle a
SIGSEGV.


void sighandler(int signum)
{
sigset_t set;

Since the handler uses the stack, wouldn’t take cause yet another
stack overflow if the initial cause of the SIGSEGV was
a stack overflow?

sigemptyset(&set);
sigaddset(&set, SIGSEGV);
sigprocmask(SIG_BLOCK, &set, NULL);
fprintf(stderr,“Caught the incorrect access!\n”);
siglongjmp(myenv, 1);
return;
}

“vasa” <vv40in@rambler.ru> wrote in message news:9tg69d$9cq$1@inn.qnx.com

if sigsegv occured by reason of stack overflow –
how can i process it with another stack?

I’m not sure that doing what you want to do is that straight forward. But
here is some example code I mocked up to show you how you might handle a
SIGSEGV.

-Adam


#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>

sigjmp_buf myenv;

void sighandler(int signum);
int testcall(int a);

int main(int argc, char* argv[])
{
char a = 0xda;
char *p = &a;

signal(SIGSEGV, sighandler);

if (sigsetjmp(myenv,1) == 0)
{
/* should cause a SIGSEGV, not portable */
printf("%s\n", *(++p));
}
else
{
printf(“recovery!\n”);
}

if ( testcall(121212) == 0)
{
printf(“Good test call\n”);
}
else
{
printf(“Bad test call\n”);
}

return EXIT_SUCCESS;
}

void sighandler(int signum)
{
sigset_t set;

sigemptyset(&set);
sigaddset(&set, SIGSEGV);
sigprocmask(SIG_BLOCK, &set, NULL);
fprintf(stderr,“Caught the incorrect access!\n”);
siglongjmp(myenv, 1);
return;
}

int testcall(int a)
{
printf(“This is the test call after the crash! Value is %d\n”, a);
return 0;
}

“Mario Charest” <mcharest@clipzinformatic.com> wrote in message
news:9tgsbi$3i2$1@inn.qnx.com

void sighandler(int signum)
{
sigset_t set;


Since the handler uses the stack, wouldn’t take cause yet another
stack overflow if the initial cause of the SIGSEGV was
a stack overflow?

I should have been clearer on my intent in my example program. I wasn’t
trying to solve the problem, more so then illustrate what was available in
terms of handling a SIGSEGV (for my particular test case). The idea was
that you could use sigsetjmp()/siglongjmp() to pseudo checkpoint along the
way in your program. The fact that a stackoverflow has occured makes this
problem not so trivial (since calling a function involves the stack). Worse
yet, in a multiple thread application, SIGSEGV is a syncronous signal, and
is applied to the thread that elicited the signal, even if you’re
sigwait’ing for it in another thread.

I hope that clarifies things - sorry about the misunderstanding.

-Adam

void sighandler(int signum)
{
sigset_t set;


Since the handler uses the stack, wouldn’t take cause yet another
stack overflow if the initial cause of the SIGSEGV was
a stack overflow?

I should have been clearer on my intent in my example program. I wasn’t
trying to solve the problem, more so then illustrate what was available in
terms of handling a SIGSEGV (for my particular test case). The idea was
that you could use sigsetjmp()/siglongjmp() to pseudo checkpoint along the
way in your program. The fact that a stackoverflow has occured makes this
problem not so trivial (since calling a function involves the stack).
Worse
yet, in a multiple thread application, SIGSEGV is a syncronous signal,
and
is applied to the thread that elicited the signal, even if you’re
sigwait’ing for it in another thread.

I hope that clarifies things - sorry about the misunderstanding.

i has replaced

/* should cause a SIGSEGV, not portable */
// printf("%s\n", *(++p));
int i, *x = &argc;
// walk down the stack
for (i=0;;i++,x–){
printf ("%d %x\n", i,d);
}

if You run it, You could se
(AFAIU) signal handler uses the same stack,
but stack pointer (SP) is not the same as at moment SIGSEGV.
It points to INNER space of stack.

vasa