Skip to content

Commit 841eb85

Browse files
Cleanup Win7 and earlier compatibility from CoreCLR (#122884)
When running on Windows, we are now always running on Win8. We also don't need to delay-load the WinRT APIs used by CoreCLR anymore as they're always available. We can also remove the delay loading for version.dll now that we pass `/DEPENDENTLOADFLAG:0x800` to force dependencies to be loaded from System32 (the original reason for the delay load hook was to force System32 instead of the default lookup rules for the commonly named `version.dll`). --------- Co-authored-by: Copilot <[email protected]>
1 parent 78d6652 commit 841eb85

File tree

7 files changed

+5
-129
lines changed

7 files changed

+5
-129
lines changed

src/coreclr/dlls/mscoree/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ set(CLR_SOURCES
1111

1212
if(CLR_CMAKE_TARGET_WIN32)
1313
list(APPEND CLR_SOURCES
14-
${CLR_SRC_NATIVE_DIR}/libs/Common/delayloadhook_windows.cpp
15-
Native.rc
14+
Native.rc
1615
)
17-
1816
set (DEF_SOURCES
1917
mscorwks_ntdef.src
2018
)

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ if (CLR_CMAKE_HOST_WIN32)
2121
# invariants (e.g. size of region between Jit_PatchedCodeLast-Jit_PatchCodeStart needs to fit in a page).
2222
add_linker_flag("/INCREMENTAL:NO")
2323

24-
# Delay load libraries required for WinRT as that is not supported on all platforms
25-
add_linker_flag("/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll")
26-
27-
# Delay load version.dll so that we can specify how to search when loading it as it is not part of Windows' known DLLs
28-
add_linker_flag("/DELAYLOAD:version.dll")
29-
3024
# No library groups for Win32
3125
set(START_LIBRARY_GROUP)
3226
set(END_LIBRARY_GROUP)
@@ -131,7 +125,6 @@ if(CLR_CMAKE_TARGET_WIN32)
131125
shlwapi.lib
132126
bcrypt.lib
133127
RuntimeObject.lib
134-
delayimp.lib
135128
)
136129
else()
137130
list(APPEND CORECLR_LIBRARIES

src/coreclr/inc/ostype.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,6 @@
1212
#define LIMITED_METHOD_CONTRACT
1313
#endif
1414

15-
//*****************************************************************************
16-
// Enum to track which version of the OS we are running
17-
// Note that Win7 is the minimum supported platform. Any code using
18-
// utilcode (which includes the CLR's execution engine) will fail to start
19-
// on a pre-Win7 platform. This is enforced by InitRunningOnVersionStatus.
20-
//*****************************************************************************
21-
typedef enum {
22-
RUNNING_ON_STATUS_UNINITED = 0,
23-
RUNNING_ON_WIN7 = 1,
24-
RUNNING_ON_WIN8 = 2
25-
} RunningOnStatusEnum;
26-
27-
extern RunningOnStatusEnum gRunningOnStatus;
28-
29-
void InitRunningOnVersionStatus();
30-
31-
//*****************************************************************************
32-
// Returns true if you are running on Windows 8 or newer.
33-
//*****************************************************************************
34-
inline BOOL RunningOnWin8()
35-
{
36-
WRAPPER_NO_CONTRACT;
37-
#if (!defined(HOST_X86) && !defined(HOST_AMD64))
38-
return TRUE;
39-
#else
40-
if (gRunningOnStatus == RUNNING_ON_STATUS_UNINITED)
41-
{
42-
InitRunningOnVersionStatus();
43-
}
44-
45-
return (gRunningOnStatus >= RUNNING_ON_WIN8) ? TRUE : FALSE;
46-
#endif
47-
}
48-
49-
#ifdef FEATURE_COMINTEROP
50-
51-
inline BOOL WinRTSupported()
52-
{
53-
return RunningOnWin8();
54-
}
55-
56-
#endif // FEATURE_COMINTEROP
57-
5815
#ifdef HOST_64BIT
5916
inline BOOL RunningInWow64()
6017
{

src/coreclr/utilcode/util_nodependencies.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,8 @@
1414
#include "utilcode.h"
1515
#include "ex.h"
1616

17-
#ifdef HOST_WINDOWS
18-
#include <versionhelpers.h>
19-
#endif
20-
2117
#if !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) || defined(_DEBUG)
2218

23-
RunningOnStatusEnum gRunningOnStatus = RUNNING_ON_STATUS_UNINITED;
24-
25-
#define NON_SUPPORTED_PLATFORM_TERMINATE_ERROR_CODE 0xBAD1BAD1
26-
27-
//*****************************************************************************
28-
// One time initialization of the OS version
29-
//*****************************************************************************
30-
void InitRunningOnVersionStatus ()
31-
{
32-
#ifdef HOST_WINDOWS
33-
STATIC_CONTRACT_NOTHROW;
34-
STATIC_CONTRACT_GC_NOTRIGGER;
35-
STATIC_CONTRACT_CANNOT_TAKE_LOCK;
36-
37-
if(IsWindows8OrGreater())
38-
{
39-
gRunningOnStatus = RUNNING_ON_WIN8;
40-
}
41-
else if(IsWindows7OrGreater())
42-
{
43-
gRunningOnStatus = RUNNING_ON_WIN7;
44-
}
45-
else
46-
{
47-
// The current platform isn't supported. Display a message to this effect and exit.
48-
minipal_log_print_error("Platform not supported: Windows 7 is the minimum supported version\n");
49-
TerminateProcess(GetCurrentProcess(), NON_SUPPORTED_PLATFORM_TERMINATE_ERROR_CODE);
50-
}
51-
#endif // HOST_WINDOWS
52-
} // InitRunningOnVersionStatus
53-
5419
#ifndef HOST_64BIT
5520
//------------------------------------------------------------------------------
5621
// Returns TRUE if we are running on a 64-bit OS in WoW, FALSE otherwise.

src/coreclr/vm/threads.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,6 @@ void Thread::BaseWinRTUninitialize()
23632363
STATIC_CONTRACT_GC_TRIGGERS;
23642364
STATIC_CONTRACT_MODE_PREEMPTIVE;
23652365

2366-
_ASSERTE(WinRTSupported());
23672366
_ASSERTE(GetThread() == this);
23682367
_ASSERTE(IsWinRTInitialized());
23692368

@@ -2401,7 +2400,6 @@ void Thread::CoUninitialize()
24012400
#ifdef FEATURE_COMINTEROP
24022401
if (IsWinRTInitialized())
24032402
{
2404-
_ASSERTE(WinRTSupported());
24052403
BaseWinRTUninitialize();
24062404
ResetWinRTInitialized();
24072405
}
@@ -2612,7 +2610,6 @@ void Thread::CleanupCOMState()
26122610
#ifdef FEATURE_COMINTEROP
26132611
if (IsWinRTInitialized())
26142612
{
2615-
_ASSERTE(WinRTSupported());
26162613
BaseWinRTUninitialize();
26172614
ResetWinRTInitialized();
26182615
}
@@ -3783,7 +3780,6 @@ Thread::ApartmentState Thread::SetApartment(ApartmentState state)
37833780
#ifdef FEATURE_COMINTEROP
37843781
if (IsWinRTInitialized())
37853782
{
3786-
_ASSERTE(WinRTSupported());
37873783
BaseWinRTUninitialize();
37883784
ResetWinRTInitialized();
37893785
}
@@ -3875,10 +3871,10 @@ Thread::ApartmentState Thread::SetApartment(ApartmentState state)
38753871
_ASSERTE(!"Unexpected HRESULT returned from CoInitializeEx!");
38763872
}
38773873

3878-
// If WinRT is supported on this OS, also initialize it at the same time. Since WinRT sits on top of COM
3879-
// we need to make sure that it is initialized in the same threading mode as we just started COM itself
3874+
// Since WinRT sits on top of COM we need to make sure that it is initialized
3875+
// in the same threading mode as we just started COM itself
38803876
// with (or that we detected COM had already been started with).
3881-
if (WinRTSupported() && !IsWinRTInitialized())
3877+
if (!IsWinRTInitialized())
38823878
{
38833879
GCX_PREEMP();
38843880

src/native/corehost/apphost/static/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ if(CLR_CMAKE_TARGET_WIN32)
6161
add_compile_definitions(UNICODE)
6262
list(APPEND SOURCES
6363
../apphost.windows.cpp
64-
${CLR_SRC_NATIVE_DIR}/libs/Common/delayloadhook_windows.cpp
6564
)
6665

6766
list(APPEND HEADERS
@@ -119,12 +118,6 @@ if(CLR_CMAKE_TARGET_WIN32)
119118
# Incremental linking results in the linker inserting extra padding and routing function calls via thunks that can break the
120119
# invariants (e.g. size of region between Jit_PatchedCodeLast-Jit_PatchCodeStart needs to fit in a page).
121120
add_linker_flag("/INCREMENTAL:NO")
122-
123-
# Delay load libraries required for WinRT as that is not supported on all platforms
124-
add_linker_flag("/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll")
125-
126-
# Delay load version.dll so that we can specify how to search when loading it as it is not part of Windows' known DLLs
127-
add_linker_flag("/DELAYLOAD:version.dll")
128121
endif()
129122

130123
if(CLR_CMAKE_TARGET_WIN32)
@@ -145,7 +138,6 @@ if(CLR_CMAKE_TARGET_WIN32)
145138
shell32.lib
146139
bcrypt.lib
147140
RuntimeObject.lib
148-
delayimp.lib
149141
)
150142

151143
# additional requirements for System.IO.Compression.Native
@@ -309,4 +301,4 @@ add_sanitizer_runtime_support(singlefilehost)
309301

310302
if (CLR_CMAKE_HOST_APPLE)
311303
adhoc_sign_with_entitlements(singlefilehost "${CLR_ENG_NATIVE_DIR}/entitlements.plist")
312-
endif()
304+
endif()

src/native/libs/Common/delayloadhook_windows.cpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)