From 657b6a89e1feaed38f2077f72bc09f5a3d9be50b Mon Sep 17 00:00:00 2001 From: Nuno Marques Date: Thu, 7 May 2026 18:07:00 -0700 Subject: [PATCH] test(windows-shim): stub g_px4_session_id and align errno_map linkage The runtime shim references g_px4_session_id, an interlocked LONG defined in platforms/posix/src/px4/windows/runtime/init.cpp. The test_windows_shim_runtime binary does not link init.cpp because doing so drags the entire process bootstrap path; without the symbol the test failed at link time with an unresolved external. Provide a local definition with C++ linkage that mirrors the runtime contract (the original is also C++-linkage in init.cpp, no extern "C"; matching avoids a name-mangling mismatch at link). Same translation unit had three forward declarations of errno_map helpers (px4_win_error_to_errno, px4_wsa_error_to_errno, px4_hstrerror_text) wrapped in extern "C", but the implementations in errno_map.cpp are C++- linkage. Drop the extern "C" so the linker resolves to the mangled names that errno_map.cpp actually exports. Add the missing , , and includes that the runtime tests rely on for _open / _close / _read / _write declarations under MSVC's CRT. Signed-off-by: Nuno Marques --- .../tests/test_windows_shim_runtime.cpp | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/platforms/posix/src/px4/windows/tests/test_windows_shim_runtime.cpp b/platforms/posix/src/px4/windows/tests/test_windows_shim_runtime.cpp index a49d69b8cf..ee5337fcf3 100644 --- a/platforms/posix/src/px4/windows/tests/test_windows_shim_runtime.cpp +++ b/platforms/posix/src/px4/windows/tests/test_windows_shim_runtime.cpp @@ -58,7 +58,18 @@ #include #include +/* The runtime shim references g_px4_session_id (defined in + * platforms/posix/src/px4/windows/runtime/init.cpp). This test binary + * does not link init.cpp because pulling it in drags the entire process + * bootstrap. Provide a local definition that mirrors the runtime + * contract. The original is C++-linkage (no extern "C") in init.cpp so + * we match that here exactly. */ +volatile LONG g_px4_session_id = 0; + #include +#include +#include +#include #include #include #include @@ -70,10 +81,12 @@ /* errno_map prototypes -- declared in px4_windows_internal.h but the * tests don't include that header (it pulls in the entire winsock+win32 - * stack via the shim umbrella). Forward-declare just what we need. */ -extern "C" int px4_win_error_to_errno(DWORD err); -extern "C" int px4_wsa_error_to_errno(int err); -extern "C" const char *px4_hstrerror_text(int err); + * stack via the shim umbrella). Forward-declare just what we need. The + * originals are C++-linkage in errno_map.cpp; matching the linkage + * exactly here keeps name mangling aligned. */ +int px4_win_error_to_errno(DWORD err); +int px4_wsa_error_to_errno(int err); +const char *px4_hstrerror_text(int err); /* errno_map ------------------------------------------------------------ */