Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
30 changes: 30 additions & 0 deletions dev/Common/AppModel.Identity.IsPackagedProcess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#ifndef __APPMODEL_IDENTITY_ISPACKAGEDPROCESS_H
#define __APPMODEL_IDENTITY_ISPACKAGEDPROCESS_H

#include <appmodel.h>

namespace AppModel::Identity
{
inline HRESULT IsPackagedProcess_nothrow(bool& isPackagedProcess) noexcept
{
isPackagedProcess = false;
UINT32 n{};
const auto rc{ ::GetCurrentPackageFullName(&n, nullptr) };
RETURN_HR_IF(HRESULT_FROM_WIN32(rc), (rc != APPMODEL_ERROR_NO_PACKAGE) && (rc != ERROR_INSUFFICIENT_BUFFER));
isPackagedProcess = (rc == ERROR_INSUFFICIENT_BUFFER);
return S_OK;
}

inline bool IsPackagedProcess()
{
UINT32 n{};
const auto rc{ ::GetCurrentPackageFullName(&n, nullptr) };
THROW_HR_IF_MSG(HRESULT_FROM_WIN32(rc), (rc != APPMODEL_ERROR_NO_PACKAGE) && (rc != ERROR_INSUFFICIENT_BUFFER), "GetCurrentPackageFullName rc=%d", rc);
return rc == ERROR_INSUFFICIENT_BUFFER;
}
}

#endif // __APPMODEL_IDENTITY_ISPACKAGEDPROCESS_H
9 changes: 2 additions & 7 deletions dev/Common/AppModel.Identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@
#include <memory>
#include <stdint.h>

#include "AppModel.Identity.IsPackagedProcess.h"

namespace AppModel::Identity
{
inline bool IsPackagedProcess()
{
UINT32 n{};
const auto rc{ ::GetCurrentPackageFullName(&n, nullptr) };
THROW_HR_IF_MSG(HRESULT_FROM_WIN32(rc), (rc != APPMODEL_ERROR_NO_PACKAGE) && (rc != ERROR_INSUFFICIENT_BUFFER), "GetCurrentPackageFullName rc=%d", rc);
return rc == ERROR_INSUFFICIENT_BUFFER;
}

template <typename Tstring>
inline Tstring GetCurrentPackageFullName()
Expand Down
1 change: 1 addition & 0 deletions dev/Common/Common.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)AppModel.Identity.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppModel.Identity.IsPackagedProcess.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppModel.Package.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)AppModel.PackageGraph.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Microsoft.Foundation.String.h" />
Expand Down
3 changes: 3 additions & 0 deletions dev/Common/Common.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<ClInclude Include="$(MSBuildThisFileDirectory)AppModel.Identity.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)AppModel.Identity.IsPackagedProcess.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)AppModel.Package.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
17 changes: 17 additions & 0 deletions dev/Common/WindowsAppRuntime.SelfContained.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ inline bool IsSelfContained()
THROW_IF_FAILED(WindowsAppRuntime_IsSelfContained(&isSelfContained));
return !!isSelfContained;
}

/// Non-throwing variant using dynamic loading (safe before DLL is loaded).
inline HRESULT IsSelfContained_nothrow(bool& isSelfContained) noexcept
{
isSelfContained = false;
auto module = ::GetModuleHandleW(L"Microsoft.WindowsAppRuntime.dll");
RETURN_LAST_ERROR_IF_NULL(module);
using IsSelfContainedFn = HRESULT(__stdcall*)(BOOL*);
auto fn = reinterpret_cast<IsSelfContainedFn>(
::GetProcAddress(module, "WindowsAppRuntime_IsSelfContained"));
RETURN_LAST_ERROR_IF_NULL(fn);
BOOL result{};
const auto hr{ fn(&result) };
RETURN_IF_FAILED(hr);
isSelfContained = !!result;
return S_OK;
}
}
#endif // defined(__cplusplus)

Expand Down
2 changes: 1 addition & 1 deletion dev/MRTCore/mrt/Core/src/MRM.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<ClCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;UNICODE;_UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(MRTCoreRoot)\mrt\mrm\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(MRTCoreRoot)\mrt\mrm\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>$(OutDir)..\mrmmin\mrmmin.lib;rpcrt4.lib;onecoreuap.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
4 changes: 2 additions & 2 deletions dev/MRTCore/mrt/mrm/UnitTests/MrmBaseUnitTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(MRTCoreRoot)\mrt\mrm\include;$(MRTCoreRoot)\mrt\mrm\mrmmin;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(MRTCoreRoot)\mrt\mrm\include;$(MRTCoreRoot)\mrt\mrm\mrmmin;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4309;4838;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(MRTCoreRoot)\mrt\mrm\include;$(MRTCoreRoot)\mrt\mrm\mrmmin;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(MRTCoreRoot)\mrt\mrm\include;$(MRTCoreRoot)\mrt\mrm\mrmmin;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4309;4838;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
Expand Down
2 changes: 1 addition & 1 deletion dev/MRTCore/mrt/mrm/mrmex/mrmex.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(MRTCoreRoot)\mrt\mrm\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(MRTCoreRoot)\mrt\mrm\include</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
Expand Down
2 changes: 1 addition & 1 deletion dev/MRTCore/mrt/mrm/mrmmin/mrmmin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(MRTCoreRoot)\mrt\mrm\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(MRTCoreRoot)\mrt\mrm\include</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -112,7 +112,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -122,7 +122,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -132,7 +132,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -143,7 +143,7 @@
<ClCompile>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -154,7 +154,7 @@
<ClCompile>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory);$(RepoRoot)\dev\WindowsAppRuntime_Insights;$(RepoRoot)\dev\common;$(OutDir)..\PushNotificationsLongRunningTask.ProxyStub;$(OutDir)\..\WindowsAppRuntime_DLL;$(OutDir)..\WindowsAppSDK_BootstrapDLL</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace Microsoft.Windows.ApplicationModel.WindowsAppRuntime
AppLifecycle_SharedMemoryRedirectionQueueFix = 60972838,
SplitMenuFlyoutItem_Available = 60878987,
TextIntelligence_Insights = 61106039,

// 1.8.7
AppRuntime_Insights = 61555948,
};

/// Represents a version of the Windows App Runtime.
Expand Down
68 changes: 67 additions & 1 deletion dev/WindowsAppRuntime_Insights/WindowsAppRuntimeInsights.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@

#include <wil/resource.h>
#include <string>
#include <appmodel.h>
#include <FrameworkUdk/Containment.h>

// Bug 61555948: [1.8.6 servicing] AppRuntime_Insights - Add IsPackagedProcess and IsSelfContained to common insights PartB fields
#define WINAPPSDK_CHANGEID_61555948 61555948, WinAppSDK_1_8_7
namespace Microsoft::WindowsAppRuntime::Insights
{
enum class TraceLoggingInformationFlags : std::uint32_t
{
None = 0,
IsDebuggerPresent = 0x00000001,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this flag factoring is compact - just want to confirm it's actually useful in reports. i.e., can you filter on specific bit values, or is it just an opaque number? if the latter, I'd stick with unique values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can query individual bits, Kusto has bitwise operators like binary_and. And since there's only 3 bits, each combo maps to a unique value (0–7) so we can also filter on the number directly if that's easier. This was Howard's design from #6233 to keep the struct at 4 fields

IsPackagedProcess = 0x00000002,
IsSelfContained = 0x00000004,
};
DEFINE_ENUM_FLAG_OPERATORS(TraceLoggingInformationFlags)

class RuntimeInformation
{
public:
Expand All @@ -32,6 +46,58 @@
return channel;
}

// Inlined from the canonical implementations (see for reference):
// IsPackagedProcess: dev/Common/AppModel.Identity.IsPackagedProcess.h
// IsSelfContained: dev/Common/WindowsAppRuntime.SelfContained.h / .cpp
// Duplicated here to avoid exposing those headers as public API.
static std::uint32_t TraceLoggingInformationFlags()
{
static std::uint32_t flags{ []() -> std::uint32_t {
auto f{ Insights::TraceLoggingInformationFlags::None };

if (wil::details::IsDebuggerPresent())
{
f |= Insights::TraceLoggingInformationFlags::IsDebuggerPresent;
}

if (WinAppSdk::Containment::IsChangeEnabled<WINAPPSDK_CHANGEID_61555948>())
{
{
UINT32 n{};
const auto rc{ ::GetCurrentPackageFullName(&n, nullptr) };
if ((rc != APPMODEL_ERROR_NO_PACKAGE) && (rc != ERROR_INSUFFICIENT_BUFFER))
{
LOG_HR(HRESULT_FROM_WIN32(rc));
}
else if (rc == ERROR_INSUFFICIENT_BUFFER)
{
f |= Insights::TraceLoggingInformationFlags::IsPackagedProcess;
}
}

{
auto module{ ::GetModuleHandleW(L"Microsoft.WindowsAppRuntime.dll") };
if (module)
{
using IsSelfContainedFn = HRESULT(__stdcall*)(BOOL*);
auto fn{ reinterpret_cast<IsSelfContainedFn>(::GetProcAddress(module, "WindowsAppRuntime_IsSelfContained")) };
if (fn)
{
BOOL result{};
if (SUCCEEDED_LOG(fn(&result)) && result)
{
f |= Insights::TraceLoggingInformationFlags::IsSelfContained;
}
}
}
}
}

return static_cast<std::uint32_t>(f);
}() };
return flags;
}

private:
static std::string LoadStringFromResource(uint32_t id)
{
Expand Down Expand Up @@ -60,7 +126,7 @@
TraceLoggingStruct(4, "COMMON_WINDOWSAPPSDK_PARAMS"), \
TraceLoggingString(::Microsoft::WindowsAppRuntime::Insights::RuntimeInformation::WindowsAppRuntimeVersion().c_str(), "Version"), \
TraceLoggingString(::Microsoft::WindowsAppRuntime::Insights::RuntimeInformation::WindowsAppRuntimeChannel().c_str(), "WindowsAppSDKChannel"), \
TraceLoggingBool(wil::details::IsDebuggerPresent(), "IsDebugging"), \
TraceLoggingUInt32(::Microsoft::WindowsAppRuntime::Insights::RuntimeInformation::TraceLoggingInformationFlags(), "Flags"), \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely not contained. For that reason alone, I'd go with conditional logging of separate bools. Probably makes reporting easier too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data values should be contained, when the change is off we just report the debugger bit (0 or 1), same as the old IsDebugging bool. The field name/type is compile-time metadata though, so I'm not sure how to contain that part without duplicating every TraceLoggingWrite call across the ~20 callsites. Open to ideas!

TraceLoggingBool(true, "UTCReplace_AppSessionGuid")

#include <wil/tracelogging.h>
Expand Down