summaryrefslogtreecommitdiffstats
path: root/sys/fs/procfs
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2001-10-07 20:08:42 +0000
committerdes <des@FreeBSD.org>2001-10-07 20:08:42 +0000
commit29c5c858fce0c57b6ec8d88ecac8c437e7eb7f31 (patch)
tree619938768546b5f4413bb8dc40f32a9f6cff02e7 /sys/fs/procfs
parent6eea6dc1d4f5db40f3dc480af266ecd685f624a2 (diff)
downloadFreeBSD-src-29c5c858fce0c57b6ec8d88ecac8c437e7eb7f31.zip
FreeBSD-src-29c5c858fce0c57b6ec8d88ecac8c437e7eb7f31.tar.gz
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called various functions in procfs depending on which ptrace operation was requested. Most of these functions were themselves wrappers around procfs_{read,write}_{,db,fp}regs(), with only some extra error checks, which weren't necessary in the ptrace case anyway. This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c (renaming it to proc_rwmem() in the process), and implements ptrace() directly in terms of procfs_{read,write}_{,db,fp}regs() instead of having it fake up a struct uio and then call procfs_do{,db,fp}regs(). It also moves the prototypes for procfs_{read,write}_{,db,fp}regs() and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files except procfs_machdep.c as "optional procfs" instead of "standard".
Diffstat (limited to 'sys/fs/procfs')
-rw-r--r--sys/fs/procfs/procfs.h9
-rw-r--r--sys/fs/procfs/procfs_dbregs.c1
-rw-r--r--sys/fs/procfs/procfs_fpregs.c1
-rw-r--r--sys/fs/procfs/procfs_mem.c218
-rw-r--r--sys/fs/procfs/procfs_regs.c1
5 files changed, 4 insertions, 226 deletions
diff --git a/sys/fs/procfs/procfs.h b/sys/fs/procfs/procfs.h
index d97f825..67af4be 100644
--- a/sys/fs/procfs/procfs.h
+++ b/sys/fs/procfs/procfs.h
@@ -118,15 +118,6 @@ struct dbreg;
void procfs_exit __P((struct proc *));
int procfs_freevp __P((struct vnode *));
int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
-struct vnode *procfs_findtextvp __P((struct proc *));
-int procfs_sstep __P((struct thread *));
-void procfs_fix_sstep __P((struct thread *));
-int procfs_read_regs __P((struct thread *, struct reg *));
-int procfs_write_regs __P((struct thread *, struct reg *));
-int procfs_read_fpregs __P((struct thread *, struct fpreg *));
-int procfs_write_fpregs __P((struct thread *, struct fpreg *));
-int procfs_read_dbregs __P((struct thread *, struct dbreg *));
-int procfs_write_dbregs __P((struct thread *, struct dbreg *));
int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
diff --git a/sys/fs/procfs/procfs_dbregs.c b/sys/fs/procfs/procfs_dbregs.c
index 5de041a..1327f27 100644
--- a/sys/fs/procfs/procfs_dbregs.c
+++ b/sys/fs/procfs/procfs_dbregs.c
@@ -48,6 +48,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/ptrace.h>
#include <sys/vnode.h>
#include <machine/reg.h>
diff --git a/sys/fs/procfs/procfs_fpregs.c b/sys/fs/procfs/procfs_fpregs.c
index 2b68693..b01509b 100644
--- a/sys/fs/procfs/procfs_fpregs.c
+++ b/sys/fs/procfs/procfs_fpregs.c
@@ -45,6 +45,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/ptrace.h>
#include <sys/vnode.h>
#include <machine/reg.h>
diff --git a/sys/fs/procfs/procfs_mem.c b/sys/fs/procfs/procfs_mem.c
index 29773a0..95c91f2 100644
--- a/sys/fs/procfs/procfs_mem.c
+++ b/sys/fs/procfs/procfs_mem.c
@@ -40,11 +40,6 @@
* $FreeBSD$
*/
-/*
- * This is a lightly hacked and merged version
- * of sef's pread/pwrite functions
- */
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/lock.h>
@@ -56,184 +51,6 @@
#include <fs/procfs/procfs.h>
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <vm/vm_extern.h>
-#include <vm/vm_map.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_object.h>
-#include <vm/vm_page.h>
-
-static int procfs_rwmem __P((struct proc *curp,
- struct proc *p, struct uio *uio));
-
-static int
-procfs_rwmem(curp, p, uio)
- struct proc *curp;
- struct proc *p;
- struct uio *uio;
-{
- int error;
- int writing;
- struct vmspace *vm;
- vm_map_t map;
- vm_object_t object = NULL;
- vm_offset_t pageno = 0; /* page number */
- vm_prot_t reqprot;
- vm_offset_t kva;
-
- GIANT_REQUIRED;
-
- /*
- * if the vmspace is in the midst of being deallocated or the
- * process is exiting, don't try to grab anything. The page table
- * usage in that process can be messed up.
- */
- vm = p->p_vmspace;
- if ((p->p_flag & P_WEXIT))
- return EFAULT;
- if (vm->vm_refcnt < 1)
- return EFAULT;
- ++vm->vm_refcnt;
- /*
- * The map we want...
- */
- map = &vm->vm_map;
-
- writing = uio->uio_rw == UIO_WRITE;
- reqprot = writing ? (VM_PROT_WRITE | VM_PROT_OVERRIDE_WRITE) : VM_PROT_READ;
-
- kva = kmem_alloc_pageable(kernel_map, PAGE_SIZE);
-
- /*
- * Only map in one page at a time. We don't have to, but it
- * makes things easier. This way is trivial - right?
- */
- do {
- vm_map_t tmap;
- vm_offset_t uva;
- int page_offset; /* offset into page */
- vm_map_entry_t out_entry;
- vm_prot_t out_prot;
- boolean_t wired;
- vm_pindex_t pindex;
- u_int len;
- vm_page_t m;
-
- object = NULL;
-
- uva = (vm_offset_t) uio->uio_offset;
-
- /*
- * Get the page number of this segment.
- */
- pageno = trunc_page(uva);
- page_offset = uva - pageno;
-
- /*
- * How many bytes to copy
- */
- len = min(PAGE_SIZE - page_offset, uio->uio_resid);
-
- /*
- * Fault the page on behalf of the process
- */
- error = vm_fault(map, pageno, reqprot, VM_FAULT_NORMAL);
- if (error) {
- error = EFAULT;
- break;
- }
-
- /*
- * 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;
- error = vm_map_lookup(&tmap, pageno, reqprot,
- &out_entry, &object, &pindex, &out_prot,
- &wired);
-
- if (error) {
- error = EFAULT;
-
- /*
- * Make sure that there is no residue in 'object' from
- * an error return on vm_map_lookup.
- */
- object = NULL;
-
- break;
- }
-
- m = vm_page_lookup(object, pindex);
-
- /* Allow fallback to backing objects if we are reading */
-
- while (m == NULL && !writing && object->backing_object) {
-
- pindex += OFF_TO_IDX(object->backing_object_offset);
- object = object->backing_object;
-
- m = vm_page_lookup(object, pindex);
- }
-
- if (m == NULL) {
- error = EFAULT;
-
- /*
- * Make sure that there is no residue in 'object' from
- * an error return on vm_map_lookup.
- */
- object = NULL;
-
- vm_map_lookup_done(tmap, out_entry);
-
- break;
- }
-
- /*
- * Wire the page into memory
- */
- vm_page_wire(m);
-
- /*
- * We're done with tmap now.
- * But reference the object first, so that we won't loose
- * it.
- */
- vm_object_reference(object);
- vm_map_lookup_done(tmap, out_entry);
-
- pmap_kenter(kva, VM_PAGE_TO_PHYS(m));
-
- /*
- * Now do the i/o move.
- */
- error = uiomove((caddr_t)(kva + page_offset), len, uio);
-
- pmap_kremove(kva);
-
- /*
- * release the page and the object
- */
- vm_page_unwire(m, 1);
- vm_object_deallocate(object);
-
- object = NULL;
-
- } while (error == 0 && uio->uio_resid > 0);
-
- if (object)
- vm_object_deallocate(object);
-
- kmem_free(kernel_map, kva, PAGE_SIZE);
- vmspace_free(vm);
- return (error);
-}
-
/*
* Copy data in and out of the target process.
* We do this by mapping the process's page into
@@ -256,38 +73,5 @@ procfs_domem(curp, p, pfs, uio)
if (error)
return (error);
- return (procfs_rwmem(curp, p, uio));
-}
-
-/*
- * Given process (p), find the vnode from which
- * its text segment is being executed.
- *
- * It would be nice to grab this information from
- * the VM system, however, there is no sure-fire
- * way of doing that. Instead, fork(), exec() and
- * wait() all maintain the p_textvp field in the
- * process proc structure which contains a held
- * reference to the exec'ed vnode.
- *
- * XXX - Currently, this is not not used, as the
- * /proc/pid/file object exposes an information leak
- * that shouldn't happen. Using a mount option would
- * make it configurable on a per-system (or, at least,
- * per-mount) basis; however, that's not really best.
- * The best way to do it, I think, would be as an
- * ioctl; this would restrict it to the uid running
- * program, or root, which seems a reasonable compromise.
- * However, the number of applications for this is
- * minimal, if it can't be seen in the filesytem space,
- * and doint it as an ioctl makes it somewhat less
- * useful due to the, well, inelegance.
- *
- */
-struct vnode *
-procfs_findtextvp(p)
- struct proc *p;
-{
-
- return (p->p_textvp);
+ return (proc_rwmem(p, uio));
}
diff --git a/sys/fs/procfs/procfs_regs.c b/sys/fs/procfs/procfs_regs.c
index f590075..27e950d 100644
--- a/sys/fs/procfs/procfs_regs.c
+++ b/sys/fs/procfs/procfs_regs.c
@@ -45,6 +45,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/ptrace.h>
#include <sys/vnode.h>
#include <machine/reg.h>
OpenPOWER on IntegriCloud