From patchwork Sat Nov 21 00:33:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 547105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 683E7140273 for ; Sat, 21 Nov 2015 11:33:51 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=n/VPejLR; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; q= dns; s=default; b=FEtgMFg1UDBMYIyP8vvfz1ULYNgm7UH11DrqKm+tuEHpOQ JqZhFOaeDELNvv1ilyydxml6o4ajN1XHP58bwtq7QWIre/PfSH7dDpil3rIVHE2E bRoirDJXhnCCFsnHwMTarxCwervhX40HFJL+ghvYuM32266aIkVTZXNvceQdM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; s= default; bh=m/PDFogzwsgYuPWNQtAiNPE4ePQ=; b=n/VPejLRhhZwTX0+svW7 vKwnjLACvbiI5g/BV3SwQNdxN+Ts9gLENnkUlBJf4Hm9leMUU2M5zMBQ5hpbdOVV OoE5CWImy7JtAXZHMOaUWR9huusjY/mtW178ctZrID1SZQROaYAbaov7CS19deHP M0oMlB3OQsZ/RcqjITb7E+Y= Received: (qmail 97883 invoked by alias); 21 Nov 2015 00:33:45 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 97781 invoked by uid 89); 21 Nov 2015 00:33:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [COMMITTED PATCH] NaCl: Use allocate_code_data after dyncode_create Message-Id: <20151121003341.EFFF52C3B90@topped-with-meat.com> Date: Fri, 20 Nov 2015 16:33:41 -0800 (PST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=RZ8DVTdv c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=hOe2yjtxAAAA:8 a=kj9zAlcOel0A:10 a=yIXTruPRkBJoh_peyp0A:9 a=p5Q17y3ZYmzgjesh:21 a=hmYyV43cCn2l8LvA:21 a=CjuIK1q_8ugA:10 I'm committing this to both trunk and 2.22 now. It affects only NaCl users in the in-browser case, which has not really worked before now (hence no bugzilla item). Thanks, Roland 2015-11-20 Roland McGrath * sysdeps/nacl/dl-map-segments.h (_dl_map_segments): Use __glibc_likely instead of __builtin_expect. After falling back to dyncode_create in a non-ET_DYN case, use the allocate_code_data system interface to register the code pages as occupied. diff --git a/sysdeps/nacl/dl-map-segments.h b/sysdeps/nacl/dl-map-segments.h index f305da3..f2d5d84 100644 --- a/sysdeps/nacl/dl-map-segments.h +++ b/sysdeps/nacl/dl-map-segments.h @@ -53,7 +53,7 @@ _dl_map_segments (struct link_map *l, int fd, const size_t maplength, bool has_holes, struct link_map *loader) { - if (__builtin_expect (type, ET_DYN) == ET_DYN) + if (__glibc_likely (type == ET_DYN)) { /* This is a position-independent shared object. Let the system choose where to place it. @@ -165,6 +165,32 @@ _dl_map_segments (struct link_map *l, int fd, errno = error; return DL_MAP_SEGMENTS_ERROR_MAP_SEGMENT; } + if (__glibc_unlikely (type != ET_DYN)) + { + /* A successful PROT_EXEC mmap would have implicitly + updated the bookkeeping so that a future + allocate_code_data call would know that this range + of the address space is already occupied. That + doesn't happen implicitly with dyncode_create, so + it's necessary to do an explicit call to update the + bookkeeping. */ + uintptr_t allocated_address; + error = __nacl_irt_code_data_alloc.allocate_code_data + (l->l_addr + c->mapstart, len, 0, 0, &allocated_address); + if (__glibc_unlikely (error)) + { + errno = error; + return DL_MAP_SEGMENTS_ERROR_MAP_SEGMENT; + } + if (__glibc_unlikely + (allocated_address != l->l_addr + c->mapstart)) + { + /* This is not a very helpful error for this case, + but there isn't really anything better to use. */ + errno = ENOMEM; + return DL_MAP_SEGMENTS_ERROR_MAP_SEGMENT; + } + } } else {