mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* trouble trapping SEGV on 2.6.11.2 & 2.6.12-rc4
@ 2005-05-24 20:31 Clifford T. Matthews
  2005-05-24 20:43 ` Chris Wright
  2005-05-24 21:14 ` Richard B. Johnson
  0 siblings, 2 replies; 4+ messages in thread
From: Clifford T. Matthews @ 2005-05-24 20:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Cliff Matthews

The included program dies with a SEGV under 2.6.11.2 and 2.6.12-rc4.
It doesn't die under 2.4.25.  I compiled the kernels myself.  The
distribution is Fedora Core release 3, with glibc 2.3.5.

I don't have any earlier 2.6 kernels to test it on, so I have no idea
when this bug first appeared.

I only skim LKML through fa.linux.kernel, so please CC me on any reply
that I should see.

--Cliff Matthews <ctm@ardi.com>
+1 505 363 5754 Cell

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdbool.h>
#include <assert.h>
#include <setjmp.h>
#include <signal.h>

static jmp_buf segv_return;

static void
segv_handler (int signum_ignored __attribute__((unused)))
{
  longjmp (segv_return, 1);
}

int
main (void)
{
  volatile char *volatile addr;
  volatile int n_failures;

  addr = (void *) 0x10000L;
  n_failures = 0;

  signal (SIGSEGV, segv_handler);
  if (setjmp (segv_return) != 0)
    ++n_failures;
  else
    *addr;

  printf ("n_failures = %d\n", n_failures);

  if (setjmp (segv_return) != 0)
    ++n_failures;
  else
    *addr;

  printf ("n_failures = %d\n", n_failures);

  return 0;
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: trouble trapping SEGV on 2.6.11.2 & 2.6.12-rc4
  2005-05-24 20:31 trouble trapping SEGV on 2.6.11.2 & 2.6.12-rc4 Clifford T. Matthews
@ 2005-05-24 20:43 ` Chris Wright
  2005-05-24 21:23   ` Clifford T. Matthews
  2005-05-24 21:14 ` Richard B. Johnson
  1 sibling, 1 reply; 4+ messages in thread
From: Chris Wright @ 2005-05-24 20:43 UTC (permalink / raw)
  To: Clifford T. Matthews; +Cc: linux-kernel

* Clifford T. Matthews (ctm@ardi.com) wrote:
> The included program dies with a SEGV under 2.6.11.2 and 2.6.12-rc4.
> It doesn't die under 2.4.25.  I compiled the kernels myself.  The
> distribution is Fedora Core release 3, with glibc 2.3.5.

2.6 has been fixed...  So your program (which happens to be slightly
buggy) no longer works as you expected.  See below.

> #include <stdio.h>
> #include <unistd.h>
> #include <sys/mman.h>
> #include <stdbool.h>
> #include <assert.h>
> #include <setjmp.h>
> #include <signal.h>
> 
> static jmp_buf segv_return;
> 
> static void
> segv_handler (int signum_ignored __attribute__((unused)))
> {
>   longjmp (segv_return, 1);

siglongjmp

> }
> 
> int
> main (void)
> {
>   volatile char *volatile addr;
>   volatile int n_failures;
> 
>   addr = (void *) 0x10000L;
>   n_failures = 0;
> 
>   signal (SIGSEGV, segv_handler);
>   if (setjmp (segv_return) != 0)

sigsetjmp

>     ++n_failures;
>   else
>     *addr;
> 
>   printf ("n_failures = %d\n", n_failures);
> 
>   if (setjmp (segv_return) != 0)

sigsetjmp

>     ++n_failures;
>   else
>     *addr;
> 
>   printf ("n_failures = %d\n", n_failures);
> 
>   return 0;
> }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: trouble trapping SEGV on 2.6.11.2 & 2.6.12-rc4
  2005-05-24 20:31 trouble trapping SEGV on 2.6.11.2 & 2.6.12-rc4 Clifford T. Matthews
  2005-05-24 20:43 ` Chris Wright
@ 2005-05-24 21:14 ` Richard B. Johnson
  1 sibling, 0 replies; 4+ messages in thread
From: Richard B. Johnson @ 2005-05-24 21:14 UTC (permalink / raw)
  To: Clifford T. Matthews; +Cc: linux-kernel


To jump out of signal handlers, you now need sigsetjmp() and
siglongjmp().


On Tue, 24 May 2005, Clifford T. Matthews wrote:

> The included program dies with a SEGV under 2.6.11.2 and 2.6.12-rc4.
> It doesn't die under 2.4.25.  I compiled the kernels myself.  The
> distribution is Fedora Core release 3, with glibc 2.3.5.
>
> I don't have any earlier 2.6 kernels to test it on, so I have no idea
> when this bug first appeared.
>
> I only skim LKML through fa.linux.kernel, so please CC me on any reply
> that I should see.
>
> --Cliff Matthews <ctm@ardi.com>
> +1 505 363 5754 Cell
>
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/mman.h>
> #include <stdbool.h>
> #include <assert.h>
> #include <setjmp.h>
> #include <signal.h>
>
> static jmp_buf segv_return;
>
> static void
> segv_handler (int signum_ignored __attribute__((unused)))
> {
>  longjmp (segv_return, 1);
> }
>
> int
> main (void)
> {
>  volatile char *volatile addr;
>  volatile int n_failures;
>
>  addr = (void *) 0x10000L;
>  n_failures = 0;
>
>  signal (SIGSEGV, segv_handler);
>  if (setjmp (segv_return) != 0)
>    ++n_failures;
>  else
>    *addr;
>
>  printf ("n_failures = %d\n", n_failures);
>
>  if (setjmp (segv_return) != 0)
>    ++n_failures;
>  else
>    *addr;
>
>  printf ("n_failures = %d\n", n_failures);
>
>  return 0;
> }
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

Cheers,
Dick Johnson
Penguin : Linux version 2.6.11.9 on an i686 machine (5537.79 BogoMips).
  Notice : All mail here is now cached for review by Dictator Bush.
                  98.36% of all statistics are fiction.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: trouble trapping SEGV on 2.6.11.2 & 2.6.12-rc4
  2005-05-24 20:43 ` Chris Wright
@ 2005-05-24 21:23   ` Clifford T. Matthews
  0 siblings, 0 replies; 4+ messages in thread
From: Clifford T. Matthews @ 2005-05-24 21:23 UTC (permalink / raw)
  To: Chris Wright; +Cc: Clifford T. Matthews, linux-kernel

>>>>> "Chris" == Chris Wright <chrisw@osdl.org> writes:

    Chris> 2.6 has been fixed...  So your program (which happens to be
    Chris> slightly buggy) no longer works as you expected.  See
    Chris> below.

Thanks for the quick response.  Using sigsetjmp and siglongjmp makes
the program print two lines.

I read the setjmp / sigsetjmp documentation and misunderstood it.

I had already seen that if I inserted "signal (SIGSEGV, segv_handler)"
before the second setjmp (not sigsetjmp), the program (under 2.6
kernels) still would die.

I guess what happens there is that after coming back from the longjmp,
the error handler is still segv_handler, but the receipt of the SEGV
signal itself is blocked and if you take a SEGV when the receipt of
SEGV is blocked a program dies with a SEGV, even if you have a SEGV
handler.

--Cliff Matthews <ctm@ardi.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-24 21:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-24 20:31 trouble trapping SEGV on 2.6.11.2 & 2.6.12-rc4 Clifford T. Matthews
2005-05-24 20:43 ` Chris Wright
2005-05-24 21:23   ` Clifford T. Matthews
2005-05-24 21:14 ` Richard B. Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®