diff mbox series

[v2] Prepare for the addition of the <sys/pagesize.h> header

Message ID 875xqagb5o.fsf@oldenburg.str.redhat.com
State New
Headers show
Series [v2] Prepare for the addition of the <sys/pagesize.h> header | expand

Commit Message

Florian Weimer Oct. 2, 2024, 8:29 a.m. UTC
Add a stub version of <bits/pagesize.h>.  This header is similar to
<bits/wordsize.h> in that every port must define its own version.

Add <sys/pagesize.h>, which will become the installed version
of this header.  PAGE_SIZE_MIN and PAGE_SIZE_MAX have type long
int, so that roundup (offset, PAGE_SIZE_MAX) gives the correct
result if offset has type off64_t on 32-bit architectures.
(With an unsigned type for PAGE_SIZE_MAX, the roundup macro
does not work as expected if the first argument is wider than
the second argument.)

---
v2: Change the type of the PAGE_SIZE_MIN, PAGE_SIZE_MAX to long int.
 bits/pagesize.h        | 10 ++++++++++
 include/sys/pagesize.h |  1 +
 misc/sys/pagesize.h    | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)


base-commit: a652eef605a5e3513246cf75af278955df6d022b

Comments

Paul Eggert Oct. 4, 2024, 12:13 a.m. UTC | #1
Thanks, this looks good.

Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>
diff mbox series

Patch

diff --git a/bits/pagesize.h b/bits/pagesize.h
new file mode 100644
index 0000000000..d83561d0c1
--- /dev/null
+++ b/bits/pagesize.h
@@ -0,0 +1,10 @@ 
+#error "This file must be written based on the possible page sizes"
+
+/* 1 << __GLIBC_PAGE_SHIFT_MIN is the minimum possible page size.
+   The least significant __GLIBC_PAGE_SHIFT_MIN bits of pointers
+   return by mmap are guaranteed to be cleared.  */
+#define __GLIBC_PAGE_SHIFT_MIN
+
+/* 1 << __GLIBC_PAGE_SHIFT_MAX is the maximum possible page size.
+   On-disk file formats must not require smaller mapping offsets.  */
+#define __GLIBC_PAGE_SHIFT_MAX
diff --git a/include/sys/pagesize.h b/include/sys/pagesize.h
new file mode 100644
index 0000000000..2533ee7e90
--- /dev/null
+++ b/include/sys/pagesize.h
@@ -0,0 +1 @@ 
+#include <misc/sys/pagesize.h>
diff --git a/misc/sys/pagesize.h b/misc/sys/pagesize.h
new file mode 100644
index 0000000000..e806c711bd
--- /dev/null
+++ b/misc/sys/pagesize.h
@@ -0,0 +1,32 @@ 
+/* Information about supported page sizes.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _SYS_PAGESIZE_H
+#define _SYS_PAGESIZE_H
+
+#include <bits/pagesize.h>
+
+/* Minimum and maximum possible page sizes, in bytes.  */
+#define PAGE_SIZE_MIN (1L << __GLIBC_PAGE_SHIFT_MIN)
+#define PAGE_SIZE_MAX (1L << __GLIBC_PAGE_SHIFT_MAX)
+
+/* Base-2 logarithm of the size limits.  */
+#define PAGE_SHIFT_MIN __GLIBC_PAGE_SHIFT_MIN
+#define PAGE_SHIFT_MAX __GLIBC_PAGE_SHIFT_MAX
+
+#endif /* _SYS_PAGESIZE_H */