Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_shutdown.c
Show First 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | struct kerneldumpcrypto { | ||||
keyInstance kdc_ki; | keyInstance kdc_ki; | ||||
cipherInstance kdc_ci; | cipherInstance kdc_ci; | ||||
uint32_t kdc_dumpkeysize; | uint32_t kdc_dumpkeysize; | ||||
struct kerneldumpkey kdc_dumpkey[]; | struct kerneldumpkey kdc_dumpkey[]; | ||||
}; | }; | ||||
#endif | #endif | ||||
struct kerneldumpcomp { | struct kerneldumpcomp { | ||||
uint8_t kdc_format; | |||||
struct compressor *kdc_stream; | struct compressor *kdc_stream; | ||||
uint8_t *kdc_buf; | uint8_t *kdc_buf; | ||||
size_t kdc_resid; | size_t kdc_resid; | ||||
}; | }; | ||||
static struct kerneldumpcomp *kerneldumpcomp_create(struct dumperinfo *di, | static struct kerneldumpcomp *kerneldumpcomp_create(struct dumperinfo *di, | ||||
uint8_t compression); | uint8_t compression); | ||||
static void kerneldumpcomp_destroy(struct dumperinfo *di); | static void kerneldumpcomp_destroy(struct dumperinfo *di); | ||||
▲ Show 20 Lines • Show All 797 Lines • ▼ Show 20 Lines | kerneldumpcrypto_dumpkeysize(const struct kerneldumpcrypto *kdc) | ||||
return (kdc->kdc_dumpkeysize); | return (kdc->kdc_dumpkeysize); | ||||
} | } | ||||
#endif /* EKCD */ | #endif /* EKCD */ | ||||
static struct kerneldumpcomp * | static struct kerneldumpcomp * | ||||
kerneldumpcomp_create(struct dumperinfo *di, uint8_t compression) | kerneldumpcomp_create(struct dumperinfo *di, uint8_t compression) | ||||
{ | { | ||||
struct kerneldumpcomp *kdcomp; | struct kerneldumpcomp *kdcomp; | ||||
int format; | |||||
if (compression != KERNELDUMP_COMP_GZIP) | switch (compression) { | ||||
case KERNELDUMP_COMP_GZIP: | |||||
format = COMPRESS_GZIP; | |||||
break; | |||||
case KERNELDUMP_COMP_ZSTD: | |||||
format = COMPRESS_ZSTD; | |||||
break; | |||||
default: | |||||
return (NULL); | return (NULL); | ||||
} | |||||
if (compression != KERNELDUMP_COMP_GZIP && | |||||
compression != KERNELDUMP_COMP_ZSTD) | |||||
return (NULL); | |||||
kdcomp = malloc(sizeof(*kdcomp), M_DUMPER, M_WAITOK | M_ZERO); | kdcomp = malloc(sizeof(*kdcomp), M_DUMPER, M_WAITOK | M_ZERO); | ||||
kdcomp->kdc_format = compression; | |||||
kdcomp->kdc_stream = compressor_init(kerneldumpcomp_write_cb, | kdcomp->kdc_stream = compressor_init(kerneldumpcomp_write_cb, | ||||
COMPRESS_GZIP, di->maxiosize, kerneldump_gzlevel, di); | format, di->maxiosize, kerneldump_gzlevel, di); | ||||
if (kdcomp->kdc_stream == NULL) { | if (kdcomp->kdc_stream == NULL) { | ||||
free(kdcomp, M_DUMPER); | free(kdcomp, M_DUMPER); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
kdcomp->kdc_buf = malloc(di->maxiosize, M_DUMPER, M_WAITOK | M_NODUMP); | kdcomp->kdc_buf = malloc(di->maxiosize, M_DUMPER, M_WAITOK | M_NODUMP); | ||||
return (kdcomp); | return (kdcomp); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | #endif | ||||
if (di->mediasize < SIZEOF_METADATA + dumpextent + 2 * di->blocksize + | if (di->mediasize < SIZEOF_METADATA + dumpextent + 2 * di->blocksize + | ||||
keysize) { | keysize) { | ||||
if (di->kdcomp != NULL) { | if (di->kdcomp != NULL) { | ||||
/* | /* | ||||
* We don't yet know how much space the compressed dump | * We don't yet know how much space the compressed dump | ||||
* will occupy, so try to use the whole swap partition | * will occupy, so try to use the whole swap partition | ||||
* (minus the first 64KB) in the hope that the | * (minus the first 64KB) in the hope that the | ||||
* compressed dump will fit. If that doesn't turn out to | * compressed dump will fit. If that doesn't turn out to | ||||
* be enouch, the bounds checking in dump_write() | * be enough, the bounds checking in dump_write() | ||||
* will catch us and cause the dump to fail. | * will catch us and cause the dump to fail. | ||||
*/ | */ | ||||
dumpextent = di->mediasize - SIZEOF_METADATA - | dumpextent = di->mediasize - SIZEOF_METADATA - | ||||
2 * di->blocksize - keysize; | 2 * di->blocksize - keysize; | ||||
kdh->dumpextent = htod64(dumpextent); | kdh->dumpextent = htod64(dumpextent); | ||||
} else | } else | ||||
return (E2BIG); | return (E2BIG); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | #endif | ||||
kdh->blocksize = htod32(di->blocksize); | kdh->blocksize = htod32(di->blocksize); | ||||
strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname)); | strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname)); | ||||
dstsize = sizeof(kdh->versionstring); | dstsize = sizeof(kdh->versionstring); | ||||
if (strlcpy(kdh->versionstring, version, dstsize) >= dstsize) | if (strlcpy(kdh->versionstring, version, dstsize) >= dstsize) | ||||
kdh->versionstring[dstsize - 2] = '\n'; | kdh->versionstring[dstsize - 2] = '\n'; | ||||
if (panicstr != NULL) | if (panicstr != NULL) | ||||
strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); | strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); | ||||
if (di->kdcomp != NULL) | if (di->kdcomp != NULL) | ||||
kdh->compression = KERNELDUMP_COMP_GZIP; | kdh->compression = di->kdcomp->kdc_format; | ||||
kdh->parity = kerneldump_parity(kdh); | kdh->parity = kerneldump_parity(kdh); | ||||
} | } | ||||
#ifdef DDB | #ifdef DDB | ||||
DB_SHOW_COMMAND(panic, db_show_panic) | DB_SHOW_COMMAND(panic, db_show_panic) | ||||
{ | { | ||||
if (panicstr == NULL) | if (panicstr == NULL) | ||||
db_printf("panicstr not set\n"); | db_printf("panicstr not set\n"); | ||||
else | else | ||||
db_printf("panic: %s\n", panicstr); | db_printf("panic: %s\n", panicstr); | ||||
} | } | ||||
#endif | #endif |