Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip WSA_FLAG_NO_HANDLE_INHERIT on system < Windows 7 SP1 #126

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Thunks/WS2_32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,44 @@ namespace YY::Thunks
}
#endif

#if (YY_Thunks_Target < __WindowsNT6_1_SP1)
#ifndef WSA_FLAG_NO_HANDLE_INHERIT
#define WSA_FLAG_NO_HANDLE_INHERIT 0x80
#endif

__DEFINE_THUNK(
ws2_32,
24,
SOCKET,
WSAAPI,
WSASocketW,
_In_ int af,
_In_ int type,
_In_ int protocol,
_In_opt_ LPWSAPROTOCOL_INFOW lpProtocolInfo,
_In_ GROUP g,
_In_ DWORD dwFlags
)
{
if (auto const pWSASocketW = try_get_WSASocketW())
{
// This include Windows 7 non-SP1
if (internal::GetSystemVersion() <= internal::MakeVersion(6, 1))
{
const auto _pPeb = ((TEB*)NtCurrentTeb())->ProcessEnvironmentBlock;
// This indicates a build version of 7601 on the lower 16-bit
if ((_pPeb->OSBuildNumber & 0xFFFF) != 7601)
{
// This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with SP1, and later
// So we strip it to prevent error on prior OS, because process handle inheritance doesn't really matter at that point
dwFlags &= ~WSA_FLAG_NO_HANDLE_INHERIT;
}
}
return pWSASocketW(af, type, protocol, lpProtocolInfo, g, dwFlags);
}
return INVALID_SOCKET;
}
#endif

#if (YY_Thunks_Target < __WindowsNT6_2)

Expand Down
Loading