|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using System.Runtime.CompilerServices; |
| 5 | + |
4 | 6 | namespace System.Reflection.Metadata
|
5 | 7 | {
|
6 | 8 | public static class AssemblyExtensions
|
7 | 9 | {
|
8 | 10 | [CLSCompliant(false)]
|
9 | 11 | public static unsafe bool TryGetRawMetadata(this Assembly assembly, out byte* blob, out int length) => throw new NotImplementedException();
|
10 | 12 |
|
11 |
| - public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDelta, ReadOnlySpan<byte> ilDelta, ReadOnlySpan<byte> pdbDelta) => throw new NotImplementedException(); |
| 13 | + /// <summary> |
| 14 | + /// Updates the specified assembly using the provided metadata, IL and PDB deltas. |
| 15 | + /// </summary> |
| 16 | + /// <remarks> |
| 17 | + /// Currently executing methods will continue to use the existing IL. New executions of modified methods will |
| 18 | + /// use the new IL. Different runtimes may have different limitations on what kinds of changes are supported, |
| 19 | + /// and runtimes make no guarantees as to the state of the assembly and process if the delta includes |
| 20 | + /// unsupported changes. |
| 21 | + /// </remarks> |
| 22 | + /// <param name="assembly">The assembly to update.</param> |
| 23 | + /// <param name="metadataDelta">The metadata changes to be applied.</param> |
| 24 | + /// <param name="ilDelta">The IL changes to be applied.</param> |
| 25 | + /// <param name="pdbDelta">The PDB changes to be applied.</param> |
| 26 | + /// <exception cref="ArgumentNullException">The assembly argument is null.</exception> |
| 27 | + /// <exception cref="NotSupportedException">The update could not be applied.</exception> |
| 28 | + public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDelta, ReadOnlySpan<byte> ilDelta, ReadOnlySpan<byte> pdbDelta = default) |
| 29 | + { |
| 30 | +#if !FEATURE_METADATA_UPDATE |
| 31 | + throw new NotSupportedException ("Method body replacement not supported in this runtime"); |
| 32 | +#else |
| 33 | + if (assembly == null) |
| 34 | + { |
| 35 | + throw new ArgumentNullException(nameof(assembly)); |
| 36 | + } |
| 37 | + |
| 38 | + RuntimeAssembly? runtimeAssembly = assembly as RuntimeAssembly; |
| 39 | + if (runtimeAssembly == null) |
| 40 | + { |
| 41 | + throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly); |
| 42 | + } |
| 43 | + |
| 44 | + unsafe |
| 45 | + { |
| 46 | + IntPtr monoAssembly = runtimeAssembly.GetUnderlyingNativeHandle (); |
| 47 | + fixed (byte* metadataDeltaPtr = metadataDelta, ilDeltaPtr = ilDelta, pdbDeltaPtr = pdbDelta) |
| 48 | + { |
| 49 | + ApplyUpdate_internal(monoAssembly, metadataDeltaPtr, metadataDelta.Length, ilDeltaPtr, ilDelta.Length, pdbDeltaPtr, pdbDelta.Length); |
| 50 | + } |
| 51 | + } |
| 52 | +#endif |
| 53 | + } |
| 54 | + |
| 55 | + internal static void ApplyUpdateSdb(Assembly assembly, byte[] metadataDelta, byte[] ilDelta, byte[]? pdbDelta = null) |
| 56 | + { |
| 57 | + ReadOnlySpan<byte> md = metadataDelta; |
| 58 | + ReadOnlySpan<byte> il = ilDelta; |
| 59 | + ReadOnlySpan<byte> dpdb = pdbDelta == null ? default : pdbDelta; |
| 60 | + ApplyUpdate (assembly, md, il, dpdb); |
| 61 | + } |
| 62 | + |
| 63 | +#if FEATURE_METADATA_UPDATE |
| 64 | + [MethodImpl (MethodImplOptions.InternalCall)] |
| 65 | + private static unsafe extern void ApplyUpdate_internal (IntPtr base_assm, byte* dmeta_bytes, int dmeta_length, byte *dil_bytes, int dil_length, byte *dpdb_bytes, int dpdb_length); |
| 66 | +#endif |
| 67 | + |
12 | 68 | }
|
13 | 69 | }
|
0 commit comments