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

Reapply "Delegate to OS RegFreeWinRT when available (>=24H1) (#4728)" (#4935) #4949

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions WindowsAppRuntime.sln
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BaseNotifications", "dev\Notifications\BaseNotifications\BaseNotifications.vcxitems", "{2BD7A1BB-D3D8-484F-9180-409D781DCCF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Windows.BadgeNotifications.Projection", "dev\Projections\CS\Microsoft.Windows.BadgeNotifications.Projection\Microsoft.Windows.BadgeNotifications.Projection.csproj", "{A243A58D-ABD7-4520-8C71-F492247B7B92}"
ProjectSection(ProjectDependencies) = postProject
{B73AD907-6164-4294-88FB-F3C9C10DA1F1} = {B73AD907-6164-4294-88FB-F3C9C10DA1F1}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CompatibilityOptions", "dev\CompatibilityOptions\CompatibilityOptions.vcxitems", "{1F7B9E9F-9987-490B-9E6E-093C7F63FEC4}"
EndProject
Expand All @@ -603,6 +606,10 @@ EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "OAuthTestAppPackage", "test\TestApps\OAuthTestAppPackage\OAuthTestAppPackage.wapproj", "{455C01F8-0A3E-42C4-9F22-13992EB909EC}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OAuth2ManagerTests", "test\OAuth2ManagerTests\OAuth2ManagerTests.vcxproj", "{0FF6A68F-6C7F-4E66-8CB8-C0B9501060CA}"
ProjectSection(ProjectDependencies) = postProject
{455C01F8-0A3E-42C4-9F22-13992EB909EC} = {455C01F8-0A3E-42C4-9F22-13992EB909EC}
{B73AD907-6164-4294-88FB-F3C9C10DA1F1} = {B73AD907-6164-4294-88FB-F3C9C10DA1F1}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
13 changes: 12 additions & 1 deletion build/AzurePipelinesTemplates/WindowsAppSDK-RunTests-Steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ steps:
inputs:
targetType: filePath
filePath: tools\DevCheck\DevCheck.ps1
arguments: -NoInteractive -Offline -Verbose -CheckTestPfx -Clean -CheckDependencies -ShowSystemInfo
arguments: -NoInteractive -Offline -Verbose -CheckTestPfx -Clean -CheckDependencies -CheckVisualStudio -ShowSystemInfo
workingDirectory: '$(Build.SourcesDirectory)'

- task: DownloadPipelineArtifact@2
Expand Down Expand Up @@ -147,6 +147,17 @@ steps:
Write-Host "WhoAmI"
Write-Host (whoami /user /groups /priv)

- task: PowerShell@2
displayName: 'Dump services'
inputs:
targetType: 'inline'
script: |
Get-Service
Get-Service | Write-Host
Get-Service | Out-Host
sc.exe queryex te.service | Write-Host
sc.exe qc te.service | Write-Host

- task: PowerShell@2
displayName: 'Run TAEF Tests'
inputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ steps:
inputs:
targetType: filePath
filePath: tools\DevCheck\DevCheck.ps1
arguments: -NoInteractive -Offline -Verbose -CheckTestPfx -Clean -CheckDependencies -ShowSystemInfo
arguments: -NoInteractive -Offline -Verbose -CheckTestPfx -Clean -CheckDependencies -CheckVisualStudio -ShowSystemInfo
workingDirectory: '$(Build.SourcesDirectory)'

- task: PowerShell@2
Expand Down
17 changes: 11 additions & 6 deletions dev/Common/IsWindowsVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,35 @@ inline bool IsExportPresent(

inline bool IsWindows10_19H1OrGreater()
{
// GetPackageInfo2() added to kernelbase.dll in NTDDI_WIN10_19H1 (aka 19H1)
// GetPackageInfo2() added to kernelbase.dll in 19H1 (aka NTDDI_WIN10_19H1)
return IsExportPresent(L"kernelbase.dll", "GetPackageInfo2");
}

inline bool IsWindows10_20H1OrGreater()
{
// GetPackageInfo3() added to kernelbase.dll in NTDDI_WIN10_VB (aka 20H1)
// GetPackageInfo3() added to kernelbase.dll in 20H1 (aka NTDDI_WIN10_VB)
return IsExportPresent(L"kernelbase.dll", "GetPackageInfo3");
}
inline bool IsWindows11_21H2OrGreater()
{
// GetMachineTypeAttributes() added to kernelbase.dll in NTDDI_WIN10_CO (aka Windows 11 21H2)
// GetMachineTypeAttributes() added to kernelbase.dll in Windows 11 21H2 (aka NTDDI_WIN10_CO)
return IsExportPresent(L"kernelbase.dll", "GetMachineTypeAttributes");
}
inline bool IsWindows11_22H2OrGreater()
{
// GetPackageGraphRevisionId() added to kernelbase.dll in NTDDI_WIN10_NI (aka Windows 11 22H2)
// GetPackageGraphRevisionId() added to kernelbase.dll in Windows 11 22H2 (aka NTDDI_WIN10_NI)
return IsExportPresent(L"kernelbase.dll", "GetPackageGraphRevisionId");
}
inline bool IsWindows11_23H1OrGreater()
inline bool IsWindows11_24H1OrGreater()
{
// TryCreatePackageDependency2() added to in NTDDI_WIN10_GE (aka Windows 11 23H1)
// TryCreatePackageDependency2() added to in Windows 11 24H1 (aka NTDDI_WIN11_GE)
return IsExportPresent(L"kernelbase.dll", "TryCreatePackageDependency2");
}
inline bool IsWindows11_24H2OrGreater()
{
// MsixIsPackageFeatureSupported() added to in Windows 11 24H2 (aka NTDDI_WIN11_GE)
return IsExportPresent(L"appxdeploymentclient.dll", "MsixIsPackageFeatureSupported");
}
}

#endif // __ISWINDOWSVERSION_H
49 changes: 37 additions & 12 deletions dev/DynamicDependency/API/MddWin11.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <MsixDynamicDependency.h>

#include <IsWindowsVersion.h>
#include <AppModel.Identity.h>

namespace MddCore::Win11
{
Expand Down Expand Up @@ -41,7 +42,7 @@ namespace MddCore::Win11
__declspec(selectany) HMODULE g_dllApisetAppmodelRuntime_1_7{};
//TODO:47775758 GetResolved2 __declspec(selectany) decltype(&::GetResolvedPackageFullNameForPackageDependency2) g_win11GetResolvedPackageFullNameForPackageDependency2{};

__declspec(selectany) bool g_isSupported{ WindowsVersion::IsWindows11_22H2OrGreater() };
__declspec(selectany) bool g_isSupported{ WindowsVersion::IsWindows11_24H1OrGreater() };

constexpr PackageDependencyLifetimeKind ToLifetimeKind(MddPackageDependencyLifetimeKind lifetimeKind)
{
Expand Down Expand Up @@ -95,18 +96,48 @@ namespace MddCore::Win11

inline bool IsSupported()
{
#if defined(TODO_WindowsAppSDKAggregator_Test_Failures)
return MddCore::Win11::details::g_isSupported;
#else
return false;
#endif
}

inline bool IsGetResolvedPackageFullNameForPackageDependency2Supported()
{
return IsSupported() && MddCore::Win11::details::g_dllApisetAppmodelRuntime_1_7;
}

constexpr PackageDependencyProcessorArchitectures GetPackageDependencyProcessorArchitecturesCompatibleWithCallerArchitecture()
{
#if defined(_M_ARM)
return PackageDependencyProcessorArchitectures_Arm | PackageDependencyProcessorArchitectures_Neutral;
#elif defined(_M_ARM64)
return PackageDependencyProcessorArchitectures_Arm64 | PackageDependencyProcessorArchitectures_Neutral;
#elif defined(_M_IX86)
return PackageDependencyProcessorArchitectures_X86 | PackageDependencyProcessorArchitectures_Neutral;
#elif defined(_M_X64)
return PackageDependencyProcessorArchitectures_X64 | PackageDependencyProcessorArchitectures_Neutral;
#else
# error "Unknown processor architecture"
#endif
}

constexpr PackageDependencyProcessorArchitectures ToPackageDependencyProcessorArchitectures(
const MddPackageDependencyProcessorArchitectures packageDependencyProcessorArchitectures)
{
if (packageDependencyProcessorArchitectures == MddPackageDependencyProcessorArchitectures::None)
{
// Workaround Windows bug (https://task.ms/54835001) that doesn't treat PackageDependencyProcessorArchitectures::None equivalent to caller-architecture + Neutral
return GetPackageDependencyProcessorArchitecturesCompatibleWithCallerArchitecture();
}

auto win11PackageDependencyProcessorArchitectures{ PackageDependencyProcessorArchitectures_None };
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_Neutral, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::Neutral));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_X86, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::X86));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_X64, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::X64));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_Arm, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::Arm));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_Arm64, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::Arm64));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_X86A64, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::X86OnArm64));
return win11PackageDependencyProcessorArchitectures;
}

inline HRESULT TryCreatePackageDependency(
PSID user,
_In_ PCWSTR packageFamilyName,
Expand All @@ -119,13 +150,7 @@ namespace MddCore::Win11
{
const ::AppModel::Identity::PackageVersion win11MinVersion{ minVersion };

auto win11PackageDependencyProcessorArchitectures{ PackageDependencyProcessorArchitectures_None };
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_Neutral, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::Neutral));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_X86, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::X86));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_X64, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::X64));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_Arm, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::Arm));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_Arm64, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::Arm64));
WI_SetFlagIf(win11PackageDependencyProcessorArchitectures, PackageDependencyProcessorArchitectures_X86A64, WI_IsFlagSet(packageDependencyProcessorArchitectures, MddPackageDependencyProcessorArchitectures::X86OnArm64));
auto win11PackageDependencyProcessorArchitectures{ ToPackageDependencyProcessorArchitectures(packageDependencyProcessorArchitectures) };

const auto win11LifetimeKind{ MddCore::Win11::details::ToLifetimeKind(lifetimeKind) };

Expand Down
2 changes: 1 addition & 1 deletion dev/MRTCore/mrt/Core/unittests/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Taef" version="10.94.240624002" targetFramework="native" />
<package id="Microsoft.Taef" version="10.95.240918004" targetFramework="native" />
</packages>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Taef" version="10.94.240624002" targetFramework="net45" />
<package id="Microsoft.Taef" version="10.95.240918004" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion dev/MRTCore/mrt/mrm/UnitTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240803.1" targetFramework="native" />
<package id="Microsoft.Taef" version="10.94.240624002" targetFramework="native" />
<package id="Microsoft.Taef" version="10.95.240918004" targetFramework="native" />
</packages>
11 changes: 8 additions & 3 deletions dev/PackageManager/API/M.W.M.D.PackageDeploymentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ namespace winrt::Microsoft::Windows::Management::Deployment::implementation
{
case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::PackageUriScheme_ms_uup:
{
//TODO Feature lookup
// Relies on PackageManagement_IsFeatureSupported(L"PackageUriScheme.ms-uup") exist in Microsoft.FrameworkUdk and enabled
return ::WindowsVersion::IsExportPresent(L"appxdeploymentclient.dll", "MsixRemovePackageByUriAsync");
BOOL isSupported{};
const HRESULT hr{ PackageManagement_IsFeatureSupported(L"PackageUriScheme.ms-uup", &isSupported) };
if (hr == E_NOTIMPL)
{
return false;
}
THROW_IF_FAILED_MSG(hr, "PackageUriScheme_ms_uup");
return !!isSupported;
}
case winrt::Microsoft::Windows::Management::Deployment::PackageDeploymentFeature::IsPackageReadyOrNewerAvailable:
{
Expand Down
46 changes: 38 additions & 8 deletions dev/UndockedRegFreeWinRT/urfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <activation.h>
#include <VersionHelpers.h>

#include <IsWindowsVersion.h>

#include "urfw.h"

#include "catalog.h"
Expand Down Expand Up @@ -58,18 +60,18 @@ static decltype(RoGetActivationFactory)* TrueRoGetActivationFactory = RoGetActiv
static decltype(RoGetMetaDataFile)* TrueRoGetMetaDataFile = RoGetMetaDataFile;
static decltype(RoResolveNamespace)* TrueRoResolveNamespace = RoResolveNamespace;

static bool g_apisAreDetoured{};

enum class ActivationLocation
{
CurrentApartment,
CrossApartmentMTA
};

VOID CALLBACK EnsureMTAInitializedCallBack
(
VOID CALLBACK EnsureMTAInitializedCallBack(
PTP_CALLBACK_INSTANCE /*instance*/,
PVOID /*parameter*/,
PTP_WORK /*work*/
)
PTP_WORK /*work*/)
{
Microsoft::WRL::ComPtr<IComThreadingInfo> spThreadingInfo;
CoGetObjectContext(IID_PPV_ARGS(&spThreadingInfo));
Expand Down Expand Up @@ -405,10 +407,34 @@ HRESULT ExtRoLoadCatalog()

HRESULT UrfwInitialize() noexcept
{
#if defined(TODO_URFW_DELEGATE_TO_OS_19H1PLUS)
// Windows' Reg-Free WinRT first appeared in Windows 10 Version 1903, May 2019 Update (aka 19H1)
// https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components/
// Delegate to the OS' implementation when available
if (WindowsVersion::IsWindows10_19H1OrGreater())
{
return S_OK;
}
#elif defined(TODO_SEEME_PRODUCT_TARGET)
// Delegate to the OS' implementation on >= Windows 11 24H1
if (WindowsVersion::IsWindows11_22H2OrGreater())
{
return S_OK;
}
#else
// Delegate to the OS' implementation on >= Windows 11 24H1
if (WindowsVersion::IsWindows11_24H1OrGreater())
{
return S_OK;
}
#endif

// OS Reg-Free WinRT isn't available so let's do it ourselves...
DetourAttach(&(PVOID&)TrueRoActivateInstance, RoActivateInstanceDetour);
DetourAttach(&(PVOID&)TrueRoGetActivationFactory, RoGetActivationFactoryDetour);
DetourAttach(&(PVOID&)TrueRoGetMetaDataFile, RoGetMetaDataFileDetour);
DetourAttach(&(PVOID&)TrueRoResolveNamespace, RoResolveNamespaceDetour);
g_apisAreDetoured = true;
try
{
RETURN_IF_FAILED(ExtRoLoadCatalog());
Expand All @@ -422,10 +448,14 @@ HRESULT UrfwInitialize() noexcept

void UrfwShutdown() noexcept
{
DetourDetach(&(PVOID&)TrueRoActivateInstance, RoActivateInstanceDetour);
DetourDetach(&(PVOID&)TrueRoGetActivationFactory, RoGetActivationFactoryDetour);
DetourDetach(&(PVOID&)TrueRoGetMetaDataFile, RoGetMetaDataFileDetour);
DetourDetach(&(PVOID&)TrueRoResolveNamespace, RoResolveNamespaceDetour);
if (g_apisAreDetoured)
{
DetourDetach(&(PVOID&)TrueRoActivateInstance, RoActivateInstanceDetour);
DetourDetach(&(PVOID&)TrueRoGetActivationFactory, RoGetActivationFactoryDetour);
DetourDetach(&(PVOID&)TrueRoGetMetaDataFile, RoGetMetaDataFileDetour);
DetourDetach(&(PVOID&)TrueRoResolveNamespace, RoResolveNamespaceDetour);
g_apisAreDetoured = false;
}
}

extern "C" void WINAPI winrtact_Initialize()
Expand Down
2 changes: 1 addition & 1 deletion eng/Version.Dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Dependency Name="Microsoft.Build.Tasks.Git" Version="1.1.1"/>
<Dependency Name="Microsoft.SourceLink.Common" Version="1.1.1"/>
<Dependency Name="Microsoft.SourceLink.GitHub" Version="1.1.1"/>
<Dependency Name="Microsoft.Taef" Version="10.94.240624002"/>
<Dependency Name="Microsoft.Taef" Version="10.95.240918004"/>
<Dependency Name="Microsoft.Telemetry.Inbox.Native" Version="10.0.19041.1-191206-1406.vb-release.x86fre" />
<Dependency Name="Microsoft.Windows.CppWinRT" Version="2.0.230706.1"/>
<Dependency Name="Microsoft.Windows.ImplementationLibrary" Version="1.0.240803.1"/>
Expand Down
2 changes: 1 addition & 1 deletion installer/test/InstallerFunctionalTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Taef" version="10.94.240624002" targetFramework="native" />
<package id="Microsoft.Taef" version="10.95.240918004" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.230706.1" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240803.1" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion test/AccessControlTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Taef" version="10.94.240624002" targetFramework="native" />
<package id="Microsoft.Taef" version="10.95.240918004" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.230706.1" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion test/AppLifecycle/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Taef" version="10.94.240624002" targetFramework="native" />
<package id="Microsoft.Taef" version="10.95.240918004" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.230706.1" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240803.1" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion test/AppNotificationBuilderTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Taef" version="10.94.240624002" targetFramework="native" />
<package id="Microsoft.Taef" version="10.95.240918004" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.230706.1" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240803.1" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion test/AppNotificationTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Taef" version="10.94.240624002" targetFramework="native" />
<package id="Microsoft.Taef" version="10.95.240918004" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.230706.1" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240803.1" targetFramework="native" />
</packages>
Loading