Skip to content

Commit 179341b

Browse files
committed
Merging branch/2023-03-04/getpagesize-vs-sysconf for GitHub pull request #188 <#188>.
2 parents 5fba2a8 + 2191f3c commit 179341b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

code/vmix.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include <signal.h> /* sig_atomic_t */
5151
#include <sys/mman.h> /* see .feature.li in config.h */
5252
#include <sys/types.h> /* mmap, munmap */
53-
#include <unistd.h> /* getpagesize */
53+
#include <unistd.h> /* sysconf, _SC_PAGESIZE */
5454

5555
SRCID(vmix, "$Id$");
5656

@@ -59,10 +59,11 @@ SRCID(vmix, "$Id$");
5959

6060
Size PageSize(void)
6161
{
62-
int pageSize;
62+
long pageSize;
6363

64-
/* Find out the operating system page size */
65-
pageSize = getpagesize();
64+
/* Find out the operating system page size
65+
(see design.mps.vm.impl.ix.page.size) */
66+
pageSize = sysconf(_SC_PAGESIZE);
6667

6768
/* Check the page size will fit in a Size. */
6869
AVER((unsigned long)pageSize <= (unsigned long)(Size)-1);

design/vm.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,13 @@ Unix implementation
269269

270270
_`.impl.ix`: In ``vmix.c``.
271271

272-
_`.impl.ix.page.size`: The page size is given by ``getpagesize()``.
272+
_`.impl.ix.page.size`: The page size is given by
273+
``sysconf(_SC_PAGESIZE)``. We avoid ``getpagesize()``, which is a
274+
legacy function in Posix:
275+
276+
Applications should use the sysconf() function instead.
277+
278+
— `The Single UNIX ® Specification, Version 2 <https://pubs.opengroup.org/onlinepubs/7908799/xsh/getpagesize.html>`__
273279

274280
_`.impl.ix.param`: Decodes no keyword arguments.
275281

0 commit comments

Comments
 (0)