summaryrefslogtreecommitdiffstats
path: root/sys/i386
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-03-31 22:37:00 +0000
committerphk <phk@FreeBSD.org>2002-03-31 22:37:00 +0000
commitef82a516346a59befd780764209cd79a53941758 (patch)
tree0962f06e2a2c422d89af486eb66e8e726fea13b7 /sys/i386
parentb19c49c220775864538a4c0608a821586b85eda2 (diff)
downloadFreeBSD-src-ef82a516346a59befd780764209cd79a53941758.zip
FreeBSD-src-ef82a516346a59befd780764209cd79a53941758.tar.gz
Here follows the new kernel dumping infrastructure.
Caveats: The new savecore program is not complete in the sense that it emulates enough of the old savecores features to do the job, but implements none of the options yet. I would appreciate if a userland hacker could help me out getting savecore to do what we want it to do from a users point of view, compression, email-notification, space reservation etc etc. (send me email if you are interested). Currently, savecore will scan all devices marked as "swap" or "dump" in /etc/fstab _or_ any devices specified on the command-line. All architectures but i386 lack an implementation of dumpsys(), but looking at the i386 version it should be trivial for anybody familiar with the platform(s) to provide this function. Documentation is quite sparse at this time, more to come. Details: ATA and SCSI drivers should work as the dump formatting code has been removed. The IDA, TWE and AAC have not yet been converted. Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set the device as dumpdev. To implement the "off" argument, /dev/null is used as the device. Savecore will fail if handed any options since they are not (yet) implemented. All devices marked "dump" or "swap" in /etc/fstab will be scanned and dumps found will be saved to diskfiles named from the MD5 hash of the header record. The header record is dumped in readable format in the .info file. The kernel is not saved. Only complete dumps will be saved. All maintainer rights for this code are disclaimed: feel free to improve and extend. Sponsored by: DARPA, NAI Labs
Diffstat (limited to 'sys/i386')
-rw-r--r--sys/i386/i386/dump_machdep.c121
-rw-r--r--sys/i386/i386/i386dump.c121
2 files changed, 242 insertions, 0 deletions
diff --git a/sys/i386/i386/dump_machdep.c b/sys/i386/i386/dump_machdep.c
new file mode 100644
index 0000000..b914af1
--- /dev/null
+++ b/sys/i386/i386/dump_machdep.c
@@ -0,0 +1,121 @@
+/*-
+ * Copyright (c) 2002 Poul-Henning Kamp
+ * Copyright (c) 2002 Networks Associates Technology, Inc.
+ * All rights reserved.
+ *
+ * This software was developed for the FreeBSD Project by Poul-Henning Kamp
+ * and NAI Labs, the Security Research Division of Network Associates, Inc.
+ * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
+ * DARPA CHATS research program.
+ *
+ * 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. The names of the authors may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/kerneldump.h>
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <machine/md_var.h>
+
+static struct kerneldumpheader kdh;
+
+void
+dumpsys(struct dumperinfo *di)
+{
+ off_t dumplo;
+ vm_offset_t a, addr;
+ u_int count, left, u;
+ void *va;
+ int i, mb;
+
+ printf("Dumping %u MB\n", Maxmem / (1024*1024 / PAGE_SIZE));
+
+ if (sizeof kdh != 512) {
+ printf(
+ "Compiled struct kerneldumpheader is %d, not %d bytes\n",
+ sizeof kdh, 512);
+ return;
+ }
+
+ /* Fill in the kernel dump header */
+ strcpy(kdh.magic, KERNELDUMPMAGIC);
+ strcpy(kdh.architecture, "i386");
+ kdh.version = KERNELDUMPVERSION;
+ kdh.architectureversion = KERNELDUMP_I386_VERSION;
+ kdh.dumplength = Maxmem * (off_t)PAGE_SIZE;
+ kdh.blocksize = di->blocksize;
+ kdh.dumptime = time_second;
+ strncpy(kdh.hostname, hostname, sizeof kdh.hostname);
+ strncpy(kdh.versionstring, version, sizeof kdh.versionstring);
+ if (panicstr != NULL)
+ strncpy(kdh.panicstring, panicstr, sizeof kdh.panicstring);
+ kdh.parity = kerneldump_parity(&kdh);
+
+ dumplo = di->mediaoffset + di->mediasize - Maxmem * (off_t)PAGE_SIZE;
+ dumplo -= sizeof kdh * 2;
+ i = di->dumper(di->priv, &kdh, NULL, dumplo, sizeof kdh);
+ if (i)
+ printf("\nDump failed writing header (%d)\n", i);
+ dumplo += sizeof kdh;
+ i = 0;
+ addr = 0;
+ va = 0;
+ mb = 0;
+ for (count = 0; count < Maxmem;) {
+ left = Maxmem - count;
+ if (left > MAXDUMPPGS)
+ left = MAXDUMPPGS;
+ for (u = 0; u < left; u++) {
+ a = addr + u * PAGE_SIZE;
+ if (!is_physical_memory(a))
+ a = 0;
+ va = pmap_kenter_temporary(trunc_page(a), u);
+ }
+ i = count / (16*1024*1024 / PAGE_SIZE);
+ if (i != mb) {
+ printf(" %d", count / (1024 * 1024 / PAGE_SIZE));
+ mb = i;
+ }
+ i = di->dumper(di->priv, va, NULL, dumplo, left * PAGE_SIZE);
+ if (i)
+ break;
+ count += left;
+ dumplo += left * PAGE_SIZE;
+ addr += left * PAGE_SIZE;
+ }
+ if (i)
+ printf("\nDump failed writing data (%d)\n", i);
+ i = di->dumper(di->priv, &kdh, NULL, dumplo, sizeof kdh);
+ if (i)
+ printf("\nDump failed writing trailer (%d)\n", i);
+ di->dumper(di->priv, NULL, NULL, 0, 0); /* tell them we are done */
+ printf("\nDump complete\n");
+ return;
+}
diff --git a/sys/i386/i386/i386dump.c b/sys/i386/i386/i386dump.c
new file mode 100644
index 0000000..b914af1
--- /dev/null
+++ b/sys/i386/i386/i386dump.c
@@ -0,0 +1,121 @@
+/*-
+ * Copyright (c) 2002 Poul-Henning Kamp
+ * Copyright (c) 2002 Networks Associates Technology, Inc.
+ * All rights reserved.
+ *
+ * This software was developed for the FreeBSD Project by Poul-Henning Kamp
+ * and NAI Labs, the Security Research Division of Network Associates, Inc.
+ * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
+ * DARPA CHATS research program.
+ *
+ * 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. The names of the authors may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/kerneldump.h>
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <machine/md_var.h>
+
+static struct kerneldumpheader kdh;
+
+void
+dumpsys(struct dumperinfo *di)
+{
+ off_t dumplo;
+ vm_offset_t a, addr;
+ u_int count, left, u;
+ void *va;
+ int i, mb;
+
+ printf("Dumping %u MB\n", Maxmem / (1024*1024 / PAGE_SIZE));
+
+ if (sizeof kdh != 512) {
+ printf(
+ "Compiled struct kerneldumpheader is %d, not %d bytes\n",
+ sizeof kdh, 512);
+ return;
+ }
+
+ /* Fill in the kernel dump header */
+ strcpy(kdh.magic, KERNELDUMPMAGIC);
+ strcpy(kdh.architecture, "i386");
+ kdh.version = KERNELDUMPVERSION;
+ kdh.architectureversion = KERNELDUMP_I386_VERSION;
+ kdh.dumplength = Maxmem * (off_t)PAGE_SIZE;
+ kdh.blocksize = di->blocksize;
+ kdh.dumptime = time_second;
+ strncpy(kdh.hostname, hostname, sizeof kdh.hostname);
+ strncpy(kdh.versionstring, version, sizeof kdh.versionstring);
+ if (panicstr != NULL)
+ strncpy(kdh.panicstring, panicstr, sizeof kdh.panicstring);
+ kdh.parity = kerneldump_parity(&kdh);
+
+ dumplo = di->mediaoffset + di->mediasize - Maxmem * (off_t)PAGE_SIZE;
+ dumplo -= sizeof kdh * 2;
+ i = di->dumper(di->priv, &kdh, NULL, dumplo, sizeof kdh);
+ if (i)
+ printf("\nDump failed writing header (%d)\n", i);
+ dumplo += sizeof kdh;
+ i = 0;
+ addr = 0;
+ va = 0;
+ mb = 0;
+ for (count = 0; count < Maxmem;) {
+ left = Maxmem - count;
+ if (left > MAXDUMPPGS)
+ left = MAXDUMPPGS;
+ for (u = 0; u < left; u++) {
+ a = addr + u * PAGE_SIZE;
+ if (!is_physical_memory(a))
+ a = 0;
+ va = pmap_kenter_temporary(trunc_page(a), u);
+ }
+ i = count / (16*1024*1024 / PAGE_SIZE);
+ if (i != mb) {
+ printf(" %d", count / (1024 * 1024 / PAGE_SIZE));
+ mb = i;
+ }
+ i = di->dumper(di->priv, va, NULL, dumplo, left * PAGE_SIZE);
+ if (i)
+ break;
+ count += left;
+ dumplo += left * PAGE_SIZE;
+ addr += left * PAGE_SIZE;
+ }
+ if (i)
+ printf("\nDump failed writing data (%d)\n", i);
+ i = di->dumper(di->priv, &kdh, NULL, dumplo, sizeof kdh);
+ if (i)
+ printf("\nDump failed writing trailer (%d)\n", i);
+ di->dumper(di->priv, NULL, NULL, 0, 0); /* tell them we are done */
+ printf("\nDump complete\n");
+ return;
+}
OpenPOWER on IntegriCloud