-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Single-File: Pass BUNDLE_PROBE property to the runtime (#34845)
* Single-File: Pass BUNDLE_PROBE property to the runtime As described in the [design doc](https://github.com/dotnet/designs/blob/master/accepted/2020/single-file/design.md#startup), pass the bundle_probe function pointer encoded as a string to the runtime.
- Loading branch information
1 parent
af36c6d
commit bfa10f1
Showing
11 changed files
with
283 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/installer/test/Assets/TestProjects/BundleProbeTester/BundleProbeTester.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(NETCoreAppFramework)</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<RuntimeIdentifier>$(TestTargetRid)</RuntimeIdentifier> | ||
<RuntimeFrameworkVersion>$(MNAVersion)</RuntimeFrameworkVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
</Project> |
89 changes: 89 additions & 0 deletions
89
src/installer/test/Assets/TestProjects/BundleProbeTester/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace BundleProbeTester | ||
{ | ||
public static class Program | ||
{ | ||
[UnmanagedFunctionPointer(CallingConvention.StdCall)] | ||
public delegate bool BundleProbeDelegate([MarshalAs(UnmanagedType.LPWStr)] string path, IntPtr size, IntPtr offset); | ||
|
||
unsafe static bool Probe(BundleProbeDelegate bundleProbe, string path, bool isExpected) | ||
{ | ||
Int64 size, offset; | ||
bool exists = bundleProbe(path, (IntPtr)(&offset), (IntPtr)(&size)); | ||
|
||
switch (exists, isExpected) | ||
{ | ||
case (true, true): | ||
if (size > 0 && offset > 0) | ||
{ | ||
return true; | ||
} | ||
|
||
Console.WriteLine($"Invalid location obtained for {path} within bundle."); | ||
return false; | ||
|
||
case (true, false): | ||
Console.WriteLine($"Unexpected file {path} found in bundle."); | ||
return false; | ||
|
||
case (false, true): | ||
Console.WriteLine($"Expected file {path} not found in bundle."); | ||
return false; | ||
|
||
case (false, false): | ||
return true; | ||
} | ||
|
||
return false; // dummy | ||
} | ||
|
||
public static int Main(string[] args) | ||
{ | ||
bool isSingleFile = args.Length > 0 && args[0].Equals("SingleFile"); | ||
object probeObject = System.AppDomain.CurrentDomain.GetData("BUNDLE_PROBE"); | ||
|
||
if (!isSingleFile) | ||
{ | ||
if (probeObject != null) | ||
{ | ||
Console.WriteLine("BUNDLE_PROBE property passed in for a non-single-file app"); | ||
return -1; | ||
} | ||
|
||
Console.WriteLine("No BUNDLE_PROBE"); | ||
return 0; | ||
} | ||
|
||
if (probeObject == null) | ||
{ | ||
Console.WriteLine("BUNDLE_PROBE property not passed in for a single-file app"); | ||
return -2; | ||
} | ||
|
||
string probeString = probeObject as string; | ||
IntPtr probePtr = (IntPtr)Convert.ToUInt64(probeString, 16); | ||
BundleProbeDelegate bundleProbeDelegate = Marshal.GetDelegateForFunctionPointer<BundleProbeDelegate>(probePtr); | ||
bool success = | ||
Probe(bundleProbeDelegate, "BundleProbeTester.dll", isExpected: true) && | ||
Probe(bundleProbeDelegate, "BundleProbeTester.runtimeconfig.json", isExpected: true) && | ||
Probe(bundleProbeDelegate, "System.Private.CoreLib.dll", isExpected: true) && | ||
Probe(bundleProbeDelegate, "hostpolicy.dll", isExpected: false) && | ||
Probe(bundleProbeDelegate, "--", isExpected: false) && | ||
Probe(bundleProbeDelegate, "", isExpected: false); | ||
|
||
if (!success) | ||
{ | ||
return -3; | ||
} | ||
|
||
Console.WriteLine("BUNDLE_PROBE OK"); | ||
return 0; | ||
} | ||
} | ||
} |
Oops, something went wrong.