Module Name: src Committed By: rin Date: Mon Jun 22 12:21:03 UTC 2020
Modified Files: src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h Log Message: Work around QEMU bug #1668041 differently, by which floating-point division by zero is not correctly trapped for i386 and amd64: https://bugs.launchpad.net/qemu/+bug/1668041 Make trigger_fpe() cause integer division by zero for x86, and floating-point one for other architectures. Also, assertions for si_code in *_crash_fpe tests are commented out for now. They should be cleaned up after the bug is fixed. Now, *_crash_fpe tests are working also on powerpc. Suggested by kamil. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_signal_wait.h cvs rdiff -u -r1.31 -r1.32 src/tests/lib/libc/sys/t_ptrace_wait.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libc/sys/t_ptrace_signal_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.3 src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.4 --- src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.3 Mon Jun 22 02:51:06 2020 +++ src/tests/lib/libc/sys/t_ptrace_signal_wait.h Mon Jun 22 12:21:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_signal_wait.h,v 1.3 2020/06/22 02:51:06 rin Exp $ */ +/* $NetBSD: t_ptrace_signal_wait.h,v 1.4 2020/06/22 12:21:02 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -423,7 +423,7 @@ traceme_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); +// XXXQEMU ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -603,7 +603,7 @@ traceme_signalmasked_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); +// XXXQEMU ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -786,7 +786,7 @@ traceme_signalignored_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); +// XXXQEMU ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -1890,7 +1890,7 @@ unrelated_tracer_sees_crash(int sig, boo info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_INTDIV); +// XXXQEMU FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, BUS_ADRERR); Index: src/tests/lib/libc/sys/t_ptrace_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.31 src/tests/lib/libc/sys/t_ptrace_wait.h:1.32 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.31 Mon Jun 22 02:51:06 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Mon Jun 22 12:21:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.31 2020/06/22 02:51:06 rin Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.32 2020/06/22 12:21:02 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -671,9 +671,6 @@ are_fpu_exceptions_supported(void) return false; return true; } -#elif __powerpc__ -/* Integer division by zero do not trap on powerpc. */ -#define are_fpu_exceptions_supported() 0 #else #define are_fpu_exceptions_supported() 1 #endif @@ -681,15 +678,28 @@ are_fpu_exceptions_supported(void) static void __used trigger_fpe(void) { - volatile int a = getpid(); - volatile int b = atoi("0"); +#if __i386__ || __x86_64__ + /* + * XXX + * Hack for QEMU bug #1668041, by which floating-point division by + * zero is not trapped correctly. Also, assertions for si_code in + * ptrace_signal_wait.h are commented out. Clean them up after the + * bug is fixed. + */ + volatile int a, b; +#else + volatile double a, b; +#endif + + a = getpid(); + b = atoi("0"); #ifdef __HAVE_FENV feenableexcept(FE_ALL_EXCEPT); #endif /* Division by zero causes CPU trap, translated to SIGFPE */ - usleep(a / b); + usleep((int)(a / b)); } static void __used