Subject: lib/26984: pthread code does not exit on blocked SIGSEGV
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <christos@zoulas.com>
List: netbsd-bugs
Date: 09/17/2004 14:23:16
>Number:         26984
>Category:       lib
>Synopsis:       pthread code does not exit on blocked SIGSEGV.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 17 18:24:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Christos Zoulas
>Release:        NetBSD 2.0G
>Organization:
	Bankrupt Fighters, Inc.
>Environment:
System: NetBSD beowulf.gw.com 2.0G NetBSD 2.0G (GW-GENERIC) #77: Sat Jul 10 16:55:52 EDT 2004 kim@hrothgar.gw.com:/usr/src/sys/arch/i386/compile/GW-GENERIC i386
Architecture: i386
Machine: i386
>Description:

Threaded code that gets sigsegv, while sigsegv is blocked keeps going.
	
>How-To-Repeat:
#include <pthread.h>
#include <signal.h>

void
sigsegv(int n) {}

void *
thread(void *p)
{
	struct sigaction sa;
	sigset_t set;

	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_SIGINFO;
	sa.sa_handler = sigsegv;
	sigaction(SIGSEGV, &sa, NULL);
	sigemptyset(&set);
	sigaddset(&set, SIGSEGV);
	sigprocmask(SIG_BLOCK, &set, NULL);
	*(char *)0xa0000000 = 1;
	return NULL;
}

int
main()
{
#ifdef THREAD
	pthread_t self = pthread_self();
	size_t i;

	if (pthread_create(&self, NULL, thread, (void *) i) != 0)
		 perror("pthread create");
#else
	thread(0);
#endif
	sleep(100);
	return 0;
}

Compile and run the above code with -DTHREAD and without. With -DTHREAD
will just infinite loop. Once you attach ktrace to it, you get SIGSEGV.
What is also strange, is that making 2 threads run the same code by
duplicating the pthread_create call infinite loops too, but when ktraced,
it dies with an assertion failure.

>Fix:
unknown
>Release-Note:
>Audit-Trail:
>Unformatted: