summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2008-10-01 22:08:53 +0000
committerpeter <peter@FreeBSD.org>2008-10-01 22:08:53 +0000
commited8d07f23214ae559c4d1e24298f7334368c1fa5 (patch)
tree63a9bf6e972762df141963f82c26829a6b8cb9b8 /sys
parent17415143e3ea50776074328a4bc9b5e9aa942dba (diff)
downloadFreeBSD-src-ed8d07f23214ae559c4d1e24298f7334368c1fa5.zip
FreeBSD-src-ed8d07f23214ae559c4d1e24298f7334368c1fa5.tar.gz
Collect N identical (or near identical) mkdumpheader() implementations into
one, as threatened in the comment. Textdump magic can be passed in.
Diffstat (limited to 'sys')
-rw-r--r--sys/amd64/amd64/dump_machdep.c23
-rw-r--r--sys/amd64/amd64/minidump_machdep.c23
-rw-r--r--sys/arm/arm/dump_machdep.c23
-rw-r--r--sys/ddb/db_textdump.c28
-rw-r--r--sys/i386/i386/dump_machdep.c23
-rw-r--r--sys/i386/i386/minidump_machdep.c23
-rw-r--r--sys/ia64/ia64/dump_machdep.c23
-rw-r--r--sys/kern/kern_shutdown.c22
-rw-r--r--sys/sparc64/sparc64/dump_machdep.c23
-rw-r--r--sys/sun4v/sun4v/dump_machdep.c23
-rw-r--r--sys/sys/kerneldump.h5
11 files changed, 37 insertions, 202 deletions
diff --git a/sys/amd64/amd64/dump_machdep.c b/sys/amd64/amd64/dump_machdep.c
index 08d32d5..c07f0ca 100644
--- a/sys/amd64/amd64/dump_machdep.c
+++ b/sys/amd64/amd64/dump_machdep.c
@@ -105,27 +105,6 @@ md_pa_next(struct md_pa *mdp)
return (mdp);
}
-/* XXX should be MI */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen,
- uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
static int
buf_write(struct dumperinfo *di, char *ptr, size_t sz)
{
@@ -326,7 +305,7 @@ dumpsys(struct dumperinfo *di)
dumplo = di->mediaoffset + di->mediasize - dumpsize;
dumplo -= sizeof(kdh) * 2;
- mkdumpheader(&kdh, KERNELDUMP_AMD64_VERSION, dumpsize, di->blocksize);
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AMD64_VERSION, dumpsize, di->blocksize);
printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20,
ehdr.e_phnum);
diff --git a/sys/amd64/amd64/minidump_machdep.c b/sys/amd64/amd64/minidump_machdep.c
index d3c4309..ec6727c 100644
--- a/sys/amd64/amd64/minidump_machdep.c
+++ b/sys/amd64/amd64/minidump_machdep.c
@@ -81,27 +81,6 @@ is_dumpable(vm_paddr_t pa)
return (0);
}
-/* XXX should be MI */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen,
- uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
#define PG2MB(pgs) (((pgs) + (1 << 8) - 1) >> 8)
static int
@@ -284,7 +263,7 @@ minidumpsys(struct dumperinfo *di)
mdhdr.dmapbase = DMAP_MIN_ADDRESS;
mdhdr.dmapend = DMAP_MAX_ADDRESS;
- mkdumpheader(&kdh, KERNELDUMP_AMD64_VERSION, dumpsize, di->blocksize);
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AMD64_VERSION, dumpsize, di->blocksize);
printf("Physical memory: %ju MB\n", ptoa((uintmax_t)physmem) / 1048576);
printf("Dumping %llu MB:", (long long)dumpsize >> 20);
diff --git a/sys/arm/arm/dump_machdep.c b/sys/arm/arm/dump_machdep.c
index 391bc40..87943c2 100644
--- a/sys/arm/arm/dump_machdep.c
+++ b/sys/arm/arm/dump_machdep.c
@@ -103,27 +103,6 @@ md_pa_next(struct md_pa *mdp)
return (mdp);
}
-/* XXX should be MI */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen,
- uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
static int
buf_write(struct dumperinfo *di, char *ptr, size_t sz)
{
@@ -325,7 +304,7 @@ dumpsys(struct dumperinfo *di)
dumplo = di->mediaoffset + di->mediasize - dumpsize;
dumplo -= sizeof(kdh) * 2;
- mkdumpheader(&kdh, KERNELDUMP_ARM_VERSION, dumpsize, di->blocksize);
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_ARM_VERSION, dumpsize, di->blocksize);
printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20,
ehdr.e_phnum);
diff --git a/sys/ddb/db_textdump.c b/sys/ddb/db_textdump.c
index dd48acc..e906962 100644
--- a/sys/ddb/db_textdump.c
+++ b/sys/ddb/db_textdump.c
@@ -177,30 +177,6 @@ char textdump_block_buffer[TEXTDUMP_BLOCKSIZE];
static struct kerneldumpheader kdh;
/*
- * Text dumps are prefixed with a normal kernel dump header but with a
- * different magic number to allow them to be uniquely identified.
- */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver,
- uint64_t dumplen, uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, TEXTDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
-/*
* Calculate and fill in the checksum for a ustar header.
*/
static void
@@ -468,7 +444,7 @@ textdump_dumpsys(struct dumperinfo *di)
*/
textdump_offset = di->mediasize - sizeof(kdh);
textdump_saveoff(&trailer_offset);
- mkdumpheader(&kdh, KERNELDUMP_TEXT_VERSION, 0, TEXTDUMP_BLOCKSIZE);
+ mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, 0, TEXTDUMP_BLOCKSIZE);
(void)textdump_writenextblock(di, (char *)&kdh);
/*
@@ -493,7 +469,7 @@ textdump_dumpsys(struct dumperinfo *di)
* size.
*/
dumplen = trailer_offset - (textdump_offset + TEXTDUMP_BLOCKSIZE);
- mkdumpheader(&kdh, KERNELDUMP_TEXT_VERSION, dumplen,
+ mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, dumplen,
TEXTDUMP_BLOCKSIZE);
(void)textdump_writenextblock(di, (char *)&kdh);
textdump_restoreoff(trailer_offset);
diff --git a/sys/i386/i386/dump_machdep.c b/sys/i386/i386/dump_machdep.c
index b9a18e3..4522dc3 100644
--- a/sys/i386/i386/dump_machdep.c
+++ b/sys/i386/i386/dump_machdep.c
@@ -105,27 +105,6 @@ md_pa_next(struct md_pa *mdp)
return (mdp);
}
-/* XXX should be MI */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen,
- uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
static int
buf_write(struct dumperinfo *di, char *ptr, size_t sz)
{
@@ -326,7 +305,7 @@ dumpsys(struct dumperinfo *di)
dumplo = di->mediaoffset + di->mediasize - dumpsize;
dumplo -= sizeof(kdh) * 2;
- mkdumpheader(&kdh, KERNELDUMP_I386_VERSION, dumpsize, di->blocksize);
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, dumpsize, di->blocksize);
printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20,
ehdr.e_phnum);
diff --git a/sys/i386/i386/minidump_machdep.c b/sys/i386/i386/minidump_machdep.c
index 61d28d3..2daab3b 100644
--- a/sys/i386/i386/minidump_machdep.c
+++ b/sys/i386/i386/minidump_machdep.c
@@ -79,27 +79,6 @@ is_dumpable(vm_paddr_t pa)
return (0);
}
-/* XXX should be MI */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen,
- uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
#define PG2MB(pgs) (((pgs) + (1 << 8) - 1) >> 8)
static int
@@ -280,7 +259,7 @@ minidumpsys(struct dumperinfo *di)
mdhdr.paemode = 1;
#endif
- mkdumpheader(&kdh, KERNELDUMP_I386_VERSION, dumpsize, di->blocksize);
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, dumpsize, di->blocksize);
printf("Physical memory: %ju MB\n", ptoa((uintmax_t)physmem) / 1048576);
printf("Dumping %llu MB:", (long long)dumpsize >> 20);
diff --git a/sys/ia64/ia64/dump_machdep.c b/sys/ia64/ia64/dump_machdep.c
index a2dfe45..db73271 100644
--- a/sys/ia64/ia64/dump_machdep.c
+++ b/sys/ia64/ia64/dump_machdep.c
@@ -60,27 +60,6 @@ static off_t dumplo, fileofs;
static char buffer[DEV_BSIZE];
static size_t fragsz;
-/* XXX should be MI */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen,
- uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
static int
buf_write(struct dumperinfo *di, char *ptr, size_t sz)
{
@@ -261,7 +240,7 @@ dumpsys(struct dumperinfo *di)
dumplo = di->mediaoffset + di->mediasize - dumpsize;
dumplo -= sizeof(kdh) * 2;
- mkdumpheader(&kdh, KERNELDUMP_IA64_VERSION, dumpsize, di->blocksize);
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_IA64_VERSION, dumpsize, di->blocksize);
printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20,
ehdr.e_phnum);
diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c
index e6d4f44..238abc7 100644
--- a/sys/kern/kern_shutdown.c
+++ b/sys/kern/kern_shutdown.c
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
#include <sys/eventhandler.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
+#include <sys/kerneldump.h>
#include <sys/kthread.h>
#include <sys/malloc.h>
#include <sys/mount.h>
@@ -64,6 +65,7 @@ __FBSDID("$FreeBSD$");
#include <sys/smp.h> /* smp_active */
#include <sys/sysctl.h>
#include <sys/sysproto.h>
+#include <sys/vimage.h>
#include <ddb/ddb.h>
@@ -686,3 +688,23 @@ dumpsys(struct dumperinfo *di __unused)
printf("Kernel dumps not implemented on this architecture\n");
}
#endif
+
+void
+mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
+ uint64_t dumplen, uint32_t blksz)
+{
+
+ bzero(kdh, sizeof(*kdh));
+ strncpy(kdh->magic, magic, sizeof(kdh->magic));
+ strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
+ kdh->version = htod32(KERNELDUMPVERSION);
+ kdh->architectureversion = htod32(archver);
+ kdh->dumplength = htod64(dumplen);
+ kdh->dumptime = htod64(time_second);
+ kdh->blocksize = htod32(blksz);
+ strncpy(kdh->hostname, G_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);
+}
diff --git a/sys/sparc64/sparc64/dump_machdep.c b/sys/sparc64/sparc64/dump_machdep.c
index 19e94cc..5a90175a 100644
--- a/sys/sparc64/sparc64/dump_machdep.c
+++ b/sys/sparc64/sparc64/dump_machdep.c
@@ -56,27 +56,6 @@ static vm_size_t fragsz;
#define MAXDUMPSZ (MAXDUMPPGS << PAGE_SHIFT)
-/* XXX should be MI */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen,
- uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
static int
buf_write(struct dumperinfo *di, char *ptr, size_t sz)
{
@@ -191,7 +170,7 @@ dumpsys(struct dumperinfo *di)
/* Determine dump offset on device. */
dumplo = di->mediaoffset + di->mediasize - totsize;
- mkdumpheader(&kdh, KERNELDUMP_SPARC64_VERSION, size, di->blocksize);
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size, di->blocksize);
printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
diff --git a/sys/sun4v/sun4v/dump_machdep.c b/sys/sun4v/sun4v/dump_machdep.c
index f3acdc6..3a5d134 100644
--- a/sys/sun4v/sun4v/dump_machdep.c
+++ b/sys/sun4v/sun4v/dump_machdep.c
@@ -57,27 +57,6 @@ static vm_size_t fragsz;
#define MAXDUMPSZ (MAXDUMPPGS << PAGE_SHIFT)
-/* XXX should be MI */
-static void
-mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen,
- uint32_t blksz)
-{
-
- bzero(kdh, sizeof(*kdh));
- strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic));
- strncpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
- kdh->version = htod32(KERNELDUMPVERSION);
- kdh->architectureversion = htod32(archver);
- kdh->dumplength = htod64(dumplen);
- kdh->dumptime = htod64(time_second);
- kdh->blocksize = htod32(blksz);
- strncpy(kdh->hostname, G_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);
-}
-
static int
buf_write(struct dumperinfo *di, char *ptr, size_t sz)
{
@@ -194,7 +173,7 @@ dumpsys(struct dumperinfo *di)
/* Determine dump offset on device. */
dumplo = di->mediaoffset + di->mediasize - totsize;
- mkdumpheader(&kdh, KERNELDUMP_SPARC64_VERSION, size, di->blocksize);
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size, di->blocksize);
printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
diff --git a/sys/sys/kerneldump.h b/sys/sys/kerneldump.h
index f9f851b..3f3eacd 100644
--- a/sys/sys/kerneldump.h
+++ b/sys/sys/kerneldump.h
@@ -98,4 +98,9 @@ kerneldump_parity(struct kerneldumpheader *kdhp)
return (parity);
}
+#ifdef _KERNEL
+void mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
+ uint64_t dumplen, uint32_t blksz);
+#endif
+
#endif /* _SYS_KERNELDUMP_H */
OpenPOWER on IntegriCloud