Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/sys Add new auxiliary functions in ATF ptrace...



details:   https://anonhg.NetBSD.org/src/rev/13326a4fea8f
branches:  trunk
changeset: 319276:13326a4fea8f
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed May 23 13:18:09 2018 +0000

description:
Add new auxiliary functions in ATF ptrace(2) tests

Introduce:
 - trigger_trap()
 - trigger_segv()
 - trigger_ill()
 - trigger_fpe()
 - trigger_bus()

These functions generate appropriate signals caused by crashes.

A debugger is required to collect the crashes regardless of signal masking,
catching or ignoring rules.

While there, append __used argument to can_we_set_dbregs().

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.h |  68 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 2 deletions(-)

diffs (89 lines):

diff -r 60371d5851bb -r 13326a4fea8f tests/lib/libc/sys/t_ptrace_wait.h
--- a/tests/lib/libc/sys/t_ptrace_wait.h        Wed May 23 11:16:13 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.h        Wed May 23 13:18:09 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.h,v 1.5 2018/05/19 05:04:09 kamil Exp $  */
+/*     $NetBSD: t_ptrace_wait.h,v 1.6 2018/05/23 13:18:09 kamil Exp $  */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -476,7 +476,7 @@
 }
 
 #if defined(HAVE_DBREGS)
-static bool
+static bool __used
 can_we_set_dbregs(void)
 {
        static long euid = -1;
@@ -504,6 +504,70 @@
 }
 #endif
 
+static void __used
+trigger_trap(void)
+{
+
+       /* Software breakpoint causes CPU trap, translated to SIGTRAP */
+#ifdef PTRACE_BREAKPOINT_ASM
+       PTRACE_BREAKPOINT_ASM;
+#else
+       /* port me */
+#endif
+}
+
+static void __used
+trigger_segv(void)
+{
+       static volatile char *ptr = NULL;
+
+       /* Access to unmapped memory causes CPU trap, translated to SIGSEGV */
+       *ptr = 1;
+}
+
+static void __used
+trigger_ill(void)
+{
+
+       /* Illegal instruction causes CPU trap, translated to SIGILL */
+#ifdef PTRACE_ILLEGAL_ASM
+       PTRACE_ILLEGAL_ASM;
+#else
+       /* port me */
+#endif
+}
+
+static int __used
+trigger_fpe(void)
+{
+       static volatile int a = 1;
+       static volatile int b = 0;
+       static volatile int c;
+
+       /* Division by zero causes CPU trap, translated to SIGFPE */
+       c = a / b;
+
+       return c;
+}
+
+static void __used
+trigger_bus(void)
+{
+       FILE *fp;
+       char *p;
+
+       /* Open an empty file for writing. */
+       fp = tmpfile();
+       FORKEE_ASSERT_NEQ((uintmax_t)fp, (uintmax_t)NULL);
+
+       /* Map an empty file with mmap(2) to a pointer. */
+       p = mmap(0, 1, PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
+       FORKEE_ASSERT_NEQ((uintmax_t)p, (uintmax_t)MAP_FAILED);
+
+       /* Invalid memory access causes CPU trap, translated to SIGBUS */
+       *p = 'a';
+}
+
 #if defined(TWAIT_HAVE_PID)
 #define ATF_TP_ADD_TC_HAVE_PID(a,b)    ATF_TP_ADD_TC(a,b)
 #else



Home | Main Index | Thread Index | Old Index