Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes for Open Watcom build #8505

Merged
merged 5 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ __SUNPRO_CC
__SVR4
__TI_COMPILER_VERSION__
__TURBOC__
__UNIX__
__USE_GNU
__USE_MISC
__USE_XOPEN2K
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -14997,6 +14997,14 @@ void bench_sphincsKeySign(byte level, byte optim)
return (double)us / 1000000.0;
}

#elif defined(__WATCOMC__)

#include <time.h>
WC_INLINE double current_time(int reset)
{
(void)reset;
return ((double)clock())/CLOCKS_PER_SEC;
}
#else

#include <time.h>
Expand Down
55 changes: 51 additions & 4 deletions wolfssl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,50 @@
#endif /* HAVE_ECC */
#endif /*HAVE_PK_CALLBACKS */

#ifdef USE_WINDOWS_API
#ifdef __WATCOMC__
#define SNPRINTF snprintf
#if defined(__NT__)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <process.h>
#ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
#include <wspiapi.h>
#endif
#define SOCKET_T SOCKET
#define XSLEEP_MS(t) Sleep(t)
#elif defined(__OS2__)
#include <netdb.h>
#include <sys/ioctl.h>
#include <tcpustd.h>
#define SOCKET_T int
#elif defined(__UNIX__)
#include <string.h>
#include <netdb.h>
#include <netinet/tcp.h>
#ifndef WOLFSSL_NDS
#include <sys/ioctl.h>
#endif
#include <time.h>
#include <sys/time.h>
#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif
#define SOCKET_T int
#ifndef SO_NOSIGPIPE
#include <signal.h> /* 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 <winsock2.h>
#include <ws2tcpip.h>
#include <process.h>
#ifdef TEST_IPV6 /* don't require newer SDK for IPV4 */
#include <ws2tcpip.h>
#include <wspiapi.h>
#endif
#define SOCKET_T SOCKET
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion wolfssl/wolfcrypt/ecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 8 additions & 0 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions wolfssl/wolfcrypt/visibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 42 additions & 18 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */
#ifndef WOLFSSL_USER_IO
#include <winsock2.h>
#include <ws2tcpip.h> /* required for InetPton */
#endif
#elif defined(__OS2__)
#include <os2.h>
#endif
#else
#if defined(USE_WINDOWS_API)
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
#include <windows.h>
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */
#include <process.h>
#ifndef WOLFSSL_USER_IO
#include <winsock2.h>
#include <ws2tcpip.h> /* required for InetPton */
#endif
#elif defined(__OS2__)
#define INCL_DOSSEMAPHORES
#define INCL_DOSPROCESS
Expand All @@ -140,17 +158,7 @@
#include <pthread.h>
#endif
#endif
#else
#if defined(USE_WINDOWS_API)
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
#include <windows.h>
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
#elif defined(__OS2__)
#include <os2.h>
#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 <pthread.h>
Expand All @@ -164,7 +172,7 @@
#if !defined(WOLFSSL_SGX) && !defined(WOLFSSL_NOT_WINDOWS_API)
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file. */
#include <windows.h>
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header file */
#undef _WINSOCKAPI_ /* undefine it for MINGW winsock2.h header */
#ifndef WOLFSSL_USER_IO
#include <winsock2.h>
#include <ws2tcpip.h> /* required for InetPton */
Expand Down Expand Up @@ -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 <unistd.h>
#include <sys/stat.h>
#define XWRITE write
#define XREAD read
#define XCLOSE close
#define XSTAT stat
#define XS_ISREG(s) S_ISREG(s)
#if defined(__UNIX__)
#include <dirent.h>
#define SEPARATOR_CHAR ':'
#else
#include <direct.h>
#define SEPARATOR_CHAR ';'
#endif
#if defined(__NT__)
#define XALTHOMEVARNAME "USERPROFILE"
#endif
#elif defined(USE_WINDOWS_API)
#include <io.h>
#include <sys/stat.h>
#ifndef XSTAT
Expand Down Expand Up @@ -964,9 +990,7 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
#define SEPARATOR_CHAR ':'

#else
#ifndef NO_WOLFSSL_DIR
#include <dirent.h>
#endif
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#define XWRITE write
Expand Down
Loading
Loading