Skip to content

Commit

Permalink
Fixes for Watcom compiler.
Browse files Browse the repository at this point in the history
* Correct cmake script to support Open Watcom toolchain (wolfSSL#8167)
* Fix thread start callback prototype for Open Watcom toolchain (wolfSSL#8175)
* Added GitHub CI action
  • Loading branch information
dgarske committed Jan 29, 2025
1 parent d78338f commit c84aecd
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 47 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/watcomc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Build Watcom C

# START OF COMMON SECTION
on:
push:
#branches: [ 'master', 'main', 'release/**' ]
branches: [ '*' ]
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: Cache OpenWatcom
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:
repository: wolfSSL/wolfssl
ref: master
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:
repository: wolfSSL/wolfssl
ref: master
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/
65 changes: 36 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,18 @@ 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}")
elseif(CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom" OR CMAKE_C_COMILER_ID STREQUAL "OpenWatcom 2.0")
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()

####################################################
Expand Down Expand Up @@ -2485,31 +2490,33 @@ if(WOLFSSL_EXAMPLES)
${WOLFSSL_OUTPUT_BASE}/examples/benchmark)
endif()

# Build unit tests
add_executable(unit_test
tests/api.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 $<TARGET_FILE:unit_test>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
if(NOT WOLFSSL_SINGLE_THREADED)
# Build unit tests
add_executable(unit_test
tests/api.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 $<TARGET_FILE:unit_test>
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
endif()

if(WOLFSSL_CRYPT_TESTS)
Expand Down
8 changes: 4 additions & 4 deletions examples/benchmark/tls_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 4 additions & 3 deletions wolfcrypt/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions wolfssl/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
36 changes: 28 additions & 8 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1553,7 +1554,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;
Expand Down Expand Up @@ -1587,17 +1592,23 @@ 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
* void return
* 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
*/
Expand All @@ -1620,8 +1631,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
Expand Down

0 comments on commit c84aecd

Please sign in to comment.