diff --git a/docs/targets.md b/docs/targets.md index 371d43b..8ddc134 100644 --- a/docs/targets.md +++ b/docs/targets.md @@ -109,7 +109,7 @@ recognized and configured like Linux; musl-specific behaviour (subprocess | Language | C++26, reflection `yes` | | Runtime | Wine 11.0 (`wine64`), no native Windows runner available | | Modules | all modules under `src/` (`VOID_WINDOWS_MODULES` in `cmake/Targets.cmake`) | -| Observed | configure, compile, `cmake --install`, consume (`TargetProfile.exe` linked); each module's suite is verified under Wine before it is allowlisted. Full allowlisted set in one Debug shared binary (MinGW-w64 GCC 16.2.0) under Wine 11: **2003 tests, 1988 passed, 15 skipped, 0 failed** | +| Observed | configure, compile, `cmake --install`, consume (`TargetProfile.exe` linked); each module's suite is verified under Wine before it is allowlisted. Full allowlisted set in one Debug shared binary (MinGW-w64 GCC 16.2.0) under Wine 11: **2008 tests, 1993 passed, 15 skipped, 0 failed** | Notes from the runtime run: @@ -150,9 +150,9 @@ Notes from the runtime run: libsodium, and `ShortUrlRemote` links the Windows `Net` client/server. - Plugin hot-reload and discovery tests run on Windows: a new generation is loaded from a fresh copy while the old DLL stays mapped, and the plugin file - is retired by rename instead of in-place replacement. The C ABI plugin - fixtures remain POSIX-only, and the reload-under-load stress test is still - gated. + is retired by rename instead of in-place replacement. The pure-C ABI fixture + suite also runs there (the V1 fixture carries a small pthread shim), and the + reload-under-load stress test is still gated. - `Observability` links after replacing the namespace-scope `inline thread_local` hook stack with a function-local `thread_local` accessor (MinGW emitted duplicate TLS init functions). diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 516e9aa..61353f4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -327,9 +327,8 @@ if(TARGET VoidTests AND TARGET Void::Plugin) add_dependencies(VoidTests VoidServicePluginV1 VoidServicePluginV2) endif() - # The pure-C ABI fixtures use pthreads/nanosleep; they are POSIX-only for - # now (the C++ plugin fixtures above still cover Plugin on Windows). - if(NOT WIN32) + # The pure-C ABI fixtures build on every platform (the V1 fixture carries + # a small pthread shim for Windows); they are loaded through the C ABI. enable_language(C) function(_void_add_cabi_fixture target_name source_file) add_library(${target_name} SHARED "${CMAKE_CURRENT_SOURCE_DIR}/plugins/${source_file}") @@ -385,5 +384,4 @@ if(TARGET VoidTests AND TARGET Void::Plugin) "VOID_CABI_CYC_A_PATH=\"$\"" "VOID_CABI_CYC_B_PATH=\"$\"" ) - endif() # NOT WIN32 endif() diff --git a/tests/plugins/CAbiPluginV1.c b/tests/plugins/CAbiPluginV1.c index ccf49fb..baf1e71 100644 --- a/tests/plugins/CAbiPluginV1.c +++ b/tests/plugins/CAbiPluginV1.c @@ -2,7 +2,12 @@ #include +#if defined(_WIN32) +#include +#include +#else #include +#endif #include #include #include @@ -10,6 +15,87 @@ #include #include +#if defined(_WIN32) +// Minimal pthread/nanosleep surface for the fixture: one worker thread per +// operation and a CRITICAL_SECTION for the operation table. +typedef HANDLE pthread_t; +typedef CRITICAL_SECTION pthread_mutex_t; + +typedef struct { + void* (*fn)(void*); + void* arg; +} void_thread_start; + +static unsigned __stdcall void_thread_trampoline(void* raw) +{ + void_thread_start* start = (void_thread_start*)raw; + void* (*fn)(void*) = start->fn; + void* arg = start->arg; + free(start); + return (unsigned)(uintptr_t)fn(arg); +} + +static int pthread_mutex_init(pthread_mutex_t* mutex, const void* attr) +{ + (void)attr; + InitializeCriticalSection(mutex); + return 0; +} + +static void pthread_mutex_destroy(pthread_mutex_t* mutex) +{ + DeleteCriticalSection(mutex); +} + +static void pthread_mutex_lock(pthread_mutex_t* mutex) +{ + EnterCriticalSection(mutex); +} + +static void pthread_mutex_unlock(pthread_mutex_t* mutex) +{ + LeaveCriticalSection(mutex); +} + +static int pthread_create(pthread_t* thread, const void* attr, + void* (*fn)(void*), void* arg) +{ + (void)attr; + void_thread_start* start = (void_thread_start*)malloc(sizeof(*start)); + if (start == NULL) { + return -1; + } + start->fn = fn; + start->arg = arg; + const uintptr_t handle = _beginthreadex(NULL, 0, void_thread_trampoline, + start, 0, NULL); + if (handle == 0) { + free(start); + return -1; + } + *thread = (HANDLE)handle; + return 0; +} + +static int pthread_join(pthread_t thread, void** result) +{ + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); + if (result != NULL) { + *result = NULL; + } + return 0; +} + +static void nanosleep(const struct timespec* request, + struct timespec* remaining) +{ + (void)remaining; + Sleep((DWORD)(request->tv_sec * 1000 + + request->tv_nsec / 1000000)); +} +#endif + typedef struct cabi_calc_v1 { uint32_t (*version)(void_module_handle* h); int32_t (*accumulate)(void_module_handle* h, int32_t delta); diff --git a/tests/standalone/Plugin/PluginHardening.cpp b/tests/standalone/Plugin/PluginHardening.cpp index 2ff7ca2..e64f9c2 100644 --- a/tests/standalone/Plugin/PluginHardening.cpp +++ b/tests/standalone/Plugin/PluginHardening.cpp @@ -1,7 +1,6 @@ #include #include #include -// @requires-posix: C ABI plugin fixtures use pthreads/nanosleep. #include #include #include