Changeset View
Changeset View
Standalone View
Standalone View
sys/i386/i386/minidump_machdep.c
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#include <machine/atomic.h> | #include <machine/atomic.h> | ||||
#include <machine/elf.h> | #include <machine/elf.h> | ||||
#include <machine/md_var.h> | #include <machine/md_var.h> | ||||
#include <machine/vmparam.h> | #include <machine/vmparam.h> | ||||
#include <machine/minidump.h> | #include <machine/minidump.h> | ||||
CTASSERT(sizeof(struct kerneldumpheader) == 512); | CTASSERT(sizeof(struct kerneldumpheader) == 512); | ||||
/* | |||||
* Don't touch the first SIZEOF_METADATA bytes on the dump device. This | |||||
* is to protect us from metadata and to protect metadata from us. | |||||
*/ | |||||
#define SIZEOF_METADATA (64*1024) | |||||
#define MD_ALIGN(x) (((off_t)(x) + PAGE_MASK) & ~PAGE_MASK) | #define MD_ALIGN(x) (((off_t)(x) + PAGE_MASK) & ~PAGE_MASK) | ||||
#define DEV_ALIGN(x) roundup2((off_t)(x), DEV_BSIZE) | #define DEV_ALIGN(x) roundup2((off_t)(x), DEV_BSIZE) | ||||
uint32_t *vm_page_dump; | uint32_t *vm_page_dump; | ||||
int vm_page_dump_size; | int vm_page_dump_size; | ||||
static struct kerneldumpheader kdh; | static struct kerneldumpheader kdh; | ||||
static off_t dumplo; | static off_t dumplo; | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | while (bits) { | ||||
} else { | } else { | ||||
dump_drop_page(pa); | dump_drop_page(pa); | ||||
} | } | ||||
bits &= ~(1ul << bit); | bits &= ~(1ul << bit); | ||||
} | } | ||||
} | } | ||||
dumpsize += PAGE_SIZE; | dumpsize += PAGE_SIZE; | ||||
/* Determine dump offset on device. */ | |||||
if (di->mediasize < SIZEOF_METADATA + dumpsize + di->blocksize * 2 + | |||||
kerneldumpcrypto_dumpkeysize(di->kdc)) { | |||||
error = ENOSPC; | |||||
goto fail; | |||||
} | |||||
dumplo = di->mediaoffset + di->mediasize - dumpsize; | |||||
dumplo -= di->blocksize * 2; | |||||
dumplo -= kerneldumpcrypto_dumpkeysize(di->kdc); | |||||
progress = dumpsize; | progress = dumpsize; | ||||
/* Initialize kernel dump crypto. */ | |||||
error = kerneldumpcrypto_init(di->kdc); | |||||
if (error) | |||||
goto fail; | |||||
/* Initialize mdhdr */ | /* Initialize mdhdr */ | ||||
bzero(&mdhdr, sizeof(mdhdr)); | bzero(&mdhdr, sizeof(mdhdr)); | ||||
strcpy(mdhdr.magic, MINIDUMP_MAGIC); | strcpy(mdhdr.magic, MINIDUMP_MAGIC); | ||||
mdhdr.version = MINIDUMP_VERSION; | mdhdr.version = MINIDUMP_VERSION; | ||||
mdhdr.msgbufsize = msgbufp->msg_size; | mdhdr.msgbufsize = msgbufp->msg_size; | ||||
mdhdr.bitmapsize = vm_page_dump_size; | mdhdr.bitmapsize = vm_page_dump_size; | ||||
mdhdr.ptesize = ptesize; | mdhdr.ptesize = ptesize; | ||||
mdhdr.kernbase = KERNBASE; | mdhdr.kernbase = KERNBASE; | ||||
#if defined(PAE) || defined(PAE_TABLES) | #if defined(PAE) || defined(PAE_TABLES) | ||||
mdhdr.paemode = 1; | mdhdr.paemode = 1; | ||||
#endif | #endif | ||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, dumpsize, | mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, dumpsize, | ||||
kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); | kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); | ||||
printf("Physical memory: %ju MB\n", ptoa((uintmax_t)physmem) / 1048576); | printf("Physical memory: %ju MB\n", ptoa((uintmax_t)physmem) / 1048576); | ||||
printf("Dumping %llu MB:", (long long)dumpsize >> 20); | printf("Dumping %llu MB:", (long long)dumpsize >> 20); | ||||
/* Dump leader */ | error = dump_start(di, &kdh, &dumplo); | ||||
error = dump_write_header(di, &kdh, 0, dumplo); | if (error != 0) | ||||
if (error) | |||||
goto fail; | goto fail; | ||||
dumplo += di->blocksize; | |||||
/* Dump key */ | |||||
error = dump_write_key(di, 0, dumplo); | |||||
if (error) | |||||
goto fail; | |||||
dumplo += kerneldumpcrypto_dumpkeysize(di->kdc); | |||||
/* Dump my header */ | /* Dump my header */ | ||||
bzero(&fakept, sizeof(fakept)); | bzero(&fakept, sizeof(fakept)); | ||||
bcopy(&mdhdr, &fakept, sizeof(mdhdr)); | bcopy(&mdhdr, &fakept, sizeof(mdhdr)); | ||||
error = blk_write(di, (char *)&fakept, 0, PAGE_SIZE); | error = blk_write(di, (char *)&fakept, 0, PAGE_SIZE); | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
/* Dump msgbuf up front */ | /* Dump msgbuf up front */ | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | while (bits) { | ||||
bits &= ~(1ul << bit); | bits &= ~(1ul << bit); | ||||
} | } | ||||
} | } | ||||
error = blk_flush(di); | error = blk_flush(di); | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
/* Dump trailer */ | error = dump_finish(di, &kdh, dumplo); | ||||
error = dump_write_header(di, &kdh, 0, dumplo); | if (error != 0) | ||||
if (error) | |||||
goto fail; | goto fail; | ||||
dumplo += di->blocksize; | |||||
/* Signal completion, signoff and exit stage left. */ | |||||
dump_write(di, NULL, 0, 0, 0); | |||||
printf("\nDump complete\n"); | printf("\nDump complete\n"); | ||||
return (0); | return (0); | ||||
fail: | fail: | ||||
if (error < 0) | if (error < 0) | ||||
error = -error; | error = -error; | ||||
if (error == ECANCELED) | if (error == ECANCELED) | ||||
printf("\nDump aborted\n"); | printf("\nDump aborted\n"); | ||||
else if (error == ENOSPC) | else if (error == E2BIG) | ||||
printf("\nDump failed. Partition too small.\n"); | printf("\nDump failed. Partition too small.\n"); | ||||
else | else | ||||
printf("\n** DUMP FAILED (ERROR %d) **\n", error); | printf("\n** DUMP FAILED (ERROR %d) **\n", error); | ||||
return (error); | return (error); | ||||
} | } | ||||
void | void | ||||
dump_add_page(vm_paddr_t pa) | dump_add_page(vm_paddr_t pa) | ||||
Show All 20 Lines |