Skip to content

Commit

Permalink
Merge pull request #8098 from dgarske/x86_notwindows_2
Browse files Browse the repository at this point in the history
More fixes for building x86 in Visual Studio for non-windows OS
  • Loading branch information
douzzer authored Nov 5, 2024
2 parents 92f7e91 + aad0f6e commit 8ecf064
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ 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, (void*)&req);
if (reqLen <= 0) {
WOLFSSL_MSG("wolfSSL_BIO_get_mem_data error");
return WOLFSSL_FAILURE;
Expand Down Expand Up @@ -1710,7 +1710,7 @@ 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, (void*)&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
21 changes: 11 additions & 10 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -7168,15 +7168,16 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
return 0;
}

#define CAN_GET_SIZE TLSX_CA_Names_GetSize
#define CAN_WRITE TLSX_CA_Names_Write
#define CAN_PARSE TLSX_CA_Names_Parse
#define CAN_GET_SIZE(data) TLSX_CA_Names_GetSize(data)
#define CAN_WRITE(data, output) TLSX_CA_Names_Write(data, output)
#define CAN_PARSE(ssl, input, length, isRequest) \
TLSX_CA_Names_Parse(ssl, input, length, isRequest)

#else

#define CAN_GET_SIZE(...) 0
#define CAN_WRITE(...) 0
#define CAN_PARSE(...) 0
#define CAN_GET_SIZE(data) 0
#define CAN_WRITE(data, output) 0
#define CAN_PARSE(ssl, input, length, isRequest) 0

#endif

Expand Down Expand Up @@ -14772,9 +14773,9 @@ static word16 TLSX_GetMinSize_Client(word16* type)
return 0;
}
}
#define TLSX_GET_MIN_SIZE_CLIENT TLSX_GetMinSize_Client
#define TLSX_GET_MIN_SIZE_CLIENT(type) TLSX_GetMinSize_Client(type)
#else
#define TLSX_GET_MIN_SIZE_CLIENT(...) 0
#define TLSX_GET_MIN_SIZE_CLIENT(type) 0
#endif


Expand Down Expand Up @@ -14841,9 +14842,9 @@ static word16 TLSX_GetMinSize_Server(const word16 *type)
return 0;
}
}
#define TLSX_GET_MIN_SIZE_SERVER TLSX_GetMinSize_Server
#define TLSX_GET_MIN_SIZE_SERVER(type) TLSX_GetMinSize_Server(type)
#else
#define TLSX_GET_MIN_SIZE_SERVER(...) 0
#define TLSX_GET_MIN_SIZE_SERVER(type) 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
2 changes: 1 addition & 1 deletion wolfcrypt/src/curve25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#if defined(WOLFSSL_LINUXKM) && !defined(USE_INTEL_SPEEDUP)
/* force off unneeded vector register save/restore. */
#undef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#undef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_SP_ASM)
/* force off unneeded vector register save/restore. */
#undef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#undef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_SP_ASM)
/* force off unneeded vector register save/restore. */
#undef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#undef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ ECC Curve Sizes:
#if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_SP_ASM)
/* force off unneeded vector register save/restore. */
#undef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#undef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/eccsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_SP_ASM)
/* force off unneeded vector register save/restore. */
#undef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#undef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ RSA keys can be used to encrypt, decrypt, sign and verify data.
#if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_SP_ASM)
/* force off unneeded vector register save/restore. */
#undef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#undef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/sakke.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_SP_ASM)
/* force off unneeded vector register save/restore. */
#undef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#undef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/sp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ This library provides single precision (SP) integer math functions.
#if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_SP_ASM)
/* force off unneeded vector register save/restore. */
#undef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#undef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
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
12 changes: 10 additions & 2 deletions wolfssl/wolfcrypt/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ 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
#ifdef __WATCOMC__ /* does not allow variadic macros */
#define WOLFSSL_MSG_EX() WC_DO_NOTHING
#else
#define WOLFSSL_MSG_EX(...) WC_DO_NOTHING
#endif
#endif
WOLFSSL_API void WOLFSSL_MSG(const char* msg);
#ifdef WOLFSSL_DEBUG_CODEPOINTS
Expand Down Expand Up @@ -209,7 +213,11 @@ WOLFSSL_API void wolfSSL_SetLoggingPrefix(const char* prefix);
#define WOLFSSL_STUB(m) WC_DO_NOTHING
#define WOLFSSL_IS_DEBUG_ON() 0

#define WOLFSSL_MSG_EX(...) WC_DO_NOTHING
#ifdef __WATCOMC__ /* does not allow variadic macros */
#define WOLFSSL_MSG_EX() WC_DO_NOTHING
#else
#define WOLFSSL_MSG_EX(...) WC_DO_NOTHING
#endif
#define WOLFSSL_MSG(m) WC_DO_NOTHING
#define WOLFSSL_BUFFER(b, l) WC_DO_NOTHING

Expand Down
5 changes: 2 additions & 3 deletions wolfssl/wolfcrypt/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag,

#endif

#define ASSERT_SAVED_VECTOR_REGISTERS(fail_clause) do { \
#define ASSERT_SAVED_VECTOR_REGISTERS() do { \
if (wc_svr_count <= 0) { \
fprintf(stderr, \
("ASSERT_SAVED_VECTOR_REGISTERS : %s @ L%d : " \
Expand All @@ -460,7 +460,6 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag,
wc_svr_last_file, \
wc_svr_last_line); \
DEBUG_VECTOR_REGISTERS_EXTRA_FAIL_CLAUSE \
{ fail_clause } \
} \
} while (0)
#define ASSERT_RESTORED_VECTOR_REGISTERS(fail_clause) do { \
Expand All @@ -477,7 +476,7 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag,
{ fail_clause } \
} \
} while (0)
#define RESTORE_VECTOR_REGISTERS(...) do { \
#define RESTORE_VECTOR_REGISTERS() do { \
--wc_svr_count; \
if ((wc_svr_count > 4) || (wc_svr_count < 0)) { \
fprintf(stderr, \
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
25 changes: 9 additions & 16 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 @@ -1758,7 +1751,7 @@ typedef struct w64wrapper {
#endif

#ifndef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define SAVE_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#endif
#ifndef SAVE_VECTOR_REGISTERS2
#define SAVE_VECTOR_REGISTERS2() 0
Expand All @@ -1772,10 +1765,10 @@ typedef struct w64wrapper {
#define WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(x) WC_DO_NOTHING
#endif
#ifndef ASSERT_SAVED_VECTOR_REGISTERS
#define ASSERT_SAVED_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define ASSERT_SAVED_VECTOR_REGISTERS() WC_DO_NOTHING
#endif
#ifndef ASSERT_RESTORED_VECTOR_REGISTERS
#define ASSERT_RESTORED_VECTOR_REGISTERS(...) WC_DO_NOTHING
#define ASSERT_RESTORED_VECTOR_REGISTERS(fail_clause) WC_DO_NOTHING
#endif
#ifndef RESTORE_VECTOR_REGISTERS
#define RESTORE_VECTOR_REGISTERS() WC_DO_NOTHING
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 8ecf064

Please sign in to comment.