Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Move code shared by procfs and the kernel proper out of ...



details:   https://anonhg.NetBSD.org/src/rev/2572b6a28b6c
branches:  trunk
changeset: 526749:2572b6a28b6c
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu May 09 15:44:44 2002 +0000

description:
Move code shared by procfs and the kernel proper out of procfs and
into the kernel proper (renaming functions from procfs_* to process_*).

diffstat:

 sys/arch/i386/i386/process_machdep.c |    6 +-
 sys/conf/files                       |    5 +-
 sys/kern/sys_process.c               |  226 +++++++++++++++++++++++++++++++++-
 sys/miscfs/procfs/files.procfs       |    5 +-
 sys/miscfs/procfs/procfs.h           |    3 +-
 sys/miscfs/procfs/procfs_cmdline.c   |    6 +-
 sys/miscfs/procfs/procfs_fpregs.c    |   55 +-------
 sys/miscfs/procfs/procfs_mem.c       |   96 +--------------
 sys/miscfs/procfs/procfs_regs.c      |   55 +-------
 sys/miscfs/procfs/procfs_vnops.c     |    7 +-
 sys/sys/ptrace.h                     |   11 +-
 11 files changed, 258 insertions(+), 217 deletions(-)

diffs (truncated from 767 to 300 lines):

diff -r f4e86627cc78 -r 2572b6a28b6c sys/arch/i386/i386/process_machdep.c
--- a/sys/arch/i386/i386/process_machdep.c      Thu May 09 14:24:03 2002 +0000
+++ b/sys/arch/i386/i386/process_machdep.c      Thu May 09 15:44:44 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: process_machdep.c,v 1.41 2001/12/06 00:01:36 thorpej Exp $     */
+/*     $NetBSD: process_machdep.c,v 1.42 2002/05/09 15:44:46 thorpej Exp $     */
 
 /*-
  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.41 2001/12/06 00:01:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.42 2002/05/09 15:44:46 thorpej Exp $");
 
 #include "opt_vm86.h"
 #include "npx.h"
@@ -533,7 +533,7 @@
        char *kv;
        int kl;
 
-       if ((error = procfs_checkioperm(curp, p)) != 0)
+       if ((error = process_checkioperm(curp, p)) != 0)
                return (error);
 
        kl = sizeof(r);
diff -r f4e86627cc78 -r 2572b6a28b6c sys/conf/files
--- a/sys/conf/files    Thu May 09 14:24:03 2002 +0000
+++ b/sys/conf/files    Thu May 09 15:44:44 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.526 2002/05/03 17:58:28 thorpej Exp $
+#      $NetBSD: files,v 1.527 2002/05/09 15:44:44 thorpej Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -1060,9 +1060,6 @@
 file   miscfs/genfs/layer_subr.c       nullfs | overlay | umapfs | lkm
 file   miscfs/genfs/layer_vfsops.c     nullfs | overlay | umapfs | lkm
 file   miscfs/genfs/layer_vnops.c      nullfs | overlay | umapfs | lkm
-file   miscfs/procfs/procfs_fpregs.c   # XXX
-file   miscfs/procfs/procfs_mem.c      # XXX
-file   miscfs/procfs/procfs_regs.c     # XXX
 file   miscfs/specfs/spec_vnops.c
 file   miscfs/syncfs/sync_subr.c
 file   miscfs/syncfs/sync_vnops.c
diff -r f4e86627cc78 -r 2572b6a28b6c sys/kern/sys_process.c
--- a/sys/kern/sys_process.c    Thu May 09 14:24:03 2002 +0000
+++ b/sys/kern/sys_process.c    Thu May 09 15:44:44 2002 +0000
@@ -1,6 +1,7 @@
-/*     $NetBSD: sys_process.c,v 1.73 2002/03/17 17:02:45 thorpej Exp $ */
+/*     $NetBSD: sys_process.c,v 1.74 2002/05/09 15:44:45 thorpej Exp $ */
 
 /*-
+ * Copyright (c) 1993 Jan-Simon Pendry.
  * Copyright (c) 1994 Christopher G. Demetriou.  All rights reserved.
  * Copyright (c) 1982, 1986, 1989, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -10,6 +11,9 @@
  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  * the permission of UNIX System Laboratories, Inc.
  *
+ * This code is derived from software contributed to Berkeley by
+ * Jan-Simon Pendry.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -53,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.73 2002/03/17 17:02:45 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.74 2002/05/09 15:44:45 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -70,8 +74,6 @@
 
 #include <machine/reg.h>
 
-#include <miscfs/procfs/procfs.h>
-
 /* Macros to clear/set/test flags. */
 #define        SET(t, f)       (t) |= (f)
 #define        CLR(t, f)       (t) &= ~(f)
@@ -254,7 +256,7 @@
                uio.uio_segflg = UIO_SYSSPACE;
                uio.uio_rw = write ? UIO_WRITE : UIO_READ;
                uio.uio_procp = p;
-               error = procfs_domem(p, t, NULL, &uio);
+               error = process_domem(p, t, &uio);
                if (!write)
                        *retval = tmp;
                return (error);
@@ -283,7 +285,7 @@
                default:
                        return (EINVAL);
                }
-               error = procfs_domem(p, t, NULL, &uio);
+               error = process_domem(p, t, &uio);
                piod.piod_len -= uio.uio_resid;
                (void) copyout(&piod, SCARG(uap, addr), sizeof(piod));
                return (error);
@@ -394,7 +396,7 @@
                /* write = 0 done above. */
 #endif
 #if defined(PT_SETREGS) || defined(PT_GETREGS)
-               if (!procfs_validregs(t, NULL))
+               if (!process_validregs(t))
                        return (EINVAL);
                else {
                        iov.iov_base = SCARG(uap, addr);
@@ -406,7 +408,7 @@
                        uio.uio_segflg = UIO_USERSPACE;
                        uio.uio_rw = write ? UIO_WRITE : UIO_READ;
                        uio.uio_procp = p;
-                       return (procfs_doregs(p, t, NULL, &uio));
+                       return (process_doregs(p, t, &uio));
                }
 #endif
 
@@ -419,7 +421,7 @@
                /* write = 0 done above. */
 #endif
 #if defined(PT_SETFPREGS) || defined(PT_GETFPREGS)
-               if (!procfs_validfpregs(t, NULL))
+               if (!process_validfpregs(t))
                        return (EINVAL);
                else {
                        iov.iov_base = SCARG(uap, addr);
@@ -431,7 +433,7 @@
                        uio.uio_segflg = UIO_USERSPACE;
                        uio.uio_rw = write ? UIO_WRITE : UIO_READ;
                        uio.uio_procp = p;
-                       return (procfs_dofpregs(p, t, NULL, &uio));
+                       return (process_dofpregs(p, t, &uio));
                }
 #endif
 
@@ -448,3 +450,207 @@
 #endif
        return 0;
 }
+
+int
+process_doregs(curp, p, uio)
+       struct proc *curp;              /* tracer */
+       struct proc *p;                 /* traced */
+       struct uio *uio;
+{
+#if defined(PT_GETREGS) || defined(PT_SETREGS)
+       int error;
+       struct reg r;
+       char *kv;
+       int kl;
+
+       if ((error = process_checkioperm(curp, p)) != 0)
+               return error;
+
+       kl = sizeof(r);
+       kv = (char *) &r;
+
+       kv += uio->uio_offset;
+       kl -= uio->uio_offset;
+       if (kl > uio->uio_resid)
+               kl = uio->uio_resid;
+
+       PHOLD(p);
+
+       if (kl < 0)
+               error = EINVAL;
+       else
+               error = process_read_regs(p, &r);
+       if (error == 0)
+               error = uiomove(kv, kl, uio);
+       if (error == 0 && uio->uio_rw == UIO_WRITE) {
+               if (p->p_stat != SSTOP)
+                       error = EBUSY;
+               else
+                       error = process_write_regs(p, &r);
+       }
+
+       PRELE(p);
+
+       uio->uio_offset = 0;
+       return (error);
+#else
+       return (EINVAL);
+#endif
+}
+
+int
+process_validregs(p)
+       struct proc *p;
+{
+
+#if defined(PT_SETREGS) || defined(PT_GETREGS)
+       return ((p->p_flag & P_SYSTEM) == 0);
+#else
+       return (0);
+#endif
+}
+
+int
+process_dofpregs(curp, p, uio)
+       struct proc *curp;              /* tracer */
+       struct proc *p;                 /* traced */
+       struct uio *uio;
+{
+#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS)
+       int error;
+       struct fpreg r;
+       char *kv;
+       int kl;
+
+       if ((error = process_checkioperm(curp, p)) != 0)
+               return (error);
+
+       kl = sizeof(r);
+       kv = (char *) &r;
+
+       kv += uio->uio_offset;
+       kl -= uio->uio_offset;
+       if (kl > uio->uio_resid)
+               kl = uio->uio_resid;
+
+       PHOLD(p);
+
+       if (kl < 0)
+               error = EINVAL;
+       else
+               error = process_read_fpregs(p, &r);
+       if (error == 0)
+               error = uiomove(kv, kl, uio);
+       if (error == 0 && uio->uio_rw == UIO_WRITE) {
+               if (p->p_stat != SSTOP)
+                       error = EBUSY;
+               else
+                       error = process_write_fpregs(p, &r);
+       }
+
+       PRELE(p);
+
+       uio->uio_offset = 0;
+       return (error);
+#else
+       return (EINVAL);
+#endif
+}
+
+int
+process_validfpregs(p)
+       struct proc *p;
+{
+
+#if defined(PT_SETFPREGS) || defined(PT_GETFPREGS)
+       return ((p->p_flag & P_SYSTEM) == 0);
+#else
+       return (0);
+#endif
+}
+
+int
+process_domem(curp, p, uio)
+       struct proc *curp;              /* tracer */
+       struct proc *p;                 /* traced */
+       struct uio *uio;
+{
+       int error;
+
+       size_t len;
+#ifdef PMAP_NEED_PROCWR
+       vaddr_t addr;
+#endif
+
+       len = uio->uio_resid;
+
+       if (len == 0)
+               return (0);
+
+#ifdef PMAP_NEED_PROCWR
+       addr = uio->uio_offset;
+#endif
+
+       if ((error = process_checkioperm(curp, p)) != 0)
+               return (error);
+
+       /* XXXCDC: how should locking work here? */
+       if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1)) 
+               return(EFAULT);
+       p->p_vmspace->vm_refcnt++;  /* XXX */
+       error = uvm_io(&p->p_vmspace->vm_map, uio);
+       uvmspace_free(p->p_vmspace);
+
+#ifdef PMAP_NEED_PROCWR
+       if (uio->uio_rw == UIO_WRITE)
+               pmap_procwr(p, addr, len);
+#endif
+       return (error);



Home | Main Index | Thread Index | Old Index