From owner-svn-src-user@freebsd.org Mon Jul 18 09:19:46 2016 Return-Path: <owner-svn-src-user@freebsd.org> Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8B4CFB9CB1F for <svn-src-user@mailman.ysv.freebsd.org>; Mon, 18 Jul 2016 09:19:46 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6866B14BF; Mon, 18 Jul 2016 09:19:46 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u6I9JjkP060060; Mon, 18 Jul 2016 09:19:45 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6I9JjwW060059; Mon, 18 Jul 2016 09:19:45 GMT (envelope-from pho@FreeBSD.org) Message-Id: <201607180919.u6I9JjwW060059@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm <pho@FreeBSD.org> Date: Mon, 18 Jul 2016 09:19:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r302996 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" <svn-src-user.freebsd.org> List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-user>, <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/> List-Post: <mailto:svn-src-user@freebsd.org> List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help> List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-user>, <mailto:svn-src-user-request@freebsd.org?subject=subscribe> X-List-Received-Date: Mon, 18 Jul 2016 09:19:46 -0000 Author: pho Date: Mon Jul 18 09:19:45 2016 New Revision: 302996 URL: https://svnweb.freebsd.org/changeset/base/302996 Log: Added a regression test. Sponsored by: EMC / Isilon Storage Division Added: user/pho/stress2/misc/ptrace8.sh (contents, props changed) Added: user/pho/stress2/misc/ptrace8.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/ptrace8.sh Mon Jul 18 09:19:45 2016 (r302996) @@ -0,0 +1,124 @@ +#!/bin/sh + +# +# Copyright (c) 2016 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# A regression test for r302919. +# Triggered a witness message: +# +# vmspace_free() called with the following non-sleepable locks held: +# shared rw vm object (vm object) r = 0 locked @ kern/sys_process.c:432 + +. ../default.cfg + +dir=/tmp +odir=`pwd` +cd $dir +sed '1,/^EOF/d' < $odir/$0 > $dir/ptrace8.c +mycc -o ptrace8 -Wall -Wextra -O0 -g ptrace8.c || exit 1 +rm -f ptrace8.c +cd $odir + +/tmp/ptrace8 +s=$? + +rm -rf /tmp/ptrace8 +exit $s + +EOF +#include <sys/param.h> +#include <sys/mman.h> +#include <sys/ptrace.h> +#include <sys/stat.h> +#include <sys/wait.h> + +#include <machine/atomic.h> + +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> + +volatile u_int *share; + +#define SYNC 0 + +int +main(void) +{ + struct ptrace_vm_entry ent; + size_t len; + int pid, r, status; + char path[MAXPATHLEN + 1]; + + len = PAGE_SIZE; + if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) + err(1, "mmap"); + + if ((pid = fork()) == 0) { + while (share[SYNC] == 0) + sleep(1); + + _exit(0); + } + + if (ptrace(PT_ATTACH, pid, 0, 0) == -1) + err(1, "ptrace"); + + if (waitpid(pid, &status, 0) == -1) + err(1, "waitpid"); + else if (!WIFSTOPPED(status)) + errx(1, "failed to stop child"); + + ent.pve_entry = 0; + ent.pve_path = path; + ent.pve_pathlen = sizeof(path); + do { + r = ptrace(PT_VM_ENTRY, pid, (caddr_t)&ent, 0); +#if defined(DEBUG) + if (r == 0) + fprintf(stderr, "path = %s 0x%lx - 0x%lx\n", + ent.pve_path, ent.pve_start, ent.pve_end); +#endif + } while (r == 0); + if (r == -1 && errno != ENOENT) + err(1, "ptrace(PT_VM_ENTRY)"); + + share[SYNC] = 1; + if (ptrace(PT_DETACH, pid, 0, 0) == -1) + err(1, "ptrace"); + + if (waitpid(pid, &status, 0) == -1) + err(1, "waitpid(%d)", pid); + + return (status != 0); +}