forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make startup hooks kind of work with native AOT (dotnet#96894)
Fixes dotnet#96052. Since we compile startup hooks anyway, just add a call to it. It will be deadcoded by default. Can be enabled and then it will at least work for hooks that were part of the app. It will throw PNSE for random file paths.
- Loading branch information
1 parent
613a13f
commit e42a873
Showing
7 changed files
with
62 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
src/coreclr/nativeaot/System.Private.CoreLib/src/System/StartupHookProvider.NativeAot.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,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
namespace System | ||
{ | ||
internal static partial class StartupHookProvider | ||
{ | ||
#pragma warning disable CA2255 | ||
[ModuleInitializer] | ||
#pragma warning restore CA2255 | ||
internal static void Initialize() | ||
{ | ||
if (IsSupported) | ||
ProcessStartupHooks(Environment.GetEnvironmentVariable("DOTNET_STARTUP_HOOKS")); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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.CodeAnalysis; | ||
|
||
class Program | ||
{ | ||
internal static int s_return; | ||
|
||
[DynamicDependency(nameof(StartupHook.Initialize), typeof(StartupHook))] | ||
static int Main() => s_return; | ||
} | ||
|
||
class StartupHook | ||
{ | ||
public static void Initialize() | ||
{ | ||
Console.WriteLine("Running startup hook"); | ||
Program.s_return = 100; | ||
} | ||
} |
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<CLRTestPriority>0</CLRTestPriority> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<StartupHookSupport>true</StartupHookSupport> | ||
<NoWarn>$(NoWarn);IL2026</NoWarn> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="StartupHook.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<CLRTestEnvironmentVariable Include="DOTNET_STARTUP_HOOKS" Value="StartupHook" /> | ||
</ItemGroup> | ||
</Project> |