dump queue
Hi The "dump" queue, with: - [PATCH v3/v4 0/9] dump: Cleanup and consolidation - [PATCH v4 0/4] dump: add 32-bit guest Windows support v2: - fix compiler warning in "dump/win_dump: add 32-bit guest Windows support" -----BEGIN PGP SIGNATURE----- iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmJigBkcHG1hcmNhbmRy ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5T92EACNSdzJTeXmoGV3yzyq oVQAH9ViuH6nINH04KZvS6gPoFvm6h/0pj2A2n9iy9ULcc0hNNKDtDkiYoIyLWTE 34ywOpWUNbRNEefifo2wcKqebpyeSS+0Y2fttHzIwVl+t5qFZt7JwXdbmo4Xpf6a MY4LS7WfmQkXZvg0nkv3nw32vAJK4VvSKhnbSTE1m0AYEkrBTntexDby9XDoDyWL QPzDemyLi6A9HO/NeB6sdKwwXd4g4mfIKy0WI+T5M1Ped0BpBoKrQpJ/KNYrZuJE 0IJJFXA8D+tIfYdGD3MAO2X7IHVR6Ld2GV10pPmzLFHt06MFlDua360cFYohB2ua 2Hk0syqwuEDRZSES5eQPbwu3sXGAZAw3kth32tlGFawTVwXLEw9YTU1ZwHhnwvG0 Uocu44v2+x0Swtuw2Dw1J5PBLH1ebYdQozpA4U4TibCKzRTjnO6idZIFh/64oA4q RdpEvrQ1nnJTnIgkllZ9KxAcOZECjREEB33UAxcpKxtJbann6bv/Gz754qqiNVZv LOMcgZJ7HItChRV+dFQQRgyeX+IrGeq+N4zoLRZehib5+kYi50UKQIPIc9TUgzbw CwOESkyipmljjx9016pmY8LYipnm0hDVMoxzdKPsdYbagxWC/JFPxvqlB+7xQBud ez/xPfN8799O+mlwZ7zgXwYaUg== =QWiq -----END PGP SIGNATURE----- Merge tag 'dump-pull-request' of gitlab.com:marcandre.lureau/qemu into staging dump queue Hi The "dump" queue, with: - [PATCH v3/v4 0/9] dump: Cleanup and consolidation - [PATCH v4 0/4] dump: add 32-bit guest Windows support v2: - fix compiler warning in "dump/win_dump: add 32-bit guest Windows support" # -----BEGIN PGP SIGNATURE----- # # iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmJigBkcHG1hcmNhbmRy # ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5T92EACNSdzJTeXmoGV3yzyq # oVQAH9ViuH6nINH04KZvS6gPoFvm6h/0pj2A2n9iy9ULcc0hNNKDtDkiYoIyLWTE # 34ywOpWUNbRNEefifo2wcKqebpyeSS+0Y2fttHzIwVl+t5qFZt7JwXdbmo4Xpf6a # MY4LS7WfmQkXZvg0nkv3nw32vAJK4VvSKhnbSTE1m0AYEkrBTntexDby9XDoDyWL # QPzDemyLi6A9HO/NeB6sdKwwXd4g4mfIKy0WI+T5M1Ped0BpBoKrQpJ/KNYrZuJE # 0IJJFXA8D+tIfYdGD3MAO2X7IHVR6Ld2GV10pPmzLFHt06MFlDua360cFYohB2ua # 2Hk0syqwuEDRZSES5eQPbwu3sXGAZAw3kth32tlGFawTVwXLEw9YTU1ZwHhnwvG0 # Uocu44v2+x0Swtuw2Dw1J5PBLH1ebYdQozpA4U4TibCKzRTjnO6idZIFh/64oA4q # RdpEvrQ1nnJTnIgkllZ9KxAcOZECjREEB33UAxcpKxtJbann6bv/Gz754qqiNVZv # LOMcgZJ7HItChRV+dFQQRgyeX+IrGeq+N4zoLRZehib5+kYi50UKQIPIc9TUgzbw # CwOESkyipmljjx9016pmY8LYipnm0hDVMoxzdKPsdYbagxWC/JFPxvqlB+7xQBud # ez/xPfN8799O+mlwZ7zgXwYaUg== # =QWiq # -----END PGP SIGNATURE----- # gpg: Signature made Fri 22 Apr 2022 03:14:49 AM PDT # gpg: using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5 # gpg: issuer "marcandre.lureau@redhat.com" # gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full] # gpg: aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full] * tag 'dump-pull-request' of gitlab.com:marcandre.lureau/qemu: dump/win_dump: add 32-bit guest Windows support include/qemu: add 32-bit Windows dump structures dump/win_dump: add helper macros for Windows dump header access include/qemu: rename Windows context definitions to expose bitness dump: Consolidate elf note function dump: Cleanup dump_begin write functions dump: Consolidate phdr note writes dump: Introduce dump_is_64bit() helper function dump: Add more offset variables dump: Remove the section if when calculating the memory offset dump: Introduce shdr_num to decrease complexity dump: Remove the sh_info variable dump: Use ERRP_GUARD() Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
f7f40b8198
@ -141,10 +141,10 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb,
|
|||||||
return kdbg;
|
return kdbg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void win_context_init_from_qemu_cpu_state(WinContext *ctx,
|
static void win_context_init_from_qemu_cpu_state(WinContext64 *ctx,
|
||||||
QEMUCPUState *s)
|
QEMUCPUState *s)
|
||||||
{
|
{
|
||||||
WinContext win_ctx = (WinContext){
|
WinContext64 win_ctx = (WinContext64){
|
||||||
.ContextFlags = WIN_CTX_X64 | WIN_CTX_INT | WIN_CTX_SEG | WIN_CTX_CTL,
|
.ContextFlags = WIN_CTX_X64 | WIN_CTX_INT | WIN_CTX_SEG | WIN_CTX_CTL,
|
||||||
.MxCsr = INITIAL_MXCSR,
|
.MxCsr = INITIAL_MXCSR,
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg,
|
|||||||
for (i = 0; i < qe->state_nr; i++) {
|
for (i = 0; i < qe->state_nr; i++) {
|
||||||
uint64_t Prcb;
|
uint64_t Prcb;
|
||||||
uint64_t Context;
|
uint64_t Context;
|
||||||
WinContext ctx;
|
WinContext64 ctx;
|
||||||
QEMUCPUState *s = qe->state[i];
|
QEMUCPUState *s = qe->state[i];
|
||||||
|
|
||||||
if (va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i,
|
if (va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i,
|
||||||
|
354
dump/dump.c
354
dump/dump.c
@ -54,6 +54,11 @@ static Error *dump_migration_blocker;
|
|||||||
DIV_ROUND_UP((name_size), 4) + \
|
DIV_ROUND_UP((name_size), 4) + \
|
||||||
DIV_ROUND_UP((desc_size), 4)) * 4)
|
DIV_ROUND_UP((desc_size), 4)) * 4)
|
||||||
|
|
||||||
|
static inline bool dump_is_64bit(DumpState *s)
|
||||||
|
{
|
||||||
|
return s->dump_info.d_class == ELFCLASS64;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t cpu_to_dump16(DumpState *s, uint16_t val)
|
uint16_t cpu_to_dump16(DumpState *s, uint16_t val)
|
||||||
{
|
{
|
||||||
if (s->dump_info.d_endian == ELFDATA2LSB) {
|
if (s->dump_info.d_endian == ELFDATA2LSB) {
|
||||||
@ -123,6 +128,12 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
|
|||||||
|
|
||||||
static void write_elf64_header(DumpState *s, Error **errp)
|
static void write_elf64_header(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* phnum in the elf header is 16 bit, if we have more segments we
|
||||||
|
* set phnum to PN_XNUM and write the real number of segments to a
|
||||||
|
* special section.
|
||||||
|
*/
|
||||||
|
uint16_t phnum = MIN(s->phdr_num, PN_XNUM);
|
||||||
Elf64_Ehdr elf_header;
|
Elf64_Ehdr elf_header;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -135,15 +146,13 @@ static void write_elf64_header(DumpState *s, Error **errp)
|
|||||||
elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
|
elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
|
||||||
elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
|
elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
|
||||||
elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
||||||
elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
|
elf_header.e_phoff = cpu_to_dump64(s, s->phdr_offset);
|
||||||
elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
|
elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
|
||||||
elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num);
|
elf_header.e_phnum = cpu_to_dump16(s, phnum);
|
||||||
if (s->have_section) {
|
if (s->shdr_num) {
|
||||||
uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->sh_info;
|
elf_header.e_shoff = cpu_to_dump64(s, s->shdr_offset);
|
||||||
|
|
||||||
elf_header.e_shoff = cpu_to_dump64(s, shoff);
|
|
||||||
elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
|
elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
|
||||||
elf_header.e_shnum = cpu_to_dump16(s, 1);
|
elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
||||||
@ -154,6 +163,12 @@ static void write_elf64_header(DumpState *s, Error **errp)
|
|||||||
|
|
||||||
static void write_elf32_header(DumpState *s, Error **errp)
|
static void write_elf32_header(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* phnum in the elf header is 16 bit, if we have more segments we
|
||||||
|
* set phnum to PN_XNUM and write the real number of segments to a
|
||||||
|
* special section.
|
||||||
|
*/
|
||||||
|
uint16_t phnum = MIN(s->phdr_num, PN_XNUM);
|
||||||
Elf32_Ehdr elf_header;
|
Elf32_Ehdr elf_header;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -166,15 +181,13 @@ static void write_elf32_header(DumpState *s, Error **errp)
|
|||||||
elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
|
elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
|
||||||
elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
|
elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
|
||||||
elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
||||||
elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
|
elf_header.e_phoff = cpu_to_dump32(s, s->phdr_offset);
|
||||||
elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
|
elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
|
||||||
elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num);
|
elf_header.e_phnum = cpu_to_dump16(s, phnum);
|
||||||
if (s->have_section) {
|
if (s->shdr_num) {
|
||||||
uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->sh_info;
|
elf_header.e_shoff = cpu_to_dump32(s, s->shdr_offset);
|
||||||
|
|
||||||
elf_header.e_shoff = cpu_to_dump32(s, shoff);
|
|
||||||
elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
|
elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
|
||||||
elf_header.e_shnum = cpu_to_dump16(s, 1);
|
elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
||||||
@ -232,25 +245,15 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_elf64_note(DumpState *s, Error **errp)
|
static void write_elf64_phdr_note(DumpState *s, Elf64_Phdr *phdr)
|
||||||
{
|
{
|
||||||
Elf64_Phdr phdr;
|
memset(phdr, 0, sizeof(*phdr));
|
||||||
hwaddr begin = s->memory_offset - s->note_size;
|
phdr->p_type = cpu_to_dump32(s, PT_NOTE);
|
||||||
int ret;
|
phdr->p_offset = cpu_to_dump64(s, s->note_offset);
|
||||||
|
phdr->p_paddr = 0;
|
||||||
memset(&phdr, 0, sizeof(Elf64_Phdr));
|
phdr->p_filesz = cpu_to_dump64(s, s->note_size);
|
||||||
phdr.p_type = cpu_to_dump32(s, PT_NOTE);
|
phdr->p_memsz = cpu_to_dump64(s, s->note_size);
|
||||||
phdr.p_offset = cpu_to_dump64(s, begin);
|
phdr->p_vaddr = 0;
|
||||||
phdr.p_paddr = 0;
|
|
||||||
phdr.p_filesz = cpu_to_dump64(s, s->note_size);
|
|
||||||
phdr.p_memsz = cpu_to_dump64(s, s->note_size);
|
|
||||||
phdr.p_vaddr = 0;
|
|
||||||
|
|
||||||
ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
|
|
||||||
if (ret < 0) {
|
|
||||||
error_setg_errno(errp, -ret,
|
|
||||||
"dump: failed to write program header table");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int cpu_index(CPUState *cpu)
|
static inline int cpu_index(CPUState *cpu)
|
||||||
@ -298,25 +301,15 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
|
|||||||
write_guest_note(f, s, errp);
|
write_guest_note(f, s, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_elf32_note(DumpState *s, Error **errp)
|
static void write_elf32_phdr_note(DumpState *s, Elf32_Phdr *phdr)
|
||||||
{
|
{
|
||||||
hwaddr begin = s->memory_offset - s->note_size;
|
memset(phdr, 0, sizeof(*phdr));
|
||||||
Elf32_Phdr phdr;
|
phdr->p_type = cpu_to_dump32(s, PT_NOTE);
|
||||||
int ret;
|
phdr->p_offset = cpu_to_dump32(s, s->note_offset);
|
||||||
|
phdr->p_paddr = 0;
|
||||||
memset(&phdr, 0, sizeof(Elf32_Phdr));
|
phdr->p_filesz = cpu_to_dump32(s, s->note_size);
|
||||||
phdr.p_type = cpu_to_dump32(s, PT_NOTE);
|
phdr->p_memsz = cpu_to_dump32(s, s->note_size);
|
||||||
phdr.p_offset = cpu_to_dump32(s, begin);
|
phdr->p_vaddr = 0;
|
||||||
phdr.p_paddr = 0;
|
|
||||||
phdr.p_filesz = cpu_to_dump32(s, s->note_size);
|
|
||||||
phdr.p_memsz = cpu_to_dump32(s, s->note_size);
|
|
||||||
phdr.p_vaddr = 0;
|
|
||||||
|
|
||||||
ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
|
|
||||||
if (ret < 0) {
|
|
||||||
error_setg_errno(errp, -ret,
|
|
||||||
"dump: failed to write program header table");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
|
static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
|
||||||
@ -346,6 +339,32 @@ static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
|
|||||||
write_guest_note(f, s, errp);
|
write_guest_note(f, s, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void write_elf_phdr_note(DumpState *s, Error **errp)
|
||||||
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
|
Elf32_Phdr phdr32;
|
||||||
|
Elf64_Phdr phdr64;
|
||||||
|
void *phdr;
|
||||||
|
size_t size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (dump_is_64bit(s)) {
|
||||||
|
write_elf64_phdr_note(s, &phdr64);
|
||||||
|
size = sizeof(phdr64);
|
||||||
|
phdr = &phdr64;
|
||||||
|
} else {
|
||||||
|
write_elf32_phdr_note(s, &phdr32);
|
||||||
|
size = sizeof(phdr32);
|
||||||
|
phdr = &phdr32;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fd_write_vmcore(phdr, size, s);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_setg_errno(errp, -ret,
|
||||||
|
"dump: failed to write program header table");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void write_elf_section(DumpState *s, int type, Error **errp)
|
static void write_elf_section(DumpState *s, int type, Error **errp)
|
||||||
{
|
{
|
||||||
Elf32_Shdr shdr32;
|
Elf32_Shdr shdr32;
|
||||||
@ -357,12 +376,12 @@ static void write_elf_section(DumpState *s, int type, Error **errp)
|
|||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
shdr_size = sizeof(Elf32_Shdr);
|
shdr_size = sizeof(Elf32_Shdr);
|
||||||
memset(&shdr32, 0, shdr_size);
|
memset(&shdr32, 0, shdr_size);
|
||||||
shdr32.sh_info = cpu_to_dump32(s, s->sh_info);
|
shdr32.sh_info = cpu_to_dump32(s, s->phdr_num);
|
||||||
shdr = &shdr32;
|
shdr = &shdr32;
|
||||||
} else {
|
} else {
|
||||||
shdr_size = sizeof(Elf64_Shdr);
|
shdr_size = sizeof(Elf64_Shdr);
|
||||||
memset(&shdr64, 0, shdr_size);
|
memset(&shdr64, 0, shdr_size);
|
||||||
shdr64.sh_info = cpu_to_dump32(s, s->sh_info);
|
shdr64.sh_info = cpu_to_dump32(s, s->phdr_num);
|
||||||
shdr = &shdr64;
|
shdr = &shdr64;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,23 +408,21 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp)
|
|||||||
static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
|
static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
|
||||||
int64_t size, Error **errp)
|
int64_t size, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
int64_t i;
|
int64_t i;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < size / s->dump_info.page_size; i++) {
|
for (i = 0; i < size / s->dump_info.page_size; i++) {
|
||||||
write_data(s, block->host_addr + start + i * s->dump_info.page_size,
|
write_data(s, block->host_addr + start + i * s->dump_info.page_size,
|
||||||
s->dump_info.page_size, &local_err);
|
s->dump_info.page_size, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((size % s->dump_info.page_size) != 0) {
|
if ((size % s->dump_info.page_size) != 0) {
|
||||||
write_data(s, block->host_addr + start + i * s->dump_info.page_size,
|
write_data(s, block->host_addr + start + i * s->dump_info.page_size,
|
||||||
size % s->dump_info.page_size, &local_err);
|
size % s->dump_info.page_size, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -475,45 +492,46 @@ static void get_offset_range(hwaddr phys_addr,
|
|||||||
|
|
||||||
static void write_elf_loads(DumpState *s, Error **errp)
|
static void write_elf_loads(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
hwaddr offset, filesz;
|
hwaddr offset, filesz;
|
||||||
MemoryMapping *memory_mapping;
|
MemoryMapping *memory_mapping;
|
||||||
uint32_t phdr_index = 1;
|
uint32_t phdr_index = 1;
|
||||||
uint32_t max_index;
|
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
if (s->have_section) {
|
|
||||||
max_index = s->sh_info;
|
|
||||||
} else {
|
|
||||||
max_index = s->phdr_num;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTAILQ_FOREACH(memory_mapping, &s->list.head, next) {
|
QTAILQ_FOREACH(memory_mapping, &s->list.head, next) {
|
||||||
get_offset_range(memory_mapping->phys_addr,
|
get_offset_range(memory_mapping->phys_addr,
|
||||||
memory_mapping->length,
|
memory_mapping->length,
|
||||||
s, &offset, &filesz);
|
s, &offset, &filesz);
|
||||||
if (s->dump_info.d_class == ELFCLASS64) {
|
if (dump_is_64bit(s)) {
|
||||||
write_elf64_load(s, memory_mapping, phdr_index++, offset,
|
write_elf64_load(s, memory_mapping, phdr_index++, offset,
|
||||||
filesz, &local_err);
|
filesz, errp);
|
||||||
} else {
|
} else {
|
||||||
write_elf32_load(s, memory_mapping, phdr_index++, offset,
|
write_elf32_load(s, memory_mapping, phdr_index++, offset,
|
||||||
filesz, &local_err);
|
filesz, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phdr_index >= max_index) {
|
if (phdr_index >= s->phdr_num) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void write_elf_notes(DumpState *s, Error **errp)
|
||||||
|
{
|
||||||
|
if (dump_is_64bit(s)) {
|
||||||
|
write_elf64_notes(fd_write_vmcore, s, errp);
|
||||||
|
} else {
|
||||||
|
write_elf32_notes(fd_write_vmcore, s, errp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* write elf header, PT_NOTE and elf note to vmcore. */
|
/* write elf header, PT_NOTE and elf note to vmcore. */
|
||||||
static void dump_begin(DumpState *s, Error **errp)
|
static void dump_begin(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
Error *local_err = NULL;
|
ERRP_GUARD();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the vmcore's format is:
|
* the vmcore's format is:
|
||||||
@ -540,77 +558,37 @@ static void dump_begin(DumpState *s, Error **errp)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* write elf header to vmcore */
|
/* write elf header to vmcore */
|
||||||
if (s->dump_info.d_class == ELFCLASS64) {
|
if (dump_is_64bit(s)) {
|
||||||
write_elf64_header(s, &local_err);
|
write_elf64_header(s, errp);
|
||||||
} else {
|
} else {
|
||||||
write_elf32_header(s, &local_err);
|
write_elf32_header(s, errp);
|
||||||
}
|
}
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->dump_info.d_class == ELFCLASS64) {
|
|
||||||
/* write PT_NOTE to vmcore */
|
/* write PT_NOTE to vmcore */
|
||||||
write_elf64_note(s, &local_err);
|
write_elf_phdr_note(s, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write all PT_LOAD to vmcore */
|
/* write all PT_LOAD to vmcore */
|
||||||
write_elf_loads(s, &local_err);
|
write_elf_loads(s, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write section to vmcore */
|
/* write section to vmcore */
|
||||||
if (s->have_section) {
|
if (s->shdr_num) {
|
||||||
write_elf_section(s, 1, &local_err);
|
write_elf_section(s, 1, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write notes to vmcore */
|
/* write notes to vmcore */
|
||||||
write_elf64_notes(fd_write_vmcore, s, &local_err);
|
write_elf_notes(s, errp);
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* write PT_NOTE to vmcore */
|
|
||||||
write_elf32_note(s, &local_err);
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write all PT_LOAD to vmcore */
|
|
||||||
write_elf_loads(s, &local_err);
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write section to vmcore */
|
|
||||||
if (s->have_section) {
|
|
||||||
write_elf_section(s, 0, &local_err);
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write notes to vmcore */
|
|
||||||
write_elf32_notes(fd_write_vmcore, s, &local_err);
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_next_block(DumpState *s, GuestPhysBlock *block)
|
static int get_next_block(DumpState *s, GuestPhysBlock *block)
|
||||||
@ -643,9 +621,9 @@ static int get_next_block(DumpState *s, GuestPhysBlock *block)
|
|||||||
/* write all memory to vmcore */
|
/* write all memory to vmcore */
|
||||||
static void dump_iterate(DumpState *s, Error **errp)
|
static void dump_iterate(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
GuestPhysBlock *block;
|
GuestPhysBlock *block;
|
||||||
int64_t size;
|
int64_t size;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
block = s->next_block;
|
block = s->next_block;
|
||||||
@ -657,9 +635,8 @@ static void dump_iterate(DumpState *s, Error **errp)
|
|||||||
size -= block->target_end - (s->begin + s->length);
|
size -= block->target_end - (s->begin + s->length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write_memory(s, block, s->start, size, &local_err);
|
write_memory(s, block, s->start, size, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,11 +645,10 @@ static void dump_iterate(DumpState *s, Error **errp)
|
|||||||
|
|
||||||
static void create_vmcore(DumpState *s, Error **errp)
|
static void create_vmcore(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
Error *local_err = NULL;
|
ERRP_GUARD();
|
||||||
|
|
||||||
dump_begin(s, &local_err);
|
dump_begin(s, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -771,7 +747,7 @@ static void get_note_sizes(DumpState *s, const void *note,
|
|||||||
uint64_t name_sz;
|
uint64_t name_sz;
|
||||||
uint64_t desc_sz;
|
uint64_t desc_sz;
|
||||||
|
|
||||||
if (s->dump_info.d_class == ELFCLASS64) {
|
if (dump_is_64bit(s)) {
|
||||||
const Elf64_Nhdr *hdr = note;
|
const Elf64_Nhdr *hdr = note;
|
||||||
note_head_sz = sizeof(Elf64_Nhdr);
|
note_head_sz = sizeof(Elf64_Nhdr);
|
||||||
name_sz = tswap64(hdr->n_namesz);
|
name_sz = tswap64(hdr->n_namesz);
|
||||||
@ -809,6 +785,7 @@ static bool note_name_equal(DumpState *s,
|
|||||||
/* write common header, sub header and elf note to vmcore */
|
/* write common header, sub header and elf note to vmcore */
|
||||||
static void create_header32(DumpState *s, Error **errp)
|
static void create_header32(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
DiskDumpHeader32 *dh = NULL;
|
DiskDumpHeader32 *dh = NULL;
|
||||||
KdumpSubHeader32 *kh = NULL;
|
KdumpSubHeader32 *kh = NULL;
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -817,7 +794,6 @@ static void create_header32(DumpState *s, Error **errp)
|
|||||||
uint32_t bitmap_blocks;
|
uint32_t bitmap_blocks;
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
uint64_t offset_note;
|
uint64_t offset_note;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
/* write common header, the version of kdump-compressed format is 6th */
|
/* write common header, the version of kdump-compressed format is 6th */
|
||||||
size = sizeof(DiskDumpHeader32);
|
size = sizeof(DiskDumpHeader32);
|
||||||
@ -893,9 +869,8 @@ static void create_header32(DumpState *s, Error **errp)
|
|||||||
s->note_buf_offset = 0;
|
s->note_buf_offset = 0;
|
||||||
|
|
||||||
/* use s->note_buf to store notes temporarily */
|
/* use s->note_buf to store notes temporarily */
|
||||||
write_elf32_notes(buf_write_note, s, &local_err);
|
write_elf32_notes(buf_write_note, s, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (write_buffer(s->fd, offset_note, s->note_buf,
|
if (write_buffer(s->fd, offset_note, s->note_buf,
|
||||||
@ -921,6 +896,7 @@ out:
|
|||||||
/* write common header, sub header and elf note to vmcore */
|
/* write common header, sub header and elf note to vmcore */
|
||||||
static void create_header64(DumpState *s, Error **errp)
|
static void create_header64(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
DiskDumpHeader64 *dh = NULL;
|
DiskDumpHeader64 *dh = NULL;
|
||||||
KdumpSubHeader64 *kh = NULL;
|
KdumpSubHeader64 *kh = NULL;
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -929,7 +905,6 @@ static void create_header64(DumpState *s, Error **errp)
|
|||||||
uint32_t bitmap_blocks;
|
uint32_t bitmap_blocks;
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
uint64_t offset_note;
|
uint64_t offset_note;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
/* write common header, the version of kdump-compressed format is 6th */
|
/* write common header, the version of kdump-compressed format is 6th */
|
||||||
size = sizeof(DiskDumpHeader64);
|
size = sizeof(DiskDumpHeader64);
|
||||||
@ -1005,9 +980,8 @@ static void create_header64(DumpState *s, Error **errp)
|
|||||||
s->note_buf_offset = 0;
|
s->note_buf_offset = 0;
|
||||||
|
|
||||||
/* use s->note_buf to store notes temporarily */
|
/* use s->note_buf to store notes temporarily */
|
||||||
write_elf64_notes(buf_write_note, s, &local_err);
|
write_elf64_notes(buf_write_note, s, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1033,10 +1007,10 @@ out:
|
|||||||
|
|
||||||
static void write_dump_header(DumpState *s, Error **errp)
|
static void write_dump_header(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
if (s->dump_info.d_class == ELFCLASS32) {
|
if (dump_is_64bit(s)) {
|
||||||
create_header32(s, errp);
|
|
||||||
} else {
|
|
||||||
create_header64(s, errp);
|
create_header64(s, errp);
|
||||||
|
} else {
|
||||||
|
create_header32(s, errp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1463,8 +1437,8 @@ out:
|
|||||||
|
|
||||||
static void create_kdump_vmcore(DumpState *s, Error **errp)
|
static void create_kdump_vmcore(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
int ret;
|
int ret;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the kdump-compressed format is:
|
* the kdump-compressed format is:
|
||||||
@ -1494,21 +1468,18 @@ static void create_kdump_vmcore(DumpState *s, Error **errp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_dump_header(s, &local_err);
|
write_dump_header(s, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_dump_bitmap(s, &local_err);
|
write_dump_bitmap(s, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_dump_pages(s, &local_err);
|
write_dump_pages(s, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1638,10 +1609,10 @@ static void dump_init(DumpState *s, int fd, bool has_format,
|
|||||||
DumpGuestMemoryFormat format, bool paging, bool has_filter,
|
DumpGuestMemoryFormat format, bool paging, bool has_filter,
|
||||||
int64_t begin, int64_t length, Error **errp)
|
int64_t begin, int64_t length, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
VMCoreInfoState *vmci = vmcoreinfo_find();
|
VMCoreInfoState *vmci = vmcoreinfo_find();
|
||||||
CPUState *cpu;
|
CPUState *cpu;
|
||||||
int nr_cpus;
|
int nr_cpus;
|
||||||
Error *err = NULL;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
s->has_format = has_format;
|
s->has_format = has_format;
|
||||||
@ -1726,8 +1697,8 @@ static void dump_init(DumpState *s, int fd, bool has_format,
|
|||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint16_t format;
|
uint16_t format;
|
||||||
|
|
||||||
note_head_size = s->dump_info.d_class == ELFCLASS32 ?
|
note_head_size = dump_is_64bit(s) ?
|
||||||
sizeof(Elf32_Nhdr) : sizeof(Elf64_Nhdr);
|
sizeof(Elf64_Nhdr) : sizeof(Elf32_Nhdr);
|
||||||
|
|
||||||
format = le16_to_cpu(vmci->vmcoreinfo.guest_format);
|
format = le16_to_cpu(vmci->vmcoreinfo.guest_format);
|
||||||
size = le32_to_cpu(vmci->vmcoreinfo.size);
|
size = le32_to_cpu(vmci->vmcoreinfo.size);
|
||||||
@ -1760,9 +1731,8 @@ static void dump_init(DumpState *s, int fd, bool has_format,
|
|||||||
|
|
||||||
/* get memory mapping */
|
/* get memory mapping */
|
||||||
if (paging) {
|
if (paging) {
|
||||||
qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, &err);
|
qemu_get_guest_memory_mapping(&s->list, &s->guest_phys_blocks, errp);
|
||||||
if (err != NULL) {
|
if (*errp) {
|
||||||
error_propagate(errp, err);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1817,39 +1787,31 @@ static void dump_init(DumpState *s, int fd, bool has_format,
|
|||||||
*/
|
*/
|
||||||
s->phdr_num = 1; /* PT_NOTE */
|
s->phdr_num = 1; /* PT_NOTE */
|
||||||
if (s->list.num < UINT16_MAX - 2) {
|
if (s->list.num < UINT16_MAX - 2) {
|
||||||
|
s->shdr_num = 0;
|
||||||
s->phdr_num += s->list.num;
|
s->phdr_num += s->list.num;
|
||||||
s->have_section = false;
|
|
||||||
} else {
|
} else {
|
||||||
s->have_section = true;
|
/* sh_info of section 0 holds the real number of phdrs */
|
||||||
s->phdr_num = PN_XNUM;
|
s->shdr_num = 1;
|
||||||
s->sh_info = 1; /* PT_NOTE */
|
|
||||||
|
|
||||||
/* the type of shdr->sh_info is uint32_t, so we should avoid overflow */
|
/* the type of shdr->sh_info is uint32_t, so we should avoid overflow */
|
||||||
if (s->list.num <= UINT32_MAX - 1) {
|
if (s->list.num <= UINT32_MAX - 1) {
|
||||||
s->sh_info += s->list.num;
|
s->phdr_num += s->list.num;
|
||||||
} else {
|
} else {
|
||||||
s->sh_info = UINT32_MAX;
|
s->phdr_num = UINT32_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->dump_info.d_class == ELFCLASS64) {
|
if (dump_is_64bit(s)) {
|
||||||
if (s->have_section) {
|
s->phdr_offset = sizeof(Elf64_Ehdr);
|
||||||
s->memory_offset = sizeof(Elf64_Ehdr) +
|
s->shdr_offset = s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_num;
|
||||||
sizeof(Elf64_Phdr) * s->sh_info +
|
s->note_offset = s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_num;
|
||||||
sizeof(Elf64_Shdr) + s->note_size;
|
s->memory_offset = s->note_offset + s->note_size;
|
||||||
} else {
|
} else {
|
||||||
s->memory_offset = sizeof(Elf64_Ehdr) +
|
|
||||||
sizeof(Elf64_Phdr) * s->phdr_num + s->note_size;
|
s->phdr_offset = sizeof(Elf32_Ehdr);
|
||||||
}
|
s->shdr_offset = s->phdr_offset + sizeof(Elf32_Phdr) * s->phdr_num;
|
||||||
} else {
|
s->note_offset = s->shdr_offset + sizeof(Elf32_Shdr) * s->shdr_num;
|
||||||
if (s->have_section) {
|
s->memory_offset = s->note_offset + s->note_size;
|
||||||
s->memory_offset = sizeof(Elf32_Ehdr) +
|
|
||||||
sizeof(Elf32_Phdr) * s->sh_info +
|
|
||||||
sizeof(Elf32_Shdr) + s->note_size;
|
|
||||||
} else {
|
|
||||||
s->memory_offset = sizeof(Elf32_Ehdr) +
|
|
||||||
sizeof(Elf32_Phdr) * s->phdr_num + s->note_size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -1861,33 +1823,32 @@ cleanup:
|
|||||||
/* this operation might be time consuming. */
|
/* this operation might be time consuming. */
|
||||||
static void dump_process(DumpState *s, Error **errp)
|
static void dump_process(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
Error *local_err = NULL;
|
ERRP_GUARD();
|
||||||
DumpQueryResult *result = NULL;
|
DumpQueryResult *result = NULL;
|
||||||
|
|
||||||
if (s->has_format && s->format == DUMP_GUEST_MEMORY_FORMAT_WIN_DMP) {
|
if (s->has_format && s->format == DUMP_GUEST_MEMORY_FORMAT_WIN_DMP) {
|
||||||
#ifdef TARGET_X86_64
|
#ifdef TARGET_X86_64
|
||||||
create_win_dump(s, &local_err);
|
create_win_dump(s, errp);
|
||||||
#endif
|
#endif
|
||||||
} else if (s->has_format && s->format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
|
} else if (s->has_format && s->format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
|
||||||
create_kdump_vmcore(s, &local_err);
|
create_kdump_vmcore(s, errp);
|
||||||
} else {
|
} else {
|
||||||
create_vmcore(s, &local_err);
|
create_vmcore(s, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make sure status is written after written_size updates */
|
/* make sure status is written after written_size updates */
|
||||||
smp_wmb();
|
smp_wmb();
|
||||||
qatomic_set(&s->status,
|
qatomic_set(&s->status,
|
||||||
(local_err ? DUMP_STATUS_FAILED : DUMP_STATUS_COMPLETED));
|
(*errp ? DUMP_STATUS_FAILED : DUMP_STATUS_COMPLETED));
|
||||||
|
|
||||||
/* send DUMP_COMPLETED message (unconditionally) */
|
/* send DUMP_COMPLETED message (unconditionally) */
|
||||||
result = qmp_query_dump(NULL);
|
result = qmp_query_dump(NULL);
|
||||||
/* should never fail */
|
/* should never fail */
|
||||||
assert(result);
|
assert(result);
|
||||||
qapi_event_send_dump_completed(result, !!local_err, (local_err ?
|
qapi_event_send_dump_completed(result, !!*errp, (*errp ?
|
||||||
error_get_pretty(local_err) : NULL));
|
error_get_pretty(*errp) : NULL));
|
||||||
qapi_free_DumpQueryResult(result);
|
qapi_free_DumpQueryResult(result);
|
||||||
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
dump_cleanup(s);
|
dump_cleanup(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1916,10 +1877,10 @@ void qmp_dump_guest_memory(bool paging, const char *file,
|
|||||||
int64_t length, bool has_format,
|
int64_t length, bool has_format,
|
||||||
DumpGuestMemoryFormat format, Error **errp)
|
DumpGuestMemoryFormat format, Error **errp)
|
||||||
{
|
{
|
||||||
|
ERRP_GUARD();
|
||||||
const char *p;
|
const char *p;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
DumpState *s;
|
DumpState *s;
|
||||||
Error *local_err = NULL;
|
|
||||||
bool detach_p = false;
|
bool detach_p = false;
|
||||||
|
|
||||||
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
if (runstate_check(RUN_STATE_INMIGRATE)) {
|
||||||
@ -2019,9 +1980,8 @@ void qmp_dump_guest_memory(bool paging, const char *file,
|
|||||||
dump_state_prepare(s);
|
dump_state_prepare(s);
|
||||||
|
|
||||||
dump_init(s, fd, has_format, format, paging, has_begin,
|
dump_init(s, fd, has_format, format, paging, has_begin,
|
||||||
begin, length, &local_err);
|
begin, length, errp);
|
||||||
if (local_err) {
|
if (*errp) {
|
||||||
error_propagate(errp, local_err);
|
|
||||||
qatomic_set(&s->status, DUMP_STATUS_FAILED);
|
qatomic_set(&s->status, DUMP_STATUS_FAILED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
229
dump/win_dump.c
229
dump/win_dump.c
@ -23,11 +23,31 @@
|
|||||||
#include "hw/misc/vmcoreinfo.h"
|
#include "hw/misc/vmcoreinfo.h"
|
||||||
#include "win_dump.h"
|
#include "win_dump.h"
|
||||||
|
|
||||||
static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp)
|
static size_t win_dump_ptr_size(bool x64)
|
||||||
|
{
|
||||||
|
return x64 ? sizeof(uint64_t) : sizeof(uint32_t);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define _WIN_DUMP_FIELD(f) (x64 ? h->x64.f : h->x32.f)
|
||||||
|
#define WIN_DUMP_FIELD(field) _WIN_DUMP_FIELD(field)
|
||||||
|
|
||||||
|
#define _WIN_DUMP_FIELD_PTR(f) (x64 ? (void *)&h->x64.f : (void *)&h->x32.f)
|
||||||
|
#define WIN_DUMP_FIELD_PTR(field) _WIN_DUMP_FIELD_PTR(field)
|
||||||
|
|
||||||
|
#define _WIN_DUMP_FIELD_SIZE(f) (x64 ? sizeof(h->x64.f) : sizeof(h->x32.f))
|
||||||
|
#define WIN_DUMP_FIELD_SIZE(field) _WIN_DUMP_FIELD_SIZE(field)
|
||||||
|
|
||||||
|
static size_t win_dump_ctx_size(bool x64)
|
||||||
|
{
|
||||||
|
return x64 ? sizeof(WinContext64) : sizeof(WinContext32);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t write_run(uint64_t base_page, uint64_t page_count,
|
||||||
|
int fd, Error **errp)
|
||||||
{
|
{
|
||||||
void *buf;
|
void *buf;
|
||||||
uint64_t addr = run->BasePage << TARGET_PAGE_BITS;
|
uint64_t addr = base_page << TARGET_PAGE_BITS;
|
||||||
uint64_t size = run->PageCount << TARGET_PAGE_BITS;
|
uint64_t size = page_count << TARGET_PAGE_BITS;
|
||||||
uint64_t len, l;
|
uint64_t len, l;
|
||||||
size_t total = 0;
|
size_t total = 0;
|
||||||
|
|
||||||
@ -56,15 +76,16 @@ static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp)
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp)
|
static void write_runs(DumpState *s, WinDumpHeader *h, bool x64, Error **errp)
|
||||||
{
|
{
|
||||||
WinDumpPhyMemDesc64 *desc = &h->PhysicalMemoryBlock;
|
uint64_t BasePage, PageCount;
|
||||||
WinDumpPhyMemRun64 *run = desc->Run;
|
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < desc->NumberOfRuns; i++) {
|
for (i = 0; i < WIN_DUMP_FIELD(PhysicalMemoryBlock.NumberOfRuns); i++) {
|
||||||
s->written_size += write_run(run + i, s->fd, &local_err);
|
BasePage = WIN_DUMP_FIELD(PhysicalMemoryBlock.Run[i].BasePage);
|
||||||
|
PageCount = WIN_DUMP_FIELD(PhysicalMemoryBlock.Run[i].PageCount);
|
||||||
|
s->written_size += write_run(BasePage, PageCount, s->fd, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return;
|
||||||
@ -72,30 +93,45 @@ static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void patch_mm_pfn_database(WinDumpHeader64 *h, Error **errp)
|
static int cpu_read_ptr(bool x64, CPUState *cpu, uint64_t addr, uint64_t *ptr)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
uint32_t ptr32;
|
||||||
|
uint64_t ptr64;
|
||||||
|
|
||||||
|
ret = cpu_memory_rw_debug(cpu, addr, x64 ? (void *)&ptr64 : (void *)&ptr32,
|
||||||
|
win_dump_ptr_size(x64), 0);
|
||||||
|
|
||||||
|
*ptr = x64 ? ptr64 : ptr32;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void patch_mm_pfn_database(WinDumpHeader *h, bool x64, Error **errp)
|
||||||
{
|
{
|
||||||
if (cpu_memory_rw_debug(first_cpu,
|
if (cpu_memory_rw_debug(first_cpu,
|
||||||
h->KdDebuggerDataBlock + KDBG_MM_PFN_DATABASE_OFFSET64,
|
WIN_DUMP_FIELD(KdDebuggerDataBlock) + KDBG_MM_PFN_DATABASE_OFFSET,
|
||||||
(uint8_t *)&h->PfnDatabase, sizeof(h->PfnDatabase), 0)) {
|
WIN_DUMP_FIELD_PTR(PfnDatabase),
|
||||||
|
WIN_DUMP_FIELD_SIZE(PfnDatabase), 0)) {
|
||||||
error_setg(errp, "win-dump: failed to read MmPfnDatabase");
|
error_setg(errp, "win-dump: failed to read MmPfnDatabase");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void patch_bugcheck_data(WinDumpHeader64 *h, Error **errp)
|
static void patch_bugcheck_data(WinDumpHeader *h, bool x64, Error **errp)
|
||||||
{
|
{
|
||||||
uint64_t KiBugcheckData;
|
uint64_t KiBugcheckData;
|
||||||
|
|
||||||
if (cpu_memory_rw_debug(first_cpu,
|
if (cpu_read_ptr(x64, first_cpu,
|
||||||
h->KdDebuggerDataBlock + KDBG_KI_BUGCHECK_DATA_OFFSET64,
|
WIN_DUMP_FIELD(KdDebuggerDataBlock) + KDBG_KI_BUGCHECK_DATA_OFFSET,
|
||||||
(uint8_t *)&KiBugcheckData, sizeof(KiBugcheckData), 0)) {
|
&KiBugcheckData)) {
|
||||||
error_setg(errp, "win-dump: failed to read KiBugcheckData");
|
error_setg(errp, "win-dump: failed to read KiBugcheckData");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpu_memory_rw_debug(first_cpu,
|
if (cpu_memory_rw_debug(first_cpu, KiBugcheckData,
|
||||||
KiBugcheckData,
|
WIN_DUMP_FIELD(BugcheckData),
|
||||||
h->BugcheckData, sizeof(h->BugcheckData), 0)) {
|
WIN_DUMP_FIELD_SIZE(BugcheckData), 0)) {
|
||||||
error_setg(errp, "win-dump: failed to read bugcheck data");
|
error_setg(errp, "win-dump: failed to read bugcheck data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -104,62 +140,72 @@ static void patch_bugcheck_data(WinDumpHeader64 *h, Error **errp)
|
|||||||
* If BugcheckCode wasn't saved, we consider guest OS as alive.
|
* If BugcheckCode wasn't saved, we consider guest OS as alive.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!h->BugcheckCode) {
|
if (!WIN_DUMP_FIELD(BugcheckCode)) {
|
||||||
h->BugcheckCode = LIVE_SYSTEM_DUMP;
|
*(uint32_t *)WIN_DUMP_FIELD_PTR(BugcheckCode) = LIVE_SYSTEM_DUMP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine tries to correct mistakes in crashdump header.
|
* This routine tries to correct mistakes in crashdump header.
|
||||||
*/
|
*/
|
||||||
static void patch_header(WinDumpHeader64 *h)
|
static void patch_header(WinDumpHeader *h, bool x64)
|
||||||
{
|
{
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
h->RequiredDumpSpace = sizeof(WinDumpHeader64) +
|
if (x64) {
|
||||||
(h->PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS);
|
h->x64.RequiredDumpSpace = sizeof(WinDumpHeader64) +
|
||||||
h->PhysicalMemoryBlock.unused = 0;
|
(h->x64.PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS);
|
||||||
h->unused1 = 0;
|
h->x64.PhysicalMemoryBlock.unused = 0;
|
||||||
|
h->x64.unused1 = 0;
|
||||||
|
} else {
|
||||||
|
h->x32.RequiredDumpSpace = sizeof(WinDumpHeader32) +
|
||||||
|
(h->x32.PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS);
|
||||||
|
}
|
||||||
|
|
||||||
patch_mm_pfn_database(h, &local_err);
|
patch_mm_pfn_database(h, x64, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
warn_report_err(local_err);
|
warn_report_err(local_err);
|
||||||
local_err = NULL;
|
local_err = NULL;
|
||||||
}
|
}
|
||||||
patch_bugcheck_data(h, &local_err);
|
patch_bugcheck_data(h, x64, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
warn_report_err(local_err);
|
warn_report_err(local_err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_header(WinDumpHeader64 *h, Error **errp)
|
static bool check_header(WinDumpHeader *h, bool *x64, Error **errp)
|
||||||
{
|
{
|
||||||
const char Signature[] = "PAGE";
|
const char Signature[] = "PAGE";
|
||||||
const char ValidDump[] = "DU64";
|
|
||||||
|
|
||||||
if (memcmp(h->Signature, Signature, sizeof(h->Signature))) {
|
if (memcmp(h->Signature, Signature, sizeof(h->Signature))) {
|
||||||
error_setg(errp, "win-dump: invalid header, expected '%.4s',"
|
error_setg(errp, "win-dump: invalid header, expected '%.4s',"
|
||||||
" got '%.4s'", Signature, h->Signature);
|
" got '%.4s'", Signature, h->Signature);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(h->ValidDump, ValidDump, sizeof(h->ValidDump))) {
|
if (!memcmp(h->ValidDump, "DUMP", sizeof(h->ValidDump))) {
|
||||||
error_setg(errp, "win-dump: invalid header, expected '%.4s',"
|
*x64 = false;
|
||||||
" got '%.4s'", ValidDump, h->ValidDump);
|
} else if (!memcmp(h->ValidDump, "DU64", sizeof(h->ValidDump))) {
|
||||||
return;
|
*x64 = true;
|
||||||
|
} else {
|
||||||
|
error_setg(errp, "win-dump: invalid header, expected 'DUMP' or 'DU64',"
|
||||||
|
" got '%.4s'", h->ValidDump);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_kdbg(WinDumpHeader64 *h, Error **errp)
|
static void check_kdbg(WinDumpHeader *h, bool x64, Error **errp)
|
||||||
{
|
{
|
||||||
const char OwnerTag[] = "KDBG";
|
const char OwnerTag[] = "KDBG";
|
||||||
char read_OwnerTag[4];
|
char read_OwnerTag[4];
|
||||||
uint64_t KdDebuggerDataBlock = h->KdDebuggerDataBlock;
|
uint64_t KdDebuggerDataBlock = WIN_DUMP_FIELD(KdDebuggerDataBlock);
|
||||||
bool try_fallback = true;
|
bool try_fallback = true;
|
||||||
|
|
||||||
try_again:
|
try_again:
|
||||||
if (cpu_memory_rw_debug(first_cpu,
|
if (cpu_memory_rw_debug(first_cpu,
|
||||||
KdDebuggerDataBlock + KDBG_OWNER_TAG_OFFSET64,
|
KdDebuggerDataBlock + KDBG_OWNER_TAG_OFFSET,
|
||||||
(uint8_t *)&read_OwnerTag, sizeof(read_OwnerTag), 0)) {
|
(uint8_t *)&read_OwnerTag, sizeof(read_OwnerTag), 0)) {
|
||||||
error_setg(errp, "win-dump: failed to read OwnerTag");
|
error_setg(errp, "win-dump: failed to read OwnerTag");
|
||||||
return;
|
return;
|
||||||
@ -173,7 +219,7 @@ try_again:
|
|||||||
* we try to use KDBG obtained by guest driver.
|
* we try to use KDBG obtained by guest driver.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
KdDebuggerDataBlock = h->BugcheckParameter1;
|
KdDebuggerDataBlock = WIN_DUMP_FIELD(BugcheckParameter1);
|
||||||
try_fallback = false;
|
try_fallback = false;
|
||||||
goto try_again;
|
goto try_again;
|
||||||
} else {
|
} else {
|
||||||
@ -184,7 +230,11 @@ try_again:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h->KdDebuggerDataBlock = KdDebuggerDataBlock;
|
if (x64) {
|
||||||
|
h->x64.KdDebuggerDataBlock = KdDebuggerDataBlock;
|
||||||
|
} else {
|
||||||
|
h->x32.KdDebuggerDataBlock = KdDebuggerDataBlock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct saved_context {
|
struct saved_context {
|
||||||
@ -192,24 +242,25 @@ struct saved_context {
|
|||||||
uint64_t addr;
|
uint64_t addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void patch_and_save_context(WinDumpHeader64 *h,
|
static void patch_and_save_context(WinDumpHeader *h, bool x64,
|
||||||
struct saved_context *saved_ctx,
|
struct saved_context *saved_ctx,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
uint64_t KdDebuggerDataBlock = WIN_DUMP_FIELD(KdDebuggerDataBlock);
|
||||||
uint64_t KiProcessorBlock;
|
uint64_t KiProcessorBlock;
|
||||||
uint16_t OffsetPrcbContext;
|
uint16_t OffsetPrcbContext;
|
||||||
CPUState *cpu;
|
CPUState *cpu;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (cpu_memory_rw_debug(first_cpu,
|
if (cpu_read_ptr(x64, first_cpu,
|
||||||
h->KdDebuggerDataBlock + KDBG_KI_PROCESSOR_BLOCK_OFFSET64,
|
KdDebuggerDataBlock + KDBG_KI_PROCESSOR_BLOCK_OFFSET,
|
||||||
(uint8_t *)&KiProcessorBlock, sizeof(KiProcessorBlock), 0)) {
|
&KiProcessorBlock)) {
|
||||||
error_setg(errp, "win-dump: failed to read KiProcessorBlock");
|
error_setg(errp, "win-dump: failed to read KiProcessorBlock");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpu_memory_rw_debug(first_cpu,
|
if (cpu_memory_rw_debug(first_cpu,
|
||||||
h->KdDebuggerDataBlock + KDBG_OFFSET_PRCB_CONTEXT_OFFSET64,
|
KdDebuggerDataBlock + KDBG_OFFSET_PRCB_CONTEXT_OFFSET,
|
||||||
(uint8_t *)&OffsetPrcbContext, sizeof(OffsetPrcbContext), 0)) {
|
(uint8_t *)&OffsetPrcbContext, sizeof(OffsetPrcbContext), 0)) {
|
||||||
error_setg(errp, "win-dump: failed to read OffsetPrcbContext");
|
error_setg(errp, "win-dump: failed to read OffsetPrcbContext");
|
||||||
return;
|
return;
|
||||||
@ -222,17 +273,17 @@ static void patch_and_save_context(WinDumpHeader64 *h,
|
|||||||
uint64_t Context;
|
uint64_t Context;
|
||||||
WinContext ctx;
|
WinContext ctx;
|
||||||
|
|
||||||
if (cpu_memory_rw_debug(first_cpu,
|
if (cpu_read_ptr(x64, first_cpu,
|
||||||
KiProcessorBlock + i * sizeof(uint64_t),
|
KiProcessorBlock + i * win_dump_ptr_size(x64),
|
||||||
(uint8_t *)&Prcb, sizeof(Prcb), 0)) {
|
&Prcb)) {
|
||||||
error_setg(errp, "win-dump: failed to read"
|
error_setg(errp, "win-dump: failed to read"
|
||||||
" CPU #%d PRCB location", i);
|
" CPU #%d PRCB location", i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpu_memory_rw_debug(first_cpu,
|
if (cpu_read_ptr(x64, first_cpu,
|
||||||
Prcb + OffsetPrcbContext,
|
Prcb + OffsetPrcbContext,
|
||||||
(uint8_t *)&Context, sizeof(Context), 0)) {
|
&Context)) {
|
||||||
error_setg(errp, "win-dump: failed to read"
|
error_setg(errp, "win-dump: failed to read"
|
||||||
" CPU #%d ContextFrame location", i);
|
" CPU #%d ContextFrame location", i);
|
||||||
return;
|
return;
|
||||||
@ -240,8 +291,9 @@ static void patch_and_save_context(WinDumpHeader64 *h,
|
|||||||
|
|
||||||
saved_ctx[i].addr = Context;
|
saved_ctx[i].addr = Context;
|
||||||
|
|
||||||
ctx = (WinContext){
|
if (x64) {
|
||||||
.ContextFlags = WIN_CTX_ALL,
|
ctx.x64 = (WinContext64){
|
||||||
|
.ContextFlags = WIN_CTX64_ALL,
|
||||||
.MxCsr = env->mxcsr,
|
.MxCsr = env->mxcsr,
|
||||||
|
|
||||||
.SegEs = env->segs[0].selector,
|
.SegEs = env->segs[0].selector,
|
||||||
@ -281,15 +333,46 @@ static void patch_and_save_context(WinDumpHeader64 *h,
|
|||||||
.MxCsr = env->mxcsr,
|
.MxCsr = env->mxcsr,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
ctx.x32 = (WinContext32){
|
||||||
|
.ContextFlags = WIN_CTX32_FULL | WIN_CTX_DBG,
|
||||||
|
|
||||||
|
.SegEs = env->segs[0].selector,
|
||||||
|
.SegCs = env->segs[1].selector,
|
||||||
|
.SegSs = env->segs[2].selector,
|
||||||
|
.SegDs = env->segs[3].selector,
|
||||||
|
.SegFs = env->segs[4].selector,
|
||||||
|
.SegGs = env->segs[5].selector,
|
||||||
|
.EFlags = cpu_compute_eflags(env),
|
||||||
|
|
||||||
|
.Dr0 = env->dr[0],
|
||||||
|
.Dr1 = env->dr[1],
|
||||||
|
.Dr2 = env->dr[2],
|
||||||
|
.Dr3 = env->dr[3],
|
||||||
|
.Dr6 = env->dr[6],
|
||||||
|
.Dr7 = env->dr[7],
|
||||||
|
|
||||||
|
.Eax = env->regs[R_EAX],
|
||||||
|
.Ebx = env->regs[R_EBX],
|
||||||
|
.Ecx = env->regs[R_ECX],
|
||||||
|
.Edx = env->regs[R_EDX],
|
||||||
|
.Esp = env->regs[R_ESP],
|
||||||
|
.Ebp = env->regs[R_EBP],
|
||||||
|
.Esi = env->regs[R_ESI],
|
||||||
|
.Edi = env->regs[R_EDI],
|
||||||
|
|
||||||
|
.Eip = env->eip,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (cpu_memory_rw_debug(first_cpu, Context,
|
if (cpu_memory_rw_debug(first_cpu, Context,
|
||||||
(uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext), 0)) {
|
&saved_ctx[i].ctx, win_dump_ctx_size(x64), 0)) {
|
||||||
error_setg(errp, "win-dump: failed to save CPU #%d context", i);
|
error_setg(errp, "win-dump: failed to save CPU #%d context", i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpu_memory_rw_debug(first_cpu, Context,
|
if (cpu_memory_rw_debug(first_cpu, Context,
|
||||||
(uint8_t *)&ctx, sizeof(WinContext), 1)) {
|
&ctx, win_dump_ctx_size(x64), 1)) {
|
||||||
error_setg(errp, "win-dump: failed to write CPU #%d context", i);
|
error_setg(errp, "win-dump: failed to write CPU #%d context", i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -298,14 +381,14 @@ static void patch_and_save_context(WinDumpHeader64 *h,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void restore_context(WinDumpHeader64 *h,
|
static void restore_context(WinDumpHeader *h, bool x64,
|
||||||
struct saved_context *saved_ctx)
|
struct saved_context *saved_ctx)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < h->NumberProcessors; i++) {
|
for (i = 0; i < WIN_DUMP_FIELD(NumberProcessors); i++) {
|
||||||
if (cpu_memory_rw_debug(first_cpu, saved_ctx[i].addr,
|
if (cpu_memory_rw_debug(first_cpu, saved_ctx[i].addr,
|
||||||
(uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext), 1)) {
|
&saved_ctx[i].ctx, win_dump_ctx_size(x64), 1)) {
|
||||||
warn_report("win-dump: failed to restore CPU #%d context", i);
|
warn_report("win-dump: failed to restore CPU #%d context", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,69 +396,71 @@ static void restore_context(WinDumpHeader64 *h,
|
|||||||
|
|
||||||
void create_win_dump(DumpState *s, Error **errp)
|
void create_win_dump(DumpState *s, Error **errp)
|
||||||
{
|
{
|
||||||
WinDumpHeader64 *h = (WinDumpHeader64 *)(s->guest_note +
|
WinDumpHeader *h = (void *)(s->guest_note + VMCOREINFO_ELF_NOTE_HDR_SIZE);
|
||||||
VMCOREINFO_ELF_NOTE_HDR_SIZE);
|
|
||||||
X86CPU *first_x86_cpu = X86_CPU(first_cpu);
|
X86CPU *first_x86_cpu = X86_CPU(first_cpu);
|
||||||
uint64_t saved_cr3 = first_x86_cpu->env.cr[3];
|
uint64_t saved_cr3 = first_x86_cpu->env.cr[3];
|
||||||
struct saved_context *saved_ctx = NULL;
|
struct saved_context *saved_ctx = NULL;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
bool x64 = true;
|
||||||
|
size_t hdr_size;
|
||||||
|
|
||||||
if (s->guest_note_size != sizeof(WinDumpHeader64) +
|
if (s->guest_note_size != VMCOREINFO_WIN_DUMP_NOTE_SIZE32 &&
|
||||||
VMCOREINFO_ELF_NOTE_HDR_SIZE) {
|
s->guest_note_size != VMCOREINFO_WIN_DUMP_NOTE_SIZE64) {
|
||||||
error_setg(errp, "win-dump: invalid vmcoreinfo note size");
|
error_setg(errp, "win-dump: invalid vmcoreinfo note size");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
check_header(h, &local_err);
|
if (!check_header(h, &x64, &local_err)) {
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hdr_size = x64 ? sizeof(WinDumpHeader64) : sizeof(WinDumpHeader32);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Further access to kernel structures by virtual addresses
|
* Further access to kernel structures by virtual addresses
|
||||||
* should be made from system context.
|
* should be made from system context.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
first_x86_cpu->env.cr[3] = h->DirectoryTableBase;
|
first_x86_cpu->env.cr[3] = WIN_DUMP_FIELD(DirectoryTableBase);
|
||||||
|
|
||||||
check_kdbg(h, &local_err);
|
check_kdbg(h, x64, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
goto out_cr3;
|
goto out_cr3;
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_header(h);
|
patch_header(h, x64);
|
||||||
|
|
||||||
saved_ctx = g_new(struct saved_context, h->NumberProcessors);
|
saved_ctx = g_new(struct saved_context, WIN_DUMP_FIELD(NumberProcessors));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Always patch context because there is no way
|
* Always patch context because there is no way
|
||||||
* to determine if the system-saved context is valid
|
* to determine if the system-saved context is valid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
patch_and_save_context(h, saved_ctx, &local_err);
|
patch_and_save_context(h, x64, saved_ctx, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->total_size = h->RequiredDumpSpace;
|
s->total_size = WIN_DUMP_FIELD(RequiredDumpSpace);
|
||||||
|
|
||||||
s->written_size = qemu_write_full(s->fd, h, sizeof(*h));
|
s->written_size = qemu_write_full(s->fd, h, hdr_size);
|
||||||
if (s->written_size != sizeof(*h)) {
|
if (s->written_size != hdr_size) {
|
||||||
error_setg(errp, QERR_IO_ERROR);
|
error_setg(errp, QERR_IO_ERROR);
|
||||||
goto out_restore;
|
goto out_restore;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_runs(s, h, &local_err);
|
write_runs(s, h, x64, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
goto out_restore;
|
goto out_restore;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_restore:
|
out_restore:
|
||||||
restore_context(h, saved_ctx);
|
restore_context(h, x64, saved_ctx);
|
||||||
out_free:
|
out_free:
|
||||||
g_free(saved_ctx);
|
g_free(saved_ctx);
|
||||||
out_cr3:
|
out_cr3:
|
||||||
|
@ -1064,7 +1064,7 @@ ERST
|
|||||||
"-l: dump in kdump-compressed format, with lzo compression.\n\t\t\t"
|
"-l: dump in kdump-compressed format, with lzo compression.\n\t\t\t"
|
||||||
"-s: dump in kdump-compressed format, with snappy compression.\n\t\t\t"
|
"-s: dump in kdump-compressed format, with snappy compression.\n\t\t\t"
|
||||||
"-w: dump in Windows crashdump format (can be used instead of ELF-dump converting),\n\t\t\t"
|
"-w: dump in Windows crashdump format (can be used instead of ELF-dump converting),\n\t\t\t"
|
||||||
" for Windows x64 guests with vmcoreinfo driver only.\n\t\t\t"
|
" for Windows x86 and x64 guests with vmcoreinfo driver only.\n\t\t\t"
|
||||||
"begin: the starting physical address.\n\t\t\t"
|
"begin: the starting physical address.\n\t\t\t"
|
||||||
"length: the memory size, in bytes.",
|
"length: the memory size, in bytes.",
|
||||||
.cmd = hmp_dump_guest_memory,
|
.cmd = hmp_dump_guest_memory,
|
||||||
|
@ -11,11 +11,22 @@
|
|||||||
#ifndef QEMU_WIN_DUMP_DEFS_H
|
#ifndef QEMU_WIN_DUMP_DEFS_H
|
||||||
#define QEMU_WIN_DUMP_DEFS_H
|
#define QEMU_WIN_DUMP_DEFS_H
|
||||||
|
|
||||||
|
typedef struct WinDumpPhyMemRun32 {
|
||||||
|
uint32_t BasePage;
|
||||||
|
uint32_t PageCount;
|
||||||
|
} QEMU_PACKED WinDumpPhyMemRun32;
|
||||||
|
|
||||||
typedef struct WinDumpPhyMemRun64 {
|
typedef struct WinDumpPhyMemRun64 {
|
||||||
uint64_t BasePage;
|
uint64_t BasePage;
|
||||||
uint64_t PageCount;
|
uint64_t PageCount;
|
||||||
} QEMU_PACKED WinDumpPhyMemRun64;
|
} QEMU_PACKED WinDumpPhyMemRun64;
|
||||||
|
|
||||||
|
typedef struct WinDumpPhyMemDesc32 {
|
||||||
|
uint32_t NumberOfRuns;
|
||||||
|
uint32_t NumberOfPages;
|
||||||
|
WinDumpPhyMemRun32 Run[86];
|
||||||
|
} QEMU_PACKED WinDumpPhyMemDesc32;
|
||||||
|
|
||||||
typedef struct WinDumpPhyMemDesc64 {
|
typedef struct WinDumpPhyMemDesc64 {
|
||||||
uint32_t NumberOfRuns;
|
uint32_t NumberOfRuns;
|
||||||
uint32_t unused;
|
uint32_t unused;
|
||||||
@ -33,6 +44,39 @@ typedef struct WinDumpExceptionRecord {
|
|||||||
uint64_t ExceptionInformation[15];
|
uint64_t ExceptionInformation[15];
|
||||||
} QEMU_PACKED WinDumpExceptionRecord;
|
} QEMU_PACKED WinDumpExceptionRecord;
|
||||||
|
|
||||||
|
typedef struct WinDumpHeader32 {
|
||||||
|
char Signature[4];
|
||||||
|
char ValidDump[4];
|
||||||
|
uint32_t MajorVersion;
|
||||||
|
uint32_t MinorVersion;
|
||||||
|
uint32_t DirectoryTableBase;
|
||||||
|
uint32_t PfnDatabase;
|
||||||
|
uint32_t PsLoadedModuleList;
|
||||||
|
uint32_t PsActiveProcessHead;
|
||||||
|
uint32_t MachineImageType;
|
||||||
|
uint32_t NumberProcessors;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
uint32_t BugcheckCode;
|
||||||
|
uint32_t BugcheckParameter1;
|
||||||
|
uint32_t BugcheckParameter2;
|
||||||
|
uint32_t BugcheckParameter3;
|
||||||
|
uint32_t BugcheckParameter4;
|
||||||
|
};
|
||||||
|
uint8_t BugcheckData[20];
|
||||||
|
};
|
||||||
|
uint8_t VersionUser[32];
|
||||||
|
uint32_t reserved0;
|
||||||
|
uint32_t KdDebuggerDataBlock;
|
||||||
|
union {
|
||||||
|
WinDumpPhyMemDesc32 PhysicalMemoryBlock;
|
||||||
|
uint8_t PhysicalMemoryBlockBuffer[700];
|
||||||
|
};
|
||||||
|
uint8_t reserved1[3200];
|
||||||
|
uint32_t RequiredDumpSpace;
|
||||||
|
uint8_t reserved2[92];
|
||||||
|
} QEMU_PACKED WinDumpHeader32;
|
||||||
|
|
||||||
typedef struct WinDumpHeader64 {
|
typedef struct WinDumpHeader64 {
|
||||||
char Signature[4];
|
char Signature[4];
|
||||||
char ValidDump[4];
|
char ValidDump[4];
|
||||||
@ -81,24 +125,48 @@ typedef struct WinDumpHeader64 {
|
|||||||
uint8_t reserved[4018];
|
uint8_t reserved[4018];
|
||||||
} QEMU_PACKED WinDumpHeader64;
|
} QEMU_PACKED WinDumpHeader64;
|
||||||
|
|
||||||
|
typedef union WinDumpHeader {
|
||||||
|
struct {
|
||||||
|
char Signature[4];
|
||||||
|
char ValidDump[4];
|
||||||
|
};
|
||||||
|
WinDumpHeader32 x32;
|
||||||
|
WinDumpHeader64 x64;
|
||||||
|
} WinDumpHeader;
|
||||||
|
|
||||||
#define KDBG_OWNER_TAG_OFFSET64 0x10
|
#define KDBG_OWNER_TAG_OFFSET64 0x10
|
||||||
#define KDBG_MM_PFN_DATABASE_OFFSET64 0xC0
|
#define KDBG_MM_PFN_DATABASE_OFFSET64 0xC0
|
||||||
#define KDBG_KI_BUGCHECK_DATA_OFFSET64 0x88
|
#define KDBG_KI_BUGCHECK_DATA_OFFSET64 0x88
|
||||||
#define KDBG_KI_PROCESSOR_BLOCK_OFFSET64 0x218
|
#define KDBG_KI_PROCESSOR_BLOCK_OFFSET64 0x218
|
||||||
#define KDBG_OFFSET_PRCB_CONTEXT_OFFSET64 0x338
|
#define KDBG_OFFSET_PRCB_CONTEXT_OFFSET64 0x338
|
||||||
|
|
||||||
|
#define KDBG_OWNER_TAG_OFFSET KDBG_OWNER_TAG_OFFSET64
|
||||||
|
#define KDBG_MM_PFN_DATABASE_OFFSET KDBG_MM_PFN_DATABASE_OFFSET64
|
||||||
|
#define KDBG_KI_BUGCHECK_DATA_OFFSET KDBG_KI_BUGCHECK_DATA_OFFSET64
|
||||||
|
#define KDBG_KI_PROCESSOR_BLOCK_OFFSET KDBG_KI_PROCESSOR_BLOCK_OFFSET64
|
||||||
|
#define KDBG_OFFSET_PRCB_CONTEXT_OFFSET KDBG_OFFSET_PRCB_CONTEXT_OFFSET64
|
||||||
|
|
||||||
#define VMCOREINFO_ELF_NOTE_HDR_SIZE 24
|
#define VMCOREINFO_ELF_NOTE_HDR_SIZE 24
|
||||||
|
#define VMCOREINFO_WIN_DUMP_NOTE_SIZE64 (sizeof(WinDumpHeader64) + \
|
||||||
|
VMCOREINFO_ELF_NOTE_HDR_SIZE)
|
||||||
|
#define VMCOREINFO_WIN_DUMP_NOTE_SIZE32 (sizeof(WinDumpHeader32) + \
|
||||||
|
VMCOREINFO_ELF_NOTE_HDR_SIZE)
|
||||||
|
|
||||||
#define WIN_CTX_X64 0x00100000L
|
#define WIN_CTX_X64 0x00100000L
|
||||||
|
#define WIN_CTX_X86 0x00010000L
|
||||||
|
|
||||||
#define WIN_CTX_CTL 0x00000001L
|
#define WIN_CTX_CTL 0x00000001L
|
||||||
#define WIN_CTX_INT 0x00000002L
|
#define WIN_CTX_INT 0x00000002L
|
||||||
#define WIN_CTX_SEG 0x00000004L
|
#define WIN_CTX_SEG 0x00000004L
|
||||||
#define WIN_CTX_FP 0x00000008L
|
#define WIN_CTX_FP 0x00000008L
|
||||||
#define WIN_CTX_DBG 0x00000010L
|
#define WIN_CTX_DBG 0x00000010L
|
||||||
|
#define WIN_CTX_EXT 0x00000020L
|
||||||
|
|
||||||
#define WIN_CTX_FULL (WIN_CTX_X64 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX_FP)
|
#define WIN_CTX64_FULL (WIN_CTX_X64 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX_FP)
|
||||||
#define WIN_CTX_ALL (WIN_CTX_FULL | WIN_CTX_SEG | WIN_CTX_DBG)
|
#define WIN_CTX64_ALL (WIN_CTX64_FULL | WIN_CTX_SEG | WIN_CTX_DBG)
|
||||||
|
|
||||||
|
#define WIN_CTX32_FULL (WIN_CTX_X86 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX_SEG)
|
||||||
|
#define WIN_CTX32_ALL (WIN_CTX32_FULL | WIN_CTX_FP | WIN_CTX_DBG | WIN_CTX_EXT)
|
||||||
|
|
||||||
#define LIVE_SYSTEM_DUMP 0x00000161
|
#define LIVE_SYSTEM_DUMP 0x00000161
|
||||||
|
|
||||||
@ -107,7 +175,41 @@ typedef struct WinM128A {
|
|||||||
int64_t high;
|
int64_t high;
|
||||||
} QEMU_ALIGNED(16) WinM128A;
|
} QEMU_ALIGNED(16) WinM128A;
|
||||||
|
|
||||||
typedef struct WinContext {
|
typedef struct WinContext32 {
|
||||||
|
uint32_t ContextFlags;
|
||||||
|
|
||||||
|
uint32_t Dr0;
|
||||||
|
uint32_t Dr1;
|
||||||
|
uint32_t Dr2;
|
||||||
|
uint32_t Dr3;
|
||||||
|
uint32_t Dr6;
|
||||||
|
uint32_t Dr7;
|
||||||
|
|
||||||
|
uint8_t FloatSave[112];
|
||||||
|
|
||||||
|
uint32_t SegGs;
|
||||||
|
uint32_t SegFs;
|
||||||
|
uint32_t SegEs;
|
||||||
|
uint32_t SegDs;
|
||||||
|
|
||||||
|
uint32_t Edi;
|
||||||
|
uint32_t Esi;
|
||||||
|
uint32_t Ebx;
|
||||||
|
uint32_t Edx;
|
||||||
|
uint32_t Ecx;
|
||||||
|
uint32_t Eax;
|
||||||
|
|
||||||
|
uint32_t Ebp;
|
||||||
|
uint32_t Eip;
|
||||||
|
uint32_t SegCs;
|
||||||
|
uint32_t EFlags;
|
||||||
|
uint32_t Esp;
|
||||||
|
uint32_t SegSs;
|
||||||
|
|
||||||
|
uint8_t ExtendedRegisters[512];
|
||||||
|
} QEMU_ALIGNED(16) WinContext32;
|
||||||
|
|
||||||
|
typedef struct WinContext64 {
|
||||||
uint64_t PHome[6];
|
uint64_t PHome[6];
|
||||||
|
|
||||||
uint32_t ContextFlags;
|
uint32_t ContextFlags;
|
||||||
@ -174,6 +276,11 @@ typedef struct WinContext {
|
|||||||
uint64_t LastBranchFromRip;
|
uint64_t LastBranchFromRip;
|
||||||
uint64_t LastExceptionToRip;
|
uint64_t LastExceptionToRip;
|
||||||
uint64_t LastExceptionFromRip;
|
uint64_t LastExceptionFromRip;
|
||||||
} QEMU_ALIGNED(16) WinContext;
|
} QEMU_ALIGNED(16) WinContext64;
|
||||||
|
|
||||||
|
typedef union WinContext {
|
||||||
|
WinContext32 x32;
|
||||||
|
WinContext64 x64;
|
||||||
|
} WinContext;
|
||||||
|
|
||||||
#endif /* QEMU_WIN_DUMP_DEFS_H */
|
#endif /* QEMU_WIN_DUMP_DEFS_H */
|
||||||
|
@ -154,12 +154,15 @@ typedef struct DumpState {
|
|||||||
GuestPhysBlockList guest_phys_blocks;
|
GuestPhysBlockList guest_phys_blocks;
|
||||||
ArchDumpInfo dump_info;
|
ArchDumpInfo dump_info;
|
||||||
MemoryMappingList list;
|
MemoryMappingList list;
|
||||||
uint16_t phdr_num;
|
uint32_t phdr_num;
|
||||||
uint32_t sh_info;
|
uint32_t shdr_num;
|
||||||
bool have_section;
|
|
||||||
bool resume;
|
bool resume;
|
||||||
bool detached;
|
bool detached;
|
||||||
ssize_t note_size;
|
ssize_t note_size;
|
||||||
|
hwaddr shdr_offset;
|
||||||
|
hwaddr phdr_offset;
|
||||||
|
hwaddr section_offset;
|
||||||
|
hwaddr note_offset;
|
||||||
hwaddr memory_offset;
|
hwaddr memory_offset;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user