2 * Copyright (c) 1994, Sean Eric Fagan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Sean Eric Fagan.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_compat.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/mutex.h>
41 #include <sys/syscallsubr.h>
42 #include <sys/sysent.h>
43 #include <sys/sysproto.h>
45 #include <sys/vnode.h>
46 #include <sys/ptrace.h>
48 #include <sys/malloc.h>
49 #include <sys/signalvar.h>
51 #include <machine/reg.h>
53 #include <security/audit/audit.h>
57 #include <vm/vm_extern.h>
58 #include <vm/vm_map.h>
59 #include <vm/vm_kern.h>
60 #include <vm/vm_object.h>
61 #include <vm/vm_page.h>
62 #include <vm/vm_pager.h>
63 #include <vm/vm_param.h>
65 #ifdef COMPAT_FREEBSD32
66 #include <sys/procfs.h>
68 struct ptrace_io_desc32 {
75 struct ptrace_vm_entry32 {
91 * Functions implemented using PROC_ACTION():
93 * proc_read_regs(proc, regs)
94 * Get the current user-visible register set from the process
95 * and copy it into the regs structure (<machine/reg.h>).
96 * The process is stopped at the time read_regs is called.
98 * proc_write_regs(proc, regs)
99 * Update the current register set from the passed in regs
100 * structure. Take care to avoid clobbering special CPU
101 * registers or privileged bits in the PSL.
102 * Depending on the architecture this may have fix-up work to do,
103 * especially if the IAR or PCW are modified.
104 * The process is stopped at the time write_regs is called.
106 * proc_read_fpregs, proc_write_fpregs
107 * deal with the floating point register set, otherwise as above.
109 * proc_read_dbregs, proc_write_dbregs
110 * deal with the processor debug register set, otherwise as above.
113 * Arrange for the process to trap after executing a single instruction.
116 #define PROC_ACTION(action) do { \
119 PROC_LOCK_ASSERT(td->td_proc, MA_OWNED); \
120 if ((td->td_proc->p_flag & P_INMEM) == 0) \
128 proc_read_regs(struct thread *td, struct reg *regs)
131 PROC_ACTION(fill_regs(td, regs));
135 proc_write_regs(struct thread *td, struct reg *regs)
138 PROC_ACTION(set_regs(td, regs));
142 proc_read_dbregs(struct thread *td, struct dbreg *dbregs)
145 PROC_ACTION(fill_dbregs(td, dbregs));
149 proc_write_dbregs(struct thread *td, struct dbreg *dbregs)
152 PROC_ACTION(set_dbregs(td, dbregs));
156 * Ptrace doesn't support fpregs at all, and there are no security holes
157 * or translations for fpregs, so we can just copy them.
160 proc_read_fpregs(struct thread *td, struct fpreg *fpregs)
163 PROC_ACTION(fill_fpregs(td, fpregs));
167 proc_write_fpregs(struct thread *td, struct fpreg *fpregs)
170 PROC_ACTION(set_fpregs(td, fpregs));
173 #ifdef COMPAT_FREEBSD32
174 /* For 32 bit binaries, we need to expose the 32 bit regs layouts. */
176 proc_read_regs32(struct thread *td, struct reg32 *regs32)
179 PROC_ACTION(fill_regs32(td, regs32));
183 proc_write_regs32(struct thread *td, struct reg32 *regs32)
186 PROC_ACTION(set_regs32(td, regs32));
190 proc_read_dbregs32(struct thread *td, struct dbreg32 *dbregs32)
193 PROC_ACTION(fill_dbregs32(td, dbregs32));
197 proc_write_dbregs32(struct thread *td, struct dbreg32 *dbregs32)
200 PROC_ACTION(set_dbregs32(td, dbregs32));
204 proc_read_fpregs32(struct thread *td, struct fpreg32 *fpregs32)
207 PROC_ACTION(fill_fpregs32(td, fpregs32));
211 proc_write_fpregs32(struct thread *td, struct fpreg32 *fpregs32)
214 PROC_ACTION(set_fpregs32(td, fpregs32));
219 proc_sstep(struct thread *td)
222 PROC_ACTION(ptrace_single_step(td));
226 proc_rwmem(struct proc *p, struct uio *uio)
229 vm_object_t backing_object, object;
230 vm_offset_t pageno; /* page number */
235 * Assert that someone has locked this vmspace. (Should be
236 * curthread but we can't assert that.) This keeps the process
237 * from exiting out from under us until this operation completes.
239 KASSERT(p->p_lock >= 1, ("%s: process %p (pid %d) not held", __func__,
245 map = &p->p_vmspace->vm_map;
247 writing = uio->uio_rw == UIO_WRITE;
248 reqprot = writing ? VM_PROT_COPY | VM_PROT_READ : VM_PROT_READ;
251 * Only map in one page at a time. We don't have to, but it
252 * makes things easier. This way is trivial - right?
257 int page_offset; /* offset into page */
258 vm_map_entry_t out_entry;
267 uva = (vm_offset_t)uio->uio_offset;
270 * Get the page number of this segment.
272 pageno = trunc_page(uva);
273 page_offset = uva - pageno;
276 * How many bytes to copy
278 len = min(PAGE_SIZE - page_offset, uio->uio_resid);
281 * Fault the page on behalf of the process
283 error = vm_fault(map, pageno, reqprot, VM_FAULT_NORMAL);
285 if (error == KERN_RESOURCE_SHORTAGE)
293 * Now we need to get the page. out_entry and wired
294 * aren't used. One would think the vm code
295 * would be a *bit* nicer... We use tmap because
296 * vm_map_lookup() can change the map argument.
299 error = vm_map_lookup(&tmap, pageno, reqprot, &out_entry,
300 &object, &pindex, &out_prot, &wired);
305 VM_OBJECT_LOCK(object);
306 while ((m = vm_page_lookup(object, pindex)) == NULL &&
308 (backing_object = object->backing_object) != NULL) {
310 * Allow fallback to backing objects if we are reading.
312 VM_OBJECT_LOCK(backing_object);
313 pindex += OFF_TO_IDX(object->backing_object_offset);
314 VM_OBJECT_UNLOCK(object);
315 object = backing_object;
317 if (writing && m != NULL) {
319 vm_pager_page_unswapped(m);
321 VM_OBJECT_UNLOCK(object);
323 vm_map_lookup_done(tmap, out_entry);
329 * Hold the page in memory.
336 * We're done with tmap now.
338 vm_map_lookup_done(tmap, out_entry);
341 * Now do the i/o move.
343 error = uiomove_fromphys(&m, page_offset, len, uio);
345 /* Make the I-cache coherent for breakpoints. */
346 if (!error && writing && (out_prot & VM_PROT_EXECUTE))
347 vm_sync_icache(map, uva, len);
356 } while (error == 0 && uio->uio_resid > 0);
362 ptrace_vm_entry(struct thread *td, struct proc *p, struct ptrace_vm_entry *pve)
366 vm_map_entry_t entry;
367 vm_object_t obj, tobj, lobj;
370 char *freepath, *fullpath;
372 int error, index, vfslocked;
377 vm = vmspace_acquire_ref(p);
379 vm_map_lock_read(map);
382 entry = map->header.next;
384 while (index < pve->pve_entry && entry != &map->header) {
388 if (index != pve->pve_entry) {
392 while (entry != &map->header &&
393 (entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) {
397 if (entry == &map->header) {
402 /* We got an entry. */
403 pve->pve_entry = index + 1;
404 pve->pve_timestamp = map->timestamp;
405 pve->pve_start = entry->start;
406 pve->pve_end = entry->end - 1;
407 pve->pve_offset = entry->offset;
408 pve->pve_prot = entry->protection;
410 /* Backing object's path needed? */
411 if (pve->pve_pathlen == 0)
414 pathlen = pve->pve_pathlen;
415 pve->pve_pathlen = 0;
417 obj = entry->object.vm_object;
422 vm_map_unlock_read(map);
425 pve->pve_fsid = VNOVAL;
426 pve->pve_fileid = VNOVAL;
428 if (error == 0 && obj != NULL) {
430 for (tobj = obj; tobj != NULL; tobj = tobj->backing_object) {
432 VM_OBJECT_LOCK(tobj);
434 VM_OBJECT_UNLOCK(lobj);
436 pve->pve_offset += tobj->backing_object_offset;
438 vp = (lobj->type == OBJT_VNODE) ? lobj->handle : NULL;
442 VM_OBJECT_UNLOCK(lobj);
443 VM_OBJECT_UNLOCK(obj);
448 vn_fullpath(td, vp, &fullpath, &freepath);
449 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
450 vn_lock(vp, LK_SHARED | LK_RETRY);
451 if (VOP_GETATTR(vp, &vattr, td->td_ucred) == 0) {
452 pve->pve_fileid = vattr.va_fileid;
453 pve->pve_fsid = vattr.va_fsid;
456 VFS_UNLOCK_GIANT(vfslocked);
458 if (fullpath != NULL) {
459 pve->pve_pathlen = strlen(fullpath) + 1;
460 if (pve->pve_pathlen <= pathlen) {
461 error = copyout(fullpath, pve->pve_path,
464 error = ENAMETOOLONG;
466 if (freepath != NULL)
467 free(freepath, M_TEMP);
474 #ifdef COMPAT_FREEBSD32
476 ptrace_vm_entry32(struct thread *td, struct proc *p,
477 struct ptrace_vm_entry32 *pve32)
479 struct ptrace_vm_entry pve;
482 pve.pve_entry = pve32->pve_entry;
483 pve.pve_pathlen = pve32->pve_pathlen;
484 pve.pve_path = (void *)(uintptr_t)pve32->pve_path;
486 error = ptrace_vm_entry(td, p, &pve);
488 pve32->pve_entry = pve.pve_entry;
489 pve32->pve_timestamp = pve.pve_timestamp;
490 pve32->pve_start = pve.pve_start;
491 pve32->pve_end = pve.pve_end;
492 pve32->pve_offset = pve.pve_offset;
493 pve32->pve_prot = pve.pve_prot;
494 pve32->pve_fileid = pve.pve_fileid;
495 pve32->pve_fsid = pve.pve_fsid;
498 pve32->pve_pathlen = pve.pve_pathlen;
501 #endif /* COMPAT_FREEBSD32 */
504 * Process debugging system call.
506 #ifndef _SYS_SYSPROTO_H_
515 #ifdef COMPAT_FREEBSD32
517 * This CPP subterfuge is to try and reduce the number of ifdefs in
518 * the body of the code.
519 * COPYIN(uap->addr, &r.reg, sizeof r.reg);
521 * copyin(uap->addr, &r.reg, sizeof r.reg);
523 * copyin(uap->addr, &r.reg32, sizeof r.reg32);
524 * .. except this is done at runtime.
526 #define COPYIN(u, k, s) wrap32 ? \
527 copyin(u, k ## 32, s ## 32) : \
529 #define COPYOUT(k, u, s) wrap32 ? \
530 copyout(k ## 32, u, s ## 32) : \
533 #define COPYIN(u, k, s) copyin(u, k, s)
534 #define COPYOUT(k, u, s) copyout(k, u, s)
537 ptrace(struct thread *td, struct ptrace_args *uap)
540 * XXX this obfuscation is to reduce stack usage, but the register
541 * structs may be too large to put on the stack anyway.
544 struct ptrace_io_desc piod;
545 struct ptrace_lwpinfo pl;
546 struct ptrace_vm_entry pve;
550 #ifdef COMPAT_FREEBSD32
551 struct dbreg32 dbreg32;
552 struct fpreg32 fpreg32;
554 struct ptrace_io_desc32 piod32;
555 struct ptrace_vm_entry32 pve32;
560 #ifdef COMPAT_FREEBSD32
563 if (SV_CURPROC_FLAG(SV_ILP32))
566 AUDIT_ARG_PID(uap->pid);
567 AUDIT_ARG_CMD(uap->req);
568 AUDIT_ARG_VALUE(uap->data);
577 error = COPYIN(uap->addr, &r.reg, sizeof r.reg);
580 error = COPYIN(uap->addr, &r.fpreg, sizeof r.fpreg);
583 error = COPYIN(uap->addr, &r.dbreg, sizeof r.dbreg);
586 error = COPYIN(uap->addr, &r.piod, sizeof r.piod);
589 error = COPYIN(uap->addr, &r.pve, sizeof r.pve);
598 error = kern_ptrace(td, uap->req, uap->pid, addr, uap->data);
604 error = COPYOUT(&r.pve, uap->addr, sizeof r.pve);
607 error = COPYOUT(&r.piod, uap->addr, sizeof r.piod);
610 error = COPYOUT(&r.reg, uap->addr, sizeof r.reg);
613 error = COPYOUT(&r.fpreg, uap->addr, sizeof r.fpreg);
616 error = COPYOUT(&r.dbreg, uap->addr, sizeof r.dbreg);
619 error = copyout(&r.pl, uap->addr, uap->data);
628 #ifdef COMPAT_FREEBSD32
630 * PROC_READ(regs, td2, addr);
632 * proc_read_regs(td2, addr);
634 * proc_read_regs32(td2, addr);
635 * .. except this is done at runtime. There is an additional
636 * complication in that PROC_WRITE disallows 32 bit consumers
637 * from writing to 64 bit address space targets.
639 #define PROC_READ(w, t, a) wrap32 ? \
640 proc_read_ ## w ## 32(t, a) : \
641 proc_read_ ## w (t, a)
642 #define PROC_WRITE(w, t, a) wrap32 ? \
643 (safe ? proc_write_ ## w ## 32(t, a) : EINVAL ) : \
644 proc_write_ ## w (t, a)
646 #define PROC_READ(w, t, a) proc_read_ ## w (t, a)
647 #define PROC_WRITE(w, t, a) proc_write_ ## w (t, a)
651 kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
655 struct proc *curp, *p, *pp;
656 struct thread *td2 = NULL;
657 struct ptrace_io_desc *piod = NULL;
658 struct ptrace_lwpinfo *pl;
659 int error, write, tmp, num;
660 int proctree_locked = 0;
661 lwpid_t tid = 0, *buf;
662 #ifdef COMPAT_FREEBSD32
663 int wrap32 = 0, safe = 0;
664 struct ptrace_io_desc32 *piod32 = NULL;
669 /* Lock proctree before locking the process. */
679 sx_xlock(&proctree_lock);
687 if (req == PT_TRACE_ME) {
691 if (pid <= PID_MAX) {
692 if ((p = pfind(pid)) == NULL) {
694 sx_xunlock(&proctree_lock);
698 /* this is slow, should be optimized */
699 sx_slock(&allproc_lock);
700 FOREACH_PROC_IN_SYSTEM(p) {
702 FOREACH_THREAD_IN_PROC(p, td2) {
703 if (td2->td_tid == pid)
707 break; /* proc lock held */
710 sx_sunlock(&allproc_lock);
713 sx_xunlock(&proctree_lock);
720 AUDIT_ARG_PROCESS(p);
722 if ((p->p_flag & P_WEXIT) != 0) {
726 if ((error = p_cansee(td, p)) != 0)
729 if ((error = p_candebug(td, p)) != 0)
733 * System processes can't be debugged.
735 if ((p->p_flag & P_SYSTEM) != 0) {
741 if ((p->p_flag & P_STOPPED_TRACE) != 0) {
742 KASSERT(p->p_xthread != NULL, ("NULL p_xthread"));
745 td2 = FIRST_THREAD_IN_PROC(p);
750 #ifdef COMPAT_FREEBSD32
752 * Test if we're a 32 bit client and what the target is.
753 * Set the wrap controls accordingly.
755 if (SV_CURPROC_FLAG(SV_ILP32)) {
756 if (td2->td_proc->p_sysent->sv_flags & SV_ILP32)
771 if (p->p_pid == td->td_proc->p_pid) {
777 if (p->p_flag & P_TRACED) {
782 /* Can't trace an ancestor if you're being traced. */
783 if (curp->p_flag & P_TRACED) {
784 for (pp = curp->p_pptr; pp != NULL; pp = pp->p_pptr) {
797 /* Allow thread to clear single step for itself */
798 if (td->td_tid == tid)
803 /* not being traced... */
804 if ((p->p_flag & P_TRACED) == 0) {
809 /* not being traced by YOU */
810 if (p->p_pptr != td->td_proc) {
815 /* not currently stopped */
816 if ((p->p_flag & (P_STOPPED_SIG | P_STOPPED_TRACE)) == 0 ||
817 p->p_suspcount != p->p_numthreads ||
818 (p->p_flag & P_WAITED) == 0) {
823 if ((p->p_flag & P_STOPPED_TRACE) == 0) {
824 static int count = 0;
826 printf("P_STOPPED_TRACE not set.\n");
833 /* Keep this process around until we finish this request. */
838 * Single step fixup ala procfs
844 * Actually do the requests
847 td->td_retval[0] = 0;
851 /* set my trace flag and "owner" so it can read/write me */
852 p->p_flag |= P_TRACED;
853 p->p_oppid = p->p_pptr->p_pid;
857 /* security check done above */
858 p->p_flag |= P_TRACED;
859 p->p_oppid = p->p_pptr->p_pid;
860 if (p->p_pptr != td->td_proc)
861 proc_reparent(p, td->td_proc);
863 goto sendsig; /* in PT_CONTINUE below */
866 error = ptrace_clear_single_step(td2);
870 error = ptrace_single_step(td2);
874 td2->td_dbgflags |= TDB_SUSPEND;
876 td2->td_flags |= TDF_NEEDSUSPCHK;
881 td2->td_dbgflags &= ~TDB_SUSPEND;
890 /* Zero means do not send any signal */
891 if (data < 0 || data > _SIG_MAXSIG) {
898 error = ptrace_single_step(td2);
903 p->p_stops |= S_PT_SCE;
906 p->p_stops |= S_PT_SCX;
909 p->p_stops |= S_PT_SCE | S_PT_SCX;
913 if (addr != (void *)1) {
914 error = ptrace_set_pc(td2, (u_long)(uintfptr_t)addr);
919 if (req == PT_DETACH) {
920 /* reset process parent */
921 if (p->p_oppid != p->p_pptr->p_pid) {
924 PROC_LOCK(p->p_pptr);
925 sigqueue_take(p->p_ksi);
926 PROC_UNLOCK(p->p_pptr);
929 pp = pfind(p->p_oppid);
935 proc_reparent(p, pp);
937 p->p_sigparent = SIGCHLD;
939 p->p_flag &= ~(P_TRACED | P_WAITED);
942 /* should we send SIGCHLD? */
943 /* childproc_continued(p); */
947 if (proctree_locked) {
948 sx_xunlock(&proctree_lock);
953 if ((p->p_flag & (P_STOPPED_SIG | P_STOPPED_TRACE)) != 0) {
954 /* deliver or queue signal */
955 td2->td_dbgflags &= ~TDB_XSIG;
958 if (req == PT_DETACH) {
960 FOREACH_THREAD_IN_PROC(p, td3) {
961 td3->td_dbgflags &= ~TDB_SUSPEND;
965 * unsuspend all threads, to not let a thread run,
966 * you should use PT_SUSPEND to suspend it before
967 * continuing process.
970 p->p_flag &= ~(P_STOPPED_TRACE|P_STOPPED_SIG|P_WAITED);
981 td2->td_dbgflags |= TDB_USERWR;
988 /* write = 0 set above */
989 iov.iov_base = write ? (caddr_t)&data : (caddr_t)&tmp;
990 iov.iov_len = sizeof(int);
993 uio.uio_offset = (off_t)(uintptr_t)addr;
994 uio.uio_resid = sizeof(int);
995 uio.uio_segflg = UIO_SYSSPACE; /* i.e.: the uap */
996 uio.uio_rw = write ? UIO_WRITE : UIO_READ;
998 error = proc_rwmem(p, &uio);
999 if (uio.uio_resid != 0) {
1001 * XXX proc_rwmem() doesn't currently return ENOSPC,
1002 * so I think write() can bogusly return 0.
1003 * XXX what happens for short writes? We don't want
1004 * to write partial data.
1005 * XXX proc_rwmem() returns EPERM for other invalid
1006 * addresses. Convert this to EINVAL. Does this
1007 * clobber returns of EPERM for other reasons?
1009 if (error == 0 || error == ENOSPC || error == EPERM)
1010 error = EINVAL; /* EOF */
1013 td->td_retval[0] = tmp;
1018 #ifdef COMPAT_FREEBSD32
1021 iov.iov_base = (void *)(uintptr_t)piod32->piod_addr;
1022 iov.iov_len = piod32->piod_len;
1023 uio.uio_offset = (off_t)(uintptr_t)piod32->piod_offs;
1024 uio.uio_resid = piod32->piod_len;
1029 iov.iov_base = piod->piod_addr;
1030 iov.iov_len = piod->piod_len;
1031 uio.uio_offset = (off_t)(uintptr_t)piod->piod_offs;
1032 uio.uio_resid = piod->piod_len;
1036 uio.uio_segflg = UIO_USERSPACE;
1038 #ifdef COMPAT_FREEBSD32
1039 tmp = wrap32 ? piod32->piod_op : piod->piod_op;
1041 tmp = piod->piod_op;
1046 uio.uio_rw = UIO_READ;
1050 td2->td_dbgflags |= TDB_USERWR;
1051 uio.uio_rw = UIO_WRITE;
1058 error = proc_rwmem(p, &uio);
1059 #ifdef COMPAT_FREEBSD32
1061 piod32->piod_len -= uio.uio_resid;
1064 piod->piod_len -= uio.uio_resid;
1070 goto sendsig; /* in PT_CONTINUE above */
1073 td2->td_dbgflags |= TDB_USERWR;
1074 error = PROC_WRITE(regs, td2, addr);
1078 error = PROC_READ(regs, td2, addr);
1082 td2->td_dbgflags |= TDB_USERWR;
1083 error = PROC_WRITE(fpregs, td2, addr);
1087 error = PROC_READ(fpregs, td2, addr);
1091 td2->td_dbgflags |= TDB_USERWR;
1092 error = PROC_WRITE(dbregs, td2, addr);
1096 error = PROC_READ(dbregs, td2, addr);
1100 if (data <= 0 || data > sizeof(*pl)) {
1105 pl->pl_lwpid = td2->td_tid;
1106 if (td2->td_dbgflags & TDB_XSIG)
1107 pl->pl_event = PL_EVENT_SIGNAL;
1111 pl->pl_sigmask = td2->td_sigmask;
1112 pl->pl_siglist = td2->td_siglist;
1116 td->td_retval[0] = p->p_numthreads;
1124 num = imin(p->p_numthreads, data);
1126 buf = malloc(num * sizeof(lwpid_t), M_TEMP, M_WAITOK);
1129 FOREACH_THREAD_IN_PROC(p, td2) {
1132 buf[tmp++] = td2->td_tid;
1135 error = copyout(buf, addr, tmp * sizeof(lwpid_t));
1138 td->td_retval[0] = tmp;
1142 case PT_VM_TIMESTAMP:
1143 td->td_retval[0] = p->p_vmspace->vm_map.timestamp;
1148 #ifdef COMPAT_FREEBSD32
1150 error = ptrace_vm_entry32(td, p, addr);
1153 error = ptrace_vm_entry(td, p, addr);
1158 #ifdef __HAVE_PTRACE_MACHDEP
1159 if (req >= PT_FIRSTMACH) {
1161 error = cpu_ptrace(td2, req, addr, data);
1165 /* Unknown request. */
1171 /* Drop our hold on this process now that the request has completed. */
1175 if (proctree_locked)
1176 sx_xunlock(&proctree_lock);
1183 * Stop a process because of a debugging event;
1184 * stay stopped until p->p_step is cleared
1185 * (cleared by PIOCCONT in procfs).
1188 stopevent(struct proc *p, unsigned int event, unsigned int val)
1191 PROC_LOCK_ASSERT(p, MA_OWNED);
1195 p->p_xthread = NULL;
1196 p->p_stype = event; /* Which event caused the stop? */
1197 wakeup(&p->p_stype); /* Wake up any PIOCWAIT'ing procs */
1198 msleep(&p->p_step, &p->p_mtx, PWAIT, "stopevent", 0);
1199 } while (p->p_step);