diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2016-10-19 08:31:34 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2016-10-19 08:31:34 +0000 |
commit | 8b1d68782954a20a07fae61156cf0385a4c058df (patch) | |
tree | 2ad803c3ae008a7408c7f6fda66856c6141bd8c7 /sys | |
parent | 3479986a00a06d19b0e074a8b2921e11c42ed785 (diff) |
Change process_{domem,auxv_offset}() to take a process instead of a proc.
Make process_auxv_offset() take and release a reference of the vmspace like
process_domem() does.
ok kettenis@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/hppa/hppa/trap.c | 6 | ||||
-rw-r--r-- | sys/arch/m88k/m88k/trap.c | 6 | ||||
-rw-r--r-- | sys/kern/sys_process.c | 62 | ||||
-rw-r--r-- | sys/sys/ptrace.h | 21 |
4 files changed, 52 insertions, 43 deletions
diff --git a/sys/arch/hppa/hppa/trap.c b/sys/arch/hppa/hppa/trap.c index 04928eea5e7..1182d837fe4 100644 --- a/sys/arch/hppa/hppa/trap.c +++ b/sys/arch/hppa/hppa/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.140 2016/10/08 05:49:08 guenther Exp $ */ +/* $OpenBSD: trap.c,v 1.141 2016/10/19 08:31:32 guenther Exp $ */ /* * Copyright (c) 1998-2004 Michael Shalayeff @@ -690,7 +690,7 @@ ss_get_value(struct proc *p, vaddr_t addr, u_int *value) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = curproc; - return (process_domem(curproc, p, &uio, PT_READ_I)); + return (process_domem(curproc, p->p_p, &uio, PT_READ_I)); } int @@ -708,7 +708,7 @@ ss_put_value(struct proc *p, vaddr_t addr, u_int value) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_WRITE; uio.uio_procp = curproc; - return (process_domem(curproc, p, &uio, PT_WRITE_I)); + return (process_domem(curproc, p->p_p, &uio, PT_WRITE_I)); } void diff --git a/sys/arch/m88k/m88k/trap.c b/sys/arch/m88k/m88k/trap.c index 0e0c3ab1bbc..35c54855e32 100644 --- a/sys/arch/m88k/m88k/trap.c +++ b/sys/arch/m88k/m88k/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.104 2016/06/13 23:51:59 dlg Exp $ */ +/* $OpenBSD: trap.c,v 1.105 2016/10/19 08:31:33 guenther Exp $ */ /* * Copyright (c) 2004, Miodrag Vallat. * Copyright (c) 1998 Steve Murphree, Jr. @@ -1447,7 +1447,7 @@ ss_get_value(struct proc *p, vaddr_t addr, u_int *value) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = curproc; - return (process_domem(curproc, p, &uio, PT_READ_I)); + return (process_domem(curproc, p->p_p, &uio, PT_READ_I)); } int @@ -1465,7 +1465,7 @@ ss_put_value(struct proc *p, vaddr_t addr, u_int value) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_WRITE; uio.uio_procp = curproc; - return (process_domem(curproc, p, &uio, PT_WRITE_I)); + return (process_domem(curproc, p->p_p, &uio, PT_WRITE_I)); } /* diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 29903e38da8..b295908c122 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_process.c,v 1.72 2016/10/19 08:28:19 guenther Exp $ */ +/* $OpenBSD: sys_process.c,v 1.73 2016/10/19 08:31:33 guenther Exp $ */ /* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */ /*- @@ -67,7 +67,7 @@ #include <machine/reg.h> -int process_auxv_offset(struct proc *, struct proc *, struct uio *); +int process_auxv_offset(struct proc *, struct process *, struct uio *); #ifdef PTRACE int global_ptrace; /* permit tracing of not children */ @@ -368,7 +368,7 @@ sys_ptrace(struct proc *p, void *v, register_t *retval) uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = write ? UIO_WRITE : UIO_READ; uio.uio_procp = p; - error = process_domem(p, t, &uio, write ? PT_WRITE_I : + error = process_domem(p, tr, &uio, write ? PT_WRITE_I : PT_READ_I); if (write == 0) *retval = temp; @@ -411,14 +411,14 @@ sys_ptrace(struct proc *p, void *v, register_t *retval) if (uio.uio_resid > temp - uio.uio_offset) uio.uio_resid = temp - uio.uio_offset; piod.piod_len = iov.iov_len = uio.uio_resid; - error = process_auxv_offset(p, t, &uio); + error = process_auxv_offset(p, tr, &uio); if (error) return (error); break; default: return (EINVAL); } - error = process_domem(p, t, &uio, req); + error = process_domem(p, tr, &uio, req); piod.piod_len -= uio.uio_resid; (void) copyout(&piod, SCARG(uap, addr), sizeof(piod)); return (error); @@ -707,7 +707,7 @@ process_checkioperm(struct proc *p, struct process *tr) } int -process_domem(struct proc *curp, struct proc *p, struct uio *uio, int req) +process_domem(struct proc *curp, struct process *tr, struct uio *uio, int req) { struct vmspace *vm; int error; @@ -716,17 +716,17 @@ process_domem(struct proc *curp, struct proc *p, struct uio *uio, int req) len = uio->uio_resid; if (len == 0) - return (0); + return 0; - if ((error = process_checkioperm(curp, p->p_p)) != 0) - return (error); + if ((error = process_checkioperm(curp, tr)) != 0) + return error; /* XXXCDC: how should locking work here? */ - if ((p->p_p->ps_flags & PS_EXITING) || (p->p_vmspace->vm_refcnt < 1)) - return(EFAULT); + vm = tr->ps_vmspace; + if ((tr->ps_flags & PS_EXITING) || (vm->vm_refcnt < 1)) + return EFAULT; addr = uio->uio_offset; - vm = p->p_vmspace; vm->vm_refcnt++; error = uvm_io(&vm->vm_map, uio, @@ -735,15 +735,15 @@ process_domem(struct proc *curp, struct proc *p, struct uio *uio, int req) uvmspace_free(vm); if (error == 0 && req == PT_WRITE_I) - pmap_proc_iflush(p->p_p, addr, len); + pmap_proc_iflush(tr, addr, len); - return (error); + return error; } int -process_auxv_offset(struct proc *curp, struct proc *p, struct uio *uiop) +process_auxv_offset(struct proc *curp, struct process *tr, struct uio *uiop) { - struct process *pr = p->p_p; + struct vmspace *vm; struct ps_strings pss; struct iovec iov; struct uio uio; @@ -753,29 +753,37 @@ process_auxv_offset(struct proc *curp, struct proc *p, struct uio *uiop) iov.iov_len = sizeof(pss); uio.uio_iov = &iov; uio.uio_iovcnt = 1; - uio.uio_offset = (off_t)pr->ps_strings; + uio.uio_offset = (off_t)tr->ps_strings; uio.uio_resid = sizeof(pss); uio.uio_segflg = UIO_SYSSPACE; uio.uio_rw = UIO_READ; uio.uio_procp = curp; - if ((error = uvm_io(&p->p_vmspace->vm_map, &uio, 0)) != 0) - return (error); + vm = tr->ps_vmspace; + if ((tr->ps_flags & PS_EXITING) || (vm->vm_refcnt < 1)) + return EFAULT; + + vm->vm_refcnt++; + error = uvm_io(&vm->vm_map, &uio, 0); + uvmspace_free(vm); + + if (error != 0) + return error; if (pss.ps_envstr == NULL) - return (EIO); + return EIO; uiop->uio_offset += (off_t)(vaddr_t)(pss.ps_envstr + pss.ps_nenvstr + 1); #ifdef MACHINE_STACK_GROWS_UP - if (uiop->uio_offset < (off_t)pr->ps_strings) - return (EIO); + if (uiop->uio_offset < (off_t)tr->ps_strings) + return EIO; #else - if (uiop->uio_offset > (off_t)pr->ps_strings) - return (EIO); - if ((uiop->uio_offset + uiop->uio_resid) > (off_t)pr->ps_strings) - uiop->uio_resid = (off_t)pr->ps_strings - uiop->uio_offset; + if (uiop->uio_offset > (off_t)tr->ps_strings) + return EIO; + if ((uiop->uio_offset + uiop->uio_resid) > (off_t)tr->ps_strings) + uiop->uio_resid = (off_t)tr->ps_strings - uiop->uio_offset; #endif - return (0); + return 0; } #endif diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index 3c8fda30f21..7133d13fe23 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ptrace.h,v 1.14 2012/04/13 16:37:50 kettenis Exp $ */ +/* $OpenBSD: ptrace.h,v 1.15 2016/10/19 08:31:33 guenther Exp $ */ /* $NetBSD: ptrace.h,v 1.21 1996/02/09 18:25:26 christos Exp $ */ /*- @@ -104,19 +104,20 @@ struct reg; struct fpreg; #endif -void proc_reparent(struct process *child, struct process *newparent); +void proc_reparent(struct process *_child, struct process *_newparent); #ifdef PT_GETFPREGS -int process_read_fpregs(struct proc *p, struct fpreg *regs); +int process_read_fpregs(struct proc *_t, struct fpreg *); #endif -int process_read_regs(struct proc *p, struct reg *regs); -int process_set_pc(struct proc *p, caddr_t addr); -int process_sstep(struct proc *p, int sstep); +int process_read_regs(struct proc *_t, struct reg *); +int process_set_pc(struct proc *_t, caddr_t _addr); +int process_sstep(struct proc *_t, int _sstep); #ifdef PT_SETFPREGS -int process_write_fpregs(struct proc *p, struct fpreg *regs); +int process_write_fpregs(struct proc *_t, struct fpreg *); #endif -int process_write_regs(struct proc *p, struct reg *regs); -int process_checkioperm(struct proc *, struct process *); -int process_domem(struct proc *, struct proc *, struct uio *, int); +int process_write_regs(struct proc *_t, struct reg *); +int process_checkioperm(struct proc *_curp, struct process *_tr); +int process_domem(struct proc *_curp, struct process *_tr, struct uio *, + int _req); #ifndef FIX_SSTEP #define FIX_SSTEP(p) |