From patchwork Wed Jun 20 17:28:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rabin Vincent X-Patchwork-Id: 166137 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 12711B6F9F for ; Thu, 21 Jun 2012 06:00:36 +1000 (EST) Received: from localhost ([::1]:50440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShQR3-0006AB-Kl for incoming@patchwork.ozlabs.org; Wed, 20 Jun 2012 15:19:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShOi4-0001cT-4f for qemu-devel@nongnu.org; Wed, 20 Jun 2012 13:28:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ShOi2-0000Zz-FA for qemu-devel@nongnu.org; Wed, 20 Jun 2012 13:28:51 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:49585) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ShOi2-0000We-6a for qemu-devel@nongnu.org; Wed, 20 Jun 2012 13:28:50 -0400 Received: by pbbro12 with SMTP id ro12so930857pbb.4 for ; Wed, 20 Jun 2012 10:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=fxw93tetmS3xGJW305PYERaPC299E5YEWM8Fjy/n9FE=; b=Zcb/i122KwvYQt1gJ7pwkozc6onQ5Z4+NiQXT7Tv8TqhOrbrNzQ5OwYSReplB1X6Rv 45yXvqc7l8TR0fYZQWO3F2KhztaKXDrBqjMOvm/ZfJRJ7x5of6lo1hK4zwOzLzf2UHep I6W59t3W/fbuZXxyz6dLB2I6eZIzsyM6zMClZnWSwXNg6a7dNgqKj5bTobNZDzrkHyV5 GSdq1HZhqwGzbA/Hi4vq7FiCKV9TnJbO669vF+X/7q47fLcwXhLYWlQcOgHHRJ6lpuOP uIUZWB9RG8hyJLf55WyxoRabLao5seKTBU2vQWnBhDudx7f/X2KERb49TpFeLvJiTqml MMdQ== Received: by 10.68.195.97 with SMTP id id1mr79337749pbc.91.1340213326996; Wed, 20 Jun 2012 10:28:46 -0700 (PDT) Received: from localhost.localdomain ([122.181.16.2]) by mx.google.com with ESMTPS id qa5sm2955103pbb.19.2012.06.20.10.28.43 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Jun 2012 10:28:44 -0700 (PDT) From: Rabin Vincent To: qemu-devel@nongnu.org Date: Wed, 20 Jun 2012 22:58:22 +0530 Message-Id: <1340213303-596-3-git-send-email-rabin@rab.in> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1340213303-596-1-git-send-email-rabin@rab.in> References: <1340213303-596-1-git-send-email-rabin@rab.in> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 X-Mailman-Approved-At: Wed, 20 Jun 2012 15:19:10 -0400 Cc: Rabin Vincent Subject: [Qemu-devel] [PATCH 3/4] dump: extract out get note size function 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 Extract out the ELF note size function from i386 so we can use it from other targets. Signed-off-by: Rabin Vincent --- dump.c | 15 +++++++++++++++ dump.h | 2 ++ target-i386/arch_dump.c | 14 ++------------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/dump.c b/dump.c index be96c6c..d3ca953 100644 --- a/dump.c +++ b/dump.c @@ -468,6 +468,21 @@ static target_phys_addr_t get_offset(target_phys_addr_t phys_addr, return -1; } +size_t dump_get_note_size(int class, const char *name, size_t descsz) +{ + int name_size = strlen(name) + 1; + int note_head_size; + + if (class == ELFCLASS32) { + note_head_size = sizeof(Elf32_Nhdr); + } else { + note_head_size = sizeof(Elf64_Nhdr); + } + + return ((note_head_size + 3) / 4 + (name_size + 3) / 4 + + (descsz + 3) / 4) * 4; +} + int dump_write_elf_note(int class, const char *name, uint32_t type, void *desc, size_t descsz, write_core_dump_function f, void *opaque) diff --git a/dump.h b/dump.h index b07816a..a06b149 100644 --- a/dump.h +++ b/dump.h @@ -36,4 +36,6 @@ int dump_write_elf_note(int class, const char *name, uint32_t type, void *desc, size_t descsz, write_core_dump_function f, void *opaque); +size_t dump_get_note_size(int class, const char *name, size_t descsz); + #endif diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c index dbc94bc..e2d18a0 100644 --- a/target-i386/arch_dump.c +++ b/target-i386/arch_dump.c @@ -305,18 +305,10 @@ int cpu_get_dump_info(ArchDumpInfo *info) ssize_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); @@ -328,10 +320,8 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) #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; + elf_note_size = dump_get_note_size(class, "CORE", elf_desc_size); + qemu_note_size = dump_get_note_size(class, "QEMU", qemu_desc_size); return (elf_note_size + qemu_note_size) * nr_cpus; }