From 4de08398ac52a0e1cdfbc1457cf7df95b8ddadea Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sat, 4 Mar 2023 14:11:09 +0700 Subject: [PATCH 1/2] Unix: Use sysconf(_SC_PAGESIZE), not getpagesize() The `getpagesize()` is a legacy function and is not available in the default configurations on some platforms. The documentation for `getpagesize()` recommends using the POSIX `sysconf(_SC_PAGESIZE)` instead. Additionally, `sysconf(_SC_PAGESIZE)` returns a `long` rather than an `int`, so the code is updated to handle that as well. Sources: * https://man7.org/linux/man-pages/man2/getpagesize.2.html * https://pubs.opengroup.org/onlinepubs/7908799/xsh/getpagesize.html --- code/vmix.c | 6 +++--- design/vm.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/vmix.c b/code/vmix.c index 167ab614fa..7ac3b873e5 100644 --- a/code/vmix.c +++ b/code/vmix.c @@ -50,7 +50,7 @@ #include /* sig_atomic_t */ #include /* see .feature.li in config.h */ #include /* mmap, munmap */ -#include /* getpagesize */ +#include /* sysconf, _SC_PAGESIZE */ SRCID(vmix, "$Id$"); @@ -59,10 +59,10 @@ SRCID(vmix, "$Id$"); Size PageSize(void) { - int pageSize; + long pageSize; /* Find out the operating system page size */ - pageSize = getpagesize(); + pageSize = sysconf(_SC_PAGESIZE); /* Check the page size will fit in a Size. */ AVER((unsigned long)pageSize <= (unsigned long)(Size)-1); diff --git a/design/vm.txt b/design/vm.txt index f4bc2e4588..de370ca45d 100644 --- a/design/vm.txt +++ b/design/vm.txt @@ -269,7 +269,7 @@ Unix implementation _`.impl.ix`: In ``vmix.c``. -_`.impl.ix.page.size`: The page size is given by ``getpagesize()``. +_`.impl.ix.page.size`: The page size is given by ``sysconf(_SC_PAGESIZE)``. _`.impl.ix.param`: Decodes no keyword arguments. From 2191f3c75df254ca272a0ce9e417983d31424a95 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Sat, 4 Mar 2023 07:56:29 +0000 Subject: [PATCH 2/2] Documenting deprecation of getpagesize(). --- code/vmix.c | 3 ++- design/vm.txt | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/code/vmix.c b/code/vmix.c index 7ac3b873e5..4bdd0caefa 100644 --- a/code/vmix.c +++ b/code/vmix.c @@ -61,7 +61,8 @@ Size PageSize(void) { long pageSize; - /* Find out the operating system page size */ + /* Find out the operating system page size + (see design.mps.vm.impl.ix.page.size) */ pageSize = sysconf(_SC_PAGESIZE); /* Check the page size will fit in a Size. */ diff --git a/design/vm.txt b/design/vm.txt index de370ca45d..457959b83c 100644 --- a/design/vm.txt +++ b/design/vm.txt @@ -269,7 +269,13 @@ Unix implementation _`.impl.ix`: In ``vmix.c``. -_`.impl.ix.page.size`: The page size is given by ``sysconf(_SC_PAGESIZE)``. +_`.impl.ix.page.size`: The page size is given by +``sysconf(_SC_PAGESIZE)``. We avoid ``getpagesize()``, which is a +legacy function in Posix: + + Applications should use the sysconf() function instead. + + — `The Single UNIX ® Specification, Version 2 `__ _`.impl.ix.param`: Decodes no keyword arguments.