Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Nov 2023 17:16:09 GMT
From:      Brooks Davis <brooks@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: ea180bb3797e - main - getpagesize(3): drop support for non-ELF kernels
Message-ID:  <202311281716.3ASHG9Dv095321@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=ea180bb3797ed4e976adccfba7d09c154d3244d1

commit ea180bb3797ed4e976adccfba7d09c154d3244d1
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2023-11-27 17:06:25 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2023-11-28 17:09:26 +0000

    getpagesize(3): drop support for non-ELF kernels
    
    AT_PAGESZ was introduced with ELF support in 1996 (commit
    e1743d02cd14069f69a50bb8a6c626c1c6f47ddd) so we can safely count on
    being able to use it to get our page size via elf_aux_info().  As such
    we don't need a fallback sysctl query.
    
    Save a few bytes of bss by dropping caching as elf_aux_info() runs
    in constant time for a given query.
    
    Reviewed by:    kevans, imp, emaste
    Sponsored by:   DARPA
    Differential Revision:  https://reviews.freebsd.org/D42708
---
 lib/libc/gen/getpagesize.c | 28 ++++------------------------
 1 file changed, 4 insertions(+), 24 deletions(-)

diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c
index 5fe9a965385f..23d2c6ea5eda 100644
--- a/lib/libc/gen/getpagesize.c
+++ b/lib/libc/gen/getpagesize.c
@@ -30,18 +30,11 @@
  */
 
 #include <sys/param.h>
-#include <sys/sysctl.h>
-
-#include <errno.h>
-#include <link.h>
-#include <unistd.h>
+#include <sys/auxv.h>
 
 #include "libc_private.h"
 
 /*
- * This is unlikely to change over the running time of any
- * program, so we cache the result to save some syscalls.
- *
  * NB: This function may be called from malloc(3) at initialization
  * NB: so must not result in a malloc(3) related call!
  */
@@ -49,23 +42,10 @@
 int
 getpagesize(void)
 {
-	int mib[2];
-	static int value;
-	size_t size;
-	int error;
-
-	if (value != 0)
-		return (value);
-
-	error = _elf_aux_info(AT_PAGESZ, &value, sizeof(value));
-	if (error == 0 && value != 0)
-		return (value);
+	int value;
 
-	mib[0] = CTL_HW;
-	mib[1] = HW_PAGESIZE;
-	size = sizeof value;
-	if (sysctl(mib, nitems(mib), &value, &size, NULL, 0) == -1)
-		return (PAGE_SIZE);
+	if (_elf_aux_info(AT_PAGESZ, &value, sizeof(value)) != 0)
+		value = PAGE_SIZE;
 
 	return (value);
 }



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