-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Startup hooks support in Mono; refactor StartupHookProvider (…
…#80391) Fixes #47462 **CoreCLR** This also makes some changes to CoreCLR to decouple EventPipe and startup hooks. Presently if startup hooks are disabled, `RuntimeEventSource.Initialize` is never called. The PR makes the two features independent by moving runtime event source initialization out of the startup hook feature check. * Implement startup hooks support in Mono * Keep StartupHookProvider.ProcessStartupHooks under feature flag * Don't catch/cleanup the exceptions from startup hooks. * Add an ios simulator startup hook functional test * Implement Android functional test * Add WASM functional test * Make a single managed startup method for CoreCLR A common configuration for coreclr is event source enabled, startup hooks disabled, so at least one managed call is inevitable. Since we have to call into managed no matter what, let the trimmer determine what happens once we get there. This is different from mono where published trimmed apps may have both startup hooks and event source disabled. In that case we would rather avoid a managed call to an empty method early in startup. * fix build and line damage
- Loading branch information
1 parent
47f171e
commit 3c3cc44
Showing
27 changed files
with
308 additions
and
22 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
7 changes: 0 additions & 7 deletions
7
src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.LibraryBuild.xml
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
26 changes: 26 additions & 0 deletions
26
src/coreclr/System.Private.CoreLib/src/System/StartupHookProvider.CoreCLR.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,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using System; | ||
using System.Diagnostics; | ||
using System.Diagnostics.Tracing; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime.Loader; | ||
|
||
namespace System | ||
{ | ||
internal static partial class StartupHookProvider | ||
{ | ||
private static void ManagedStartup() | ||
{ | ||
#if FEATURE_PERFTRACING | ||
if (EventSource.IsSupported) | ||
RuntimeEventSource.Initialize(); | ||
#endif | ||
|
||
if (IsSupported) | ||
ProcessStartupHooks(); | ||
} | ||
} | ||
} |
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
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
19 changes: 19 additions & 0 deletions
19
...Tests/Android/Device_Emulator/StartupHook/Android.Device_Emulator.StartupHook.Test.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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TestRuntime>true</TestRuntime> | ||
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
<MainLibraryFileName>Android.Device_Emulator.StartupHook.Test.dll</MainLibraryFileName> | ||
<IncludesTestRunner>false</IncludesTestRunner> | ||
<ExpectedExitCode>42</ExpectedExitCode> | ||
<StartupHookSupport>true</StartupHookSupport> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\TestAssets\StartupHookForFunctionalTest\StartupHookForFunctionalTest.csproj" /> | ||
</ItemGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
src/tests/FunctionalTests/Android/Device_Emulator/StartupHook/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,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Runtime.InteropServices; | ||
|
||
public static class Program | ||
{ | ||
public static int Main() | ||
{ | ||
string appContextKey = "Test.StartupHookForFunctionalTest.DidRun"; | ||
var data = (string) AppContext.GetData (appContextKey); | ||
|
||
if (data != "Yes") { | ||
string msg = $"Expected startup hook to set {appContextKey} to 'Yes', got '{data}'"; | ||
Console.Error.WriteLine(msg); | ||
return 104; | ||
} | ||
return 42; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/tests/FunctionalTests/Android/Device_Emulator/StartupHook/runtimeconfig.template.json
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,5 @@ | ||
{ | ||
"configProperties": { | ||
"STARTUP_HOOKS": "StartupHookForFunctionalTest" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...s/FunctionalTests/TestAssets/StartupHookForFunctionalTest/StartupHookForFunctionalTest.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,9 @@ | ||
using System; | ||
|
||
internal class StartupHook | ||
{ | ||
public static void Initialize() | ||
{ | ||
AppContext.SetData("Test.StartupHookForFunctionalTest.DidRun", "Yes"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...nctionalTests/TestAssets/StartupHookForFunctionalTest/StartupHookForFunctionalTest.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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
<IsTestProject>false</IsTestProject> | ||
<IsFunctionalTest>false</IsFunctionalTest> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="StartupHookForFunctionalTest.cs" /> | ||
</ItemGroup> | ||
</Project> |
30 changes: 30 additions & 0 deletions
30
src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/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,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices.JavaScript; | ||
|
||
namespace Sample | ||
{ | ||
public partial class Test | ||
{ | ||
public static void Main() | ||
{ | ||
} | ||
|
||
[JSExport] | ||
public static int TestMeaning() | ||
{ | ||
string appContextKey = "Test.StartupHookForFunctionalTest.DidRun"; | ||
var data = (string) AppContext.GetData (appContextKey); | ||
|
||
if (data != "Yes") { | ||
string msg = $"Expected startup hook to set {appContextKey} to 'Yes', got '{data}'"; | ||
Console.Error.WriteLine(msg); | ||
return 104; | ||
} | ||
return 42; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...nctionalTests/WebAssembly/Browser/StartupHook/WebAssembly.Browser.StartupHook.Test.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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TestRuntime>true</TestRuntime> | ||
<Scenario>WasmTestOnBrowser</Scenario> | ||
<TestArchiveTestsRoot>$(TestArchiveRoot)browseronly/</TestArchiveTestsRoot> | ||
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir> | ||
<DefineConstants>$(DefineConstants);TARGET_BROWSER</DefineConstants> | ||
<ExpectedExitCode>42</ExpectedExitCode> | ||
<WasmMainJSPath>main.js</WasmMainJSPath> | ||
<StartupHookSupport>true</StartupHookSupport> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<WasmExtraFilesToDeploy Include="index.html" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\gen\JSImportGenerator\JSImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\src\System.Runtime.InteropServices.JavaScript.csproj" SkipUseReferenceAssembly="true"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\TestAssets\StartupHookForFunctionalTest\StartupHookForFunctionalTest.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
18 changes: 18 additions & 0 deletions
18
src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/index.html
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,18 @@ | ||
<!DOCTYPE html> | ||
<!-- Licensed to the .NET Foundation under one or more agreements. --> | ||
<!-- The .NET Foundation licenses this file to you under the MIT license. --> | ||
<html> | ||
|
||
<head> | ||
<title>Runtime config test</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script type='module' src="./main.js"></script> | ||
</head> | ||
|
||
<body> | ||
<h3 id="header">Runtime config test</h3> | ||
Answer to the Ultimate Question of Life, the Universe, and Everything is : <span id="out"></span> | ||
</body> | ||
|
||
</html> |
24 changes: 24 additions & 0 deletions
24
src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/main.js
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,24 @@ | ||
import { dotnet } from './dotnet.js' | ||
|
||
function wasm_exit(exit_code) { | ||
var tests_done_elem = document.createElement("label"); | ||
tests_done_elem.id = "tests_done"; | ||
tests_done_elem.innerHTML = exit_code.toString(); | ||
document.body.appendChild(tests_done_elem); | ||
|
||
console.log(`WASM EXIT ${exit_code}`); | ||
} | ||
|
||
try { | ||
const { getAssemblyExports } = await dotnet.create(); | ||
const exports = await getAssemblyExports("WebAssembly.Browser.StartupHook.Test.dll"); | ||
const testMeaning = exports.Sample.Test.TestMeaning; | ||
const ret = testMeaning(); | ||
document.getElementById("out").innerHTML = `${ret}`; | ||
console.debug(`ret: ${ret}`); | ||
|
||
let exit_code = ret; | ||
wasm_exit(exit_code); | ||
} catch (err) { | ||
console.log(`WASM ERROR ${err}`); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/runtimeconfig.template.json
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,5 @@ | ||
{ | ||
"configProperties": { | ||
"STARTUP_HOOKS": "StartupHookForFunctionalTest" | ||
} | ||
} |
Oops, something went wrong.