From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 8 23:49:58 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 22D8D1065670 for ; Tue, 8 Feb 2011 23:49:58 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id AE2AD8FC13 for ; Tue, 8 Feb 2011 23:49:57 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id p18NnqrD091904 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 9 Feb 2011 01:49:52 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id p18Nnq4j086788; Wed, 9 Feb 2011 01:49:52 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id p18NnqEe086787; Wed, 9 Feb 2011 01:49:52 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 9 Feb 2011 01:49:52 +0200 From: Kostik Belousov To: Ali Polatel Message-ID: <20110208234952.GG78089@deviant.kiev.zoral.com.ua> References: <87fwrydu7s.fsf@karatren.ev> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="h6w+13shfCQ8v2Yw" Content-Disposition: inline In-Reply-To: <87fwrydu7s.fsf@karatren.ev> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: FreeBSD Hackers Subject: Re: ptrace weirdness with 9.0-CURRENT X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Feb 2011 23:49:58 -0000 --h6w+13shfCQ8v2Yw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 09, 2011 at 12:42:15AM +0200, Ali Polatel wrote: > Hello everyone, >=20 > I'm the developer of pinktrace - http://dev.exherbo.org/~alip/pinktrace/ > - a simple ptrace() wrapper library for FreeBSD and Linux. I have set up > a FreeBSD-9.0-CURRENT VM today to test various new features recently > added to ptrace(). This is about a behaviour difference between > 8.1-RELEASE and 9.0-CURRENT which I've noticed through a unit test of > pinktrace. I don't want to bother you with the internals of this library > so I'll briefly explain the problem. >=20 > I've inserted the testcase I've used below. The aim is to trace a > open(NULL, 0) call which should fail with EFAULT. Running this on two > different VMs I get: >=20 > % uname -a > FreeBSD 9.0-CURRENT FreeBSD 9.0-CURRENT #0: Wed Feb 9 05:02:31 EET 2011= root@:/usr/obj/usr/src/sys/GENERIC amd64 > % sudo cat /root/world.txt > -------------------------------------------------------------- > >>> World build completed on Wed Feb 9 00:23:30 EET 2011 > -------------------------------------------------------------- > % gcc -Wall ptrace-amd64-fbsd-return.c > % ./a.out > retval:0 error:0 >=20 > $ uname -a > FreeBSD 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:36:49 UTC 2010= root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 > $ gcc -Wall ptrace-amd64-fbsd-return.c > $ ./a.out > retval:14 error:1 > $=20 >=20 > Important note: I couldn't notice a problem with truss tracing a > open(NULL, 0) call so I think this is a problem with my testcase. > I'll be happy if you can shed some light on what I'm doing wrong here: There is no issue with ptrace(2). Your test fails because, apparently, rtld in HEAD calls setjmp(3) when resolving symbols, and setjmp(3) calls sigprocmask(2). The end result is that you get SCX event for sigprocmask, and not for your open(2). The issue with sigprocmask call from setjmp shall be fixed, but this is not an issue with ptrace(2). >=20 > #include > #include > #include >=20 > #include > #include >=20 > #include > #include > #include > #include > #include > #include > #include >=20 > #undef NDEBUG > #include >=20 > int > main(void) > { > int status; > pid_t pid; >=20 > if ((pid =3D fork()) < 0) { > perror("fork"); > abort(); > } > else if (!pid) { /* child */ > assert(!(ptrace(PT_TRACE_ME, 0, NULL, 0) < 0)); > kill(getpid(), SIGSTOP); > open(NULL, 0); > fprintf(stderr, "open: (errno:%d %s)\n", errno, strerror(errno)); > _exit(0); > } > else { > assert(!(waitpid(pid, &status, 0) < 0)); > assert(WIFSTOPPED(status)); > assert(WSTOPSIG(status) =3D=3D SIGSTOP); >=20 > assert(!(ptrace(PT_TO_SCX, pid, (caddr_t)1, 0) < 0)); > assert(!(waitpid(pid, &status, 0) < 0)); > assert(WIFSTOPPED(status)); > assert(WSTOPSIG(status) =3D=3D SIGTRAP); >=20 > #if defined(PT_LWPINFO) && defined(PL_FLAG_SCX) > struct ptrace_lwpinfo info; > assert(!(ptrace(PT_LWPINFO, pid, (caddr_t)&info, sizeof(struct ptrace_l= wpinfo)) < 0)); > assert(info.pl_flags & PL_FLAG_SCX); > #endif >=20 > struct reg r; > assert(!(ptrace(PT_GETREGS, pid, (caddr_t)&r, 0) < 0)); >=20 > printf("retval:%ld error:%d\n", r.r_rax, !!(r.r_rflags & PSL_C)); >=20 > ptrace(PT_CONTINUE, pid, (caddr_t)1, 0); > waitpid(pid, &status, 0); >=20 > return 0; > } > } >=20 > --=20 > Regards, > Ali Polatel --h6w+13shfCQ8v2Yw Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAk1R1p8ACgkQC3+MBN1Mb4hDMgCg6MXFbqChftKh9M55mW81nZ2T 9bUAnjVudJXmMtJfDZHJxj8tUDs9QTX9 =9c0P -----END PGP SIGNATURE----- --h6w+13shfCQ8v2Yw--