1#!/bin/sh
2
3#
4# Copyright (c) 2013 Peter Holm <pho@FreeBSD.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# "panic: smp_tlb_shootdown: interrupts disabled" seen.
30# http://people.freebsd.org/~pho/stress/log/freebsd4_sigreturn.txt
31# Fixed in r251033.
32
33. ../default.cfg
34
35dir=/tmp
36odir=`pwd`
37cd $dir
38sed '1,/^EOF/d' < $odir/$0 > $dir/sigreturn.c
39mycc -o sigreturn -Wall -Wextra sigreturn.c -lpthread || exit 1
40rm -f sigreturn.c
41cd $odir
42
43/tmp/sigreturn
44
45rm -f /tmp/sigreturn ./sigreturn.core
46exit
47EOF
48#include <sys/types.h>
49#include <err.h>
50#include <fcntl.h>
51#include <pthread.h>
52#include <signal.h>
53#include <stdio.h>
54#include <stdlib.h>
55#include <sys/param.h>
56#include <sys/syscall.h>
57#include <sys/wait.h>
58#include <unistd.h>
59
60unsigned long buf[] = {
610xe8243489, 0x000e7cc9, 0x85204e8b, 0xc0940fc9, 0x0fc2950f, 0x5589d2b6,
620x56bf0fe4, 0xe855890e, 0x890fd285, 0x0000014a, 0x850fc084, 0x00000142,
630x891c468b, 0xd1ff2404, 0x00012ee9, 0x04b3e800, 0x388bffff, 0xe8243489,
640xfffefbd9, 0xff04a4e8, 0xe93889ff, 0x00000343, 0x0fc08566, 0x00031f84,
650x46bf0f00, 0x2404890e, 0x042444c7, 0x00000003, 0xfefb90e8, 0x85c789ff,
660x0d880fff, 0x89000002, 0x03e083f8, 0x7402f883, 0xf04d8b0e, 0x3903e183,
670xe1850fc8, 0xf6000002, 0x74080c46, 0x24348908, 0x0e7c2ce8, 0xf0458b00,
680xf931c189, 0x7408c1f6, 0xf7e7832b, 0x0908e083, 0x4ebf0ff8, 0x2444890e,
690x240c8908, 0x042444c7, 0x00000004, 0xfefb34e8, 0x0fc085ff, 0x0001b388,
700xf0458b00, 0x7404c4f6, 0x46bf0f1f, 0x2404890e, 0x082444c7, 0x00000000,
710x042444c7, 0x00000000, 0xff0898e8, 0xf0458bff, 0x237508a8, 0xc7243489,
720x000c2444, 0xc7000000, 0x00082444, 0xc7000000, 0x00042444, 0xe8000000,
730x000e86ad, 0xa9f0458b, 0x00100000, 0xbf0f1c74, 0x04890e46, 0x2444c724,
740x00000108, 0x2444c700, 0x00000204, 0xfabbe800, 0xbf0ffffe, 0x45c70e7e,
750xffffffe8, 0xe445c7ff, 0x00000000, 0xc76634eb, 0x00200c46, 0xffe845c7
76};
77
78#if !defined(SYS_freebsd4_sigreturn)
79#define SYS_freebsd4_sigreturn 344
80#endif
81
82static void
83hand(int i __unused) {	/* handler */
84	_exit(1);
85}
86
87void *
88calls(void *arg __unused)
89{
90	alarm(1);
91	syscall(SYS_freebsd4_sigreturn, buf);
92
93	return (0);
94}
95
96int
97main(void)
98{
99	pthread_t cp;
100	int e;
101
102	signal(SIGALRM, hand);
103	signal(SIGILL,  hand);
104	signal(SIGFPE,  hand);
105	signal(SIGSEGV, hand);
106	signal(SIGBUS,  hand);
107	signal(SIGURG,  hand);
108	signal(SIGSYS,  hand);
109	signal(SIGTRAP, hand);
110
111	if (fork() == 0) {
112		if ((e = pthread_create(&cp, NULL, calls, NULL)) != 0)
113			errc(1, e, "pthread_create");
114
115		pthread_join(cp, NULL);
116		_exit(0);
117	}
118	wait(NULL);
119
120	return (0);
121}
122