From c61c9821e8417243a5a0cf691415f5e5626f2b3b Mon Sep 17 00:00:00 2001 From: kinichiro Date: Wed, 15 Mar 2017 21:02:22 +0900 Subject: [PATCH] Add support for getpagesize --- .gitignore | 1 + crypto/CMakeLists.txt | 4 ++++ crypto/Makefile.am | 4 ++++ crypto/compat/getpagesize.c | 18 ++++++++++++++++++ include/compat/unistd.h | 4 ++++ m4/check-libc.m4 | 3 ++- 6 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 crypto/compat/getpagesize.c diff --git a/.gitignore b/.gitignore index 5543d7a..052804e 100644 --- a/.gitignore +++ b/.gitignore @@ -142,6 +142,7 @@ include/openssl/*.h !/crypto/compat/arc4random.h !/crypto/compat/b_win.c !/crypto/compat/explicit_bzero_win.c +!/crypto/compat/getpagesize.c !/crypto/compat/posix_win.c !/crypto/compat/bsd_asprintf.c !/crypto/compat/inet_pton.c diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index cda4fb3..e36004a 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -681,6 +681,10 @@ if(NOT HAVE_ASPRINTF) set(EXTRA_EXPORT ${EXTRA_EXPORT} vasprintf) endif() +if(NOT HAVE_GETPAGESIZE) + set(CRYPTO_SRC ${CRYPTO_SRC} compat/getpagesize.c) +endif() + if(NOT HAVE_INET_PTON) set(CRYPTO_SRC ${CRYPTO_SRC} compat/inet_pton.c) set(EXTRA_EXPORT ${EXTRA_EXPORT} inet_pton) diff --git a/crypto/Makefile.am b/crypto/Makefile.am index 78f3dd8..dc94a8c 100644 --- a/crypto/Makefile.am +++ b/crypto/Makefile.am @@ -81,6 +81,10 @@ if !HAVE_ASPRINTF libcompat_la_SOURCES += compat/bsd-asprintf.c endif +if !HAVE_GETPAGESIZE +libcompat_la_SOURCES += compat/getpagesize.c +endif + if !HAVE_INET_PTON libcompat_la_SOURCES += compat/inet_pton.c endif diff --git a/crypto/compat/getpagesize.c b/crypto/compat/getpagesize.c new file mode 100644 index 0000000..098efa9 --- /dev/null +++ b/crypto/compat/getpagesize.c @@ -0,0 +1,18 @@ +/* $OpenBSD$ */ + +#include + +#ifdef _MSC_VER +#include +#endif + +int +getpagesize(void) { +#ifdef _MSC_VER + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + return system_info.dwPageSize; +#else + return sysconf(_SC_PAGESIZE); +#endif +} diff --git a/include/compat/unistd.h b/include/compat/unistd.h index b37a2f6..d596043 100644 --- a/include/compat/unistd.h +++ b/include/compat/unistd.h @@ -39,6 +39,10 @@ int getentropy(void *buf, size_t buflen); #endif #endif +#ifndef HAVE_GETPAGESIZE +int getpagesize(void); +#endif + #define pledge(request, paths) 0 #ifndef HAVE_PIPE2 diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 22f0b35..e61d412 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 @@ -2,11 +2,12 @@ AC_DEFUN([CHECK_LIBC_COMPAT], [ # Check for libc headers AC_CHECK_HEADERS([err.h readpassphrase.h]) # Check for general libc functions -AC_CHECK_FUNCS([asprintf inet_ntop inet_pton memmem readpassphrase]) +AC_CHECK_FUNCS([asprintf getpagesize inet_ntop inet_pton memmem readpassphrase]) AC_CHECK_FUNCS([reallocarray recallocarray]) AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) AC_CHECK_FUNCS([timegm _mkgmtime]) AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) +AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes]) AM_CONDITIONAL([HAVE_INET_NTOP], [test "x$ac_cv_func_inet_ntop" = xyes]) AM_CONDITIONAL([HAVE_INET_PTON], [test "x$ac_cv_func_inet_pton" = xyes]) AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])