diff --git a/.wolfssl_known_macro_extras b/.wolfssl_known_macro_extras index d399da0aea..c7ce71064e 100644 --- a/.wolfssl_known_macro_extras +++ b/.wolfssl_known_macro_extras @@ -947,6 +947,7 @@ __SUNPRO_CC __SVR4 __TI_COMPILER_VERSION__ __TURBOC__ +__UNIX__ __USE_GNU __USE_MISC __USE_XOPEN2K diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a9486c673..dfe891bca6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2419,12 +2419,15 @@ target_include_directories(wolfssl target_link_libraries(wolfssl PUBLIC ${WOLFSSL_LINK_LIBS}) -if (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_SYSTEM_NAME} MATCHES "^MINGW") +if(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom") + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + target_link_libraries(wolfssl PUBLIC ws2_32 crypt32) + endif() +elseif (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "^MSYS" OR ${CMAKE_SYSTEM_NAME} MATCHES "^MINGW") # For Windows link required libraries message("Building on Windows/MSYS/MINGW") target_link_libraries(wolfssl PUBLIC ws2_32 crypt32 advapi32) -elseif(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom") elseif(APPLE) message("Building on Apple") if(WOLFSSL_SYS_CA_CERTS) diff --git a/src/wolfio.c b/src/wolfio.c index ab99a891c2..e63595a550 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -1251,6 +1251,9 @@ int wolfIO_SendTo(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int wr ret = ioctlsocket(sockfd, FIONBIO, &blocking); if (ret == SOCKET_ERROR) ret = WOLFSSL_FATAL_ERROR; + #elif defined(__WATCOMC__) && defined(__OS2__) + if (ioctl(sockfd, FIONBIO, &non_blocking) == -1) + ret = WOLFSSL_FATAL_ERROR; #else ret = fcntl(sockfd, F_GETFL, 0); if (ret >= 0) { @@ -1290,9 +1293,9 @@ int wolfIO_SendTo(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int wr ret = select(nfds, &rfds, &wfds, NULL, &timeout); if (ret == 0) { - #ifdef DEBUG_HTTP + #ifdef DEBUG_HTTP fprintf(stderr, "Timeout: %d\n", ret); - #endif + #endif return HTTP_TIMEOUT; } else if (ret > 0) { diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index fe482d6266..fa308dfcad 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -14997,6 +14997,14 @@ void bench_sphincsKeySign(byte level, byte optim) return (double)us / 1000000.0; } +#elif defined(__WATCOMC__) + + #include + WC_INLINE double current_time(int reset) + { + (void)reset; + return ((double)clock())/CLOCKS_PER_SEC; + } #else #include diff --git a/wolfssl/test.h b/wolfssl/test.h index 6fa29344b8..fa84ab0e00 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -85,11 +85,50 @@ #endif /* HAVE_ECC */ #endif /*HAVE_PK_CALLBACKS */ -#ifdef USE_WINDOWS_API +#ifdef __WATCOMC__ + #define SNPRINTF snprintf + #if defined(__NT__) + #include + #include + #include + #ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */ + #include + #endif + #define SOCKET_T SOCKET + #define XSLEEP_MS(t) Sleep(t) + #elif defined(__OS2__) + #include + #include + #include + #define SOCKET_T int + #elif defined(__UNIX__) + #include + #include + #include + #ifndef WOLFSSL_NDS + #include + #endif + #include + #include + #ifdef HAVE_PTHREAD + #include + #endif + #define SOCKET_T int + #ifndef SO_NOSIGPIPE + #include /* ignore SIGPIPE */ + #endif + + #define XSLEEP_MS(m) \ + { \ + struct timespec req = { (m)/1000, ((m) % 1000) * 1000 }; \ + nanosleep( &req, NULL ); \ + } + #endif +#elif defined(USE_WINDOWS_API) #include + #include #include #ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */ - #include #include #endif #define SOCKET_T SOCKET @@ -1429,7 +1468,7 @@ static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp) err_sys_with_errno("socket failed\n"); } -#ifndef USE_WINDOWS_API +#if !defined(USE_WINDOWS_API) && !defined(__WATCOMC__) && !defined(__OS2__) #ifdef SO_NOSIGPIPE { int on = 1; @@ -1457,7 +1496,7 @@ static WC_INLINE void tcp_socket(SOCKET_T* sockfd, int udp, int sctp) err_sys_with_errno("setsockopt TCP_NODELAY failed\n"); } #endif -#endif /* USE_WINDOWS_API */ +#endif /* !defined(USE_WINDOWS_API) && !defined(__WATCOMC__) && ... */ } #if defined(WOLFSSL_WOLFSENTRY_HOOKS) && defined(WOLFSENTRY_H) @@ -1801,6 +1840,10 @@ static WC_INLINE void tcp_set_nonblocking(SOCKET_T* sockfd) || defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \ || defined(WOLFSSL_ZEPHYR) /* non blocking not supported, for now */ + #elif defined(__WATCOMC__) && defined(__OS2__) + int blocking = 1; + if (ioctl(*sockfd, FIONBIO, &blocking) == -1) + err_sys_with_errno("ioctl failed"); #else int flags = fcntl(*sockfd, F_GETFL, 0); if (flags < 0) @@ -1822,6 +1865,10 @@ static WC_INLINE void tcp_set_blocking(SOCKET_T* sockfd) || defined (WOLFSSL_TIRTOS)|| defined(WOLFSSL_VXWORKS) \ || defined(WOLFSSL_ZEPHYR) /* non blocking not supported, for now */ + #elif defined(__WATCOMC__) && defined(__OS2__) + int blocking = 0; + if (ioctl(*sockfd, FIONBIO, &blocking) == -1) + err_sys_with_errno("ioctl failed"); #else int flags = fcntl(*sockfd, F_GETFL, 0); if (flags < 0) diff --git a/wolfssl/wolfcrypt/ecc.h b/wolfssl/wolfcrypt/ecc.h index 3d5e939d91..04a7a66e94 100644 --- a/wolfssl/wolfcrypt/ecc.h +++ b/wolfssl/wolfcrypt/ecc.h @@ -287,7 +287,8 @@ typedef byte ecc_oid_t; #endif -#if !defined(WOLFSSL_ECC_CURVE_STATIC) && defined(USE_WINDOWS_API) +#if !defined(WOLFSSL_ECC_CURVE_STATIC) && defined(USE_WINDOWS_API) && \ + !defined(__WATCOMC__) /* MSC does something different with the pointers to the arrays than GCC, * and it causes the FIPS checksum to fail. In the case of windows builds, * store everything as arrays instead of pointers to strings. */ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 498c807aa1..a87a309ab5 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -922,6 +922,13 @@ typedef struct w64wrapper { /* use only Thread Safe version of strtok */ #if defined(USE_WOLF_STRTOK) #define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr)) + #elif defined(__WATCOMC__) + #if __WATCOMC__ < 1300 + #define USE_WOLF_STRTOK + #define XSTRTOK(s1,d,ptr) wc_strtok((s1),(d),(ptr)) + #else + #define XSTRTOK(s1,d,ptr) strtok_r((s1),(d),(ptr)) + #endif #elif defined(USE_WINDOWS_API) || defined(INTIME_RTOS) #define XSTRTOK(s1,d,ptr) strtok_s((s1),(d),(ptr)) #else @@ -1503,6 +1510,7 @@ typedef struct w64wrapper { #define WOLFSSL_THREAD __stdcall #define WOLFSSL_THREAD_NO_JOIN _WCCALLBACK #elif defined(__OS2__) + #define WOLFSSL_THREAD_VOID_RETURN typedef void THREAD_RETURN; typedef TID THREAD_TYPE; typedef struct COND_TYPE { diff --git a/wolfssl/wolfcrypt/visibility.h b/wolfssl/wolfcrypt/visibility.h index b8eb035e4a..aa506ba21d 100644 --- a/wolfssl/wolfcrypt/visibility.h +++ b/wolfssl/wolfcrypt/visibility.h @@ -51,8 +51,15 @@ #define WOLFSSL_LOCAL #endif /* HAVE_VISIBILITY */ #else /* BUILDING_WOLFSSL */ - #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) || \ - defined(_WIN32_WCE) || defined(__WATCOMC__) + #if defined(__WATCOMC__) + #if defined(WOLFSSL_DLL) && defined(__NT__) + #define WOLFSSL_API __declspec(dllimport) + #else + #define WOLFSSL_API + #endif + #define WOLFSSL_LOCAL + #elif defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) || \ + defined(_WIN32_WCE) #if defined(WOLFSSL_DLL) #define WOLFSSL_API __declspec(dllimport) #else diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 29e30e6172..b53c1586f6 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -120,13 +120,31 @@ #endif /* THREADING/MUTEX SECTION */ -#if defined(__WATCOMC__) - #if !defined(SINGLE_THREADED) +#if defined(SINGLE_THREADED) && defined(NO_FILESYSTEM) + /* No system headers required for build. */ +#elif defined(__WATCOMC__) + #if defined(SINGLE_THREADED) #if defined(USE_WINDOWS_API) #define _WINSOCKAPI_ /* block inclusion of winsock.h header file */ #include - #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */ + #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */ + #ifndef WOLFSSL_USER_IO + #include + #include /* required for InetPton */ + #endif + #elif defined(__OS2__) + #include + #endif + #else + #if defined(USE_WINDOWS_API) + #define _WINSOCKAPI_ /* block inclusion of winsock.h header file */ + #include + #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */ #include + #ifndef WOLFSSL_USER_IO + #include + #include /* required for InetPton */ + #endif #elif defined(__OS2__) #define INCL_DOSSEMAPHORES #define INCL_DOSPROCESS @@ -140,17 +158,7 @@ #include #endif #endif - #else - #if defined(USE_WINDOWS_API) - #define _WINSOCKAPI_ /* block inclusion of winsock.h header file */ - #include - #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */ - #elif defined(__OS2__) - #include - #endif #endif -#elif defined(SINGLE_THREADED) && defined(NO_FILESYSTEM) - /* No system headers required for build. */ #elif defined(USE_WINDOWS_API) #if defined(WOLFSSL_PTHREADS) #include @@ -164,7 +172,7 @@ #if !defined(WOLFSSL_SGX) && !defined(WOLFSSL_NOT_WINDOWS_API) #define _WINSOCKAPI_ /* block inclusion of winsock.h header file. */ #include - #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */ + #undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */ #ifndef WOLFSSL_USER_IO #include #include /* required for InetPton */ @@ -926,7 +934,25 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); #if !defined(NO_WOLFSSL_DIR)\ && !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2) - #if defined(USE_WINDOWS_API) + #if defined(__WATCOMC__) + #include + #include + #define XWRITE write + #define XREAD read + #define XCLOSE close + #define XSTAT stat + #define XS_ISREG(s) S_ISREG(s) + #if defined(__UNIX__) + #include + #define SEPARATOR_CHAR ':' + #else + #include + #define SEPARATOR_CHAR ';' + #endif + #if defined(__NT__) + #define XALTHOMEVARNAME "USERPROFILE" + #endif + #elif defined(USE_WINDOWS_API) #include #include #ifndef XSTAT @@ -964,9 +990,7 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); #define SEPARATOR_CHAR ':' #else - #ifndef NO_WOLFSSL_DIR - #include - #endif + #include #include #include #define XWRITE write diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index 2e460f5f4f..de45a18b5e 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -57,7 +57,32 @@ #include "zlib.h" #endif -#ifndef USE_WINDOWS_API +#if defined(__WATCOMC__) + #if defined(__NT__) + #elif defined(__OS2__) + #include + #include + #include + #include + #include + #include + #include + #include + #include + + typedef int socklen_t; + #elif defined(__LINUX__) + #include + #include + #include + #include + #define XFCNTL(fd, flag, block) fcntl((fd), (flag), (block)) + #include + #include + #include + #endif +#elif defined(USE_WINDOWS_API) +#else #if defined(WOLFSSL_LWIP) && !defined(WOLFSSL_APACHE_MYNEWT) /* lwIP needs to be configured to use sockets API in this mode */ /* LWIP_SOCKET 1 in lwip/opt.h or in build */ @@ -152,26 +177,6 @@ #include #elif defined(WOLFSSL_EMNET) #include - #elif defined(__WATCOMC__) - #if defined(__OS2__) - #include - #include - #include - #include - #include - #include - #include - #include - - typedef int socklen_t; - #elif defined(__LINUX__) - #include - #include - #include - #include - #include - #include - #endif #elif !defined(WOLFSSL_NO_SOCK) #include #include @@ -224,7 +229,40 @@ #define SOCKET_RECEIVING 1 #define SOCKET_SENDING 2 -#ifdef USE_WINDOWS_API +#ifdef __WATCOMC__ + #if defined(__NT__) + /* no epipe yet */ + #ifndef WSAEPIPE + #define WSAEPIPE -12345 + #endif + #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK + #define SOCKET_EAGAIN WSAETIMEDOUT + #define SOCKET_ETIMEDOUT WSAETIMEDOUT + #define SOCKET_ECONNRESET WSAECONNRESET + #define SOCKET_EINTR WSAEINTR + #define SOCKET_EPIPE WSAEPIPE + #define SOCKET_ECONNREFUSED WSAENOTCONN + #define SOCKET_ECONNABORTED WSAECONNABORTED + #elif defined(__OS2__) + #define SOCKET_EWOULDBLOCK SOCEWOULDBLOCK + #define SOCKET_EAGAIN SOCEAGAIN + #define SOCKET_ETIMEDOUT SOCETIMEDOUT + #define SOCKET_ECONNRESET SOCECONNRESET + #define SOCKET_EINTR SOCEINTR + #define SOCKET_EPIPE SOCEPIPE + #define SOCKET_ECONNREFUSED SOCECONNREFUSED + #define SOCKET_ECONNABORTED SOCECONNABORTED + #elif defined(__UNIX__) + #define SOCKET_EWOULDBLOCK EWOULDBLOCK + #define SOCKET_EAGAIN EAGAIN + #define SOCKET_ETIMEDOUT ETIMEDOUT + #define SOCKET_ECONNRESET ECONNRESET + #define SOCKET_EINTR EINTR + #define SOCKET_EPIPE EPIPE + #define SOCKET_ECONNREFUSED ECONNREFUSED + #define SOCKET_ECONNABORTED ECONNABORTED + #endif +#elif defined(USE_WINDOWS_API) /* no epipe yet */ #ifndef WSAEPIPE #define WSAEPIPE -12345 @@ -856,21 +894,36 @@ WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags); #ifndef XINET_NTOP - #define XINET_NTOP(a,b,c,d) inet_ntop((a),(b),(c),(d)) - #ifdef USE_WINDOWS_API /* Windows-friendly definition */ - #undef XINET_NTOP + #if defined(__WATCOMC__) + #if defined(__OS2__) || defined(__NT__) && \ + (NTDDI_VERSION >= NTDDI_VISTA) + #define XINET_NTOP(a,b,c,d) inet_ntop((a),(b),(c),(d)) + #else + #define XINET_NTOP(a,b,c,d) \ + strncpy((c),inet_ntoa(*(unsigned *)(b)),(d)) + #endif + #elif defined(USE_WINDOWS_API) /* Windows-friendly definition */ #define XINET_NTOP(a,b,c,d) InetNtop((a),(b),(c),(d)) + #else + #define XINET_NTOP(a,b,c,d) inet_ntop((a),(b),(c),(d)) #endif #endif #ifndef XINET_PTON - #define XINET_PTON(a,b,c) inet_pton((a),(b),(c)) - #ifdef USE_WINDOWS_API /* Windows-friendly definition */ - #undef XINET_PTON + #if defined(__WATCOMC__) + #if defined(__OS2__) || defined(__NT__) && \ + (NTDDI_VERSION >= NTDDI_VISTA) + #define XINET_PTON(a,b,c) inet_pton((a),(b),(c)) + #else + #define XINET_PTON(a,b,c) *(unsigned *)(c) = inet_addr((b)) + #endif + #elif defined(USE_WINDOWS_API) /* Windows-friendly definition */ #if defined(__MINGW64__) && !defined(UNICODE) #define XINET_PTON(a,b,c) InetPton((a),(b),(c)) #else #define XINET_PTON(a,b,c) InetPton((a),(PCWSTR)(b),(c)) #endif + #else + #define XINET_PTON(a,b,c) inet_pton((a),(b),(c)) #endif #endif