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: case ORIOS_WRITE:
{ {
const unsigned char *req; 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) { if (reqLen <= 0) {
WOLFSSL_MSG("wolfSSL_BIO_get_mem_data error"); WOLFSSL_MSG("wolfSSL_BIO_get_mem_data error");
return WOLFSSL_FAILURE; return WOLFSSL_FAILURE;
@@ -1710,7 +1711,8 @@ int wolfSSL_OCSP_sendreq_nbio(OcspResponse **presp, WOLFSSL_OCSP_REQ_CTX *ctx)
if (ret != WOLFSSL_SUCCESS) if (ret != WOLFSSL_SUCCESS)
return ret; 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) if (len <= 0)
return WOLFSSL_FAILURE; return WOLFSSL_FAILURE;
return wolfSSL_d2i_OCSP_RESPONSE(presp, &resp, len) != NULL 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 */ mem->free_func(ret); /* never a stack so we can call this directly */
return NULL; return NULL;
} }
*len -= (tmp - *src); *len -= (long)(tmp - *src);
*src = tmp; *src = tmp;
return ret; return ret;
} }
@@ -586,7 +586,7 @@ static void* d2i_generic(const WOLFSSL_ASN1_TEMPLATE* mem,
WOLFSSL_MSG("ptr not advanced enough"); WOLFSSL_MSG("ptr not advanced enough");
goto error; goto error;
} }
*len -= tmp - *src; *len -= (long)(tmp - *src);
*src = tmp; *src = tmp;
return ret; return ret;
error: error:

View File

@@ -7174,9 +7174,9 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
#else #else
#define CAN_GET_SIZE(...) 0 #define CAN_GET_SIZE() 0
#define CAN_WRITE(...) 0 #define CAN_WRITE() 0
#define CAN_PARSE(...) 0 #define CAN_PARSE() 0
#endif #endif
@@ -14764,7 +14764,7 @@ static word16 TLSX_GetMinSize_Client(word16* type)
} }
#define TLSX_GET_MIN_SIZE_CLIENT TLSX_GetMinSize_Client #define TLSX_GET_MIN_SIZE_CLIENT TLSX_GetMinSize_Client
#else #else
#define TLSX_GET_MIN_SIZE_CLIENT(...) 0 #define TLSX_GET_MIN_SIZE_CLIENT() 0
#endif #endif
@@ -14833,7 +14833,7 @@ static word16 TLSX_GetMinSize_Server(const word16 *type)
} }
#define TLSX_GET_MIN_SIZE_SERVER TLSX_GetMinSize_Server #define TLSX_GET_MIN_SIZE_SERVER TLSX_GetMinSize_Server
#else #else
#define TLSX_GET_MIN_SIZE_SERVER(...) 0 #define TLSX_GET_MIN_SIZE_SERVER() 0
#endif #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. */ /* Copy it in, decrement available space. */
XSTRNCPY(dst, pfx, bytes_left); XSTRNCPY(dst, pfx, bytes_left);
dst += XSTRLEN(pfx); dst += XSTRLEN(pfx);
total_len += XSTRLEN(pfx); total_len += (int)XSTRLEN(pfx);
bytes_left -= XSTRLEN(pfx); bytes_left -= (int)XSTRLEN(pfx);
if (fld_len > bytes_left) { if (fld_len > bytes_left) {
/* Not enough space left. */ /* Not enough space left. */

View File

@@ -3604,7 +3604,8 @@ time_t stm32_hal_time(time_t *t1)
#endif /* !NO_ASN_TIME */ #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) char* mystrnstr(const char* s1, const char* s2, unsigned int n)
{ {
unsigned int s2_len = (unsigned int)XSTRLEN(s2); 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, ...); WOLFSSL_API void WOLFSSL_MSG_EX(const char* fmt, ...);
#define HAVE_WOLFSSL_MSG_EX #define HAVE_WOLFSSL_MSG_EX
#else #else
#define WOLFSSL_MSG_EX(...) WC_DO_NOTHING #define WOLFSSL_MSG_EX() WC_DO_NOTHING
#endif #endif
WOLFSSL_API void WOLFSSL_MSG(const char* msg); WOLFSSL_API void WOLFSSL_MSG(const char* msg);
#ifdef WOLFSSL_DEBUG_CODEPOINTS #ifdef WOLFSSL_DEBUG_CODEPOINTS

View File

@@ -1358,10 +1358,13 @@
#define NO_SESSION_CACHE #define NO_SESSION_CACHE
#endif #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) && \ #if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \
!defined(FREERTOS_TCP) && !defined(EBSNET) && !defined(WOLFSSL_EROAD) && \ !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 #define USE_WINDOWS_API
#endif #endif

View File

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

View File

@@ -182,7 +182,10 @@ decouple library dependencies with standard string, memory and so on.
#endif #endif
#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 WORD64_AVAILABLE
#define W64LIT(x) x##ui64 #define W64LIT(x) x##ui64
#define SW64LIT(x) x##i64 #define SW64LIT(x) x##i64
@@ -379,8 +382,8 @@ typedef struct w64wrapper {
#endif #endif
/* set up rotate style */ /* set up rotate style */
#if (defined(_MSC_VER) || defined(__BCPLUSPLUS__)) && \ #if ((defined(_MSC_VER) && !defined(WOLFSSL_NOT_WINDOWS_API)) || \
!defined(WOLFSSL_SGX) && !defined(INTIME_RTOS) defined(__BCPLUSPLUS__)) && !defined(WOLFSSL_SGX) && !defined(INTIME_RTOS)
#define INTEL_INTRINSICS #define INTEL_INTRINSICS
#define FAST_ROTATE #define FAST_ROTATE
#elif defined(__MWERKS__) && TARGET_CPU_PPC #elif defined(__MWERKS__) && TARGET_CPU_PPC
@@ -428,16 +431,6 @@ typedef struct w64wrapper {
#define FALL_THROUGH #define FALL_THROUGH
#endif #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 XSTR_SIZEOF(x) (sizeof(x) - 1) /* -1 to not count the null char */
#define XELEM_CNT(x) (sizeof((x))/sizeof(*(x))) #define XELEM_CNT(x) (sizeof((x))/sizeof(*(x)))
@@ -1757,7 +1750,11 @@ typedef struct w64wrapper {
#endif #endif
#ifndef SAVE_VECTOR_REGISTERS #ifndef SAVE_VECTOR_REGISTERS
#ifdef __WATCOMC__
#define SAVE_VECTOR_REGISTERS() WC_DO_NOTHING
#else
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING #define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#endif
#endif #endif
#ifndef SAVE_VECTOR_REGISTERS2 #ifndef SAVE_VECTOR_REGISTERS2
#define SAVE_VECTOR_REGISTERS2() 0 #define SAVE_VECTOR_REGISTERS2() 0

View File

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