Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/arm/minidump_machdep.c
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
#include <machine/cpu.h> | #include <machine/cpu.h> | ||||
#include <machine/elf.h> | #include <machine/elf.h> | ||||
#include <machine/md_var.h> | #include <machine/md_var.h> | ||||
#include <machine/minidump.h> | #include <machine/minidump.h> | ||||
#include <machine/vmparam.h> | #include <machine/vmparam.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) | |||||
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; | ||||
/* Handle chunked writes. */ | /* Handle chunked writes. */ | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | if (pa != 0 && is_dumpable(pa)) | ||||
dump_add_page(pa); | dump_add_page(pa); | ||||
ptesize += sizeof(pt2_entry_t); | ptesize += sizeof(pt2_entry_t); | ||||
} | } | ||||
/* Calculate dump size. */ | /* Calculate dump size. */ | ||||
dumpsize = ptesize; | dumpsize = ptesize; | ||||
dumpsize += round_page(msgbufp->msg_size); | dumpsize += round_page(msgbufp->msg_size); | ||||
dumpsize += round_page(vm_page_dump_size); | dumpsize += round_page(vm_page_dump_size); | ||||
for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) { | for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) { | ||||
bits = vm_page_dump[i]; | bits = vm_page_dump[i]; | ||||
while (bits) { | while (bits) { | ||||
bit = ffs(bits) - 1; | bit = ffs(bits) - 1; | ||||
pa = (((uint64_t)i * sizeof(*vm_page_dump) * NBBY) + | pa = (((uint64_t)i * sizeof(*vm_page_dump) * NBBY) + | ||||
bit) * PAGE_SIZE; | bit) * PAGE_SIZE; | ||||
/* Clear out undumpable pages now if needed */ | /* Clear out undumpable pages now if needed */ | ||||
if (is_dumpable(pa)) | if (is_dumpable(pa)) | ||||
dumpsize += PAGE_SIZE; | dumpsize += PAGE_SIZE; | ||||
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; | ||||
mdhdr.arch = __ARM_ARCH; | mdhdr.arch = __ARM_ARCH; | ||||
#if __ARM_ARCH >= 6 | #if __ARM_ARCH >= 6 | ||||
mdhdr.mmuformat = MINIDUMP_MMU_FORMAT_V6; | mdhdr.mmuformat = MINIDUMP_MMU_FORMAT_V6; | ||||
#else | #else | ||||
mdhdr.mmuformat = MINIDUMP_MMU_FORMAT_V4; | mdhdr.mmuformat = MINIDUMP_MMU_FORMAT_V4; | ||||
#endif | #endif | ||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_ARM_VERSION, dumpsize, | mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_ARM_VERSION, dumpsize, | ||||
kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); | kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); | ||||
printf("Physical memory: %u MB\n", ptoa((uintmax_t)physmem) / 1048576); | printf("Physical memory: %u 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(dumpbuf, sizeof(dumpbuf)); | bzero(dumpbuf, sizeof(dumpbuf)); | ||||
bcopy(&mdhdr, dumpbuf, sizeof(mdhdr)); | bcopy(&mdhdr, dumpbuf, sizeof(mdhdr)); | ||||
error = blk_write(di, dumpbuf, 0, PAGE_SIZE); | error = blk_write(di, dumpbuf, 0, PAGE_SIZE); | ||||
if (error) | if (error) | ||||
goto fail; | goto fail; | ||||
/* Dump msgbuf up front */ | /* Dump msgbuf up front */ | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (count) { | ||||
count = 0; | count = 0; | ||||
prev_pa = 0; | prev_pa = 0; | ||||
} | } | ||||
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) | ||||
def: I was thinking about
```
else if (error == E2BIG || error == ENOSPC)
```
here and in other… | |||||
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 19 Lines |
I was thinking about
here and in other architectures as dump_write() can still return ENOSPC which might happen when a number of pages being dumped has increased during dumping.