[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 11/11 v10] introduce a new monitor command 'dump
From: |
Wen Congyang |
Subject: |
Re: [Qemu-devel] [PATCH 11/11 v10] introduce a new monitor command 'dump-guest-memory' to dump guest's memory |
Date: |
Mon, 26 Mar 2012 09:43:29 +0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 |
At 03/23/2012 05:00 PM, HATAYAMA Daisuke Wrote:
> From: Wen Congyang <address@hidden>
> Subject: [PATCH 11/11 v10] introduce a new monitor command
> 'dump-guest-memory' to dump guest's memory
> Date: Tue, 20 Mar 2012 11:57:43 +0800
>
>> +static int write_elf64_header(DumpState *s)
>> +{
>> + Elf64_Ehdr elf_header;
>> + int ret;
>> + int endian = s->dump_info.d_endian;
>> +
>> + memset(&elf_header, 0, sizeof(Elf64_Ehdr));
>> + memcpy(&elf_header, ELFMAG, 4);
>
> Use SELFMAG instead of 4.
Yes, SELFMAG is more readable than 4.
>
>> + elf_header.e_ident[EI_CLASS] = ELFCLASS64;
>> + elf_header.e_ident[EI_DATA] = s->dump_info.d_endian;
>> + elf_header.e_ident[EI_VERSION] = EV_CURRENT;
>> + elf_header.e_type = cpu_convert_to_target16(ET_CORE, endian);
>> + elf_header.e_machine = cpu_convert_to_target16(s->dump_info.d_machine,
>> + endian);
>> + elf_header.e_version = cpu_convert_to_target32(EV_CURRENT, endian);
>> + elf_header.e_ehsize = cpu_convert_to_target16(sizeof(elf_header),
>> endian);
>> + elf_header.e_phoff = cpu_convert_to_target64(sizeof(Elf64_Ehdr),
>> endian);
>> + elf_header.e_phentsize = cpu_convert_to_target16(sizeof(Elf64_Phdr),
>> + endian);
>> + elf_header.e_phnum = cpu_convert_to_target16(s->phdr_num, endian);
>> + if (s->have_section) {
>> + uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) *
>> s->sh_info;
>> +
>> + elf_header.e_shoff = cpu_convert_to_target64(shoff, endian);
>> + elf_header.e_shentsize = cpu_convert_to_target16(sizeof(Elf64_Shdr),
>> + endian);
>> + elf_header.e_shnum = cpu_convert_to_target16(1, endian);
>> + }
>> +
>> + ret = s->f(0, &elf_header, sizeof(elf_header), s->opaque);
>> + if (ret < 0) {
>> + dump_error(s, "dump: failed to write elf header.\n");
>> + return -1;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +static int write_elf32_header(DumpState *s)
>> +{
>> + Elf32_Ehdr elf_header;
>> + int ret;
>> + int endian = s->dump_info.d_endian;
>> +
>> + memset(&elf_header, 0, sizeof(Elf32_Ehdr));
>> + memcpy(&elf_header, ELFMAG, 4);
>
> Also.
I got it.
Thanks
Wen Congyang
>
>> + elf_header.e_ident[EI_CLASS] = ELFCLASS32;
>> + elf_header.e_ident[EI_DATA] = endian;
>> + elf_header.e_ident[EI_VERSION] = EV_CURRENT;
>> + elf_header.e_type = cpu_convert_to_target16(ET_CORE, endian);
>> + elf_header.e_machine = cpu_convert_to_target16(s->dump_info.d_machine,
>> + endian);
>> + elf_header.e_version = cpu_convert_to_target32(EV_CURRENT, endian);
>> + elf_header.e_ehsize = cpu_convert_to_target16(sizeof(elf_header),
>> endian);
>> + elf_header.e_phoff = cpu_convert_to_target32(sizeof(Elf32_Ehdr),
>> endian);
>> + elf_header.e_phentsize = cpu_convert_to_target16(sizeof(Elf32_Phdr),
>> + endian);
>> + elf_header.e_phnum = cpu_convert_to_target16(s->phdr_num, endian);
>> + if (s->have_section) {
>> + uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) *
>> s->sh_info;
>> +
>> + elf_header.e_shoff = cpu_convert_to_target32(shoff, endian);
>> + elf_header.e_shentsize = cpu_convert_to_target16(sizeof(Elf32_Shdr),
>> + endian);
>> + elf_header.e_shnum = cpu_convert_to_target16(1, endian);
>> + }
>> +
>> + ret = s->f(0, &elf_header, sizeof(elf_header), s->opaque);
>> + if (ret < 0) {
>> + dump_error(s, "dump: failed to write elf header.\n");
>> + return -1;
>> + }
>> +
>> + return 0;
>> +}
>
> Thanks.
> HATAYAMA, Daisuke
>
>