From patchwork Thu Dec 20 01:24:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Prutyanov X-Patchwork-Id: 10738443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC1B56C5 for ; Thu, 20 Dec 2018 01:30:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA89B2863D for ; Thu, 20 Dec 2018 01:30:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE5E32863E; Thu, 20 Dec 2018 01:30:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 690982863C for ; Thu, 20 Dec 2018 01:30:23 +0000 (UTC) Received: from localhost ([::1]:34871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZnAM-0001Tl-Hi for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Dec 2018 20:30:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZn5b-0005ql-VF for qemu-devel@nongnu.org; Wed, 19 Dec 2018 20:25:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZn5X-00030N-Vs for qemu-devel@nongnu.org; Wed, 19 Dec 2018 20:25:27 -0500 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:33234) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gZn5W-0002gK-1f for qemu-devel@nongnu.org; Wed, 19 Dec 2018 20:25:23 -0500 Received: by mail-lj1-x244.google.com with SMTP id v1-v6so85893ljd.0 for ; Wed, 19 Dec 2018 17:25:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=phystech-edu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=50bkBNnopCIabFq0KYD4Rn26wGbOyf+b3JGsbOd950A=; b=L6KImHxU80Knpa+BdpZDfeDGTdWOb+L2UGFnB1ntXTeCrcCs2omFGThoutLkVyZHXP jJC+Qh0Mjp+q9AZWfW7mBnfbnzyYRQVl9SpvKjKJxtXKz0wn6xE0cCiWre8thtZo7qsT 29HFxqQy/CpRJZxwuy7fK6njp9hT5G0zBI3N9gMjmRoJVaTl4omG6HgmcIekGUSAxHfZ tSDqhbUX1wF5cIKp0bm1IJcJA5qM5ezgNf+9OgwU0I5tS13ovYRluzbw0PJPphd5ZdaW ssmse5jpqoEmdIaUlmC39cdnaj/sYd5xPGUPuHINFBNbKk9eFNrp4Tnh8Tx1HgCAAHjj MMqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=50bkBNnopCIabFq0KYD4Rn26wGbOyf+b3JGsbOd950A=; b=VkLnk05LFXmFZdLU6VnofG1g+1MIg/o7FG37rP0EhkxX0g/y79T+1uNvQAvmc6pP/7 PyBkTWXpvoYzQiqlNx3MhMHhy+YYdwxbjRQHw0QneR7MnM7F6eTZsKfXkpISofQHMELq dwbZe0nQ/H8MbYKoXHLI/8l0ppJrghY2zs7PHbeC+6Se9m9dGgo/o9L0vf51fpBpNDiU uihGP5WHRm7S+lukdRgZHgQYEimOIOrS67pIU+L0PFnHh1rWqB3QDv93b350mmwpF2oW +2+ne98JoktOVd7vu8D32xauo4BuHo0V6/yOT+8fOKYlYURx/0oH5GK5v04SBEaC5JSE Vfdw== X-Gm-Message-State: AA+aEWabDfBpIe2TBGfoKX0AktzIVYvyQfMtMcfwx7zGJeV/G1n3NSLy K4txgYZt8uKNuxNKNUBEzcNaAMmsJKAufA== X-Google-Smtp-Source: AFSGD/WtHFKoT8ZUNNsbNwIKEvzbbNuCTtC726bPFrW/AdjnkulR2L5YtlDLCg0Cupdly4Odba74sA== X-Received: by 2002:a05:651c:14e:: with SMTP id c14mr13279011ljd.20.1545269106308; Wed, 19 Dec 2018 17:25:06 -0800 (PST) Received: from localhost.localdomain ([93.175.11.132]) by smtp.gmail.com with ESMTPSA id z7-v6sm3737540lji.42.2018.12.19.17.25.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Dec 2018 17:25:05 -0800 (PST) From: Viktor Prutyanov To: pbonzini@redhat.com, rkagan@virtuozzo.com Date: Thu, 20 Dec 2018 04:24:38 +0300 Message-Id: <20181220012441.13694-4-viktor.prutyanov@phystech.edu> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181220012441.13694-1-viktor.prutyanov@phystech.edu> References: <20181220012441.13694-1-viktor.prutyanov@phystech.edu> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::244 Subject: [Qemu-devel] [PATCH v2 3/6] 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: qemu-devel@nongnu.org, Viktor Prutyanov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 bcb01b414f..52e352df79 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 4351a2dd61..8e395119d1 100644 --- a/contrib/elf2dmp/pdb.h +++ b/contrib/elf2dmp/pdb.h @@ -218,7 +218,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;