From 6691dd2aa6348a9901023eee51de535b4e698b5b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 14 Jun 2024 10:47:06 -0700 Subject: [PATCH] =?utf8?q?mprotect:=20don=E2=80=99t=20assume=20pointers=20?= =?utf8?q?fit=20in=20long?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * m4/mprotect.m4 (gl_FUNC_MPROTECT_WORKS): Don’t assume pointers fit into unsigned long, as this is not true on CheriBSD. Prefer sysconf (_SC_PAGESIZE) to getpagesize. --- ChangeLog | 5 +++++ m4/mprotect.m4 | 24 ++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index d1939c1418..690c886f78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2024-06-14 Paul Eggert + mprotect: don’t assume pointers fit in long + * m4/mprotect.m4 (gl_FUNC_MPROTECT_WORKS): Don’t assume pointers + fit into unsigned long, as this is not true on CheriBSD. Prefer + sysconf (_SC_PAGESIZE) to getpagesize. + memchr,strncat: prefer sysconf (_SC_PAGESIZE) * m4/memchr.m4 (gl_FUNC_MEMCHR): * m4/strncat.m4 (gl_FUNC_STRNCAT): diff --git a/m4/mprotect.m4 b/m4/mprotect.m4 index 536f2ad094..f0968b413e 100644 --- a/m4/mprotect.m4 +++ b/m4/mprotect.m4 @@ -1,5 +1,5 @@ # mprotect.m4 -# serial 3 +# serial 4 dnl Copyright (C) 1993-2024 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License as published by the Free Software Foundation; @@ -25,24 +25,20 @@ AC_DEFUN([gl_FUNC_MPROTECT_WORKS], #include /* Declare malloc(). */ #include - /* Declare getpagesize(). */ - #if HAVE_UNISTD_H - #include - #endif - #ifdef __hpux - extern - #ifdef __cplusplus - "C" - #endif - int getpagesize (void); - #endif + /* Declare sysconf(). */ + #include /* Declare mprotect(). */ #include char foo; + static unsigned long int pagesize; + static char * + page_align (char *address) + { + return address - ((unsigned long int) address & (pagesize - 1)); + } int main () { - unsigned long pagesize = getpagesize (); - #define page_align(address) (char*)((unsigned long)(address) & -pagesize) + pagesize = sysconf (_SC_PAGESIZE); ' no_mprotect= AC_RUN_IFELSE( -- 2.39.5