2001-03-08 22:29:20

by Camm Maguire

[permalink] [raw]
Subject: 2.2.x kernels not filling in siginfo_t.si_addr on SEGV?

Greetings! Shouldn't a SIGSEGV fill in th si_addr member of the
siginfo_t structure passed to a signal handler? Here is what I see
(on several archs):
=============================================================================
q.c
=============================================================================
#include <stdio.h>
#include <signal.h>

void
nh(int s,siginfo_t *si,void *sc) {
printf("%p\n",si->si_addr);
exit(0);
}

int
main() {

struct sigaction sa;
char c[3];

memset(&sa,0,sizeof(sa));
sa.sa_sigaction=nh;
sa.sa_flags=SA_RESTART|SA_SIGINFO;
sigaction(SIGSEGV,&sa,0);
c[4096]=0;

/* raise(SIGSEGV); */

return 0;

}
=============================================================================
camm@kullervo:~$ cc -g q.c -o q
cc -g q.c -o q
camm@kullervo:~$ ./q
./q
(nil)
=============================================================================
Take care,

--
Camm Maguire [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens." -- Baha'u'llah


2001-03-09 00:26:55

by David Watson

[permalink] [raw]
Subject: Re: 2.2.x kernels not filling in siginfo_t.si_addr on SEGV?


> Greetings!? Shouldn't a SIGSEGV fill in th si_addr member of the
> siginfo_t structure passed to a signal handler?? Here is what I see

Our group ran into this problem last summer while we were developing the
Oasis+ DSM system. We worked around it by utilizing the following code
fragment:

void fault_handler(int sig, siginfo_t *sip, ucontext_t *ucp)
{
void *addr;

addr = (void *) ucp->uc_mcontext.cr2;

...
}

Hope that helps.

Regards,
David

--
The theory of groups is a branch of Mathematics in which one does
something to something and then compares the result with the result
obtained from doing the same thing to something else, or something else to
the same thing.
J. R. Newman

2001-03-09 03:29:47

by Camm Maguire

[permalink] [raw]
Subject: Re: 2.2.x kernels not filling in siginfo_t.si_addr on SEGV?

Greetings, and thank you so much for your helpful reply! Was this on
an i386? I'm specifically looking for a way to do his on arm, alpha,
and sparc, and I don't believe they have the cr2 member of struct
sigcontext. Any info you might have, including where you found this
solution, would be appreciated!

Take care,

David Watson <[email protected]> writes:

> > Greetings!? Shouldn't a SIGSEGV fill in th si_addr member of the
> > siginfo_t structure passed to a signal handler?? Here is what I see
>
> Our group ran into this problem last summer while we were developing the
> Oasis+ DSM system. We worked around it by utilizing the following code
> fragment:
>
> void fault_handler(int sig, siginfo_t *sip, ucontext_t *ucp)
> {
> void *addr;
>
> addr = (void *) ucp->uc_mcontext.cr2;
>
> ...
> }
>
> Hope that helps.
>
> Regards,
> David
>
> --
> The theory of groups is a branch of Mathematics in which one does
> something to something and then compares the result with the result
> obtained from doing the same thing to something else, or something else to
> the same thing.
> J. R. Newman
>
>
>

--
Camm Maguire [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens." -- Baha'u'llah

2001-03-09 22:30:32

by Camm Maguire

[permalink] [raw]
Subject: Re: 2.2.x kernels not filling in siginfo_t.si_addr on SEGV?

Greetings, and thanks for your reply!

Russell King <[email protected]> writes:

> On Thu, Mar 08, 2001 at 10:28:39PM -0500, Camm Maguire wrote:
> > Greetings, and thank you so much for your helpful reply! Was this on
> > an i386? I'm specifically looking for a way to do his on arm, alpha,
> > and sparc, and I don't believe they have the cr2 member of struct
> > sigcontext. Any info you might have, including where you found this
> > solution, would be appreciated!
>
> ARM does have this information available of course (its required for the
> page fault processing), but it didn't fill in the tss struct with the
> address in 2.2 kernels. In 2.4, we use the siginfo stuff.
>
> You're the first person to report that it doesn't. We do have an
> "tss.address" member which should be filled in however.
>

Thanks so much for this info. Does this mean that given the siginfo_t
and sigcontext pointers, one cannot find this address anywhere by
poking around at a specified offset, or something? Roman Hodek came
up with the following rather elaborate scheme for m68k:
=============================================================================
/* GET_FAULT_ADDR is a bit complicated to implement on m68k, because the fault
address can't be found directly in the sigcontext. One has to look at the
CPU frame, and that one is different for each CPU.
*/
#define GET_FAULT_ADDR(sig,code,sv,a) \
({ \
struct sigcontext *scp = (struct sigcontext *)(sv); \
int format = (scp->sc_formatvec >> 12) & 0xf; \
unsigned long *framedata = (unsigned long *)(scp + 1); \
unsigned long ea; \
if (format == 0xa || format == 0xb) \
/* 68020/030 */ \
ea = framedata[2]; \
else if (format == 7) \
/* 68040 */ \
ea = framedata[3]; \
else if (format == 4) { \
/* 68060 */ \
ea = framedata[0]; \
if (framedata[1] & 0x08000000) \
/* correct addr on misaligned access */ \
ea = (ea+4095)&(~4095); \
} \
ea; \
})
#endif
=============================================================================

Is there any analog for arm (or alpha, sparc, etc. for that matter)
for current 2.2.x kernels?

Thanks again!


>

--
Camm Maguire [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens." -- Baha'u'llah