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 <sys/cdefs.h> -__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, &info, 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, &info, 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. @@ -3050,7 +3050,7 @@ x86_register_test(enum x86_test_regset r ATF_REQUIRE(regs < FPREGS_MM); DPRINTF("Parse core file for PT_GETREGS\n"); ATF_REQUIRE_EQ(core_find_note(core_path, - "NetBSD-CORE@1", PT_GETREGS, &gpr, sizeof(gpr)), + "NetBSD-CORE@*", PT_GETREGS, &gpr, sizeof(gpr)), sizeof(gpr)); break; case TEST_XMMREGS: @@ -3071,14 +3071,14 @@ x86_register_test(enum x86_test_regset r #endif DPRINTF("Parse core file for PT_GETFPREGS\n"); ATF_REQUIRE_EQ(core_find_note(core_path, - "NetBSD-CORE@1", PT_GETFPREGS, &fpr, sizeof(fpr)), + "NetBSD-CORE@*", PT_GETFPREGS, &fpr, sizeof(fpr)), sizeof(fpr)); break; case TEST_XSTATE: ATF_REQUIRE(regs >= FPREGS_MM); DPRINTF("Parse core file for PT_GETXSTATE\n"); ATF_REQUIRE_EQ(core_find_note(core_path, - "NetBSD-CORE@1", PT_GETXSTATE, &xst, sizeof(xst)), + "NetBSD-CORE@*", PT_GETXSTATE, &xst, sizeof(xst)), sizeof(xst)); ATF_REQUIRE((xst.xs_xstate_bv & xst_flags) == xst_flags);