Files
VoidUniveralFormat/tests/e2e/load_host_libc_pthread.cpp
T
faumaray bba5c8a39a initial commit
Signed-off-by: Aleksey Selihov <faumaray@gmail.com>
2026-05-22 02:40:32 +03:00

41 lines
1.4 KiB
C++

// E2E: host-libc delegation — pthread_create/join resolved from libpthread.so.0
// (or libc.so.6 on modern glibc where pthread is merged).
#include <cstdio>
#include <cstdlib>
#include <dlfcn.h>
#ifndef VOIDLIBC_TEST_VLC_PATH
#error "VOIDLIBC_TEST_VLC_PATH must be set by CMake"
#endif
#define REQUIRE(cond) do { \
if (!(cond)) { \
std::fprintf(stderr, "FAIL: %s (line %d)\n", #cond, \
__LINE__); \
const char* le = ::dlerror(); \
if (le) std::fprintf(stderr, " dlerror: %s\n", le); \
std::exit(1); \
} \
} while (0)
int main() {
void* h = ::dlopen(VOIDLIBC_TEST_VLC_PATH, RTLD_NOW);
REQUIRE(h != nullptr);
using fn_t = int (*)(int);
auto* fn = reinterpret_cast<fn_t>(::dlsym(h, "pthread_double"));
REQUIRE(fn != nullptr);
const int result = fn(21);
if (result != 42) {
std::fprintf(stderr, "FAIL: pthread_double(21) = %d (expected 42)\n", result);
std::exit(1);
}
REQUIRE(::dlclose(h) == 0);
std::printf("PASS: e2e_host_libc_pthread — pthread_create/join resolved, "
"pthread_double(21) = %d\n", result);
return 0;
}