Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 May 2008 12:55:58 -0400
From:      Mike <deathjestr@gmail.com>
To:        "Jille Timmermans" <jille@quis.cx>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Trying (not) to crash with libpthread (6.3-RELEASE)
Message-ID:  <44b564930805160955r76d6861fo1949c7f4d5b71ca5@mail.gmail.com>
In-Reply-To: <482DAB0E.70600@quis.cx>
References:  <482DAB0E.70600@quis.cx>

next in thread | previous in thread | raw e-mail | index | archive | help
> void
> sigcatcher(int sig) {
>  printf("[%p] signal %d\n", pthread_self(), sig);
>  printf("Test (probably) succeeded\n");
>  fflush(NULL);
>  success=1;
>  exit(0);
> }

Take a look at the man page for sigaction(2). Here's an excerpt:

"All functions not in the above lists are considered to be unsafe with
respect to signals.  That is to say, the behaviour of such functions when
called from a signal handler is undefined.  In general though, signal
handlers should do little more than set a flag; most other actions are
not safe."

> void *
> crashingthread(void *nada) {
>  /* This will likely crash */
>  char *x=malloc(1);
>
>  if(signal(SIGSEGV, sigcatcher)==SIG_ERR)
>   err(1, "signal(SIGSEGV, catchz0r)");
>
>  x[666]=0;
>
>  /* HOPEFULLY NOT REACHED (aargh! die harder!) */
>
>  int i;
>  for(i=1; 999999>i; i++)
>   x[i]=0;
>
>  /* NOT REACHED (either killed, or exit()'ed in sigcatcher) */
>  abort();
> }

Something like *(int*)0 = 0 is probably an easier, more reliable way to
crash your program. Maybe not quite as much fun though. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44b564930805160955r76d6861fo1949c7f4d5b71ca5>