Module Name: src
Committed By: kamil
Date: Wed May 30 17:31:34 UTC 2018
Modified Files:
src/tests/kernel: h_segv.c
src/tests/lib/libc/sys: t_ptrace_wait.h
Log Message:
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>
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/h_segv.c
cvs rdiff -u -r1.9 -r1.10 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/kernel/h_segv.c
diff -u src/tests/kernel/h_segv.c:1.5 src/tests/kernel/h_segv.c:1.6
--- src/tests/kernel/h_segv.c:1.5 Sun May 27 17:04:45 2018
+++ src/tests/kernel/h_segv.c Wed May 30 17:31:34 2018
@@ -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 @@ trigger_bus(void)
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");
Index: src/tests/lib/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.9 src/tests/lib/libc/sys/t_ptrace_wait.h:1.10
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.9 Sun May 27 17:16:39 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.h Wed May 30 17:31:34 2018
@@ -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 @@ trigger_bus(void)
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 */