From patchwork Fri May 10 07:15:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1097861 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=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 450hTV3nWDz9s9y for ; Fri, 10 May 2019 17:21:18 +1000 (AEST) Received: from localhost ([127.0.0.1]:38234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOzqG-0000iz-Dr for incoming@patchwork.ozlabs.org; Fri, 10 May 2019 03:21:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOzlS-0005mo-IC for qemu-devel@nongnu.org; Fri, 10 May 2019 03:16:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOzlR-0001jv-Jc for qemu-devel@nongnu.org; Fri, 10 May 2019 03:16:18 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:52555) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOzlR-0001jB-Ag for qemu-devel@nongnu.org; Fri, 10 May 2019 03:16:17 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MaIvT-1hAT2I1WKb-00WH7u; Fri, 10 May 2019 09:16:07 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 09:15:55 +0200 Message-Id: <20190510071557.30126-6-laurent@vivier.eu> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190510071557.30126-1-laurent@vivier.eu> References: <20190510071557.30126-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:h4K/Muix8nnOwDYsE8KmBPWIKOFAWv/R08FoTG5nkbPg0twbLH6 ts2MLG4HJ1ZvWs03fnf9VgPT3dijKAW2YyN0w7rgXLp4pY1C+CnXZZaaLZBz7MRN1ebK5dq GoxIiCSj2m4YdZJq+YIZiPhKugG+Hj2k31o0uNHhX5Hu3m6bnjamu6ybvzGTXUualvlpk25 jzNI6RHaMfPjCF0yZBBzQ== X-UI-Out-Filterresults: notjunk:1; V03:K0:NSI+UmOAKto=:Xt4sAnAwAyhn6puOUhOoZA M2u/+iDSCiv9xbq6DgTqlguI4bbX7RcmHmCqZzwFUkqVZ0MmKGs5ozti1+GcqH6nB6Qixb7q3 D3hnYHpV7pDGUqTt2iPG6Bqhp/mbEolhpTuA2RdyofqWtoikIbqTBPyVDibS5rqBe8lvFX214 NgMSuw8NVU8nJ5G6cH58XNBzaNS+QWNCuMb5gLhPo0HH1xoso8dsuliGgEt61Z+pq0dr8hh1P YTWIeEt4I1omTQzeViPP+T7x3k3irqf9+m9LanWgrTxN8BqDcMUtMjRxwabyHwCN9sezGUr6B fFWt6U+A4y6mksvsOCBBiiCPANVAh6JO5TsSAj+uBis/pdVcxELdrun5hI+B195ja6Yb9aAnC 33UAoox80w8ck1K4cSlweiCZ8sIV8euQBZ164oZJrL9ZN6euYZsTZGDveDC/N0rq0Ou5AlEys zq4XAjPJE50AasaA4nzYee7l5VAMLR3A6skZlQxg026TZ9ZgJcTYTZHRlJQdEN6c2hPHOTOjV CfBIcbm3UoKTrwcnCMUdpo4rkmNKTxpk+YuwS2SIuFjUPUojhHVoef3grol3p9LNUgeLRaWXw 0VIIVH3njBuGKZ20BdbE5ARsnREd96n9EIZhjqE/eCIB/yzrkjK20abL7PRqOTFu8A8byIuTM KYZnqlDHbOCsfJVsnWB+zE3YPF52wRGK/gkVQ0i0I+O8LOCh85ivING5BmgB9X/tNf+tVRcB2 cAr5KtAB5bFyFcWuqUUqoVds2UNS/Us2Jru43w== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.13 Subject: [Qemu-devel] [PULL 5/7] linux-user: elf: Map empty PT_LOAD segments 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: Giuseppe Musacchio , Peter Maydell , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Giuseppe Musacchio Some PT_LOAD segments may be completely zeroed out and their p_filesize is zero, in that case the loader should just allocate a page that's at least p_memsz bytes large (plus eventual alignment padding). Calling zero_bss does this job for us, all we have to do is make sure we don't try to mmap a zero-length page. Signed-off-by: Giuseppe Musacchio Reviewed-by: Peter Maydell Message-Id: <20190503122007.lkjsvztgt4ycovac@debian> Signed-off-by: Laurent Vivier --- linux-user/elfload.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d08fe2346683..ef42e02d8233 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2366,11 +2366,19 @@ static void load_elf_image(const char *image_name, int image_fd, vaddr_ps = TARGET_ELF_PAGESTART(vaddr); vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); - error = target_mmap(vaddr_ps, vaddr_len, - elf_prot, MAP_PRIVATE | MAP_FIXED, - image_fd, eppnt->p_offset - vaddr_po); - if (error == -1) { - goto exit_perror; + /* + * Some segments may be completely empty without any backing file + * segment, in that case just let zero_bss allocate an empty buffer + * for it. + */ + if (eppnt->p_filesz != 0) { + error = target_mmap(vaddr_ps, vaddr_len, elf_prot, + MAP_PRIVATE | MAP_FIXED, + image_fd, eppnt->p_offset - vaddr_po); + + if (error == -1) { + goto exit_perror; + } } vaddr_ef = vaddr + eppnt->p_filesz;