Source-Changes-HG archive

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

[src/trunk]: src/tests Make the trigger_bus() test compatible with more CPUs ...



details:   https://anonhg.NetBSD.org/src/rev/548a92b66376
branches:  trunk
changeset: 323078:548a92b66376
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed May 30 17:31:34 2018 +0000

description:
Make the trigger_bus() test compatible with more CPUs (at least ALPHA)

If we write a byte character into a pointer, a compiler can emit a
read-modify-write operation, especially when a CPU cannot access directly
a character wide address.

In this scenario calling mmap(2) with PROT_WRITE, without PROT_READ will
emit unexpected trap.

There are two possible workarounds for this issue:
 - write register wide memory without rmw sequence,
 - mark the region with additional protection PROT_READ

Both work for NetBSD/alpha.

Go for the latter as perhaps more safe for dump compilers emitting rmw
sequences.

Investigated by <martin>

diffstat:

 tests/kernel/h_segv.c              |  6 +++---
 tests/lib/libc/sys/t_ptrace_wait.h |  4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r 6d1a93f1cd15 -r 548a92b66376 tests/kernel/h_segv.c
--- a/tests/kernel/h_segv.c     Wed May 30 17:17:11 2018 +0000
+++ b/tests/kernel/h_segv.c     Wed May 30 17:31:34 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: h_segv.c,v 1.5 2018/05/27 17:04:45 kamil Exp $ */
+/*     $NetBSD: h_segv.c,v 1.6 2018/05/30 17:31:34 kamil Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: h_segv.c,v 1.5 2018/05/27 17:04:45 kamil Exp $");
+__RCSID("$NetBSD: h_segv.c,v 1.6 2018/05/30 17:31:34 kamil Exp $");
 
 #include <sys/types.h>
 #include <sys/mman.h>
@@ -120,7 +120,7 @@
                err(EXIT_FAILURE, "tmpfile");
 
        /* Map an empty file with mmap(2) to a pointer. */
-       p = mmap(0, 1, PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
+       p = mmap(0, 1, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
        if (p == MAP_FAILED)
                err(EXIT_FAILURE, "mmap");
 
diff -r 6d1a93f1cd15 -r 548a92b66376 tests/lib/libc/sys/t_ptrace_wait.h
--- a/tests/lib/libc/sys/t_ptrace_wait.h        Wed May 30 17:17:11 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.h        Wed May 30 17:31:34 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.h,v 1.9 2018/05/27 17:16:39 kamil Exp $  */
+/*     $NetBSD: t_ptrace_wait.h,v 1.10 2018/05/30 17:31:34 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -575,7 +575,7 @@
        FORKEE_ASSERT_NEQ((uintptr_t)fp, (uintptr_t)NULL);
 
        /* Map an empty file with mmap(2) to a pointer. */
-       p = mmap(0, 1, PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
+       p = mmap(0, 1, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
        FORKEE_ASSERT_NEQ((uintptr_t)p, (uintptr_t)MAP_FAILED);
 
        /* Invalid memory access causes CPU trap, translated to SIGBUS */



Home | Main Index | Thread Index | Old Index