Module Name: src Committed By: kamil Date: Wed May 23 13:18:09 UTC 2018
Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: 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> To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 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_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.5 src/tests/lib/libc/sys/t_ptrace_wait.h:1.6 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.5 Sat May 19 05:04:09 2018 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Wed May 23 13:18:09 2018 @@ -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 @@ check_happy(unsigned n) } #if defined(HAVE_DBREGS) -static bool +static bool __used can_we_set_dbregs(void) { static long euid = -1; @@ -504,6 +504,70 @@ can_we_set_dbregs(void) } #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