From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 8 22:57:10 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 A67A7106566B for ; Tue, 8 Feb 2011 22:57:10 +0000 (UTC) (envelope-from alip@exherbo.org) Received: from bach.exherbo.org (bach.exherbo.org [78.47.197.147]) by mx1.freebsd.org (Postfix) with ESMTP id 0B1808FC08 for ; Tue, 8 Feb 2011 22:57:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=karatren.karatren.ev ident=alip) by bach.exherbo.org with esmtpa (Exim 4.71) (envelope-from ) id 1PmwFx-0002IH-3I for freebsd-hackers@freebsd.org; Tue, 08 Feb 2011 22:41:57 +0000 Received: by karatren.karatren.ev (Postfix, from userid 1000) id 7B14A2588B; Wed, 9 Feb 2011 00:42:18 +0200 (EET) From: Ali Polatel To: FreeBSD Hackers User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.2.1 (x86_64-pc-linux-gnu) Date: Wed, 09 Feb 2011 00:42:15 +0200 Message-ID: <87fwrydu7s.fsf@karatren.ev> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Subject: 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 22:57:10 -0000 --=-=-= Content-Transfer-Encoding: quoted-printable Hello everyone, I'm the developer of pinktrace - http://dev.exherbo.org/~alip/pinktrace/ =2D 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. 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: % 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 =2D------------------------------------------------------------- >>> World build completed on Wed Feb 9 00:23:30 EET 2011 =2D------------------------------------------------------------- % gcc -Wall ptrace-amd64-fbsd-return.c % ./a.out retval:0 error:0 $ 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 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: #include #include #include #include #include #include #include #include #include #include #include #include #undef NDEBUG #include int main(void) { int status; pid_t pid; 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); 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); #if defined(PT_LWPINFO) && defined(PL_FLAG_SCX) struct ptrace_lwpinfo info; assert(!(ptrace(PT_LWPINFO, pid, (caddr_t)&info, sizeof(struct ptrace_lwp= info)) < 0)); assert(info.pl_flags & PL_FLAG_SCX); #endif struct reg r; assert(!(ptrace(PT_GETREGS, pid, (caddr_t)&r, 0) < 0)); printf("retval:%ld error:%d\n", r.r_rax, !!(r.r_rflags & PSL_C)); ptrace(PT_CONTINUE, pid, (caddr_t)1, 0); waitpid(pid, &status, 0); return 0; } } =2D-=20 Regards, Ali Polatel --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iEYEARECAAYFAk1RxskACgkQQU4yORhF8iBBxgCguEk/Js8WyUlDQaXIJ6PwygdD AqIAn3F6cdQeqiODzStm1UKxiRSUYa05 =rnOI -----END PGP SIGNATURE----- --=-=-=--