Skip to content

Commit

Permalink
move version logic to platform_xyz instead of datapath
Browse files Browse the repository at this point in the history
  • Loading branch information
ProjectsByJackHe committed Jan 8, 2025
1 parent 39c6b52 commit 617cb91
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 62 deletions.
19 changes: 2 additions & 17 deletions src/platform/datapath_winkernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,24 +600,9 @@ CxPlatDataPathQuerySockoptSupport(

} while (FALSE);

do {
RTL_OSVERSIONINFOW osInfo;
RtlZeroMemory(&osInfo, sizeof(osInfo));
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
NTSTATUS status = RtlGetVersion(&osInfo);
if (NT_SUCCESS(status)) {
DWORD BuildNumber = osInfo.dwBuildNumber;
//
// Some USO/URO bug blocks TTL feature support on Windows Server 2022.
//
if (BuildNumber == 20348) {
break;
}
} else {
break;
}
if (CxPlatform.dwBuildNumber != 20348)
Datapath->Features |= CXPLAT_DATAPATH_FEATURE_TTL;
} while (FALSE);
}

Error:

Expand Down
49 changes: 5 additions & 44 deletions src/platform/datapath_winuser.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void
SocketDelete(
_In_ CXPLAT_SOCKET* Socket
);

CXPLAT_EVENT_COMPLETION CxPlatIoRecvEventComplete;
CXPLAT_EVENT_COMPLETION CxPlatIoRecvFailureEventComplete;
CXPLAT_EVENT_COMPLETION CxPlatIoSendEventComplete;
Expand Down Expand Up @@ -524,12 +524,6 @@ CxPlatDataPathQueryRssScalabilityInfo(
}
}

//
// To determine the OS version, we are going to use RtlGetVersion API
// since GetVersion call can be shimmed on Win8.1+.
//
typedef LONG (WINAPI *FuncRtlGetVersion)(RTL_OSVERSIONINFOW *);

QUIC_STATUS
CxPlatDataPathQuerySockoptSupport(
_Inout_ CXPLAT_DATAPATH* Datapath
Expand Down Expand Up @@ -706,27 +700,8 @@ CxPlatDataPathQuerySockoptSupport(
Datapath->Features |= CXPLAT_DATAPATH_FEATURE_RECV_COALESCING;
}
}
//
// TODO: This "TTL_FEATURE check" code works, and mirrors the approach for Kernel mode.
// However, it is considered a "hack" and we should determine whether or not
// the current release story fits this current workaround.
//
HMODULE NtDllHandle = LoadLibraryA("ntdll.dll");
if (NtDllHandle) {
FuncRtlGetVersion VersionFunc = (FuncRtlGetVersion)GetProcAddress(NtDllHandle, "RtlGetVersion");
if (VersionFunc) {
RTL_OSVERSIONINFOW VersionInfo = {0};
VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
if ((*VersionFunc)(&VersionInfo) == 0) {
//
// Some USO/URO bug blocks TTL feature support on Windows Server 2022.
//
if (VersionInfo.dwBuildNumber != 20348) {
Datapath->Features |= CXPLAT_DATAPATH_FEATURE_TTL;
}
}
}
FreeLibrary(NtDllHandle);
if (CxPlatform.dwBuildNumber != 20348) {
Datapath->Features |= CXPLAT_DATAPATH_FEATURE_TTL;
}

Datapath->Features |= CXPLAT_DATAPATH_FEATURE_TCP;
Expand Down Expand Up @@ -844,22 +819,8 @@ DataPathInitialize(
// Check for port reservation support.
//
#ifndef QUIC_UWP_BUILD
HMODULE NtDllHandle = LoadLibraryA("ntdll.dll");
if (NtDllHandle) {
FuncRtlGetVersion VersionFunc = (FuncRtlGetVersion)GetProcAddress(NtDllHandle, "RtlGetVersion");
if (VersionFunc) {
RTL_OSVERSIONINFOW VersionInfo = {0};
VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
if ((*VersionFunc)(&VersionInfo) == 0) {
//
// Only RS5 and newer can use the port reservation feature safely.
//
if (VersionInfo.dwBuildNumber >= 17763) {
Datapath->Features |= CXPLAT_DATAPATH_FEATURE_PORT_RESERVATIONS;
}
}
}
FreeLibrary(NtDllHandle);
if (CxPlatform.dwBuildNumber >= 17763) {
Datapath->Features |= CXPLAT_DATAPATH_FEATURE_PORT_RESERVATIONS;
}
#endif

Expand Down
12 changes: 11 additions & 1 deletion src/platform/platform_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ typedef struct CX_PLATFORM {
//
BCRYPT_ALG_HANDLE RngAlgorithm;

//
// Current Windows build number
//
DWORD dwBuildNumber;

#ifdef DEBUG
//
// 1/Denominator of allocations to fail.
Expand Down Expand Up @@ -305,6 +310,11 @@ typedef struct CX_PLATFORM {
//
HANDLE Heap;

//
// Current Windows build number
//
DWORD dwBuildNumber;

#ifdef DEBUG
//
// 1/Denominator of allocations to fail.
Expand Down Expand Up @@ -747,7 +757,7 @@ CxPlatCryptUninitialize(

//
// Platform Worker APIs
//
//

BOOLEAN
CxPlatWorkerPoolLazyStart(
Expand Down
11 changes: 11 additions & 0 deletions src/platform/platform_winkernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ CxPlatInitialize(
CxPlatProcessorCount =
(uint32_t)KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS);

RTL_OSVERSIONINFOW osInfo;
RtlZeroMemory(&osInfo, sizeof(osInfo));
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
NTSTATUS status = RtlGetVersion(&osInfo);
if (NT_SUCCESS(status)) {
DWORD BuildNumber = osInfo.dwBuildNumber;
CxPlatform.dwBuildNumber = BuildNumber;
} else {
CXPLAT_DBG_ASSERT(FALSE); // TODO: Is the assert here enough or is there an appropritae QUIC_STATUS we return?
}

QUIC_STATUS Status =
BCryptOpenAlgorithmProvider(
&CxPlatform.RngAlgorithm,
Expand Down
22 changes: 22 additions & 0 deletions src/platform/platform_winuser.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ TIMECAPS CxPlatTimerCapabilities;
#endif // TIMERR_NOERROR
QUIC_TRACE_RUNDOWN_CALLBACK* QuicTraceRundownCallback;

//
// To determine the OS version, we are going to use RtlGetVersion API
// since GetVersion call can be shimmed on Win8.1+.
//
typedef LONG (WINAPI *FuncRtlGetVersion)(RTL_OSVERSIONINFOW *);

_IRQL_requires_max_(PASSIVE_LEVEL)
void
CxPlatSystemLoad(
Expand Down Expand Up @@ -242,6 +248,22 @@ CxPlatInitialize(
goto Error;
}

BOOLEAN SuccessfullySetVersion = FALSE;
HMODULE NtDllHandle = LoadLibraryA("ntdll.dll");
if (NtDllHandle) {
FuncRtlGetVersion VersionFunc = (FuncRtlGetVersion)GetProcAddress(NtDllHandle, "RtlGetVersion");
if (VersionFunc) {
RTL_OSVERSIONINFOW VersionInfo = {0};
VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
if ((*VersionFunc)(&VersionInfo) == 0) {
CxPlatform.dwBuildNumber = VersionInfo.dwBuildNumber;
SuccessfullySetVersion = TRUE;
}
}
FreeLibrary(NtDllHandle);
}
CXPLAT_DBG_ASSERT(SuccessfullySetVersion); // TODO: Is the assert here enough or is there an appropritae QUIC_STATUS we return?

if (QUIC_FAILED(Status = CxPlatProcessorInfoInit())) {
QuicTraceEvent(
LibraryError,
Expand Down

0 comments on commit 617cb91

Please sign in to comment.