[*] Removed static IAT lookups to WS2_32.dll

This commit is contained in:
Reece Wilson 2023-12-07 11:13:32 +00:00
parent 8944d8bd16
commit ae70feb29b
11 changed files with 368 additions and 113 deletions

View File

@ -231,6 +231,23 @@ namespace Aurora
ADD_GET_PROC(WS2, FreeAddrInfoExW)
ADD_GET_PROC(WS2, getaddrinfo)
ADD_GET_PROC(WS2, freeaddrinfo)
ADD_GET_PROC(WS2, listen)
ADD_GET_PROC(WS2, bind)
ADD_GET_PROC(WS2, closesocket)
ADD_GET_PROC(WS2, shutdown)
ADD_GET_PROC(WS2, getpeername)
ADD_GET_PROC(WS2, getsockname)
ADD_GET_PROC(WS2, ioctlsocket)
ADD_GET_PROC(WS2, setsockopt)
ADD_GET_PROC(WS2, WSAStartup)
ADD_GET_PROC(WS2, WSAIoctl)
ADD_GET_PROC(WS2, WSAGetLastError)
ADD_GET_PROC(WS2, WSASocketW)
ADD_GET_PROC(WS2, WSARecvFrom)
ADD_GET_PROC(WS2, WSARecv)
ADD_GET_PROC(WS2, WSASendTo)
ADD_GET_PROC(WS2, WSASend)
ADD_GET_PROC(WS2, WSAStringToAddressA)
ADD_GET_PROC(WinTrust, WinVerifyTrust)

View File

@ -268,45 +268,6 @@ namespace Aurora
inline PVOID(__stdcall *pAddDllDirectory)(
PCWSTR NewDirectory
);
inline INT(__stdcall *pGetAddrInfoExCancel)(
LPHANDLE lpHandle
);
using LPLOOKUPSERVICE_COMPLETION_ROUTINE = void(__stdcall *)(
DWORD dwError,
DWORD dwBytes,
LPWSAOVERLAPPED lpOverlapped
);
inline INT(__stdcall *pGetAddrInfoExW)(
PCWSTR pName,
PCWSTR pServiceName,
DWORD dwNameSpace,
LPGUID lpNspId,
const ADDRINFOEXW * hints,
PADDRINFOEXW * ppResult,
struct timeval * timeout,
LPOVERLAPPED lpOverlapped,
LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
LPHANDLE lpHandle
);
inline void(__stdcall *pFreeAddrInfoExW)(
PADDRINFOEXW pAddrInfoEx
);
inline INT(__stdcall *pgetaddrinfo)(
PCSTR pNodeName,
PCSTR pServiceName,
const ADDRINFOA * pHints,
PADDRINFOA * ppResult
);
inline void(__stdcall *pfreeaddrinfo)(
PADDRINFOA pAddrInfo
);
inline BOOL(__stdcall *pPrefetchVirtualMemory)(
HANDLE hProcess,
ULONG_PTR NumberOfEntries,
@ -809,6 +770,7 @@ namespace Aurora
);
// MPR.dll
inline DWORD(__stdcall *pWNetCloseEnum)(
HANDLE hEnum
);
@ -835,6 +797,172 @@ namespace Aurora
LPDWORD lpBufferSize
);
// Winsock2
inline INT(__stdcall *pGetAddrInfoExCancel)(
LPHANDLE lpHandle
);
using LPLOOKUPSERVICE_COMPLETION_ROUTINE = void(__stdcall *)(
DWORD dwError,
DWORD dwBytes,
LPWSAOVERLAPPED lpOverlapped
);
inline INT(__stdcall *pGetAddrInfoExW)(
PCWSTR pName,
PCWSTR pServiceName,
DWORD dwNameSpace,
LPGUID lpNspId,
const ADDRINFOEXW * hints,
PADDRINFOEXW * ppResult,
struct timeval * timeout,
LPOVERLAPPED lpOverlapped,
LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
LPHANDLE lpHandle
);
inline void(__stdcall *pFreeAddrInfoExW)(
PADDRINFOEXW pAddrInfoEx
);
inline INT(__stdcall *pgetaddrinfo)(
PCSTR pNodeName,
PCSTR pServiceName,
const ADDRINFOA * pHints,
PADDRINFOA * ppResult
);
inline void(__stdcall *pfreeaddrinfo)(
PADDRINFOA pAddrInfo
);
inline int(__stdcall *plisten)(
SOCKET s,
int backlog
);
inline int(__stdcall *pbind)(
SOCKET s,
const sockaddr *name,
int namelen
);
inline int(__stdcall *pclosesocket)(
SOCKET s
);
inline int(__stdcall *pWSAStartup)(
WORD wVersionRequested,
LPWSADATA lpWSAData
);
inline int(__stdcall *pshutdown)(
SOCKET s,
int flags
);
inline int(__stdcall *pgetpeername)(
SOCKET s,
sockaddr *name,
int *namelen
);
inline int(__stdcall *pgetsockname)(
SOCKET s,
sockaddr *name,
int *namelen
);
inline int(__stdcall *pWSAIoctl)(
SOCKET s,
DWORD dwIoControlCode,
LPVOID lpvInBuffer,
DWORD cbInBuffer,
LPVOID lpvOutBuffer,
DWORD cbOutBuffer,
LPDWORD lpcbBytesReturned,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
inline int(__stdcall *pioctlsocket)(
SOCKET s,
long cmd,
u_long *argp
);
inline int(__stdcall *psetsockopt)(
SOCKET s,
int level,
int optname,
const char * optval,
int optlen
);
inline int(__stdcall *pWSAGetLastError)();
inline SOCKET(__stdcall *pWSASocketW)(
int af,
int type,
int protocol,
LPWSAPROTOCOL_INFOW lpProtocolInfo,
GROUP g,
DWORD dwFlags
);
inline int(__stdcall *pWSARecvFrom)(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesRecvd,
LPDWORD lpFlags,
sockaddr * lpFrom,
LPINT lpFromlen,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
inline int(__stdcall *pWSARecv)(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesRecvd,
LPDWORD lpFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
inline int(__stdcall *pWSASendTo)(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesSent,
DWORD dwFlags,
const sockaddr * lpTo,
int iTolen,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
inline int(__stdcall *pWSASend)(
SOCKET s,
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesSent,
DWORD dwFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
inline INT(__stdcall *pWSAStringToAddressA)(
LPSTR AddressString,
INT AddressFamily,
LPWSAPROTOCOL_INFOA lpProtocolInfo,
LPSOCKADDR lpAddress,
LPINT lpAddressLength
);
inline bool gUseNativeWaitMutex {};
inline bool gUseNativeWaitCondvar {};
inline bool gUseNativeWaitSemapahore {};

View File

@ -29,7 +29,12 @@ namespace Aurora::IO::Net
int size = sizeof(sastor);
if (::WSAStringToAddressA(AuString(src).data(),
if (!pWSAStringToAddressA)
{
return 0;
}
if (pWSAStringToAddressA(AuString(src).data(),
af,
NULL,
(struct sockaddr *)&sastor,

View File

@ -28,7 +28,10 @@ namespace Aurora::IO::Net
void NetError_SetCurrent(NetError &error)
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
NetError_SetOsError(error, ::WSAGetLastError());
if (pWSAGetLastError)
{
NetError_SetOsError(error, pWSAGetLastError());
}
#elif defined(AURORA_IS_POSIX_DERIVED)
NetError_SetOsError(error, errno);
#endif

View File

@ -70,7 +70,10 @@ namespace Aurora::IO::Net
if (this->osHandle_ &&
this->osHandle_ != -1)
{
::closesocket(this->osHandle_);
if (pclosesocket)
{
pclosesocket(this->osHandle_);
}
this->osHandle_ = 0;
}
}
@ -100,11 +103,19 @@ namespace Aurora::IO::Net
if (this->osHandle_ &&
this->osHandle_ != -1)
{
::closesocket(this->osHandle_);
if (pclosesocket)
{
pclosesocket(this->osHandle_);
}
this->osHandle_ = 0;
}
this->osHandle_ = ::WSASocketW(
if (!pWSASocketW)
{
return;
}
this->osHandle_ = pWSASocketW(
IPToDomain(this->remoteEndpoint_),
TransportToPlatformType(this->remoteEndpoint_),
IPPROTO_IP,
@ -156,11 +167,15 @@ namespace Aurora::IO::Net
bool Socket::PrepareConnectOperations()
{
::setsockopt(this->osHandle_,
if (psetsockopt)
{
// we'll soon find out if this truly failed later on...
(void)psetsockopt(this->osHandle_,
SOL_SOCKET,
SO_UPDATE_CONNECT_CONTEXT,
nullptr,
0);
}
return true;
}
@ -174,7 +189,12 @@ namespace Aurora::IO::Net
{
int iLen { (int)this->endpointSize_ };
if (::getsockname(this->osHandle_, (sockaddr *)this->localEndpoint_.hint, &iLen) == -1)
if (!pgetsockname)
{
return false;
}
if (pgetsockname(this->osHandle_, (sockaddr *)this->localEndpoint_.hint, &iLen) == -1)
{
SysPushErrorIO();
return false;
@ -189,7 +209,12 @@ namespace Aurora::IO::Net
{
int iLen { (int)this->endpointSize_ };
if (::getpeername(this->osHandle_, (sockaddr *)this->remoteEndpoint_.hint, &iLen) == -1)
if (!pgetpeername)
{
return false;
}
if (pgetpeername(this->osHandle_, (sockaddr *)this->remoteEndpoint_.hint, &iLen) == -1)
{
SysPushErrorIO();
return false;
@ -208,7 +233,11 @@ namespace Aurora::IO::Net
AF_UNSPEC;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = 0;
return ::bind(this->osHandle_,
if (!pbind)
{
return false;
}
return pbind(this->osHandle_,
(SOCKADDR *)&addr, sizeof(addr)) == 0;
}
@ -218,7 +247,12 @@ namespace Aurora::IO::Net
GUID guid = WSAID_CONNECTEX;
LPFN_CONNECTEX lpConnectEx {};
if (::WSAIoctl(this->osHandle_,
if (!pWSAIoctl)
{
return false;
}
if (pWSAIoctl(this->osHandle_,
SIO_GET_EXTENSION_FUNCTION_POINTER,
&guid,
sizeof(guid),
@ -264,7 +298,8 @@ namespace Aurora::IO::Net
bool Socket::MakeNonblocking()
{
u_long iMode { 1 };
return ::ioctlsocket(this->osHandle_, FIONBIO, &iMode) == 0;
return pioctlsocket &&
pioctlsocket(this->osHandle_, FIONBIO, &iMode) == 0;
}
void Socket::Shutdown(bool bNow)
@ -272,7 +307,10 @@ namespace Aurora::IO::Net
if (bNow)
{
this->SendEnd();
::shutdown(this->osHandle_, SD_BOTH);
if (pshutdown)
{
pshutdown(this->osHandle_, SD_BOTH);
}
}
else
{

View File

@ -49,13 +49,18 @@ namespace Aurora::IO::Net
this->pSocketDriver_ = AuDynamicCast<SocketServerImpl>(this->SharedFromThis());
this->localEndpoint_ = localAddress;
if (!pWSASocketW)
{
return {};
}
if (!this->SendPreestablish())
{
SysPushErrorIO("Preestablish drop");
return false;
}
this->osHandle_ = ::WSASocketW(
this->osHandle_ = pWSASocketW(
IPToDomain(localAddress),
TransportToPlatformType(localAddress),
IPPROTO_IP,
@ -77,7 +82,11 @@ namespace Aurora::IO::Net
bool SocketServerImpl::ImplBind()
{
if (::bind(this->osHandle_,
if (!pbind)
{
return false;
}
if (pbind(this->osHandle_,
(SOCKADDR *)this->localEndpoint_.hint, this->endpointSize_) != 0)
{
NetError error;
@ -104,7 +113,12 @@ namespace Aurora::IO::Net
We need a sane number between the two. 512 seems reasonable
*/
if (::listen(this->osHandle_, this->uBacklog) != 0)
if (!plisten)
{
return false;
}
if (plisten(this->osHandle_, this->uBacklog) != 0)
{
NetError error;
NetError_SetCurrent(error);

View File

@ -268,7 +268,12 @@ namespace Aurora::IO::Net
{
socklen_t iLen { (int)this->endpointSize_ };
if (::getsockname(this->osHandle_, (sockaddr *)this->localEndpoint_.hint, &iLen) == -1)
if (!pgetsockname)
{
return false;
}
if (pgetsockname(this->osHandle_, (sockaddr *)this->localEndpoint_.hint, &iLen) == -1)
{
SysPushErrorIO();
return false;

View File

@ -40,13 +40,19 @@ namespace Aurora::IO::Net
return;
}
if (!psetsockopt)
{
this->nextSocketPtr->SendErrorNoStream({});
return;
}
SOCKET hListenHandle = (SOCKET)this->pParent_->ToPlatformHandle();
int ret = ::setsockopt(this->nextSocket,
int ret = psetsockopt(this->nextSocket,
SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT,
(char *)&hListenHandle,
sizeof(SOCKET));
auto dwError = WSAGetLastError();
auto dwError = pWSAGetLastError();
if (ret == -1)
{
SysPushErrorNet("Couldn't enable socket after overlapped accept");
@ -149,12 +155,22 @@ namespace Aurora::IO::Net
return;
}
if (!pWSAGetLastError)
{
return;
}
if (!pWSAIoctl)
{
return;
}
GUID GuidAcceptEx = WSAID_ACCEPTEX;
OVERLAPPED a {};
DWORD dwBytes;
a.hEvent = CreateEventA(NULL, true, 0, NULL);
if ((WSAIoctl(this->pParent_->ToPlatformHandle(),
if ((pWSAIoctl(this->pParent_->ToPlatformHandle(),
SIO_GET_EXTENSION_FUNCTION_POINTER,
&GuidAcceptEx,
sizeof(GuidAcceptEx),
@ -163,9 +179,9 @@ namespace Aurora::IO::Net
&dwBytes,
&a,
NULL) != 0) &&
(::WSAGetLastError() != ERROR_IO_PENDING))
(pWSAGetLastError() != ERROR_IO_PENDING))
{
int error = ::WSAGetLastError();
int error = pWSAGetLastError();
SysPushErrorIO();
::CloseHandle(a.hEvent);
return;
@ -178,7 +194,13 @@ namespace Aurora::IO::Net
bool SocketServerAcceptReadOperation::Pretick()
{
auto &localAddress = this->pParent_->GetLocalEndpoint();
nextSocket = ::WSASocketW(
if (!pWSASocketW)
{
return {};
}
nextSocket = pWSASocketW(
IPToDomain(localAddress),
TransportToPlatformType(localAddress),
IPPROTO_IP,

View File

@ -121,7 +121,12 @@ namespace Aurora::IO::Net
if (!this->bDatagramMode)
{
ret = ::WSARecv(this->GetSocket(),
if (!pWSARecv)
{
return this->TranslateLastError(false, true);
}
ret = pWSARecv(this->GetSocket(),
bufferArray,
1,
NULL,
@ -131,8 +136,13 @@ namespace Aurora::IO::Net
}
else
{
if (!pWSARecvFrom)
{
return this->TranslateLastError(false, true);
}
this->iSocketLength = this->pSocket->endpointSize_;
ret = ::WSARecvFrom(this->GetSocket(),
ret = pWSARecvFrom(this->GetSocket(),
bufferArray,
1,
NULL,
@ -213,7 +223,12 @@ namespace Aurora::IO::Net
int ret;
if (!this->bDatagramMode)
{
ret = ::WSASend(this->GetSocket(),
if (!pWSASend)
{
return this->TranslateLastError(false, true);
}
ret = pWSASend(this->GetSocket(),
bufferArray,
1,
NULL,
@ -223,8 +238,13 @@ namespace Aurora::IO::Net
}
else
{
if (!pWSASendTo)
{
return this->TranslateLastError(false, true);
}
this->iSocketLength = this->pSocket->endpointSize_;
ret = ::WSASendTo(this->GetSocket(),
ret = pWSASendTo(this->GetSocket(),
bufferArray,
1,
NULL,
@ -238,9 +258,11 @@ namespace Aurora::IO::Net
return this->TranslateLastError(ret != -1);
}
bool NtAsyncNetworkTransaction::TranslateLastError(bool bReturnValue)
bool NtAsyncNetworkTransaction::TranslateLastError(bool bReturnValue, bool bForceFail)
{
auto er = WSAGetLastError();
auto er = bForceFail ?
ERROR_IO_PREEMPTED :
pWSAGetLastError();
if (bReturnValue)
{
return true;

View File

@ -55,7 +55,7 @@ namespace Aurora::IO::Net
SOCKET GetSocket();
HANDLE GetAlertable();
bool TranslateLastError(bool bReturnValue);
bool TranslateLastError(bool bReturnValue, bool bForceFail = false);
SocketBase * pSocket;
OVERLAPPED overlap {};

View File

@ -23,7 +23,8 @@ namespace Aurora::IO::Net
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 2);
gWin32NetReady = !WSAStartup(wVersionRequested, &wsaData);
gWin32NetReady = pWSAStartup &&
!pWSAStartup(wVersionRequested, &wsaData);
#endif