From owner-svn-src-all@FreeBSD.ORG Wed Feb 10 00:11:59 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 819461065693; Wed, 10 Feb 2010 00:11:59 +0000 (UTC) (envelope-from xcllnt@mac.com) Received: from asmtpout029.mac.com (asmtpout029.mac.com [17.148.16.104]) by mx1.freebsd.org (Postfix) with ESMTP id 6205A8FC13; Wed, 10 Feb 2010 00:11:59 +0000 (UTC) MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_n1FZHhxZlAiiO2ipDJ1qwg)" Received: from [172.24.241.171] (natint3.juniper.net [66.129.224.36]) by asmtp029.mac.com (Sun Java(tm) System Messaging Server 6.3-8.01 (built Dec 16 2008; 32bit)) with ESMTPSA id <0KXL00C2KN7JFI70@asmtp029.mac.com>; Tue, 09 Feb 2010 16:11:47 -0800 (PST) X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=5.0.0-0908210000 definitions=main-1002090247 From: Marcel Moolenaar In-reply-to: <896B58E6-12EA-48AB-86C2-5BA9F0C59512@mac.com> Date: Tue, 09 Feb 2010 16:11:43 -0800 Message-id: <86989446-64EF-411F-8E25-173DB6AEE10B@mac.com> References: <201002090552.o195qZcD074581@svn.freebsd.org> <20100209095722.GQ9991@deviant.kiev.zoral.com.ua> <65DCE552-7EFD-48F2-85A4-EA0F1F0638EE@mac.com> <20100209184043.GV9991@deviant.kiev.zoral.com.ua> <896B58E6-12EA-48AB-86C2-5BA9F0C59512@mac.com> To: Kostik Belousov X-Mailer: Apple Mail (2.1077) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r203696 - in head: lib/libc/sys sys/kern sys/sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Feb 2010 00:11:59 -0000 --Boundary_(ID_n1FZHhxZlAiiO2ipDJ1qwg) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT On Feb 9, 2010, at 11:17 AM, Marcel Moolenaar wrote: > Action items: > >>>> - vmspace should be referenced by vmspace_acquire_ref() >>>> - vm_map should be read-locked before iterating the map entries. > > I'll implement it and send a patch for review to avoid unnecessary > repository churn... Please review attached patch. I have a sample session of how a debugger can use the information (see XXX lines): hob% /usr/obj/nfs/bsddbg/trunk/bdb/bdb images/abort/abort [cursor=0x2000000000000560:0] bdb> run process 1539 created process 1539 stopped with signal 5 XXX: 1: 0x2000000000000000-0x2000000000001fff, 5, 0 37 `/nfs/bsddbg/trunk/images/abort/abort` XXX: 2: 0x2000000000010000-0x2000000000011fff, 3, 0 0 `` XXX: 3: 0x2000000040010000-0x2000000040077fff, 5, 0 21 `/libexec/ld-elf.so.1` XXX: 4: 0x2000000040086000-0x2000000040089fff, 3, 0x66000 21 `/libexec/ld-elf.so.1` XXX: 5: 0x200000004008a000-0x2000000040091fff, 3, 0 0 `` XXX: 6: 0x8000000000000000-0x800000000001ffff, 3, 0 0 `` XXX: 7: 0x9ffffffffffe0000-0x9fffffffffffffff, 3, 0 0 `` 0x200000004001c560: { // MFB; > alloc r2 = ar.pfs, 0x0, 0x3, 0x3, 0x0 nop.f 0x0 nop.b 0x0 ;; } [cursor=0x200000004001c560:0] bdb> step process 1575 stopped with signal 5 0x200000004001c560: { // MFB; alloc r2 = ar.pfs, 0x0, 0x3, 0x3, 0x0 > nop.f 0x0 nop.b 0x0 ;; } [cursor=0x200000004001c560:1] bdb> continue process 1539 stopped with signal 6 XXX: 1: 0x2000000000000000-0x2000000000001fff, 5, 0 37 `/nfs/bsddbg/trunk/images/abort/abort` XXX: 2: 0x2000000000010000-0x2000000000011fff, 3, 0 0 `` XXX: 3: 0x2000000040010000-0x2000000040077fff, 5, 0 21 `/libexec/ld-elf.so.1` XXX: 4: 0x200000004007e000-0x2000000040085fff, 3, 0x6000 0 `` XXX: 5: 0x2000000040086000-0x2000000040089fff, 3, 0x66000 21 `/libexec/ld-elf.so.1` XXX: 6: 0x200000004008a000-0x2000000040099fff, 3, 0 0 `` XXX: 7: 0x200000004009c000-0x20000000402e1fff, 5, 0 15 `/lib/libc.so.7` XXX: 8: 0x20000000402e2000-0x20000000402effff, 0, 0x246000 0 `` XXX: 9: 0x20000000402f0000-0x20000000402fdfff, 3, 0x244000 15 `/lib/libc.so.7` XXX: 10: 0x20000000402fe000-0x2000000040319fff, 3, 0x262000 0 `` XXX: 11: 0x2000000040328000-0x2000000040339fff, 3, 0xe000 0 `` XXX: 12: 0x8000000000000000-0x800000000001ffff, 3, 0 0 `` XXX: 13: 0x9ffffffffffe0000-0x9fffffffffffffff, 3, 0 0 `` 0x20000000402a0c40: { // MBB; > cmp.eq p0, p6 = r0, r10 (p6) br.sptk.few 20000000400ded00 br.ret.sptk.few rp ;; } [cursor=0x20000000402a0c40:0] bdb> -- Marcel Moolenaar xcllnt@mac.com --Boundary_(ID_n1FZHhxZlAiiO2ipDJ1qwg) Content-type: application/octet-stream; name=ptrace.diff Content-transfer-encoding: 7bit Content-disposition: attachment; filename=ptrace.diff Index: kern/sys_process.c =================================================================== --- kern/sys_process.c (revision 203724) +++ kern/sys_process.c (working copy) @@ -75,7 +75,8 @@ }; struct ptrace_vm_entry32 { - uint32_t pve_cookie; + int pve_entry; + int pve_timestamp; uint32_t pve_start; uint32_t pve_end; uint32_t pve_offset; @@ -363,42 +364,56 @@ vm_map_t map; vm_map_entry_t entry; vm_object_t obj, tobj, lobj; + struct vmspace *vm; struct vnode *vp; char *freepath, *fullpath; u_int pathlen; - int error, vfslocked; + int error, index, vfslocked; - map = &p->p_vmspace->vm_map; + vm = vmspace_acquire_ref(p); + map = &vm->vm_map; + vm_map_lock_read(map); + entry = map->header.next; - if (pve->pve_cookie != NULL) { - while (entry != &map->header && entry != pve->pve_cookie) - entry = entry->next; - if (entry != pve->pve_cookie) - return (EINVAL); + index = 0; + while (index < pve->pve_entry && entry != &map->header) { entry = entry->next; + index++; } - while (entry != &map->header && (entry->eflags & MAP_ENTRY_IS_SUB_MAP)) + if (index != pve->pve_entry) { + error = EINVAL; + goto out; + } + while (entry != &map->header && + (entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) { entry = entry->next; - if (entry == &map->header) - return (ENOENT); + index++; + } + if (entry == &map->header) { + error = ENOENT; + goto out; + } /* We got an entry. */ - pve->pve_cookie = entry; + pve->pve_entry = index + 1; + pve->pve_timestamp = map->timestamp; pve->pve_start = entry->start; pve->pve_end = entry->end - 1; pve->pve_offset = entry->offset; pve->pve_prot = entry->protection; + error = 0; + /* Backing object's path needed? */ if (pve->pve_pathlen == 0) - return (0); + goto out; pathlen = pve->pve_pathlen; pve->pve_pathlen = 0; obj = entry->object.vm_object; if (obj == NULL) - return (0); + goto out; VM_OBJECT_LOCK(obj); for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) { @@ -420,7 +435,7 @@ vp = NULL; if (vp == NULL) - return (0); + goto out; freepath = NULL; fullpath = NULL; @@ -429,7 +444,6 @@ vrele(vp); VFS_UNLOCK_GIANT(vfslocked); - error = 0; if (fullpath != NULL) { pve->pve_pathlen = strlen(fullpath) + 1; if (pve->pve_pathlen <= pathlen) { @@ -440,9 +454,40 @@ } if (freepath != NULL) free(freepath, M_TEMP); + + out: + vm_map_unlock_read(map); + vmspace_free(vm); return (error); } +#ifdef COMPAT_IA32 +static int +ptrace_vm_entry32(struct thread *td, struct proc *p, + struct ptrace_vm_entry32 *pve32) +{ + struct ptrace_vm_entry pve; + int error; + + pve.pve_entry = pve32->pve_entry; + pve.pve_pathlen = pve32->pve_pathlen; + pve.pve_path = (void *)(uintptr_t)pve32->pve_path; + + error = ptrace_vm_entry(td, p, &pve); + if (error == 0) { + pve32->pve_entry = pve.pve_entry; + pve32->pve_timestamp = pve.pve_timestamp; + pve32->pve_start = pve.pve_start; + pve32->pve_end = pve.pve_end; + pve32->pve_offset = pve.pve_offset; + pve32->pve_prot = pve.pve_prot; + } + + pve32->pve_pathlen = pve.pve_pathlen; + return (error); +} +#endif /* COMPAT_IA32 */ + /* * Process debugging system call. */ @@ -1087,14 +1132,12 @@ break; case PT_VM_ENTRY: + PROC_UNLOCK(p); #ifdef COMPAT_IA32 - /* XXX to be implemented. */ - if (wrap32) { - error = EDOOFUS; - break; - } + if (wrap32) + error = ptrace_vm_entry32(td, p, addr); + else #endif - PROC_UNLOCK(p); error = ptrace_vm_entry(td, p, addr); PROC_LOCK(p); break; Index: sys/ptrace.h =================================================================== --- sys/ptrace.h (revision 203724) +++ sys/ptrace.h (working copy) @@ -104,7 +104,8 @@ /* Argument structure for PT_VM_ENTRY. */ struct ptrace_vm_entry { - void *pve_cookie; /* Token used to iterate. */ + int pve_entry; /* Entry number used for iteration. */ + int pve_timestamp; /* Generation number of VM map. */ u_long pve_start; /* Start VA of range. */ u_long pve_end; /* End VA of range (incl). */ u_long pve_offset; /* Offset in backing object. */ --Boundary_(ID_n1FZHhxZlAiiO2ipDJ1qwg)--