Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel Use feenableexcept to trap fp exceptions, and t...



details:   https://anonhg.NetBSD.org/src/rev/f88cccee90e2
branches:  trunk
changeset: 994499:f88cccee90e2
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Nov 11 01:26:08 2018 +0000

description:
Use feenableexcept to trap fp exceptions, and trigger one, for SIGFPE.

Not every CPU traps integer division by zero -- aarch64, powerpc,
&c., just return zero.

diffstat:

 tests/kernel/Makefile |   4 +++-
 tests/kernel/h_segv.c |  13 ++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diffs (57 lines):

diff -r 5a792e0f0342 -r f88cccee90e2 tests/kernel/Makefile
--- a/tests/kernel/Makefile     Sun Nov 11 01:26:00 2018 +0000
+++ b/tests/kernel/Makefile     Sun Nov 11 01:26:08 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.53 2018/03/14 02:13:47 kamil Exp $
+# $NetBSD: Makefile,v 1.54 2018/11/11 01:26:08 riastradh Exp $
 
 NOMAN=         # defined
 
@@ -67,4 +67,6 @@
 
 CLEANFILES+=   t_subr_prf.c
 
+LDADD.h_segv+= -lm
+
 .include <bsd.test.mk>
diff -r 5a792e0f0342 -r f88cccee90e2 tests/kernel/h_segv.c
--- a/tests/kernel/h_segv.c     Sun Nov 11 01:26:00 2018 +0000
+++ b/tests/kernel/h_segv.c     Sun Nov 11 01:26:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: h_segv.c,v 1.8 2018/11/11 01:26:00 riastradh Exp $     */
+/*     $NetBSD: h_segv.c,v 1.9 2018/11/11 01:26:08 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -29,13 +29,14 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: h_segv.c,v 1.8 2018/11/11 01:26:00 riastradh Exp $");
+__RCSID("$NetBSD: h_segv.c,v 1.9 2018/11/11 01:26:08 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/ptrace.h>
 
 #include <err.h>
+#include <fenv.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -103,10 +104,12 @@
 static void
 trigger_fpe(void)
 {
-       volatile int a = getpid();
-       volatile int b = strtol("0", NULL, 0);
+       volatile double a = getpid();
+       volatile double b = strtol("0", NULL, 0);
 
-       usleep(a/b);
+       feenableexcept(FE_ALL_EXCEPT);
+
+       usleep((int)(a/b));
 }
 
 static void



Home | Main Index | Thread Index | Old Index