Home | History | Annotate | Line # | Download | only in gen
t_siginfo.c revision 1.10
      1  1.10       riz /* $NetBSD: t_siginfo.c,v 1.10 2011/03/02 03:42:56 riz Exp $ */
      2   1.1  pgoyette 
      3   1.1  pgoyette /*-
      4   1.1  pgoyette  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5   1.1  pgoyette  * All rights reserved.
      6   1.1  pgoyette  *
      7   1.1  pgoyette  * Redistribution and use in source and binary forms, with or without
      8   1.1  pgoyette  * modification, are permitted provided that the following conditions
      9   1.1  pgoyette  * are met:
     10   1.1  pgoyette  * 1. Redistributions of source code must retain the above copyright
     11   1.1  pgoyette  *    notice, this list of conditions and the following disclaimer.
     12   1.1  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  pgoyette  *    documentation and/or other materials provided with the distribution.
     15   1.1  pgoyette  *
     16   1.1  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17   1.1  pgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18   1.1  pgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19   1.1  pgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20   1.1  pgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21   1.1  pgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22   1.1  pgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23   1.1  pgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24   1.1  pgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25   1.1  pgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   1.1  pgoyette  * POSSIBILITY OF SUCH DAMAGE.
     27   1.1  pgoyette  */
     28   1.1  pgoyette 
     29   1.1  pgoyette #include <atf-c.h>
     30  1.10       riz #include <atf-c/config.h>
     31   1.1  pgoyette 
     32   1.2  pgoyette #include <sys/inttypes.h>
     33   1.1  pgoyette #include <sys/resource.h>
     34   1.1  pgoyette #include <sys/time.h>
     35   1.1  pgoyette #include <sys/ucontext.h>
     36   1.1  pgoyette #include <sys/wait.h>
     37   1.1  pgoyette 
     38   1.1  pgoyette #include <assert.h>
     39   1.1  pgoyette #include <signal.h>
     40   1.1  pgoyette #include <stdio.h>
     41   1.1  pgoyette #include <stdlib.h>
     42  1.10       riz #include <string.h>
     43   1.1  pgoyette #include <unistd.h>
     44   1.5   mlelstv #include <setjmp.h>
     45   1.1  pgoyette 
     46   1.1  pgoyette #ifndef __vax__
     47   1.1  pgoyette #include <ieeefp.h>
     48   1.1  pgoyette #endif
     49   1.1  pgoyette 
     50   1.1  pgoyette /* for sigchild */
     51   1.1  pgoyette pid_t child;
     52   1.1  pgoyette int code;
     53   1.1  pgoyette int status;
     54   1.1  pgoyette 
     55   1.1  pgoyette /* for sigfpe */
     56   1.1  pgoyette sig_atomic_t fltdiv_signalled = 0;
     57   1.1  pgoyette sig_atomic_t intdiv_signalled = 0;
     58   1.1  pgoyette 
     59   1.1  pgoyette static void
     60   1.1  pgoyette sig_debug(int signo, siginfo_t *info, ucontext_t *ctx)
     61   1.1  pgoyette {
     62   1.1  pgoyette 	unsigned int i;
     63   1.1  pgoyette 
     64   1.1  pgoyette 	printf("%d %p %p\n", signo, info, ctx);
     65   1.1  pgoyette 	if (info != NULL) {
     66   1.1  pgoyette 		printf("si_signo=%d\n", info->si_signo);
     67   1.1  pgoyette 		printf("si_errno=%d\n", info->si_errno);
     68   1.1  pgoyette 		printf("si_code=%d\n", info->si_code);
     69   1.1  pgoyette 		printf("si_value.sival_int=%d\n", info->si_value.sival_int);
     70   1.1  pgoyette 	}
     71   1.1  pgoyette 	if (ctx != NULL) {
     72   1.1  pgoyette 		printf("uc_flags 0x%x\n", ctx->uc_flags);
     73   1.1  pgoyette 		printf("uc_link %p\n", ctx->uc_link);
     74   1.1  pgoyette 		for (i = 0; i < __arraycount(ctx->uc_sigmask.__bits); i++)
     75   1.1  pgoyette 			printf("uc_sigmask[%d] 0x%x\n", i,
     76   1.1  pgoyette 			    ctx->uc_sigmask.__bits[i]);
     77   1.1  pgoyette 		printf("uc_stack %p %lu 0x%x\n", ctx->uc_stack.ss_sp,
     78   1.1  pgoyette 		    (unsigned long)ctx->uc_stack.ss_size,
     79   1.1  pgoyette 		    ctx->uc_stack.ss_flags);
     80   1.3  pgoyette 		for (i = 0; i < __arraycount(ctx->uc_mcontext.__gregs); i++)
     81   1.3  pgoyette 			printf("uc_mcontext.greg[%d] 0x%lx\n", i,
     82   1.3  pgoyette 			    (long)ctx->uc_mcontext.__gregs[i]);
     83   1.1  pgoyette 	}
     84   1.1  pgoyette }
     85   1.1  pgoyette 
     86   1.1  pgoyette static void
     87   1.1  pgoyette sigalrm_action(int signo, siginfo_t *info, void *ptr)
     88   1.1  pgoyette {
     89   1.1  pgoyette 
     90   1.1  pgoyette 	sig_debug(signo, info, (ucontext_t *)ptr);
     91   1.1  pgoyette 
     92   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_signo, SIGALRM);
     93   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_code, SI_TIMER);
     94   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_value.sival_int, ITIMER_REAL);
     95   1.1  pgoyette 
     96   1.1  pgoyette 	atf_tc_pass();
     97   1.1  pgoyette 	/* NOTREACHED */
     98   1.1  pgoyette }
     99   1.1  pgoyette 
    100   1.1  pgoyette ATF_TC(sigalarm);
    101   1.1  pgoyette 
    102   1.1  pgoyette ATF_TC_HEAD(sigalarm, tc)
    103   1.1  pgoyette {
    104   1.1  pgoyette 
    105   1.1  pgoyette 	atf_tc_set_md_var(tc, "descr",
    106   1.1  pgoyette 	    "Checks that signal trampoline correctly calls SIGALRM handler");
    107   1.1  pgoyette }
    108   1.1  pgoyette 
    109   1.1  pgoyette ATF_TC_BODY(sigalarm, tc)
    110   1.1  pgoyette {
    111   1.1  pgoyette 	struct sigaction sa;
    112   1.1  pgoyette 	sa.sa_flags = SA_SIGINFO;
    113   1.1  pgoyette 	sa.sa_sigaction = sigalrm_action;
    114   1.1  pgoyette 	sigemptyset(&sa.sa_mask);
    115   1.1  pgoyette 	sigaction(SIGALRM, &sa, NULL);
    116   1.1  pgoyette 	for (;;) {
    117   1.1  pgoyette 		alarm(1);
    118   1.1  pgoyette 		sleep(1);
    119   1.1  pgoyette 	}
    120   1.1  pgoyette 	atf_tc_fail("SIGALRM handler wasn't called");
    121   1.1  pgoyette }
    122   1.1  pgoyette 
    123   1.1  pgoyette static void
    124   1.1  pgoyette sigchild_action(int signo, siginfo_t *info, void *ptr)
    125   1.1  pgoyette {
    126   1.1  pgoyette 	if (info != NULL) {
    127   1.1  pgoyette 		printf("info=%p\n", info);
    128   1.1  pgoyette 		printf("ptr=%p\n", ptr);
    129   1.1  pgoyette 		printf("si_signo=%d\n", info->si_signo);
    130   1.1  pgoyette 		printf("si_errno=%d\n", info->si_errno);
    131   1.1  pgoyette 		printf("si_code=%d\n", info->si_code);
    132   1.1  pgoyette 		printf("si_uid=%d\n", info->si_uid);
    133   1.1  pgoyette 		printf("si_pid=%d\n", info->si_pid);
    134   1.1  pgoyette 		printf("si_status=%d\n", info->si_status);
    135   1.3  pgoyette 		printf("si_utime=%lu\n", (unsigned long int)info->si_utime);
    136   1.3  pgoyette 		printf("si_stime=%lu\n", (unsigned long int)info->si_stime);
    137   1.1  pgoyette 	}
    138   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_code, code);
    139   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_signo, SIGCHLD);
    140   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_uid, getuid());
    141   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_pid, child);
    142   1.1  pgoyette 	if (WIFEXITED(info->si_status))
    143   1.1  pgoyette 		ATF_REQUIRE_EQ(WEXITSTATUS(info->si_status), status);
    144   1.1  pgoyette 	else if (WIFSTOPPED(info->si_status))
    145   1.1  pgoyette 		ATF_REQUIRE_EQ(WSTOPSIG(info->si_status), status);
    146   1.1  pgoyette 	else if (WIFSIGNALED(info->si_status))
    147   1.1  pgoyette 		ATF_REQUIRE_EQ(WTERMSIG(info->si_status), status);
    148   1.1  pgoyette }
    149   1.1  pgoyette 
    150   1.1  pgoyette static void
    151   1.1  pgoyette setchildhandler(void (*action)(int, siginfo_t *, void *))
    152   1.1  pgoyette {
    153   1.1  pgoyette 	struct sigaction sa;
    154   1.1  pgoyette 	sa.sa_flags = SA_SIGINFO;
    155   1.1  pgoyette 	sa.sa_sigaction = action;
    156   1.1  pgoyette 	sigemptyset(&sa.sa_mask);
    157   1.1  pgoyette 	sigaction(SIGCHLD, &sa, NULL);
    158   1.1  pgoyette }
    159   1.1  pgoyette 
    160   1.1  pgoyette static void
    161   1.1  pgoyette sigchild_setup(void)
    162   1.1  pgoyette {
    163   1.1  pgoyette 	sigset_t set;
    164   1.1  pgoyette 	struct rlimit rlim;
    165   1.1  pgoyette 
    166   1.1  pgoyette 	(void)getrlimit(RLIMIT_CORE, &rlim);
    167   1.1  pgoyette 	rlim.rlim_cur = rlim.rlim_max;
    168   1.1  pgoyette 	(void)setrlimit(RLIMIT_CORE, &rlim);
    169   1.1  pgoyette 
    170   1.1  pgoyette 	setchildhandler(sigchild_action);
    171   1.1  pgoyette 	sigemptyset(&set);
    172   1.1  pgoyette 	sigaddset(&set, SIGCHLD);
    173   1.1  pgoyette 	sigprocmask(SIG_BLOCK, &set, NULL);
    174   1.1  pgoyette }
    175   1.1  pgoyette 
    176   1.1  pgoyette ATF_TC(sigchild_normal);
    177   1.1  pgoyette ATF_TC_HEAD(sigchild_normal, tc)
    178   1.1  pgoyette {
    179   1.1  pgoyette 
    180   1.1  pgoyette 	atf_tc_set_md_var(tc, "descr",
    181   1.1  pgoyette 	    "Checks that signal trampoline correctly calls SIGCHLD handler "
    182   1.1  pgoyette 	    "when child exits normally");
    183   1.1  pgoyette }
    184   1.1  pgoyette 
    185   1.1  pgoyette ATF_TC_BODY(sigchild_normal, tc)
    186   1.1  pgoyette {
    187   1.1  pgoyette 	sigset_t set;
    188   1.1  pgoyette 
    189   1.1  pgoyette 	sigchild_setup();
    190   1.1  pgoyette 
    191   1.1  pgoyette 	status = 25;
    192   1.1  pgoyette 	code = CLD_EXITED;
    193   1.1  pgoyette 
    194   1.1  pgoyette 	switch ((child = fork())) {
    195   1.1  pgoyette 	case 0:
    196   1.1  pgoyette 		sleep(1);
    197   1.1  pgoyette 		exit(status);
    198   1.1  pgoyette 	case -1:
    199   1.1  pgoyette 		atf_tc_fail("fork failed");
    200   1.1  pgoyette 	default:
    201   1.1  pgoyette 		sigemptyset(&set);
    202   1.1  pgoyette 		sigsuspend(&set);
    203   1.1  pgoyette 	}
    204   1.1  pgoyette }
    205   1.1  pgoyette 
    206   1.1  pgoyette ATF_TC(sigchild_dump);
    207   1.1  pgoyette ATF_TC_HEAD(sigchild_dump, tc)
    208   1.1  pgoyette {
    209   1.1  pgoyette 
    210   1.1  pgoyette 	atf_tc_set_md_var(tc, "descr",
    211   1.1  pgoyette 	    "Checks that signal trampoline correctly calls SIGCHLD handler "
    212   1.1  pgoyette 	    "when child segfaults");
    213   1.1  pgoyette }
    214   1.1  pgoyette 
    215   1.1  pgoyette ATF_TC_BODY(sigchild_dump, tc)
    216   1.1  pgoyette {
    217   1.1  pgoyette 	sigset_t set;
    218   1.1  pgoyette 
    219   1.1  pgoyette 	sigchild_setup();
    220   1.1  pgoyette 
    221   1.1  pgoyette 	status = SIGSEGV;
    222   1.1  pgoyette 	code = CLD_DUMPED;
    223   1.1  pgoyette 
    224   1.1  pgoyette 	switch ((child = fork())) {
    225   1.1  pgoyette 	case 0:
    226   1.1  pgoyette 		sleep(1);
    227   1.1  pgoyette 		*(long *)0 = 0;
    228   1.1  pgoyette 		atf_tc_fail("Child did not segfault");
    229   1.1  pgoyette 		/* NOTREACHED */
    230   1.1  pgoyette 	case -1:
    231   1.1  pgoyette 		atf_tc_fail("fork failed");
    232   1.1  pgoyette 	default:
    233   1.1  pgoyette 		sigemptyset(&set);
    234   1.1  pgoyette 		sigsuspend(&set);
    235   1.1  pgoyette 	}
    236   1.1  pgoyette }
    237   1.1  pgoyette 
    238   1.1  pgoyette ATF_TC(sigchild_kill);
    239   1.1  pgoyette ATF_TC_HEAD(sigchild_kill, tc)
    240   1.1  pgoyette {
    241   1.1  pgoyette 
    242   1.1  pgoyette 	atf_tc_set_md_var(tc, "descr",
    243   1.1  pgoyette 	    "Checks that signal trampoline correctly calls SIGCHLD handler "
    244   1.1  pgoyette 	    "when child is killed");
    245   1.1  pgoyette }
    246   1.1  pgoyette 
    247   1.1  pgoyette ATF_TC_BODY(sigchild_kill, tc)
    248   1.1  pgoyette {
    249   1.1  pgoyette 	sigset_t set;
    250   1.1  pgoyette 
    251   1.1  pgoyette 	sigchild_setup();
    252   1.1  pgoyette 
    253   1.1  pgoyette 	status = SIGPIPE;
    254   1.1  pgoyette 	code = CLD_KILLED;
    255   1.1  pgoyette 
    256   1.1  pgoyette 	switch ((child = fork())) {
    257   1.1  pgoyette 	case 0:
    258   1.1  pgoyette 		sigemptyset(&set);
    259   1.1  pgoyette 		sigsuspend(&set);
    260   1.1  pgoyette 		break;
    261   1.1  pgoyette 	case -1:
    262   1.1  pgoyette 		atf_tc_fail("fork failed");
    263   1.1  pgoyette 	default:
    264   1.1  pgoyette 		kill(child, SIGPIPE);
    265   1.1  pgoyette 		sigemptyset(&set);
    266   1.1  pgoyette 		sigsuspend(&set);
    267   1.1  pgoyette 	}
    268   1.1  pgoyette }
    269   1.1  pgoyette 
    270   1.5   mlelstv static sigjmp_buf sigfpe_flt_env;
    271   1.1  pgoyette static void
    272   1.1  pgoyette sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
    273   1.1  pgoyette {
    274   1.1  pgoyette 
    275   1.1  pgoyette 	sig_debug(signo, info, (ucontext_t *)ptr);
    276   1.1  pgoyette 
    277   1.1  pgoyette 	if (fltdiv_signalled++ != 0)
    278   1.1  pgoyette 		atf_tc_fail("FPE handler called more than once");
    279   1.1  pgoyette 
    280   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_signo, SIGFPE);
    281   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_code, FPE_FLTDIV);
    282   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_errno, 0);
    283   1.5   mlelstv 
    284   1.5   mlelstv 	siglongjmp(sigfpe_flt_env, 1);
    285   1.1  pgoyette }
    286   1.1  pgoyette 
    287   1.1  pgoyette ATF_TC(sigfpe_flt);
    288   1.1  pgoyette ATF_TC_HEAD(sigfpe_flt, tc)
    289   1.1  pgoyette {
    290   1.1  pgoyette 
    291   1.1  pgoyette 	atf_tc_set_md_var(tc, "descr",
    292   1.1  pgoyette 	    "Checks that signal trampoline correctly calls SIGFPE handler "
    293   1.1  pgoyette 	    "for floating div-by-zero");
    294   1.1  pgoyette }
    295   1.1  pgoyette 
    296   1.1  pgoyette ATF_TC_BODY(sigfpe_flt, tc)
    297   1.1  pgoyette {
    298   1.1  pgoyette 	struct sigaction sa;
    299   1.1  pgoyette 	double d = strtod("0", NULL);
    300   1.1  pgoyette 
    301   1.8  pgoyette 	if (system("cpuctl identify 0 | grep -q QEMU") == 0)
    302   1.8  pgoyette 		atf_tc_skip("Test does not run correctly under qemu");
    303   1.9     pooka 	if (system("cpuctl identify 0 | grep -q "
    304   1.9     pooka 	    "'cpu0: Intel Pentium II (Klamath) (686-class), id 0x633'") == 0)
    305   1.9     pooka 		atf_tc_skip("Test does not run correctly under qemu "
    306   1.9     pooka 		    "(heuristic match)");
    307  1.10       riz 	if (strcmp(atf_config_get("atf_arch"),"powerpc") == 0)
    308  1.10       riz 		atf_tc_skip("Test not valid on powerpc");
    309   1.5   mlelstv 	if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
    310   1.5   mlelstv 		sa.sa_flags = SA_SIGINFO;
    311   1.5   mlelstv 		sa.sa_sigaction = sigfpe_flt_action;
    312   1.5   mlelstv 		sigemptyset(&sa.sa_mask);
    313   1.5   mlelstv 		sigaction(SIGFPE, &sa, NULL);
    314   1.1  pgoyette #ifndef __vax__
    315   1.5   mlelstv 		fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
    316   1.1  pgoyette #endif
    317   1.5   mlelstv 		printf("%g\n", 1 / d);
    318   1.5   mlelstv 	}
    319   1.1  pgoyette 	if (fltdiv_signalled == 0)
    320   1.1  pgoyette 		atf_tc_fail("FPE signal handler was not invoked");
    321   1.1  pgoyette }
    322   1.1  pgoyette 
    323   1.5   mlelstv static sigjmp_buf sigfpe_int_env;
    324   1.1  pgoyette static void
    325   1.1  pgoyette sigfpe_int_action(int signo, siginfo_t *info, void *ptr)
    326   1.1  pgoyette {
    327   1.1  pgoyette 
    328   1.1  pgoyette 	sig_debug(signo, info, (ucontext_t *)ptr);
    329   1.1  pgoyette 
    330   1.1  pgoyette 	if (intdiv_signalled++ != 0)
    331   1.1  pgoyette 		atf_tc_fail("INTDIV handler called more than once");
    332   1.1  pgoyette 
    333   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_signo, SIGFPE);
    334   1.1  pgoyette 	if (info->si_code == FPE_FLTDIV)
    335   1.1  pgoyette 		atf_tc_expect_fail("PR port-i386/43655 : integer div-by-zero "
    336   1.1  pgoyette 		    "reports FPE_FLTDIV instead of FPE_INTDIV");
    337   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_code, FPE_INTDIV);
    338   1.7  pgoyette 	atf_tc_expect_pass();
    339   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_errno, 0);
    340   1.5   mlelstv 
    341   1.5   mlelstv 	siglongjmp(sigfpe_int_env, 1);
    342   1.1  pgoyette }
    343   1.1  pgoyette 
    344   1.1  pgoyette ATF_TC(sigfpe_int);
    345   1.1  pgoyette ATF_TC_HEAD(sigfpe_int, tc)
    346   1.1  pgoyette {
    347   1.1  pgoyette 
    348   1.1  pgoyette 	atf_tc_set_md_var(tc, "descr",
    349   1.1  pgoyette 	    "Checks that signal trampoline correctly calls SIGFPE handler "
    350   1.1  pgoyette 	    "for integer div-by-zero");
    351   1.1  pgoyette }
    352   1.1  pgoyette 
    353   1.1  pgoyette ATF_TC_BODY(sigfpe_int, tc)
    354   1.1  pgoyette {
    355   1.1  pgoyette 	struct sigaction sa;
    356   1.4     njoly 	long l = strtol("0", NULL, 10);
    357   1.1  pgoyette 
    358  1.10       riz 	if (strcmp(atf_config_get("atf_arch"),"powerpc") == 0)
    359  1.10       riz 		atf_tc_skip("Test not valid on powerpc");
    360   1.5   mlelstv 	if (sigsetjmp(sigfpe_int_env, 0) == 0) {
    361   1.5   mlelstv 		sa.sa_flags = SA_SIGINFO;
    362   1.5   mlelstv 		sa.sa_sigaction = sigfpe_int_action;
    363   1.5   mlelstv 		sigemptyset(&sa.sa_mask);
    364   1.5   mlelstv 		sigaction(SIGFPE, &sa, NULL);
    365   1.1  pgoyette #ifndef __vax__
    366   1.5   mlelstv 		fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
    367   1.1  pgoyette #endif
    368   1.5   mlelstv 		printf("%ld\n", 1 / l);
    369   1.5   mlelstv 	}
    370   1.1  pgoyette 	if (intdiv_signalled == 0)
    371   1.1  pgoyette 		atf_tc_fail("FPE signal handler was not invoked");
    372   1.1  pgoyette }
    373   1.1  pgoyette 
    374   1.1  pgoyette static void
    375   1.1  pgoyette sigsegv_action(int signo, siginfo_t *info, void *ptr)
    376   1.1  pgoyette {
    377   1.1  pgoyette 
    378   1.1  pgoyette 	sig_debug(signo, info, (ucontext_t *)ptr);
    379   1.1  pgoyette 
    380   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_signo, SIGSEGV);
    381   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_errno, 0);
    382   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_code, SEGV_MAPERR);
    383   1.1  pgoyette 	ATF_REQUIRE_EQ(info->si_addr, (void *)0);
    384   1.1  pgoyette 
    385   1.1  pgoyette 	atf_tc_pass();
    386   1.1  pgoyette 	/* NOTREACHED */
    387   1.1  pgoyette }
    388   1.1  pgoyette 
    389   1.1  pgoyette ATF_TC(sigsegv);
    390   1.1  pgoyette ATF_TC_HEAD(sigsegv, tc)
    391   1.1  pgoyette {
    392   1.1  pgoyette 
    393   1.1  pgoyette 	atf_tc_set_md_var(tc, "descr",
    394   1.1  pgoyette 	    "Checks that signal trampoline correctly calls SIGSEGV handler");
    395   1.1  pgoyette }
    396   1.1  pgoyette 
    397   1.1  pgoyette ATF_TC_BODY(sigsegv, tc)
    398   1.1  pgoyette {
    399   1.1  pgoyette 	struct sigaction sa;
    400   1.1  pgoyette 
    401   1.1  pgoyette 	sa.sa_flags = SA_SIGINFO;
    402   1.1  pgoyette 	sa.sa_sigaction = sigsegv_action;
    403   1.1  pgoyette 	sigemptyset(&sa.sa_mask);
    404   1.1  pgoyette 	sigaction(SIGSEGV, &sa, NULL);
    405   1.1  pgoyette 
    406   1.1  pgoyette 	*(long *)0 = 0;
    407   1.1  pgoyette 	atf_tc_fail("Test did not fault as expected");
    408   1.1  pgoyette }
    409   1.1  pgoyette 
    410   1.1  pgoyette ATF_TP_ADD_TCS(tp)
    411   1.1  pgoyette {
    412   1.1  pgoyette 
    413   1.1  pgoyette 	ATF_TP_ADD_TC(tp, sigalarm);
    414   1.1  pgoyette 	ATF_TP_ADD_TC(tp, sigchild_normal);
    415   1.1  pgoyette 	ATF_TP_ADD_TC(tp, sigchild_dump);
    416   1.1  pgoyette 	ATF_TP_ADD_TC(tp, sigchild_kill);
    417   1.1  pgoyette 	ATF_TP_ADD_TC(tp, sigfpe_flt);
    418   1.1  pgoyette 	ATF_TP_ADD_TC(tp, sigfpe_int);
    419   1.1  pgoyette 	ATF_TP_ADD_TC(tp, sigsegv);
    420   1.1  pgoyette 
    421   1.1  pgoyette 	return atf_no_error();
    422   1.1  pgoyette }
    423