diff --git a/.github/workflows/watcomc.yml b/.github/workflows/watcomc.yml new file mode 100644 index 0000000000..6e128d0e57 --- /dev/null +++ b/.github/workflows/watcomc.yml @@ -0,0 +1,66 @@ +name: Build Watcom C + +# START OF COMMON SECTION +on: + push: + branches: [ 'master', 'main', 'release/**' ] + pull_request: + branches: [ '*' ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +# END OF COMMON SECTION + +jobs: + wolfssl_watcomc_linux: + if: github.repository_owner == 'wolfssl' + runs-on: ubuntu-latest + steps: + - name: Download OpenWatcom v2 C compiler + shell: bash + run: | + wget --no-verbose 'https://github.com/open-watcom/open-watcom-v2/releases/download/Current-build/open-watcom-2_0-c-linux-x64' -O ~/ow.zip + mkdir -p ~/openwatcom + cd ~/openwatcom + unzip -q ~/ow.zip + chmod -R a+rx ~/openwatcom + + - name: Checkout wolfSSL + uses: actions/checkout@v4 + with: + path: wolfssl + + - name: Build wolfSSL + working-directory: wolfssl + shell: bash + run: | + export WATCOM=~/openwatcom + export PATH="$WATCOM/binl64:$WATCOM/binl:$PATH" + export INCLUDE=$WATCOM/lh:$INCLUDE + export EDPATH=$WATCOM/eddat + export WWINHELP=$WATCOM/binw + export WIPFC=$WATCOM/wipfc + cmake -B build -G "Watcom WMake" -D CMAKE_VERBOSE_MAKEFILE=TRUE -D CMAKE_SYSTEM_NAME=Linux -D CMAKE_SYSTEM_PROCESSOR=x86 -D WOLFSSL_ASM=no -D WOLFSSL_SINGLE_THREADED=yes -D BUILD_SHARED_LIBS=no -D WOLFSSL_EXAMPLES=no -D WOLFSSL_CRYPT_TESTS=no + cmake --build ./build/ + + wolfssl_watcomc_windows: + if: github.repository_owner == 'wolfssl' + runs-on: windows-latest + steps: + - name: Setup OpenOatcom V2 + uses: open-watcom/setup-watcom@v0 + with: + version: "2.0" + + - name: Checkout wolfSSL + uses: actions/checkout@v4 + with: + path: wolfssl + + - name: Build wolfSSL + working-directory: wolfssl + shell: bash + run: | + cmake -B build -G "Watcom WMake" -D CMAKE_VERBOSE_MAKEFILE=TRUE -D CMAKE_SYSTEM_NAME=Windows -D CMAKE_SYSTEM_PROCESSOR=x86 -D WOLFSSL_ASM=no -D WOLFSSL_SINGLE_THREADED=yes -D BUILD_SHARED_LIBS=no -D WOLFSSL_EXAMPLES=no -D WOLFSSL_CRYPT_TESTS=no + cmake --build build diff --git a/CMakeLists.txt b/CMakeLists.txt index 19f3819642..3e0f9008e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,13 +198,20 @@ find_package(Threads) # Example for map file and custom linker script #set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"") +message(STATUS "C Compiler ID: ${CMAKE_C_COMPILER_ID}") + if(DEFINED WARNING_C_FLAGS) -set(CMAKE_C_FLAGS "${WARNING_C_FLAGS} ${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS "${WARNING_C_FLAGS} ${CMAKE_C_FLAGS}") +endif() + +if(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wx -wcd=202") + list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_NOT_WINDOWS_API -DWOLFSSL_HAVE_MIN -DWOLFSSL_HAVE_MAX -DNO_WRITEV -DWOLFSSL_NO_SOCK -DWOLFSSL_USER_IO") elseif(WIN32) -# Windows cl.exe does not support the -Wextra, -Wno-unused and -Werror flags. -set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}") + # Windows cl.exe does not support the -Wextra, -Wno-unused and -Werror flags. + set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}") else() -set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused -Werror ${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused -Werror ${CMAKE_C_FLAGS}") endif() #################################################### @@ -2485,32 +2492,34 @@ if(WOLFSSL_EXAMPLES) ${WOLFSSL_OUTPUT_BASE}/examples/benchmark) endif() - # Build unit tests - add_executable(unit_test - tests/api.c - tests/api/ascon.c - tests/hash.c - tests/srp.c - tests/suites.c - tests/w64wrapper.c - tests/unit.c - tests/quic.c - examples/server/server.c - examples/client/client.c) - target_include_directories(unit_test PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}) - target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER") - target_link_libraries(unit_test wolfssl) - target_link_libraries(unit_test Threads::Threads) - set_property(TARGET unit_test - PROPERTY RUNTIME_OUTPUT_DIRECTORY - ${WOLFSSL_OUTPUT_BASE}/tests/) - set_property(TARGET unit_test - PROPERTY RUNTIME_OUTPUT_NAME - unit.test) - add_test(NAME unit_test - COMMAND $ - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + if(NOT WOLFSSL_SINGLE_THREADED) + # Build unit tests + add_executable(unit_test + tests/api.c + tests/api/ascon.c + tests/hash.c + tests/srp.c + tests/suites.c + tests/w64wrapper.c + tests/unit.c + tests/quic.c + examples/server/server.c + examples/client/client.c) + target_include_directories(unit_test PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}) + target_compile_options(unit_test PUBLIC "-DNO_MAIN_DRIVER") + target_link_libraries(unit_test wolfssl) + target_link_libraries(unit_test Threads::Threads) + set_property(TARGET unit_test + PROPERTY RUNTIME_OUTPUT_DIRECTORY + ${WOLFSSL_OUTPUT_BASE}/tests/) + set_property(TARGET unit_test + PROPERTY RUNTIME_OUTPUT_NAME + unit.test) + add_test(NAME unit_test + COMMAND $ + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + endif() endif() if(WOLFSSL_CRYPT_TESTS) diff --git a/examples/benchmark/tls_bench.c b/examples/benchmark/tls_bench.c index c22404260b..15e053dfdb 100644 --- a/examples/benchmark/tls_bench.c +++ b/examples/benchmark/tls_bench.c @@ -1230,7 +1230,7 @@ static int bench_tls_client(info_t* info) } #if !defined(SINGLE_THREADED) && defined(WOLFSSL_THREAD_NO_JOIN) -static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN client_thread(void* args) +static THREAD_RETURN_NOJOIN WOLFSSL_THREAD_NO_JOIN client_thread(void* args) { int ret; info_t* info = (info_t*)args; @@ -1243,7 +1243,7 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN client_thread(void* args) THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_server.cond)); THREAD_CHECK_RET(wolfSSL_CondEnd(&info->to_server.cond)); - WOLFSSL_RETURN_FROM_THREAD(0); + RETURN_FROM_THREAD_NOJOIN(0); } #endif /* !SINGLE_THREADED */ #endif /* !NO_WOLFSSL_CLIENT */ @@ -1675,7 +1675,7 @@ static int bench_tls_server(info_t* info) } #if !defined(SINGLE_THREADED) && defined(WOLFSSL_THREAD_NO_JOIN) -static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN server_thread(void* args) +static THREAD_RETURN_NOJOIN WOLFSSL_THREAD_NO_JOIN server_thread(void* args) { int ret = 0; info_t* info = (info_t*)args; @@ -1703,7 +1703,7 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN server_thread(void* args) THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_client.cond)); THREAD_CHECK_RET(wolfSSL_CondEnd(&info->to_client.cond)); - WOLFSSL_RETURN_FROM_THREAD(0); + RETURN_FROM_THREAD_NOJOIN(0); } #endif /* !SINGLE_THREADED */ #endif /* !NO_WOLFSSL_SERVER */ diff --git a/src/internal.c b/src/internal.c index 6bf9e06ea2..a608198188 100644 --- a/src/internal.c +++ b/src/internal.c @@ -11916,7 +11916,7 @@ static int GetRecordHeader(WOLFSSL* ssl, word32* inOutIdx, (!ssl->options.dtls && rh->pvMinor < ssl->version.minor)) #else - rh->pvMinor < ssl->version.minor + (rh->pvMinor < ssl->version.minor) #endif )) { WOLFSSL_MSG("SSL version error"); diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index e0d2daebf3..444b6413d0 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -913,7 +913,8 @@ static WC_INLINE word64 Entropy_TimeHiRes(void) * @param [in,out] args Entropy data including: counter and stop flag. * @return NULL always. */ -static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN Entropy_IncCounter(void* args) +static THREAD_RETURN_NOJOIN WOLFSSL_THREAD_NO_JOIN + Entropy_IncCounter(void* args) { (void)args; @@ -926,8 +927,8 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN Entropy_IncCounter(void* args) #ifdef WOLFSSL_DEBUG_ENTROPY_MEMUSE fprintf(stderr, "EXITING ENTROPY COUNTER THREAD\n"); #endif - /* Exit from thread. */ - WOLFSSL_RETURN_FROM_THREAD(0); + + RETURN_FROM_THREAD_NOJOIN(0); } /* Start a thread that increments counter if not one already. diff --git a/wolfssl/test.h b/wolfssl/test.h index 33b86404eb..81f4ef7186 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -1521,7 +1521,7 @@ static WC_INLINE int tcp_select_ex(SOCKET_T socketfd, int to_sec, int rx) fd_set* recvfds = NULL; fd_set* sendfds = NULL; SOCKET_T nfds = socketfd + 1; -#if !defined(__INTEGRITY) +#if !defined(__INTEGRITY) && !defined(__WATCOMC__) struct timeval timeout = {(to_sec > 0) ? to_sec : 0, 0}; #else struct timeval timeout; @@ -1538,7 +1538,7 @@ static WC_INLINE int tcp_select_ex(SOCKET_T socketfd, int to_sec, int rx) else sendfds = &fds; -#if defined(__INTEGRITY) +#if defined(__INTEGRITY) || defined(__WATCOMC__) timeout.tv_sec = (long long)(to_sec > 0) ? to_sec : 0, 0; #endif result = select(nfds, recvfds, sendfds, &errfds, &timeout); diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 6431dd4ceb..5a2b993a70 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -408,9 +408,10 @@ typedef struct w64wrapper { #ifdef HAVE_THREAD_LS #if defined(_MSC_VER) #define THREAD_LS_T __declspec(thread) - /* Thread local storage only in FreeRTOS v8.2.1 and higher */ + /* Thread local storage only in FreeRTOS v8.2.1 and higher, not zephyr + * and not Watcom C compiler */ #elif defined(FREERTOS) || defined(FREERTOS_TCP) || \ - defined(WOLFSSL_ZEPHYR) + defined(WOLFSSL_ZEPHYR) || defined(__WATCOMC__) #define THREAD_LS_T #else #define THREAD_LS_T __thread @@ -1554,7 +1555,11 @@ typedef struct w64wrapper { #define INVALID_THREAD_VAL ((THREAD_TYPE)(INVALID_HANDLE_VALUE)) #define WOLFSSL_THREAD __stdcall #if !defined(__MINGW32__) - #define WOLFSSL_THREAD_NO_JOIN __cdecl + #if defined(__WATCOMC__) + #define WOLFSSL_THREAD_NO_JOIN + #else + #define WOLFSSL_THREAD_NO_JOIN __cdecl + #endif #endif #elif defined(THREADX) typedef unsigned int THREAD_RETURN; @@ -1588,8 +1593,6 @@ typedef struct w64wrapper { * to check if the value is an invalid thread * WOLFSSL_THREAD - attribute that should be used to declare thread * callbacks - * WOLFSSL_THREAD_NO_JOIN - attribute that should be used to declare - * thread callbacks that don't require cleanup * WOLFSSL_COND - defined if this system supports signaling * COND_TYPE - type that should be passed into the signaling API * WOLFSSL_THREAD_VOID_RETURN - defined if the thread callback has a @@ -1597,8 +1600,16 @@ typedef struct w64wrapper { * WOLFSSL_RETURN_FROM_THREAD - define used to correctly return from a * thread callback * THREAD_CB - thread callback type for regular threading API - * THREAD_CB_NOJOIN - thread callback type for threading API that don't + * + * WOLFSSL_THREAD_NO_JOIN - attribute used to declare thread callbacks + * that do not require cleanup + * THREAD_CB_NOJOIN - thread callback type for thread APIs that do not * require cleanup + * THREAD_RETURN_NOJOIN - return type used to declare thread callbacks + * that do not require cleanup + * RETURN_FROM_THREAD_NOJOIN - define used to correctly return from + * a thread callback that do not require + * cleanup * * Other defines/types are specific for the threading implementation */ @@ -1621,8 +1632,17 @@ typedef struct w64wrapper { /* Create a thread that will be automatically cleaned up. We can't * return a handle/pointer to the new thread because there are no * guarantees for how long it will be valid. */ - typedef THREAD_RETURN (WOLFSSL_THREAD_NO_JOIN *THREAD_CB_NOJOIN) - (void* arg); + #if defined(WOLFSSL_PTHREADS) + #define THREAD_CB_NOJOIN THREAD_CB + #define THREAD_RETURN_NOJOIN THREAD_RETURN + #define RETURN_FROM_THREAD_NOJOIN(x) \ + WOLFSSL_RETURN_FROM_THREAD(x) + #else + #define THREAD_RETURN_NOJOIN void + typedef THREAD_RETURN_NOJOIN + (WOLFSSL_THREAD_NO_JOIN *THREAD_CB_NOJOIN)(void* arg); + #define RETURN_FROM_THREAD_NOJOIN(x) return + #endif WOLFSSL_API int wolfSSL_NewThreadNoJoin(THREAD_CB_NOJOIN cb, void* arg); #endif