Skip to content

Commit

Permalink
More fixes for building x86 in Visual Studio for non-windows OS (Watc…
Browse files Browse the repository at this point in the history
…om 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.
  • Loading branch information
dgarske committed Oct 29, 2024
1 parent 57a5895 commit 84b5d66
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 35 deletions.
6 changes: 4 additions & 2 deletions src/ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ssl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions src/x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
3 changes: 2 additions & 1 deletion wolfcrypt/src/wc_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/wolfcrypt/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions wolfssl/wolfcrypt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 17 additions & 4 deletions wolfssl/wolfcrypt/sp_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ This library provides single precision (SP) integer math functions.
#ifndef WOLFSSL_LINUXKM
#include <limits.h>
#endif
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/hash.h>
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/hash.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
23 changes: 10 additions & 13 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -1757,7 +1750,11 @@ 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
Expand Down
7 changes: 4 additions & 3 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 84b5d66

Please sign in to comment.