Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 May 2019 12:52:20 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r348161 - stable/12/libexec/rtld-elf
Message-ID:  <201905231252.x4NCqKiL088784@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Thu May 23 12:52:19 2019
New Revision: 348161
URL: https://svnweb.freebsd.org/changeset/base/348161

Log:
  MFC r347693:
  rtld_malloc.c: cleanup morepages().

Modified:
  stable/12/libexec/rtld-elf/rtld_malloc.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/libexec/rtld-elf/rtld_malloc.c
==============================================================================
--- stable/12/libexec/rtld-elf/rtld_malloc.c	Thu May 23 12:51:29 2019	(r348160)
+++ stable/12/libexec/rtld-elf/rtld_malloc.c	Thu May 23 12:52:19 2019	(r348161)
@@ -345,12 +345,11 @@ findbucket(union overhead *freep, int srchlen)
 static int
 morepages(int n)
 {
-	int	fd = -1;
-	int	offset;
+	caddr_t	addr;
+	int offset;
 
 	if (pagepool_end - pagepool_start > pagesz) {
-		caddr_t	addr = (caddr_t)
-			(((long)pagepool_start + pagesz - 1) & ~(pagesz - 1));
+		addr = (caddr_t)roundup2((long)pagepool_start, pagesz);
 		if (munmap(addr, pagepool_end - addr) != 0) {
 #ifdef IN_RTLD
 			rtld_fdprintf(STDERR_FILENO, _BASENAME_RTLD ": "
@@ -360,20 +359,21 @@ morepages(int n)
 		}
 	}
 
-	offset = (long)pagepool_start - ((long)pagepool_start & ~(pagesz - 1));
+	offset = (long)pagepool_start - rounddown2((long)pagepool_start,
+	    pagesz);
 
-	if ((pagepool_start = mmap(0, n * pagesz,
-			PROT_READ|PROT_WRITE,
-			MAP_ANON|MAP_PRIVATE, fd, 0)) == (caddr_t)-1) {
+	pagepool_start = mmap(0, n * pagesz, PROT_READ | PROT_WRITE,
+	    MAP_ANON | MAP_PRIVATE, -1, 0);
+	if (pagepool_start == MAP_FAILED) {
 #ifdef IN_RTLD
 		rtld_fdprintf(STDERR_FILENO, _BASENAME_RTLD ": morepages: "
 		    "cannot mmap anonymous memory: %s\n",
 		    rtld_strerror(errno));
 #endif
-		return 0;
+		return (0);
 	}
 	pagepool_end = pagepool_start + n * pagesz;
 	pagepool_start += offset;
 
-	return n;
+	return (n);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905231252.x4NCqKiL088784>