From patchwork Tue Feb 5 18:14:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1037044 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t9rHg/g/"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43vCzX4RG6z9s7h for ; Wed, 6 Feb 2019 05:39:36 +1100 (AEDT) Received: from localhost ([127.0.0.1]:37669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr5d8-0004Eb-J5 for incoming@patchwork.ozlabs.org; Tue, 05 Feb 2019 13:39:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr5GT-0002VH-Lv for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:16:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gr5GJ-0003qd-9a for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:16:05 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:39702) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gr5GJ-0003oT-04 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 13:15:59 -0500 Received: by mail-wm1-x331.google.com with SMTP id y8so4738880wmi.4 for ; Tue, 05 Feb 2019 10:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=sqwQPKdocbDxps8MVWl7rxABk3kmzXXc0ngmbIU+9XQ=; b=t9rHg/g//YP250aJK5GxRMc3e4JxzlQc0uUerxyo/qv4w/GTcoW5Z2O5f7AKrwyhE2 MUuKeOFOeyVkQ8qRbB2F0m4TprV9BCK0qqcVVNBuu/3ROaRRu6SZbauutYCjkrO41gZA sZJ97JGDfpvFsNWGVW1Ot9SZaRznad6117Okm5vROK/zvdGKDs8ynAK8ugIVEunlKZm0 2OYhbgTW5rVE9591pzQmg+YRH8nkn/VodAwAtszJw6keBHSTq025ubiqgnvPInWenl1v G0WV7YWYmlWH6KbTQ6NIh1Yzk5xz0ccnvczaItPLC5B2SgKafTVK6U7C7tKVKqYoDQc0 oxDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=sqwQPKdocbDxps8MVWl7rxABk3kmzXXc0ngmbIU+9XQ=; b=s0MyyHLjiRO1VeaBXwbhM3rx5tx4Z9meo/3JRJRNmaz42dJDLAIZkPZwsQ5P49SUD5 neA59NnxWRKKTHYS/lzO2pIWB8ePYvzOIDOhpaCxFE0tRDwoCxtaBYbfDJZ6i1hI+Irl nlvbBRnpRu8O3WtXeUDsEvhmFpTXMeO1NJdz5xpzdCUx1yJkFBP3y6SgcwP8Ko+E3Ui3 Q1zuATcE8n3eARaEnMTPvdJh5ew+zlRCwISN65k5ZLG10XyQZDwd+itDuMVglmunR9Qq Cp3+JXuP69GipAnqrtfWO79dfRPPi9N77mcG5ZyeKCX/KpLCAfuOR57hyMl0vyXbeHVu x07w== X-Gm-Message-State: AHQUAuZVZDUhTmITkCAchq4CxefOrg9Gb+G9849G/nVbPNJZlFYgtlGB oIsemM0CJfKcKQj5k6OXniRZt7dY X-Google-Smtp-Source: AHgI3IaxhSYgNNbZ4yrMSmansMOwWANzHF7Z/pXi8SWZg/ukIsBwoTlwA1wB0RooPR9tOLFCxffJUg== X-Received: by 2002:a1c:c181:: with SMTP id r123mr36712wmf.8.1549390557601; Tue, 05 Feb 2019 10:15:57 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id p5sm8931665wmh.16.2019.02.05.10.15.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 10:15:56 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 5 Feb 2019 19:14:38 +0100 Message-Id: <1549390526-24246-29-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549390526-24246-1-git-send-email-pbonzini@redhat.com> References: <1549390526-24246-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::331 Subject: [Qemu-devel] [PULL 28/76] contrib/elf2dmp: use GLib in PDB processing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viktor Prutyanov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Viktor Prutyanov Replace POSIX mmap with GLib g_mapped_file_new in PDB processing stage to make elf2dmp cross-platform. There are no direct POSIX in elf2dmp after this patch. Signed-off-by: Viktor Prutyanov Message-Id: <20181220012441.13694-4-viktor.prutyanov@phystech.edu> Signed-off-by: Paolo Bonzini --- contrib/elf2dmp/pdb.c | 29 ++++++++--------------------- contrib/elf2dmp/pdb.h | 2 +- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index bcb01b4..52e352d 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -277,28 +277,18 @@ static void pdb_reader_exit(struct pdb_reader *r) int pdb_init_from_file(const char *name, struct pdb_reader *reader) { + GError *gerr = NULL; int err = 0; - int fd; void *map; - struct stat st; - fd = open(name, O_RDONLY, 0); - if (fd == -1) { - eprintf("Failed to open PDB file \'%s\'\n", name); + reader->gmf = g_mapped_file_new(name, TRUE, &gerr); + if (gerr) { + eprintf("Failed to map PDB file \'%s\'\n", name); return 1; } - reader->fd = fd; - - fstat(fd, &st); - reader->file_size = st.st_size; - - map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (map == MAP_FAILED) { - eprintf("Failed to map PDB file\n"); - err = 1; - goto out_fd; - } + reader->file_size = g_mapped_file_get_length(reader->gmf); + map = g_mapped_file_get_contents(reader->gmf); if (pdb_reader_init(reader, map)) { err = 1; goto out_unmap; @@ -307,16 +297,13 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader) return 0; out_unmap: - munmap(map, st.st_size); -out_fd: - close(fd); + g_mapped_file_unref(reader->gmf); return err; } void pdb_exit(struct pdb_reader *reader) { - munmap(reader->ds.header, reader->file_size); - close(reader->fd); + g_mapped_file_unref(reader->gmf); pdb_reader_exit(reader); } diff --git a/contrib/elf2dmp/pdb.h b/contrib/elf2dmp/pdb.h index a3a3cac..1640d54 100644 --- a/contrib/elf2dmp/pdb.h +++ b/contrib/elf2dmp/pdb.h @@ -216,7 +216,7 @@ typedef struct pdb_seg { #define IMAGE_FILE_MACHINE_AMD64 0x8664 struct pdb_reader { - int fd; + GMappedFile *gmf; size_t file_size; struct { PDB_DS_HEADER *header;