]> Savannah Git Hosting - gnulib.git/commitdiff
mprotect: don’t assume pointers fit in long
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 14 Jun 2024 17:47:06 +0000 (10:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 14 Jun 2024 20:19:03 +0000 (13:19 -0700)
* 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
m4/mprotect.m4

index d1939c141814d126f1c2a3841acdc60acefeba95..690c886f784c9e4f2c54a04c21d8d2b5013da504 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2024-06-14  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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):
index 536f2ad09435243f526826911c958d6f4a562e16..f0968b413e7c1a11d9fb0958dcb7995a83b41b44 100644 (file)
@@ -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 <sys/types.h>
            /* Declare malloc().  */
            #include <stdlib.h>
-           /* Declare getpagesize().  */
-           #if HAVE_UNISTD_H
-            #include <unistd.h>
-           #endif
-           #ifdef __hpux
-            extern
-            #ifdef __cplusplus
-            "C"
-            #endif
-            int getpagesize (void);
-           #endif
+           /* Declare sysconf().  */
+           #include <unistd.h>
            /* Declare mprotect().  */
            #include <sys/mman.h>
            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(