diff --git a/runtime/shims/ws2_offline.cpp b/runtime/shims/ws2_offline.cpp index fc124af135..309525c546 100644 --- a/runtime/shims/ws2_offline.cpp +++ b/runtime/shims/ws2_offline.cpp @@ -87,6 +87,13 @@ void set_wsa_error(int err) { } } +// The host's WSAGetLastError through host_proc, like set_wsa_error: gta6rt does not link ws2_32. +int wsa_last_error() { + using LastErrFn = int(WSAAPI*)(); + static LastErrFn fn = host_proc("WSAGetLastError"); + return fn ? fn() : static_cast(GetLastError()); +} + uint16_t read_be16(uint16_t net_val) { const auto* b = reinterpret_cast(&net_val); return static_cast((static_cast(b[0]) << 8) | b[1]); @@ -876,7 +883,7 @@ int wrap_extension_lookup(Fn real_fn, SOCKET s, DWORD io_control_code, LPVOID in std::memcpy(out_buf, &wrapped, sizeof(wrapped)); const int rc = real_fn(s, io_control_code, in_buf, in_len, &answer->pointer, sizeof(answer->pointer), &answer->returned, overlapped, completion); - const int error = rc == 0 ? 0 : WSAGetLastError(); + const int error = rc == 0 ? 0 : wsa_last_error(); if (rc == 0) { *bytes_returned = sizeof(wrapped); delete answer;