Date: Thu, 10 Feb 2011 01:07:58 +0200 From: Ali Polatel <alip@exherbo.org> To: Kostik Belousov <kostikbel@gmail.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: ptrace weirdness with 9.0-CURRENT Message-ID: <87fwrw9581.fsf@karatren.ev> In-Reply-To: <20110208235542.GH78089@deviant.kiev.zoral.com.ua> References: <87fwrydu7s.fsf@karatren.ev> <20110208234952.GG78089@deviant.kiev.zoral.com.ua> <20110208235542.GH78089@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-=-= Content-Transfer-Encoding: quoted-printable On Wed, 9 Feb 2011 01:55:42 +0200, Kostik Belousov <kostikbel@gmail.com> wr= ote: > On Wed, Feb 09, 2011 at 01:49:52AM +0200, Kostik Belousov wrote: > > 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/pinktra= ce/ > > > - 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 libr= ary > > > 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). Ah interesting. > > The issue with sigprocmask call from setjmp shall be fixed, but this > > is not an issue with ptrace(2). >=20 > The following should fix the problem. I confirm that this patch fixes the problem, thanks! =20 > diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c > index 50ab393..948cf49 100644 > --- a/libexec/rtld-elf/rtld.c > +++ b/libexec/rtld-elf/rtld.c > @@ -560,7 +560,7 @@ _rtld_bind(Obj_Entry *obj, Elf_Size reloff) > RtldLockState lockstate; >=20=20 > rlock_acquire(rtld_bind_lock, &lockstate); > - if (setjmp(lockstate.env) !=3D 0) > + if (sigsetjmp(lockstate.env, 0) !=3D 0) > lock_upgrade(rtld_bind_lock, &lockstate); > if (obj->pltrel) > rel =3D (const Elf_Rel *) ((caddr_t) obj->pltrel + reloff); > @@ -2142,7 +2142,7 @@ dlopen(const char *name, int mode) > ld_tracing =3D (mode & RTLD_TRACE) =3D=3D 0 ? NULL : "1"; > if (ld_tracing !=3D NULL) { > rlock_acquire(rtld_bind_lock, &lockstate); > - if (setjmp(lockstate.env) !=3D 0) > + if (sigsetjmp(lockstate.env, 0) !=3D 0) > lock_upgrade(rtld_bind_lock, &lockstate); > environ =3D (char **)*get_program_var_addr("environ", &lockstate); > lock_release(rtld_bind_lock, &lockstate); > @@ -2264,7 +2264,7 @@ do_dlsym(void *handle, const char *name, void *reta= ddr, const Ver_Entry *ve, > req.lockstate =3D &lockstate; >=20=20 > rlock_acquire(rtld_bind_lock, &lockstate); > - if (setjmp(lockstate.env) !=3D 0) > + if (sigsetjmp(lockstate.env, 0) !=3D 0) > lock_upgrade(rtld_bind_lock, &lockstate); > if (handle =3D=3D NULL || handle =3D=3D RTLD_NEXT || > handle =3D=3D RTLD_DEFAULT || handle =3D=3D RTLD_SELF) { > diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h > index 8941d29..bb365a7 100644 > --- a/libexec/rtld-elf/rtld.h > +++ b/libexec/rtld-elf/rtld.h > @@ -276,7 +276,7 @@ typedef struct Struct_DoneList { >=20=20 > struct Struct_RtldLockState { > int lockstate; > - jmp_buf env; > + sigjmp_buf env; > }; >=20=20 > /* > diff --git a/libexec/rtld-elf/rtld_lock.c b/libexec/rtld-elf/rtld_lock.c > index e76a4da..024e1e2 100644 > --- a/libexec/rtld-elf/rtld_lock.c > +++ b/libexec/rtld-elf/rtld_lock.c > @@ -259,7 +259,7 @@ lock_restart_for_upgrade(RtldLockState *lockstate) > case RTLD_LOCK_WLOCKED: > break; > case RTLD_LOCK_RLOCKED: > - longjmp(lockstate->env, 1); > + siglongjmp(lockstate->env, 1); > break; > default: > assert(0); =2D-=20 Regards, Ali Polatel --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iEYEARECAAYFAk1THlQACgkQQU4yORhF8iAxRQCeIJiSlayl8G+85db+KvnbMz3p dGsAn3JV0xCN8ZD9bLlxYsRz9ug9I3ic =UIXh -----END PGP SIGNATURE----- --=-=-=--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87fwrw9581.fsf>