Rename mkdumpheader() and group EKCD functions in kern_shutdown.c.
This helps simplify the code in kern_shutdown.c and reduces the number of globally visible functions. No functional change intended. Reviewed by: cem, def Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D11603
This commit is contained in:
parent
50ef60dabe
commit
01938d3666
@ -327,8 +327,8 @@ minidumpsys(struct dumperinfo *di)
|
||||
mdhdr.dmapbase = DMAP_MIN_ADDRESS;
|
||||
mdhdr.dmapend = DMAP_MAX_ADDRESS;
|
||||
|
||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AMD64_VERSION, dumpsize,
|
||||
kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize);
|
||||
dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_AMD64_VERSION,
|
||||
dumpsize);
|
||||
|
||||
printf("Dumping %llu out of %ju MB:", (long long)dumpsize >> 20,
|
||||
ptoa((uintmax_t)physmem) / 1048576);
|
||||
|
@ -245,8 +245,8 @@ minidumpsys(struct dumperinfo *di)
|
||||
#else
|
||||
mdhdr.mmuformat = MINIDUMP_MMU_FORMAT_V4;
|
||||
#endif
|
||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_ARM_VERSION, dumpsize,
|
||||
kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize);
|
||||
dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_ARM_VERSION,
|
||||
dumpsize);
|
||||
|
||||
printf("Physical memory: %u MB\n", ptoa((uintmax_t)physmem) / 1048576);
|
||||
printf("Dumping %llu MB:", (long long)dumpsize >> 20);
|
||||
|
@ -289,8 +289,8 @@ minidumpsys(struct dumperinfo *di)
|
||||
mdhdr.dmapbase = DMAP_MIN_ADDRESS;
|
||||
mdhdr.dmapend = DMAP_MAX_ADDRESS;
|
||||
|
||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AARCH64_VERSION,
|
||||
dumpsize, kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize);
|
||||
dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_AARCH64_VERSION,
|
||||
dumpsize);
|
||||
|
||||
printf("Dumping %llu out of %ju MB:", (long long)dumpsize >> 20,
|
||||
ptoa((uintmax_t)physmem) / 1048576);
|
||||
|
@ -463,8 +463,7 @@ textdump_dumpsys(struct dumperinfo *di)
|
||||
*/
|
||||
textdump_offset = di->mediasize - sizeof(kdh);
|
||||
textdump_saveoff(&trailer_offset);
|
||||
mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, 0, 0,
|
||||
TEXTDUMP_BLOCKSIZE);
|
||||
dump_init_header(di, &kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, 0);
|
||||
(void)textdump_writenextblock(di, (char *)&kdh);
|
||||
|
||||
/*
|
||||
@ -489,8 +488,8 @@ textdump_dumpsys(struct dumperinfo *di)
|
||||
* size.
|
||||
*/
|
||||
dumplen = trailer_offset - (textdump_offset + TEXTDUMP_BLOCKSIZE);
|
||||
mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, dumplen, 0,
|
||||
TEXTDUMP_BLOCKSIZE);
|
||||
dump_init_header(di, &kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION,
|
||||
dumplen);
|
||||
(void)textdump_writenextblock(di, (char *)&kdh);
|
||||
textdump_restoreoff(trailer_offset);
|
||||
(void)textdump_writenextblock(di, (char *)&kdh);
|
||||
|
@ -252,8 +252,8 @@ minidumpsys(struct dumperinfo *di)
|
||||
mdhdr.paemode = 1;
|
||||
#endif
|
||||
|
||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, dumpsize,
|
||||
kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize);
|
||||
dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION,
|
||||
dumpsize);
|
||||
|
||||
printf("Physical memory: %ju MB\n", ptoa((uintmax_t)physmem) / 1048576);
|
||||
printf("Dumping %llu MB:", (long long)dumpsize >> 20);
|
||||
|
@ -341,8 +341,8 @@ dumpsys_generic(struct dumperinfo *di)
|
||||
dumpsize += fileofs;
|
||||
hdrgap = fileofs - roundup2((off_t)hdrsz, di->blocksize);
|
||||
|
||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_ARCH_VERSION, dumpsize,
|
||||
kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize);
|
||||
dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_ARCH_VERSION,
|
||||
dumpsize);
|
||||
|
||||
printf("Dumping %ju MB (%d chunks)\n", (uintmax_t)dumpsize >> 20,
|
||||
ehdr.e_phnum - DUMPSYS_NUM_AUX_HDRS);
|
||||
|
@ -895,14 +895,10 @@ failed:
|
||||
free(kdc, M_EKCD);
|
||||
return (NULL);
|
||||
}
|
||||
#endif /* EKCD */
|
||||
|
||||
static int
|
||||
kerneldumpcrypto_init(struct kerneldumpcrypto *kdc)
|
||||
{
|
||||
#ifndef EKCD
|
||||
return (0);
|
||||
#else
|
||||
uint8_t hash[SHA256_DIGEST_LENGTH];
|
||||
SHA256_CTX ctx;
|
||||
struct kerneldumpkey *kdk;
|
||||
@ -942,21 +938,17 @@ kerneldumpcrypto_init(struct kerneldumpcrypto *kdc)
|
||||
out:
|
||||
explicit_bzero(hash, sizeof(hash));
|
||||
return (error);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t
|
||||
static uint32_t
|
||||
kerneldumpcrypto_dumpkeysize(const struct kerneldumpcrypto *kdc)
|
||||
{
|
||||
|
||||
#ifdef EKCD
|
||||
if (kdc == NULL)
|
||||
return (0);
|
||||
return (kdc->kdc_dumpkeysize);
|
||||
#else
|
||||
return (0);
|
||||
#endif
|
||||
}
|
||||
#endif /* EKCD */
|
||||
|
||||
/* Registration of dumpers */
|
||||
int
|
||||
@ -1036,6 +1028,20 @@ dump_check_bounds(struct dumperinfo *di, off_t offset, size_t length)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Call dumper with bounds checking. */
|
||||
static int
|
||||
dump_raw_write(struct dumperinfo *di, void *virtual, vm_offset_t physical,
|
||||
off_t offset, size_t length)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = dump_check_bounds(di, offset, length);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
return (di->dumper(di->priv, virtual, physical, offset, length));
|
||||
}
|
||||
|
||||
#ifdef EKCD
|
||||
static int
|
||||
dump_encrypt(struct kerneldumpcrypto *kdc, uint8_t *buf, size_t size)
|
||||
@ -1115,21 +1121,20 @@ dump_encrypted_write(struct dumperinfo *di, void *virtual, vm_offset_t physical,
|
||||
|
||||
return (0);
|
||||
}
|
||||
#endif /* EKCD */
|
||||
|
||||
/* Call dumper with bounds checking. */
|
||||
static int
|
||||
dump_raw_write(struct dumperinfo *di, void *virtual, vm_offset_t physical,
|
||||
off_t offset, size_t length)
|
||||
dump_write_key(struct dumperinfo *di, vm_offset_t physical, off_t offset)
|
||||
{
|
||||
int error;
|
||||
struct kerneldumpcrypto *kdc;
|
||||
|
||||
error = dump_check_bounds(di, offset, length);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
kdc = di->kdc;
|
||||
if (kdc == NULL)
|
||||
return (0);
|
||||
|
||||
return (di->dumper(di->priv, virtual, physical, offset, length));
|
||||
return (dump_raw_write(di, kdc->kdc_dumpkey, physical, offset,
|
||||
kdc->kdc_dumpkeysize));
|
||||
}
|
||||
#endif /* EKCD */
|
||||
|
||||
int
|
||||
dump_write(struct dumperinfo *di, void *virtual, vm_offset_t physical,
|
||||
@ -1194,23 +1199,6 @@ dump_write_header(struct dumperinfo *di, struct kerneldumpheader *kdh,
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
dump_write_key(struct dumperinfo *di, vm_offset_t physical, off_t offset)
|
||||
{
|
||||
#ifndef EKCD
|
||||
return (0);
|
||||
#else /* EKCD */
|
||||
struct kerneldumpcrypto *kdc;
|
||||
|
||||
kdc = di->kdc;
|
||||
if (kdc == NULL)
|
||||
return (0);
|
||||
|
||||
return (dump_raw_write(di, kdc->kdc_dumpkey, physical, offset,
|
||||
kdc->kdc_dumpkeysize));
|
||||
#endif /* !EKCD */
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't touch the first SIZEOF_METADATA bytes on the dump device. This is to
|
||||
* protect us from metadata and metadata from us.
|
||||
@ -1226,14 +1214,19 @@ int
|
||||
dump_start(struct dumperinfo *di, struct kerneldumpheader *kdh, off_t *dumplop)
|
||||
{
|
||||
uint64_t dumpsize;
|
||||
uint32_t keysize;
|
||||
int error;
|
||||
|
||||
#ifdef EKCD
|
||||
error = kerneldumpcrypto_init(di->kdc);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
keysize = kerneldumpcrypto_dumpkeysize(di->kdc);
|
||||
#else
|
||||
keysize = 0;
|
||||
#endif
|
||||
|
||||
dumpsize = dtoh64(kdh->dumplength) + 2 * di->blocksize +
|
||||
kerneldumpcrypto_dumpkeysize(di->kdc);
|
||||
dumpsize = dtoh64(kdh->dumplength) + 2 * di->blocksize + keysize;
|
||||
if (di->mediasize < SIZEOF_METADATA + dumpsize)
|
||||
return (E2BIG);
|
||||
|
||||
@ -1244,10 +1237,12 @@ dump_start(struct dumperinfo *di, struct kerneldumpheader *kdh, off_t *dumplop)
|
||||
return (error);
|
||||
*dumplop += di->blocksize;
|
||||
|
||||
#ifdef EKCD
|
||||
error = dump_write_key(di, 0, *dumplop);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
*dumplop += kerneldumpcrypto_dumpkeysize(di->kdc);
|
||||
*dumplop += keysize;
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -1270,8 +1265,8 @@ dump_finish(struct dumperinfo *di, struct kerneldumpheader *kdh, off_t dumplo)
|
||||
}
|
||||
|
||||
void
|
||||
mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
|
||||
uint64_t dumplen, uint32_t dumpkeysize, uint32_t blksz)
|
||||
dump_init_header(const struct dumperinfo *di, struct kerneldumpheader *kdh,
|
||||
char *magic, uint32_t archver, uint64_t dumplen)
|
||||
{
|
||||
size_t dstsize;
|
||||
|
||||
@ -1282,8 +1277,12 @@ mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
|
||||
kdh->architectureversion = htod32(archver);
|
||||
kdh->dumplength = htod64(dumplen);
|
||||
kdh->dumptime = htod64(time_second);
|
||||
kdh->dumpkeysize = htod32(dumpkeysize);
|
||||
kdh->blocksize = htod32(blksz);
|
||||
#ifdef EKCD
|
||||
kdh->dumpkeysize = htod32(kerneldumpcrypto_dumpkeysize(di->kdc));
|
||||
#else
|
||||
kdh->dumpkeysize = 0;
|
||||
#endif
|
||||
kdh->blocksize = htod32(di->blocksize);
|
||||
strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname));
|
||||
dstsize = sizeof(kdh->versionstring);
|
||||
if (strlcpy(kdh->versionstring, version, dstsize) >= dstsize)
|
||||
|
@ -261,8 +261,8 @@ minidumpsys(struct dumperinfo *di)
|
||||
mdhdr.ptesize = ptesize;
|
||||
mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS;
|
||||
|
||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_MIPS_VERSION, dumpsize,
|
||||
kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize);
|
||||
dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_MIPS_VERSION,
|
||||
dumpsize);
|
||||
|
||||
printf("Dumping %llu out of %ju MB:", (long long)dumpsize >> 20,
|
||||
ptoa((uintmax_t)physmem) / 1048576);
|
||||
|
@ -94,8 +94,8 @@ dumpsys(struct dumperinfo *di)
|
||||
DEV_BSIZE);
|
||||
size += hdrsize;
|
||||
|
||||
mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size,
|
||||
kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize);
|
||||
dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION,
|
||||
size);
|
||||
|
||||
printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
|
||||
|
||||
|
@ -342,6 +342,8 @@ struct dumperinfo {
|
||||
int set_dumper(struct dumperinfo *di, const char *devname, struct thread *td,
|
||||
uint8_t encrypt, const uint8_t *key, uint32_t encryptedkeysize,
|
||||
const uint8_t *encryptedkey);
|
||||
void dump_init_header(const struct dumperinfo *di, struct kerneldumpheader *kdh,
|
||||
char *magic, uint32_t archver, uint64_t dumplen);
|
||||
int dump_start(struct dumperinfo *di, struct kerneldumpheader *kdh,
|
||||
off_t *dumplop);
|
||||
int dump_finish(struct dumperinfo *di, struct kerneldumpheader *kdh,
|
||||
|
@ -125,11 +125,6 @@ struct dump_pa {
|
||||
vm_paddr_t pa_size;
|
||||
};
|
||||
|
||||
uint32_t kerneldumpcrypto_dumpkeysize(const struct kerneldumpcrypto *kdc);
|
||||
|
||||
void mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
|
||||
uint64_t dumplen, uint32_t dumpkeysize, uint32_t blksz);
|
||||
|
||||
int dumpsys_generic(struct dumperinfo *);
|
||||
|
||||
void dumpsys_map_chunk(vm_paddr_t, size_t, void **);
|
||||
|
Loading…
x
Reference in New Issue
Block a user