Process/thread context in critical signal handling

Hi all

I am porting to QNX6 a set of routines that I use under QNX4 to save all
the information about process context in the exact moment it has catched
a critical signal (SIGSEGV/FPE/ILL/BUS).

QNX4 pass to the signal handler a ptr to a struct _sigcontext,
containing all the registers values: there is something similar under QNX6?

Thanks in advance,
Davide


/* Ancri Davide - */

Davide Ancri <falsemail@nospam.xx> wrote:

Hi all

I am porting to QNX6 a set of routines that I use under QNX4 to save all
the information about process context in the exact moment it has catched
a critical signal (SIGSEGV/FPE/ILL/BUS).

QNX4 pass to the signal handler a ptr to a struct _sigcontext,
containing all the registers values: there is something similar under QNX6?

There isn’t something giving all the registers, but the siginfo_t passed
to the handler (defined in <sys/siginfo.h> does give some extra information
for those signals – in particular it gives fltno, ip, and address that
caused the fault. I’m not sure what the address will be.

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

David Gibbs <dagibbs@qnx.com> wrote:

Davide Ancri <> falsemail@nospam.xx> > wrote:
Hi all

I am porting to QNX6 a set of routines that I use under QNX4 to save all
the information about process context in the exact moment it has catched
a critical signal (SIGSEGV/FPE/ILL/BUS).

QNX4 pass to the signal handler a ptr to a struct _sigcontext,
containing all the registers values: there is something similar under QNX6?

There isn’t something giving all the registers, but the siginfo_t passed
to the handler (defined in <sys/siginfo.h> does give some extra information
for those signals – in particular it gives fltno, ip, and address that
caused the fault. I’m not sure what the address will be.

I have been corrected – apparently the third “void *” entry may/will be
a ucontext_t in this case that gives a full register set. <ucontext.h>.

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

David Gibbs wrote:

David Gibbs <> dagibbs@qnx.com> > wrote:

There isn’t something giving all the registers, but the siginfo_t passed
to the handler (defined in <sys/siginfo.h> does give some extra information
for those signals – in particular it gives fltno, ip, and address that
caused the fault. I’m not sure what the address will be.

I have been corrected – apparently the third “void *” entry may/will be
a ucontext_t in this case that gives a full register set. <ucontext.h>.

Thanks a lot, David!

<sys/siginfo.h> and <ucontext.h> are not so easy to understand at the
first view, but if I’m not missing something, I can start experimenting
with code similar to this:

#include <signal.h>
#include <sys/siginfo.h>
#include <ucontext.h>

void MySegv ( int signo, siginfo_t* s, ucontext_t* u )
{

}

int main ( int c, char** v )
{
signal( SIGSEGV, (void*)MySegv );
(int)0xDEADC0DE = -1;
return 0;
}

Am I right?

Thanks again!
Davide


/* Ancri Davide - */

Davide Ancri <falsemail@nospam.xx> wrote:

David Gibbs wrote:
David Gibbs <> dagibbs@qnx.com> > wrote:

There isn’t something giving all the registers, but the siginfo_t passed
to the handler (defined in <sys/siginfo.h> does give some extra information
for those signals – in particular it gives fltno, ip, and address that
caused the fault. I’m not sure what the address will be.

I have been corrected – apparently the third “void *” entry may/will be
a ucontext_t in this case that gives a full register set. <ucontext.h>.

Thanks a lot, David!

sys/siginfo.h> and <ucontext.h> are not so easy to understand at the
first view,

Yeah, cause they’re unions to cover various different cases.

<sys/siginfo.h> is messy cause it is information for various different
types of signals – but the comments looked ok.

<ucontext.h> is messy cause the register sets are different for all
the different processors we support.

but if I’m not missing something, I can start experimenting
with code similar to this:

#include <signal.h
#include <sys/siginfo.h
#include <ucontext.h

void MySegv ( int signo, siginfo_t* s, ucontext_t* u )
{

}

int main ( int c, char** v )
{
signal( SIGSEGV, (void*)MySegv );
(int)0xDEADC0DE = -1;
return 0;
}

Am I right?

Assuming DEADCODE isn’t a valid address, yeah, I think that will work.
(I don’t think the C compiler will call that an invalid lvalue.)

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

David Gibbs wrote:

sys/siginfo.h> and <ucontext.h> are not so easy to understand at the
first view,

Yeah, cause they’re unions to cover various different cases.

sys/siginfo.h> is messy cause it is information for various different
types of signals – but the comments looked ok.

It’s well documented in C language.


ucontext.h> is messy cause the register sets are different for all
the different processors we support.

It’s well documented in assembly language :wink:


(int)0xDEADC0DE = -1;

Assuming DEADCODE isn’t a valid address, yeah, I think that will work.
(I don’t think the C compiler will call that an invalid lvalue.)

{
volatile int b = 1, a = 0;

return( b / a );
}

will always work!

Thanks again, I’ll post here some results as soon as I’ll start testing…

Davide


/* Ancri Davide - */