Skip to content

Commit

Permalink
Add an NT service to DevHome (microsoft#3706)
Browse files Browse the repository at this point in the history
* NT service

* Maybe fix build break

* Potiential build break fix

* PR feedback

* Updated architecture doc

* Fix build breaks?

* Build break fix?

* Implementation

* Functional

* Fix build break

* Added fast rundown

* Updates

* Updates

* Enabled Fast COM rundown and lifetime management

* PR feedback
  • Loading branch information
timkur authored Aug 29, 2024
1 parent e320a7a commit 963723c
Show file tree
Hide file tree
Showing 25 changed files with 934 additions and 4 deletions.
108 changes: 108 additions & 0 deletions DevHome.sln
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.FileExplorerSourceC
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.FileExplorerSourceControlIntegrationUnitTest", "tools\Customization\DevHome.FileExplorerSourceControlIntegrationUnitTest\DevHome.FileExplorerSourceControlIntegrationUnitTest.csproj", "{A1FAE679-39D4-4278-A8E8-EA351F21A3E7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.Service", "service\DevHome.Service\DevHome.Service.csproj", "{8A0AD1A7-29E1-47E1-9579-91F2B460518F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.Service.Projection", "service\DevHome.Service.Projection\DevHome.Service.Projection.csproj", "{13F1F098-262B-432D-977C-F710E6826C5C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Devhome.Service.IDL", "service\Devhome.Service.IDL\Devhome.Service.IDL.vcxproj", "{17E96025-8251-4D62-BFFB-C571F728B66B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestTools", "TestTools", "{7857275B-7970-4C26-B092-FF62EA890B1E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestDumpAnalyzer", "tools\DevInsights\TestTools\TestDumpAnalyzer\TestDumpAnalyzer.csproj", "{29963C5C-4CB6-4406-850A-99503CB87081}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestServiceCaller", "tools\DevInsights\TestTools\TestServiceCaller\TestServiceCaller.csproj", "{024CB70C-3449-4204-9171-A25C6C25783D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_FailFast|arm64 = Debug_FailFast|arm64
Expand Down Expand Up @@ -1161,6 +1173,96 @@ Global
{A1FAE679-39D4-4278-A8E8-EA351F21A3E7}.Release|x64.Build.0 = Release|x64
{A1FAE679-39D4-4278-A8E8-EA351F21A3E7}.Release|x86.ActiveCfg = Release|x86
{A1FAE679-39D4-4278-A8E8-EA351F21A3E7}.Release|x86.Build.0 = Release|x86
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug_FailFast|arm64.ActiveCfg = Debug|ARM64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug_FailFast|arm64.Build.0 = Debug|ARM64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug_FailFast|x64.ActiveCfg = Debug|x64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug_FailFast|x64.Build.0 = Debug|x64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug_FailFast|x86.ActiveCfg = Debug|x86
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug_FailFast|x86.Build.0 = Debug|x86
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug|arm64.ActiveCfg = Debug|ARM64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug|arm64.Build.0 = Debug|ARM64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug|x64.ActiveCfg = Debug|x64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug|x64.Build.0 = Debug|x64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug|x86.ActiveCfg = Debug|x86
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Debug|x86.Build.0 = Debug|x86
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Release|arm64.ActiveCfg = Release|ARM64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Release|arm64.Build.0 = Release|ARM64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Release|x64.ActiveCfg = Release|x64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Release|x64.Build.0 = Release|x64
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Release|x86.ActiveCfg = Release|x86
{8A0AD1A7-29E1-47E1-9579-91F2B460518F}.Release|x86.Build.0 = Release|x86
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug_FailFast|arm64.ActiveCfg = Debug|ARM64
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug_FailFast|arm64.Build.0 = Debug|ARM64
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug_FailFast|x64.ActiveCfg = Debug|x64
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug_FailFast|x64.Build.0 = Debug|x64
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug_FailFast|x86.ActiveCfg = Debug|x86
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug_FailFast|x86.Build.0 = Debug|x86
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug|arm64.ActiveCfg = Debug|ARM64
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug|arm64.Build.0 = Debug|ARM64
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug|x64.ActiveCfg = Debug|x64
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug|x64.Build.0 = Debug|x64
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug|x86.ActiveCfg = Debug|x86
{13F1F098-262B-432D-977C-F710E6826C5C}.Debug|x86.Build.0 = Debug|x86
{13F1F098-262B-432D-977C-F710E6826C5C}.Release|arm64.ActiveCfg = Release|ARM64
{13F1F098-262B-432D-977C-F710E6826C5C}.Release|arm64.Build.0 = Release|ARM64
{13F1F098-262B-432D-977C-F710E6826C5C}.Release|x64.ActiveCfg = Release|x64
{13F1F098-262B-432D-977C-F710E6826C5C}.Release|x64.Build.0 = Release|x64
{13F1F098-262B-432D-977C-F710E6826C5C}.Release|x86.ActiveCfg = Release|x86
{13F1F098-262B-432D-977C-F710E6826C5C}.Release|x86.Build.0 = Release|x86
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug_FailFast|arm64.ActiveCfg = Debug|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug_FailFast|arm64.Build.0 = Debug|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug_FailFast|x64.ActiveCfg = Debug|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug_FailFast|x64.Build.0 = Debug|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug_FailFast|x86.ActiveCfg = Debug|Win32
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug_FailFast|x86.Build.0 = Debug|Win32
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug|arm64.ActiveCfg = Debug|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug|arm64.Build.0 = Debug|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug|x64.ActiveCfg = Debug|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug|x64.Build.0 = Debug|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug|x86.ActiveCfg = Debug|Win32
{17E96025-8251-4D62-BFFB-C571F728B66B}.Debug|x86.Build.0 = Debug|Win32
{17E96025-8251-4D62-BFFB-C571F728B66B}.Release|arm64.ActiveCfg = Release|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Release|arm64.Build.0 = Release|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Release|x64.ActiveCfg = Release|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Release|x64.Build.0 = Release|x64
{17E96025-8251-4D62-BFFB-C571F728B66B}.Release|x86.ActiveCfg = Release|Win32
{17E96025-8251-4D62-BFFB-C571F728B66B}.Release|x86.Build.0 = Release|Win32
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug_FailFast|arm64.ActiveCfg = Debug_FailFast|ARM64
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug_FailFast|arm64.Build.0 = Debug_FailFast|ARM64
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug_FailFast|x64.ActiveCfg = Debug_FailFast|x64
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug_FailFast|x64.Build.0 = Debug_FailFast|x64
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug_FailFast|x86.ActiveCfg = Debug_FailFast|x86
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug_FailFast|x86.Build.0 = Debug_FailFast|x86
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug|arm64.ActiveCfg = Debug|ARM64
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug|arm64.Build.0 = Debug|ARM64
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug|x64.ActiveCfg = Debug|x64
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug|x64.Build.0 = Debug|x64
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug|x86.ActiveCfg = Debug|x86
{29963C5C-4CB6-4406-850A-99503CB87081}.Debug|x86.Build.0 = Debug|x86
{29963C5C-4CB6-4406-850A-99503CB87081}.Release|arm64.ActiveCfg = Release|ARM64
{29963C5C-4CB6-4406-850A-99503CB87081}.Release|arm64.Build.0 = Release|ARM64
{29963C5C-4CB6-4406-850A-99503CB87081}.Release|x64.ActiveCfg = Release|x64
{29963C5C-4CB6-4406-850A-99503CB87081}.Release|x64.Build.0 = Release|x64
{29963C5C-4CB6-4406-850A-99503CB87081}.Release|x86.ActiveCfg = Release|x86
{29963C5C-4CB6-4406-850A-99503CB87081}.Release|x86.Build.0 = Release|x86
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug_FailFast|arm64.ActiveCfg = Debug_FailFast|ARM64
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug_FailFast|arm64.Build.0 = Debug_FailFast|ARM64
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug_FailFast|x64.ActiveCfg = Debug_FailFast|x64
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug_FailFast|x64.Build.0 = Debug_FailFast|x64
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug_FailFast|x86.ActiveCfg = Debug_FailFast|x86
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug_FailFast|x86.Build.0 = Debug_FailFast|x86
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug|arm64.ActiveCfg = Debug|ARM64
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug|arm64.Build.0 = Debug|ARM64
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug|x64.ActiveCfg = Debug|x64
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug|x64.Build.0 = Debug|x64
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug|x86.ActiveCfg = Debug|x86
{024CB70C-3449-4204-9171-A25C6C25783D}.Debug|x86.Build.0 = Debug|x86
{024CB70C-3449-4204-9171-A25C6C25783D}.Release|arm64.ActiveCfg = Release|ARM64
{024CB70C-3449-4204-9171-A25C6C25783D}.Release|arm64.Build.0 = Release|ARM64
{024CB70C-3449-4204-9171-A25C6C25783D}.Release|x64.ActiveCfg = Release|x64
{024CB70C-3449-4204-9171-A25C6C25783D}.Release|x64.Build.0 = Release|x64
{024CB70C-3449-4204-9171-A25C6C25783D}.Release|x86.ActiveCfg = Release|x86
{024CB70C-3449-4204-9171-A25C6C25783D}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1228,12 +1330,18 @@ Global
{8C1C7BF8-B27B-4F4D-97E5-A16E02C7860E} = {01AB3100-A939-41DD-A67F-1F8C275A307D}
{83D12033-364A-45F2-8FCA-9BD8E8322D91} = {623998FD-B0A6-4980-95D5-A5072301CA10}
{A1FAE679-39D4-4278-A8E8-EA351F21A3E7} = {623998FD-B0A6-4980-95D5-A5072301CA10}
{7857275B-7970-4C26-B092-FF62EA890B1E} = {DB3D0F2C-1A7F-44B4-B408-B21A56212985}
{29963C5C-4CB6-4406-850A-99503CB87081} = {7857275B-7970-4C26-B092-FF62EA890B1E}
{024CB70C-3449-4204-9171-A25C6C25783D} = {7857275B-7970-4C26-B092-FF62EA890B1E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {030B5641-B206-46BB-BF71-36FF009088FA}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
build\cppversion\version.vcxitems*{024cb70c-3449-4204-9171-a25c6c25783d}*SharedItemsImports = 5
build\cppversion\version.vcxitems*{092ac740-da01-4872-8e93-b9557dad6be5}*SharedItemsImports = 5
build\cppversion\version.vcxitems*{13f1f098-262b-432d-977c-f710e6826c5c}*SharedItemsImports = 5
build\cppversion\version.vcxitems*{60e0fd98-5396-436d-bab7-187a853a5dc6}*SharedItemsImports = 5
build\cppversion\version.vcxitems*{8a0ad1a7-29e1-47e1-9579-91f2b460518f}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
5 changes: 5 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ graph TD;
DevHome.Dashboard-->DevHome;
DevHome.Experiments-->DevHome;
DevHome.ExtensionLibrary-->DevHome;
DevHome.DevInsights-->DevHome.Service;
DevHome.Settings-->DevHome;
DevHome.SetupFlow-->DevHome;
DevHome.Services.Core-->DevHome.Services.WindowsPackageManager;
Expand Down Expand Up @@ -67,6 +68,10 @@ Dev Home Common also provides telemetry functionality.

This is a special component that acts similarly to a tool but isn't actually a tool. The Settings component, like other tools, consumes the Common project and is used by Dev Home Core. It manages user preferences across all tools and extensions.

## Service

This is an NT service which runs as local system that provides functionality to various DevHome components. This functionality would typically require elevation and isn't transactional in nature. For items in DevHome that require elevation and are of a transactional nature, helper utilities are launched elevated instead.

## Tools

The tools are a set of functionalities that are integrated within Dev Home's codebase. They are designed to provide specific capabilities or features to Dev Home. They live as their own component but run in the same process as Dev Home and can communicate with each other and the core component through Dev Home's API.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)ToolingVersions.props" />
<Import Project="$(SolutionDir)Directory.CppBuild.props" />
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" />
</ItemGroup>

<ItemGroup>
<CsWinRTInputs Include="..\DevHome.Service.IDL\Generated Files\DevHome.Service.winmd" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Devhome.Service.IDL\Devhome.Service.IDL.vcxproj" />
</ItemGroup>

<PropertyGroup>
<CsWinRTIncludes>DevHome.Service</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(SolutionDir)DevHome.Service.Projection\bin\$(Platform)\$(Configuration)\</CsWinRTGeneratedFilesDir>
</PropertyGroup>

</Project>
81 changes: 81 additions & 0 deletions service/DevHome.Service/BasicClassWinRTFactory`1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Runtime.InteropServices;
using DevHome.Service;
using Windows.Win32.Foundation;
using WinRT;

namespace COMRegistration;

[ComVisible(true)]
public class BasicClassWinRTFactory<T> : IClassFactory
where T : new()
{
public BasicClassWinRTFactory()
{
}

public int CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject)
{
ppvObject = IntPtr.Zero;

if (pUnkOuter != IntPtr.Zero)
{
Marshal.ThrowExceptionForHR(HRESULT.CLASS_E_NOAGGREGATION);
}

if (riid == typeof(T).GUID || riid == Guid.Parse(Guids.IUnknown))
{
try
{
// Create the instance of the WinRT object
ppvObject = MarshalInspectable<T>.FromManaged(new T());
}
catch (Exception)
{
// We failed creating an object (possibly due to access denied). If we were just spun up
// to handle this (failed) activation, shut down our service.
if (ServiceLifetimeController.CanUnload())
{
WindowsBackgroundService.Stop();
}

throw;
}
}
else
{
// The object that ppvObject points to does not support the
// interface identified by riid.
Marshal.ThrowExceptionForHR(HRESULT.E_NOINTERFACE);
}

return 0;
}

int IClassFactory.LockServer(bool fLock)
{
return 0;
}
}

internal static class Guids
{
public const string IClassFactory = "00000001-0000-0000-C000-000000000046";
public const string IUnknown = "00000000-0000-0000-C000-000000000046";
}

// IClassFactory declaration
[ComImport]
[ComVisible(false)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid(Guids.IClassFactory)]
internal interface IClassFactory
{
[PreserveSig]
int CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject);

[PreserveSig]
int LockServer(bool fLock);
}
Loading

0 comments on commit 963723c

Please sign in to comment.