[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/9] mprotect: don’t assume pointers fit in long
From: |
Paul Eggert |
Subject: |
[PATCH 5/9] mprotect: don’t assume pointers fit in long |
Date: |
Fri, 14 Jun 2024 13:19:46 -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 | 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 <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):
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 <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(
--
2.45.2
- [PATCH 0/9] getpagesize simplifications etc., Paul Eggert, 2024/06/14
- [PATCH 3/9] getcwd: simplify abort bug checking, Paul Eggert, 2024/06/14
- [PATCH 4/9] memchr,strncat: prefer sysconf (_SC_PAGESIZE), Paul Eggert, 2024/06/14
- [PATCH 5/9] mprotect: don’t assume pointers fit in long,
Paul Eggert <=
- [PATCH 6/9] maint: avoid some test getpagesize dependencies, Paul Eggert, 2024/06/14
- [PATCH 8/9] sigsegv-tests: port to plain POSIX, Paul Eggert, 2024/06/14
- [PATCH 7/9] free-posix-tests: port to plain POSIX, Paul Eggert, 2024/06/14
- [PATCH 9/9] ssfmalloc-tests: simplify by using sysconf, Paul Eggert, 2024/06/14
- Re: [PATCH 0/9] getpagesize simplifications etc., Collin Funk, 2024/06/14