-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Move the metadata update related APIs to the MetadataUpdater class #54590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
72bc435
Move the metadata update related APIs to the MetadataUpdater class
94ed51a
Code review feedback
d8e5ccb
Update mono's MetadataUpdater.IsSupported property
b4cd895
Update feature switch doc
fa0b55d
Code review feedback. Making the new MetadataUpdater.GetCapabilities(…
caa69d6
Code review feedback.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
63 changes: 63 additions & 0 deletions
63
src/coreclr/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs
This file contains hidden or 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,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace System.Reflection.Metadata | ||
{ | ||
public static class MetadataUpdater | ||
{ | ||
[DllImport(RuntimeHelpers.QCall)] | ||
private static extern unsafe void ApplyUpdate(QCallAssembly assembly, byte* metadataDelta, int metadataDeltaLength, byte* ilDelta, int ilDeltaLength, byte* pdbDelta, int pdbDeltaLength); | ||
|
||
[DllImport(RuntimeHelpers.QCall)] | ||
private static extern unsafe bool IsApplyUpdateSupported(); | ||
|
||
/// <summary> | ||
/// Updates the specified assembly using the provided metadata, IL and PDB deltas. | ||
/// </summary> | ||
/// <remarks> | ||
/// Currently executing methods will continue to use the existing IL. New executions of modified methods will | ||
/// use the new IL. Different runtimes may have different limitations on what kinds of changes are supported, | ||
/// and runtimes make no guarantees as to the state of the assembly and process if the delta includes | ||
/// unsupported changes. | ||
/// </remarks> | ||
/// <param name="assembly">The assembly to update.</param> | ||
/// <param name="metadataDelta">The metadata changes to be applied.</param> | ||
/// <param name="ilDelta">The IL changes to be applied.</param> | ||
/// <param name="pdbDelta">The PDB changes to be applied.</param> | ||
/// <exception cref="ArgumentException">The assembly argument is not a runtime assembly.</exception> | ||
/// <exception cref="ArgumentNullException">The assembly argument is null.</exception> | ||
/// <exception cref="InvalidOperationException">The assembly is not editable.</exception> | ||
/// <exception cref="NotSupportedException">The update could not be applied.</exception> | ||
public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDelta, ReadOnlySpan<byte> ilDelta, ReadOnlySpan<byte> pdbDelta) | ||
mikem8361 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (assembly is not RuntimeAssembly runtimeAssembly) | ||
{ | ||
if (assembly is null) throw new ArgumentNullException(nameof(assembly)); | ||
throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly); | ||
} | ||
|
||
unsafe | ||
{ | ||
RuntimeAssembly rtAsm = runtimeAssembly; | ||
fixed (byte* metadataDeltaPtr = metadataDelta, ilDeltaPtr = ilDelta, pdbDeltaPtr = pdbDelta) | ||
{ | ||
ApplyUpdate(new QCallAssembly(ref rtAsm), metadataDeltaPtr, metadataDelta.Length, ilDeltaPtr, ilDelta.Length, pdbDeltaPtr, pdbDelta.Length); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns the metadata update capabilities. | ||
/// </summary> | ||
internal static string GetCapabilities() => "Baseline AddMethodToExistingType AddStaticFieldToExistingType AddInstanceFieldToExistingType NewTypeDefinition ChangeCustomAttributes"; | ||
|
||
/// <summary> | ||
/// Returns true if the apply assembly update is enabled and available. | ||
/// </summary> | ||
public static bool IsSupported { get; } = IsApplyUpdateSupported(); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
48 changes: 0 additions & 48 deletions
48
src/libraries/System.Runtime.Loader/tests/AssemblyExtensionsTest.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.