From 541bf3e639457695effbc0598af67aff19da4b5e Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 16 Jan 2020 07:15:18 -0800 Subject: [PATCH 1/2] Improvements for detection of 64-bit support. Adds support for IBM s390x. Improves detection on Windows. Adds new `WC_USE_LIMITS_FOR_SIZEOF` option to use limits.h to detect sizeof long. Fixes #2600 and Fixes #2745. --- wolfssl/wolfcrypt/types.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index b25a57dc2..b72e19065 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -61,12 +61,22 @@ #endif - /* try to set SIZEOF_LONG or LONG_LONG if user didn't */ - #if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__) && !defined(__EMSCRIPTEN__) + /* try to set SIZEOF_LONG or SIZEOF_LONG_LONG if user didn't */ + #if defined(_MSC_VER) || defined(WC_USE_LIMITS_FOR_SIZEOF) + #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG) + #include + #if defined(ULONG_MAX) && (ULONG_MAX == 0xffffffffUL) + #define SIZEOF_LONG 4 + #endif + #if defined(ULLONG_MAX) && (ULLONG_MAX == 0xffffffffffffffffui64) + #define SIZEOF_LONG_LONG 8 + #endif + #endif + #elif !defined(__BCPLUSPLUS__) && !defined(__EMSCRIPTEN__) #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG) #if (defined(__alpha__) || defined(__ia64__) || \ defined(_ARCH_PPC64) || defined(__mips64) || \ - defined(__x86_64__) || \ + defined(__x86_64__) || defined(__s390x__ ) || \ ((defined(sun) || defined(__sun)) && \ (defined(LP64) || defined(_LP64)))) /* long should be 64bit */ @@ -104,7 +114,7 @@ /* These platforms have 64-bit CPU registers. */ #if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) || \ - defined(__aarch64__) || defined(__sparc64__) || \ + defined(__aarch64__) || defined(__sparc64__) || defined(__s390x__ ) || \ (defined(__riscv_xlen) && (__riscv_xlen == 64)) typedef word64 wolfssl_word; #define WC_64BIT_CPU From c38d5e9a290aa2fb42b3cab467afe8d901841b1e Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 16 Jan 2020 09:06:44 -0800 Subject: [PATCH 2/2] Further improved to use `HAVE_LIMITS_H` and `ULL` instead of `ui64` --- wolfssl/wolfcrypt/types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index b72e19065..299b4c628 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -62,13 +62,13 @@ /* try to set SIZEOF_LONG or SIZEOF_LONG_LONG if user didn't */ - #if defined(_MSC_VER) || defined(WC_USE_LIMITS_FOR_SIZEOF) + #if defined(_MSC_VER) || defined(HAVE_LIMITS_H) #if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG) #include #if defined(ULONG_MAX) && (ULONG_MAX == 0xffffffffUL) #define SIZEOF_LONG 4 #endif - #if defined(ULLONG_MAX) && (ULLONG_MAX == 0xffffffffffffffffui64) + #if defined(ULLONG_MAX) && (ULLONG_MAX == 0xffffffffffffffffULL) #define SIZEOF_LONG_LONG 8 #endif #endif