Wed Jun 24 04:47:10 2020 UTC ()
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.


(rin)
diff -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_core_wait.h

cvs diff -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_core_wait.h (expand / switch to unified diff)

--- src/tests/lib/libc/sys/t_ptrace_core_wait.h 2020/05/05 01:24:29 1.1
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h 2020/06/24 04:47:10 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_ptrace_core_wait.h,v 1.1 2020/05/05 01:24:29 kamil Exp $ */ 1/* $NetBSD: t_ptrace_core_wait.h,v 1.2 2020/06/24 04:47:10 rin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -197,26 +197,41 @@ ATF_TC_BODY(core_dump_procinfo, tc) @@ -197,26 +197,41 @@ ATF_TC_BODY(core_dump_procinfo, tc)
197 ATF_CHECK_EQ(procinfo.cpi_pgrp, getpgid(child)); 197 ATF_CHECK_EQ(procinfo.cpi_pgrp, getpgid(child));
198 ATF_CHECK_EQ(procinfo.cpi_sid, getsid(child)); 198 ATF_CHECK_EQ(procinfo.cpi_sid, getsid(child));
199 ATF_CHECK_EQ(procinfo.cpi_ruid, getuid()); 199 ATF_CHECK_EQ(procinfo.cpi_ruid, getuid());
200 ATF_CHECK_EQ(procinfo.cpi_euid, geteuid()); 200 ATF_CHECK_EQ(procinfo.cpi_euid, geteuid());
201 ATF_CHECK_EQ(procinfo.cpi_rgid, getgid()); 201 ATF_CHECK_EQ(procinfo.cpi_rgid, getgid());
202 ATF_CHECK_EQ(procinfo.cpi_egid, getegid()); 202 ATF_CHECK_EQ(procinfo.cpi_egid, getegid());
203 ATF_CHECK_EQ(procinfo.cpi_nlwps, 1); 203 ATF_CHECK_EQ(procinfo.cpi_nlwps, 1);
204 ATF_CHECK(procinfo.cpi_siglwp > 0); 204 ATF_CHECK(procinfo.cpi_siglwp > 0);
205 205
206 unlink(core_path); 206 unlink(core_path);
207 207
208 DPRINTF("Before resuming the child process where it left off and " 208 DPRINTF("Before resuming the child process where it left off and "
209 "without signal to be sent\n"); 209 "without signal to be sent\n");
 210#ifndef __powerpc__
210 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 211 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 212#else
 213 /*
 214 * For powerpc, program counter is not automatically incremented by
 215 * a trap instruction. We cannot increment PC in the trap handler,
 216 * which breaks applications depending on this behavior, e.g., GDB.
 217 * Therefore, we need to pass (PC + 4) instead of (void *)1 (== PC)
 218 * to PT_CONTINUE here.
 219 */
 220 struct reg r;
 221
 222 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1);
 223 SYSCALL_REQUIRE(
 224 ptrace(PT_CONTINUE, child, (void *)(r.pc + 4), 0) != -1);
 225#endif
211 226
212 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 227 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
213 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 228 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
214 229
215 validate_status_exited(status, exitval); 230 validate_status_exited(status, exitval);
216 231
217 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 232 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
218 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 233 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
219} 234}
220 235
221#define ATF_TP_ADD_TCS_PTRACE_WAIT_CORE() \ 236#define ATF_TP_ADD_TCS_PTRACE_WAIT_CORE() \
222 ATF_TP_ADD_TC(tp, core_dump_procinfo); 237 ATF_TP_ADD_TC(tp, core_dump_procinfo);