From patchwork Wed Apr 18 12:57:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 153502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2DD72B6F9A for ; Wed, 18 Apr 2012 22:54:19 +1000 (EST) Received: from localhost ([::1]:40340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKUOm-0001Nl-Nh for incoming@patchwork.ozlabs.org; Wed, 18 Apr 2012 08:54:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKUOX-0001Lg-IS for qemu-devel@nongnu.org; Wed, 18 Apr 2012 08:54:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKUOS-0006fj-Nw for qemu-devel@nongnu.org; Wed, 18 Apr 2012 08:54:01 -0400 Received: from [222.73.24.84] (port=47157 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKUOS-0006fF-6N for qemu-devel@nongnu.org; Wed, 18 Apr 2012 08:53:56 -0400 X-IronPort-AV: E=Sophos;i="4.75,441,1330876800"; d="scan'208";a="4783523" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 18 Apr 2012 20:53:33 +0800 Received: from mailserver.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id q3ICrq41020676; Wed, 18 Apr 2012 20:53:52 +0800 Received: from [10.167.225.226] ([10.167.225.226]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012041820525849-62344 ; Wed, 18 Apr 2012 20:52:58 +0800 Message-ID: <4F8EBA20.7060500@cn.fujitsu.com> Date: Wed, 18 Apr 2012 20:57:04 +0800 From: Wen Congyang 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 MIME-Version: 1.0 To: qemu-devel , HATAYAMA Daisuke , Luiz Capitulino , "Daniel P. Berrange" References: <4F8EB840.90108@cn.fujitsu.com> In-Reply-To: <4F8EB840.90108@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/04/18 20:52:58, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/04/18 20:52:58, Serialize complete at 2012/04/18 20:52:58 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [PATCH 10/12 v13] target-i386: Add API to get note's size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We should know where the note and memory is stored before writing them to vmcore. If we know this, we can avoid using lseek() when creating vmcore. Signed-off-by: Wen Congyang --- cpu-all.h | 6 ++++++ target-i386/arch_dump.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 1a1a06d..5c9838d 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -555,6 +555,7 @@ int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env, int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env, void *opaque); int cpu_get_dump_info(ArchDumpInfo *info); +size_t cpu_get_note_size(int class, int machine, int nr_cpus); #else static inline int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env, int cpuid, @@ -588,6 +589,11 @@ static inline int cpu_get_dump_info(ArchDumpInfo *info) { return -1; } + +static inline int cpu_get_note_size(int class, int machine, int nr_cpus) +{ + return -1; +} #endif #endif /* CPU_ALL_H */ diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c index e378579..135d855 100644 --- a/target-i386/arch_dump.c +++ b/target-i386/arch_dump.c @@ -414,3 +414,36 @@ int cpu_get_dump_info(ArchDumpInfo *info) return 0; } + +size_t cpu_get_note_size(int class, int machine, int nr_cpus) +{ + int name_size = 5; /* "CORE" or "QEMU" */ + size_t elf_note_size = 0; + size_t qemu_note_size = 0; + int elf_desc_size = 0; + int qemu_desc_size = 0; + int note_head_size; + + if (class == ELFCLASS32) { + note_head_size = sizeof(Elf32_Nhdr); + } else { + note_head_size = sizeof(Elf64_Nhdr); + } + + if (machine == EM_386) { + elf_desc_size = sizeof(x86_elf_prstatus); + } +#ifdef TARGET_X86_64 + else { + elf_desc_size = sizeof(x86_64_elf_prstatus); + } +#endif + qemu_desc_size = sizeof(QEMUCPUState); + + elf_note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 + + (elf_desc_size + 3) / 4) * 4; + qemu_note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 + + (qemu_desc_size + 3) / 4) * 4; + + return (elf_note_size + qemu_note_size) * nr_cpus; +}