1994-08-08 13:00:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, Sean Eric Fagan
|
|
|
|
* All rights reserved.
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1994-08-08 13:00:27 +00:00
|
|
|
* This product includes software developed by Sean Eric Fagan.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
1994-08-08 13:00:27 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
1994-05-24 10:09:53 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
1994-08-08 13:00:27 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1994-05-24 10:09:53 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1996-05-02 14:21:14 +00:00
|
|
|
* $Id: sys_process.c,v 1.22 1996/03/30 15:02:58 peter Exp $
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1994-08-18 22:36:09 +00:00
|
|
|
#include <sys/systm.h>
|
1995-11-12 06:43:28 +00:00
|
|
|
#include <sys/sysproto.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/proc.h>
|
1994-08-08 13:00:27 +00:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/ptrace.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/errno.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <sys/queue.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
#include <machine/reg.h>
|
|
|
|
#include <machine/psl.h>
|
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/vm_prot.h>
|
|
|
|
#include <vm/lock.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <vm/vm_map.h>
|
|
|
|
#include <vm/vm_object.h>
|
1994-08-08 13:00:27 +00:00
|
|
|
#include <vm/vm_page.h>
|
|
|
|
#include <vm/vm_kern.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_extern.h>
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/user.h>
|
1996-01-24 18:29:00 +00:00
|
|
|
#include <miscfs/procfs/procfs.h>
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
/* use the equivalent procfs code */
|
|
|
|
#if 0
|
1995-05-12 21:39:48 +00:00
|
|
|
static int
|
1994-08-08 13:00:27 +00:00
|
|
|
pread (struct proc *procp, unsigned int addr, unsigned int *retval) {
|
|
|
|
int rv;
|
|
|
|
vm_map_t map, tmap;
|
|
|
|
vm_object_t object;
|
|
|
|
vm_offset_t kva = 0;
|
|
|
|
int page_offset; /* offset into page */
|
|
|
|
vm_offset_t pageno; /* page number */
|
|
|
|
vm_map_entry_t out_entry;
|
|
|
|
vm_prot_t out_prot;
|
|
|
|
boolean_t wired, single_use;
|
1995-12-17 06:59:36 +00:00
|
|
|
vm_pindex_t pindex;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
|
|
|
/* Map page into kernel space */
|
|
|
|
|
|
|
|
map = &procp->p_vmspace->vm_map;
|
|
|
|
|
|
|
|
page_offset = addr - trunc_page(addr);
|
|
|
|
pageno = trunc_page(addr);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
tmap = map;
|
|
|
|
rv = vm_map_lookup (&tmap, pageno, VM_PROT_READ, &out_entry,
|
1995-12-17 06:59:36 +00:00
|
|
|
&object, &pindex, &out_prot, &wired, &single_use);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
|
|
|
if (rv != KERN_SUCCESS)
|
|
|
|
return EINVAL;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
vm_map_lookup_done (tmap, out_entry);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
/* Find space in kernel_map for the page we're interested in */
|
1996-01-19 04:00:31 +00:00
|
|
|
rv = vm_map_find (kernel_map, object, IDX_TO_OFF(pindex),
|
|
|
|
&kva, PAGE_SIZE, 0, VM_PROT_ALL, VM_PROT_ALL, 0);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
|
|
|
if (!rv) {
|
|
|
|
vm_object_reference (object);
|
|
|
|
|
|
|
|
rv = vm_map_pageable (kernel_map, kva, kva + PAGE_SIZE, 0);
|
|
|
|
if (!rv) {
|
|
|
|
*retval = 0;
|
1994-08-18 22:36:09 +00:00
|
|
|
bcopy ((caddr_t)kva + page_offset,
|
|
|
|
retval, sizeof *retval);
|
1994-08-08 13:00:27 +00:00
|
|
|
}
|
|
|
|
vm_map_remove (kernel_map, kva, kva + PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1995-05-12 21:39:48 +00:00
|
|
|
static int
|
1994-08-08 13:00:27 +00:00
|
|
|
pwrite (struct proc *procp, unsigned int addr, unsigned int datum) {
|
|
|
|
int rv;
|
|
|
|
vm_map_t map, tmap;
|
|
|
|
vm_object_t object;
|
|
|
|
vm_offset_t kva = 0;
|
|
|
|
int page_offset; /* offset into page */
|
|
|
|
vm_offset_t pageno; /* page number */
|
|
|
|
vm_map_entry_t out_entry;
|
|
|
|
vm_prot_t out_prot;
|
|
|
|
boolean_t wired, single_use;
|
1995-12-17 06:59:36 +00:00
|
|
|
vm_pindex_t pindex;
|
1994-08-08 13:00:27 +00:00
|
|
|
boolean_t fix_prot = 0;
|
|
|
|
|
|
|
|
/* Map page into kernel space */
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
map = &procp->p_vmspace->vm_map;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
page_offset = addr - trunc_page(addr);
|
|
|
|
pageno = trunc_page(addr);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
/*
|
|
|
|
* Check the permissions for the area we're interested in.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (vm_map_check_protection (map, pageno, pageno + PAGE_SIZE,
|
|
|
|
VM_PROT_WRITE) == FALSE) {
|
|
|
|
/*
|
|
|
|
* If the page was not writable, we make it so.
|
|
|
|
* XXX It is possible a page may *not* be read/executable,
|
|
|
|
* if a process changes that!
|
|
|
|
*/
|
|
|
|
fix_prot = 1;
|
|
|
|
/* The page isn't writable, so let's try making it so... */
|
|
|
|
if ((rv = vm_map_protect (map, pageno, pageno + PAGE_SIZE,
|
|
|
|
VM_PROT_ALL, 0)) != KERN_SUCCESS)
|
|
|
|
return EFAULT; /* I guess... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we need to get the page. out_entry, out_prot, wired, and
|
|
|
|
* single_use aren't used. One would think the vm code would be
|
|
|
|
* a *bit* nicer... We use tmap because vm_map_lookup() can
|
|
|
|
* change the map argument.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tmap = map;
|
|
|
|
rv = vm_map_lookup (&tmap, pageno, VM_PROT_WRITE, &out_entry,
|
1995-12-17 06:59:36 +00:00
|
|
|
&object, &pindex, &out_prot, &wired, &single_use);
|
1994-08-08 13:00:27 +00:00
|
|
|
if (rv != KERN_SUCCESS) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Okay, we've got the page. Let's release tmap.
|
|
|
|
*/
|
|
|
|
|
|
|
|
vm_map_lookup_done (tmap, out_entry);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
/*
|
|
|
|
* Fault the page in...
|
|
|
|
*/
|
|
|
|
|
1995-02-19 02:50:31 +00:00
|
|
|
vm_map_pageable(map, trunc_page(vtopte(pageno)),
|
|
|
|
trunc_page(vtopte(pageno)) + PAGE_SIZE, FALSE);
|
1995-02-10 22:36:11 +00:00
|
|
|
rv = vm_fault(map, pageno, VM_PROT_WRITE|VM_PROT_READ, FALSE);
|
1995-02-19 02:50:31 +00:00
|
|
|
vm_map_pageable(map, trunc_page(vtopte(pageno)),
|
|
|
|
trunc_page(vtopte(pageno)) + PAGE_SIZE, TRUE);
|
1994-08-08 13:00:27 +00:00
|
|
|
if (rv != KERN_SUCCESS)
|
|
|
|
return EFAULT;
|
|
|
|
|
|
|
|
/* Find space in kernel_map for the page we're interested in */
|
1996-01-19 04:00:31 +00:00
|
|
|
rv = vm_map_find (kernel_map, object, IDX_TO_OFF(pindex),
|
|
|
|
&kva, PAGE_SIZE, 0,
|
|
|
|
VM_PROT_ALL, VM_PROT_ALL, 0);
|
1994-08-08 13:00:27 +00:00
|
|
|
if (!rv) {
|
|
|
|
vm_object_reference (object);
|
|
|
|
|
|
|
|
rv = vm_map_pageable (kernel_map, kva, kva + PAGE_SIZE, 0);
|
|
|
|
if (!rv) {
|
1994-08-18 22:36:09 +00:00
|
|
|
bcopy (&datum, (caddr_t)kva + page_offset, sizeof datum);
|
1994-08-08 13:00:27 +00:00
|
|
|
}
|
|
|
|
vm_map_remove (kernel_map, kva, kva + PAGE_SIZE);
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
if (fix_prot)
|
|
|
|
vm_map_protect (map, pageno, pageno + PAGE_SIZE,
|
|
|
|
VM_PROT_READ|VM_PROT_EXECUTE, 0);
|
|
|
|
return rv;
|
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
#endif
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Process debugging system call.
|
|
|
|
*/
|
1995-11-12 06:43:28 +00:00
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
1994-05-24 10:09:53 +00:00
|
|
|
struct ptrace_args {
|
|
|
|
int req;
|
|
|
|
pid_t pid;
|
|
|
|
caddr_t addr;
|
|
|
|
int data;
|
|
|
|
};
|
1995-11-12 06:43:28 +00:00
|
|
|
#endif
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
1994-08-08 13:00:27 +00:00
|
|
|
ptrace(curp, uap, retval)
|
|
|
|
struct proc *curp;
|
|
|
|
struct ptrace_args *uap;
|
|
|
|
int *retval;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1994-08-08 13:00:27 +00:00
|
|
|
struct proc *p;
|
1996-01-24 18:29:00 +00:00
|
|
|
struct iovec iov;
|
|
|
|
struct uio uio;
|
1994-09-25 19:34:02 +00:00
|
|
|
int error = 0;
|
1996-01-24 18:29:00 +00:00
|
|
|
int write;
|
|
|
|
int s;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
if (uap->req == PT_TRACE_ME)
|
|
|
|
p = curp;
|
|
|
|
else {
|
|
|
|
if ((p = pfind(uap->pid)) == NULL)
|
|
|
|
return ESRCH;
|
1994-08-08 13:00:27 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
/*
|
|
|
|
* Permissions check
|
|
|
|
*/
|
|
|
|
switch (uap->req) {
|
|
|
|
case PT_TRACE_ME:
|
|
|
|
/* Always legal. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PT_ATTACH:
|
|
|
|
/* Self */
|
|
|
|
if (p->p_pid == curp->p_pid)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* Already traced */
|
|
|
|
if (p->p_flag & P_TRACED)
|
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
/* not owned by you, has done setuid (unless you're root) */
|
|
|
|
if ((p->p_cred->p_ruid != curp->p_cred->p_ruid) ||
|
|
|
|
(p->p_flag & P_SUGID)) {
|
|
|
|
if (error = suser(curp->p_ucred, &curp->p_acflag))
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK */
|
|
|
|
break;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_READ_I:
|
|
|
|
case PT_READ_D:
|
|
|
|
case PT_READ_U:
|
|
|
|
case PT_WRITE_I:
|
|
|
|
case PT_WRITE_D:
|
|
|
|
case PT_WRITE_U:
|
|
|
|
case PT_CONTINUE:
|
|
|
|
case PT_KILL:
|
|
|
|
case PT_STEP:
|
|
|
|
case PT_DETACH:
|
|
|
|
#ifdef PT_GETREGS
|
|
|
|
case PT_GETREGS:
|
|
|
|
#endif
|
|
|
|
#ifdef PT_SETREGS
|
|
|
|
case PT_SETREGS:
|
|
|
|
#endif
|
|
|
|
#ifdef PT_GETFPREGS
|
|
|
|
case PT_GETFPREGS:
|
1994-08-08 13:00:27 +00:00
|
|
|
#endif
|
1996-01-24 18:29:00 +00:00
|
|
|
#ifdef PT_SETFPREGS
|
|
|
|
case PT_SETFPREGS:
|
1994-08-08 13:00:27 +00:00
|
|
|
#endif
|
1996-01-24 18:29:00 +00:00
|
|
|
/* not being traced... */
|
1994-08-08 13:00:27 +00:00
|
|
|
if ((p->p_flag & P_TRACED) == 0)
|
|
|
|
return EPERM;
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
/* not being traced by YOU */
|
|
|
|
if (p->p_pptr != curp)
|
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
/* not currently stopped */
|
1994-08-08 13:00:27 +00:00
|
|
|
if (p->p_stat != SSTOP || (p->p_flag & P_WAITED) == 0)
|
|
|
|
return EBUSY;
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
/* OK */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
1994-08-08 13:00:27 +00:00
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
#ifdef FIX_SSTEP
|
|
|
|
/*
|
|
|
|
* Single step fixup ala procfs
|
|
|
|
*/
|
|
|
|
FIX_SSTEP(p);
|
1994-08-08 13:00:27 +00:00
|
|
|
#endif
|
1996-01-24 18:29:00 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1996-01-24 18:29:00 +00:00
|
|
|
* Actually do the requests
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
write = 0;
|
|
|
|
*retval = 0;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
switch (uap->req) {
|
|
|
|
case PT_TRACE_ME:
|
|
|
|
/* set my trace flag and "owner" so it can read/write me */
|
1994-08-08 13:00:27 +00:00
|
|
|
p->p_flag |= P_TRACED;
|
1996-01-24 18:29:00 +00:00
|
|
|
p->p_oppid = p->p_pptr->p_pid;
|
1994-08-08 13:00:27 +00:00
|
|
|
return 0;
|
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_ATTACH:
|
|
|
|
/* security check done above */
|
|
|
|
p->p_flag |= P_TRACED;
|
|
|
|
p->p_oppid = p->p_pptr->p_pid;
|
|
|
|
if (p->p_pptr != curp)
|
|
|
|
proc_reparent(p, curp);
|
|
|
|
uap->data = SIGSTOP;
|
|
|
|
goto sendsig; /* in PT_CONTINUE below */
|
|
|
|
|
|
|
|
case PT_STEP:
|
|
|
|
case PT_CONTINUE:
|
1994-08-08 13:00:27 +00:00
|
|
|
case PT_DETACH:
|
|
|
|
if ((unsigned)uap->data >= NSIG)
|
|
|
|
return EINVAL;
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
PHOLD(p);
|
|
|
|
|
|
|
|
if (uap->req == PT_STEP) {
|
|
|
|
if ((error = ptrace_single_step (p))) {
|
|
|
|
PRELE(p);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uap->addr != (caddr_t)1) {
|
|
|
|
fill_eproc (p, &p->p_addr->u_kproc.kp_eproc);
|
|
|
|
if ((error = ptrace_set_pc (p, (u_int)uap->addr))) {
|
|
|
|
PRELE(p);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PRELE(p);
|
|
|
|
|
|
|
|
if (uap->req == PT_DETACH) {
|
|
|
|
/* reset process parent */
|
|
|
|
if (p->p_oppid != p->p_pptr->p_pid) {
|
|
|
|
struct proc *pp;
|
|
|
|
|
|
|
|
pp = pfind(p->p_oppid);
|
|
|
|
proc_reparent(p, pp ? pp : initproc);
|
|
|
|
}
|
|
|
|
|
|
|
|
p->p_flag &= ~(P_TRACED | P_WAITED);
|
|
|
|
p->p_oppid = 0;
|
|
|
|
|
|
|
|
/* should we send SIGCHLD? */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sendsig:
|
|
|
|
/* deliver or queue signal */
|
1994-08-08 13:00:27 +00:00
|
|
|
s = splhigh();
|
|
|
|
if (p->p_stat == SSTOP) {
|
|
|
|
p->p_xstat = uap->data;
|
|
|
|
setrunnable(p);
|
|
|
|
} else if (uap->data) {
|
|
|
|
psignal(p, uap->data);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case PT_WRITE_I:
|
|
|
|
case PT_WRITE_D:
|
1996-01-24 18:29:00 +00:00
|
|
|
write = 1;
|
1994-08-08 13:00:27 +00:00
|
|
|
/* fallthrough */
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_READ_I:
|
|
|
|
case PT_READ_D:
|
|
|
|
/* write = 0 set above */
|
|
|
|
iov.iov_base = write ? (caddr_t)&uap->data : (caddr_t)retval;
|
|
|
|
iov.iov_len = sizeof(int);
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = (off_t)(u_long)uap->addr;
|
|
|
|
uio.uio_resid = sizeof(int);
|
|
|
|
uio.uio_segflg = UIO_SYSSPACE; /* ie: the uap */
|
|
|
|
uio.uio_rw = write ? UIO_WRITE : UIO_READ;
|
|
|
|
uio.uio_procp = p;
|
1996-03-30 15:02:58 +00:00
|
|
|
error = procfs_domem(curp, p, NULL, &uio);
|
|
|
|
if (uio.uio_resid != 0) {
|
|
|
|
/*
|
|
|
|
* XXX procfs_domem() doesn't currently return ENOSPC,
|
|
|
|
* so I think write() can bogusly return 0.
|
|
|
|
* XXX what happens for short writes? We don't want
|
|
|
|
* to write partial data.
|
|
|
|
* XXX procfs_domem() returns EPERM for other invalid
|
|
|
|
* addresses. Convert this to EINVAL. Does this
|
|
|
|
* clobber returns of EPERM for other reasons?
|
|
|
|
*/
|
|
|
|
if (error == 0 || error == ENOSPC || error == EPERM)
|
|
|
|
error = EINVAL; /* EOF */
|
|
|
|
}
|
|
|
|
return (error);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
|
|
|
case PT_READ_U:
|
1996-05-02 14:21:14 +00:00
|
|
|
if ((u_int)uap->addr > (UPAGES * PAGE_SIZE - sizeof(int))) {
|
1994-08-08 13:00:27 +00:00
|
|
|
return EFAULT;
|
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
error = 0;
|
|
|
|
PHOLD(p); /* user had damn well better be incore! */
|
|
|
|
if (p->p_flag & P_INMEM) {
|
|
|
|
p->p_addr->u_kproc.kp_proc = *p;
|
|
|
|
fill_eproc (p, &p->p_addr->u_kproc.kp_eproc);
|
|
|
|
*retval = *(int*)((u_int)p->p_addr + (u_int)uap->addr);
|
|
|
|
} else {
|
|
|
|
*retval = 0;
|
|
|
|
error = EFAULT;
|
|
|
|
}
|
|
|
|
PRELE(p);
|
|
|
|
return error;
|
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
case PT_WRITE_U:
|
1996-01-24 18:29:00 +00:00
|
|
|
PHOLD(p); /* user had damn well better be incore! */
|
|
|
|
if (p->p_flag & P_INMEM) {
|
|
|
|
p->p_addr->u_kproc.kp_proc = *p;
|
|
|
|
fill_eproc (p, &p->p_addr->u_kproc.kp_eproc);
|
|
|
|
error = ptrace_write_u(p, (vm_offset_t)uap->addr, uap->data);
|
|
|
|
} else {
|
|
|
|
error = EFAULT;
|
|
|
|
}
|
|
|
|
PRELE(p);
|
|
|
|
return error;
|
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
case PT_KILL:
|
1996-01-24 18:29:00 +00:00
|
|
|
uap->data = SIGKILL;
|
|
|
|
goto sendsig; /* in PT_CONTINUE above */
|
|
|
|
|
|
|
|
#ifdef PT_SETREGS
|
|
|
|
case PT_SETREGS:
|
|
|
|
write = 1;
|
|
|
|
/* fallthrough */
|
|
|
|
#endif /* PT_SETREGS */
|
1994-08-08 13:00:27 +00:00
|
|
|
#ifdef PT_GETREGS
|
|
|
|
case PT_GETREGS:
|
1996-01-24 18:29:00 +00:00
|
|
|
/* write = 0 above */
|
|
|
|
#endif /* PT_SETREGS */
|
|
|
|
#if defined(PT_SETREGS) || defined(PT_GETREGS)
|
|
|
|
if (!procfs_validregs(p)) /* no P_SYSTEM procs please */
|
|
|
|
return EINVAL;
|
|
|
|
else {
|
|
|
|
iov.iov_base = uap->addr;
|
|
|
|
iov.iov_len = sizeof(struct reg);
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = 0;
|
|
|
|
uio.uio_resid = sizeof(struct reg);
|
|
|
|
uio.uio_segflg = UIO_USERSPACE;
|
|
|
|
uio.uio_rw = write ? UIO_WRITE : UIO_READ;
|
|
|
|
uio.uio_procp = curp;
|
|
|
|
return (procfs_doregs(curp, p, NULL, &uio));
|
|
|
|
}
|
|
|
|
#endif /* defined(PT_SETREGS) || defined(PT_GETREGS) */
|
|
|
|
|
|
|
|
#ifdef PT_SETFPREGS
|
|
|
|
case PT_SETFPREGS:
|
|
|
|
write = 1;
|
|
|
|
/* fallthrough */
|
|
|
|
#endif /* PT_SETFPREGS */
|
|
|
|
#ifdef PT_GETFPREGS
|
|
|
|
case PT_GETFPREGS:
|
|
|
|
/* write = 0 above */
|
|
|
|
#endif /* PT_SETFPREGS */
|
|
|
|
#if defined(PT_SETFPREGS) || defined(PT_GETFPREGS)
|
|
|
|
if (!procfs_validfpregs(p)) /* no P_SYSTEM procs please */
|
|
|
|
return EINVAL;
|
|
|
|
else {
|
|
|
|
iov.iov_base = uap->addr;
|
|
|
|
iov.iov_len = sizeof(struct fpreg);
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = 0;
|
|
|
|
uio.uio_resid = sizeof(struct fpreg);
|
|
|
|
uio.uio_segflg = UIO_USERSPACE;
|
|
|
|
uio.uio_rw = write ? UIO_WRITE : UIO_READ;
|
|
|
|
uio.uio_procp = curp;
|
|
|
|
return (procfs_dofpregs(curp, p, NULL, &uio));
|
|
|
|
}
|
|
|
|
#endif /* defined(PT_SETFPREGS) || defined(PT_GETFPREGS) */
|
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
1994-08-08 13:00:27 +00:00
|
|
|
trace_req(p)
|
|
|
|
struct proc *p;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1994-08-08 13:00:27 +00:00
|
|
|
return 1;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|