From: Dan Gohman Date: Mon, 11 Jul 2022 15:27:39 +0000 (-0700) Subject: Add a `getpagesize` function. (#300) X-Git-Url: https://git.proxmox.com/?p=wasi-libc.git;a=commitdiff_plain;h=e066a8b9d9c15e4c67fbcaeed3b62470f8785ce0 Add a `getpagesize` function. (#300) * Add a `getpagesize` function. This adds a `getpagesize` function. This interface is deprecated in POSIX, but it's sufficiently widely used and not problematic in practice. * Use musl's `getpagesize`. * Enable the `getpagesize` declaration in unistd.h. --- diff --git a/Makefile b/Makefile index 4341980..6eaf094 100644 --- a/Makefile +++ b/Makefile @@ -145,6 +145,7 @@ LIBC_TOP_HALF_MUSL_SOURCES = \ env/unsetenv.c \ unistd/posix_close.c \ stat/futimesat.c \ + legacy/getpagesize.c \ ) \ $(filter-out %/procfdname.c %/syscall.c %/syscall_ret.c %/vdso.c %/version.c, \ $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/*.c)) \ diff --git a/expected/wasm32-wasi/defined-symbols.txt b/expected/wasm32-wasi/defined-symbols.txt index 69242c7..40023d9 100644 --- a/expected/wasm32-wasi/defined-symbols.txt +++ b/expected/wasm32-wasi/defined-symbols.txt @@ -681,6 +681,7 @@ getline getopt getopt_long getopt_long_only +getpagesize getpid getrusage getsockopt diff --git a/libc-bottom-half/headers/public/__macro_PAGESIZE.h b/libc-bottom-half/headers/public/__macro_PAGESIZE.h index 0243c98..d892220 100644 --- a/libc-bottom-half/headers/public/__macro_PAGESIZE.h +++ b/libc-bottom-half/headers/public/__macro_PAGESIZE.h @@ -5,6 +5,11 @@ * The page size in WebAssembly is fixed at 64 KiB. If this ever changes, * it's expected that applications will need to opt in, so we can change * this. + * + * If this ever needs to be a value outside the range of an `int`, the + * `getpagesize` function which returns this value will need special + * consideration. POSIX has deprecated `getpagesize` in favor of + * `sysconf(_SC_PAGESIZE)` which does not have this problem. */ #define PAGESIZE (0x10000) diff --git a/libc-top-half/musl/include/unistd.h b/libc-top-half/musl/include/unistd.h index 9231d60..b5cb5c6 100644 --- a/libc-top-half/musl/include/unistd.h +++ b/libc-top-half/musl/include/unistd.h @@ -244,7 +244,9 @@ void *sbrk(intptr_t); pid_t vfork(void); int vhangup(void); int chroot(const char *); +#endif int getpagesize(void); +#ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ int getdtablesize(void); int sethostname(const char *, size_t); int getdomainname(char *, size_t);