More fixes for building x86 in Visual Studio for non-windows OS (Watcom C compiler). Followup to PR #7884. Fixes ZD 18465

* Consolidate the USE_WINDOWS_API to a single place.
* Expand the `WOLFSSL_NOT_WINDOWS_API` improvement for intrinsics and word sizes.
* Fix for macro variadic `...` when no variables are used (some compilers like Watcom C have issue with this).
* Fix for Watcom C compiler "long long" -> "__int64".
* Fix a couple of minor cast warnings reported from VS.
This commit is contained in:
David Garske
2024-10-29 11:50:24 -07:00
parent 57a5895d0e
commit 84b5d6613d
10 changed files with 52 additions and 35 deletions

View File

@ -1634,7 +1634,8 @@ int wolfSSL_OCSP_REQ_CTX_nbio(WOLFSSL_OCSP_REQ_CTX *ctx)
case ORIOS_WRITE:
{
const unsigned char *req;
int reqLen = wolfSSL_BIO_get_mem_data(ctx->reqResp, &req);
int reqLen = wolfSSL_BIO_get_mem_data(ctx->reqResp,
(unsigned char*)&req);
if (reqLen <= 0) {
WOLFSSL_MSG("wolfSSL_BIO_get_mem_data error");
return WOLFSSL_FAILURE;
@ -1710,7 +1711,8 @@ int wolfSSL_OCSP_sendreq_nbio(OcspResponse **presp, WOLFSSL_OCSP_REQ_CTX *ctx)
if (ret != WOLFSSL_SUCCESS)
return ret;
len = wolfSSL_BIO_get_mem_data(ctx->reqResp, &resp);
len = wolfSSL_BIO_get_mem_data(ctx->reqResp,
(unsigned char*)&resp);
if (len <= 0)
return WOLFSSL_FAILURE;
return wolfSSL_d2i_OCSP_RESPONSE(presp, &resp, len) != NULL

View File

@ -456,7 +456,7 @@ static void* d2i_obj(const WOLFSSL_ASN1_TEMPLATE* mem, const byte** src,
mem->free_func(ret); /* never a stack so we can call this directly */
return NULL;
}
*len -= (tmp - *src);
*len -= (long)(tmp - *src);
*src = tmp;
return ret;
}
@ -586,7 +586,7 @@ static void* d2i_generic(const WOLFSSL_ASN1_TEMPLATE* mem,
WOLFSSL_MSG("ptr not advanced enough");
goto error;
}
*len -= tmp - *src;
*len -= (long)(tmp - *src);
*src = tmp;
return ret;
error:

View File

@ -7174,9 +7174,9 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
#else
#define CAN_GET_SIZE(...) 0
#define CAN_WRITE(...) 0
#define CAN_PARSE(...) 0
#define CAN_GET_SIZE() 0
#define CAN_WRITE() 0
#define CAN_PARSE() 0
#endif
@ -14764,7 +14764,7 @@ static word16 TLSX_GetMinSize_Client(word16* type)
}
#define TLSX_GET_MIN_SIZE_CLIENT TLSX_GetMinSize_Client
#else
#define TLSX_GET_MIN_SIZE_CLIENT(...) 0
#define TLSX_GET_MIN_SIZE_CLIENT() 0
#endif
@ -14833,7 +14833,7 @@ static word16 TLSX_GetMinSize_Server(const word16 *type)
}
#define TLSX_GET_MIN_SIZE_SERVER TLSX_GetMinSize_Server
#else
#define TLSX_GET_MIN_SIZE_SERVER(...) 0
#define TLSX_GET_MIN_SIZE_SERVER() 0
#endif

View File

@ -5926,8 +5926,8 @@ static int X509PrintDirType(char * dst, int max_len, const DNS_entry * entry)
/* Copy it in, decrement available space. */
XSTRNCPY(dst, pfx, bytes_left);
dst += XSTRLEN(pfx);
total_len += XSTRLEN(pfx);
bytes_left -= XSTRLEN(pfx);
total_len += (int)XSTRLEN(pfx);
bytes_left -= (int)XSTRLEN(pfx);
if (fld_len > bytes_left) {
/* Not enough space left. */

View File

@ -3604,7 +3604,8 @@ time_t stm32_hal_time(time_t *t1)
#endif /* !NO_ASN_TIME */
#if !defined(WOLFSSL_LEANPSK) && !defined(STRING_USER)
#if (!defined(WOLFSSL_LEANPSK) && !defined(STRING_USER)) || \
defined(USE_WOLF_STRNSTR)
char* mystrnstr(const char* s1, const char* s2, unsigned int n)
{
unsigned int s2_len = (unsigned int)XSTRLEN(s2);

View File

@ -178,7 +178,7 @@ WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix);
WOLFSSL_API void WOLFSSL_MSG_EX(const char* fmt, ...);
#define HAVE_WOLFSSL_MSG_EX
#else
#define WOLFSSL_MSG_EX(...) WC_DO_NOTHING
#define WOLFSSL_MSG_EX() WC_DO_NOTHING
#endif
WOLFSSL_API void WOLFSSL_MSG(const char* msg);
#ifdef WOLFSSL_DEBUG_CODEPOINTS

View File

@ -1358,10 +1358,13 @@
#define NO_SESSION_CACHE
#endif
/* Micrium will use Visual Studio for compilation but not the Win32 API */
/* For platforms where the target OS is not Windows, but compilation is
* done on Windows/Visual Studio, enable a way to disable USE_WINDOWS_API.
* Examples: Micrium, TenAsus INtime, uTasker, FreeRTOS simulator */
#if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \
!defined(FREERTOS_TCP) && !defined(EBSNET) && !defined(WOLFSSL_EROAD) && \
!defined(WOLFSSL_UTASKER) && !defined(INTIME_RTOS)
!defined(WOLFSSL_UTASKER) && !defined(INTIME_RTOS) && \
!defined(WOLFSSL_NOT_WINDOWS_API)
#define USE_WINDOWS_API
#endif

View File

@ -31,6 +31,7 @@ This library provides single precision (SP) integer math functions.
#include <limits.h>
#endif
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/hash.h>
#ifdef __cplusplus
@ -100,6 +101,15 @@ extern "C" {
#error "Size of unsigned int not detected"
#endif
#if defined(__WATCOMC__) && defined(__WATCOM_INT64__)
/* For older Watcom C compiler force types */
#define SP_ULLONG_BITS 64
typedef unsigned __int64 sp_uint64;
typedef __int64 sp_int64;
#else
/* 32-bit type */
#if defined(WOLF_C89) && !defined(NO_64BIT) && \
ULONG_MAX == 18446744073709551615UL
#define SP_ULONG_BITS 64
@ -108,8 +118,8 @@ extern "C" {
typedef long sp_int64;
#elif !defined(WOLF_C89) && !defined(NO_64BIT) && \
ULONG_MAX == 18446744073709551615ULL && \
4294967295UL != 18446744073709551615ULL /* verify pre-processor supports
* 64-bit ULL types */
/* sanity check pre-processor supports 64-bit ULL types */ \
4294967295UL != 18446744073709551615ULL
#define SP_ULONG_BITS 64
typedef unsigned long sp_uint64;
@ -132,6 +142,7 @@ extern "C" {
#error "Size of unsigned long not detected"
#endif
/* 64-bit type */
#ifdef ULLONG_MAX
#if defined(WOLF_C89) && ULLONG_MAX == 18446744073709551615UL
#define SP_ULLONG_BITS 64
@ -165,6 +176,7 @@ extern "C" {
#error "Size of unsigned long long not detected"
#endif
#elif (SP_ULONG_BITS == 32) && !defined(NO_64BIT)
#define SP_ULLONG_BITS 64
/* Speculatively use long long as the 64-bit type as we don't have one
* otherwise. */
typedef unsigned long long sp_uint64;
@ -173,6 +185,7 @@ extern "C" {
#define SP_ULLONG_BITS 0
#endif
#endif /* __WATCOMC__ */
#ifdef WOLFSSL_SP_DIV_32
#define WOLFSSL_SP_DIV_WORD_HALF

View File

@ -182,7 +182,10 @@ decouple library dependencies with standard string, memory and so on.
#endif
#endif
#if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
#if (defined(_MSC_VER) && !defined(WOLFSSL_NOT_WINDOWS_API)) || \
defined(__BCPLUSPLUS__) || \
(defined(__WATCOMC__) && defined(__WATCOM_INT64__))
/* windows types */
#define WORD64_AVAILABLE
#define W64LIT(x) x##ui64
#define SW64LIT(x) x##i64
@ -379,8 +382,8 @@ typedef struct w64wrapper {
#endif
/* set up rotate style */
#if (defined(_MSC_VER) || defined(__BCPLUSPLUS__)) && \
!defined(WOLFSSL_SGX) && !defined(INTIME_RTOS)
#if ((defined(_MSC_VER) && !defined(WOLFSSL_NOT_WINDOWS_API)) || \
defined(__BCPLUSPLUS__)) && !defined(WOLFSSL_SGX) && !defined(INTIME_RTOS)
#define INTEL_INTRINSICS
#define FAST_ROTATE
#elif defined(__MWERKS__) && TARGET_CPU_PPC
@ -428,16 +431,6 @@ typedef struct w64wrapper {
#define FALL_THROUGH
#endif
/* For platforms where the target OS is not Windows, but compilation is
* done on Windows/Visual Studio, enable a way to disable USE_WINDOWS_API.
* Examples: Micrium, TenAsus INtime, uTasker, FreeRTOS simulator */
#if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \
!defined(FREERTOS_TCP) && !defined(EBSNET) && \
!defined(WOLFSSL_UTASKER) && !defined(INTIME_RTOS) && \
!defined(WOLFSSL_NOT_WINDOWS_API)
#define USE_WINDOWS_API
#endif
#define XSTR_SIZEOF(x) (sizeof(x) - 1) /* -1 to not count the null char */
#define XELEM_CNT(x) (sizeof((x))/sizeof(*(x)))
@ -1757,8 +1750,12 @@ typedef struct w64wrapper {
#endif
#ifndef SAVE_VECTOR_REGISTERS
#ifdef __WATCOMC__
#define SAVE_VECTOR_REGISTERS() WC_DO_NOTHING
#else
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#endif
#endif
#ifndef SAVE_VECTOR_REGISTERS2
#define SAVE_VECTOR_REGISTERS2() 0
#define SAVE_VECTOR_REGISTERS2_DOES_NOTHING

View File

@ -75,7 +75,7 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef WOLFSSL_SGX
#if !defined(WOLFSSL_SGX) && !defined(WOLFSSL_NOT_WINDOWS_API)
#if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
/* On WinCE winsock2.h must be included before windows.h */
#include <winsock2.h>
@ -346,7 +346,7 @@
#define WOLFSSL_ATOMIC_OPS
#endif /* WOLFSSL_HAVE_ATOMIC_H */
#endif
#elif defined(_MSC_VER)
#elif defined(_MSC_VER) && !defined(WOLFSSL_NOT_WINDOWS_API)
/* Use MSVC compiler intrinsics for atomic ops */
#ifdef _WIN32_WCE
#include <armintr.h>
@ -1273,7 +1273,8 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
#endif /* !NO_ASN_TIME */
#ifndef WOLFSSL_LEANPSK
#if (!defined(WOLFSSL_LEANPSK) && !defined(STRING_USER)) || \
defined(USE_WOLF_STRNSTR)
char* mystrnstr(const char* s1, const char* s2, unsigned int n);
#endif