Tests: build the pure-C ABI plugin fixtures on Windows

The V1 fixture gets a small pthread/nanosleep shim over
_beginthreadex and CRITICAL_SECTION, so the C ABI hardening suite
runs on Windows too (+5 tests). The fixture block is no longer
gated to non-Windows.
This commit is contained in:
faumaray committed 2026-12-06 16:54:41 +03:00
1 parent 7cddcf15ea
commit 7d9884d86b
4 files changed
+92 -9

No files matched your search

+86
View File
@@ -2,7 +2,12 @@
#include <Void/Plugin/CAbi.h>
#if defined(_WIN32)
#include <process.h>
#include <windows.h>
#else
#include <pthread.h>
#endif
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
@@ -10,6 +15,87 @@
#include <string.h>
#include <time.h>
#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);