Subject: lib/30585: Sigcontext misfilled in pthread mode.
To: None <,,>
From: None <>
List: netbsd-bugs
Date: 06/23/2005 15:25:00
>Number:         30585
>Category:       lib
>Synopsis:       Sigcontext misfilled in pthread mode.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 23 15:25:00 +0000 2005
>Originator:     Guilhem Lavaux
>Release:        Netbsd 2.0.2
NetBSD rochben 2.0.2 NetBSD 2.0.2 (GENERIC.MP) #0: Wed Mar 23 01:32:33 UTC 2005 sparc
Kaffe needs to have access to the stack pointer and the instruction pointer at the place where a SIGSEGV/SIGBUS/SIGFPE occurs. For that we use the sigcontext structure which is given in parameter of the signal handler. However this structure seems to be misfilled in pthread mode.

#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>

void segvHandler(int sig, int code, struct sigcontext *sc)
  fprintf(stderr, "caught SEGV (sp=%p, pc=%p)\n", sc->sc_sp, sc->sc_pc);

void *specialThread(void *arg)
  int *i = (int *)arg;

  *i = 1;

int main(void)
  pthread_t th;
  struct sigaction newact, oldact;

  newact.sa_handler = segvHandler;

  newact.sa_flags = SA_SIGINFO | SA_RESTART;
  sigaction(SIGSEGV, &newact, NULL);

  pthread_create(&th, NULL, specialThread, NULL);


  return 0;

You'll see that it prints:
caught SEGV (sp=0x0, pc=0x0)

on netbsd 2.0.2 / sparc

This has not been tested on other processors.