Received: from eggs.gnu.org ([208.118.235.92]:47917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SB0Ma-0005nV-Tj for qemu-devel@nongnu.org; Fri, 23 Mar 2012 05:00:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SB0MU-0005kx-QG for qemu-devel@nongnu.org; Fri, 23 Mar 2012 05:00:48 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:55398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SB0MU-0005kU-93 for qemu-devel@nongnu.org; Fri, 23 Mar 2012 05:00:42 -0400 Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id A6E293EE081 for ; Fri, 23 Mar 2012 18:00:38 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 86F0945DE56 for ; Fri, 23 Mar 2012 18:00:38 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 65CA045DE55 for ; Fri, 23 Mar 2012 18:00:38 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 58D741DB8048 for ; Fri, 23 Mar 2012 18:00:38 +0900 (JST) Received: from ml13.s.css.fujitsu.com (ml13.s.css.fujitsu.com [10.240.81.133]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 02D331DB804A for ; Fri, 23 Mar 2012 18:00:38 +0900 (JST) Date: Fri, 23 Mar 2012 18:00:23 +0900 ( ) Message-Id: <20120323.180023.276755898.d.hatayama@jp.fujitsu.com> From: HATAYAMA Daisuke In-Reply-To: <4F680037.9090101@cn.fujitsu.com> References: <4F680037.9090101@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 11/11 v10] introduce a new monitor command 'dump-guest-memory' to dump guest's memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: wency@cn.fujitsu.com Cc: jan.kiszka@siemens.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, anderson@redhat.com, anthony@codemonkey.ws, eblake@redhat.com From: Wen Congyang 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. > + 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. > + 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