Subject: lib/26984: pthread code does not exit on blocked SIGSEGV
To: None <>
From: None <>
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
>Originator:     Christos Zoulas
>Release:        NetBSD 2.0G
	Bankrupt Fighters, Inc.
System: NetBSD 2.0G NetBSD 2.0G (GW-GENERIC) #77: Sat Jul 10 16:55:52 EDT 2004 i386
Architecture: i386
Machine: i386

Threaded code that gets sigsegv, while sigsegv is blocked keeps going.
#include <pthread.h>
#include <signal.h>

sigsegv(int n) {}

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

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

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

	if (pthread_create(&self, NULL, thread, (void *) i) != 0)
		 perror("pthread create");
	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.