From patchwork Fri Sep 18 13:27:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 8781 Received: (qmail 8719 invoked by alias); 18 Sep 2015 13:27:40 -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 8708 invoked by uid 89); 18 Sep 2015 13:27:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com To: GNU C Library From: "Carlos O'Donell" Subject: [COMMITTED] Use ALIGN_* in _dl_map_object_from_fd. X-Enigmail-Draft-Status: N1110 Message-ID: <55FC1148.90300@redhat.com> Date: Fri, 18 Sep 2015 09:27:36 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 Cleanup _dl_map_object_from_fd to make it clear exactly what we're doing with the mappings i.e. extending the the start of the map down to a page boundary, extending the end of the map up to a page boundary, and offset itself also to page boundary. The result is much easier to read as expected from the ALIGN_* cleanups. 2015-09-18 Carlos O'Donell * elf/dl-load.c: Include libc-internal.h. (_dl_map_object_from_fd): Use ALIGN_UP and ALIGN_DOWN. --- Cheers, Carlos. diff --git a/elf/dl-load.c b/elf/dl-load.c index 0c052e4..993a419 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -1077,12 +1078,11 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp, } struct loadcmd *c = &loadcmds[nloadcmds++]; - c->mapstart = ph->p_vaddr & ~(GLRO(dl_pagesize) - 1); - c->mapend = ((ph->p_vaddr + ph->p_filesz + GLRO(dl_pagesize) - 1) - & ~(GLRO(dl_pagesize) - 1)); + c->mapstart = ALIGN_DOWN (ph->p_vaddr, GLRO(dl_pagesize)); + c->mapend = ALIGN_UP (ph->p_vaddr + ph->p_filesz, GLRO(dl_pagesize)); c->dataend = ph->p_vaddr + ph->p_filesz; c->allocend = ph->p_vaddr + ph->p_memsz; - c->mapoff = ph->p_offset & ~(GLRO(dl_pagesize) - 1); + c->mapoff = ALIGN_DOWN (ph->p_offset, GLRO(dl_pagesize)); /* Determine whether there is a gap between the last segment and this one. */