CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Sat Jul 24 08:39:54 UTC 2021 Modified Files: src/tests/lib/libc/sys: t_ptrace_core_wait.h Log Message: For sh3, increment PC when PT_CONTINUE from trigger_trap(), as already done for aarch64, arm, and powerpc. Otherwise, child is trapped to the PTRACE_BREAKPOINT_ASM (== trapa) instruction indefinitely. Fix tests/lib/libc/sys/t_ptrace_wait*:core_dump_procinfo. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_core_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_core_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.3 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.4 --- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.3 Thu Oct 15 22:59:50 2020 +++ src/tests/lib/libc/sys/t_ptrace_core_wait.h Sat Jul 24 08:39:54 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_core_wait.h,v 1.3 2020/10/15 22:59:50 rin Exp $ */ +/* $NetBSD: t_ptrace_core_wait.h,v 1.4 2021/07/24 08:39:54 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -208,7 +208,8 @@ ATF_TC_BODY(core_dump_procinfo, tc) DPRINTF("Before resuming the child process where it left off and " "without signal to be sent\n"); -#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) +#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) || \ +defined(__sh3__) /* * For these archs, program counter is not automatically incremented * by a trap instruction. We cannot increment PC in the trap handler, @@ -220,12 +221,7 @@ ATF_TC_BODY(core_dump_procinfo, tc) SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, , 0) != -1); SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, -# if defined(__aarch64__) || defined(__arm__) - (void *)(r.r_pc + PTRACE_BREAKPOINT_SIZE), -# elif defined(__powerpc__) - (void *)(r.pc + PTRACE_BREAKPOINT_SIZE), -# endif - 0) != -1); + (void *)(PTRACE_REG_PC() + PTRACE_BREAKPOINT_SIZE), 0) != -1); #else SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); #endif
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: martin Date: Sat Jul 17 14:03:36 UTC 2021 Modified Files: src/tests/lib/libc/sys: t_wait.c Log Message: PR 56313: fix eroneous = that was meant to be == To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/sys/t_wait.c 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_wait.c diff -u src/tests/lib/libc/sys/t_wait.c:1.9 src/tests/lib/libc/sys/t_wait.c:1.10 --- src/tests/lib/libc/sys/t_wait.c:1.9 Mon Feb 4 09:35:11 2019 +++ src/tests/lib/libc/sys/t_wait.c Sat Jul 17 14:03:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_wait.c,v 1.9 2019/02/04 09:35:11 mrg Exp $ */ +/* $NetBSD: t_wait.c,v 1.10 2021/07/17 14:03:35 martin Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_wait.c,v 1.9 2019/02/04 09:35:11 mrg Exp $"); +__RCSID("$NetBSD: t_wait.c,v 1.10 2021/07/17 14:03:35 martin Exp $"); #include #include @@ -85,7 +85,7 @@ ATF_TC_BODY(wait6_exited, tc) default: ATF_REQUIRE(wait6(P_PID, pid, , WEXITED, , ) == pid); ATF_REQUIRE(WIFEXITED(st) && WEXITSTATUS(st) == 0x5a); - ATF_REQUIRE(si.si_status = 0x5a5a5a5a); + ATF_REQUIRE(si.si_status == 0x5a5a5a5a); ATF_REQUIRE(si.si_pid == pid); ATF_REQUIRE(si.si_uid == getuid()); ATF_REQUIRE(si.si_code == CLD_EXITED);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: gson Date: Mon May 24 10:44:06 UTC 2021 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: On mips, avoid deliberately executing an illegal instruction for now because it causes GXemul to exit rather than generating a trap. A bug report has been sent to the GXemul author. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 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.32 src/tests/lib/libc/sys/t_ptrace_wait.h:1.33 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.32 Mon Jun 22 12:21:02 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Mon May 24 10:44:06 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.32 2020/06/22 12:21:02 rin Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.33 2021/05/24 10:44:06 gson Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -648,7 +648,9 @@ trigger_ill(void) /* Illegal instruction causes CPU trap, translated to SIGILL */ #ifdef PTRACE_ILLEGAL_ASM +#ifndef __mips__ /* To avoid GXemul crash */ PTRACE_ILLEGAL_ASM; +#endif #else /* port me */ #endif
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Sun Mar 28 17:30:01 UTC 2021 Modified Files: src/tests/lib/libc/sys: t_sendrecv.c Log Message: yield so we can lose packets To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_sendrecv.c 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_sendrecv.c diff -u src/tests/lib/libc/sys/t_sendrecv.c:1.7 src/tests/lib/libc/sys/t_sendrecv.c:1.8 --- src/tests/lib/libc/sys/t_sendrecv.c:1.7 Sun Mar 21 12:58:07 2021 +++ src/tests/lib/libc/sys/t_sendrecv.c Sun Mar 28 13:30:01 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $ */ +/* $NetBSD: t_sendrecv.c,v 1.8 2021/03/28 17:30:01 christos Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $"); +__RCSID("$NetBSD: t_sendrecv.c,v 1.8 2021/03/28 17:30:01 christos Exp $"); #include #include @@ -40,6 +40,7 @@ __RCSID("$NetBSD: t_sendrecv.c,v 1.7 202 #include #include #include +#include #include #include @@ -94,6 +95,8 @@ receiver(int sd) return; if (p.seq != seq) printf("%ju != %ju\n", p.seq, seq); + if (seq % 10 == 0) +sched_yield(); seq = p.seq + 1; } // printf("<<%zd %d %ju\n", n, errno, seq);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Sun Mar 21 16:58:07 UTC 2021 Modified Files: src/tests/lib/libc/sys: t_sendrecv.c Log Message: use a pipe instead of sched_yield() To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_sendrecv.c 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_sendrecv.c diff -u src/tests/lib/libc/sys/t_sendrecv.c:1.6 src/tests/lib/libc/sys/t_sendrecv.c:1.7 --- src/tests/lib/libc/sys/t_sendrecv.c:1.6 Sat Feb 2 22:19:28 2019 +++ src/tests/lib/libc/sys/t_sendrecv.c Sun Mar 21 12:58:07 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_sendrecv.c,v 1.6 2019/02/03 03:19:28 mrg Exp $ */ +/* $NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_sendrecv.c,v 1.6 2019/02/03 03:19:28 mrg Exp $"); +__RCSID("$NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $"); #include #include @@ -41,7 +41,6 @@ __RCSID("$NetBSD: t_sendrecv.c,v 1.6 201 #include #include #include -#include #include @@ -62,33 +61,33 @@ handle_sigchld(__unused int pid) } static void -sender(int fd) +sender(int sd) { union packet p; ssize_t n; p.seq = 0; for (size_t i = 0; i < COUNT; i++) { - for (; (n = send(fd, , sizeof(p), 0)) == sizeof(p); + for (; (n = send(sd, , sizeof(p), 0)) == sizeof(p); p.seq++) continue; - printf(">>%zd %d %ju\n", n, errno, p.seq); +// printf(">>%zd %d %ju\n", n, errno, p.seq); ATF_REQUIRE_MSG(errno == ENOBUFS, "send %s", strerror(errno)); -// sched_yield(); } - printf("sender done\n"); + close(sd); +// printf("sender done\n"); } static void -receiver(int fd) +receiver(int sd) { union packet p; ssize_t n; uintmax_t seq = 0; - do { + for (size_t i = 0; i < COUNT; i++) { if (rdied) return; - while ((n = recv(fd, , sizeof(p), 0), sizeof(p)) + while ((n = recv(sd, , sizeof(p), 0), sizeof(p)) == sizeof(p)) { if (rdied) @@ -97,26 +96,29 @@ receiver(int fd) printf("%ju != %ju\n", p.seq, seq); seq = p.seq + 1; } - printf("<<%zd %d %ju\n", n, errno, seq); +// printf("<<%zd %d %ju\n", n, errno, seq); if (n == 0) return; ATF_REQUIRE_EQ(n, -1); ATF_REQUIRE_MSG(errno == ENOBUFS, "recv %s", strerror(errno)); - } while (p.seq < COUNT); + } + close(sd); } static void sendrecv(int rerror) { - int fd[2], error; + int fd[2], sd[2], error; + char c = 0; struct sigaction sa; - error = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd); -// error = pipe(fd); + error = socketpair(AF_UNIX, SOCK_DGRAM, 0, sd); ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno)); + error = pipe(fd); + ATF_REQUIRE_MSG(error != -1, "pipe failed (%s)", strerror(errno)); - for (size_t i = 0; i < __arraycount(fd); i++) { - error = setsockopt(fd[i], SOL_SOCKET, SO_RERROR, , + for (size_t i = 0; i < __arraycount(sd); i++) { + error = setsockopt(sd[i], SOL_SOCKET, SO_RERROR, , sizeof(rerror)); ATF_REQUIRE_MSG(error != -1, "setsockopt(SO_RERROR) failed (%s)", strerror(errno)); @@ -133,17 +135,18 @@ sendrecv(int rerror) switch (fork()) { case -1: ATF_REQUIRE_MSG(errno == 0, - "socketpair failed (%s)", strerror(errno)); + "fork failed (%s)", strerror(errno)); __unreachable(); /*NOTREACHED*/ case 0: - sched_yield(); - sender(fd[0]); - close(fd[0]); + read(fd[1], , sizeof(c)); + sender(sd[0]); + close(sd[0]); exit(EXIT_SUCCESS); /*NOTREACHED*/ default: - receiver(fd[1]); + write(fd[0], , sizeof(c)); + receiver(sd[1]); return; } }
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: simonb Date: Fri Mar 19 00:44:09 UTC 2021 Modified Files: src/tests/lib/libc/sys: t_ptrace_signal_wait.h Log Message: Sprinkle a few more \n's and the end of some debug printfs. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_ptrace_signal_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_signal_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.4 src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.5 --- src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.4 Mon Jun 22 12:21:02 2020 +++ src/tests/lib/libc/sys/t_ptrace_signal_wait.h Fri Mar 19 00:44:09 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_signal_wait.h,v 1.4 2020/06/22 12:21:02 rin Exp $ */ +/* $NetBSD: t_ptrace_signal_wait.h,v 1.5 2021/03/19 00:44:09 simonb Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ traceme_raise(int sigval) ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); - DPRINTF("Assert that PT_GET_PROCESS_STATE returns non-error"); + DPRINTF("Assert that PT_GET_PROCESS_STATE returns non-error\n"); SYSCALL_REQUIRE( ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1); ATF_REQUIRE(memcmp(, _state, slen) == 0); @@ -401,7 +401,7 @@ traceme_crash(int sig) validate_status_stopped(status, sig); - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child"); + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); SYSCALL_REQUIRE( ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); @@ -567,7 +567,7 @@ traceme_signalmasked_crash(int sig) validate_status_stopped(status, sig); - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child"); + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); SYSCALL_REQUIRE( ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); @@ -750,7 +750,7 @@ traceme_signalignored_crash(int sig) validate_status_stopped(status, sig); - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child"); + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); SYSCALL_REQUIRE( ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: simonb Date: Mon Jan 18 05:44:21 UTC 2021 Modified Files: src/tests/lib/libc/sys: t_syscall.c Log Message: Check for MAP_FAILED instead of NULL when looking for an error from mmap(2). To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_syscall.c 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_syscall.c diff -u src/tests/lib/libc/sys/t_syscall.c:1.3 src/tests/lib/libc/sys/t_syscall.c:1.4 --- src/tests/lib/libc/sys/t_syscall.c:1.3 Mon May 28 07:55:56 2018 +++ src/tests/lib/libc/sys/t_syscall.c Mon Jan 18 05:44:20 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_syscall.c,v 1.3 2018/05/28 07:55:56 martin Exp $ */ +/* $NetBSD: t_syscall.c,v 1.4 2021/01/18 05:44:20 simonb Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_syscall.c,v 1.3 2018/05/28 07:55:56 martin Exp $"); +__RCSID("$NetBSD: t_syscall.c,v 1.4 2021/01/18 05:44:20 simonb Exp $"); #include @@ -75,7 +75,7 @@ ATF_TC_BODY(mmap_syscall, tc) p = (const char *)syscall(SYS_mmap, 0, sizeof(secrect_data), PROT_READ, MAP_PRIVATE, fd, 0, 0, 0); - ATF_REQUIRE(p != NULL); + ATF_REQUIRE(p != MAP_FAILED); ATF_REQUIRE(strcmp(p, secrect_data) == 0); } @@ -101,7 +101,7 @@ ATF_TC_BODY(mmap___syscall, tc) p = (const char *)__SYSCALL_TO_UINTPTR_T(__syscall(SYS_mmap, 0, sizeof(secrect_data), PROT_READ, MAP_PRIVATE, fd, /* pad*/ 0, (off_t)0)); - ATF_REQUIRE(p != NULL); + ATF_REQUIRE(p != MAP_FAILED); ATF_REQUIRE(strcmp(p, secrect_data) == 0); }
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Tue Oct 27 08:32:36 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Add tests for AVX-512 registers (zmm0..zmm31, k0..7) Thanks to David Seifert for providing a VM on an AVX-512 capable hardware Reviewed by kamil To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.30 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.31 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.30 Sat Oct 24 07:14:30 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Tue Oct 27 08:32:36 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.30 2020/10/24 07:14:30 mgorny Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.31 2020/10/27 08:32:36 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -2177,6 +2177,9 @@ ATF_TC_BODY(x86_cve_2018_8897, tc) union x86_test_register { struct { + uint64_t a, b, c, d, e, f, g, h; + } zmm; + struct { uint64_t a, b, c, d; } ymm; struct { @@ -2220,7 +2223,8 @@ enum x86_test_registers { FPREGS_MM, FPREGS_XMM, /* TEST_XSTATE */ - FPREGS_YMM + FPREGS_YMM, + FPREGS_ZMM }; enum x86_test_regmode { @@ -2396,14 +2400,14 @@ static __inline void get_gp64_r8_regs(un "\n\t" "int3\n\t" "\n\t" - "movq%%r8, 0x00(%0)\n\t" - "movq%%r9, 0x20(%0)\n\t" - "movq%%r10, 0x40(%0)\n\t" - "movq%%r11, 0x60(%0)\n\t" - "movq%%r12, 0x80(%0)\n\t" - "movq%%r13, 0xA0(%0)\n\t" - "movq%%r14, 0xC0(%0)\n\t" - "movq%%r15, 0xE0(%0)\n\t" + "movq%%r8, 0x000(%0)\n\t" + "movq%%r9, 0x040(%0)\n\t" + "movq%%r10, 0x080(%0)\n\t" + "movq%%r11, 0x0C0(%0)\n\t" + "movq%%r12, 0x100(%0)\n\t" + "movq%%r13, 0x140(%0)\n\t" + "movq%%r14, 0x180(%0)\n\t" + "movq%%r15, 0x1C0(%0)\n\t" : : "a"(out), "m"(fill) : "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" @@ -2417,14 +2421,14 @@ static __inline void set_gp64_r8_regs(co { #if defined(__x86_64__) __asm__ __volatile__( - "movq0x00(%0), %%r8\n\t" - "movq0x20(%0), %%r9\n\t" - "movq0x40(%0), %%r10\n\t" - "movq0x60(%0), %%r11\n\t" - "movq0x80(%0), %%r12\n\t" - "movq0xA0(%0), %%r13\n\t" - "movq0xC0(%0), %%r14\n\t" - "movq0xE0(%0), %%r15\n\t" + "movq0x000(%0), %%r8\n\t" + "movq0x040(%0), %%r9\n\t" + "movq0x080(%0), %%r10\n\t" + "movq0x0C0(%0), %%r11\n\t" + "movq0x100(%0), %%r12\n\t" + "movq0x140(%0), %%r13\n\t" + "movq0x180(%0), %%r14\n\t" + "movq0x1C0(%0), %%r15\n\t" "int3\n\t" : : "b"(data) @@ -2526,14 +2530,14 @@ static __inline void get_mm_regs(union x "\n\t" "int3\n\t" "\n\t" - "movq%%mm0, 0x00(%0)\n\t" - "movq%%mm1, 0x20(%0)\n\t" - "movq%%mm2, 0x40(%0)\n\t" - "movq%%mm3, 0x60(%0)\n\t" - "movq%%mm4, 0x80(%0)\n\t" - "movq%%mm5, 0xA0(%0)\n\t" - "movq%%mm6, 0xC0(%0)\n\t" - "movq%%mm7, 0xE0(%0)\n\t" + "movq%%mm0, 0x000(%0)\n\t" + "movq%%mm1, 0x040(%0)\n\t" + "movq%%mm2, 0x080(%0)\n\t" + "movq%%mm3, 0x0C0(%0)\n\t" + "movq%%mm4, 0x100(%0)\n\t" + "movq%%mm5, 0x140(%0)\n\t" + "movq%%mm6, 0x180(%0)\n\t" + "movq%%mm7, 0x1C0(%0)\n\t" : : "a"(out), "m"(fill) : "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7" @@ -2544,14 +2548,14 @@ __attribute__((target("mmx"))) static __inline void set_mm_regs(const union x86_test_register data[]) { __asm__ __volatile__( - "movq0x00(%0), %%mm0\n\t" - "movq0x20(%0), %%mm1\n\t" - "movq0x40(%0), %%mm2\n\t" - "movq0x60(%0), %%mm3\n\t" - "movq0x80(%0), %%mm4\n\t" - "movq0xA0(%0), %%mm5\n\t" - "movq0xC0(%0), %%mm6\n\t" - "movq0xE0(%0), %%mm7\n\t" + "movq0x000(%0), %%mm0\n\t" + "movq0x040(%0), %%mm1\n\t" + "movq0x080(%0), %%mm2\n\t" + "movq0x0C0(%0), %%mm3\n\t" + "movq0x100(%0), %%mm4\n\t" + "movq0x140(%0), %%mm5\n\t" + "movq0x180(%0), %%mm6\n\t" + "movq0x1C0(%0), %%mm7\n\t" "int3\n\t" : : "b"(data) @@ -2590,22 +2594,22 @@ static __inline void get_xmm_regs(union "int3\n\t" "\n\t" "movaps %%xmm0, 0x000(%0)\n\t" - "movaps %%xmm1, 0x020(%0)\n\t" - "movaps %%xmm2, 0x040(%0)\n\t" - "movaps %%xmm3, 0x060(%0)\n\t" - "movaps %%xmm4, 0x080(%0)\n\t" - "movaps %%xmm5, 0x0A0(%0)\n\t" - "movaps %%xmm6, 0x0C0(%0)\n\t" - "movaps %%xmm7, 0x0E0(%0)\n\t" -#if defined(__x86_64__) - "movaps %%xmm8, 0x100(%0)\n\t" - "movaps %%xmm9, 0x120(%0)\n\t" - "movaps %%xmm10, 0x140(%0)\n\t" - "movaps %%xmm11, 0x160(%0)\n\t" - "movaps %%xmm12, 0x180(%0)\n\t" - "movaps %%xmm13, 0x1A0(%0)\n\t" - "movaps %%xmm14, 0x1C0(%0)\n\t" - "movaps %%xmm15,
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Fri Oct 16 08:51:12 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Remove leftover commented out #if 0 To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.28 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.29 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.28 Thu Oct 15 17:43:09 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Fri Oct 16 08:51:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.28 2020/10/15 17:43:09 mgorny Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.29 2020/10/16 08:51:12 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -3551,9 +3551,7 @@ x86_register_test(enum x86_test_regset r /* SETFPREGS on i386 */ fpr.fstate.s87_cw = expected_fpu.cw; fpr.fstate.s87_sw = expected_fpu.sw; -//#if 0 /* TODO: translation from FXSAVE is broken */ fpr.fstate.s87_tw = expected_fpu.tw; -//#endif fpr.fstate.s87_opcode = expected_fpu.opcode; fpr.fstate.s87_ip = expected_fpu.ip; fpr.fstate.s87_dp = expected_fpu.dp;
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Thu Oct 15 22:59:50 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_core_wait.h Log Message: Apply fix in rev 1.2 for core_dump_procinfo to aarch64 and arm: http://cvsweb.netbsd.org/bsdweb.cgi/src/tests/lib/libc/sys/t_ptrace_core_wait.h#rev1.2 > For powerpc, program counter is not automatically incremented by trap > instruction. We cannot increment PC in the trap handler, which breaks > applications depending on this behavior, e.g., GDB. This statement is true for aarch64 and arm. Also, use PTRACE_BREAKPOINT_SIZE instead of hard-coded 4 to address instruction next to PC. OK ryo To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_ptrace_core_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_core_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.2 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.3 --- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.2 Wed Jun 24 04:47:10 2020 +++ src/tests/lib/libc/sys/t_ptrace_core_wait.h Thu Oct 15 22:59:50 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_core_wait.h,v 1.2 2020/06/24 04:47:10 rin Exp $ */ +/* $NetBSD: t_ptrace_core_wait.h,v 1.3 2020/10/15 22:59:50 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -207,21 +207,27 @@ ATF_TC_BODY(core_dump_procinfo, tc) DPRINTF("Before resuming the child process where it left off and " "without signal to be sent\n"); -#ifndef __powerpc__ - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); -#else + +#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) /* - * For powerpc, program counter is not automatically incremented by - * a trap instruction. We cannot increment PC in the trap handler, + * For these archs, program counter is not automatically incremented + * by a trap instruction. We cannot increment PC in the trap handler, * which breaks applications depending on this behavior, e.g., GDB. - * Therefore, we need to pass (PC + 4) instead of (void *)1 (== PC) - * to PT_CONTINUE here. + * Therefore, we need to pass PC++ instead of (void *)1 (== PC) to + * PT_CONTINUE here. */ struct reg r; SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, , 0) != -1); - SYSCALL_REQUIRE( - ptrace(PT_CONTINUE, child, (void *)(r.pc + 4), 0) != -1); + SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, +# if defined(__aarch64__) || defined(__arm__) + (void *)(r.r_pc + PTRACE_BREAKPOINT_SIZE), +# elif defined(__powerpc__) + (void *)(r.pc + PTRACE_BREAKPOINT_SIZE), +# endif + 0) != -1); +#else + SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); #endif DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Tue Oct 13 06:58:57 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_setrlimit.c Log Message: Bump soft/hard limits for stack to 6MB for aarch64{,eb}, where old value (~4MB) is too small to be accepted. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_setrlimit.c 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_setrlimit.c diff -u src/tests/lib/libc/sys/t_setrlimit.c:1.6 src/tests/lib/libc/sys/t_setrlimit.c:1.7 --- src/tests/lib/libc/sys/t_setrlimit.c:1.6 Fri Jan 13 21:16:38 2017 +++ src/tests/lib/libc/sys/t_setrlimit.c Tue Oct 13 06:58:57 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_setrlimit.c,v 1.6 2017/01/13 21:16:38 christos Exp $ */ +/* $NetBSD: t_setrlimit.c,v 1.7 2020/10/13 06:58:57 rin Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_setrlimit.c,v 1.6 2017/01/13 21:16:38 christos Exp $"); +__RCSID("$NetBSD: t_setrlimit.c,v 1.7 2020/10/13 06:58:57 rin Exp $"); #include #include @@ -517,7 +517,7 @@ ATF_TC_BODY(setrlimit_stack, tc) struct rlimit res; /* Ensure soft limit is not bigger than hard limit */ - res.rlim_cur = res.rlim_max = 4192256; + res.rlim_cur = res.rlim_max = 6 * 1024 * 1024; ATF_REQUIRE(setrlimit(RLIMIT_STACK, ) == 0); ATF_REQUIRE(getrlimit(RLIMIT_STACK, ) == 0); ATF_CHECK(res.rlim_cur <= res.rlim_max);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Fri Oct 9 17:43:30 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Add tests for x87 FPU registers Reviewed by kamil To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.26 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.27 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.26 Fri Oct 9 17:43:07 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Fri Oct 9 17:43:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.26 2020/10/09 17:43:07 mgorny Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.27 2020/10/09 17:43:30 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -2186,6 +2186,21 @@ union x86_test_register { uint32_t u32; }; +struct x86_test_fpu_registers { + struct { + uint64_t mantissa; + uint16_t sign_exp; + } __aligned(16) st[8]; + + uint16_t cw; + uint16_t sw; + uint16_t tw; + uint8_t tw_abridged; + uint16_t opcode; + union fp_addr ip; + union fp_addr dp; +}; + enum x86_test_regset { TEST_GPREGS, TEST_FPREGS, @@ -2201,6 +2216,7 @@ enum x86_test_registers { GPREGS_64, GPREGS_64_R8, /* TEST_FPREGS/TEST_XMMREGS */ + FPREGS_FPU, FPREGS_MM, FPREGS_XMM, /* TEST_XSTATE */ @@ -2419,6 +2435,79 @@ static __inline void set_gp64_r8_regs(co #endif } +static __inline void get_fpu_regs(struct x86_test_fpu_registers *out) +{ + struct save87 fsave; + struct fxsave fxsave; + + __CTASSERT(sizeof(out->st[0]) == 16); + + __asm__ __volatile__( + "finit\n\t" + "int3\n\t" +#if defined(__x86_64__) + "fxsave64 %2\n\t" +#else + "fxsave %2\n\t" +#endif + "fnstenv %1\n\t" + "fnclex\n\t" + "fstpt 0x00(%0)\n\t" + "fstpt 0x10(%0)\n\t" + "fstpt 0x20(%0)\n\t" + "fstpt 0x30(%0)\n\t" + "fstpt 0x40(%0)\n\t" + "fstpt 0x50(%0)\n\t" + "fstpt 0x60(%0)\n\t" + "fstpt 0x70(%0)\n\t" + : + : "a"(out->st), "m"(fsave), "m"(fxsave) + : "st", "memory" + ); + + FORKEE_ASSERT(fsave.s87_cw == fxsave.fx_cw); + FORKEE_ASSERT(fsave.s87_sw == fxsave.fx_sw); + + /* fsave contains full tw */ + out->cw = fsave.s87_cw; + out->sw = fsave.s87_sw; + out->tw = fsave.s87_tw; + out->tw_abridged = fxsave.fx_tw; + out->opcode = fxsave.fx_opcode; + out->ip = fxsave.fx_ip; + out->dp = fxsave.fx_dp; +} + +/* used as single-precision float */ +uint32_t x86_test_zero = 0; + +static __inline void set_fpu_regs(const struct x86_test_fpu_registers *data) +{ + __CTASSERT(sizeof(data->st[0]) == 16); + + __asm__ __volatile__( + "finit\n\t" + "fldcw %1\n\t" + /* load on stack in reverse order to make it easier to read */ + "fldt 0x70(%0)\n\t" + "fldt 0x60(%0)\n\t" + "fldt 0x50(%0)\n\t" + "fldt 0x40(%0)\n\t" + "fldt 0x30(%0)\n\t" + "fldt 0x20(%0)\n\t" + "fldt 0x10(%0)\n\t" + "fldt 0x00(%0)\n\t" + /* free st7 */ + "ffree %%st(7)\n\t" + /* this should trigger a divide-by-zero */ + "fdivs (%2)\n\t" + "int3\n\t" + : + : "a"(>st), "m"(data->cw), "b"(_test_zero) + : "st" + ); +} + __attribute__((target("mmx"))) static __inline void get_mm_regs(union x86_test_register out[]) { @@ -2712,6 +2801,54 @@ x86_register_test(enum x86_test_regset r 0x262524232221201F, 0x2E2D2C2B2A292827, }}, }; + const struct x86_test_fpu_registers expected_fpu = { + .st = { + {0x8000, 0x4000}, /* +2.0 */ + {0x3f00, 0x}, /* 1.654785e-4932 */ + {0x, 0x}, /* +0 */ + {0x, 0x8000}, /* -0 */ + {0x8000, 0x7fff}, /* +inf */ + {0x8000, 0x}, /* -inf */ + {0xc000, 0x}, /* nan */ + /* st(7) will be freed to test tag word better */ + {0x, 0x}, /* +0 */ + }, + /* 0011 0111 1011 + * PU OZDI -- unmask divide-by-zero exc. + * RR - reserved + *PC 64-bit precision + * RC -- round to nearest + *I - allow interrupts (unused) + */ + .cw = 0x037b, + /* 1000 1000 0100 + *SPU OZDI -- divide-by-zero exception + * I -- interrupt (exception handling) + * CCCC condition codes + * TO P --- top register is 0 + * B FPU is busy + */ + .sw = 0x8084, + /* 1110 1010 0101 1000 + * R7R6 R5R4 R3R2 R1R0 + * nz -- non-zero (+2.0) + *sp special (denormal) + * zrzr --- zeroes + * sp spsp specials (NaN + infinities) + * em --- empty register + */ + .tw = 0xea58, + /* 0111 -- registers 0 to 6 are used */ + .tw_abridged = 0x7f, + /* FDIV */ + .opcode = 0x0033, + /* random bits for IP/DP write
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Fri Oct 9 17:43:07 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Rename MM_REG macro to ST_MAN, and cover fpr/xstate with it Rename the MM_REG macro to ST_MAN, to make it clearer that it gets mantissa of ST registers which overlaps with MM registers but can be also used to read ST registers (to be used in the next commit). Extend it to cover the difference between GETFPREGS and GETXSTATE, and therefore avoid additional condition on i386. Reviewed by kamil. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.25 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.26 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.25 Fri Apr 24 03:25:20 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Fri Oct 9 17:43:07 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.25 2020/04/24 03:25:20 thorpej Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.26 2020/10/09 17:43:07 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -3089,9 +3089,13 @@ x86_register_test(enum x86_test_regset r } #if defined(__x86_64__) -#define MM_REG(n) fpr.fxstate.fx_87_ac[n].r.f87_mantissa +#define ST_MAN(n) fxs->fx_87_ac[n].r.f87_mantissa #else -#define MM_REG(n) fpr.fstate.s87_ac[n].f87_mantissa +#define ST_MAN(n) *( \ +regset == TEST_FPREGS \ +? _ac[n].f87_mantissa\ +: >fx_87_ac[n].r.f87_mantissa \ +) #endif switch (regmode) { @@ -3155,33 +3159,14 @@ x86_register_test(enum x86_test_regset r #endif break; case FPREGS_MM: - if (regset == TEST_FPREGS) { -ATF_CHECK_EQ(MM_REG(0), expected[0].u64); -ATF_CHECK_EQ(MM_REG(1), expected[1].u64); -ATF_CHECK_EQ(MM_REG(2), expected[2].u64); -ATF_CHECK_EQ(MM_REG(3), expected[3].u64); -ATF_CHECK_EQ(MM_REG(4), expected[4].u64); -ATF_CHECK_EQ(MM_REG(5), expected[5].u64); -ATF_CHECK_EQ(MM_REG(6), expected[6].u64); -ATF_CHECK_EQ(MM_REG(7), expected[7].u64); - } else { -ATF_CHECK_EQ(fxs->fx_87_ac[0].r.f87_mantissa, - expected[0].u64); -ATF_CHECK_EQ(fxs->fx_87_ac[1].r.f87_mantissa, - expected[1].u64); -ATF_CHECK_EQ(fxs->fx_87_ac[2].r.f87_mantissa, - expected[2].u64); -ATF_CHECK_EQ(fxs->fx_87_ac[3].r.f87_mantissa, - expected[3].u64); -ATF_CHECK_EQ(fxs->fx_87_ac[4].r.f87_mantissa, - expected[4].u64); -ATF_CHECK_EQ(fxs->fx_87_ac[5].r.f87_mantissa, - expected[5].u64); -ATF_CHECK_EQ(fxs->fx_87_ac[6].r.f87_mantissa, - expected[6].u64); -ATF_CHECK_EQ(fxs->fx_87_ac[7].r.f87_mantissa, - expected[7].u64); - } + ATF_CHECK_EQ(ST_MAN(0), expected[0].u64); + ATF_CHECK_EQ(ST_MAN(1), expected[1].u64); + ATF_CHECK_EQ(ST_MAN(2), expected[2].u64); + ATF_CHECK_EQ(ST_MAN(3), expected[3].u64); + ATF_CHECK_EQ(ST_MAN(4), expected[4].u64); + ATF_CHECK_EQ(ST_MAN(5), expected[5].u64); + ATF_CHECK_EQ(ST_MAN(6), expected[6].u64); + ATF_CHECK_EQ(ST_MAN(7), expected[7].u64); break; case FPREGS_YMM: ATF_CHECK(!memcmp(_ymm_hi128.xs_ymm[0], @@ -3300,33 +3285,14 @@ x86_register_test(enum x86_test_regset r #endif break; case FPREGS_MM: - if (regset == TEST_FPREGS) { -MM_REG(0) = expected[0].u64; -MM_REG(1) = expected[1].u64; -MM_REG(2) = expected[2].u64; -MM_REG(3) = expected[3].u64; -MM_REG(4) = expected[4].u64; -MM_REG(5) = expected[5].u64; -MM_REG(6) = expected[6].u64; -MM_REG(7) = expected[7].u64; - } else { -fxs->fx_87_ac[0].r.f87_mantissa = -expected[0].u64; -fxs->fx_87_ac[1].r.f87_mantissa = -expected[1].u64; -fxs->fx_87_ac[2].r.f87_mantissa = -expected[2].u64; -fxs->fx_87_ac[3].r.f87_mantissa = -expected[3].u64; -fxs->fx_87_ac[4].r.f87_mantissa = -expected[4].u64; -fxs->fx_87_ac[5].r.f87_mantissa = -expected[5].u64; -fxs->fx_87_ac[6].r.f87_mantissa = -expected[6].u64; -fxs->fx_87_ac[7].r.f87_mantissa = -expected[7].u64; - } + ST_MAN(0) = expected[0].u64; + ST_MAN(1) = expected[1].u64; + ST_MAN(2) = expected[2].u64; + ST_MAN(3) = expected[3].u64; + ST_MAN(4) = expected[4].u64; + ST_MAN(5) = expected[5].u64; + ST_MAN(6) = expected[6].u64; + ST_MAN(7) = expected[7].u64; break; case FPREGS_YMM: memcpy(_ymm_hi128.xs_ymm[0], @@ -3431,7 +3397,7 @@ x86_register_test(enum x86_test_regset r break; } -#undef MM_REG +#undef ST_MAN DPRINTF("Before resuming the child process where it left off and " "without signal to be sent\n");
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: riastradh Date: Tue Aug 25 01:37:39 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_getrandom.c Log Message: Fix getrandom() tests. Use sigaction() without SA_RESTART -- signal() implies SA_RESTART so we never got the EINTR. While here, reduce the timeout to something more reasonable so we don't waste 20min of testbed time if anything goes wrong and the one-second alarm doesn't fire. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_getrandom.c 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_getrandom.c diff -u src/tests/lib/libc/sys/t_getrandom.c:1.2 src/tests/lib/libc/sys/t_getrandom.c:1.3 --- src/tests/lib/libc/sys/t_getrandom.c:1.2 Sun Aug 23 17:50:19 2020 +++ src/tests/lib/libc/sys/t_getrandom.c Tue Aug 25 01:37:38 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_getrandom.c,v 1.2 2020/08/23 17:50:19 riastradh Exp $ */ +/* $NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -30,13 +30,14 @@ */ #include -__RCSID("$NetBSD: t_getrandom.c,v 1.2 2020/08/23 17:50:19 riastradh Exp $"); +__RCSID("$NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $"); #include #include #include #include +#include #include static uint8_t buf[65536]; @@ -45,6 +46,22 @@ static uint8_t zero24[24]; static void alarm_handler(int signo) { + + fprintf(stderr, "timeout\n"); +} + +static void +install_alarm_handler(void) +{ + struct sigaction sa; + + memset(, 0, sizeof sa); + sa.sa_handler = alarm_handler; + sigfillset(_mask); + sa.sa_flags = 0; /* no SA_RESTART */ + + ATF_CHECK_MSG(sigaction(SIGALRM, , NULL) != -1, + "sigaction(SIGALRM): %s", strerror(errno)); } /* @@ -58,14 +75,14 @@ ATF_TC(getrandom_default); ATF_TC_HEAD(getrandom_default, tc) { atf_tc_set_md_var(tc, "descr", "getrandom(..., 0)"); + atf_tc_set_md_var(tc, "timeout", "2"); } ATF_TC_BODY(getrandom_default, tc) { ssize_t n; - ATF_REQUIRE(signal(SIGALRM, _handler) != SIG_ERR); - /* default */ + install_alarm_handler(); alarm(1); memset(buf, 0, sizeof buf); n = getrandom(buf, sizeof buf, 0); @@ -141,14 +158,14 @@ ATF_TC(getrandom_random); ATF_TC_HEAD(getrandom_random, tc) { atf_tc_set_md_var(tc, "descr", "getrandom(..., GRND_RANDOM)"); + atf_tc_set_md_var(tc, "timeout", "2"); } ATF_TC_BODY(getrandom_random, tc) { ssize_t n; - ATF_REQUIRE(signal(SIGALRM, _handler) != SIG_ERR); - /* `random' (hokey) */ + install_alarm_handler(); alarm(1); memset(buf, 0, sizeof buf); n = getrandom(buf, sizeof buf, GRND_RANDOM);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: riastradh Date: Sun Aug 23 17:50:19 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_getrandom.c Log Message: Split getrandom tests into several cases to find out which ones hang. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_getrandom.c 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_getrandom.c diff -u src/tests/lib/libc/sys/t_getrandom.c:1.1 src/tests/lib/libc/sys/t_getrandom.c:1.2 --- src/tests/lib/libc/sys/t_getrandom.c:1.1 Fri Aug 14 00:53:16 2020 +++ src/tests/lib/libc/sys/t_getrandom.c Sun Aug 23 17:50:19 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_getrandom.c,v 1.1 2020/08/14 00:53:16 riastradh Exp $ */ +/* $NetBSD: t_getrandom.c,v 1.2 2020/08/23 17:50:19 riastradh Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: t_getrandom.c,v 1.1 2020/08/14 00:53:16 riastradh Exp $"); +__RCSID("$NetBSD: t_getrandom.c,v 1.2 2020/08/23 17:50:19 riastradh Exp $"); #include @@ -47,13 +47,6 @@ alarm_handler(int signo) { } -ATF_TC(getrandom); -ATF_TC_HEAD(getrandom, tc) -{ - - atf_tc_set_md_var(tc, "descr", "getrandom(2)"); -} - /* * Probability of spurious failure is 1/2^192 for each of the memcmps. * As long as there are fewer than 2^64 of them, the probability of @@ -61,7 +54,12 @@ ATF_TC_HEAD(getrandom, tc) * don't care about it. */ -ATF_TC_BODY(getrandom, tc) +ATF_TC(getrandom_default); +ATF_TC_HEAD(getrandom_default, tc) +{ + atf_tc_set_md_var(tc, "descr", "getrandom(..., 0)"); +} +ATF_TC_BODY(getrandom_default, tc) { ssize_t n; @@ -79,6 +77,16 @@ ATF_TC_BODY(getrandom, tc) ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0); } alarm(0); +} + +ATF_TC(getrandom_nonblock); +ATF_TC_HEAD(getrandom_nonblock, tc) +{ + atf_tc_set_md_var(tc, "descr", "getrandom(..., GRND_NONBLOCK)"); +} +ATF_TC_BODY(getrandom_nonblock, tc) +{ + ssize_t n; /* default, nonblocking */ memset(buf, 0, sizeof buf); @@ -90,6 +98,16 @@ ATF_TC_BODY(getrandom, tc) ATF_CHECK(memcmp(buf, zero24, 24) != 0); ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0); } +} + +ATF_TC(getrandom_insecure); +ATF_TC_HEAD(getrandom_insecure, tc) +{ + atf_tc_set_md_var(tc, "descr", "getrandom(..., GRND_INSECURE)"); +} +ATF_TC_BODY(getrandom_insecure, tc) +{ + ssize_t n; /* insecure */ memset(buf, 0, sizeof buf); @@ -98,6 +116,17 @@ ATF_TC_BODY(getrandom, tc) ATF_CHECK_EQ((size_t)n, sizeof buf); ATF_CHECK(memcmp(buf, zero24, 24) != 0); ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0); +} + +ATF_TC(getrandom_insecure_nonblock); +ATF_TC_HEAD(getrandom_insecure_nonblock, tc) +{ + atf_tc_set_md_var(tc, "descr", + "getrandom(..., GRND_INSECURE|GRND_NONBLOCK)"); +} +ATF_TC_BODY(getrandom_insecure_nonblock, tc) +{ + ssize_t n; /* insecure, nonblocking -- same as mere insecure */ memset(buf, 0, sizeof buf); @@ -106,6 +135,18 @@ ATF_TC_BODY(getrandom, tc) ATF_CHECK_EQ((size_t)n, sizeof buf); ATF_CHECK(memcmp(buf, zero24, 24) != 0); ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0); +} + +ATF_TC(getrandom_random); +ATF_TC_HEAD(getrandom_random, tc) +{ + atf_tc_set_md_var(tc, "descr", "getrandom(..., GRND_RANDOM)"); +} +ATF_TC_BODY(getrandom_random, tc) +{ + ssize_t n; + + ATF_REQUIRE(signal(SIGALRM, _handler) != SIG_ERR); /* `random' (hokey) */ alarm(1); @@ -122,6 +163,17 @@ ATF_TC_BODY(getrandom, tc) } } alarm(0); +} + +ATF_TC(getrandom_random_nonblock); +ATF_TC_HEAD(getrandom_random_nonblock, tc) +{ + atf_tc_set_md_var(tc, "descr", + "getrandom(..., GRND_RANDOM|GRND_NONBLOCK)"); +} +ATF_TC_BODY(getrandom_random_nonblock, tc) +{ + ssize_t n; /* `random' (hokey), nonblocking */ memset(buf, 0, sizeof buf); @@ -136,17 +188,49 @@ ATF_TC_BODY(getrandom, tc) ATF_CHECK(memcmp(buf + n - 24, zero24, 24) != 0); } } +} + +ATF_TC(getrandom_random_insecure); +ATF_TC_HEAD(getrandom_random_insecure, tc) +{ + atf_tc_set_md_var(tc, "descr", + "getrandom(..., GRND_RANDOM|GRND_INSECURE)"); +} +ATF_TC_BODY(getrandom_random_insecure, tc) +{ + ssize_t n; /* random and insecure -- nonsensical */ n = getrandom(buf, sizeof buf, GRND_RANDOM|GRND_INSECURE); ATF_CHECK_EQ(n, -1); ATF_CHECK_EQ(errno, EINVAL); +} + +ATF_TC(getrandom_random_insecure_nonblock); +ATF_TC_HEAD(getrandom_random_insecure_nonblock, tc) +{ + atf_tc_set_md_var(tc, "descr", + "getrandom(..., GRND_RANDOM|GRND_INSECURE|GRND_NONBLOCK)"); +} +ATF_TC_BODY(getrandom_random_insecure_nonblock, tc) +{ + ssize_t n; /* random and insecure, nonblocking -- nonsensical */ n = getrandom(buf, sizeof buf, GRND_RANDOM|GRND_INSECURE|GRND_NONBLOCK); ATF_CHECK_EQ(n, -1); ATF_CHECK_EQ(errno, EINVAL); +} + +ATF_TC(getrandom_invalid); +ATF_TC_HEAD(getrandom_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr",
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Wed Jun 24 04:47:10 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_core_wait.h Log Message: Fix core_dump_procinfo tests for powerpc, for which child process was stalled indefinitely in trap instruction even after PT_CONTINUE. For powerpc, program counter is not automatically incremented by trap instruction. We cannot increment PC in the trap handler, which breaks applications depending on this behavior, e.g., GDB. Therefore, we need to pass (PC + 4) instead of (void *)1 (== PC) to PT_CONTINUE when child process traps itself. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_core_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_core_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.1 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.2 --- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.1 Tue May 5 01:24:29 2020 +++ src/tests/lib/libc/sys/t_ptrace_core_wait.h Wed Jun 24 04:47:10 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_core_wait.h,v 1.1 2020/05/05 01:24:29 kamil Exp $ */ +/* $NetBSD: t_ptrace_core_wait.h,v 1.2 2020/06/24 04:47:10 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -207,7 +207,22 @@ ATF_TC_BODY(core_dump_procinfo, tc) DPRINTF("Before resuming the child process where it left off and " "without signal to be sent\n"); +#ifndef __powerpc__ SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); +#else + /* + * For powerpc, program counter is not automatically incremented by + * a trap instruction. We cannot increment PC in the trap handler, + * which breaks applications depending on this behavior, e.g., GDB. + * Therefore, we need to pass (PC + 4) instead of (void *)1 (== PC) + * to PT_CONTINUE here. + */ + struct reg r; + + SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, , 0) != -1); + SYSCALL_REQUIRE( + ptrace(PT_CONTINUE, child, (void *)(r.pc + 4), 0) != -1); +#endif DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Mon Jun 22 12:21:03 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h Log Message: Work around QEMU bug #1668041 differently, by which floating-point division by zero is not correctly trapped for i386 and amd64: https://bugs.launchpad.net/qemu/+bug/1668041 Make trigger_fpe() cause integer division by zero for x86, and floating-point one for other architectures. Also, assertions for si_code in *_crash_fpe tests are commented out for now. They should be cleaned up after the bug is fixed. Now, *_crash_fpe tests are working also on powerpc. Suggested by kamil. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_signal_wait.h cvs rdiff -u -r1.31 -r1.32 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_signal_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.3 src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.4 --- src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.3 Mon Jun 22 02:51:06 2020 +++ src/tests/lib/libc/sys/t_ptrace_signal_wait.h Mon Jun 22 12:21:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_signal_wait.h,v 1.3 2020/06/22 02:51:06 rin Exp $ */ +/* $NetBSD: t_ptrace_signal_wait.h,v 1.4 2020/06/22 12:21:02 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -423,7 +423,7 @@ traceme_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); +// XXXQEMU ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -603,7 +603,7 @@ traceme_signalmasked_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); +// XXXQEMU ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -786,7 +786,7 @@ traceme_signalignored_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); +// XXXQEMU ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -1890,7 +1890,7 @@ unrelated_tracer_sees_crash(int sig, boo info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_INTDIV); +// XXXQEMU FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, BUS_ADRERR); Index: src/tests/lib/libc/sys/t_ptrace_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.31 src/tests/lib/libc/sys/t_ptrace_wait.h:1.32 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.31 Mon Jun 22 02:51:06 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Mon Jun 22 12:21:02 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.31 2020/06/22 02:51:06 rin Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.32 2020/06/22 12:21:02 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -671,9 +671,6 @@ are_fpu_exceptions_supported(void) return false; return true; } -#elif __powerpc__ -/* Integer division by zero do not trap on powerpc. */ -#define are_fpu_exceptions_supported() 0 #else #define are_fpu_exceptions_supported() 1 #endif @@ -681,15 +678,28 @@ are_fpu_exceptions_supported(void) static void __used trigger_fpe(void) { - volatile int a = getpid(); - volatile int b = atoi("0"); +#if __i386__ || __x86_64__ + /* + * XXX + * Hack for QEMU bug #1668041, by which floating-point division by + * zero is not trapped correctly. Also, assertions for si_code in + * ptrace_signal_wait.h are commented out. Clean them up after the + * bug is fixed. + */ + volatile int a, b; +#else + volatile double a, b; +#endif + + a = getpid(); + b = atoi("0"); #ifdef __HAVE_FENV feenableexcept(FE_ALL_EXCEPT); #endif /* Division by zero causes CPU trap, translated to SIGFPE */ - usleep(a / b); + usleep((int)(a / b)); } static void __used
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Mon Jun 22 02:51:07 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h Log Message: Turn trigger_fpe() back to integer division by zero for a while until QEMU bug #1668041 is fixed: https://bugs.launchpad.net/qemu/+bug/1668041 by which floating-point division by zero is not trapped correctly both on amd64 and i386. Skip *_crash_fpe tests on powerpc, where integer division by zero is never trapped. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_ptrace_signal_wait.h cvs rdiff -u -r1.30 -r1.31 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_signal_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.2 src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.3 --- src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.2 Wed Jun 17 08:42:16 2020 +++ src/tests/lib/libc/sys/t_ptrace_signal_wait.h Mon Jun 22 02:51:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_signal_wait.h,v 1.2 2020/06/17 08:42:16 rin Exp $ */ +/* $NetBSD: t_ptrace_signal_wait.h,v 1.3 2020/06/22 02:51:06 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -423,7 +423,7 @@ traceme_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -603,7 +603,7 @@ traceme_signalmasked_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -786,7 +786,7 @@ traceme_signalignored_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -1890,7 +1890,7 @@ unrelated_tracer_sees_crash(int sig, boo info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); + FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_INTDIV); break; case SIGBUS: FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, BUS_ADRERR); Index: src/tests/lib/libc/sys/t_ptrace_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.30 src/tests/lib/libc/sys/t_ptrace_wait.h:1.31 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.30 Wed Jun 17 08:42:16 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Mon Jun 22 02:51:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.30 2020/06/17 08:42:16 rin Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.31 2020/06/22 02:51:06 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -671,6 +671,9 @@ are_fpu_exceptions_supported(void) return false; return true; } +#elif __powerpc__ +/* Integer division by zero do not trap on powerpc. */ +#define are_fpu_exceptions_supported() 0 #else #define are_fpu_exceptions_supported() 1 #endif @@ -678,14 +681,15 @@ are_fpu_exceptions_supported(void) static void __used trigger_fpe(void) { - volatile double a = getpid(); - volatile double b = atoi("0"); + volatile int a = getpid(); + volatile int b = atoi("0"); #ifdef __HAVE_FENV feenableexcept(FE_ALL_EXCEPT); #endif - usleep((int)(a / b)); + /* Division by zero causes CPU trap, translated to SIGFPE */ + usleep(a / b); } static void __used
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Wed Jun 17 22:07:21 UTC 2020 Modified Files: src/tests/lib/libc/sys: Makefile Log Message: Fix build for vax; Compile t_ptrace_sigchld.c with -D__TEST_FENV. To generate a diff of this commit: cvs rdiff -u -r1.64 -r1.65 src/tests/lib/libc/sys/Makefile 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/Makefile diff -u src/tests/lib/libc/sys/Makefile:1.64 src/tests/lib/libc/sys/Makefile:1.65 --- src/tests/lib/libc/sys/Makefile:1.64 Thu Apr 30 11:03:29 2020 +++ src/tests/lib/libc/sys/Makefile Wed Jun 17 22:07:21 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.64 2020/04/30 11:03:29 ryo Exp $ +# $NetBSD: Makefile,v 1.65 2020/06/17 22:07:21 rin Exp $ MKMAN= no @@ -111,6 +111,7 @@ CPPFLAGS.t_futex_ops.c += -I${.CURDIR}/ CPPFLAGS.t_futex_robust.c += -I${.CURDIR}/../../../../lib CPPFLAGS.t_lwp_create.c += -D_KERNTYPES +CPPFLAGS.t_ptrace_sigchld.c += -D__TEST_FENV CPPFLAGS.t_ptrace_wait.c += -D_KERNTYPES -D__TEST_FENV CPPFLAGS.t_ptrace_wait3.c += -D_KERNTYPES -D__TEST_FENV CPPFLAGS.t_ptrace_wait4.c += -D_KERNTYPES -D__TEST_FENV
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Wed Jun 17 08:42:16 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h Log Message: Let trigger_fpe() cause floating-point divide by zero exception, instead of integer one, which is not trapped for powerpc and aarch64. Note that it is checked in lib/libc/gen/t_siginfo whether integer divide by zero is interpreted as SIGFPE or not. Now, all *_crash_fpe tests pass for powerpc, and nothing changes for amd64 at least. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_signal_wait.h cvs rdiff -u -r1.29 -r1.30 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_signal_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.1 src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.2 --- src/tests/lib/libc/sys/t_ptrace_signal_wait.h:1.1 Mon May 4 23:49:31 2020 +++ src/tests/lib/libc/sys/t_ptrace_signal_wait.h Wed Jun 17 08:42:16 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_signal_wait.h,v 1.1 2020/05/04 23:49:31 kamil Exp $ */ +/* $NetBSD: t_ptrace_signal_wait.h,v 1.2 2020/06/17 08:42:16 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -423,7 +423,7 @@ traceme_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -603,7 +603,7 @@ traceme_signalmasked_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -786,7 +786,7 @@ traceme_signalignored_crash(int sig) info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); @@ -1890,7 +1890,7 @@ unrelated_tracer_sees_crash(int sig, boo info.psi_siginfo.si_code <= ILL_BADSTK); break; case SIGFPE: - FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_INTDIV); + FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, FPE_FLTDIV); break; case SIGBUS: FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, BUS_ADRERR); Index: src/tests/lib/libc/sys/t_ptrace_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.29 src/tests/lib/libc/sys/t_ptrace_wait.h:1.30 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.29 Wed Jun 17 08:23:18 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Wed Jun 17 08:42:16 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.29 2020/06/17 08:23:18 rin Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.30 2020/06/17 08:42:16 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -678,15 +678,14 @@ are_fpu_exceptions_supported(void) static void __used trigger_fpe(void) { - volatile int a = getpid(); - volatile int b = atoi("0"); + volatile double a = getpid(); + volatile double b = atoi("0"); #ifdef __HAVE_FENV feenableexcept(FE_ALL_EXCEPT); #endif - /* Division by zero causes CPU trap, translated to SIGFPE */ - usleep(a / b); + usleep((int)(a / b)); } static void __used
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: rin Date: Wed Jun 17 08:23:18 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: Regardless of __HAVE_FENV, include , which itself defines __HAVE_FENV. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 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.28 src/tests/lib/libc/sys/t_ptrace_wait.h:1.29 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.28 Tue May 5 00:50:39 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Wed Jun 17 08:23:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.28 2020/05/05 00:50:39 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.29 2020/06/17 08:23:18 rin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -654,9 +654,7 @@ trigger_ill(void) #endif } -#ifdef __HAVE_FENV #include -#endif #if (__arm__ && !__SOFTFP__) || __aarch64__ #include /* only need for ARM Cortex/Neon hack */
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Mon Jun 15 13:57:45 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_wait_noproc.c Log Message: language sensitivity To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_wait_noproc.c 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_wait_noproc.c diff -u src/tests/lib/libc/sys/t_wait_noproc.c:1.5 src/tests/lib/libc/sys/t_wait_noproc.c:1.6 --- src/tests/lib/libc/sys/t_wait_noproc.c:1.5 Wed Nov 9 12:50:19 2016 +++ src/tests/lib/libc/sys/t_wait_noproc.c Mon Jun 15 09:57:45 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $ */ +/* $NetBSD: t_wait_noproc.c,v 1.6 2020/06/15 13:57:45 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $"); +__RCSID("$NetBSD: t_wait_noproc.c,v 1.6 2020/06/15 13:57:45 christos Exp $"); #include #include @@ -141,7 +141,7 @@ get_options6(size_t pos) */ const int matrix[] = { - WNOWAIT, /* First in order to blacklist it easily */ + WNOWAIT, /* First in order to exclude it easily */ WEXITED, WUNTRACED, WSTOPPED, /* SUS compatibility, equal to WUNTRACED */
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue Jun 9 00:28:57 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_fork_wait.h Log Message: Add fork/vfork/posix_spawn tests for processes within pgrp New tests: - fork_setpgid - vfork_setpgid - posix_spawn_setpgid - unrelated_tracer_fork_setpgid - unrelated_tracer_vfork_setpgid - unrelated_tracer_posix_spawn_setpgid These tests trigger a kernel assert for pg_jobc going negative. The tests are temporarily skipped. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_ptrace_fork_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_fork_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.6 src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.7 --- src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.6 Sat May 16 23:10:26 2020 +++ src/tests/lib/libc/sys/t_ptrace_fork_wait.h Tue Jun 9 00:28:57 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_fork_wait.h,v 1.6 2020/05/16 23:10:26 kamil Exp $ */ +/* $NetBSD: t_ptrace_fork_wait.h,v 1.7 2020/06/09 00:28:57 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2020 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ static void fork_body(const char *fn, bool trackspawn, bool trackfork, bool trackvfork, -bool trackvforkdone) +bool trackvforkdone, bool newpgrp) { const int exitval = 5; const int exitval2 = 0; /* This matched exit status from /bin/echo */ @@ -46,9 +46,17 @@ fork_body(const char *fn, bool trackspaw char * const arg[] = { __UNCONST("/bin/echo"), NULL }; + if (newpgrp) + atf_tc_skip("kernel panic (pg_jobc going negative)"); + DPRINTF("Before forking process PID=%d\n", getpid()); SYSCALL_REQUIRE((child = fork()) != -1); if (child == 0) { + if (newpgrp) { + DPRINTF("Before entering new process group"); + setpgid(0, 0); + } + DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); @@ -232,24 +240,28 @@ fork_body(const char *fn, bool trackspaw TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); } -#define FORK_TEST(name,fun,tspawn,tfork,tvfork,tvforkdone) \ +#define FORK_TEST2(name,fun,tspawn,tfork,tvfork,tvforkdone,newpgrp) \ ATF_TC(name);\ ATF_TC_HEAD(name, tc) \ { \ atf_tc_set_md_var(tc, "descr", "Verify " fun "() " \ - "called with 0%s%s%s%s in EVENT_MASK", \ + "called with 0%s%s%s%s in EVENT_MASK%s", \ tspawn ? "|PTRACE_POSIX_SPAWN" : "", \ tfork ? "|PTRACE_FORK" : "",\ tvfork ? "|PTRACE_VFORK" : "",\ - tvforkdone ? "|PTRACE_VFORK_DONE" : ""); \ + tvforkdone ? "|PTRACE_VFORK_DONE" : "", \ + newpgrp ? " and the traced processes call setpgrp(0,0)":"");\ } \ \ ATF_TC_BODY(name, tc) \ { \ \ - fork_body(fun, tspawn, tfork, tvfork, tvforkdone); \ + fork_body(fun, tspawn, tfork, tvfork, tvforkdone, newpgrp); \ } +#define FORK_TEST(name,fun,tspawn,tfork,tvfork,tvforkdone) \ + FORK_TEST2(name,fun,tspawn,tfork,tvfork,tvforkdone,false) + FORK_TEST(fork1, "fork", false, false, false, false) #if defined(TWAIT_HAVE_PID) FORK_TEST(fork2, "fork", false, true, false, false) @@ -275,6 +287,10 @@ FORK_TEST(fork15, "fork", true, false, t FORK_TEST(fork16, "fork", true, true, true, true) #endif +#if defined(TWAIT_HAVE_PID) +FORK_TEST2(fork_setpgid, "fork", true, true, true, true, true) +#endif + FORK_TEST(vfork1, "vfork", false, false, false, false) #if defined(TWAIT_HAVE_PID) FORK_TEST(vfork2, "vfork", false, true, false, false) @@ -300,6 +316,10 @@ FORK_TEST(vfork15, "vfork", true, false, FORK_TEST(vfork16, "vfork", true, true, true, true) #endif +#if defined(TWAIT_HAVE_PID) +FORK_TEST2(vfork_setpgid, "vfork", true, true, true, true, true) +#endif + FORK_TEST(posix_spawn1, "spawn", false, false, false, false) FORK_TEST(posix_spawn2, "spawn", false, true, false, false) FORK_TEST(posix_spawn3, "spawn", false, false, true, false) @@ -319,12 +339,16 @@ FORK_TEST(posix_spawn15, "spawn", true, FORK_TEST(posix_spawn16, "spawn", true, true, true, true) #endif +#if defined(TWAIT_HAVE_PID) +FORK_TEST2(posix_spawn_setpgid, "spawn", true, true, true, true, true) +#endif + /// #if defined(TWAIT_HAVE_PID) static void unrelated_tracer_fork_body(const char *fn, bool trackspawn, bool trackfork, -bool trackvfork, bool trackvforkdone) +bool trackvfork, bool trackvforkdone, bool newpgrp) { const int sigval = SIGSTOP; struct msg_fds parent_tracee, parent_tracer; @@ -346,10 +370,18 @@ unrelated_tracer_fork_body(const char *f char * const arg[] = { __UNCONST("/bin/echo"), NULL }; + if (newpgrp) + atf_tc_skip("kernel panic (pg_jobc going negative)"); + DPRINTF("Spawn tracee\n");
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: thorpej Date: Sat Jun 6 18:11:21 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_lwp_create.c Log Message: Add a test case to ensure that _lwp_create() fails with the expected error code when a bad new-lwp-id pointer is passed. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_lwp_create.c 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_lwp_create.c diff -u src/tests/lib/libc/sys/t_lwp_create.c:1.2 src/tests/lib/libc/sys/t_lwp_create.c:1.3 --- src/tests/lib/libc/sys/t_lwp_create.c:1.2 Tue May 22 09:23:39 2012 +++ src/tests/lib/libc/sys/t_lwp_create.c Sat Jun 6 18:11:21 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_lwp_create.c,v 1.2 2012/05/22 09:23:39 martin Exp $ */ +/* $NetBSD: t_lwp_create.c,v 1.3 2020/06/06 18:11:21 thorpej Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -119,6 +119,30 @@ ATF_TC_BODY(lwp_create_works, tc) ATF_REQUIRE(lid == the_lwp_id); } +ATF_TC(lwp_create_bad_lid_ptr); +ATF_TC_HEAD(lwp_create_bad_lid_ptr, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify _lwp_create() fails as expected with bad lid pointer"); +} + +ATF_TC_BODY(lwp_create_bad_lid_ptr, tc) +{ + ucontext_t uc; + int error; + int serrno; + void *stack; + static const size_t ssize = 16*1024; + + stack = malloc(ssize); + _lwp_makecontext(, lwp_main_func, NULL, NULL, stack, ssize); + + error = _lwp_create(, 0, NULL); + serrno = errno; + ATF_REQUIRE(error == -1); + ATF_REQUIRE(serrno == EFAULT); +} + INVALID_UCONTEXT(generic, no_uc_cpu, "not setting cpu registers") uc->uc_flags &= ~_UC_CPU; } @@ -206,6 +230,7 @@ INVALID_UCONTEXT(vax, psl_cm, "setting C ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, lwp_create_works); + ATF_TP_ADD_TC(tp, lwp_create_bad_lid_ptr); ATF_TP_ADD_TC(tp, lwp_create_generic_fail_no_uc_cpu); #ifdef __alpha__ ATF_TP_ADD_TC(tp, lwp_create_alpha_fail_pslset);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Sat May 16 23:10:26 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_fork_wait.h Log Message: Ignore interception of SIGCHLD signals in the debugger Set SIGPASS for SIGCHLD for the traced child in the following tests: - unrelated_tracer_fork* - unrelated_tracer_vfork* - unrelated_tracer_posix_spawn* There is a race that SIGCHLD might be blocked during forking and dropped. PR/55241 by Andreas Gustafsson To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_ptrace_fork_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_fork_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.5 src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.6 --- src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.5 Sat May 16 22:07:06 2020 +++ src/tests/lib/libc/sys/t_ptrace_fork_wait.h Sat May 16 23:10:26 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_fork_wait.h,v 1.5 2020/05/16 22:07:06 kamil Exp $ */ +/* $NetBSD: t_ptrace_fork_wait.h,v 1.6 2020/05/16 23:10:26 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2020 The NetBSD Foundation, Inc. @@ -337,6 +337,7 @@ unrelated_tracer_fork_body(const char *f int status; #endif + sigset_t set; struct ptrace_siginfo info; ptrace_state_t state; const int slen = sizeof(state); @@ -453,6 +454,21 @@ unrelated_tracer_fork_body(const char *f SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, tracee, , elen) != -1); + /* + * Ignore interception of the SIGCHLD signals. + * + * SIGCHLD once blocked is discarded by the kernel as it has the + * SA_IGNORE property. During the fork(2) operation all signals + * can be shortly blocked and missed (unless there is a + * registered signal handler in the traced child). This leads to + * a race in this test if there would be an intention to catch + * SIGCHLD. + */ + sigemptyset(); + sigaddset(, SIGCHLD); + SYSCALL_REQUIRE(ptrace(PT_SET_SIGPASS, tracee, , + sizeof(set)) != -1); + DPRINTF("Before resuming the child process where it left off " "and without signal to be sent\n"); SYSCALL_REQUIRE(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); @@ -559,16 +575,6 @@ unrelated_tracer_fork_body(const char *f wpid = TWAIT_GENERIC(tracee2, , 0)); } - DPRINTF("Before calling %s() for the tracee - expected stopped " - "SIGCHLD\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, , 0), tracee); - - validate_status_stopped(status, SIGCHLD); - - DPRINTF("Before resuming the tracee process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); - DPRINTF("Before calling %s() for the tracee - expected exited\n", TWAIT_FNAME); TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, , 0), tracee);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Sat May 16 22:07:06 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_fork_wait.h Log Message: Fix typo in test names Noted by To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_ptrace_fork_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_fork_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.4 src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.5 --- src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.4 Sat May 16 19:08:20 2020 +++ src/tests/lib/libc/sys/t_ptrace_fork_wait.h Sat May 16 22:07:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_fork_wait.h,v 1.4 2020/05/16 19:08:20 kamil Exp $ */ +/* $NetBSD: t_ptrace_fork_wait.h,v 1.5 2020/05/16 22:07:06 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2020 The NetBSD Foundation, Inc. @@ -1600,14 +1600,14 @@ ATF_TC_BODY(name, tc) \ fork2_body(fn, masked, ignored);\ } -FORK2_TEST(posix_spawn_singalmasked, "spawn", true, false) -FORK2_TEST(posix_spawn_singalignored, "spawn", false, true) -FORK2_TEST(fork_singalmasked, "fork", true, false) -FORK2_TEST(fork_singalignored, "fork", false, true) -FORK2_TEST(vfork_singalmasked, "vfork", true, false) -FORK2_TEST(vfork_singalignored, "vfork", false, true) -FORK2_TEST(vforkdone_singalmasked, "vforkdone", true, false) -FORK2_TEST(vforkdone_singalignored, "vforkdone", false, true) +FORK2_TEST(posix_spawn_signalmasked, "spawn", true, false) +FORK2_TEST(posix_spawn_signalignored, "spawn", false, true) +FORK2_TEST(fork_signalmasked, "fork", true, false) +FORK2_TEST(fork_signalignored, "fork", false, true) +FORK2_TEST(vfork_signalmasked, "vfork", true, false) +FORK2_TEST(vfork_signalignored, "vfork", false, true) +FORK2_TEST(vforkdone_signalmasked, "vforkdone", true, false) +FORK2_TEST(vforkdone_signalignored, "vforkdone", false, true) #endif #define ATF_TP_ADD_TCS_PTRACE_WAIT_FORK() \ @@ -1725,11 +1725,11 @@ FORK2_TEST(vforkdone_singalignored, "vfo ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_vfork_kill_vforkerdone); \ ATF_TP_ADD_TC(tp, traceme_vfork_fork); \ ATF_TP_ADD_TC(tp, traceme_vfork_vfork); \ - ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn_singalmasked); \ - ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn_singalignored); \ - ATF_TP_ADD_TC_HAVE_PID(tp, fork_singalmasked); \ - ATF_TP_ADD_TC_HAVE_PID(tp, fork_singalignored); \ - ATF_TP_ADD_TC_HAVE_PID(tp, vfork_singalmasked); \ - ATF_TP_ADD_TC_HAVE_PID(tp, vfork_singalignored); \ - ATF_TP_ADD_TC_HAVE_PID(tp, vforkdone_singalmasked); \ - ATF_TP_ADD_TC_HAVE_PID(tp, vforkdone_singalignored); + ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn_signalmasked); \ + ATF_TP_ADD_TC_HAVE_PID(tp, posix_spawn_signalignored); \ + ATF_TP_ADD_TC_HAVE_PID(tp, fork_signalmasked); \ + ATF_TP_ADD_TC_HAVE_PID(tp, fork_signalignored); \ + ATF_TP_ADD_TC_HAVE_PID(tp, vfork_signalmasked); \ + ATF_TP_ADD_TC_HAVE_PID(tp, vfork_signalignored); \ + ATF_TP_ADD_TC_HAVE_PID(tp, vforkdone_signalmasked); \ + ATF_TP_ADD_TC_HAVE_PID(tp, vforkdone_signalignored);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Sat May 16 19:08:20 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_fork_wait.h Log Message: Ignore interception of SIGCHLD signals in the debugger Set SIGPASS for SIGCHLD for the traced child in the following tests: - posix_spawn_singalmasked - posix_spawn_singalignored - fork_singalmasked - fork_singalignored - vfork_singalmasked - vfork_singalignored - vforkdone_singalmasked - vforkdone_singalignored There is a race that SIGCHLD might be blocked during forking and dropped. PR/55241 by Andreas Gustafsson To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_fork_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_fork_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.3 src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.4 --- src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.3 Thu May 14 19:21:35 2020 +++ src/tests/lib/libc/sys/t_ptrace_fork_wait.h Sat May 16 19:08:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_fork_wait.h,v 1.3 2020/05/14 19:21:35 kamil Exp $ */ +/* $NetBSD: t_ptrace_fork_wait.h,v 1.4 2020/05/16 19:08:20 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2020 The NetBSD Foundation, Inc. @@ -1250,6 +1250,7 @@ fork2_body(const char *fn, bool masked, int name[6]; const size_t namelen = __arraycount(name); + sigset_t set; ki_sigset_t kp_sigmask; ki_sigset_t kp_sigignore; @@ -1341,6 +1342,19 @@ fork2_body(const char *fn, bool masked, event.pe_set_event |= PTRACE_VFORK_DONE; SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1); + /* + * Ignore interception of the SIGCHLD signals. + * + * SIGCHLD once blocked is discarded by the kernel as it has the + * SA_IGNORE property. During the fork(2) operation all signals can be + * shortly blocked and missed (unless there is a registered signal + * handler in the traced child). This leads to a race in this test if + * there would be an intention to catch SIGCHLD. + */ + sigemptyset(); + sigaddset(, SIGCHLD); + SYSCALL_REQUIRE(ptrace(PT_SET_SIGPASS, child, , sizeof(set)) != -1); + DPRINTF("Before resuming the child process where it left off and " "without signal to be sent\n"); SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); @@ -1560,16 +1574,6 @@ fork2_body(const char *fn, bool masked, wpid = TWAIT_GENERIC(child2, , 0)); } - DPRINTF("Before calling %s() for the child - expected stopped " - "SIGCHLD\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, SIGCHLD); - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - DPRINTF("Before calling %s() for the child - expected exited\n", TWAIT_FNAME); TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Thu May 14 19:21:35 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_fork_wait.h Log Message: Ignore interception of the SIGCHLD signals. SIGCHLD once blocked is discarded by the kernel as it has the SA_IGNORE property. During the fork(2) operation all signals can be shortly blocked and missed (unless there is a registered signal handler in the traced child). This leads to a race in this test if there would be an intention to catch SIGCHLD. Fixes PR lib/55241 by Andreas Gustafsson To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_ptrace_fork_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_fork_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.2 src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.3 --- src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.2 Mon May 11 20:58:48 2020 +++ src/tests/lib/libc/sys/t_ptrace_fork_wait.h Thu May 14 19:21:35 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_fork_wait.h,v 1.2 2020/05/11 20:58:48 kamil Exp $ */ +/* $NetBSD: t_ptrace_fork_wait.h,v 1.3 2020/05/14 19:21:35 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2020 The NetBSD Foundation, Inc. @@ -38,6 +38,7 @@ fork_body(const char *fn, bool trackspaw #if defined(TWAIT_HAVE_STATUS) int status; #endif + sigset_t set; ptrace_state_t state; const int slen = sizeof(state); ptrace_event_t event; @@ -98,6 +99,19 @@ fork_body(const char *fn, bool trackspaw event.pe_set_event |= PTRACE_VFORK_DONE; SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1); + /* + * Ignore interception of the SIGCHLD signals. + * + * SIGCHLD once blocked is discarded by the kernel as it has the + * SA_IGNORE property. During the fork(2) operation all signals can be + * shortly blocked and missed (unless there is a registered signal + * handler in the traced child). This leads to a race in this test if + * there would be an intention to catch SIGCHLD. + */ + sigemptyset(); + sigaddset(, SIGCHLD); + SYSCALL_REQUIRE(ptrace(PT_SET_SIGPASS, child, , sizeof(set)) != -1); + DPRINTF("Before resuming the child process where it left off and " "without signal to be sent\n"); SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); @@ -207,16 +221,6 @@ fork_body(const char *fn, bool trackspaw } #endif - DPRINTF("Before calling %s() for the child - expected stopped " - "SIGCHLD\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, SIGCHLD); - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - DPRINTF("Before calling %s() for the child - expected exited\n", TWAIT_FNAME); TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 11 21:18:11 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_clone_wait.h Log Message: Fix potential race in ptrace(2) clone(2) tests Instead of comparing old and new signal mask, just after the cloning operation, check whether the expected signal is still masked and in another test whether it is still ignored. Catch up after t_ptrace_fork_wait.h r. 1.2. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_ptrace_clone_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_clone_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_clone_wait.h:1.2 src/tests/lib/libc/sys/t_ptrace_clone_wait.h:1.3 --- src/tests/lib/libc/sys/t_ptrace_clone_wait.h:1.2 Mon May 4 22:24:31 2020 +++ src/tests/lib/libc/sys/t_ptrace_clone_wait.h Mon May 11 21:18:11 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_clone_wait.h,v 1.2 2020/05/04 22:24:31 kamil Exp $ */ +/* $NetBSD: t_ptrace_clone_wait.h,v 1.3 2020/05/11 21:18:11 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -414,11 +414,8 @@ clone_body2(int flags, bool masked, bool FORKEE_ASSERT_EQ(sysctl(name, namelen, , , NULL, 0), 0); - if (masked) - kp_sigmask = kp.p_sigmask; - - if (ignored) - kp_sigignore = kp.p_sigignore; + kp_sigmask = kp.p_sigmask; + kp_sigignore = kp.p_sigignore; DPRINTF("Set PTRACE_FORK | PTRACE_VFORK | PTRACE_VFORK_DONE in " "EVENT_MASK for the child %d\n", child); @@ -451,8 +448,8 @@ clone_body2(int flags, bool masked, bool kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1], kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]); - ATF_REQUIRE(!memcmp(_sigmask, _sigmask, - sizeof(kp_sigmask))); + ATF_REQUIRE(sigismember((sigset_t *)_sigmask, + SIGTRAP)); } if (ignored) { @@ -468,8 +465,8 @@ clone_body2(int flags, bool masked, bool kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1], kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]); - ATF_REQUIRE(!memcmp(_sigignore, _sigignore, - sizeof(kp_sigignore))); + ATF_REQUIRE(sigismember((sigset_t *)_sigignore, + SIGTRAP)); } SYSCALL_REQUIRE( @@ -510,8 +507,8 @@ clone_body2(int flags, bool masked, bool kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1], kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]); - ATF_REQUIRE(!memcmp(_sigmask, _sigmask, - sizeof(kp_sigmask))); + ATF_REQUIRE(sigismember((sigset_t *)_sigmask, + SIGTRAP)); } if (ignored) { @@ -527,8 +524,8 @@ clone_body2(int flags, bool masked, bool kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1], kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]); - ATF_REQUIRE(!memcmp(_sigignore, _sigignore, - sizeof(kp_sigignore))); + ATF_REQUIRE(sigismember((sigset_t *)_sigignore, + SIGTRAP)); } SYSCALL_REQUIRE(
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 11 20:58:48 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_fork_wait.h Log Message: Fix race in fork_singalmasked ELF RTLD after rtld.c r. 1.204 introduced locking that wraps the fork syscall. This locking changes signal mask of the calling process during the forking process. Instead of comparing old and new signal mask, just after the forking operation, check whether the expected signal is still masked and in another test whether it is still ignored. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_fork_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_fork_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.1 src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.2 --- src/tests/lib/libc/sys/t_ptrace_fork_wait.h:1.1 Mon May 4 22:34:22 2020 +++ src/tests/lib/libc/sys/t_ptrace_fork_wait.h Mon May 11 20:58:48 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_fork_wait.h,v 1.1 2020/05/04 22:34:22 kamil Exp $ */ +/* $NetBSD: t_ptrace_fork_wait.h,v 1.2 2020/05/11 20:58:48 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2020 The NetBSD Foundation, Inc. @@ -1318,11 +1318,8 @@ fork2_body(const char *fn, bool masked, FORKEE_ASSERT_EQ(sysctl(name, namelen, , , NULL, 0), 0); - if (masked) - kp_sigmask = kp.p_sigmask; - - if (ignored) - kp_sigignore = kp.p_sigignore; + kp_sigmask = kp.p_sigmask; + kp_sigignore = kp.p_sigignore; DPRINTF("Set 0%s%s%s%s in EVENT_MASK for the child %d\n", strcmp(fn, "spawn") == 0 ? "|PTRACE_POSIX_SPAWN" : "", @@ -1368,8 +1365,8 @@ fork2_body(const char *fn, bool masked, kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1], kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]); - ATF_REQUIRE(!memcmp(_sigmask, _sigmask, - sizeof(kp_sigmask))); + ATF_REQUIRE(sigismember((sigset_t *)_sigmask, + SIGTRAP)); } if (ignored) { @@ -1385,8 +1382,8 @@ fork2_body(const char *fn, bool masked, kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1], kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]); - ATF_REQUIRE(!memcmp(_sigignore, _sigignore, - sizeof(kp_sigignore))); + ATF_REQUIRE(sigismember((sigset_t *)_sigignore, + SIGTRAP)); } SYSCALL_REQUIRE( @@ -1431,8 +1428,8 @@ fork2_body(const char *fn, bool masked, kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1], kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]); - ATF_REQUIRE(!memcmp(_sigmask, _sigmask, - sizeof(kp_sigmask))); + ATF_REQUIRE(sigismember((sigset_t *)_sigmask, + SIGTRAP)); } if (ignored) { @@ -1448,8 +1445,8 @@ fork2_body(const char *fn, bool masked, kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1], kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]); - ATF_REQUIRE(!memcmp(_sigignore, _sigignore, - sizeof(kp_sigignore))); + ATF_REQUIRE(sigismember((sigset_t *)_sigignore, + SIGTRAP)); } SYSCALL_REQUIRE( @@ -1510,8 +1507,8 @@ fork2_body(const char *fn, bool masked, kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1], kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]); - ATF_REQUIRE(!memcmp(_sigmask, _sigmask, - sizeof(kp_sigmask))); + ATF_REQUIRE(sigismember((sigset_t *)_sigmask, + SIGTRAP)); } if (ignored) { @@ -1527,8 +1524,8 @@ fork2_body(const char *fn, bool masked, kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1], kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]); - ATF_REQUIRE(!memcmp(_sigignore, _sigignore, - sizeof(kp_sigignore))); + ATF_REQUIRE(sigismember((sigset_t *)_sigignore, + SIGTRAP)); } SYSCALL_REQUIRE(
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 11 12:17:57 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_register_wait.h Log Message: Simplify previous Emit SIGKILL without a loop and without checking for exact process status once it is collected. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_ptrace_register_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_register_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.2 src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.3 --- src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.2 Mon May 11 11:03:15 2020 +++ src/tests/lib/libc/sys/t_ptrace_register_wait.h Mon May 11 12:17:57 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_register_wait.h,v 1.2 2020/05/11 11:03:15 kamil Exp $ */ +/* $NetBSD: t_ptrace_register_wait.h,v 1.3 2020/05/11 12:17:57 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -136,19 +136,13 @@ access_regs(const char *regset, const ch if (strstr(aux, "unaligned") != NULL) { DPRINTF("Before resuming the child process where it left off " "and without signal to be sent\n"); - for (;;) { - errno = 0; - if (ptrace(PT_KILL, child, NULL, 0) == 0) -break; - ATF_REQUIRE_EQ(errno, ESRCH); - } + + ptrace(PT_KILL, child, NULL, 0); DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - validate_status_signaled(status, SIGKILL, 0); - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0));
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 11 11:03:15 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_register_wait.h Log Message: Do not fail when trying to kill a dying process A dying process can disappear for a while. Rather than aborting, retry sending SIGKILL to it. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_register_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_register_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.1 src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.2 --- src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.1 Mon May 4 20:55:48 2020 +++ src/tests/lib/libc/sys/t_ptrace_register_wait.h Mon May 11 11:03:15 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_register_wait.h,v 1.1 2020/05/04 20:55:48 kamil Exp $ */ +/* $NetBSD: t_ptrace_register_wait.h,v 1.2 2020/05/11 11:03:15 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -136,7 +136,12 @@ access_regs(const char *regset, const ch if (strstr(aux, "unaligned") != NULL) { DPRINTF("Before resuming the child process where it left off " "and without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1); + for (;;) { + errno = 0; + if (ptrace(PT_KILL, child, NULL, 0) == 0) +break; + ATF_REQUIRE_EQ(errno, ESRCH); + } DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0),
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: thorpej Date: Wed May 6 05:14:27 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_futex_ops.c Log Message: Fix a bug in the futex_wake_highest_pri test case. Still fails as expected. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_futex_ops.c 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_futex_ops.c diff -u src/tests/lib/libc/sys/t_futex_ops.c:1.4 src/tests/lib/libc/sys/t_futex_ops.c:1.5 --- src/tests/lib/libc/sys/t_futex_ops.c:1.4 Mon May 4 15:09:34 2020 +++ src/tests/lib/libc/sys/t_futex_ops.c Wed May 6 05:14:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_futex_ops.c,v 1.4 2020/05/04 15:09:34 thorpej Exp $ */ +/* $NetBSD: t_futex_ops.c,v 1.5 2020/05/06 05:14:27 thorpej Exp $ */ /*- * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2019, 2020\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_futex_ops.c,v 1.4 2020/05/04 15:09:34 thorpej Exp $"); +__RCSID("$NetBSD: t_futex_ops.c,v 1.5 2020/05/06 05:14:27 thorpej Exp $"); #include #include @@ -1416,8 +1416,8 @@ do_test_wake_highest_pri(void) lwp_data[1].block_val = 0; lwp_data[1].bitset = 0; lwp_data[1].wait_op = FUTEX_WAIT; - ATF_REQUIRE(_lwp_create(_data[0].context, 0, -_data[0].lwpid) == 0); + ATF_REQUIRE(_lwp_create(_data[1].context, 0, +_data[1].lwpid) == 0); for (tries = 0; tries < 5; tries++) { membar_sync();
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 18:12:20 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_sigchld.c Log Message: Skip traceme_raise* tests rather than failing upfront This avoid reporting the tests as unexpected failure. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_ptrace_sigchld.c 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_sigchld.c diff -u src/tests/lib/libc/sys/t_ptrace_sigchld.c:1.2 src/tests/lib/libc/sys/t_ptrace_sigchld.c:1.3 --- src/tests/lib/libc/sys/t_ptrace_sigchld.c:1.2 Fri Mar 6 19:10:27 2020 +++ src/tests/lib/libc/sys/t_ptrace_sigchld.c Tue May 5 18:12:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_sigchld.c,v 1.2 2020/03/06 19:10:27 kamil Exp $ */ +/* $NetBSD: t_ptrace_sigchld.c,v 1.3 2020/05/05 18:12:20 kamil Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_sigchld.c,v 1.2 2020/03/06 19:10:27 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_sigchld.c,v 1.3 2020/05/05 18:12:20 kamil Exp $"); #include #include @@ -123,7 +123,7 @@ traceme_raise(int sigval) sa.sa_flags = SA_SIGINFO | SA_NOCLDWAIT; sigemptyset(_mask); - atf_tc_fail("XXX: zombie is not collected before tracer's death"); + atf_tc_skip("XXX: zombie is not collected before tracer's death"); SYSCALL_REQUIRE(sigaction(SIGCHLD, , NULL) == 0);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 02:06:08 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_misc_wait.h Log Message: Move misc tests out of t_ptrace_wait.c to t_ptrace_misc_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_misc_wait.h cvs rdiff -u -r1.190 -r1.191 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.190 src/tests/lib/libc/sys/t_ptrace_wait.c:1.191 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.190 Tue May 5 01:24:29 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 02:06:08 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.190 2020/05/05 01:24:29 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.191 2020/05/05 02:06:08 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.190 2020/05/05 01:24:29 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.191 2020/05/05 02:06:08 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -103,94 +103,6 @@ static int debug = 0; /// -static void -user_va0_disable(int operation) -{ - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - const int sigval = SIGSTOP; - int rv; - - struct ptrace_siginfo info; - - if (get_user_va0_disable() == 0) - atf_tc_skip("vm.user_va0_disable is set to 0"); - - memset(, 0, sizeof(info)); - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - /* NOTREACHED */ - FORKEE_ASSERTX(0 && "This shall not be reached"); - __unreachable(); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for " - "child\n"); - SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , - sizeof(info)) != -1); - - DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); - DPRINTF("Signal properties: si_signo=%#x si_code=%#x " - "si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); - - DPRINTF("Before resuming the child process in PC=0x0 " - "and without signal to be sent\n"); - errno = 0; - rv = ptrace(operation, child, (void *)0, 0); - ATF_REQUIRE_EQ(errno, EINVAL); - ATF_REQUIRE_EQ(rv, -1); - - SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - validate_status_signaled(status, SIGKILL, 0); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); -} - -#define USER_VA0_DISABLE(test, operation)\ -ATF_TC(test);\ -ATF_TC_HEAD(test, tc) \ -{ \ - atf_tc_set_md_var(tc, "descr", \ - "Verify behavior of " #operation " with PC set to 0x0"); \ -} \ - \ -ATF_TC_BODY(test, tc) \ -{ \ - \ - user_va0_disable(operation); \ -} - -USER_VA0_DISABLE(user_va0_disable_pt_continue, PT_CONTINUE) -USER_VA0_DISABLE(user_va0_disable_pt_syscall, PT_SYSCALL) -USER_VA0_DISABLE(user_va0_disable_pt_detach, PT_DETACH) - -/// - #include "t_ptrace_register_wait.h" #include "t_ptrace_syscall_wait.h" #include "t_ptrace_step_wait.h" @@ -206,6 +118,7 @@ USER_VA0_DISABLE(user_va0_disable_pt_det #include "t_ptrace_threads_wait.h" #include "t_ptrace_siginfo_wait.h" #include "t_ptrace_core_wait.h" +#include "t_ptrace_misc_wait.h" /// @@ -236,10 +149,6 @@ ATF_TP_ADD_TCS(tp) setvbuf(stderr, NULL, _IONBF, 0); #ifdef ENABLE_TESTS - ATF_TP_ADD_TC(tp, user_va0_disable_pt_continue); - ATF_TP_ADD_TC(tp, user_va0_disable_pt_syscall); - ATF_TP_ADD_TC(tp, user_va0_disable_pt_detach); - ATF_TP_ADD_TCS_PTRACE_WAIT_REGISTER();
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 01:24:29 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_core_wait.h Log Message: Move core tests out of t_ptrace_wait.c to t_ptrace_core_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_core_wait.h cvs rdiff -u -r1.189 -r1.190 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.189 src/tests/lib/libc/sys/t_ptrace_wait.c:1.190 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.189 Tue May 5 00:57:34 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 01:24:29 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.189 2020/05/05 00:57:34 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.190 2020/05/05 01:24:29 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.189 2020/05/05 00:57:34 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.190 2020/05/05 01:24:29 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -191,199 +191,6 @@ USER_VA0_DISABLE(user_va0_disable_pt_det /// -/* - * Parse the core file and find the requested note. If the reading or parsing - * fails, the test is failed. If the note is found, it is read onto buf, up to - * buf_len. The actual length of the note is returned (which can be greater - * than buf_len, indicating that it has been truncated). If the note is not - * found, -1 is returned. - * - * If the note_name ends in '*', then we find the first note that matches - * the note_name prefix up to the '*' character, e.g.: - * - * NetBSD-CORE@* - * - * finds the first note whose name prefix matches "NetBSD-CORE@". - */ -static ssize_t core_find_note(const char *core_path, -const char *note_name, uint64_t note_type, void *buf, size_t buf_len) -{ - int core_fd; - Elf *core_elf; - size_t core_numhdr, i; - ssize_t ret = -1; - size_t name_len = strlen(note_name); - bool prefix_match = false; - - if (note_name[name_len - 1] == '*') { - prefix_match = true; - name_len--; - } else { - /* note: we assume note name will be null-terminated */ - name_len++; - } - - SYSCALL_REQUIRE((core_fd = open(core_path, O_RDONLY)) != -1); - SYSCALL_REQUIRE(elf_version(EV_CURRENT) != EV_NONE); - SYSCALL_REQUIRE((core_elf = elf_begin(core_fd, ELF_C_READ, NULL))); - - SYSCALL_REQUIRE(elf_getphnum(core_elf, _numhdr) != 0); - for (i = 0; i < core_numhdr && ret == -1; i++) { - GElf_Phdr core_hdr; - size_t offset; - SYSCALL_REQUIRE(gelf_getphdr(core_elf, i, _hdr)); - if (core_hdr.p_type != PT_NOTE) - continue; - - for (offset = core_hdr.p_offset; - offset < core_hdr.p_offset + core_hdr.p_filesz;) { - Elf64_Nhdr note_hdr; - char name_buf[64]; - - switch (gelf_getclass(core_elf)) { - case ELFCLASS64: -SYSCALL_REQUIRE(pread(core_fd, _hdr, -sizeof(note_hdr), offset) -== sizeof(note_hdr)); -offset += sizeof(note_hdr); -break; - case ELFCLASS32: -{ -Elf32_Nhdr tmp_hdr; -SYSCALL_REQUIRE(pread(core_fd, _hdr, -sizeof(tmp_hdr), offset) -== sizeof(tmp_hdr)); -offset += sizeof(tmp_hdr); -note_hdr.n_namesz = tmp_hdr.n_namesz; -note_hdr.n_descsz = tmp_hdr.n_descsz; -note_hdr.n_type = tmp_hdr.n_type; -} -break; - } - - /* indicates end of notes */ - if (note_hdr.n_namesz == 0 || note_hdr.n_descsz == 0) -break; - if (((prefix_match && - note_hdr.n_namesz > name_len) || - (!prefix_match && - note_hdr.n_namesz == name_len)) && - note_hdr.n_namesz <= sizeof(name_buf)) { -SYSCALL_REQUIRE(pread(core_fd, name_buf, -note_hdr.n_namesz, offset) -== (ssize_t)(size_t)note_hdr.n_namesz); - -if (!strncmp(note_name, name_buf, name_len) && -note_hdr.n_type == note_type) - ret = note_hdr.n_descsz; - } - - offset += note_hdr.n_namesz; - /* fix to alignment */ - offset = roundup(offset, core_hdr.p_align); - - /* if name & type matched above */ - if (ret != -1) { -ssize_t read_len = MIN(buf_len, -note_hdr.n_descsz); -SYSCALL_REQUIRE(pread(core_fd, buf, -read_len, offset) == read_len); -break; - } - - offset += note_hdr.n_descsz; - /* fix to alignment */ - offset = roundup(offset, core_hdr.p_align); - } - } - - elf_end(core_elf); - close(core_fd); - - return ret; -} - -ATF_TC(core_dump_procinfo); -ATF_TC_HEAD(core_dump_procinfo, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Trigger a core dump and verify its
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 00:57:34 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_siginfo_wait.h Log Message: Move siginfo tests out of t_ptrace_wait.c to t_ptrace_siginfo_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_siginfo_wait.h cvs rdiff -u -r1.188 -r1.189 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.188 src/tests/lib/libc/sys/t_ptrace_wait.c:1.189 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.188 Tue May 5 00:50:39 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 00:57:34 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.188 2020/05/05 00:50:39 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.189 2020/05/05 00:57:34 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.188 2020/05/05 00:50:39 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.189 2020/05/05 00:57:34 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -104,132 +104,6 @@ static int debug = 0; /// static void -ptrace_siginfo(bool faked, void (*sah)(int a, siginfo_t *b, void *c), int *signal_caught) -{ - const int exitval = 5; - const int sigval = SIGINT; - const int sigfaked = SIGTRAP; - const int sicodefaked = TRAP_BRKPT; - pid_t child, wpid; - struct sigaction sa; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - struct ptrace_siginfo info; - memset(, 0, sizeof(info)); - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - sa.sa_sigaction = sah; - sa.sa_flags = SA_SIGINFO; - sigemptyset(_mask); - - FORKEE_ASSERT(sigaction(faked ? sigfaked : sigval, , NULL) - != -1); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - FORKEE_ASSERT_EQ(*signal_caught, 1); - - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - SYSCALL_REQUIRE( - ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - - DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); - DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - if (faked) { - DPRINTF("Before setting new faked signal to signo=%d " - "si_code=%d\n", sigfaked, sicodefaked); - info.psi_siginfo.si_signo = sigfaked; - info.psi_siginfo.si_code = sicodefaked; - } - - DPRINTF("Before calling ptrace(2) with PT_SET_SIGINFO for child\n"); - SYSCALL_REQUIRE( - ptrace(PT_SET_SIGINFO, child, , sizeof(info)) != -1); - - if (faked) { - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for " - "child\n"); - SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , - sizeof(info)) != -1); - - DPRINTF("Before checking siginfo_t\n"); - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigfaked); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, sicodefaked); - } - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, - faked ? sigfaked : sigval) != -1); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_exited(status, exitval); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); -} - -#define PTRACE_SIGINFO(test, faked) \ -ATF_TC(test);\ -ATF_TC_HEAD(test, tc) \ -{ \ - atf_tc_set_md_var(tc, "descr", \ - "Verify basic PT_GET_SIGINFO and PT_SET_SIGINFO calls" \ - "with%s setting signal to new value", faked ? "" : "out"); \ -} \ - \ -static int test##_caught = 0; \ - \ -static void\ -test##_sighandler(int sig, siginfo_t *info, void *ctx) \ -{ \ - if (faked) { \ - FORKEE_ASSERT_EQ(sig, SIGTRAP);\ -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 00:50:39 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h Added Files: src/tests/lib/libc/sys: t_ptrace_threads_wait.h Log Message: Move threads tests out of t_ptrace_wait.c to t_ptrace_threads_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_threads_wait.h cvs rdiff -u -r1.187 -r1.188 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.27 -r1.28 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.187 src/tests/lib/libc/sys/t_ptrace_wait.c:1.188 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.187 Tue May 5 00:33:37 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 00:50:39 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.187 2020/05/05 00:33:37 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.188 2020/05/05 00:50:39 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.187 2020/05/05 00:33:37 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.188 2020/05/05 00:50:39 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -229,631 +229,6 @@ PTRACE_SIGINFO(siginfo_set_faked, true) /// -#define TRACE_THREADS_NUM 100 - -static volatile int done; -pthread_mutex_t trace_threads_mtx = PTHREAD_MUTEX_INITIALIZER; - -static void * -trace_threads_cb(void *arg __unused) -{ - - pthread_mutex_lock(_threads_mtx); - done++; - pthread_mutex_unlock(_threads_mtx); - - while (done < TRACE_THREADS_NUM) - sched_yield(); - - return NULL; -} - -static void -trace_threads(bool trace_create, bool trace_exit, bool masked) -{ - const int sigval = SIGSTOP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - ptrace_state_t state; - const int slen = sizeof(state); - ptrace_event_t event; - const int elen = sizeof(event); - struct ptrace_siginfo info; - - sigset_t intmask; - - pthread_t t[TRACE_THREADS_NUM]; - int rv; - size_t n; - lwpid_t lid; - - /* Track created and exited threads */ - struct lwp_event_count traced_lwps[__arraycount(t)] = {{0, 0}}; - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - if (masked) { - sigemptyset(); - sigaddset(, SIGTRAP); - sigprocmask(SIG_BLOCK, , NULL); - } - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - for (n = 0; n < __arraycount(t); n++) { - rv = pthread_create([n], NULL, trace_threads_cb, - NULL); - FORKEE_ASSERT(rv == 0); - } - - for (n = 0; n < __arraycount(t); n++) { - rv = pthread_join(t[n], NULL); - FORKEE_ASSERT(rv == 0); - } - - /* - * There is race between _exit() and pthread_join() detaching - * a thread. For simplicity kill the process after detecting - * LWP events. - */ - while (true) - continue; - - FORKEE_ASSERT(0 && "Not reached"); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - SYSCALL_REQUIRE( - ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - - DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); - DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); - - DPRINTF("Set LWP event mask for the child %d\n", child); - memset(, 0, sizeof(event)); - if (trace_create) - event.pe_set_event |= PTRACE_LWP_CREATE; - if (trace_exit) - event.pe_set_event |= PTRACE_LWP_EXIT; - SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1); - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - for (n = 0; n < (trace_create ? __arraycount(t) : 0); n++) { - DPRINTF("Before calling %s() for the child - expected stopped " - "SIGTRAP\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), - child); - - validate_status_stopped(status,
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 00:33:37 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_topology_wait.h Log Message: Move topology tests out of t_ptrace_wait.c to t_ptrace_topology_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_topology_wait.h cvs rdiff -u -r1.186 -r1.187 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.186 src/tests/lib/libc/sys/t_ptrace_wait.c:1.187 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.186 Tue May 5 00:23:12 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 00:33:37 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.186 2020/05/05 00:23:12 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.187 2020/05/05 00:33:37 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.186 2020/05/05 00:23:12 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.187 2020/05/05 00:33:37 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -103,683 +103,6 @@ static int debug = 0; /// -ATF_TC(traceme_pid1_parent); -ATF_TC_HEAD(traceme_pid1_parent, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Verify that PT_TRACE_ME is not allowed when our parent is PID1"); -} - -ATF_TC_BODY(traceme_pid1_parent, tc) -{ - struct msg_fds parent_child; - int exitval_child1 = 1, exitval_child2 = 2; - pid_t child1, child2, wpid; - uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - - SYSCALL_REQUIRE(msg_open(_child) == 0); - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child1 = fork()) != -1); - if (child1 == 0) { - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child2 = fork()) != -1); - if (child2 != 0) { - DPRINTF("Parent process PID=%d, child2's PID=%d\n", - getpid(), child2); - _exit(exitval_child1); - } - CHILD_FROM_PARENT("exit child1", parent_child, msg); - - DPRINTF("Assert that our parent is PID1 (initproc)\n"); - FORKEE_ASSERT_EQ(getppid(), 1); - - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) == -1); - SYSCALL_REQUIRE_ERRNO(errno, EPERM); - - CHILD_TO_PARENT("child2 exiting", parent_child, msg); - - _exit(exitval_child2); - } - DPRINTF("Parent process PID=%d, child1's PID=%d\n", getpid(), child1); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS( - wpid = TWAIT_GENERIC(child1, , WEXITED), child1); - - validate_status_exited(status, exitval_child1); - - DPRINTF("Notify that child1 is dead\n"); - PARENT_TO_CHILD("exit child1", parent_child, msg); - - DPRINTF("Wait for exiting of child2\n"); - PARENT_FROM_CHILD("child2 exiting", parent_child, msg); -} - -/// - -#if defined(TWAIT_HAVE_PID) -static void -tracer_sees_terminaton_before_the_parent_raw(bool notimeout, bool unrelated, - bool stopped) -{ - /* - * notimeout - disable timeout in await zombie function - * unrelated - attach from unrelated tracer reparented to initproc - * stopped - attach to a stopped process - */ - - struct msg_fds parent_tracee, parent_tracer; - const int exitval_tracee = 5; - const int exitval_tracer = 10; - pid_t tracee, tracer, wpid; - uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - - /* - * Only a subset of options are supported. - */ - ATF_REQUIRE((!notimeout && !unrelated && !stopped) || - (!notimeout && unrelated && !stopped) || - (notimeout && !unrelated && !stopped) || - (!notimeout && unrelated && stopped)); - - DPRINTF("Spawn tracee\n"); - SYSCALL_REQUIRE(msg_open(_tracee) == 0); - tracee = atf_utils_fork(); - if (tracee == 0) { - if (stopped) { - DPRINTF("Stop self PID %d\n", getpid()); - raise(SIGSTOP); - } - - // Wait for parent to let us exit - CHILD_FROM_PARENT("exit tracee", parent_tracee, msg); - _exit(exitval_tracee); - } - - DPRINTF("Spawn debugger\n"); - SYSCALL_REQUIRE(msg_open(_tracer) == 0); - tracer = atf_utils_fork(); - if (tracer == 0) { - if(unrelated) { - /* Fork again and drop parent to reattach to PID 1 */ - tracer = atf_utils_fork(); - if (tracer != 0) -_exit(exitval_tracer); - } - - if (stopped) { -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 00:23:13 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_exec_wait.h Log Message: Move exec() tests out of t_ptrace_wait.c to t_ptrace_exec_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_exec_wait.h cvs rdiff -u -r1.185 -r1.186 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.185 src/tests/lib/libc/sys/t_ptrace_wait.c:1.186 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.185 Tue May 5 00:15:45 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 00:23:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.185 2020/05/05 00:15:45 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.186 2020/05/05 00:23:12 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.185 2020/05/05 00:15:45 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.186 2020/05/05 00:23:12 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -162,153 +162,6 @@ ATF_TC_BODY(traceme_pid1_parent, tc) /// -static void -traceme_vfork_exec(bool masked, bool ignored) -{ - const int sigval = SIGTRAP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - struct sigaction sa; - struct ptrace_siginfo info; - sigset_t intmask; - struct kinfo_proc2 kp; - size_t len = sizeof(kp); - - int name[6]; - const size_t namelen = __arraycount(name); - ki_sigset_t kp_sigmask; - ki_sigset_t kp_sigignore; - - memset(, 0, sizeof(info)); - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = vfork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - if (masked) { - sigemptyset(); - sigaddset(, sigval); - sigprocmask(SIG_BLOCK, , NULL); - } - - if (ignored) { - memset(, 0, sizeof(sa)); - sa.sa_handler = SIG_IGN; - sigemptyset(_mask); - FORKEE_ASSERT(sigaction(sigval, , NULL) != -1); - } - - DPRINTF("Before calling execve(2) from child\n"); - execlp("/bin/echo", "/bin/echo", NULL); - - /* NOTREACHED */ - FORKEE_ASSERTX(0 && "Not reached"); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - name[0] = CTL_KERN, - name[1] = KERN_PROC2, - name[2] = KERN_PROC_PID; - name[3] = getpid(); - name[4] = sizeof(kp); - name[5] = 1; - - ATF_REQUIRE_EQ(sysctl(name, namelen, , , NULL, 0), 0); - - if (masked) - kp_sigmask = kp.p_sigmask; - - if (ignored) - kp_sigignore = kp.p_sigignore; - - name[3] = getpid(); - - ATF_REQUIRE_EQ(sysctl(name, namelen, , , NULL, 0), 0); - - if (masked) { - DPRINTF("kp_sigmask=" - "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02" PRIx32"\n", - kp_sigmask.__bits[0], kp_sigmask.__bits[1], - kp_sigmask.__bits[2], kp_sigmask.__bits[3]); - - DPRINTF("kp.p_sigmask=" - "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02" PRIx32"\n", - kp.p_sigmask.__bits[0], kp.p_sigmask.__bits[1], - kp.p_sigmask.__bits[2], kp.p_sigmask.__bits[3]); - - ATF_REQUIRE(!memcmp(_sigmask, _sigmask, - sizeof(kp_sigmask))); - } - - if (ignored) { - DPRINTF("kp_sigignore=" - "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02" PRIx32"\n", - kp_sigignore.__bits[0], kp_sigignore.__bits[1], - kp_sigignore.__bits[2], kp_sigignore.__bits[3]); - - DPRINTF("kp.p_sigignore=" - "%#02" PRIx32 "%02" PRIx32 "%02" PRIx32 "%02" PRIx32"\n", - kp.p_sigignore.__bits[0], kp.p_sigignore.__bits[1], - kp.p_sigignore.__bits[2], kp.p_sigignore.__bits[3]); - - ATF_REQUIRE(!memcmp(_sigignore, _sigignore, - sizeof(kp_sigignore))); - } - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - SYSCALL_REQUIRE( - ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - - DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); - DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 00:15:45 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_lwp_wait.h Log Message: Move LWP tests out of t_ptrace_wait.c to t_ptrace_lwp_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_lwp_wait.h cvs rdiff -u -r1.184 -r1.185 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.184 src/tests/lib/libc/sys/t_ptrace_wait.c:1.185 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.184 Tue May 5 00:03:49 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 00:15:45 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.184 2020/05/05 00:03:49 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.185 2020/05/05 00:15:45 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.184 2020/05/05 00:03:49 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.185 2020/05/05 00:15:45 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -927,618 +927,6 @@ TRACEE_SEES_ITS_ORIGINAL_PARENT( /// -static int lwpinfo_thread_sigmask[] = {SIGXCPU, SIGPIPE, SIGALRM, SIGURG}; - -static pthread_mutex_t lwpinfo_thread_mtx = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t lwpinfo_thread_cnd = PTHREAD_COND_INITIALIZER; -static volatile size_t lwpinfo_thread_done; - -static void * -lwpinfo_thread(void *arg) -{ - sigset_t s; - volatile void **tcb; - - tcb = (volatile void **)arg; - - *tcb = _lwp_getprivate(); - DPRINTF("Storing tcb[] = %p from thread %d\n", *tcb, _lwp_self()); - - pthread_setname_np(pthread_self(), "thread %d", - (void *)(intptr_t)_lwp_self()); - - sigemptyset(); - pthread_mutex_lock(_thread_mtx); - sigaddset(, lwpinfo_thread_sigmask[lwpinfo_thread_done]); - lwpinfo_thread_done++; - pthread_sigmask(SIG_BLOCK, , NULL); - pthread_cond_signal(_thread_cnd); - pthread_mutex_unlock(_thread_mtx); - - return infinite_thread(NULL); -} - -static void -traceme_lwpinfo(const size_t threads, const char *iter) -{ - const int sigval = SIGSTOP; - const int sigval2 = SIGINT; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - struct ptrace_lwpinfo lwp = {0, 0}; - struct ptrace_lwpstatus lwpstatus = {0}; - struct ptrace_siginfo info; - void *private; - char *name; - char namebuf[PL_LNAMELEN]; - volatile void *tcb[4]; - bool found; - sigset_t s; - - /* Maximum number of supported threads in this test */ - pthread_t t[__arraycount(tcb) - 1]; - size_t n, m; - int rv; - size_t bytes_read; - - struct ptrace_io_desc io; - sigset_t sigmask; - - ATF_REQUIRE(__arraycount(t) >= threads); - memset(tcb, 0, sizeof(tcb)); - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - tcb[0] = _lwp_getprivate(); - DPRINTF("Storing tcb[0] = %p\n", tcb[0]); - - pthread_setname_np(pthread_self(), "thread %d", - (void *)(intptr_t)_lwp_self()); - - sigemptyset(); - sigaddset(, lwpinfo_thread_sigmask[lwpinfo_thread_done]); - pthread_sigmask(SIG_BLOCK, , NULL); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - for (n = 0; n < threads; n++) { - rv = pthread_create([n], NULL, lwpinfo_thread, - [n + 1]); - FORKEE_ASSERT(rv == 0); - } - - pthread_mutex_lock(_thread_mtx); - while (lwpinfo_thread_done < threads) { - pthread_cond_wait(_thread_cnd, - _thread_mtx); - } - pthread_mutex_unlock(_thread_mtx); - - DPRINTF("Before raising %s from child\n", strsignal(sigval2)); - FORKEE_ASSERT(raise(sigval2) == 0); - - /* NOTREACHED */ - FORKEE_ASSERTX(0 && "Not reached"); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child"); - SYSCALL_REQUIRE( - ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - - DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); - DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 00:03:49 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Remove the duplicate ATF_TP_ADD_TC() entries Event mask tests are already defined in ATF_TP_ADD_TCS_PTRACE_WAIT_EVENTMASK(). To generate a diff of this commit: cvs rdiff -u -r1.183 -r1.184 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.183 src/tests/lib/libc/sys/t_ptrace_wait.c:1.184 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.183 Tue May 5 00:01:14 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 00:03:49 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.183 2020/05/05 00:01:14 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.184 2020/05/05 00:03:49 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.183 2020/05/05 00:01:14 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.184 2020/05/05 00:03:49 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -3172,14 +3172,6 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC_HAVE_PID(tp, tracee_sees_its_original_parent_procfs_status); - ATF_TP_ADD_TC(tp, eventmask_preserved_empty); - ATF_TP_ADD_TC(tp, eventmask_preserved_fork); - ATF_TP_ADD_TC(tp, eventmask_preserved_vfork); - ATF_TP_ADD_TC(tp, eventmask_preserved_vfork_done); - ATF_TP_ADD_TC(tp, eventmask_preserved_lwp_create); - ATF_TP_ADD_TC(tp, eventmask_preserved_lwp_exit); - ATF_TP_ADD_TC(tp, eventmask_preserved_posix_spawn); - ATF_TP_ADD_TC(tp, traceme_lwpinfo0); ATF_TP_ADD_TC(tp, traceme_lwpinfo1); ATF_TP_ADD_TC(tp, traceme_lwpinfo2);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue May 5 00:01:15 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_eventmask_wait.h Log Message: Move eventmask tests out of t_ptrace_wait.c to t_ptrace_eventmask_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_eventmask_wait.h cvs rdiff -u -r1.182 -r1.183 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.182 src/tests/lib/libc/sys/t_ptrace_wait.c:1.183 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.182 Mon May 4 23:53:20 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue May 5 00:01:14 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.182 2020/05/04 23:53:20 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.183 2020/05/05 00:01:14 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.182 2020/05/04 23:53:20 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.183 2020/05/05 00:01:14 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -927,83 +927,6 @@ TRACEE_SEES_ITS_ORIGINAL_PARENT( /// -static void -eventmask_preserved(int event) -{ - const int exitval = 5; - const int sigval = SIGSTOP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - ptrace_event_t set_event, get_event; - const int len = sizeof(ptrace_event_t); - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - set_event.pe_set_event = event; - SYSCALL_REQUIRE( - ptrace(PT_SET_EVENT_MASK, child, _event, len) != -1); - SYSCALL_REQUIRE( - ptrace(PT_GET_EVENT_MASK, child, _event, len) != -1); - DPRINTF("set_event=%#x get_event=%#x\n", set_event.pe_set_event, - get_event.pe_set_event); - ATF_REQUIRE(memcmp(_event, _event, len) == 0); - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_exited(status, exitval); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); -} - -#define EVENTMASK_PRESERVED(test, event)\ -ATF_TC(test);\ -ATF_TC_HEAD(test, tc) \ -{ \ - atf_tc_set_md_var(tc, "descr", \ - "Verify that eventmask " #event " is preserved"); \ -} \ - \ -ATF_TC_BODY(test, tc) \ -{ \ - \ - eventmask_preserved(event); \ -} - -EVENTMASK_PRESERVED(eventmask_preserved_empty, 0) -EVENTMASK_PRESERVED(eventmask_preserved_fork, PTRACE_FORK) -EVENTMASK_PRESERVED(eventmask_preserved_vfork, PTRACE_VFORK) -EVENTMASK_PRESERVED(eventmask_preserved_vfork_done, PTRACE_VFORK_DONE) -EVENTMASK_PRESERVED(eventmask_preserved_lwp_create, PTRACE_LWP_CREATE) -EVENTMASK_PRESERVED(eventmask_preserved_lwp_exit, PTRACE_LWP_EXIT) -EVENTMASK_PRESERVED(eventmask_preserved_posix_spawn, PTRACE_POSIX_SPAWN) - -/// - static int lwpinfo_thread_sigmask[] = {SIGXCPU, SIGPIPE, SIGALRM, SIGURG}; static pthread_mutex_t lwpinfo_thread_mtx = PTHREAD_MUTEX_INITIALIZER; @@ -3193,6 +3116,7 @@ THREAD_CONCURRENT_TEST(thread_concurrent #include "t_ptrace_clone_wait.h" #include "t_ptrace_fork_wait.h" #include "t_ptrace_signal_wait.h" +#include "t_ptrace_eventmask_wait.h" /// @@ -3362,6 +3286,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TCS_PTRACE_WAIT_CLONE(); ATF_TP_ADD_TCS_PTRACE_WAIT_FORK(); ATF_TP_ADD_TCS_PTRACE_WAIT_SIGNAL(); + ATF_TP_ADD_TCS_PTRACE_WAIT_EVENTMASK(); ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64(); ATF_TP_ADD_TCS_PTRACE_WAIT_I386(); Added files: Index:
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 4 23:53:20 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Remove the duplicate ATF_TP_ADD_TC() entries Byte transfer tests are already defined in ATF_TP_ADD_TCS_PTRACE_WAIT_BYTETRANSFER(). To generate a diff of this commit: cvs rdiff -u -r1.181 -r1.182 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.181 src/tests/lib/libc/sys/t_ptrace_wait.c:1.182 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.181 Mon May 4 23:49:31 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon May 4 23:53:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.181 2020/05/04 23:49:31 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.182 2020/05/04 23:53:20 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.181 2020/05/04 23:49:31 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.182 2020/05/04 23:53:20 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -3256,80 +3256,6 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, eventmask_preserved_lwp_exit); ATF_TP_ADD_TC(tp, eventmask_preserved_posix_spawn); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_8); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_16); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_32); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_64); - - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_8); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_16); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_32); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_64); - - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_8); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_16); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_32); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_64); - - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_8); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_16); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_32); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_64); - - ATF_TP_ADD_TC(tp, bytes_transfer_read_d); - ATF_TP_ADD_TC(tp, bytes_transfer_read_i); - ATF_TP_ADD_TC(tp, bytes_transfer_write_d); - ATF_TP_ADD_TC(tp, bytes_transfer_write_i); - - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_8_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_16_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_32_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_64_text); - - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_8_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_16_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_32_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_64_text); - - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_8_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_16_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_32_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_64_text); - - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_8_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_16_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_32_text); - ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_64_text); - - ATF_TP_ADD_TC(tp, bytes_transfer_read_d_text); - ATF_TP_ADD_TC(tp, bytes_transfer_read_i_text); - ATF_TP_ADD_TC(tp, bytes_transfer_write_d_text); - ATF_TP_ADD_TC(tp, bytes_transfer_write_i_text); - - ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_auxv); - - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_pt_read_i); - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_pt_read_d); - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_pt_write_i); - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_pt_write_d); - - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_piod_read_i); - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_piod_read_d); - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_piod_write_i); - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_piod_write_d); - - ATF_TP_ADD_TC(tp, bytes_transfer_alignment_piod_read_auxv); - - ATF_TP_ADD_TC(tp, bytes_transfer_eof_pt_read_i); - ATF_TP_ADD_TC(tp, bytes_transfer_eof_pt_read_d); - ATF_TP_ADD_TC(tp, bytes_transfer_eof_pt_write_i); - ATF_TP_ADD_TC(tp, bytes_transfer_eof_pt_write_d); - - ATF_TP_ADD_TC(tp, bytes_transfer_eof_piod_read_i); - ATF_TP_ADD_TC(tp, bytes_transfer_eof_piod_read_d); - ATF_TP_ADD_TC(tp, bytes_transfer_eof_piod_write_i); - ATF_TP_ADD_TC(tp, bytes_transfer_eof_piod_write_d); - ATF_TP_ADD_TC(tp, traceme_lwpinfo0); ATF_TP_ADD_TC(tp, traceme_lwpinfo1); ATF_TP_ADD_TC(tp, traceme_lwpinfo2);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 4 22:24:31 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_clone_wait.h Log Message: Bump (c) year To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_clone_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_clone_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_clone_wait.h:1.1 src/tests/lib/libc/sys/t_ptrace_clone_wait.h:1.2 --- src/tests/lib/libc/sys/t_ptrace_clone_wait.h:1.1 Mon May 4 22:15:23 2020 +++ src/tests/lib/libc/sys/t_ptrace_clone_wait.h Mon May 4 22:24:31 2020 @@ -1,7 +1,7 @@ -/* $NetBSD: t_ptrace_clone_wait.h,v 1.1 2020/05/04 22:15:23 kamil Exp $ */ +/* $NetBSD: t_ptrace_clone_wait.h,v 1.2 2020/05/04 22:24:31 kamil Exp $ */ /*- - * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. + * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 4 22:15:23 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_clone_wait.h Log Message: Move clone() tests out of t_ptrace_wait.c to t_ptrace_clone_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_clone_wait.h cvs rdiff -u -r1.178 -r1.179 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.178 src/tests/lib/libc/sys/t_ptrace_wait.c:1.179 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.178 Mon May 4 22:05:28 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon May 4 22:15:23 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.178 2020/05/04 22:05:28 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.179 2020/05/04 22:15:23 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.178 2020/05/04 22:05:28 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.179 2020/05/04 22:15:23 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -6159,742 +6159,6 @@ ATF_TC_BODY(resume, tc) /// static void -clone_body(int flags, bool trackfork, bool trackvfork, -bool trackvforkdone) -{ - const int exitval = 5; - const int exitval2 = 15; - const int sigval = SIGSTOP; - pid_t child, child2 = 0, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - ptrace_state_t state; - const int slen = sizeof(state); - ptrace_event_t event; - const int elen = sizeof(event); - - const size_t stack_size = 1024 * 1024; - void *stack, *stack_base; - - stack = malloc(stack_size); - ATF_REQUIRE(stack != NULL); - -#ifdef __MACHINE_STACK_GROWS_UP - stack_base = stack; -#else - stack_base = (char *)stack + stack_size; -#endif - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - SYSCALL_REQUIRE((child2 = __clone(clone_func, stack_base, - flags|SIGCHLD, (void *)(intptr_t)exitval2)) != -1); - - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), - child2); - - // XXX WALLSIG? - FORKEE_REQUIRE_SUCCESS - (wpid = TWAIT_GENERIC(child2, , WALLSIG), child2); - - forkee_status_exited(status, exitval2); - - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Set 0%s%s%s in EVENT_MASK for the child %d\n", - trackfork ? "|PTRACE_FORK" : "", - trackvfork ? "|PTRACE_VFORK" : "", - trackvforkdone ? "|PTRACE_VFORK_DONE" : "", child); - event.pe_set_event = 0; - if (trackfork) - event.pe_set_event |= PTRACE_FORK; - if (trackvfork) - event.pe_set_event |= PTRACE_VFORK; - if (trackvforkdone) - event.pe_set_event |= PTRACE_VFORK_DONE; - SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1); - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - -#if defined(TWAIT_HAVE_PID) - if ((trackfork && !(flags & CLONE_VFORK)) || - (trackvfork && (flags & CLONE_VFORK))) { - DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, - child); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), - child); - - validate_status_stopped(status, SIGTRAP); - - SYSCALL_REQUIRE( - ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1); - if (trackfork && !(flags & CLONE_VFORK)) { - ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK, - PTRACE_FORK); - } - if (trackvfork && (flags & CLONE_VFORK)) { - ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_VFORK, - PTRACE_VFORK); - } - - child2 = state.pe_other_pid; - DPRINTF("Reported ptrace event with forkee %d\n", child2); - - DPRINTF("Before calling %s() for the forkee %d of the child " - "%d\n", TWAIT_FNAME, child2, child); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, , 0), - child2); - - validate_status_stopped(status, SIGTRAP); - - SYSCALL_REQUIRE( - ptrace(PT_GET_PROCESS_STATE, child2, , slen) != -1); - if (trackfork
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 4 22:05:29 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_bytetransfer_wait.h Log Message: Move byte transfer tests out of t_ptrace_wait.c to t_ptrace_bytetransfer_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_bytetransfer_wait.h cvs rdiff -u -r1.177 -r1.178 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.177 src/tests/lib/libc/sys/t_ptrace_wait.c:1.178 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.177 Mon May 4 21:55:12 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon May 4 22:05:28 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.177 2020/05/04 21:55:12 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.178 2020/05/04 22:05:28 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.177 2020/05/04 21:55:12 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.178 2020/05/04 22:05:28 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -4194,826 +4194,6 @@ TRACEME_VFORK_FORK_TEST(traceme_vfork_vf /// -enum bytes_transfer_type { - BYTES_TRANSFER_DATA, - BYTES_TRANSFER_DATAIO, - BYTES_TRANSFER_TEXT, - BYTES_TRANSFER_TEXTIO, - BYTES_TRANSFER_AUXV -}; - -static int __used -bytes_transfer_dummy(int a, int b, int c, int d) -{ - int e, f, g, h; - - a *= 4; - b += 3; - c -= 2; - d /= 1; - - e = strtol("10", NULL, 10); - f = strtol("20", NULL, 10); - g = strtol("30", NULL, 10); - h = strtol("40", NULL, 10); - - return (a + b * c - d) + (e * f - g / h); -} - -static void -bytes_transfer(int operation, size_t size, enum bytes_transfer_type type) -{ - const int exitval = 5; - const int sigval = SIGSTOP; - pid_t child, wpid; - bool skip = false; - - int lookup_me = 0; - uint8_t lookup_me8 = 0; - uint16_t lookup_me16 = 0; - uint32_t lookup_me32 = 0; - uint64_t lookup_me64 = 0; - - int magic = 0x13579246; - uint8_t magic8 = 0xab; - uint16_t magic16 = 0x1234; - uint32_t magic32 = 0x98765432; - uint64_t magic64 = 0xabcdef0123456789; - - struct ptrace_io_desc io; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - /* 513 is just enough, for the purposes of ATF it's good enough */ - AuxInfo ai[513], *aip; - - ATF_REQUIRE(size < sizeof(ai)); - - /* Prepare variables for .TEXT transfers */ - switch (type) { - case BYTES_TRANSFER_TEXT: - memcpy(, bytes_transfer_dummy, sizeof(magic)); - break; - case BYTES_TRANSFER_TEXTIO: - switch (size) { - case 8: - memcpy(, bytes_transfer_dummy, sizeof(magic8)); - break; - case 16: - memcpy(, bytes_transfer_dummy, sizeof(magic16)); - break; - case 32: - memcpy(, bytes_transfer_dummy, sizeof(magic32)); - break; - case 64: - memcpy(, bytes_transfer_dummy, sizeof(magic64)); - break; - } - break; - default: - break; - } - - /* Prepare variables for PIOD and AUXV transfers */ - switch (type) { - case BYTES_TRANSFER_TEXTIO: - case BYTES_TRANSFER_DATAIO: - io.piod_op = operation; - switch (size) { - case 8: - io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ? - (void *)bytes_transfer_dummy : - _me8; - io.piod_addr = _me8; - io.piod_len = sizeof(lookup_me8); - break; - case 16: - io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ? - (void *)bytes_transfer_dummy : - _me16; - io.piod_addr = _me16; - io.piod_len = sizeof(lookup_me16); - break; - case 32: - io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ? - (void *)bytes_transfer_dummy : - _me32; - io.piod_addr = _me32; - io.piod_len = sizeof(lookup_me32); - break; - case 64: - io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ? - (void *)bytes_transfer_dummy : - _me64; - io.piod_addr = _me64; - io.piod_len = sizeof(lookup_me64); - break; - default: - break; - } - break; - case BYTES_TRANSFER_AUXV: - io.piod_op = operation; - io.piod_offs = 0; - io.piod_addr = ai; - io.piod_len = size; - break; - default: - break; - } - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - switch (type) { - case BYTES_TRANSFER_DATA: - switch (operation) { - case PT_READ_D: - case PT_READ_I: -lookup_me = magic; -break; - default: -break; - } -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 4 21:55:12 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_kill_wait.h Log Message: Move kill()-like tests out of t_ptrace_wait.c to t_ptrace_kill_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_kill_wait.h cvs rdiff -u -r1.176 -r1.177 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.176 src/tests/lib/libc/sys/t_ptrace_wait.c:1.177 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.176 Mon May 4 21:33:20 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon May 4 21:55:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.176 2020/05/04 21:33:20 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.177 2020/05/04 21:55:12 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.176 2020/05/04 21:33:20 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.177 2020/05/04 21:55:12 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -5014,75 +5014,6 @@ BYTES_TRANSFER_EOF(bytes_transfer_eof_pi /// -static void -ptrace_kill(const char *type) -{ - const int sigval = SIGSTOP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - /* NOTREACHED */ - FORKEE_ASSERTX(0 && - "Child should be terminated by a signal from its parent"); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Before killing the child process with %s\n", type); - if (strcmp(type, "ptrace(PT_KILL)") == 0) { - SYSCALL_REQUIRE(ptrace(PT_KILL, child, (void*)1, 0) != -1); - } else if (strcmp(type, "kill(SIGKILL)") == 0) { - kill(child, SIGKILL); - } else if (strcmp(type, "killpg(SIGKILL)") == 0) { - setpgid(child, 0); - killpg(getpgid(child), SIGKILL); - } - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_signaled(status, SIGKILL, 0); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); -} - -#define PTRACE_KILL(test, type) \ -ATF_TC(test);\ -ATF_TC_HEAD(test, tc) \ -{ \ -atf_tc_set_md_var(tc, "descr", \ -"Verify killing the child with " type); \ -} \ - \ -ATF_TC_BODY(test, tc) \ -{ \ - \ -ptrace_kill(type); \ -} - -// PT_CONTINUE with SIGKILL is covered by traceme_sendsignal_simple1 -PTRACE_KILL(kill1, "ptrace(PT_KILL)") -PTRACE_KILL(kill2, "kill(SIGKILL)") -PTRACE_KILL(kill3, "killpg(SIGKILL)") - -/// - static int lwpinfo_thread_sigmask[] = {SIGXCPU, SIGPIPE, SIGALRM, SIGURG}; static pthread_mutex_t lwpinfo_thread_mtx = PTHREAD_MUTEX_INITIALIZER; @@ -8458,6 +8389,7 @@ THREAD_CONCURRENT_TEST(thread_concurrent #include "t_ptrace_register_wait.h" #include "t_ptrace_syscall_wait.h" #include "t_ptrace_step_wait.h" +#include "t_ptrace_kill_wait.h" /// @@ -8865,10 +8797,6 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, bytes_transfer_eof_piod_write_i); ATF_TP_ADD_TC(tp, bytes_transfer_eof_piod_write_d); - ATF_TP_ADD_TC(tp, kill1); - ATF_TP_ADD_TC(tp, kill2); - ATF_TP_ADD_TC(tp, kill3); - ATF_TP_ADD_TC(tp, traceme_lwpinfo0); ATF_TP_ADD_TC(tp, traceme_lwpinfo1); ATF_TP_ADD_TC(tp, traceme_lwpinfo2); @@ -9055,6 +8983,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TCS_PTRACE_WAIT_REGISTER(); ATF_TP_ADD_TCS_PTRACE_WAIT_SYSCALL(); ATF_TP_ADD_TCS_PTRACE_WAIT_STEP(); + ATF_TP_ADD_TCS_PTRACE_WAIT_KILL(); ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64(); ATF_TP_ADD_TCS_PTRACE_WAIT_I386(); Added files: Index: src/tests/lib/libc/sys/t_ptrace_kill_wait.h diff -u /dev/null src/tests/lib/libc/sys/t_ptrace_kill_wait.h:1.1 --- /dev/null Mon May 4 21:55:12 2020
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 4 21:33:20 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_step_wait.h Log Message: Move PT_STEP tests out of t_ptrace_wait.c to t_ptrace_step_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_step_wait.h cvs rdiff -u -r1.175 -r1.176 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.175 src/tests/lib/libc/sys/t_ptrace_wait.c:1.176 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.175 Mon May 4 21:21:30 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon May 4 21:33:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.175 2020/05/04 21:21:30 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.176 2020/05/04 21:33:20 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.175 2020/05/04 21:21:30 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.176 2020/05/04 21:33:20 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -5014,226 +5014,6 @@ BYTES_TRANSFER_EOF(bytes_transfer_eof_pi /// -#if defined(PT_STEP) -static void -ptrace_step(int N, int setstep, bool masked, bool ignored) -{ - const int exitval = 5; - const int sigval = SIGSTOP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - int happy; - struct sigaction sa; - struct ptrace_siginfo info; - sigset_t intmask; - struct kinfo_proc2 kp; - size_t len = sizeof(kp); - - int name[6]; - const size_t namelen = __arraycount(name); - ki_sigset_t kp_sigmask; - ki_sigset_t kp_sigignore; - -#if defined(__arm__) - /* PT_STEP not supported on arm 32-bit */ - atf_tc_expect_fail("PR kern/52119"); -#endif - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - if (masked) { - sigemptyset(); - sigaddset(, SIGTRAP); - sigprocmask(SIG_BLOCK, , NULL); - } - - if (ignored) { - memset(, 0, sizeof(sa)); - sa.sa_handler = SIG_IGN; - sigemptyset(_mask); - FORKEE_ASSERT(sigaction(SIGTRAP, , NULL) != -1); - } - - happy = check_happy(999); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - FORKEE_ASSERT_EQ(happy, check_happy(999)); - - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - SYSCALL_REQUIRE( - ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - - DPRINTF("Before checking siginfo_t\n"); - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); - - name[0] = CTL_KERN, - name[1] = KERN_PROC2, - name[2] = KERN_PROC_PID; - name[3] = child; - name[4] = sizeof(kp); - name[5] = 1; - - FORKEE_ASSERT_EQ(sysctl(name, namelen, , , NULL, 0), 0); - - if (masked) - kp_sigmask = kp.p_sigmask; - - if (ignored) - kp_sigignore = kp.p_sigignore; - - while (N --> 0) { - if (setstep) { - DPRINTF("Before resuming the child process where it " - "left off and without signal to be sent (use " - "PT_SETSTEP and PT_CONTINUE)\n"); - SYSCALL_REQUIRE(ptrace(PT_SETSTEP, child, 0, 0) != -1); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) - != -1); - } else { - DPRINTF("Before resuming the child process where it " - "left off and without signal to be sent (use " - "PT_STEP)\n"); - SYSCALL_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) - != -1); - } - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), - child); - - validate_status_stopped(status, SIGTRAP); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - SYSCALL_REQUIRE( - ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - - DPRINTF("Before checking siginfo_t\n"); - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_TRACE); - - if (setstep) { - SYSCALL_REQUIRE(ptrace(PT_CLEARSTEP, child, 0, 0) != -1); - } - - ATF_REQUIRE_EQ(sysctl(name,
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 4 21:21:30 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_syscall_wait.h Log Message: Move syscall tests out of t_ptrace_wait.c to t_ptrace_syscall_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_syscall_wait.h cvs rdiff -u -r1.174 -r1.175 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.174 src/tests/lib/libc/sys/t_ptrace_wait.c:1.175 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.174 Mon May 4 20:55:48 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon May 4 21:21:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.174 2020/05/04 20:55:48 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.175 2020/05/04 21:21:30 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.174 2020/05/04 20:55:48 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.175 2020/05/04 21:21:30 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -7267,245 +7267,6 @@ ATF_TC_BODY(resume, tc) /// -static int test_syscall_caught; - -static void -syscall_sighand(int arg) -{ - - DPRINTF("Caught a signal %d in process %d\n", arg, getpid()); - - FORKEE_ASSERT_EQ(arg, SIGINFO); - - ++test_syscall_caught; - - FORKEE_ASSERT_EQ(test_syscall_caught, 1); -} - -static void -syscall_body(const char *op) -{ - const int exitval = 5; - const int sigval = SIGSTOP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - struct ptrace_siginfo info; - - memset(, 0, sizeof(info)); - -#if defined(TWAIT_HAVE_STATUS) - if (strstr(op, "signal") != NULL) { - atf_tc_expect_fail("XXX: behavior under investigation"); - } -#endif - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - signal(SIGINFO, syscall_sighand); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - syscall(SYS_getpid); - - if (strstr(op, "signal") != NULL) { - FORKEE_ASSERT_EQ(test_syscall_caught, 1); - } - - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, SIGTRAP); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - - DPRINTF("Before checking siginfo_t and lwpid\n"); - ATF_REQUIRE(info.psi_lwpid > 0); - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCE); - - if (strstr(op, "killed") != NULL) { - SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS( - wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_signaled(status, SIGKILL, 0); - } else { - if (strstr(op, "signal") != NULL) { - DPRINTF("Before resuming the child %d and sending a " - "signal SIGINFO\n", child); - SYSCALL_REQUIRE( - ptrace(PT_CONTINUE, child, (void *)1, SIGINFO) - != -1); - } else if (strstr(op, "detach") != NULL) { - DPRINTF("Before detaching the child %d\n", child); - SYSCALL_REQUIRE( - ptrace(PT_DETACH, child, (void *)1, 0) != -1); - } else { - DPRINTF("Before resuming the child process where it " - "left off and without signal to be sent\n"); - SYSCALL_REQUIRE( - ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); - - DPRINTF("Before calling %s() for the child\n", - TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS( - wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, SIGTRAP); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO " - "for child\n"); - SYSCALL_REQUIRE( -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon May 4 20:55:48 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Added Files: src/tests/lib/libc/sys: t_ptrace_register_wait.h Log Message: Move register tests out of t_ptrace_wait.c to t_ptrace_register_wait.h The same tests are now included with the preprocessor in t_ptrace_wait.c. No functional change intended. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_ptrace_register_wait.h cvs rdiff -u -r1.173 -r1.174 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.173 src/tests/lib/libc/sys/t_ptrace_wait.c:1.174 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.173 Fri Apr 24 12:17:45 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon May 4 20:55:48 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.173 2020/04/24 12:17:45 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.174 2020/05/04 20:55:48 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.173 2020/04/24 12:17:45 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.174 2020/05/04 20:55:48 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -5014,172 +5014,6 @@ BYTES_TRANSFER_EOF(bytes_transfer_eof_pi /// -#if defined(HAVE_GPREGS) || defined(HAVE_FPREGS) -static void -access_regs(const char *regset, const char *aux) -{ - const int exitval = 5; - const int sigval = SIGSTOP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif -#if defined(HAVE_GPREGS) - struct reg gpr; - register_t rgstr; -#endif -#if defined(HAVE_FPREGS) - struct fpreg fpr; -#endif - -#if !defined(HAVE_GPREGS) - if (strcmp(regset, "regs") == 0) - atf_tc_fail("Impossible test scenario!"); -#endif - -#if !defined(HAVE_FPREGS) - if (strcmp(regset, "fpregs") == 0) - atf_tc_fail("Impossible test scenario!"); -#endif - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - -#if defined(HAVE_GPREGS) - if (strcmp(regset, "regs") == 0) { - DPRINTF("Call GETREGS for the child process\n"); - SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, , 0) != -1); - - if (strcmp(aux, "none") == 0) { - DPRINTF("Retrieved registers\n"); - } else if (strcmp(aux, "pc") == 0) { - rgstr = PTRACE_REG_PC(); - DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr); - } else if (strstr(aux, "set_pc") != NULL) { - rgstr = PTRACE_REG_PC(); - DPRINTF("Retrieved PC %" PRIxREGISTER "\n", rgstr); - if (strstr(aux, "0x1") != NULL) { -rgstr |= 0x1; - } else if (strstr(aux, "0x3") != NULL) { -rgstr |= 0x3; - } else if (strstr(aux, "0x7") != NULL) { -rgstr |= 0x7; - } - DPRINTF("Set PC %" PRIxREGISTER "\n", rgstr); - PTRACE_REG_SET_PC(, rgstr); - if (strcmp(aux, "set_pc") != 0) { -/* This call can fail with EINVAL or similar. */ -ptrace(PT_SETREGS, child, , 0); - } - } else if (strcmp(aux, "sp") == 0) { - rgstr = PTRACE_REG_SP(); - DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr); - } else if (strcmp(aux, "intrv") == 0) { - rgstr = PTRACE_REG_INTRV(); - DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr); - } else if (strcmp(aux, "setregs") == 0) { - DPRINTF("Call SETREGS for the child process\n"); - SYSCALL_REQUIRE( - ptrace(PT_SETREGS, child, , 0) != -1); - } - } -#endif - -#if defined(HAVE_FPREGS) - if (strcmp(regset, "fpregs") == 0) { - DPRINTF("Call GETFPREGS for the child process\n"); - SYSCALL_REQUIRE(ptrace(PT_GETFPREGS, child, , 0) != -1); - - if (strcmp(aux, "getfpregs") == 0) { - DPRINTF("Retrieved FP registers\n"); - } else if (strcmp(aux, "setfpregs") == 0) { - DPRINTF("Call SETFPREGS for the child\n"); - SYSCALL_REQUIRE( - ptrace(PT_SETFPREGS, child, , 0) != -1); - } - } -#endif - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - if (strstr(aux, "unaligned") != NULL) { - DPRINTF("Before resuming the child process where it left off " - "and without
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: thorpej Date: Mon May 4 15:09:34 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_futex_ops.c Log Message: Add a test case for PR kern/55230. It is currently marked as expect-fail. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_futex_ops.c 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_futex_ops.c diff -u src/tests/lib/libc/sys/t_futex_ops.c:1.3 src/tests/lib/libc/sys/t_futex_ops.c:1.4 --- src/tests/lib/libc/sys/t_futex_ops.c:1.3 Thu Apr 30 04:18:07 2020 +++ src/tests/lib/libc/sys/t_futex_ops.c Mon May 4 15:09:34 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_futex_ops.c,v 1.3 2020/04/30 04:18:07 thorpej Exp $ */ +/* $NetBSD: t_futex_ops.c,v 1.4 2020/05/04 15:09:34 thorpej Exp $ */ /*- * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2019, 2020\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_futex_ops.c,v 1.3 2020/04/30 04:18:07 thorpej Exp $"); +__RCSID("$NetBSD: t_futex_ops.c,v 1.4 2020/05/04 15:09:34 thorpej Exp $"); #include #include @@ -42,6 +42,7 @@ __RCSID("$NetBSD: t_futex_ops.c,v 1.3 20 #include #include #include +#include #include #include @@ -1334,6 +1335,152 @@ ATF_TC_CLEANUP(futex_wait_evil_unmapped_ /*/ +static int pri_min; +static int pri_max; + +static void +lowpri_simple_test_waiter_lwp(void *arg) +{ + struct lwp_data *d = arg; + struct sched_param sp; + int policy; + + d->threadid = _lwp_self(); + + ATF_REQUIRE(_sched_getparam(getpid(), d->threadid, , ) == 0); + policy = SCHED_RR; + sp.sched_priority = pri_min; + ATF_REQUIRE(_sched_setparam(getpid(), d->threadid, policy, ) == 0); + + simple_test_waiter_lwp(arg); +} + +static void +highpri_simple_test_waiter_lwp(void *arg) +{ + struct lwp_data *d = arg; + struct sched_param sp; + int policy; + + d->threadid = _lwp_self(); + + ATF_REQUIRE(_sched_getparam(getpid(), d->threadid, , ) == 0); + policy = SCHED_RR; + sp.sched_priority = pri_max; + ATF_REQUIRE(_sched_setparam(getpid(), d->threadid, policy, ) == 0); + + simple_test_waiter_lwp(arg); +} + +static void +do_test_wake_highest_pri(void) +{ + lwpid_t waiter; + int tries; + long pri; + + ATF_REQUIRE((pri = sysconf(_SC_SCHED_PRI_MIN)) != -1); + pri_min = (int)pri; + ATF_REQUIRE((pri = sysconf(_SC_SCHED_PRI_MAX)) != -1); + pri_max = (int)pri; + + futex_word = 0; + membar_sync(); + + setup_lwp_context(_data[0], lowpri_simple_test_waiter_lwp); + lwp_data[0].op_flags = FUTEX_PRIVATE_FLAG; + lwp_data[0].futex_error = -1; + lwp_data[0].futex_ptr = _word; + lwp_data[0].block_val = 0; + lwp_data[0].bitset = 0; + lwp_data[0].wait_op = FUTEX_WAIT; + ATF_REQUIRE(_lwp_create(_data[0].context, 0, +_data[0].lwpid) == 0); + + for (tries = 0; tries < 5; tries++) { + membar_sync(); + if (nlwps_running == 1) + break; + sleep(1); + } + membar_sync(); + ATF_REQUIRE_EQ_MSG(nlwps_running, 1, "lowpri waiter failed to start"); + + /* Ensure it's blocked. */ + ATF_REQUIRE(lwp_data[0].futex_error == -1); + + setup_lwp_context(_data[1], highpri_simple_test_waiter_lwp); + lwp_data[1].op_flags = FUTEX_PRIVATE_FLAG; + lwp_data[1].futex_error = -1; + lwp_data[1].futex_ptr = _word; + lwp_data[1].block_val = 0; + lwp_data[1].bitset = 0; + lwp_data[1].wait_op = FUTEX_WAIT; + ATF_REQUIRE(_lwp_create(_data[0].context, 0, +_data[0].lwpid) == 0); + + for (tries = 0; tries < 5; tries++) { + membar_sync(); + if (nlwps_running == 2) + break; + sleep(1); + } + membar_sync(); + ATF_REQUIRE_EQ_MSG(nlwps_running, 2, "highpri waiter failed to start"); + + /* Ensure it's blocked. */ + ATF_REQUIRE(lwp_data[1].futex_error == -1); + + /* Wake the first LWP. We should get the highpri thread. */ + ATF_REQUIRE(__futex(_word, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, + 1, NULL, NULL, 0, 0) == 1); + sleep(1); + for (tries = 0; tries < 5; tries++) { + membar_sync(); + if (nlwps_running == 1) + break; + sleep(1); + } + membar_sync(); + ATF_REQUIRE(nlwps_running == 1); + ATF_REQUIRE(_lwp_wait(0, ) == 0); + ATF_REQUIRE(waiter == lwp_data[1].threadid); + + /* Wake the second LWP. We should get the lowpri thread. */ + ATF_REQUIRE(__futex(_word, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, + 1, NULL, NULL, 0, 0) == 1); + sleep(1); + for (tries = 0; tries < 5; tries++) { + membar_sync(); + if (nlwps_running == 0) + break; + sleep(1); + } + membar_sync(); + ATF_REQUIRE(nlwps_running == 0); + ATF_REQUIRE(_lwp_wait(0, ) == 0); + ATF_REQUIRE(waiter == lwp_data[0].threadid); +} + +ATF_TC_WITH_CLEANUP(futex_wake_highest_pri); +ATF_TC_HEAD(futex_wake_highest_pri, tc) +{ + atf_tc_set_md_var(tc, "descr", + "tests that futex WAKE wakes the highest priority waiter"); + atf_tc_set_md_var(tc, "require.user", "root"); +}
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Fri May 1 21:35:30 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_sigaltstack.c Log Message: no need for alloca() (breaks SSP) To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_sigaltstack.c 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_sigaltstack.c diff -u src/tests/lib/libc/sys/t_sigaltstack.c:1.1 src/tests/lib/libc/sys/t_sigaltstack.c:1.2 --- src/tests/lib/libc/sys/t_sigaltstack.c:1.1 Thu Apr 30 07:03:29 2020 +++ src/tests/lib/libc/sys/t_sigaltstack.c Fri May 1 17:35:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_sigaltstack.c,v 1.1 2020/04/30 11:03:29 ryo Exp $ */ +/* $NetBSD: t_sigaltstack.c,v 1.2 2020/05/01 21:35:30 christos Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_sigaltstack.c,v 1.1 2020/04/30 11:03:29 ryo Exp $"); +__RCSID("$NetBSD: t_sigaltstack.c,v 1.2 2020/05/01 21:35:30 christos Exp $"); #include #include @@ -43,7 +43,7 @@ static bool handler_use_altstack; static void handler(int signo __unused) { - char *sp = alloca(128); + char sp[128]; handler_called = true;
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: thorpej Date: Fri May 1 01:44:30 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_futex_robust.c Log Message: Oops, accidentally #if 0'd some tests, probably while debugging something else. Correct this silly mistake. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_futex_robust.c 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_futex_robust.c diff -u src/tests/lib/libc/sys/t_futex_robust.c:1.1 src/tests/lib/libc/sys/t_futex_robust.c:1.2 --- src/tests/lib/libc/sys/t_futex_robust.c:1.1 Sun Apr 26 18:53:33 2020 +++ src/tests/lib/libc/sys/t_futex_robust.c Fri May 1 01:44:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_futex_robust.c,v 1.1 2020/04/26 18:53:33 thorpej Exp $ */ +/* $NetBSD: t_futex_robust.c,v 1.2 2020/05/01 01:44:30 thorpej Exp $ */ /*- * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2019\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_futex_robust.c,v 1.1 2020/04/26 18:53:33 thorpej Exp $"); +__RCSID("$NetBSD: t_futex_robust.c,v 1.2 2020/05/01 01:44:30 thorpej Exp $"); #include #include @@ -396,12 +396,10 @@ ATF_TC_CLEANUP(futex_robust_bad_pending, ATF_TP_ADD_TCS(tp) { -#if 0 ATF_TP_ADD_TC(tp, futex_robust_positive); ATF_TP_ADD_TC(tp, futex_robust_negative); ATF_TP_ADD_TC(tp, futex_robust_unmapped); ATF_TP_ADD_TC(tp, futex_robust_evil_circular); -#endif ATF_TP_ADD_TC(tp, futex_robust_bad_pending); return atf_no_error();
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Fri Apr 24 12:17:45 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Reduce assumptions about LWP numbers To generate a diff of this commit: cvs rdiff -u -r1.172 -r1.173 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.172 src/tests/lib/libc/sys/t_ptrace_wait.c:1.173 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.172 Fri Apr 24 03:25:20 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Fri Apr 24 12:17:45 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.172 2020/04/24 03:25:20 thorpej Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.173 2020/04/24 12:17:45 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.172 2020/04/24 03:25:20 thorpej Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.173 2020/04/24 12:17:45 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -7506,11 +7506,8 @@ syscall_body(const char *op) DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - /* - * N.B. 9.99.59 and later - single-LWP processes lwpid==pid. - */ DPRINTF("Before checking siginfo_t and lwpid\n"); - ATF_REQUIRE(info.psi_lwpid == 1 || info.psi_lwpid == child); + ATF_REQUIRE(info.psi_lwpid > 0); ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCE); @@ -7552,13 +7549,8 @@ syscall_body(const char *op) ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - /* - * N.B. 9.99.59 and later - single-LWP processes - * lwpid==pid. - */ DPRINTF("Before checking siginfo_t and lwpid\n"); - ATF_REQUIRE(info.psi_lwpid == 1 || -info.psi_lwpid == child); + ATF_REQUIRE(info.psi_lwpid > 0); ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCX); @@ -8678,10 +8670,7 @@ ATF_TC_BODY(core_dump_procinfo, tc) ATF_CHECK_EQ(procinfo.cpi_rgid, getgid()); ATF_CHECK_EQ(procinfo.cpi_egid, getegid()); ATF_CHECK_EQ(procinfo.cpi_nlwps, 1); - /* - * N.B. 9.99.59 and later - single-LWP processes lwpid==pid. - */ - ATF_CHECK(procinfo.cpi_siglwp == 1 || procinfo.cpi_siglwp == child); + ATF_CHECK(procinfo.cpi_siglwp > 0); unlink(core_path);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: thorpej Date: Fri Apr 24 03:25:20 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_x86_wait.h Log Message: Update for new LWP behavior -- as of 9.99.59, the LWP ID of a single-LWP process is the PID, not 1. To generate a diff of this commit: cvs rdiff -u -r1.171 -r1.172 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.24 -r1.25 src/tests/lib/libc/sys/t_ptrace_x86_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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.171 src/tests/lib/libc/sys/t_ptrace_wait.c:1.172 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.171 Fri Apr 17 22:53:52 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Fri Apr 24 03:25:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.171 2020/04/17 22:53:52 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.172 2020/04/24 03:25:20 thorpej Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.171 2020/04/17 22:53:52 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.172 2020/04/24 03:25:20 thorpej Exp $"); #define __LEGACY_PT_LWPINFO @@ -7506,8 +7506,11 @@ syscall_body(const char *op) DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); + /* + * N.B. 9.99.59 and later - single-LWP processes lwpid==pid. + */ DPRINTF("Before checking siginfo_t and lwpid\n"); - ATF_REQUIRE_EQ(info.psi_lwpid, 1); + ATF_REQUIRE(info.psi_lwpid == 1 || info.psi_lwpid == child); ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCE); @@ -7549,8 +7552,13 @@ syscall_body(const char *op) ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); + /* + * N.B. 9.99.59 and later - single-LWP processes + * lwpid==pid. + */ DPRINTF("Before checking siginfo_t and lwpid\n"); - ATF_REQUIRE_EQ(info.psi_lwpid, 1); + ATF_REQUIRE(info.psi_lwpid == 1 || +info.psi_lwpid == child); ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCX); @@ -8502,6 +8510,13 @@ USER_VA0_DISABLE(user_va0_disable_pt_det * buf_len. The actual length of the note is returned (which can be greater * than buf_len, indicating that it has been truncated). If the note is not * found, -1 is returned. + * + * If the note_name ends in '*', then we find the first note that matches + * the note_name prefix up to the '*' character, e.g.: + * + * NetBSD-CORE@* + * + * finds the first note whose name prefix matches "NetBSD-CORE@". */ static ssize_t core_find_note(const char *core_path, const char *note_name, uint64_t note_type, void *buf, size_t buf_len) @@ -8510,8 +8525,16 @@ static ssize_t core_find_note(const char Elf *core_elf; size_t core_numhdr, i; ssize_t ret = -1; - /* note: we assume note name will be null-terminated */ - size_t name_len = strlen(note_name) + 1; + size_t name_len = strlen(note_name); + bool prefix_match = false; + + if (note_name[name_len - 1] == '*') { + prefix_match = true; + name_len--; + } else { + /* note: we assume note name will be null-terminated */ + name_len++; + } SYSCALL_REQUIRE((core_fd = open(core_path, O_RDONLY)) != -1); SYSCALL_REQUIRE(elf_version(EV_CURRENT) != EV_NONE); @@ -8554,7 +8577,10 @@ static ssize_t core_find_note(const char /* indicates end of notes */ if (note_hdr.n_namesz == 0 || note_hdr.n_descsz == 0) break; - if (note_hdr.n_namesz == name_len && + if (((prefix_match && + note_hdr.n_namesz > name_len) || + (!prefix_match && + note_hdr.n_namesz == name_len)) && note_hdr.n_namesz <= sizeof(name_buf)) { SYSCALL_REQUIRE(pread(core_fd, name_buf, note_hdr.n_namesz, offset) @@ -8652,7 +8678,10 @@ ATF_TC_BODY(core_dump_procinfo, tc) ATF_CHECK_EQ(procinfo.cpi_rgid, getgid()); ATF_CHECK_EQ(procinfo.cpi_egid, getegid()); ATF_CHECK_EQ(procinfo.cpi_nlwps, 1); - ATF_CHECK_EQ(procinfo.cpi_siglwp, 1); + /* + * N.B. 9.99.59 and later - single-LWP processes lwpid==pid. + */ + ATF_CHECK(procinfo.cpi_siglwp == 1 || procinfo.cpi_siglwp == child); unlink(core_path); Index: src/tests/lib/libc/sys/t_ptrace_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.24 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.25 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.24 Thu Feb 20 23:57:16 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Fri Apr 24 03:25:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.24 2020/02/20 23:57:16 kamil Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.25 2020/04/24 03:25:20 thorpej Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: thorpej Date: Wed Apr 22 21:28:03 UTC 2020 Removed Files: src/tests/lib/libc/sys: t_lwp_tid.c Log Message: Remove unit tests for the never-exposed _lwp_gettid(2). To generate a diff of this commit: cvs rdiff -u -r1.1 -r0 src/tests/lib/libc/sys/t_lwp_tid.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Sat Apr 18 17:45:16 UTC 2020 Added Files: src/tests/lib/libc/sys: t_mprotect_helper.h Log Message: Oops, need the header too. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_mprotect_helper.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Added files: Index: src/tests/lib/libc/sys/t_mprotect_helper.h diff -u /dev/null src/tests/lib/libc/sys/t_mprotect_helper.h:1.1 --- /dev/null Sat Apr 18 13:45:16 2020 +++ src/tests/lib/libc/sys/t_mprotect_helper.h Sat Apr 18 13:45:16 2020 @@ -0,0 +1,3 @@ +int return_1(void); +int return_2(void); +int return_3(void);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Sat Apr 18 17:44:53 UTC 2020 Modified Files: src/tests/lib/libc/sys: Makefile t_mprotect.c Added Files: src/tests/lib/libc/sys: t_mprotect_helper.c Log Message: PR/55177: Carlo Arenas: mremap(MAP_REMAPDUP) fails after fork() To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/tests/lib/libc/sys/Makefile cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_mprotect.c cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_mprotect_helper.c 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/Makefile diff -u src/tests/lib/libc/sys/Makefile:1.61 src/tests/lib/libc/sys/Makefile:1.62 --- src/tests/lib/libc/sys/Makefile:1.61 Fri Mar 6 13:32:35 2020 +++ src/tests/lib/libc/sys/Makefile Sat Apr 18 13:44:53 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.61 2020/03/06 18:32:35 kamil Exp $ +# $NetBSD: Makefile,v 1.62 2020/04/18 17:44:53 christos Exp $ MKMAN= no @@ -85,7 +85,7 @@ TESTS_C+= t_wait_noproc TESTS_C+= t_wait_noproc_wnohang TESTS_C+= t_write -SRCS.t_mprotect= t_mprotect.c ${SRCS_EXEC_PROT} +SRCS.t_mprotect= t_mprotect.c ${SRCS_EXEC_PROT} t_mprotect_helper.c LDADD.t_getpid+=-lpthread Index: src/tests/lib/libc/sys/t_mprotect.c diff -u src/tests/lib/libc/sys/t_mprotect.c:1.8 src/tests/lib/libc/sys/t_mprotect.c:1.9 --- src/tests/lib/libc/sys/t_mprotect.c:1.8 Tue Jul 16 13:29:18 2019 +++ src/tests/lib/libc/sys/t_mprotect.c Sat Apr 18 13:44:53 2020 @@ -1,7 +1,7 @@ -/* $NetBSD: t_mprotect.c,v 1.8 2019/07/16 17:29:18 martin Exp $ */ +/* $NetBSD: t_mprotect.c,v 1.9 2020/04/18 17:44:53 christos Exp $ */ /*- - * Copyright (c) 2011 The NetBSD Foundation, Inc. + * Copyright (c) 2011, 2020 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_mprotect.c,v 1.8 2019/07/16 17:29:18 martin Exp $"); +__RCSID("$NetBSD: t_mprotect.c,v 1.9 2020/04/18 17:44:53 christos Exp $"); #include #include @@ -45,6 +45,7 @@ __RCSID("$NetBSD: t_mprotect.c,v 1.8 201 #include #include "../common/exec_prot.h" +#include "t_mprotect_helper.h" static long page = 0; static char path[] = "mmap"; @@ -243,8 +244,8 @@ ATF_TC_BODY(mprotect_pax, tc) * (3) making a non-executable mapping executable * * (4) making an executable/read-only file mapping - * writable except for performing relocations - * on an ET_DYN ELF file (non-PIC shared library) + * writable except for performing relocations + * on an ET_DYN ELF file (non-PIC shared library) * * The following will test only the case (3). * @@ -383,6 +384,60 @@ ATF_TC_BODY(mprotect_mremap_exec, tc) ATF_REQUIRE(munmap(map2, page) == 0); } +ATF_TC(mprotect_mremap_fork_exec); +ATF_TC_HEAD(mprotect_mremap_fork_exec, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test mremap(2)+fork(2)+mprotect(2) executable space protections"); +} + +ATF_TC_BODY(mprotect_mremap_fork_exec, tc) +{ + void *map, *map2; + pid_t pid; + + atf_tc_expect_fail("PR lib/55177"); + + /* + * Map a page read/write/exec and duplicate it. + * Map the copy executable. + * Copy a function to the writeable mapping and execute it + * Fork a child and wait for it + * Copy a different function to the writeable mapping and execute it + * The original function shouldn't be called + */ + + map = mmap(NULL, page, PROT_READ|PROT_WRITE|PROT_MPROTECT(PROT_EXEC), + MAP_ANON, -1, 0); + ATF_REQUIRE(map != MAP_FAILED); + map2 = mremap(map, page, NULL, page, MAP_REMAPDUP); + ATF_REQUIRE(map2 != MAP_FAILED); + ATF_REQUIRE(mprotect(map2, page, PROT_EXEC|PROT_READ) == 0); + + memcpy(map, (void *)return_1, + (uintptr_t)return_2 - (uintptr_t)return_1); + __builtin___clear_cache(map, (void *)((uintptr_t)map + page)); + + ATF_REQUIRE(((int (*)(void))map2)() == 1); + + pid = fork(); + ATF_REQUIRE(pid >= 0); + + if (pid == 0) + _exit(0); + + (void)wait(NULL); + + memcpy(map, (void *)return_2, + (uintptr_t)return_3 - (uintptr_t)return_2); + __builtin___clear_cache(map, (void *)((uintptr_t)map + page)); + + ATF_REQUIRE(((int (*)(void))map2)() == 2); + + ATF_REQUIRE(munmap(map, page) == 0); + ATF_REQUIRE(munmap(map2, page) == 0); +} + ATF_TP_ADD_TCS(tp) { page = sysconf(_SC_PAGESIZE); @@ -394,6 +449,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, mprotect_pax); ATF_TP_ADD_TC(tp, mprotect_write); ATF_TP_ADD_TC(tp, mprotect_mremap_exec); + ATF_TP_ADD_TC(tp, mprotect_mremap_fork_exec); return atf_no_error(); } Added files: Index: src/tests/lib/libc/sys/t_mprotect_helper.c diff -u /dev/null src/tests/lib/libc/sys/t_mprotect_helper.c:1.1 --- /dev/null Sat Apr 18 13:44:53 2020 +++ src/tests/lib/libc/sys/t_mprotect_helper.c Sat Apr 18 13:44:53 2020 @@ -0,0 +1,17 @@ +#include "t_mprotect_helper.h" + +int
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Fri Apr 17 22:53:52 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Switch from C11 specific static_assert() to __CTASSERT() To generate a diff of this commit: cvs rdiff -u -r1.170 -r1.171 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.170 src/tests/lib/libc/sys/t_ptrace_wait.c:1.171 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.170 Tue Apr 14 22:37:24 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Fri Apr 17 22:53:52 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.170 2020/04/14 22:37:24 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.171 2020/04/17 22:53:52 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.170 2020/04/14 22:37:24 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.171 2020/04/17 22:53:52 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -74,18 +74,14 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.17 #ifdef ENABLE_TESTS /* Assumptions in the kernel code that must be kept. */ -static_assert(sizeof(((struct ptrace_state *)0)->pe_report_event) == -sizeof(((siginfo_t *)0)->si_pe_report_event), -"pe_report_event and si_pe_report_event must be of the same size"); -static_assert(sizeof(((struct ptrace_state *)0)->pe_other_pid) == -sizeof(((siginfo_t *)0)->si_pe_other_pid), -"pe_other_pid and si_pe_other_pid must be of the same size"); -static_assert(sizeof(((struct ptrace_state *)0)->pe_lwp) == -sizeof(((siginfo_t *)0)->si_pe_lwp), -"pe_lwp and si_pe_lwp must be of the same size"); -static_assert(sizeof(((struct ptrace_state *)0)->pe_other_pid) == -sizeof(((struct ptrace_state *)0)->pe_lwp), -"pe_other_pid and pe_lwp must be of the same size"); +__CTASSERT(sizeof(((struct ptrace_state *)0)->pe_report_event) == +sizeof(((siginfo_t *)0)->si_pe_report_event)); +__CTASSERT(sizeof(((struct ptrace_state *)0)->pe_other_pid) == +sizeof(((siginfo_t *)0)->si_pe_other_pid)); +__CTASSERT(sizeof(((struct ptrace_state *)0)->pe_lwp) == +sizeof(((siginfo_t *)0)->si_pe_lwp)); +__CTASSERT(sizeof(((struct ptrace_state *)0)->pe_other_pid) == +sizeof(((struct ptrace_state *)0)->pe_lwp)); #include "h_macros.h"
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue Apr 14 22:37:25 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Add timeout to syscall_signal_on_sce that hangs from time to time To generate a diff of this commit: cvs rdiff -u -r1.169 -r1.170 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.169 src/tests/lib/libc/sys/t_ptrace_wait.c:1.170 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.169 Sat Mar 7 14:53:14 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue Apr 14 22:37:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.169 2020/03/07 14:53:14 christos Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.170 2020/04/14 22:37:24 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.169 2020/03/07 14:53:14 christos Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.170 2020/04/14 22:37:24 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -7579,6 +7579,7 @@ syscall_body(const char *op) ATF_TC(name);\ ATF_TC_HEAD(name, tc) \ { \ + atf_tc_set_md_var(tc, "timeout", "15");\ atf_tc_set_md_var(tc, "descr", \ "Verify that getpid(2) can be traced with PT_SYSCALL %s", \ #op ); \
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: martin Date: Sun Mar 8 15:07:44 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: Only inlcude fenv.h if __HAVE_FENV To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 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.26 src/tests/lib/libc/sys/t_ptrace_wait.h:1.27 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.26 Sat Mar 7 19:47:44 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Sun Mar 8 15:07:44 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.26 2020/03/07 19:47:44 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.27 2020/03/08 15:07:44 martin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -654,7 +654,9 @@ trigger_ill(void) #endif } +#ifdef __HAVE_FENV #include +#endif #if (__arm__ && !__SOFTFP__) || __aarch64__ #include /* only need for ARM Cortex/Neon hack */
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Sat Mar 7 19:47:44 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: Fix typo To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 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.25 src/tests/lib/libc/sys/t_ptrace_wait.h:1.26 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.25 Sat Mar 7 14:53:14 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Sat Mar 7 19:47:44 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.25 2020/03/07 14:53:14 christos Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.26 2020/03/07 19:47:44 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -672,7 +672,7 @@ are_fpu_exceptions_supported(void) return true; } #else -#define are_fpu_exceptions_supporter() 1 +#define are_fpu_exceptions_supported() 1 #endif static void __used
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Sat Mar 7 14:53:14 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h Log Message: Try to fix the build. This is why all those inlines should really be in a separate file as regular function. The code is too large and hard to manage this way, and only increases in complexity as time goes by. To generate a diff of this commit: cvs rdiff -u -r1.168 -r1.169 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.24 -r1.25 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.168 src/tests/lib/libc/sys/t_ptrace_wait.c:1.169 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.168 Fri Mar 6 09:06:56 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Sat Mar 7 09:53:14 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.168 2020/03/06 14:06:56 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.169 2020/03/07 14:53:14 christos Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.168 2020/03/06 14:06:56 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.169 2020/03/07 14:53:14 christos Exp $"); #define __LEGACY_PT_LWPINFO @@ -60,11 +60,6 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.16 #include #include -#include -#if (__arm__ && !__SOFTFP__) || __aarch64__ -#include /* only need for ARM Cortex/Neon hack */ -#endif - #if defined(__i386__) || defined(__x86_64__) #include #include Index: src/tests/lib/libc/sys/t_ptrace_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.24 src/tests/lib/libc/sys/t_ptrace_wait.h:1.25 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.24 Fri Mar 6 12:03:35 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Sat Mar 7 09:53:14 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.24 2020/03/06 17:03:35 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.25 2020/03/07 14:53:14 christos Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -654,10 +654,14 @@ trigger_ill(void) #endif } +#include + +#if (__arm__ && !__SOFTFP__) || __aarch64__ +#include /* only need for ARM Cortex/Neon hack */ + static bool __used are_fpu_exceptions_supported(void) { -#if (__arm__ && !__SOFTFP__) || __aarch64__ /* * Some NEON fpus do not trap on IEEE 754 FP exceptions. * Skip these tests if running on them and compiled for @@ -665,9 +669,11 @@ are_fpu_exceptions_supported(void) */ if (0 == fpsetmask(fpsetmask(FP_X_INV))) return false; -#endif return true; } +#else +#define are_fpu_exceptions_supporter() 1 +#endif static void __used trigger_fpe(void)
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Fri Mar 6 19:10:27 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_sigchld.c Log Message: Remove duplicated lines To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_sigchld.c 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_sigchld.c diff -u src/tests/lib/libc/sys/t_ptrace_sigchld.c:1.1 src/tests/lib/libc/sys/t_ptrace_sigchld.c:1.2 --- src/tests/lib/libc/sys/t_ptrace_sigchld.c:1.1 Fri Mar 6 18:32:35 2020 +++ src/tests/lib/libc/sys/t_ptrace_sigchld.c Fri Mar 6 19:10:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_sigchld.c,v 1.1 2020/03/06 18:32:35 kamil Exp $ */ +/* $NetBSD: t_ptrace_sigchld.c,v 1.2 2020/03/06 19:10:27 kamil Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -27,258 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_sigchld.c,v 1.1 2020/03/06 18:32:35 kamil Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "h_macros.h" -#include "msg.h" - -#include "t_ptrace_wait.h" - -#define SYSCALL_REQUIRE(expr) ATF_REQUIRE_MSG(expr, "%s: %s", # expr, \ -strerror(errno)) -#define SYSCALL_REQUIRE_ERRNO(res, exp) ATF_REQUIRE_MSG(res == exp, \ -"%d(%s) != %d", res, strerror(res), exp) - -static int debug = 0; - -#define DPRINTF(a, ...) do \ - if (debug) \ - printf("%s() %d.%d %s:%d " a, \ - __func__, getpid(), _lwp_self(), __FILE__, __LINE__, ##__VA_ARGS__); \ -while (/*CONSTCOND*/0) - -/// - -static int expected_signo; -static int expected_code; -static int expected_status; -static pid_t expected_pid; - -static void -sigchld_action(int sig, siginfo_t *info, void *ctx) -{ - - FORKEE_ASSERT_EQ(info->si_signo, expected_signo); - FORKEE_ASSERT_EQ(info->si_code, expected_code); - FORKEE_ASSERT_EQ(info->si_uid, getuid()); - FORKEE_ASSERT_EQ(info->si_pid, expected_pid); - - if (WIFEXITED(info->si_status)) - ATF_REQUIRE_EQ(WEXITSTATUS(info->si_status), expected_status); - else if (WIFSTOPPED(info->si_status)) - ATF_REQUIRE_EQ(WSTOPSIG(info->si_status), expected_status); - else if (WIFSIGNALED(info->si_status)) - ATF_REQUIRE_EQ(WTERMSIG(info->si_status), expected_status); -/* - else if (WIFCONTINUED(info->si_status)) - ; -*/ -} - -static void -traceme_raise(int sigval) -{ - const int exitval = 5; - struct sigaction sa; - pid_t child; - struct msg_fds parent_child; - uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ - - struct ptrace_siginfo info; - memset(, 0, sizeof(info)); - - memset(, 0, sizeof(sa)); - sa.sa_sigaction = sigchld_action; - sa.sa_flags = SA_SIGINFO | SA_NOCLDWAIT; - sigemptyset(_mask); - - atf_tc_fail("XXX: zombie is not collected before tracer's death"); - - SYSCALL_REQUIRE(sigaction(SIGCHLD, , NULL) == 0); - - SYSCALL_REQUIRE(msg_open(_child) == 0); - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - CHILD_FROM_PARENT("raise1 child", parent_child, msg); - - raise(sigval); - - CHILD_TO_PARENT("raise2 child", parent_child, msg); - - switch (sigval) { - case SIGKILL: - /* NOTREACHED */ - FORKEE_ASSERTX(0 && "This shall not be reached"); - __unreachable(); - default: - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); - } - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - expected_signo = SIGCHLD; - expected_pid = child; - switch (sigval) { - case SIGKILL: - expected_code = CLD_KILLED; - expected_status = SIGKILL; - break; - case SIGSTOP: - expected_code = CLD_STOPPED; - expected_status = SIGSTOP; - break; - default: - break; - } - - PARENT_TO_CHILD("raise1 child", parent_child, msg); - - switch (sigval) { - case SIGKILL: - break; - default: - PARENT_FROM_CHILD("raise2 child", parent_child, msg); - - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for " - "child\n"); - SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , - sizeof(info)) != -1); - - DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); - DPRINTF("Signal properties: si_signo=%#x si_code=%#x " - "si_errno=%#x\n", - info.psi_siginfo.si_signo, info.psi_siginfo.si_code, - info.psi_siginfo.si_errno); - - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); - - expected_code = CLD_EXITED; - expected_status = exitval; - -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Fri Mar 6 17:03:35 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: Add await_collected() This functions waits for collecting a process. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 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.23 src/tests/lib/libc/sys/t_ptrace_wait.h:1.24 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.23 Tue Mar 3 17:09:22 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Fri Mar 6 17:03:35 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.23 2020/03/03 17:09:22 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.24 2020/03/06 17:03:35 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -463,6 +463,33 @@ await_stopped_child(pid_t process) return child; } +static void __used +await_collected(pid_t process) +{ + struct kinfo_proc2 p; + size_t len = sizeof(p); + + const int name[] = { + [0] = CTL_KERN, + [1] = KERN_PROC2, + [2] = KERN_PROC_PID, + [3] = process, + [4] = sizeof(p), + [5] = 1 + }; + + const size_t namelen = __arraycount(name); + + /* Await the process to disappear */ + while(1) { + FORKEE_ASSERT_EQ(sysctl(name, namelen, , , NULL, 0), 0); + if (len == 0) + break; + + ATF_REQUIRE(usleep(1000) == 0); + } +} + /* Happy number sequence -- this function is used to just consume cpu cycles */ #define HAPPY_NUMBER 1
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Fri Mar 6 14:06:56 UTC 2020 Modified Files: src/tests/lib/libc/sys: msg.h t_ptrace_wait.c Log Message: Move macros wrapping functions from msg.h into msg.h This makes code reusing easier. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/msg.h cvs rdiff -u -r1.167 -r1.168 src/tests/lib/libc/sys/t_ptrace_wait.c 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/msg.h diff -u src/tests/lib/libc/sys/msg.h:1.2 src/tests/lib/libc/sys/msg.h:1.3 --- src/tests/lib/libc/sys/msg.h:1.2 Tue Mar 13 14:45:36 2018 +++ src/tests/lib/libc/sys/msg.h Fri Mar 6 14:06:56 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: msg.h,v 1.2 2018/03/13 14:45:36 kamil Exp $ */ +/* $NetBSD: msg.h,v 1.3 2020/03/06 14:06:56 kamil Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ struct msg_fds { } \ } while (/*CONSTCOND*/ 0) -static int +static int __used msg_open(struct msg_fds *fds) { if (pipe(fds->pfd) == -1) @@ -54,7 +54,7 @@ msg_open(struct msg_fds *fds) return 0; } -static void +static void __used msg_close(struct msg_fds *fds) { CLOSEFD(fds->pfd[0]); @@ -63,7 +63,7 @@ msg_close(struct msg_fds *fds) CLOSEFD(fds->cfd[1]); } -static int +static int __used msg_write_child(const char *info, struct msg_fds *fds, void *msg, size_t len) { ssize_t rv; @@ -81,7 +81,7 @@ msg_write_child(const char *info, struct return 0; } -static int +static int __used msg_write_parent(const char *info, struct msg_fds *fds, void *msg, size_t len) { ssize_t rv; @@ -99,7 +99,7 @@ msg_write_parent(const char *info, struc return 0; } -static int +static int __used msg_read_parent(const char *info, struct msg_fds *fds, void *msg, size_t len) { ssize_t rv; @@ -117,7 +117,7 @@ msg_read_parent(const char *info, struct return 0; } -static int +static int __used msg_read_child(const char *info, struct msg_fds *fds, void *msg, size_t len) { ssize_t rv; @@ -134,3 +134,19 @@ msg_read_child(const char *info, struct return 1; return 0; } + +#define PARENT_TO_CHILD(info, fds, msg) \ +SYSCALL_REQUIRE(msg_write_child(info " to child " # fds, , , \ + sizeof(msg)) == 0) + +#define CHILD_FROM_PARENT(info, fds, msg) \ +FORKEE_ASSERT(msg_read_parent(info " from parent " # fds, , , \ + sizeof(msg)) == 0) + +#define CHILD_TO_PARENT(info, fds, msg) \ +FORKEE_ASSERT(msg_write_parent(info " to parent " # fds, , , \ + sizeof(msg)) == 0) + +#define PARENT_FROM_CHILD(info, fds, msg) \ +SYSCALL_REQUIRE(msg_read_child(info " from parent " # fds, , , \ + sizeof(msg)) == 0) Index: src/tests/lib/libc/sys/t_ptrace_wait.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.167 src/tests/lib/libc/sys/t_ptrace_wait.c:1.168 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.167 Sun Mar 1 18:22:00 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Fri Mar 6 14:06:56 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.167 2020/03/01 18:22:00 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.168 2020/03/06 14:06:56 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.167 2020/03/01 18:22:00 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.168 2020/03/06 14:06:56 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -97,22 +97,6 @@ static_assert(sizeof(((struct ptrace_sta #include "t_ptrace_wait.h" #include "msg.h" -#define PARENT_TO_CHILD(info, fds, msg) \ -SYSCALL_REQUIRE(msg_write_child(info " to child " # fds, , , \ - sizeof(msg)) == 0) - -#define CHILD_FROM_PARENT(info, fds, msg) \ -FORKEE_ASSERT(msg_read_parent(info " from parent " # fds, , , \ - sizeof(msg)) == 0) - -#define CHILD_TO_PARENT(info, fds, msg) \ -FORKEE_ASSERT(msg_write_parent(info " to parent " # fds, , , \ - sizeof(msg)) == 0) - -#define PARENT_FROM_CHILD(info, fds, msg) \ -SYSCALL_REQUIRE(msg_read_child(info " from parent " # fds, , , \ - sizeof(msg)) == 0) - #define SYSCALL_REQUIRE(expr) ATF_REQUIRE_MSG(expr, "%s: %s", # expr, \ strerror(errno)) #define SYSCALL_REQUIRE_ERRNO(res, exp) ATF_REQUIRE_MSG(res == exp, \
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue Mar 3 17:09:22 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: Mark find_event_count() with __used To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 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.22 src/tests/lib/libc/sys/t_ptrace_wait.h:1.23 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.22 Sat Feb 22 19:44:07 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Tue Mar 3 17:09:22 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.22 2020/02/22 19:44:07 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.23 2020/03/03 17:09:22 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -684,7 +684,7 @@ struct lwp_event_count { int lec_count; }; -static int * +static int * __used find_event_count(struct lwp_event_count list[], lwpid_t lwp, size_t max_lwps) { size_t i;
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Sun Mar 1 20:24:07 UTC 2020 Modified Files: src/tests/lib/libc/sys: Makefile Log Message: fix variable name To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/tests/lib/libc/sys/Makefile 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/Makefile diff -u src/tests/lib/libc/sys/Makefile:1.59 src/tests/lib/libc/sys/Makefile:1.60 --- src/tests/lib/libc/sys/Makefile:1.59 Sun Mar 1 13:08:15 2020 +++ src/tests/lib/libc/sys/Makefile Sun Mar 1 15:24:07 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.59 2020/03/01 18:08:15 christos Exp $ +# $NetBSD: Makefile,v 1.60 2020/03/01 20:24:07 christos Exp $ MKMAN= no @@ -98,7 +98,7 @@ LDADD.t_ptrace_waitpid+= -pthread -lm -l .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE) CPPFLAGS.t_posix_fadvise.c += -D_KERNTYPES TESTS_C+= t_posix_fadvise -LDADD.t_posix_fadvise+= ${RUMPVFSLIB} +LDADD.t_posix_fadvise+= ${LIBRUMPBASE} .endif CPPFLAGS.t_lwp_create.c += -D_KERNTYPES
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Sun Mar 1 18:22:00 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Add new signal trap entry tests in t_ptrace_wait* New tests: - syscall_signal_on_sce - syscall_detach_on_sce The first one fails as a signal emitted to the child is caught by the debugger. The second one passes. To generate a diff of this commit: cvs rdiff -u -r1.166 -r1.167 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.166 src/tests/lib/libc/sys/t_ptrace_wait.c:1.167 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.166 Mon Feb 24 23:46:45 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Sun Mar 1 18:22:00 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.166 2020/02/24 23:46:45 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.167 2020/03/01 18:22:00 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.166 2020/02/24 23:46:45 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.167 2020/03/01 18:22:00 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -7458,8 +7458,23 @@ ATF_TC_BODY(resume, tc) /// +static int test_syscall_caught; + +static void +syscall_sighand(int arg) +{ + + DPRINTF("Caught a signal %d in process %d\n", arg, getpid()); + + FORKEE_ASSERT_EQ(arg, SIGINFO); + + ++test_syscall_caught; + + FORKEE_ASSERT_EQ(test_syscall_caught, 1); +} + static void -syscall_body(bool killed) +syscall_body(const char *op) { const int exitval = 5; const int sigval = SIGSTOP; @@ -7468,19 +7483,32 @@ syscall_body(bool killed) int status; #endif struct ptrace_siginfo info; + memset(, 0, sizeof(info)); +#if defined(TWAIT_HAVE_STATUS) + if (strstr(op, "signal") != NULL) { + atf_tc_expect_fail("XXX: behavior under investigation"); + } +#endif + DPRINTF("Before forking process PID=%d\n", getpid()); SYSCALL_REQUIRE((child = fork()) != -1); if (child == 0) { DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + signal(SIGINFO, syscall_sighand); + DPRINTF("Before raising %s from child\n", strsignal(sigval)); FORKEE_ASSERT(raise(sigval) == 0); syscall(SYS_getpid); + if (strstr(op, "signal") != NULL) { + FORKEE_ASSERT_EQ(test_syscall_caught, 1); + } + DPRINTF("Before exiting of the child process\n"); _exit(exitval); } @@ -7508,7 +7536,7 @@ syscall_body(bool killed) ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCE); - if (killed) { + if (strstr(op, "killed") != NULL) { SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1); DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); @@ -7517,29 +7545,45 @@ syscall_body(bool killed) validate_status_signaled(status, SIGKILL, 0); } else { - DPRINTF("Before resuming the child process where it left off " - "and without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); + if (strstr(op, "signal") != NULL) { + DPRINTF("Before resuming the child %d and sending a " + "signal SIGINFO\n", child); + SYSCALL_REQUIRE( + ptrace(PT_CONTINUE, child, (void *)1, SIGINFO) + != -1); + } else if (strstr(op, "detach") != NULL) { + DPRINTF("Before detaching the child %d\n", child); + SYSCALL_REQUIRE( + ptrace(PT_DETACH, child, (void *)1, 0) != -1); + } else { + DPRINTF("Before resuming the child process where it " + "left off and without signal to be sent\n"); + SYSCALL_REQUIRE( + ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS( - wpid = TWAIT_GENERIC(child, , 0), child); + DPRINTF("Before calling %s() for the child\n", + TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS( + wpid = TWAIT_GENERIC(child, , 0), child); - validate_status_stopped(status, SIGTRAP); + validate_status_stopped(status, SIGTRAP); - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for " - "child\n"); - SYSCALL_REQUIRE( - ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO " + "for child\n"); + SYSCALL_REQUIRE( + ptrace(PT_GET_SIGINFO, child, , sizeof(info)) + != -1); - DPRINTF("Before checking siginfo_t and lwpid\n"); - ATF_REQUIRE_EQ(info.psi_lwpid, 1); - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCX); + DPRINTF("Before checking siginfo_t and lwpid\n"); + ATF_REQUIRE_EQ(info.psi_lwpid, 1); +
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon Feb 24 23:46:45 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Add new test in t_ptrace_wait* New test: syscall_killed_on_sce Test passes correctly. To generate a diff of this commit: cvs rdiff -u -r1.165 -r1.166 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.165 src/tests/lib/libc/sys/t_ptrace_wait.c:1.166 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.165 Sat Feb 22 19:44:07 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon Feb 24 23:46:45 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.165 2020/02/22 19:44:07 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.166 2020/02/24 23:46:45 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.165 2020/02/22 19:44:07 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.166 2020/02/24 23:46:45 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -7458,14 +7458,8 @@ ATF_TC_BODY(resume, tc) /// -ATF_TC(syscall1); -ATF_TC_HEAD(syscall1, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Verify that getpid(2) can be traced with PT_SYSCALL"); -} - -ATF_TC_BODY(syscall1, tc) +static void +syscall_body(bool killed) { const int exitval = 5; const int sigval = SIGSTOP; @@ -7514,36 +7508,69 @@ ATF_TC_BODY(syscall1, tc) ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCE); - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); + if (killed) { + SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1); - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); + DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS( + wpid = TWAIT_GENERIC(child, , 0), child); - validate_status_stopped(status, SIGTRAP); + validate_status_signaled(status, SIGKILL, 0); + } else { + DPRINTF("Before resuming the child process where it left off " + "and without signal to be sent\n"); + SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); - DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); - SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); + DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS( + wpid = TWAIT_GENERIC(child, , 0), child); - DPRINTF("Before checking siginfo_t and lwpid\n"); - ATF_REQUIRE_EQ(info.psi_lwpid, 1); - ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); - ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCX); + validate_status_stopped(status, SIGTRAP); - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for " + "child\n"); + SYSCALL_REQUIRE( + ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); + DPRINTF("Before checking siginfo_t and lwpid\n"); + ATF_REQUIRE_EQ(info.psi_lwpid, 1); + ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCX); + + DPRINTF("Before resuming the child process where it left off " + "and without signal to be sent\n"); + SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS( + wpid = TWAIT_GENERIC(child, , 0), child); + + validate_status_exited(status, exitval); + } - validate_status_exited(status, exitval); DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); } +#define SYSCALL_TEST(name,killed) \ +ATF_TC(name);\ +ATF_TC_HEAD(name, tc) \ +{ \ + atf_tc_set_md_var(tc, "descr", \ + "Verify that getpid(2) can be traced with PT_SYSCALL %s", \ + killed ? "and killed on syscall entry" : "" ); \ +} \ + \ +ATF_TC_BODY(name, tc) \ +{ \ + \ + syscall_body(killed); \ +} + +SYSCALL_TEST(syscall, false) +SYSCALL_TEST(syscall_killed_on_sce, true) + /// ATF_TC(syscallemu1); @@ -9532,7 +9559,8 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, resume); -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Sat Feb 22 19:44:07 UTC 2020 Modified Files: src/tests/lib/libc/sys: Makefile t_ptrace_wait.c t_ptrace_wait.h Log Message: Disable t_ptrace_wait* tests for MKSANITIZER/MKLIBCSANITIZER A subset of tests is not compatible with the sanitizers. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/tests/lib/libc/sys/Makefile cvs rdiff -u -r1.164 -r1.165 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.21 -r1.22 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/Makefile diff -u src/tests/lib/libc/sys/Makefile:1.57 src/tests/lib/libc/sys/Makefile:1.58 --- src/tests/lib/libc/sys/Makefile:1.57 Sun Jun 30 21:20:04 2019 +++ src/tests/lib/libc/sys/Makefile Sat Feb 22 19:44:07 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.57 2019/06/30 21:20:04 mgorny Exp $ +# $NetBSD: Makefile,v 1.58 2020/02/22 19:44:07 kamil Exp $ MKMAN= no @@ -110,6 +110,15 @@ CPPFLAGS.t_ptrace_waitid.c += -D_KERNTYP CPPFLAGS.t_ptrace_waitpid.c += -D_KERNTYPES -D__TEST_FENV CPPFLAGS.t_ucontext.c += -D_KERNTYPES +.if ${MKSANITIZER:Uno} != "yes" && ${MKLIBCSANITIZER:Uno} != "yes" +CPPFLAGS.t_ptrace_wait.c += -DENABLE_TESTS +CPPFLAGS.t_ptrace_wait3.c += -DENABLE_TESTS +CPPFLAGS.t_ptrace_wait4.c += -DENABLE_TESTS +CPPFLAGS.t_ptrace_wait6.c += -DENABLE_TESTS +CPPFLAGS.t_ptrace_waitid.c += -DENABLE_TESTS +CPPFLAGS.t_ptrace_waitpid.c += -DENABLE_TESTS +.endif + FILES= truncate_test.root_owned FILESBUILD= yes FILESDIR_truncate_test.root_owned= ${TESTSDIR} Index: src/tests/lib/libc/sys/t_ptrace_wait.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.164 src/tests/lib/libc/sys/t_ptrace_wait.c:1.165 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.164 Thu Feb 20 22:38:54 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Sat Feb 22 19:44:07 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.164 2020/02/20 22:38:54 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.165 2020/02/22 19:44:07 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.164 2020/02/20 22:38:54 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.165 2020/02/22 19:44:07 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -76,6 +76,8 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.16 #include +#ifdef ENABLE_TESTS + /* Assumptions in the kernel code that must be kept. */ static_assert(sizeof(((struct ptrace_state *)0)->pe_report_event) == sizeof(((siginfo_t *)0)->si_pe_report_event), @@ -9016,11 +9018,29 @@ THREAD_CONCURRENT_TEST(thread_concurrent #include "t_ptrace_i386_wait.h" #include "t_ptrace_x86_wait.h" +/// + +#else +ATF_TC(dummy); +ATF_TC_HEAD(dummy, tc) +{ + atf_tc_set_md_var(tc, "descr", "A dummy test"); +} + +ATF_TC_BODY(dummy, tc) +{ + + // Dummy, skipped + // The ATF framework requires at least a single defined test. +} +#endif + ATF_TP_ADD_TCS(tp) { setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); +#ifdef ENABLE_TESTS ATF_TP_ADD_TC(tp, traceme_raise1); ATF_TP_ADD_TC(tp, traceme_raise2); ATF_TP_ADD_TC(tp, traceme_raise3); @@ -9620,5 +9640,9 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TCS_PTRACE_WAIT_I386(); ATF_TP_ADD_TCS_PTRACE_WAIT_X86(); +#else + ATF_TP_ADD_TC(tp, dummy); +#endif + return atf_no_error(); } Index: src/tests/lib/libc/sys/t_ptrace_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.21 src/tests/lib/libc/sys/t_ptrace_wait.h:1.22 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.21 Thu Feb 13 13:38:44 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Sat Feb 22 19:44:07 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.21 2020/02/13 13:38:44 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.22 2020/02/22 19:44:07 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -606,11 +606,6 @@ trigger_trap(void) #endif } -#if defined(__clang__) -__attribute__((no_sanitize("undefined"))) -#else -__attribute__((no_sanitize_undefined)) -#endif static void __used trigger_segv(void) { @@ -647,11 +642,6 @@ are_fpu_exceptions_supported(void) return true; } -#if defined(__clang__) -__attribute__((no_sanitize("undefined"))) -#else -__attribute__((no_sanitize_undefined)) -#endif static void __used trigger_fpe(void) {
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Thu Feb 20 23:57:16 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Refactor dbregs_dont_inherit_lwp() Switch from native LWP calls to pthread(3) calls. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.23 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.24 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.23 Fri Feb 14 04:20:59 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Thu Feb 20 23:57:16 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.23 2020/02/14 04:20:59 christos Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.24 2020/02/20 23:57:16 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -1617,13 +1617,11 @@ ATF_TC_BODY(dbregs_dr3_trap_code, tc) } #endif -volatile lwpid_t x86_the_lwp_id = 0; - -static void __used -x86_lwp_main_func(void *arg) +static void * __used +x86_main_func(void *arg) { - x86_the_lwp_id = _lwp_self(); - _lwp_exit(); + + return arg; } static void @@ -1639,10 +1637,8 @@ dbregs_dont_inherit_lwp(int reg) const int slen = sizeof(state); ptrace_event_t event; const int elen = sizeof(event); - ucontext_t uc; + pthread_t t; lwpid_t lid; - static const size_t ssize = 16*1024; - void *stack; size_t i; struct dbreg r1; struct dbreg r2; @@ -1661,22 +1657,10 @@ dbregs_dont_inherit_lwp(int reg) DPRINTF("Before raising %s from child\n", strsignal(sigval)); FORKEE_ASSERT(raise(sigval) == 0); - DPRINTF("Before allocating memory for stack in child\n"); - FORKEE_ASSERT((stack = malloc(ssize)) != NULL); + FORKEE_ASSERT(!pthread_create(, NULL, x86_main_func, NULL)); - DPRINTF("Before making context for new lwp in child\n"); - _lwp_makecontext(, x86_lwp_main_func, NULL, NULL, stack, - ssize); - - DPRINTF("Before creating new in child\n"); - FORKEE_ASSERT(_lwp_create(, 0, ) == 0); - - DPRINTF("Before waiting for lwp %d to exit\n", lid); - FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); - - DPRINTF("Before verifying that reported %d and running lid %d " - "are the same\n", lid, x86_the_lwp_id); - FORKEE_ASSERT_EQ(lid, x86_the_lwp_id); + DPRINTF("Before waiting for thread to exit\n"); + FORKEE_ASSERT(!pthread_join(t, NULL)); DPRINTF("Before exiting of the child process\n"); _exit(exitval);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Thu Feb 20 22:38:54 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Minor changes to t_ptrace_wait* Add check for security.models.extensions.user_set_dbregs in the concurrent event tests. Use unconditionally atf_tc_skip(); as the test is racy. To generate a diff of this commit: cvs rdiff -u -r1.163 -r1.164 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.163 src/tests/lib/libc/sys/t_ptrace_wait.c:1.164 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.163 Wed Feb 19 17:13:00 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 20 22:38:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.163 2020/02/19 17:13:00 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.164 2020/02/20 22:38:54 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.163 2020/02/19 17:13:00 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.164 2020/02/20 22:38:54 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -2488,6 +2488,7 @@ ATF_TC_BODY(tracer_sees_terminaton_befor ATF_TC(tracer_sysctl_lookup_without_duplicates); ATF_TC_HEAD(tracer_sysctl_lookup_without_duplicates, tc) { + atf_tc_set_md_var(tc, "timeout", "15"); atf_tc_set_md_var(tc, "descr", "Assert that await_zombie() in attach1 always finds a single " "process and no other error is reported"); @@ -7541,6 +7542,8 @@ ATF_TC_BODY(syscall1, tc) TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); } +/// + ATF_TC(syscallemu1); ATF_TC_HEAD(syscallemu1, tc) { @@ -8728,10 +8731,14 @@ thread_concurrent_test(enum thread_concu ptrace_event_t event; int i; - if (signal_handle == TCSH_SIG_IGN) - atf_tc_expect_fail("PR kern/54960"); - else if (signal_handle == TCSH_HANDLER) - atf_tc_skip("PR kern/54960"); +#if defined(HAVE_DBREGS) + if (!can_we_set_dbregs()) { + atf_tc_skip("Either run this test as root or set sysctl(3) " + "security.models.extensions.user_set_dbregs to 1"); +} +#endif + + atf_tc_skip("PR kern/54960"); /* Protect against out-of-bounds array access. */ ATF_REQUIRE(breakpoint_threads <= THREAD_CONCURRENT_BREAKPOINT_NUM);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Wed Feb 19 17:13:00 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Fix clang(1) build Namespace a symbol that can be unused. To generate a diff of this commit: cvs rdiff -u -r1.162 -r1.163 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.162 src/tests/lib/libc/sys/t_ptrace_wait.c:1.163 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.162 Thu Feb 13 15:27:41 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Wed Feb 19 17:13:00 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.162 2020/02/13 15:27:41 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.163 2020/02/19 17:13:00 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.162 2020/02/13 15:27:41 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.163 2020/02/19 17:13:00 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -8948,6 +8948,7 @@ THREAD_CONCURRENT_TEST(thread_concurrent "Verify that concurrent signals issued to a single thread are reported " "correctly and passed back to a handler function"); +#if defined(__i386__) || defined(__x86_64__) THREAD_CONCURRENT_TEST(thread_concurrent_breakpoints, TCSH_DISCARD, THREAD_CONCURRENT_BREAKPOINT_NUM, 0, 0, "Verify that concurrent breakpoints are reported correctly"); @@ -8998,6 +8999,7 @@ THREAD_CONCURRENT_TEST(thread_concurrent THREAD_CONCURRENT_WATCHPOINT_NUM, "Verify that concurrent breakpoints, watchpoints and signals are reported " "correctly and passed back to a handler function"); +#endif #endif /*defined(TWAIT_HAVE_STATUS)*/
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Fri Feb 14 04:20:59 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Instead of turning optimization off, use unique labels with %= (thanks joerg@) To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.22 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.23 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.22 Thu Feb 13 13:31:54 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Thu Feb 13 23:20:59 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.22 2020/02/13 18:31:54 tnn Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.23 2020/02/14 04:20:59 christos Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -1972,11 +1972,6 @@ ATF_TC_HEAD(x86_cve_2018_8897, tc) #define X86_CVE_2018_8897_PAGE 0x5000 /* page addressable by 32-bit registers */ static void -#ifdef __clang__ -__attribute__((optnone)) -#else -__attribute__((__optimize__("O0"))) -#endif x86_cve_2018_8897_trigger(void) { /* @@ -2077,13 +2072,13 @@ x86_cve_2018_8897_trigger(void) ); #else /* !__PIE__ */ __asm__ __volatile__( - " movq $farjmp32, %%rax\n\t" + " movq $farjmp32%=, %%rax\n\t" " ljmp *(%%rax)\n\t" - "farjmp32:\n\t" - " .long trigger32\n\t" + "farjmp32%=:\n\t" + " .long trigger32%=\n\t" " .word 0x73\n\t" " .code32\n\t" - "trigger32:\n\t" + "trigger32%=:\n\t" " movl $0x5000, %%esp\n\t" " pop %%ss\n\t" " int $4\n\t"
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: tnn Date: Thu Feb 13 18:31:55 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: adjust r1.19; add clang equivalent of gcc specific attribute To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.21 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.22 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.21 Thu Feb 13 15:27:25 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Thu Feb 13 18:31:54 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.21 2020/02/13 15:27:25 mgorny Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.22 2020/02/13 18:31:54 tnn Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -1971,7 +1971,12 @@ ATF_TC_HEAD(x86_cve_2018_8897, tc) #define X86_CVE_2018_8897_PAGE 0x5000 /* page addressable by 32-bit registers */ -static __attribute__((__optimize__("O0"))) void +static void +#ifdef __clang__ +__attribute__((optnone)) +#else +__attribute__((__optimize__("O0"))) +#endif x86_cve_2018_8897_trigger(void) { /*
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Feb 13 15:27:41 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Enable combined breakpoint, watchpoint and signal tests To generate a diff of this commit: cvs rdiff -u -r1.161 -r1.162 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.161 src/tests/lib/libc/sys/t_ptrace_wait.c:1.162 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.161 Thu Feb 13 15:27:25 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 13 15:27:41 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.161 2020/02/13 15:27:25 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.162 2020/02/13 15:27:41 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.161 2020/02/13 15:27:25 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.162 2020/02/13 15:27:41 mgorny Exp $"); #define __LEGACY_PT_LWPINFO @@ -8954,6 +8954,50 @@ THREAD_CONCURRENT_TEST(thread_concurrent THREAD_CONCURRENT_TEST(thread_concurrent_watchpoints, TCSH_DISCARD, 0, 0, THREAD_CONCURRENT_WATCHPOINT_NUM, "Verify that concurrent breakpoints are reported correctly"); +THREAD_CONCURRENT_TEST(thread_concurrent_bp_wp, TCSH_DISCARD, +THREAD_CONCURRENT_BREAKPOINT_NUM, 0, THREAD_CONCURRENT_WATCHPOINT_NUM, +"Verify that concurrent breakpoints and watchpoints are reported " +"correctly"); + +THREAD_CONCURRENT_TEST(thread_concurrent_bp_sig, TCSH_DISCARD, +THREAD_CONCURRENT_BREAKPOINT_NUM, THREAD_CONCURRENT_SIGNALS_NUM, 0, +"Verify that concurrent breakpoints and signals are reported correctly"); +THREAD_CONCURRENT_TEST(thread_concurrent_bp_sig_sig_ign, TCSH_SIG_IGN, +THREAD_CONCURRENT_BREAKPOINT_NUM, THREAD_CONCURRENT_SIGNALS_NUM, 0, +"Verify that concurrent breakpoints and signals are reported correctly " +"and passed back to SIG_IGN handler"); +THREAD_CONCURRENT_TEST(thread_concurrent_bp_sig_handler, TCSH_HANDLER, +THREAD_CONCURRENT_BREAKPOINT_NUM, THREAD_CONCURRENT_SIGNALS_NUM, 0, +"Verify that concurrent breakpoints and signals are reported correctly " +"and passed back to a handler function"); + +THREAD_CONCURRENT_TEST(thread_concurrent_wp_sig, TCSH_DISCARD, +0, THREAD_CONCURRENT_SIGNALS_NUM, THREAD_CONCURRENT_WATCHPOINT_NUM, +"Verify that concurrent watchpoints and signals are reported correctly"); +THREAD_CONCURRENT_TEST(thread_concurrent_wp_sig_sig_ign, TCSH_SIG_IGN, +0, THREAD_CONCURRENT_SIGNALS_NUM, THREAD_CONCURRENT_WATCHPOINT_NUM, +"Verify that concurrent watchpoints and signals are reported correctly " +"and passed back to SIG_IGN handler"); +THREAD_CONCURRENT_TEST(thread_concurrent_wp_sig_handler, TCSH_HANDLER, +0, THREAD_CONCURRENT_SIGNALS_NUM, THREAD_CONCURRENT_WATCHPOINT_NUM, +"Verify that concurrent watchpoints and signals are reported correctly " +"and passed back to a handler function"); + +THREAD_CONCURRENT_TEST(thread_concurrent_bp_wp_sig, TCSH_DISCARD, +THREAD_CONCURRENT_BREAKPOINT_NUM, THREAD_CONCURRENT_SIGNALS_NUM, +THREAD_CONCURRENT_WATCHPOINT_NUM, +"Verify that concurrent breakpoints, watchpoints and signals are reported " +"correctly"); +THREAD_CONCURRENT_TEST(thread_concurrent_bp_wp_sig_sig_ign, TCSH_SIG_IGN, +THREAD_CONCURRENT_BREAKPOINT_NUM, THREAD_CONCURRENT_SIGNALS_NUM, +THREAD_CONCURRENT_WATCHPOINT_NUM, +"Verify that concurrent breakpoints, watchpoints and signals are reported " +"correctly and passed back to SIG_IGN handler"); +THREAD_CONCURRENT_TEST(thread_concurrent_bp_wp_sig_handler, TCSH_HANDLER, +THREAD_CONCURRENT_BREAKPOINT_NUM, THREAD_CONCURRENT_SIGNALS_NUM, +THREAD_CONCURRENT_WATCHPOINT_NUM, +"Verify that concurrent breakpoints, watchpoints and signals are reported " +"correctly and passed back to a handler function"); #endif /*defined(TWAIT_HAVE_STATUS)*/ @@ -9550,6 +9594,16 @@ ATF_TP_ADD_TCS(tp) #if defined(__i386__) || defined(__x86_64__) ATF_TP_ADD_TC(tp, thread_concurrent_breakpoints); ATF_TP_ADD_TC(tp, thread_concurrent_watchpoints); + ATF_TP_ADD_TC(tp, thread_concurrent_bp_wp); + ATF_TP_ADD_TC(tp, thread_concurrent_bp_sig); + ATF_TP_ADD_TC(tp, thread_concurrent_bp_sig_sig_ign); + ATF_TP_ADD_TC(tp, thread_concurrent_bp_sig_handler); + ATF_TP_ADD_TC(tp, thread_concurrent_wp_sig); + ATF_TP_ADD_TC(tp, thread_concurrent_wp_sig_sig_ign); + ATF_TP_ADD_TC(tp, thread_concurrent_wp_sig_handler); + ATF_TP_ADD_TC(tp, thread_concurrent_bp_wp_sig); + ATF_TP_ADD_TC(tp, thread_concurrent_bp_wp_sig_sig_ign); + ATF_TP_ADD_TC(tp, thread_concurrent_bp_wp_sig_handler); #endif #endif
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Feb 13 15:27:25 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_x86_wait.h Log Message: Extend concurrent events test to watchpoints To generate a diff of this commit: cvs rdiff -u -r1.160 -r1.161 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.20 -r1.21 src/tests/lib/libc/sys/t_ptrace_x86_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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.160 src/tests/lib/libc/sys/t_ptrace_wait.c:1.161 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.160 Thu Feb 13 15:27:05 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 13 15:27:25 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.160 2020/02/13 15:27:05 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.161 2020/02/13 15:27:25 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.160 2020/02/13 15:27:05 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.161 2020/02/13 15:27:25 mgorny Exp $"); #define __LEGACY_PT_LWPINFO @@ -8622,6 +8622,7 @@ ATF_TC_BODY(core_dump_procinfo, tc) #define THREAD_CONCURRENT_BREAKPOINT_NUM 50 #define THREAD_CONCURRENT_SIGNALS_NUM 50 +#define THREAD_CONCURRENT_WATCHPOINT_NUM 50 /* List of signals to use for the test */ const int thread_concurrent_signals_list[] = { @@ -8647,6 +8648,7 @@ enum thread_concurrent_signal_handling { static pthread_barrier_t thread_concurrent_barrier; static pthread_key_t thread_concurrent_key; +static uint32_t thread_concurrent_watchpoint_var = 0; static void * thread_concurrent_breakpoint_thread(void *arg) @@ -8687,10 +8689,20 @@ thread_concurrent_signals_thread(void *a return NULL; } +static void * +thread_concurrent_watchpoint_thread(void *arg) +{ + pthread_barrier_wait(_concurrent_barrier); + DPRINTF("Before modifying var from LWP %d\n", _lwp_self()); + thread_concurrent_watchpoint_var = 1; + return NULL; +} + #if defined(__i386__) || defined(__x86_64__) enum thread_concurrent_sigtrap_event { TCSE_UNKNOWN, - TCSE_BREAKPOINT + TCSE_BREAKPOINT, + TCSE_WATCHPOINT }; static void @@ -8701,7 +8713,7 @@ thread_concurrent_handle_sigtrap(pid_t c static void thread_concurrent_test(enum thread_concurrent_signal_handling signal_handle, -int breakpoint_threads, int signal_threads) +int breakpoint_threads, int signal_threads, int watchpoint_threads) { const int exitval = 5; const int sigval = SIGSTOP; @@ -8711,6 +8723,8 @@ thread_concurrent_test(enum thread_concu = {{0, 0}}; struct lwp_event_count bp_counts[THREAD_CONCURRENT_BREAKPOINT_NUM] = {{0, 0}}; + struct lwp_event_count wp_counts[THREAD_CONCURRENT_BREAKPOINT_NUM] + = {{0, 0}}; ptrace_event_t event; int i; @@ -8722,12 +8736,14 @@ thread_concurrent_test(enum thread_concu /* Protect against out-of-bounds array access. */ ATF_REQUIRE(breakpoint_threads <= THREAD_CONCURRENT_BREAKPOINT_NUM); ATF_REQUIRE(signal_threads <= THREAD_CONCURRENT_SIGNALS_NUM); + ATF_REQUIRE(watchpoint_threads <= THREAD_CONCURRENT_WATCHPOINT_NUM); DPRINTF("Before forking process PID=%d\n", getpid()); SYSCALL_REQUIRE((child = fork()) != -1); if (child == 0) { pthread_t bp_threads[THREAD_CONCURRENT_BREAKPOINT_NUM]; pthread_t sig_threads[THREAD_CONCURRENT_SIGNALS_NUM]; + pthread_t wp_threads[THREAD_CONCURRENT_WATCHPOINT_NUM]; DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); @@ -8757,7 +8773,8 @@ thread_concurrent_test(enum thread_concu DPRINTF("Before starting threads from the child\n"); FORKEE_ASSERT(pthread_barrier_init( _concurrent_barrier, NULL, - breakpoint_threads + signal_threads) == 0); + breakpoint_threads + signal_threads + watchpoint_threads) + == 0); FORKEE_ASSERT(pthread_key_create(_concurrent_key, NULL) == 0); @@ -8770,8 +8787,15 @@ thread_concurrent_test(enum thread_concu FORKEE_ASSERT(pthread_create(_threads[i], NULL, thread_concurrent_breakpoint_thread, NULL) == 0); } + for (i = 0; i < watchpoint_threads; i++) { + FORKEE_ASSERT(pthread_create(_threads[i], NULL, + thread_concurrent_watchpoint_thread, NULL) == 0); + } DPRINTF("Before joining threads from the child\n"); + for (i = 0; i < watchpoint_threads; i++) { + FORKEE_ASSERT(pthread_join(wp_threads[i], NULL) == 0); + } for (i = 0; i < breakpoint_threads; i++) { FORKEE_ASSERT(pthread_join(bp_threads[i], NULL) == 0); } @@ -8852,6 +8876,10 @@ thread_concurrent_test(enum thread_concu *FIND_EVENT_COUNT(bp_counts, info.psi_lwpid) += 1; break; +case TCSE_WATCHPOINT: + *FIND_EVENT_COUNT(wp_counts, + info.psi_lwpid) += 1; + break; }
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Feb 13 15:27:05 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_x86_wait.h Log Message: Extend concurrent events test to breakpoints Add testing for concurrent breakpoint hits. The code is currently x86-specific but since it reuses most of the generic concurrent event test code, it's put in t_ptrace_wait.c with arch-specific hooks. To generate a diff of this commit: cvs rdiff -u -r1.159 -r1.160 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.19 -r1.20 src/tests/lib/libc/sys/t_ptrace_x86_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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.159 src/tests/lib/libc/sys/t_ptrace_wait.c:1.160 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.159 Thu Feb 13 15:26:45 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 13 15:27:05 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.159 2020/02/13 15:26:45 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.160 2020/02/13 15:27:05 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.159 2020/02/13 15:26:45 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.160 2020/02/13 15:27:05 mgorny Exp $"); #define __LEGACY_PT_LWPINFO @@ -8620,6 +8620,7 @@ ATF_TC_BODY(core_dump_procinfo, tc) #if defined(TWAIT_HAVE_STATUS) +#define THREAD_CONCURRENT_BREAKPOINT_NUM 50 #define THREAD_CONCURRENT_SIGNALS_NUM 50 /* List of signals to use for the test */ @@ -8647,6 +8648,16 @@ enum thread_concurrent_signal_handling { static pthread_barrier_t thread_concurrent_barrier; static pthread_key_t thread_concurrent_key; +static void * +thread_concurrent_breakpoint_thread(void *arg) +{ + static volatile int watchme = 1; + pthread_barrier_wait(_concurrent_barrier); + DPRINTF("Before entering breakpoint func from LWP %d\n", _lwp_self()); + check_happy(watchme); + return NULL; +} + static void thread_concurrent_sig_handler(int sig) { @@ -8676,9 +8687,21 @@ thread_concurrent_signals_thread(void *a return NULL; } +#if defined(__i386__) || defined(__x86_64__) +enum thread_concurrent_sigtrap_event { + TCSE_UNKNOWN, + TCSE_BREAKPOINT +}; + +static void +thread_concurrent_lwp_setup(pid_t child, lwpid_t lwpid); +static enum thread_concurrent_sigtrap_event +thread_concurrent_handle_sigtrap(pid_t child, ptrace_siginfo_t *info); +#endif + static void thread_concurrent_test(enum thread_concurrent_signal_handling signal_handle, -int signal_threads) +int breakpoint_threads, int signal_threads) { const int exitval = 5; const int sigval = SIGSTOP; @@ -8686,6 +8709,8 @@ thread_concurrent_test(enum thread_concu int status; struct lwp_event_count signal_counts[THREAD_CONCURRENT_SIGNALS_NUM] = {{0, 0}}; + struct lwp_event_count bp_counts[THREAD_CONCURRENT_BREAKPOINT_NUM] + = {{0, 0}}; ptrace_event_t event; int i; @@ -8695,11 +8720,13 @@ thread_concurrent_test(enum thread_concu atf_tc_skip("PR kern/54960"); /* Protect against out-of-bounds array access. */ + ATF_REQUIRE(breakpoint_threads <= THREAD_CONCURRENT_BREAKPOINT_NUM); ATF_REQUIRE(signal_threads <= THREAD_CONCURRENT_SIGNALS_NUM); DPRINTF("Before forking process PID=%d\n", getpid()); SYSCALL_REQUIRE((child = fork()) != -1); if (child == 0) { + pthread_t bp_threads[THREAD_CONCURRENT_BREAKPOINT_NUM]; pthread_t sig_threads[THREAD_CONCURRENT_SIGNALS_NUM]; DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); @@ -8730,7 +8757,7 @@ thread_concurrent_test(enum thread_concu DPRINTF("Before starting threads from the child\n"); FORKEE_ASSERT(pthread_barrier_init( _concurrent_barrier, NULL, - signal_threads) == 0); + breakpoint_threads + signal_threads) == 0); FORKEE_ASSERT(pthread_key_create(_concurrent_key, NULL) == 0); @@ -8739,8 +8766,15 @@ thread_concurrent_test(enum thread_concu thread_concurrent_signals_thread, _handle) == 0); } + for (i = 0; i < breakpoint_threads; i++) { + FORKEE_ASSERT(pthread_create(_threads[i], NULL, + thread_concurrent_breakpoint_thread, NULL) == 0); + } DPRINTF("Before joining threads from the child\n"); + for (i = 0; i < breakpoint_threads; i++) { + FORKEE_ASSERT(pthread_join(bp_threads[i], NULL) == 0); + } for (i = 0; i < signal_threads; i++) { FORKEE_ASSERT(pthread_join(sig_threads[i], NULL) == 0); } @@ -8804,10 +8838,25 @@ thread_concurrent_test(enum thread_concu expected_sig, WSTOPSIG(status)); *FIND_EVENT_COUNT(signal_counts, info.psi_lwpid) += 1; + } else if (info.psi_siginfo.si_code == TRAP_LWP) { +#if defined(__i386__) || defined(__x86_64__) + thread_concurrent_lwp_setup(child, info.psi_lwpid); +#endif } else { -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Feb 13 15:26:18 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Test whether signal handler is called in concurrent bombarding To generate a diff of this commit: cvs rdiff -u -r1.157 -r1.158 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.157 src/tests/lib/libc/sys/t_ptrace_wait.c:1.158 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.157 Thu Feb 13 15:25:58 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 13 15:26:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.157 2020/02/13 15:25:58 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.158 2020/02/13 15:26:18 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.157 2020/02/13 15:25:58 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.158 2020/02/13 15:26:18 mgorny Exp $"); #define __LEGACY_PT_LWPINFO @@ -8645,11 +8645,15 @@ enum thread_concurrent_signal_handling { }; static pthread_barrier_t thread_concurrent_barrier; +static pthread_key_t thread_concurrent_key; static void thread_concurrent_sig_handler(int sig) { - /* TODO: verify that handler is actually called */ + void *tls_val = pthread_getspecific(thread_concurrent_key); + DPRINTF("Before increment, LWP %d tls_val=%p\n", _lwp_self(), tls_val); + FORKEE_ASSERT(pthread_setspecific(thread_concurrent_key, + (void*)((uintptr_t)tls_val + 1)) == 0); } static void * @@ -8657,10 +8661,18 @@ thread_concurrent_signals_thread(void *a { int sigval = thread_concurrent_signals_list[ _lwp_self() % __arraycount(thread_concurrent_signals_list)]; + enum thread_concurrent_signal_handling *signal_handle = arg; + void *tls_val; + pthread_barrier_wait(_concurrent_barrier); DPRINTF("Before raising %s from LWP %d\n", strsignal(sigval), _lwp_self()); pthread_kill(pthread_self(), sigval); + if (*signal_handle == TCSH_HANDLER) { + tls_val = pthread_getspecific(thread_concurrent_key); + DPRINTF("After raising, LWP %d tls_val=%p\n", _lwp_self(), tls_val); + FORKEE_ASSERT(tls_val == (void*)1); + } return NULL; } @@ -8718,10 +8730,13 @@ thread_concurrent_test(enum thread_concu FORKEE_ASSERT(pthread_barrier_init( _concurrent_barrier, NULL, signal_threads) == 0); + FORKEE_ASSERT(pthread_key_create(_concurrent_key, NULL) + == 0); for (i = 0; i < signal_threads; i++) { FORKEE_ASSERT(pthread_create(_threads[i], NULL, - thread_concurrent_signals_thread, NULL) == 0); + thread_concurrent_signals_thread, + _handle) == 0); } DPRINTF("Before joining threads from the child\n"); @@ -8729,6 +8744,7 @@ thread_concurrent_test(enum thread_concu FORKEE_ASSERT(pthread_join(sig_threads[i], NULL) == 0); } + FORKEE_ASSERT(pthread_key_delete(thread_concurrent_key) == 0); FORKEE_ASSERT(pthread_barrier_destroy( _concurrent_barrier) == 0);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Feb 13 15:26:45 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Include LWP events in concurrent event test LWP events will be necessary when breakpoint/watchpoint support is added to the test. However, they also benefit us by testing whether TRAP_LWP events do not break signal reporting. To generate a diff of this commit: cvs rdiff -u -r1.158 -r1.159 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.158 src/tests/lib/libc/sys/t_ptrace_wait.c:1.159 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.158 Thu Feb 13 15:26:18 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 13 15:26:45 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.158 2020/02/13 15:26:18 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.159 2020/02/13 15:26:45 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.158 2020/02/13 15:26:18 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.159 2020/02/13 15:26:45 mgorny Exp $"); #define __LEGACY_PT_LWPINFO @@ -8686,6 +8686,7 @@ thread_concurrent_test(enum thread_concu int status; struct lwp_event_count signal_counts[THREAD_CONCURRENT_SIGNALS_NUM] = {{0, 0}}; + ptrace_event_t event; int i; if (signal_handle == TCSH_SIG_IGN) @@ -8758,13 +8759,18 @@ thread_concurrent_test(enum thread_concu validate_status_stopped(status, sigval); + DPRINTF("Set LWP event mask for the child process\n"); + memset(, 0, sizeof(event)); + event.pe_set_event |= PTRACE_LWP_CREATE; + SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , sizeof(event)) + != -1); + DPRINTF("Before resuming the child process where it left off\n"); SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); DPRINTF("Before entering signal collection loop\n"); while (1) { ptrace_siginfo_t info; - int expected_sig; DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), @@ -8785,21 +8791,29 @@ thread_concurrent_test(enum thread_concu info.psi_siginfo.si_signo, info.psi_lwpid, WSTOPSIG(status)); - expected_sig = thread_concurrent_signals_list[info.psi_lwpid % - __arraycount(thread_concurrent_signals_list)]; - ATF_CHECK_EQ_MSG(info.psi_siginfo.si_signo, expected_sig, - "lwp=%d, expected %d, got %d", info.psi_lwpid, - expected_sig, info.psi_siginfo.si_signo); - ATF_CHECK_EQ_MSG(WSTOPSIG(status), expected_sig, - "lwp=%d, expected %d, got %d", info.psi_lwpid, - expected_sig, WSTOPSIG(status)); + ATF_CHECK_EQ_MSG(info.psi_siginfo.si_signo, WSTOPSIG(status), + "lwp=%d, WSTOPSIG=%d, psi_siginfo=%d", info.psi_lwpid, + WSTOPSIG(status), info.psi_siginfo.si_signo); + + if (WSTOPSIG(status) != SIGTRAP) { + int expected_sig = + thread_concurrent_signals_list[info.psi_lwpid % + __arraycount(thread_concurrent_signals_list)]; + ATF_CHECK_EQ_MSG(WSTOPSIG(status), expected_sig, +"lwp=%d, expected %d, got %d", info.psi_lwpid, +expected_sig, WSTOPSIG(status)); - *FIND_EVENT_COUNT(signal_counts, info.psi_lwpid) += 1; + *FIND_EVENT_COUNT(signal_counts, info.psi_lwpid) += 1; + } else { + ATF_CHECK_EQ_MSG(info.psi_siginfo.si_code, TRAP_LWP, + "lwp=%d, expected TRAP_LWP (%d), got %d", + info.psi_lwpid, TRAP_LWP, info.psi_siginfo.si_code); + } DPRINTF("Before resuming the child process\n"); SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, - signal_handle != TCSH_DISCARD ? WSTOPSIG(status) : 0) - != -1); + signal_handle != TCSH_DISCARD && WSTOPSIG(status) != SIGTRAP + ? WSTOPSIG(status) : 0) != -1); } for (i = 0; i < signal_threads; i++)
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Feb 13 15:25:58 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Extend concurrent signal tests to pass signal back to the thread To generate a diff of this commit: cvs rdiff -u -r1.156 -r1.157 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.156 src/tests/lib/libc/sys/t_ptrace_wait.c:1.157 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.156 Thu Feb 13 15:25:29 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 13 15:25:58 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.156 2020/02/13 15:25:29 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.157 2020/02/13 15:25:58 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.156 2020/02/13 15:25:29 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.157 2020/02/13 15:25:58 mgorny Exp $"); #define __LEGACY_PT_LWPINFO @@ -8635,8 +8635,23 @@ const int thread_concurrent_signals_list SIGUSR2 }; +enum thread_concurrent_signal_handling { + /* the signal is discarded by debugger */ + TCSH_DISCARD, + /* the handler is set to SIG_IGN */ + TCSH_SIG_IGN, + /* an actual handler is used */ + TCSH_HANDLER +}; + static pthread_barrier_t thread_concurrent_barrier; +static void +thread_concurrent_sig_handler(int sig) +{ + /* TODO: verify that handler is actually called */ +} + static void * thread_concurrent_signals_thread(void *arg) { @@ -8650,7 +8665,8 @@ thread_concurrent_signals_thread(void *a } static void -thread_concurrent_test(int signal_threads) +thread_concurrent_test(enum thread_concurrent_signal_handling signal_handle, +int signal_threads) { const int exitval = 5; const int sigval = SIGSTOP; @@ -8660,6 +8676,11 @@ thread_concurrent_test(int signal_thread = {{0, 0}}; int i; + if (signal_handle == TCSH_SIG_IGN) + atf_tc_expect_fail("PR kern/54960"); + else if (signal_handle == TCSH_HANDLER) + atf_tc_skip("PR kern/54960"); + /* Protect against out-of-bounds array access. */ ATF_REQUIRE(signal_threads <= THREAD_CONCURRENT_SIGNALS_NUM); @@ -8674,6 +8695,25 @@ thread_concurrent_test(int signal_thread DPRINTF("Before raising %s from child\n", strsignal(sigval)); FORKEE_ASSERT(raise(sigval) == 0); + if (signal_handle != TCSH_DISCARD) { + struct sigaction sa; + unsigned int j; + + memset(, 0, sizeof(sa)); + if (signal_handle == TCSH_SIG_IGN) +sa.sa_handler = SIG_IGN; + else +sa.sa_handler = thread_concurrent_sig_handler; + sigemptyset(_mask); + + for (j = 0; + j < __arraycount(thread_concurrent_signals_list); + j++) +FORKEE_ASSERT(sigaction( +thread_concurrent_signals_list[j], , NULL) +!= -1); + } + DPRINTF("Before starting threads from the child\n"); FORKEE_ASSERT(pthread_barrier_init( _concurrent_barrier, NULL, @@ -8741,7 +8781,9 @@ thread_concurrent_test(int signal_thread *FIND_EVENT_COUNT(signal_counts, info.psi_lwpid) += 1; DPRINTF("Before resuming the child process\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, + signal_handle != TCSH_DISCARD ? WSTOPSIG(status) : 0) + != -1); } for (i = 0; i < signal_threads; i++) @@ -8756,7 +8798,7 @@ thread_concurrent_test(int signal_thread validate_status_exited(status, exitval); } -#define THREAD_CONCURRENT_TEST(test, sigs, descr) \ +#define THREAD_CONCURRENT_TEST(test, sig_hdl, sigs, descr) \ ATF_TC(test);\ ATF_TC_HEAD(test, tc) \ { \ @@ -8765,13 +8807,21 @@ ATF_TC_HEAD(test, tc) \ \ ATF_TC_BODY(test, tc) \ { \ - thread_concurrent_test(sigs); \ + thread_concurrent_test(sig_hdl, sigs);\ } -THREAD_CONCURRENT_TEST(thread_concurrent_signals, - THREAD_CONCURRENT_SIGNALS_NUM, - "Verify that concurrent signals issued to a single thread are reported " - "correctly"); +THREAD_CONCURRENT_TEST(thread_concurrent_signals, TCSH_DISCARD, +THREAD_CONCURRENT_SIGNALS_NUM, +"Verify that concurrent signals issued to a single thread are reported " +"correctly"); +THREAD_CONCURRENT_TEST(thread_concurrent_signals_sig_ign, TCSH_SIG_IGN, +THREAD_CONCURRENT_SIGNALS_NUM, +"Verify that concurrent signals issued to a single thread are reported " +"correctly and passed back to SIG_IGN handler"); +THREAD_CONCURRENT_TEST(thread_concurrent_signals_handler, TCSH_HANDLER, +THREAD_CONCURRENT_SIGNALS_NUM, +"Verify that concurrent signals issued to a single thread are reported " +"correctly and passed back to a handler function"); #endif /*defined(TWAIT_HAVE_STATUS)*/ @@ -9363,6 +9413,8
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Thu Feb 13 15:25:29 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Generalize thread_concurrent_signals to a generic factory Build thread_concurrent_signals on a generic parametrized thread_concurrent_test() function. At first, this permits adjusting the number of running signal threads but in the followup commits support for different concurrent events (breakpoints, watchpoints) and different signal handling will be added. To generate a diff of this commit: cvs rdiff -u -r1.155 -r1.156 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.155 src/tests/lib/libc/sys/t_ptrace_wait.c:1.156 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.155 Tue Feb 11 00:41:37 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Feb 13 15:25:29 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.155 2020/02/11 00:41:37 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.156 2020/02/13 15:25:29 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.155 2020/02/11 00:41:37 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.156 2020/02/13 15:25:29 mgorny Exp $"); #define __LEGACY_PT_LWPINFO @@ -8620,13 +8620,7 @@ ATF_TC_BODY(core_dump_procinfo, tc) #if defined(TWAIT_HAVE_STATUS) -ATF_TC(thread_concurrent_signals); -ATF_TC_HEAD(thread_concurrent_signals, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Verify that concurrent signals issued to a single thread " - "are reported correctly"); -} +#define THREAD_CONCURRENT_SIGNALS_NUM 50 /* List of signals to use for the test */ const int thread_concurrent_signals_list[] = { @@ -8641,23 +8635,22 @@ const int thread_concurrent_signals_list SIGUSR2 }; -pthread_barrier_t thread_concurrent_signals_barrier; +static pthread_barrier_t thread_concurrent_barrier; static void * thread_concurrent_signals_thread(void *arg) { int sigval = thread_concurrent_signals_list[ _lwp_self() % __arraycount(thread_concurrent_signals_list)]; - pthread_barrier_wait(_concurrent_signals_barrier); + pthread_barrier_wait(_concurrent_barrier); DPRINTF("Before raising %s from LWP %d\n", strsignal(sigval), _lwp_self()); pthread_kill(pthread_self(), sigval); return NULL; } -#define THREAD_CONCURRENT_SIGNALS_NUM 50 - -ATF_TC_BODY(thread_concurrent_signals, tc) +static void +thread_concurrent_test(int signal_threads) { const int exitval = 5; const int sigval = SIGSTOP; @@ -8665,12 +8658,15 @@ ATF_TC_BODY(thread_concurrent_signals, t int status; struct lwp_event_count signal_counts[THREAD_CONCURRENT_SIGNALS_NUM] = {{0, 0}}; - unsigned int i; + int i; + + /* Protect against out-of-bounds array access. */ + ATF_REQUIRE(signal_threads <= THREAD_CONCURRENT_SIGNALS_NUM); DPRINTF("Before forking process PID=%d\n", getpid()); SYSCALL_REQUIRE((child = fork()) != -1); if (child == 0) { - pthread_t threads[THREAD_CONCURRENT_SIGNALS_NUM]; + pthread_t sig_threads[THREAD_CONCURRENT_SIGNALS_NUM]; DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); @@ -8680,21 +8676,21 @@ ATF_TC_BODY(thread_concurrent_signals, t DPRINTF("Before starting threads from the child\n"); FORKEE_ASSERT(pthread_barrier_init( - _concurrent_signals_barrier, NULL, - __arraycount(threads)) == 0); + _concurrent_barrier, NULL, + signal_threads) == 0); - for (i = 0; i < __arraycount(threads); i++) { - FORKEE_ASSERT(pthread_create([i], NULL, + for (i = 0; i < signal_threads; i++) { + FORKEE_ASSERT(pthread_create(_threads[i], NULL, thread_concurrent_signals_thread, NULL) == 0); } DPRINTF("Before joining threads from the child\n"); - for (i = 0; i < __arraycount(threads); i++) { - FORKEE_ASSERT(pthread_join(threads[i], NULL) == 0); + for (i = 0; i < signal_threads; i++) { + FORKEE_ASSERT(pthread_join(sig_threads[i], NULL) == 0); } FORKEE_ASSERT(pthread_barrier_destroy( - _concurrent_signals_barrier) == 0); + _concurrent_barrier) == 0); DPRINTF("Before exiting of the child process\n"); _exit(exitval); @@ -8748,14 +8744,35 @@ ATF_TC_BODY(thread_concurrent_signals, t SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); } - for (i = 0; i < __arraycount(signal_counts); i++) + for (i = 0; i < signal_threads; i++) ATF_CHECK_EQ_MSG(signal_counts[i].lec_count, 1, "signal_counts[%d].lec_count=%d; lec_lwp=%d", i, signal_counts[i].lec_count, signal_counts[i].lec_lwp); + for (i = signal_threads; i < THREAD_CONCURRENT_SIGNALS_NUM; i++) + ATF_CHECK_EQ_MSG(signal_counts[i].lec_count, 0, + "extraneous
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Thu Feb 13 13:38:44 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: Disable UBSan warnings for trigger_segv() Dereferencing the NULL pointer is on purpose. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 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.20 src/tests/lib/libc/sys/t_ptrace_wait.h:1.21 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.20 Thu Feb 13 13:34:47 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Thu Feb 13 13:38:44 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.20 2020/02/13 13:34:47 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.21 2020/02/13 13:38:44 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -606,6 +606,11 @@ trigger_trap(void) #endif } +#if defined(__clang__) +__attribute__((no_sanitize("undefined"))) +#else +__attribute__((no_sanitize_undefined)) +#endif static void __used trigger_segv(void) {
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Thu Feb 13 13:34:48 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.h Log Message: Disable UBSan reports in trigger_fpe() Division by 0 is on purpose. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 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.19 src/tests/lib/libc/sys/t_ptrace_wait.h:1.20 --- src/tests/lib/libc/sys/t_ptrace_wait.h:1.19 Tue Feb 11 00:41:37 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.h Thu Feb 13 13:34:47 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.h,v 1.19 2020/02/11 00:41:37 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.h,v 1.20 2020/02/13 13:34:47 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -642,6 +642,11 @@ are_fpu_exceptions_supported(void) return true; } +#if defined(__clang__) +__attribute__((no_sanitize("undefined"))) +#else +__attribute__((no_sanitize_undefined)) +#endif static void __used trigger_fpe(void) {
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: christos Date: Thu Feb 13 02:53:46 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Turn off optimization on a function which contains constant labels. The optimizer splits it and we end up with 2 copies and duplicate symbols. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.18 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.19 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.18 Wed Jan 8 12:23:34 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Wed Feb 12 21:53:46 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.18 2020/01/08 17:23:34 mgorny Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.19 2020/02/13 02:53:46 christos Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -1971,7 +1971,7 @@ ATF_TC_HEAD(x86_cve_2018_8897, tc) #define X86_CVE_2018_8897_PAGE 0x5000 /* page addressable by 32-bit registers */ -static void +static __attribute__((__optimize__("O0"))) void x86_cve_2018_8897_trigger(void) { /*
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue Feb 11 00:41:37 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h Log Message: Rewrite the t_ptrace_wait resume1 test Switch to pthread functions. Rename to 'resume'. Synchronize the threads with pthread barriers. Avoid race in the test. Test passes correctly. Fixes PR bin/54893 by Andreas Gustafsson To generate a diff of this commit: cvs rdiff -u -r1.154 -r1.155 src/tests/lib/libc/sys/t_ptrace_wait.c cvs rdiff -u -r1.18 -r1.19 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.154 src/tests/lib/libc/sys/t_ptrace_wait.c:1.155 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.154 Mon Feb 10 11:42:41 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue Feb 11 00:41:37 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.154 2020/02/10 11:42:41 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.155 2020/02/11 00:41:37 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.154 2020/02/10 11:42:41 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.155 2020/02/11 00:41:37 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -7317,44 +7317,44 @@ ATF_TC_BODY(suspend_no_deadlock, tc) /// -volatile lwpid_t the_lwp_id = 0; +static pthread_barrier_t barrier1_resume; +static pthread_barrier_t barrier2_resume; -static void -lwp_main_stop(void *arg) +static void * +resume_thread(void *arg) { - the_lwp_id = _lwp_self(); - raise(SIGTRAP); + raise(SIGUSR1); + + pthread_barrier_wait(_resume); + + /* Debugger will suspend the process here */ + + pthread_barrier_wait(_resume); + + raise(SIGUSR2); - _lwp_exit(); + return infinite_thread(arg); } -ATF_TC(resume1); -ATF_TC_HEAD(resume1, tc) +ATF_TC(resume); +ATF_TC_HEAD(resume, tc) { atf_tc_set_md_var(tc, "descr", "Verify that a thread can be suspended by a debugger and later " "resumed by the debugger"); } -ATF_TC_BODY(resume1, tc) +ATF_TC_BODY(resume, tc) { - struct msg_fds fds; - const int exitval = 5; const int sigval = SIGSTOP; pid_t child, wpid; - uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ #if defined(TWAIT_HAVE_STATUS) int status; #endif - ucontext_t uc; lwpid_t lid; - static const size_t ssize = 16*1024; - void *stack; - struct ptrace_lwpinfo pl; struct ptrace_siginfo psi; - - SYSCALL_REQUIRE(msg_open() == 0); + pthread_t t; DPRINTF("Before forking process PID=%d\n", getpid()); SYSCALL_REQUIRE((child = fork()) != -1); @@ -7362,31 +7362,20 @@ ATF_TC_BODY(resume1, tc) DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + pthread_barrier_init(_resume, NULL, 2); + pthread_barrier_init(_resume, NULL, 2); + DPRINTF("Before raising %s from child\n", strsignal(sigval)); FORKEE_ASSERT(raise(sigval) == 0); - DPRINTF("Before allocating memory for stack in child\n"); - FORKEE_ASSERT((stack = malloc(ssize)) != NULL); - - DPRINTF("Before making context for new lwp in child\n"); - _lwp_makecontext(, lwp_main_stop, NULL, NULL, stack, ssize); + DPRINTF("Before creating new thread in child\n"); + FORKEE_ASSERT(pthread_create(, NULL, resume_thread, NULL) == 0); - DPRINTF("Before creating new in child\n"); - FORKEE_ASSERT(_lwp_create(, 0, ) == 0); + pthread_barrier_wait(_resume); - CHILD_TO_PARENT("Message", fds, msg); + pthread_barrier_wait(_resume); - raise(SIGINT); - - DPRINTF("Before waiting for lwp %d to exit\n", lid); - FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); - - DPRINTF("Before verifying that reported %d and running lid %d " - "are the same\n", lid, the_lwp_id); - FORKEE_ASSERT_EQ(lid, the_lwp_id); - - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); + infinite_thread(NULL); } DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); @@ -7400,10 +7389,10 @@ ATF_TC_BODY(resume1, tc) SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); DPRINTF("Before calling %s() for the child - expected stopped " - "SIGTRAP\n", TWAIT_FNAME); + "SIGUSR1\n", TWAIT_FNAME); TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - validate_status_stopped(status, SIGTRAP); + validate_status_stopped(status, SIGUSR1); DPRINTF("Before reading siginfo and lwpid_t\n"); SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, , sizeof(psi)) != -1); @@ -7411,53 +7400,61 @@ ATF_TC_BODY(resume1, tc) DPRINTF("Before suspending LWP %d\n", psi.psi_lwpid); SYSCALL_REQUIRE(ptrace(PT_SUSPEND, child, NULL, psi.psi_lwpid) != -1); - PARENT_FROM_CHILD("Message", fds,
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Mon Feb 10 11:42:41 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Rename suspend2 to suspend_no_deadlock To generate a diff of this commit: cvs rdiff -u -r1.153 -r1.154 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.153 src/tests/lib/libc/sys/t_ptrace_wait.c:1.154 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.153 Wed Feb 5 23:43:18 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Mon Feb 10 11:42:41 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.153 2020/02/05 23:43:18 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.154 2020/02/10 11:42:41 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.153 2020/02/05 23:43:18 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.154 2020/02/10 11:42:41 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -7249,27 +7249,15 @@ ATF_TC_BODY(threads_and_exec, tc) /// -volatile lwpid_t the_lwp_id = 0; - -static void -lwp_main_stop(void *arg) -{ - the_lwp_id = _lwp_self(); - - raise(SIGTRAP); - - _lwp_exit(); -} - -ATF_TC(suspend2); -ATF_TC_HEAD(suspend2, tc) +ATF_TC(suspend_no_deadlock); +ATF_TC_HEAD(suspend_no_deadlock, tc) { atf_tc_set_md_var(tc, "descr", "Verify that the while the only thread within a process is " "suspended, the whole process cannot be unstopped"); } -ATF_TC_BODY(suspend2, tc) +ATF_TC_BODY(suspend_no_deadlock, tc) { const int exitval = 5; const int sigval = SIGSTOP; @@ -7327,6 +7315,20 @@ ATF_TC_BODY(suspend2, tc) TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); } +/// + +volatile lwpid_t the_lwp_id = 0; + +static void +lwp_main_stop(void *arg) +{ + the_lwp_id = _lwp_self(); + + raise(SIGTRAP); + + _lwp_exit(); +} + ATF_TC(resume1); ATF_TC_HEAD(resume1, tc) { @@ -9257,7 +9259,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, threads_and_exec); - ATF_TP_ADD_TC(tp, suspend2); + ATF_TP_ADD_TC(tp, suspend_no_deadlock); ATF_TP_ADD_TC(tp, resume1);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Wed Feb 5 23:43:18 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Refactor signal9 and signal10 tests in t_ptrace_wait* Remove signal9 and signal10. Reimplement the idea of these test in new trace_thread_lwpexit_masked_sigtrap, trace_thread_lwpcreate_masked_sigtrap and trace_thread_lwpcreate_and_exit_masked_sigtrap. This removes 2 tests directly using low-level lwp APIs. To generate a diff of this commit: cvs rdiff -u -r1.152 -r1.153 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.152 src/tests/lib/libc/sys/t_ptrace_wait.c:1.153 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.152 Tue Feb 4 21:34:47 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Wed Feb 5 23:43:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.152 2020/02/04 21:34:47 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.153 2020/02/05 23:43:18 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.152 2020/02/04 21:34:47 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.153 2020/02/05 23:43:18 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -6395,7 +6395,7 @@ trace_threads_cb(void *arg __unused) } static void -trace_threads(bool trace_create, bool trace_exit) +trace_threads(bool trace_create, bool trace_exit, bool masked) { const int sigval = SIGSTOP; pid_t child, wpid; @@ -6408,6 +6408,8 @@ trace_threads(bool trace_create, bool tr const int elen = sizeof(event); struct ptrace_siginfo info; + sigset_t intmask; + pthread_t t[TRACE_THREADS_NUM]; int rv; size_t n; @@ -6422,6 +6424,12 @@ trace_threads(bool trace_create, bool tr DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + if (masked) { + sigemptyset(); + sigaddset(, SIGTRAP); + sigprocmask(SIG_BLOCK, , NULL); + } + DPRINTF("Before raising %s from child\n", strsignal(sigval)); FORKEE_ASSERT(raise(sigval) == 0); @@ -6570,7 +6578,7 @@ trace_threads(bool trace_create, bool tr TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); } -#define TRACE_THREADS(test, trace_create, trace_exit) \ +#define TRACE_THREADS(test, trace_create, trace_exit, mask) \ ATF_TC(test);\ ATF_TC_HEAD(test, tc) \ { \ @@ -6583,13 +6591,17 @@ ATF_TC_HEAD(test, tc) \ ATF_TC_BODY(test, tc) \ { \ \ -trace_threads(trace_create, trace_exit); \ +trace_threads(trace_create, trace_exit, mask); \ } -TRACE_THREADS(trace_thread_nolwpevents, false, false) -TRACE_THREADS(trace_thread_lwpexit, false, true) -TRACE_THREADS(trace_thread_lwpcreate, true, false) -TRACE_THREADS(trace_thread_lwpcreate_and_exit, true, true) +TRACE_THREADS(trace_thread_nolwpevents, false, false, false) +TRACE_THREADS(trace_thread_lwpexit, false, true, false) +TRACE_THREADS(trace_thread_lwpcreate, true, false, false) +TRACE_THREADS(trace_thread_lwpcreate_and_exit, true, true, false) + +TRACE_THREADS(trace_thread_lwpexit_masked_sigtrap, false, true, true) +TRACE_THREADS(trace_thread_lwpcreate_masked_sigtrap, true, false, true) +TRACE_THREADS(trace_thread_lwpcreate_and_exit_masked_sigtrap, true, true, true) /// @@ -7240,217 +7252,6 @@ ATF_TC_BODY(threads_and_exec, tc) volatile lwpid_t the_lwp_id = 0; static void -lwp_main_func(void *arg) -{ - the_lwp_id = _lwp_self(); - _lwp_exit(); -} - -ATF_TC(signal9); -ATF_TC_HEAD(signal9, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Verify that masking SIGTRAP in tracee does not stop tracer from " - "catching PTRACE_LWP_CREATE breakpoint"); -} - -ATF_TC_BODY(signal9, tc) -{ - const int exitval = 5; - const int sigval = SIGSTOP; - const int sigmasked = SIGTRAP; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - int status; -#endif - sigset_t intmask; - ptrace_state_t state; - const int slen = sizeof(state); - ptrace_event_t event; - const int elen = sizeof(event); - ucontext_t uc; - lwpid_t lid; - static const size_t ssize = 16*1024; - void *stack; - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - sigemptyset(); - sigaddset(, sigmasked); - sigprocmask(SIG_BLOCK, , NULL); - - DPRINTF("Before raising %s from child\n", strsignal(sigval)); - FORKEE_ASSERT(raise(sigval) == 0); - - DPRINTF("Before allocating memory for stack in child\n"); - FORKEE_ASSERT((stack = malloc(ssize)) != NULL); - -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue Feb 4 21:34:47 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Disable debug code To generate a diff of this commit: cvs rdiff -u -r1.151 -r1.152 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.151 src/tests/lib/libc/sys/t_ptrace_wait.c:1.152 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.151 Tue Feb 4 21:34:12 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue Feb 4 21:34:47 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.151 2020/02/04 21:34:12 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.152 2020/02/04 21:34:47 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.151 2020/02/04 21:34:12 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.152 2020/02/04 21:34:47 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -116,7 +116,7 @@ static_assert(sizeof(((struct ptrace_sta #define SYSCALL_REQUIRE_ERRNO(res, exp) ATF_REQUIRE_MSG(res == exp, \ "%d(%s) != %d", res, strerror(res), exp) -static int debug = 1; +static int debug = 0; #define DPRINTF(a, ...) do \ if (debug) \
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue Feb 4 21:34:12 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Add new ATF ptrace(2) test in t_ptrace_wait* threads_and_exec - verify that the expected LWP events are reported for a multithreaded process that calls execve(2). Test passes. To generate a diff of this commit: cvs rdiff -u -r1.150 -r1.151 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.150 src/tests/lib/libc/sys/t_ptrace_wait.c:1.151 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.150 Tue Feb 4 15:06:27 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue Feb 4 21:34:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.150 2020/02/04 15:06:27 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.151 2020/02/04 21:34:12 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.150 2020/02/04 15:06:27 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.151 2020/02/04 21:34:12 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -7048,6 +7048,195 @@ FORK2_TEST(vforkdone_singalignored, "vfo /// +static void * +thread_and_exec_thread_cb(void *arg __unused) +{ + + execlp("/bin/echo", "/bin/echo", NULL); + + abort(); +} + +static void +threads_and_exec(void) +{ + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_state_t state; + const int slen = sizeof(state); + ptrace_event_t event; + const int elen = sizeof(event); + struct ptrace_siginfo info; + + pthread_t t; + lwpid_t lid; + + DPRINTF("Before forking process PID=%d\n", getpid()); + SYSCALL_REQUIRE((child = fork()) != -1); + if (child == 0) { + DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + DPRINTF("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + FORKEE_ASSERT(pthread_create(, NULL, + thread_and_exec_thread_cb, NULL) == 0); + + for (;;) + continue; + + FORKEE_ASSERT(0 && "Not reached"); + } + DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); + + validate_status_stopped(status, sigval); + + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); + SYSCALL_REQUIRE( + ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); + + DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); + DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", + info.psi_siginfo.si_signo, info.psi_siginfo.si_code, + info.psi_siginfo.si_errno); + + ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); + + DPRINTF("Set LWP event mask for the child %d\n", child); + memset(, 0, sizeof(event)); + event.pe_set_event |= PTRACE_LWP_CREATE | PTRACE_LWP_EXIT; + SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, , elen) != -1); + + DPRINTF("Before resuming the child process where it left off and " + "without signal to be sent\n"); + SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + DPRINTF("Before calling %s() for the child - expected stopped " + "SIGTRAP\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), + child); + + validate_status_stopped(status, SIGTRAP); + + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for " + "child\n"); + SYSCALL_REQUIRE( + ptrace(PT_GET_SIGINFO, child, , sizeof(info)) != -1); + + DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); + DPRINTF("Signal properties: si_signo=%#x si_code=%#x " + "si_errno=%#x\n", + info.psi_siginfo.si_signo, info.psi_siginfo.si_code, + info.psi_siginfo.si_errno); + + ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); + ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_LWP); + + SYSCALL_REQUIRE( + ptrace(PT_GET_PROCESS_STATE, child, , slen) != -1); + + ATF_REQUIRE_EQ_MSG(state.pe_report_event, PTRACE_LWP_CREATE, + "%d != %d", state.pe_report_event, PTRACE_LWP_CREATE); + + lid = state.pe_lwp; + DPRINTF("Reported PTRACE_LWP_CREATE event with lid %d\n", lid); + + DPRINTF("Before resuming the child process where it left off " + "and without signal to be sent\n"); + SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + DPRINTF("Before calling %s() for the child - expected stopped " + "SIGTRAP\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), + child); + + validate_status_stopped(status, SIGTRAP); + + DPRINTF("Before
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue Feb 4 15:06:27 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Add new ATF tests for unrelated tracer in t_ptrace_wait* New tests: - unrelated_tracer_posix_spawn_detach_spawner - unrelated_tracer_fork_detach_forker - unrelated_tracer_vfork_detach_vforker - unrelated_tracer_vfork_detach_vforkerdone - unrelated_tracer_posix_spawn_kill_spawner - unrelated_tracer_fork_kill_forker - unrelated_tracer_vfork_kill_vforker - unrelated_tracer_vfork_kill_vforkerdone All tests pass. To generate a diff of this commit: cvs rdiff -u -r1.149 -r1.150 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.149 src/tests/lib/libc/sys/t_ptrace_wait.c:1.150 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.149 Wed Jan 29 03:51:56 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue Feb 4 15:06:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.149 2020/01/29 03:51:56 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.150 2020/02/04 15:06:27 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.149 2020/01/29 03:51:56 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.150 2020/02/04 15:06:27 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -116,7 +116,7 @@ static_assert(sizeof(((struct ptrace_sta #define SYSCALL_REQUIRE_ERRNO(res, exp) ATF_REQUIRE_MSG(res == exp, \ "%d(%s) != %d", res, strerror(res), exp) -static int debug = 0; +static int debug = 1; #define DPRINTF(a, ...) do \ if (debug) \ @@ -3869,6 +3869,292 @@ FORK_DETACH_FORKER(vfork_kill_vforkerdon /// +#if defined(TWAIT_HAVE_PID) +static void +unrelated_tracer_fork_detach_forker_body(const char *fn, bool kill_process) +{ + const int sigval = SIGSTOP; + struct msg_fds parent_tracee, parent_tracer; + const int exitval = 10; + const int exitval2 = 0; /* This matched exit status from /bin/echo */ + pid_t tracee, tracer, wpid; + pid_t tracee2 = 0; + uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + int op; + + struct ptrace_siginfo info; + ptrace_state_t state; + const int slen = sizeof(state); + ptrace_event_t event; + const int elen = sizeof(event); + + char * const arg[] = { __UNCONST("/bin/echo"), NULL }; + + DPRINTF("Spawn tracee\n"); + SYSCALL_REQUIRE(msg_open(_tracee) == 0); + tracee = atf_utils_fork(); + if (tracee == 0) { + // Wait for parent to let us crash + CHILD_FROM_PARENT("exit tracee", parent_tracee, msg); + + DPRINTF("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + if (strcmp(fn, "spawn") == 0) { + FORKEE_ASSERT_EQ(posix_spawn(, + arg[0], NULL, NULL, arg, NULL), 0); + } else { + if (strcmp(fn, "fork") == 0) { +FORKEE_ASSERT((tracee2 = fork()) != -1); + } else { +FORKEE_ASSERT((tracee2 = vfork()) != -1); + } + + if (tracee2 == 0) +_exit(exitval2); + } + + FORKEE_REQUIRE_SUCCESS + (wpid = TWAIT_GENERIC(tracee2, , 0), tracee2); + + forkee_status_exited(status, exitval2); + + DPRINTF("Before exiting of the child process\n"); + _exit(exitval); + } + + DPRINTF("Spawn debugger\n"); + SYSCALL_REQUIRE(msg_open(_tracer) == 0); + tracer = atf_utils_fork(); + if (tracer == 0) { + /* Fork again and drop parent to reattach to PID 1 */ + tracer = atf_utils_fork(); + if (tracer != 0) + _exit(exitval); + + DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); + + /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ + FORKEE_REQUIRE_SUCCESS( + wpid = TWAIT_GENERIC(tracee, , 0), tracee); + + forkee_status_stopped(status, SIGSTOP); + + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for the " + "traced process\n"); + SYSCALL_REQUIRE( + ptrace(PT_GET_SIGINFO, tracee, , sizeof(info)) != -1); + + DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); + DPRINTF("Signal properties: si_signo=%#x si_code=%#x " + "si_errno=%#x\n", info.psi_siginfo.si_signo, + info.psi_siginfo.si_code, info.psi_siginfo.si_errno); + + FORKEE_ASSERT_EQ(info.psi_siginfo.si_signo, SIGSTOP); + FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, SI_USER); + + /* Resume tracee with PT_CONTINUE */ + FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); + + /* Inform parent that tracer has attached to tracee */ + CHILD_TO_PARENT("tracer ready", parent_tracer, msg); + + /* Wait for parent to tell use that tracee should have exited */ + CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Wed Jan 29 03:51:56 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Add new fork/vfork/posix_spawn ATF tests in t_ptrace_wait* Add unrelated tracer variation of tests: fork1-16, vfork1-16, posix_spawn1-16. All tests pass. To generate a diff of this commit: cvs rdiff -u -r1.148 -r1.149 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.148 src/tests/lib/libc/sys/t_ptrace_wait.c:1.149 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.148 Thu Jan 23 06:17:21 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Wed Jan 29 03:51:56 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.148 2020/01/23 06:17:21 martin Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.149 2020/01/29 03:51:56 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.148 2020/01/23 06:17:21 martin Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.149 2020/01/29 03:51:56 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -3312,6 +3312,374 @@ FORK_TEST(posix_spawn16, "spawn", true, #if defined(TWAIT_HAVE_PID) static void +unrelated_tracer_fork_body(const char *fn, bool trackspawn, bool trackfork, +bool trackvfork, bool trackvforkdone) +{ + const int sigval = SIGSTOP; + struct msg_fds parent_tracee, parent_tracer; + const int exitval = 10; + const int exitval2 = 0; /* This matched exit status from /bin/echo */ + pid_t tracee, tracer, wpid; + pid_t tracee2 = 0; + uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + + struct ptrace_siginfo info; + ptrace_state_t state; + const int slen = sizeof(state); + ptrace_event_t event; + const int elen = sizeof(event); + + char * const arg[] = { __UNCONST("/bin/echo"), NULL }; + + DPRINTF("Spawn tracee\n"); + SYSCALL_REQUIRE(msg_open(_tracee) == 0); + tracee = atf_utils_fork(); + if (tracee == 0) { + // Wait for parent to let us crash + CHILD_FROM_PARENT("exit tracee", parent_tracee, msg); + + DPRINTF("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + if (strcmp(fn, "spawn") == 0) { + FORKEE_ASSERT_EQ(posix_spawn(, + arg[0], NULL, NULL, arg, NULL), 0); + } else { + if (strcmp(fn, "fork") == 0) { +FORKEE_ASSERT((tracee2 = fork()) != -1); + } else if (strcmp(fn, "vfork") == 0) { +FORKEE_ASSERT((tracee2 = vfork()) != -1); + } + + if (tracee2 == 0) +_exit(exitval2); + } + FORKEE_REQUIRE_SUCCESS + (wpid = TWAIT_GENERIC(tracee2, , 0), tracee2); + + forkee_status_exited(status, exitval2); + + DPRINTF("Before exiting of the child process\n"); + _exit(exitval); + } + + DPRINTF("Spawn debugger\n"); + SYSCALL_REQUIRE(msg_open(_tracer) == 0); + tracer = atf_utils_fork(); + if (tracer == 0) { + /* Fork again and drop parent to reattach to PID 1 */ + tracer = atf_utils_fork(); + if (tracer != 0) + _exit(exitval); + + DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); + + /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ + FORKEE_REQUIRE_SUCCESS( + wpid = TWAIT_GENERIC(tracee, , 0), tracee); + + forkee_status_stopped(status, SIGSTOP); + + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for the " + "traced process\n"); + SYSCALL_REQUIRE( + ptrace(PT_GET_SIGINFO, tracee, , sizeof(info)) != -1); + + DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); + DPRINTF("Signal properties: si_signo=%#x si_code=%#x " + "si_errno=%#x\n", info.psi_siginfo.si_signo, + info.psi_siginfo.si_code, info.psi_siginfo.si_errno); + + FORKEE_ASSERT_EQ(info.psi_siginfo.si_signo, SIGSTOP); + FORKEE_ASSERT_EQ(info.psi_siginfo.si_code, SI_USER); + + /* Resume tracee with PT_CONTINUE */ + FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); + + /* Inform parent that tracer has attached to tracee */ + CHILD_TO_PARENT("tracer ready", parent_tracer, msg); + + /* Wait for parent to tell use that tracee should have exited */ + CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg); + + /* Wait for tracee and assert that it exited */ + FORKEE_REQUIRE_SUCCESS( + wpid = TWAIT_GENERIC(tracee, , 0), tracee); + + forkee_status_stopped(status, sigval); + + DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for the " + "traced process\n"); + SYSCALL_REQUIRE( + ptrace(PT_GET_SIGINFO, tracee, , sizeof(info)) != -1); + + DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); + DPRINTF("Signal properties: si_signo=%#x si_code=%#x " + "si_errno=%#x\n", info.psi_siginfo.si_signo, + info.psi_siginfo.si_code,
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: skrll Date: Fri Jan 24 08:45:16 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_mlock.c Log Message: Don't print the pagesize it messes up atf-report To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_mlock.c 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_mlock.c diff -u src/tests/lib/libc/sys/t_mlock.c:1.7 src/tests/lib/libc/sys/t_mlock.c:1.8 --- src/tests/lib/libc/sys/t_mlock.c:1.7 Wed Mar 13 08:50:12 2019 +++ src/tests/lib/libc/sys/t_mlock.c Fri Jan 24 08:45:16 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_mlock.c,v 1.7 2019/03/13 08:50:12 kre Exp $ */ +/* $NetBSD: t_mlock.c,v 1.8 2020/01/24 08:45:16 skrll Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_mlock.c,v 1.7 2019/03/13 08:50:12 kre Exp $"); +__RCSID("$NetBSD: t_mlock.c,v 1.8 2020/01/24 08:45:16 skrll Exp $"); #include #include @@ -302,7 +302,6 @@ ATF_TP_ADD_TCS(tp) { page = sysconf(_SC_PAGESIZE); - fprintf(stderr, "t_mlock: pagesize %ld\n", page); ATF_REQUIRE(page >= 0); ATF_TP_ADD_TC(tp, mlock_clip);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: martin Date: Thu Jan 23 06:17:22 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Fix the build: access_regs_set_unaligned_pc_* tests depend on availability of gpregs To generate a diff of this commit: cvs rdiff -u -r1.147 -r1.148 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.147 src/tests/lib/libc/sys/t_ptrace_wait.c:1.148 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.147 Tue Jan 21 16:46:07 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Thu Jan 23 06:17:21 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.147 2020/01/21 16:46:07 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.148 2020/01/23 06:17:21 martin Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.147 2020/01/21 16:46:07 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.148 2020/01/23 06:17:21 martin Exp $"); #define __LEGACY_PT_LWPINFO @@ -8449,9 +8449,9 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs5); ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs6); - ATF_TP_ADD_TC(tp, access_regs_set_unaligned_pc_0x1); - ATF_TP_ADD_TC(tp, access_regs_set_unaligned_pc_0x3); - ATF_TP_ADD_TC(tp, access_regs_set_unaligned_pc_0x7); + ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs_set_unaligned_pc_0x1); + ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs_set_unaligned_pc_0x3); + ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs_set_unaligned_pc_0x7); ATF_TP_ADD_TC_HAVE_FPREGS(tp, access_fpregs1); ATF_TP_ADD_TC_HAVE_FPREGS(tp, access_fpregs2);
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: kamil Date: Tue Jan 21 16:46:07 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Add new ATF tests in t_ptrace_wait* New tests: - access_regs_set_unaligned_pc_0x1 - access_regs_set_unaligned_pc_0x3 - access_regs_set_unaligned_pc_0x7 The purpose of these tests is check whether unaligned PC can panic the kernel. If there is a panic it is fine to return EINVAL on PT_SETREGS. New tests check respectively pc |= 0x1, pc |= 0x3 and pc |= 0x7. Inspired by https://marc.info/?l=openbsd-bugs=107558043319084=2 While there fix access_regs6 to really test PT_SETREGS. To generate a diff of this commit: cvs rdiff -u -r1.146 -r1.147 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.146 src/tests/lib/libc/sys/t_ptrace_wait.c:1.147 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.146 Wed Jan 8 17:22:40 2020 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Tue Jan 21 16:46:07 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.146 2020/01/08 17:22:40 mgorny Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.147 2020/01/21 16:46:07 kamil Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.146 2020/01/08 17:22:40 mgorny Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.147 2020/01/21 16:46:07 kamil Exp $"); #define __LEGACY_PT_LWPINFO @@ -4439,9 +4439,22 @@ access_regs(const char *regset, const ch } else if (strcmp(aux, "pc") == 0) { rgstr = PTRACE_REG_PC(); DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr); - } else if (strcmp(aux, "set_pc") == 0) { + } else if (strstr(aux, "set_pc") != NULL) { rgstr = PTRACE_REG_PC(); + DPRINTF("Retrieved PC %" PRIxREGISTER "\n", rgstr); + if (strstr(aux, "0x1") != NULL) { +rgstr |= 0x1; + } else if (strstr(aux, "0x3") != NULL) { +rgstr |= 0x3; + } else if (strstr(aux, "0x7") != NULL) { +rgstr |= 0x7; + } + DPRINTF("Set PC %" PRIxREGISTER "\n", rgstr); PTRACE_REG_SET_PC(, rgstr); + if (strcmp(aux, "set_pc") != 0) { +/* This call can fail with EINVAL or similar. */ +ptrace(PT_SETREGS, child, , 0); + } } else if (strcmp(aux, "sp") == 0) { rgstr = PTRACE_REG_SP(); DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr); @@ -4451,7 +4464,7 @@ access_regs(const char *regset, const ch } else if (strcmp(aux, "setregs") == 0) { DPRINTF("Call SETREGS for the child process\n"); SYSCALL_REQUIRE( - ptrace(PT_GETREGS, child, , 0) != -1); + ptrace(PT_SETREGS, child, , 0) != -1); } } #endif @@ -4475,13 +4488,31 @@ access_regs(const char *regset, const ch "without signal to be sent\n"); SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); + if (strstr(aux, "unaligned") != NULL) { + DPRINTF("Before resuming the child process where it left off " + "and without signal to be sent\n"); + SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1); - validate_status_exited(status, exitval); + DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), + child); - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); + validate_status_signaled(status, SIGKILL, 0); + + DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, + wpid = TWAIT_GENERIC(child, , 0)); + } else { + DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS( + wpid = TWAIT_GENERIC(child, , 0), child); + + validate_status_exited(status, exitval); + + DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, + wpid = TWAIT_GENERIC(child, , 0)); + } } #define ACCESS_REGS(test, regset, aux) \ @@ -4506,6 +4537,9 @@ ACCESS_REGS(access_regs3, "regs", "set_p ACCESS_REGS(access_regs4, "regs", "sp") ACCESS_REGS(access_regs5, "regs", "intrv") ACCESS_REGS(access_regs6, "regs", "setregs") +ACCESS_REGS(access_regs_set_unaligned_pc_0x1, "regs", "set_pc+unaligned+0x1") +ACCESS_REGS(access_regs_set_unaligned_pc_0x3, "regs", "set_pc+unaligned+0x3") +ACCESS_REGS(access_regs_set_unaligned_pc_0x7, "regs", "set_pc+unaligned+0x7") #endif #if defined(HAVE_FPREGS) ACCESS_REGS(access_fpregs1, "fpregs", "getfpregs") @@ -8415,6 +8449,10 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs5); ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs6); + ATF_TP_ADD_TC(tp, access_regs_set_unaligned_pc_0x1); + ATF_TP_ADD_TC(tp, access_regs_set_unaligned_pc_0x3); +
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Wed Jan 8 17:23:34 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_x86_wait.h Log Message: Add tests for reading registers from x86 core dumps To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_ptrace_x86_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_x86_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.17 src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.18 --- src/tests/lib/libc/sys/t_ptrace_x86_wait.h:1.17 Wed Jan 8 17:23:15 2020 +++ src/tests/lib/libc/sys/t_ptrace_x86_wait.h Wed Jan 8 17:23:34 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_x86_wait.h,v 1.17 2020/01/08 17:23:15 mgorny Exp $ */ +/* $NetBSD: t_ptrace_x86_wait.h,v 1.18 2020/01/08 17:23:34 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -2225,7 +2225,8 @@ enum x86_test_registers { enum x86_test_regmode { TEST_GETREGS, - TEST_SETREGS + TEST_SETREGS, + TEST_COREDUMP }; static __inline void get_gp32_regs(union x86_test_register out[]) @@ -2687,8 +2688,10 @@ x86_register_test(enum x86_test_regset r #endif struct xstate xst; struct iovec iov; - struct fxsave* fxs; + struct fxsave* fxs = NULL; uint64_t xst_flags = 0; + char core_path[] = "/tmp/core.XX"; + int core_fd; const union x86_test_register expected[] __aligned(32) = { {{ 0x0706050403020100, 0x0F0E0D0C0B0A0908, @@ -2796,6 +2799,7 @@ x86_register_test(enum x86_test_regset r DPRINTF("Before running assembly from child\n"); switch (regmode) { case TEST_GETREGS: + case TEST_COREDUMP: switch (regs) { case GPREGS_32: set_gp32_regs(expected); @@ -2969,40 +2973,7 @@ x86_register_test(enum x86_test_regset r validate_status_stopped(status, sigval); - switch (regset) { - case TEST_GPREGS: - ATF_REQUIRE(regs < FPREGS_MM); - DPRINTF("Call GETREGS for the child process\n"); - SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, , 0) != -1); - break; - case TEST_XMMREGS: -#if defined(__i386__) - ATF_REQUIRE(regs >= FPREGS_MM && regs < FPREGS_YMM); - DPRINTF("Call GETXMMREGS for the child process\n"); - SYSCALL_REQUIRE(ptrace(PT_GETXMMREGS, child, , 0) != -1); - fxs = - break; -#else - /*FALLTHROUGH*/ -#endif - case TEST_FPREGS: -#if defined(__x86_64__) - ATF_REQUIRE(regs >= FPREGS_MM && regs < FPREGS_YMM); - fxs = -#else - ATF_REQUIRE(regs >= FPREGS_MM && regs < FPREGS_XMM); -#endif - DPRINTF("Call GETFPREGS for the child process\n"); - SYSCALL_REQUIRE(ptrace(PT_GETFPREGS, child, , 0) != -1); - break; - case TEST_XSTATE: - ATF_REQUIRE(regs >= FPREGS_MM); - iov.iov_base = - iov.iov_len = sizeof(xst); - - DPRINTF("Call GETXSTATE for the child process\n"); - SYSCALL_REQUIRE(ptrace(PT_GETXSTATE, child, , 0) != -1); - + if (regset == TEST_XSTATE) { switch (regs) { case FPREGS_MM: xst_flags |= XCR0_X87; @@ -3020,21 +2991,117 @@ x86_register_test(enum x86_test_regset r __unreachable(); break; } + } - ATF_REQUIRE((xst.xs_rfbm & xst_flags) == xst_flags); - switch (regmode) { - case TEST_SETREGS: - xst.xs_rfbm = xst_flags; - xst.xs_xstate_bv = xst_flags; + switch (regmode) { + case TEST_GETREGS: + case TEST_SETREGS: + switch (regset) { + case TEST_GPREGS: + ATF_REQUIRE(regs < FPREGS_MM); + DPRINTF("Call GETREGS for the child process\n"); + SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, , 0) + != -1); break; - case TEST_GETREGS: + case TEST_XMMREGS: +#if defined(__i386__) + ATF_REQUIRE(regs >= FPREGS_MM && regs < FPREGS_YMM); + DPRINTF("Call GETXMMREGS for the child process\n"); + SYSCALL_REQUIRE(ptrace(PT_GETXMMREGS, child, , 0) + != -1); + fxs = + break; +#else + /*FALLTHROUGH*/ +#endif + case TEST_FPREGS: +#if defined(__x86_64__) + ATF_REQUIRE(regs >= FPREGS_MM && regs < FPREGS_YMM); + fxs = +#else + ATF_REQUIRE(regs >= FPREGS_MM && regs < FPREGS_XMM); +#endif + DPRINTF("Call GETFPREGS for the child process\n"); + SYSCALL_REQUIRE(ptrace(PT_GETFPREGS, child, , 0) + != -1); + break; + case TEST_XSTATE: + ATF_REQUIRE(regs >= FPREGS_MM); + iov.iov_base = + iov.iov_len = sizeof(xst); + + DPRINTF("Call GETXSTATE for the child process\n"); + SYSCALL_REQUIRE(ptrace(PT_GETXSTATE, child, , 0) + != -1); + + ATF_REQUIRE((xst.xs_rfbm & xst_flags) == xst_flags); + switch (regmode) { + case TEST_SETREGS: +xst.xs_rfbm = xst_flags; +xst.xs_xstate_bv = xst_flags; +break; + case TEST_GETREGS: +ATF_REQUIRE((xst.xs_xstate_bv & xst_flags) +== xst_flags); +break; + case TEST_COREDUMP: +__unreachable(); +break; + } + + fxs = _fxsave; + break; + } + break; + case TEST_COREDUMP: + SYSCALL_REQUIRE((core_fd = mkstemp(core_path)) != -1); + close(core_fd); + + DPRINTF("Call DUMPCORE for the child process\n"); +
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Wed Jan 8 17:23:15 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_amd64_wait.h t_ptrace_i386_wait.h t_ptrace_x86_wait.h Log Message: Combine x86 register tests into unified test function Reduce the code duplication and improve maintainability of x86 register tests by combining all of them to a single base function. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/lib/libc/sys/t_ptrace_amd64_wait.h cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/sys/t_ptrace_i386_wait.h cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libc/sys/t_ptrace_x86_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_amd64_wait.h diff -u src/tests/lib/libc/sys/t_ptrace_amd64_wait.h:1.11 src/tests/lib/libc/sys/t_ptrace_amd64_wait.h:1.12 --- src/tests/lib/libc/sys/t_ptrace_amd64_wait.h:1.11 Tue Jun 4 12:17:05 2019 +++ src/tests/lib/libc/sys/t_ptrace_amd64_wait.h Wed Jan 8 17:23:15 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_amd64_wait.h,v 1.11 2019/06/04 12:17:05 mgorny Exp $ */ +/* $NetBSD: t_ptrace_amd64_wait.h,v 1.12 2020/01/08 17:23:15 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -111,415 +111,11 @@ ATF_TC_BODY(x86_64_regs1, tc) TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); } -ATF_TC(x86_64_regs_gp_read); -ATF_TC_HEAD(x86_64_regs_gp_read, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Set general-purpose reg values from debugged program and read " - "them via PT_GETREGS, comparing values against expected."); -} - -ATF_TC_BODY(x86_64_regs_gp_read, tc) -{ - const int exitval = 5; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - const int sigval = SIGTRAP; - int status; -#endif - struct reg gpr; - - const uint64_t rax = 0x0001020304050607; - const uint64_t rbx = 0x1011121314151617; - const uint64_t rcx = 0x2021222324252627; - const uint64_t rdx = 0x3031323334353637; - const uint64_t rsi = 0x4041424344454647; - const uint64_t rdi = 0x5051525354555657; - const uint64_t rsp = 0x6061626364656667; - const uint64_t rbp = 0x7071727374757677; - - DPRINTF("Before forking process PID=%d\n", getpid()); - SYSCALL_REQUIRE((child = fork()) != -1); - if (child == 0) { - DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); - FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); - - DPRINTF("Before running assembly from child\n"); - - __asm__ __volatile__( - /* rbp & rbp are a bit tricky, we must not clobber them */ - "movq%%rsp, %%r8\n\t" - "movq%%rbp, %%r9\n\t" - "movq%6, %%rsp\n\t" - "movq%7, %%rbp\n\t" - "\n\t" - "int3\n\t" - "\n\t" - "movq%%r8, %%rsp\n\t" - "movq%%r9, %%rbp\n\t" - : - : "a"(rax), "b"(rbx), "c"(rcx), "d"(rdx), "S"(rsi), "D"(rdi), - "i"(rsp), "i"(rbp) - : "%r8", "%r9" - ); - - DPRINTF("Before exiting of the child process\n"); - _exit(exitval); - } - DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_stopped(status, sigval); - - DPRINTF("Call GETREGS for the child process\n"); - SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, , 0) != -1); - - ATF_CHECK_EQ((uint64_t)gpr.regs[_REG_RAX], rax); - ATF_CHECK_EQ((uint64_t)gpr.regs[_REG_RBX], rbx); - ATF_CHECK_EQ((uint64_t)gpr.regs[_REG_RCX], rcx); - ATF_CHECK_EQ((uint64_t)gpr.regs[_REG_RDX], rdx); - ATF_CHECK_EQ((uint64_t)gpr.regs[_REG_RSI], rsi); - ATF_CHECK_EQ((uint64_t)gpr.regs[_REG_RDI], rdi); - ATF_CHECK_EQ((uint64_t)gpr.regs[_REG_RSP], rsp); - ATF_CHECK_EQ((uint64_t)gpr.regs[_REG_RBP], rbp); - - DPRINTF("Before resuming the child process where it left off and " - "without signal to be sent\n"); - SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, , 0), child); - - validate_status_exited(status, exitval); - - DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); - TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, , 0)); -} - -ATF_TC(x86_64_regs_gp_write); -ATF_TC_HEAD(x86_64_regs_gp_write, tc) -{ - atf_tc_set_md_var(tc, "descr", - "Set general-purpose reg values into a debugged program via " - "PT_SETREGS and compare the result against expected."); -} - -ATF_TC_BODY(x86_64_regs_gp_write, tc) -{ - const int exitval = 5; - pid_t child, wpid; -#if defined(TWAIT_HAVE_STATUS) - const int sigval = SIGTRAP; - int status; -#endif - struct reg gpr; - - const uint64_t rax = 0x0001020304050607; - const uint64_t rbx = 0x1011121314151617; - const uint64_t rcx = 0x2021222324252627; - const uint64_t rdx = 0x3031323334353637; - const uint64_t rsi = 0x4041424344454647; - const uint64_t rdi = 0x5051525354555657; -
CVS commit: src/tests/lib/libc/sys
Module Name:src Committed By: mgorny Date: Wed Jan 8 17:22:40 UTC 2020 Modified Files: src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: Fix alignment when reading core notes Both desc and note header needs to be aligned. Therefore, we need to realign after skipping past desc as well. While at it, fix the other alignment fix to use roundup() macro. To generate a diff of this commit: cvs rdiff -u -r1.145 -r1.146 src/tests/lib/libc/sys/t_ptrace_wait.c 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.c diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.145 src/tests/lib/libc/sys/t_ptrace_wait.c:1.146 --- src/tests/lib/libc/sys/t_ptrace_wait.c:1.145 Wed Dec 25 02:23:37 2019 +++ src/tests/lib/libc/sys/t_ptrace_wait.c Wed Jan 8 17:22:40 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.145 2019/12/25 02:23:37 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.146 2020/01/08 17:22:40 mgorny Exp $ */ /*- * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.145 2019/12/25 02:23:37 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.146 2020/01/08 17:22:40 mgorny Exp $"); #define __LEGACY_PT_LWPINFO @@ -7837,8 +7837,7 @@ static ssize_t core_find_note(const char offset += note_hdr.n_namesz; /* fix to alignment */ - offset = ((offset + core_hdr.p_align - 1) - / core_hdr.p_align) * core_hdr.p_align; + offset = roundup(offset, core_hdr.p_align); /* if name & type matched above */ if (ret != -1) { @@ -7850,6 +7849,8 @@ static ssize_t core_find_note(const char } offset += note_hdr.n_descsz; + /* fix to alignment */ + offset = roundup(offset, core_hdr.p_align); } }