Source-Changes-HG archive

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

[src/trunk]: src/sys Rework the coredump code to have no explicit knownledge ...



details:   https://anonhg.NetBSD.org/src/rev/dd3616c63df7
branches:  trunk
changeset: 581916:dd3616c63df7
user:      matt <matt%NetBSD.org@localhost>
date:      Fri Jun 10 05:10:12 2005 +0000

description:
Rework the coredump code to have no explicit knownledge of how coredump
i/o is done.  Instead, pass an opaque cookie which is then passed to a
new routine, coredump_write, which does the actual i/o.  This allows the
method of doing i/o to change without affecting any future MD code.
Also, make netbsd32_core.c [re]use core_netbsd.c (in a similar manner that
core_elf64.c uses core_elf32.c) and eliminate that code duplication.
cpu_coredump{,32} is now called twice, first with a NULL iocookie to fill
the core structure and a second to actually write md parts of the coredump.
All i/o is nolonger random access and is suitable for shipping over a stream.

diffstat:

 sys/arch/alpha/alpha/vm_machdep.c           |   34 ++---
 sys/arch/amd64/amd64/netbsd32_machdep.c     |   34 ++---
 sys/arch/amd64/amd64/vm_machdep.c           |   37 ++----
 sys/arch/arm/arm/vm_machdep_arm.c           |   35 ++---
 sys/arch/hppa/hppa/vm_machdep.c             |   36 +++---
 sys/arch/i386/i386/vm_machdep.c             |   34 ++---
 sys/arch/m68k/m68k/vm_machdep.c             |   34 ++---
 sys/arch/mips/mips/vm_machdep.c             |   37 +++---
 sys/arch/pc532/pc532/vm_machdep.c           |   37 ++----
 sys/arch/pdp10/pdp10/vm_machdep.c           |    5 +-
 sys/arch/powerpc/powerpc/vm_machdep.c       |   33 +++---
 sys/arch/sh3/sh3/vm_machdep.c               |   35 ++---
 sys/arch/sh5/sh5/netbsd32_machdep.c         |    6 +-
 sys/arch/sh5/sh5/vm_machdep.c               |   36 +++---
 sys/arch/sparc/sparc/vm_machdep.c           |   40 +++----
 sys/arch/sparc64/sparc64/netbsd32_machdep.c |   37 +++---
 sys/arch/sparc64/sparc64/vm_machdep.c       |   38 +++----
 sys/arch/vax/vax/vm_machdep.c               |   46 +++-----
 sys/compat/netbsd32/netbsd32.h              |    4 +-
 sys/compat/netbsd32/netbsd32_core.c         |  116 +---------------------
 sys/kern/core_elf32.c                       |  148 ++++++++++-----------------
 sys/kern/core_netbsd.c                      |   96 ++++++++++-------
 sys/kern/kern_sig.c                         |   36 ++++++-
 sys/sys/exec.h                              |   14 ++-
 sys/sys/exec_elf.h                          |   14 +-
 sys/sys/signalvar.h                         |   10 +-
 sys/uvm/uvm_extern.h                        |    7 +-
 sys/uvm/uvm_glue.c                          |   14 +-
 28 files changed, 438 insertions(+), 615 deletions(-)

diffs (truncated from 2123 to 300 lines):

diff -r 41d93a01ff9e -r dd3616c63df7 sys/arch/alpha/alpha/vm_machdep.c
--- a/sys/arch/alpha/alpha/vm_machdep.c Fri Jun 10 02:35:34 2005 +0000
+++ b/sys/arch/alpha/alpha/vm_machdep.c Fri Jun 10 05:10:12 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.85 2005/04/01 11:59:22 yamt Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.86 2005/06/10 05:10:12 matt Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.85 2005/04/01 11:59:22 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.86 2005/06/10 05:10:12 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -52,17 +52,20 @@
  * Dump the machine specific header information at the start of a core dump.
  */
 int
-cpu_coredump(struct lwp *l, struct vnode *vp, struct ucred *cred,
-    struct core *chdr)
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
 {
        int error;
        struct md_coredump cpustate;
        struct coreseg cseg;
 
-       CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-       chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-       chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-       chdr->c_cpusize = sizeof(cpustate);
+       if (iocookie == NULL) {
+               CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+               chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+               chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+               chdr->c_cpusize = sizeof(cpustate);
+               chdr->c_nseg++;
+               return 0;
+       }
 
        cpustate.md_tf = *l->l_md.md_tf;
        cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp();   /* XXX */
@@ -77,20 +80,13 @@
        cseg.c_addr = 0;
        cseg.c_size = chdr->c_cpusize;
 
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cseg, chdr->c_seghdrsize,
-           (off_t)chdr->c_hdrsize, UIO_SYSSPACE,
-           IO_NODELOCKED|IO_UNIT, cred, NULL, NULL);
+       error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+           chdr->c_seghdrsize);
        if (error)
                return error;
 
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cpustate, sizeof(cpustate),
-           (off_t)(chdr->c_hdrsize + chdr->c_seghdrsize), UIO_SYSSPACE,
-           IO_NODELOCKED|IO_UNIT, cred, NULL, NULL);
-
-       if (!error)
-               chdr->c_nseg++;
-
-       return error;
+       return coredump_write(iocookie, UIO_SYSSPACE, &cpustate,
+           sizeof(cpustate));
 }
 
 void
diff -r 41d93a01ff9e -r dd3616c63df7 sys/arch/amd64/amd64/netbsd32_machdep.c
--- a/sys/arch/amd64/amd64/netbsd32_machdep.c   Fri Jun 10 02:35:34 2005 +0000
+++ b/sys/arch/amd64/amd64/netbsd32_machdep.c   Fri Jun 10 05:10:12 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.c,v 1.14 2005/06/02 10:29:04 drochner Exp $   */
+/*     $NetBSD: netbsd32_machdep.c,v 1.15 2005/06/10 05:10:12 matt Exp $       */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.14 2005/06/02 10:29:04 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.15 2005/06/10 05:10:12 matt Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_execfmt.h"
@@ -419,17 +419,20 @@
 };
 
 int
-cpu_coredump32(struct lwp *l, struct vnode *vp, struct ucred *cred,
-            struct core32 *chdr)
+cpu_coredump32(struct lwp *l, void *iocookie, struct core32 *chdr)
 {
        struct md_core32 md_core;
        struct coreseg cseg;
        int error;
 
-       CORE_SETMAGIC(*chdr, COREMAGIC, MID_I386, 0);
-       chdr->c_hdrsize = ALIGN32(sizeof(*chdr));
-       chdr->c_seghdrsize = ALIGN32(sizeof(cseg));
-       chdr->c_cpusize = sizeof(md_core);
+       if (iocookie == NULL) {
+               CORE_SETMAGIC(*chdr, COREMAGIC, MID_I386, 0);
+               chdr->c_hdrsize = ALIGN32(sizeof(*chdr));
+               chdr->c_seghdrsize = ALIGN32(sizeof(cseg));
+               chdr->c_cpusize = sizeof(md_core);
+               chdr->c_nseg++;
+               return 0;
+       }
 
        /* Save integer registers. */
        error = process_read_regs32(l, &md_core.intreg);
@@ -445,20 +448,13 @@
        cseg.c_addr = 0;
        cseg.c_size = chdr->c_cpusize;
 
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cseg, chdr->c_seghdrsize,
-           (off_t)chdr->c_hdrsize, UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred,
-           NULL, NULL);
+       error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+           chdr->c_seghdrsize);
        if (error)
                return error;
 
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&md_core, sizeof(md_core),
-           (off_t)(chdr->c_hdrsize + chdr->c_seghdrsize), UIO_SYSSPACE,
-           IO_NODELOCKED|IO_UNIT, cred, NULL, NULL);
-       if (error)
-               return error;
-
-       chdr->c_nseg++;
-       return 0;
+       return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
+           sizeof(md_core));
 }
 
 
diff -r 41d93a01ff9e -r dd3616c63df7 sys/arch/amd64/amd64/vm_machdep.c
--- a/sys/arch/amd64/amd64/vm_machdep.c Fri Jun 10 02:35:34 2005 +0000
+++ b/sys/arch/amd64/amd64/vm_machdep.c Fri Jun 10 05:10:12 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vm_machdep.c,v 1.10 2005/04/01 11:59:23 yamt Exp $     */
+/*     $NetBSD: vm_machdep.c,v 1.11 2005/06/10 05:10:12 matt Exp $     */
 
 /*-
  * Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.10 2005/04/01 11:59:23 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.11 2005/06/10 05:10:12 matt Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_largepages.h"
@@ -285,20 +285,20 @@
 };
 
 int
-cpu_coredump(l, vp, cred, chdr)
-       struct lwp *l;
-       struct vnode *vp;
-       struct ucred *cred;
-       struct core *chdr;
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
 {
        struct md_core md_core;
        struct coreseg cseg;
        int error;
 
-       CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-       chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-       chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-       chdr->c_cpusize = sizeof(md_core);
+       if (iocookie == NULL) {
+               CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+               chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+               chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+               chdr->c_cpusize = sizeof(md_core);
+               chdr->c_nseg++;
+               return 0;
+       }
 
        /* Save integer registers. */
        error = process_read_regs(l, &md_core.intreg);
@@ -314,20 +314,13 @@
        cseg.c_addr = 0;
        cseg.c_size = chdr->c_cpusize;
 
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cseg, chdr->c_seghdrsize,
-           (off_t)chdr->c_hdrsize, UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred,
-           NULL, NULL);
+       error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
+           chdr->c_seghdrsize);
        if (error)
                return error;
 
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&md_core, sizeof(md_core),
-           (off_t)(chdr->c_hdrsize + chdr->c_seghdrsize), UIO_SYSSPACE,
-           IO_NODELOCKED|IO_UNIT, cred, NULL, NULL);
-       if (error)
-               return error;
-
-       chdr->c_nseg++;
-       return 0;
+       return coredump_write(iocookie, UIO_USERSPACE, &md_core,
+           sizeof(md_core));
 }
 
 /*
diff -r 41d93a01ff9e -r dd3616c63df7 sys/arch/arm/arm/vm_machdep_arm.c
--- a/sys/arch/arm/arm/vm_machdep_arm.c Fri Jun 10 02:35:34 2005 +0000
+++ b/sys/arch/arm/arm/vm_machdep_arm.c Fri Jun 10 05:10:12 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vm_machdep_arm.c,v 1.8 2004/09/17 14:11:21 skrll Exp $ */
+/*     $NetBSD: vm_machdep_arm.c,v 1.9 2005/06/10 05:10:12 matt Exp $  */
 
 /*
  * Copyright (c) 1994-1998 Mark Brinicombe.
@@ -37,7 +37,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep_arm.c,v 1.8 2004/09/17 14:11:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep_arm.c,v 1.9 2005/06/10 05:10:12 matt Exp $");
 
 #include <sys/core.h>
 #include <sys/exec.h>
@@ -55,8 +55,7 @@
  */
 
 int
-cpu_coredump(struct lwp *l, struct vnode *vp, struct ucred *cred,
-    struct core *chdr)
+cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
 {
        int error;
        struct {
@@ -65,10 +64,14 @@
        } cpustate;
        struct coreseg cseg;
 
-       CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
-       chdr->c_hdrsize = ALIGN(sizeof(*chdr));
-       chdr->c_seghdrsize = ALIGN(sizeof(cseg));
-       chdr->c_cpusize = sizeof(cpustate);
+       if (iocookie == NULL) {
+               CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
+               chdr->c_hdrsize = ALIGN(sizeof(*chdr));
+               chdr->c_seghdrsize = ALIGN(sizeof(cseg));
+               chdr->c_cpusize = sizeof(cpustate);
+               chdr->c_nseg++;
+               return 0;
+       }
 
        /* Save integer registers. */
        error = process_read_regs(l, &cpustate.regs);
@@ -83,19 +86,11 @@
        cseg.c_addr = 0;
        cseg.c_size = chdr->c_cpusize;
 
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cseg, chdr->c_seghdrsize,
-           (off_t)chdr->c_hdrsize, UIO_SYSSPACE,
-           IO_NODELOCKED|IO_UNIT, cred, NULL, NULL);
+       error = coredump_write(iocookie, UIO_SYSSPACE,
+           &cseg, chdr->c_seghdrsize);
        if (error)
                return error;
 
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cpustate, sizeof(cpustate),
-           (off_t)(chdr->c_hdrsize + chdr->c_seghdrsize), UIO_SYSSPACE,
-           IO_NODELOCKED|IO_UNIT, cred, NULL, NULL);
-       if (error)
-               return error;
-
-       chdr->c_nseg++;
-
-       return error;
+       return coredump_write(iocookie, UIO_SYSSPACE,
+           &cpustate, sizeof(cpustate));
 }
diff -r 41d93a01ff9e -r dd3616c63df7 sys/arch/hppa/hppa/vm_machdep.c
--- a/sys/arch/hppa/hppa/vm_machdep.c   Fri Jun 10 02:35:34 2005 +0000
+++ b/sys/arch/hppa/hppa/vm_machdep.c   Fri Jun 10 05:10:12 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vm_machdep.c,v 1.16 2005/05/01 15:23:18 chs Exp $      */
+/*     $NetBSD: vm_machdep.c,v 1.17 2005/06/10 05:10:12 matt Exp $     */
 
 /*     $OpenBSD: vm_machdep.c,v 1.25 2001/09/19 20:50:56 mickey Exp $  */
 
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.16 2005/05/01 15:23:18 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.17 2005/06/10 05:10:12 matt Exp $");
 



Home | Main Index | Thread Index | Old Index