NetBSD Problem Report #30585

From www@netbsd.org  Thu Jun 23 15:24:48 2005
Return-Path: <www@netbsd.org>
Received: by narn.netbsd.org (Postfix, from userid 31301)
	id 83D8A63B120; Thu, 23 Jun 2005 15:24:48 +0000 (UTC)
Message-Id: <20050623152448.83D8A63B120@narn.netbsd.org>
Date: Thu, 23 Jun 2005 15:24:48 +0000 (UTC)
From: guilhem.lavaux@free.fr
Reply-To: guilhem.lavaux@free.fr
To: gnats-bugs@netbsd.org
Subject: Sigcontext misfilled in pthread mode.
X-Send-Pr-Version: www-1.0

>Number:         30585
>Category:       pkg
>Synopsis:       Sigcontext misfilled in pthread mode.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 23 15:25:00 +0000 2005
>Closed-Date:    Tue Oct 11 10:12:02 +0000 2005
>Last-Modified:  Tue Oct 11 10:12:02 +0000 2005
>Originator:     Guilhem Lavaux
>Release:        Netbsd 2.0.2
>Organization:
>Environment:
NetBSD rochben 2.0.2 NetBSD 2.0.2 (GENERIC.MP) #0: Wed Mar 23 01:32:33 UTC 2005 jmc@faith.netbsd.org:/home/builds/ab/netbsd-2-0-2-RELEASE/sparc/200503220140Z-obj/home/builds/ab/netbsd-2-0-2-RELEASE/src/sys/arch/sparc/compile/GENERIC.MP sparc
>Description:
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.

>How-To-Repeat:
#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);
  exit(0);
}

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

  *i = 1;
}

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

  newact.sa_handler = segvHandler;
  sigemptyset(&newact.sa_mask);

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

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

  sleep(10);

  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.

>Fix:

>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: lib/30585: Sigcontext misfilled in pthread mode.
Date: Thu, 23 Jun 2005 17:35:57 +0200

 On Thu, Jun 23, 2005 at 03:25:00PM +0000, guilhem.lavaux@free.fr wrote:
 > void segvHandler(int sig, int code, struct sigcontext *sc)
 > {
 >   fprintf(stderr, "caught SEGV (sp=%p, pc=%p)\n", sc->sc_sp, sc->sc_pc);
 >   exit(0);
 > }

 [..]

 >   struct sigaction newact, oldact;
 > 
 >   newact.sa_handler = segvHandler;
 >   sigemptyset(&newact.sa_mask);

 That is an incompatible pointer type, isn't it? According to the man page
 sa_handler is just

   void      (*sa_handler)(int sig);

 Better use sa_sigaction and SA_SIGINFO?

 Martin

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@netbsd.org, lib-bug-people@netbsd.org,
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: martin@duskware.de
Subject: Re: lib/30585: Sigcontext misfilled in pthread mode.
Date: Thu, 23 Jun 2005 11:40:50 -0400

 You need to use siginfo not sigcontext. Sigcontext is not supported except
 in compatibility mode for non-threaded applications.

 christos

From: Matthias Drochner <M.Drochner@fz-juelich.de>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: lib/30585: Sigcontext misfilled in pthread mode. 
Date: Mon, 27 Jun 2005 14:59:13 +0200

 This is a multipart MIME message.

 --==_Exmh_73218017620350
 Content-Type: text/plain; charset=us-ascii


 Here are 2 patches for the pkgsrc kaffe.
 Can you give them a try?

 best regards
 Matthias



 --==_Exmh_73218017620350
 Content-Type: text/plain ; name="patch-af"; charset=us-ascii
 Content-Description: patch-af
 Content-Disposition: attachment; filename="patch-af"

 $NetBSD$

 --- config/i386/netbsd1/md.h.orig	2005-02-09 20:46:44.000000000 +0100
 +++ config/i386/netbsd1/md.h
 @@ -19,16 +19,26 @@
  #include "i386/sysdepCallMethod.h"
  #include "i386/threads.h"

 +#include <signal.h>
 +
  /*
   * Redefine stack pointer offset.
   */
  #undef SP_OFFSET
  #define SP_OFFSET 2

 +#ifdef SA_SIGINFO
 +#include <sys/ucontext.h>
 +#define SIGNAL_ARGS(sig, sc) int sig, siginfo_t *__si, void *sc
 +#define SIGNAL_CONTEXT_POINTER(scp) ucontext_t *scp
 +#define GET_SIGNAL_CONTEXT_POINTER(sc) (sc)
 +#define SIGNAL_PC(scp) ((ucontext_t *)(scp))->uc_mcontext.__gregs[_REG_EIP]
 +#else
  #define SIGNAL_ARGS(sig, sc) int sig, int __code, struct sigcontext *sc
  #define SIGNAL_CONTEXT_POINTER(scp) struct sigcontext *scp
  #define GET_SIGNAL_CONTEXT_POINTER(sc) (sc)
  #define SIGNAL_PC(scp) (scp)->sc_pc
 +#endif

  #if defined(TRANSLATOR)
  #include "jit-md.h"

 --==_Exmh_73218017620350
 Content-Type: text/plain ; name="patch-ag"; charset=us-ascii
 Content-Description: patch-ag
 Content-Disposition: attachment; filename="patch-ag"

 $NetBSD$

 --- config/i386/netbsd1/jit-md.h.orig	2005-02-09 21:25:34.000000000 +0100
 +++ config/i386/netbsd1/jit-md.h
 @@ -26,7 +26,7 @@

  /* Get the first exception frame from a signal handler */
  #define	EXCEPTIONFRAME(f, c)						\
 -	(f).retbp = (c)->sc_ebp;					\
 -	(f).retpc = (c)->sc_eip + 1
 +	(f).retbp = ((ucontext_t *)(c))->uc_mcontext.__gregs[_REG_EBP];					\
 +	(f).retpc = ((ucontext_t *)(c))->uc_mcontext.__gregs[_REG_EIP] + 1

  #endif

 --==_Exmh_73218017620350--


Responsible-Changed-From-To: lib-bug-people->pkg-manager
Responsible-Changed-By: chs@netbsd.org
Responsible-Changed-When: Sun, 09 Oct 2005 16:47:38 +0000
Responsible-Changed-Why:
this needs to be fixed in kaffe, not the netbsd pthreads code.


From: Antoine Reilles <tonio@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/30585 CVS commit: pkgsrc/lang/kaffe
Date: Tue, 11 Oct 2005 10:00:15 +0000 (UTC)

 Module Name:	pkgsrc
 Committed By:	tonio
 Date:		Tue Oct 11 10:00:15 UTC 2005

 Modified Files:
 	pkgsrc/lang/kaffe: Makefile Makefile.common PLIST buildlink3.mk
 	    distinfo
 	pkgsrc/lang/kaffe/patches: patch-aa patch-ab patch-ac patch-af
 Removed Files:
 	pkgsrc/lang/kaffe/patches: patch-ad

 Log Message:
 Update lang/kaffe to 1.1.6

 This release contains many improvements, including the merge with gnu classpath
 0.18
 Also, patches from PR 30585 have been integrated upstream.
 Thanks joerg for testing it under dragonfly


 To generate a diff of this commit:
 cvs rdiff -r1.63 -r1.64 pkgsrc/lang/kaffe/Makefile
 cvs rdiff -r1.8 -r1.9 pkgsrc/lang/kaffe/Makefile.common \
     pkgsrc/lang/kaffe/buildlink3.mk
 cvs rdiff -r1.12 -r1.13 pkgsrc/lang/kaffe/PLIST
 cvs rdiff -r1.14 -r1.15 pkgsrc/lang/kaffe/distinfo
 cvs rdiff -r1.13 -r1.14 pkgsrc/lang/kaffe/patches/patch-aa
 cvs rdiff -r1.9 -r1.10 pkgsrc/lang/kaffe/patches/patch-ab
 cvs rdiff -r1.8 -r1.9 pkgsrc/lang/kaffe/patches/patch-ac
 cvs rdiff -r1.6 -r0 pkgsrc/lang/kaffe/patches/patch-ad
 cvs rdiff -r1.5 -r1.6 pkgsrc/lang/kaffe/patches/patch-af

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: tonio@netbsd.org
State-Changed-When: Tue, 11 Oct 2005 10:12:02 +0000
State-Changed-Why:
This has been fixed this way in kaffe 1.1.6.
kaffe has been updated to 1.1.6
Thanks for the PR and the fix


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.