Skip to content

Commit 3ee5618

Browse files
authored
Update vendored System.Reflection.Metadata (#8455)
## Summary of changes - Remove some unused types from System.Reflection.Metadata (mostly around builder/writer infrastructure that was unused) - Update the vendored version of System.Reflection.Metadata to use the runtime repo directly, and bump to latest patch version ## Reason for change We want to update our vendored .NET library versions. ## Implementation details - Make the vendoring repeatable - Run the tool, check for errors, tweak, rinse and repeat - After running the tool, used 🤖 to identify segments of code that weren't used, so we could strip them out ## Test coverage This is the test, if it compiles and tests pass, we should be ok 🤞 ## Other details https://datadoghq.atlassian.net/browse/APMLP-1207 Part of a stack updating our vendored system code - #8391 - #8454
1 parent 1de5a0f commit 3ee5618

566 files changed

Lines changed: 34699 additions & 36737 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tracer/build/_build/UpdateVendors/VendoredDependency.cs

Lines changed: 256 additions & 33 deletions
Large diffs are not rendered by default.

tracer/dependabot/Datadog.Dependabot.Vendors.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
<!-- https://www.nuget.org/packages/System.Private.CoreLib/1.0.0 -->
4141
<PackageReference Include="System.Private.CoreLib" Version="1.0.0" />
4242

43-
<!-- https://www.nuget.org/packages/System.Reflection.Metadata/7.0.2 -->
44-
<PackageReference Include="System.Reflection.Metadata" Version="7.0.2" />
43+
<!-- https://www.nuget.org/packages/System.Reflection.Metadata.Interop/7.0.20 -->
44+
<PackageReference Include="System.Reflection.Metadata.Interop" Version="7.0.20" />
45+
46+
<!-- https://www.nuget.org/packages/System.Reflection.Metadata/7.0.20 -->
47+
<PackageReference Include="System.Reflection.Metadata" Version="7.0.20" />
4548

4649
<!-- https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/1.0.0 -->
4750
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="1.0.0" />

tracer/src/Datadog.Trace/Datadog.Trace.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101

102102
<!-- we don't need the vendored .NET runtime code when targetting .NET Core 3.1+ -->
103103
<PropertyGroup>
104-
<DotNetRuntimeFiles>Vendors/System.Collections.Immutable/**;Vendors/System.Memory/**;Vendors/System.Private.CoreLib/**;Vendors/System.Reflection.Metadata/**;Vendors/System.Runtime.CompilerServices.Unsafe/**</DotNetRuntimeFiles>
104+
<DotNetRuntimeFiles>Vendors/System.Collections.Immutable/**;Vendors/System.Memory/**;Vendors/System.Private.CoreLib/**;Vendors/System.Reflection.Metadata/**;Vendors/System.Reflection.Metadata.Interop/**;Vendors/System.Runtime.CompilerServices.Unsafe/**</DotNetRuntimeFiles>
105105
</PropertyGroup>
106106

107107
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'netcoreapp3.1'))">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated />
3+
// This file was automatically generated by the UpdateVendoredCode tool.
4+
//------------------------------------------------------------------------------
5+
#pragma warning disable CS0105, CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0023, SYSLIB0032
6+
#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774
7+
#nullable enable
8+
// Licensed to the .NET Foundation under one or more agreements.
9+
// The .NET Foundation licenses this file to you under the MIT license.
10+
11+
using System;
12+
using System.Runtime.InteropServices;
13+
14+
namespace Datadog.Trace.VendoredMicrosoftCode.System.Reflection.Internal;
15+
16+
internal static partial class Interop
17+
{
18+
internal static partial class Kernel32
19+
{
20+
[DllImport("kernel32.dll", SetLastError = true)]
21+
internal static extern unsafe int ReadFile(
22+
SafeHandle handle,
23+
byte* bytes,
24+
int numBytesToRead,
25+
out int numBytesRead,
26+
IntPtr mustBeZero);
27+
}
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/dotnet/runtime/archive/refs/tags/v7.0.20.zip
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated />
3+
// This file was automatically generated by the UpdateVendoredCode tool.
4+
//------------------------------------------------------------------------------
5+
#pragma warning disable CS0105, CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0023, SYSLIB0032
6+
#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774
7+
#nullable enable
8+
// Licensed to the .NET Foundation under one or more agreements.
9+
// The .NET Foundation licenses this file to you under the MIT license.
10+
11+
using Datadog.Trace.VendoredMicrosoftCode.System.Collections.Immutable;
12+
using Datadog.Trace.VendoredMicrosoftCode.System.Reflection.Metadata;
13+
14+
#nullable enable
15+
using System;
16+
using System.Collections;
17+
using System.Collections.Generic;
18+
using System.IO;
19+
using System.Linq;
20+
using System.Reflection;
21+
using System.Threading;
22+
using System.Threading.Tasks;
23+
24+
namespace Datadog.Trace.VendoredMicrosoftCode.System.Reflection.Internal
25+
{
26+
/// <summary>
27+
/// Represents a disposable blob of memory accessed via unsafe pointer.
28+
/// </summary>
29+
internal abstract class AbstractMemoryBlock : IDisposable
30+
{
31+
/// <summary>
32+
/// Pointer to the underlying data (not valid after disposal).
33+
/// </summary>
34+
public abstract unsafe byte* Pointer { get; }
35+
36+
/// <summary>
37+
/// Size of the block.
38+
/// </summary>
39+
public abstract int Size { get; }
40+
41+
public unsafe BlobReader GetReader() => new BlobReader(Pointer, Size);
42+
43+
/// <summary>
44+
/// Returns the content of the entire memory block.
45+
/// </summary>
46+
/// <remarks>
47+
/// Does not check bounds.
48+
///
49+
/// Only creates a copy of the data if they are not represented by a managed byte array,
50+
/// or if the specified range doesn't span the entire block.
51+
/// </remarks>
52+
public virtual unsafe ImmutableArray<byte> GetContentUnchecked(int start, int length)
53+
{
54+
var result = BlobUtilities.ReadImmutableBytes(Pointer + start, length);
55+
GC.KeepAlive(this);
56+
return result;
57+
}
58+
59+
/// <summary>
60+
/// Disposes the block.
61+
/// </summary>
62+
/// <remarks>
63+
/// The operation is idempotent, but must not be called concurrently with any other operations on the block.
64+
///
65+
/// Using the block after dispose is an error in our code and therefore no effort is made to throw a tidy
66+
/// ObjectDisposedException and null ref or AV is possible.
67+
/// </remarks>
68+
public abstract void Dispose();
69+
}
70+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated />
3+
// This file was automatically generated by the UpdateVendoredCode tool.
4+
//------------------------------------------------------------------------------
5+
#pragma warning disable CS0105, CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0023, SYSLIB0032
6+
#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774
7+
#nullable enable
8+
// Licensed to the .NET Foundation under one or more agreements.
9+
// The .NET Foundation licenses this file to you under the MIT license.
10+
11+
using Datadog.Trace.VendoredMicrosoftCode.System.Collections.Immutable;
12+
using System.Diagnostics;
13+
14+
#nullable enable
15+
using System;
16+
using System.Collections;
17+
using System.Collections.Generic;
18+
using System.IO;
19+
using System.Linq;
20+
using System.Reflection;
21+
using System.Threading;
22+
using System.Threading.Tasks;
23+
24+
namespace Datadog.Trace.VendoredMicrosoftCode.System.Reflection.Internal
25+
{
26+
/// <summary>
27+
/// Represents a memory block backed by an array of bytes.
28+
/// </summary>
29+
internal sealed class ByteArrayMemoryBlock : AbstractMemoryBlock
30+
{
31+
private ByteArrayMemoryProvider _provider;
32+
private readonly int _start;
33+
private readonly int _size;
34+
35+
internal ByteArrayMemoryBlock(ByteArrayMemoryProvider provider, int start, int size)
36+
{
37+
_provider = provider;
38+
_size = size;
39+
_start = start;
40+
}
41+
42+
public override void Dispose()
43+
{
44+
_provider = null!;
45+
}
46+
47+
public override unsafe byte* Pointer => _provider.Pointer + _start;
48+
public override int Size => _size;
49+
50+
public override ImmutableArray<byte> GetContentUnchecked(int start, int length)
51+
{
52+
return ImmutableArray.Create(_provider.Array, _start + start, length);
53+
}
54+
}
55+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated />
3+
// This file was automatically generated by the UpdateVendoredCode tool.
4+
//------------------------------------------------------------------------------
5+
#pragma warning disable CS0105, CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0023, SYSLIB0032
6+
#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774
7+
#nullable enable
8+
// Licensed to the .NET Foundation under one or more agreements.
9+
// The .NET Foundation licenses this file to you under the MIT license.
10+
11+
using Datadog.Trace.VendoredMicrosoftCode.System.Collections.Immutable;
12+
using System.Diagnostics;
13+
using System.IO;
14+
using System.Threading;
15+
16+
#nullable enable
17+
using System;
18+
using System.Collections;
19+
using System.Collections.Generic;
20+
using System.IO;
21+
using System.Linq;
22+
using System.Reflection;
23+
using System.Threading;
24+
using System.Threading.Tasks;
25+
26+
namespace Datadog.Trace.VendoredMicrosoftCode.System.Reflection.Internal
27+
{
28+
internal sealed class ByteArrayMemoryProvider : MemoryBlockProvider
29+
{
30+
private readonly ImmutableArray<byte> _array;
31+
private PinnedObject? _pinned;
32+
33+
public ByteArrayMemoryProvider(ImmutableArray<byte> array)
34+
{
35+
Debug.Assert(!array.IsDefault);
36+
_array = array;
37+
}
38+
39+
protected override void Dispose(bool disposing)
40+
{
41+
Debug.Assert(disposing);
42+
Interlocked.Exchange(ref _pinned, null)?.Dispose();
43+
}
44+
45+
public override int Size => _array.Length;
46+
public ImmutableArray<byte> Array => _array;
47+
48+
protected override AbstractMemoryBlock GetMemoryBlockImpl(int start, int size)
49+
{
50+
return new ByteArrayMemoryBlock(this, start, size);
51+
}
52+
53+
public override Stream GetStream(out StreamConstraints constraints)
54+
{
55+
constraints = new StreamConstraints(null, 0, Size);
56+
return new ImmutableMemoryStream(_array);
57+
}
58+
59+
internal unsafe byte* Pointer
60+
{
61+
get
62+
{
63+
if (_pinned == null)
64+
{
65+
var newPinned = new PinnedObject(ImmutableByteArrayInterop.DangerousGetUnderlyingArray(_array)!);
66+
67+
if (Interlocked.CompareExchange(ref _pinned, newPinned, null) != null)
68+
{
69+
// another thread has already allocated the handle:
70+
newPinned.Dispose();
71+
}
72+
}
73+
74+
return _pinned.Pointer;
75+
}
76+
}
77+
}
78+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated />
3+
// This file was automatically generated by the UpdateVendoredCode tool.
4+
//------------------------------------------------------------------------------
5+
#pragma warning disable CS0105, CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0023, SYSLIB0032
6+
#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774
7+
#nullable enable
8+
// Licensed to the .NET Foundation under one or more agreements.
9+
// The .NET Foundation licenses this file to you under the MIT license.
10+
11+
#nullable enable
12+
using System;
13+
using System.Collections;
14+
using System.Collections.Generic;
15+
using System.IO;
16+
using System.Linq;
17+
using System.Reflection;
18+
using System.Threading;
19+
using System.Threading.Tasks;
20+
21+
namespace Datadog.Trace.VendoredMicrosoftCode.System.Reflection.Internal
22+
{
23+
/// <summary>
24+
/// Class representing raw memory but not owning the memory.
25+
/// </summary>
26+
internal sealed unsafe class ExternalMemoryBlock : AbstractMemoryBlock
27+
{
28+
// keeps the owner of the memory alive as long as the block is alive:
29+
private readonly object _memoryOwner;
30+
31+
private byte* _buffer;
32+
private int _size;
33+
34+
public ExternalMemoryBlock(object memoryOwner, byte* buffer, int size)
35+
{
36+
_memoryOwner = memoryOwner;
37+
_buffer = buffer;
38+
_size = size;
39+
}
40+
41+
public override void Dispose()
42+
{
43+
_buffer = null;
44+
_size = 0;
45+
}
46+
47+
public override byte* Pointer => _buffer;
48+
public override int Size => _size;
49+
}
50+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated />
3+
// This file was automatically generated by the UpdateVendoredCode tool.
4+
//------------------------------------------------------------------------------
5+
#pragma warning disable CS0105, CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0023, SYSLIB0032
6+
#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774
7+
#nullable enable
8+
// Licensed to the .NET Foundation under one or more agreements.
9+
// The .NET Foundation licenses this file to you under the MIT license.
10+
11+
using System.Diagnostics;
12+
using System.IO;
13+
14+
#nullable enable
15+
using System;
16+
using System.Collections;
17+
using System.Collections.Generic;
18+
using System.IO;
19+
using System.Linq;
20+
using System.Reflection;
21+
using System.Threading;
22+
using System.Threading.Tasks;
23+
24+
namespace Datadog.Trace.VendoredMicrosoftCode.System.Reflection.Internal
25+
{
26+
/// <summary>
27+
/// Represents raw memory owned by an external object.
28+
/// </summary>
29+
internal sealed unsafe class ExternalMemoryBlockProvider : MemoryBlockProvider
30+
{
31+
private byte* _memory;
32+
private int _size;
33+
34+
public unsafe ExternalMemoryBlockProvider(byte* memory, int size)
35+
{
36+
_memory = memory;
37+
_size = size;
38+
}
39+
40+
public override int Size
41+
{
42+
get
43+
{
44+
return _size;
45+
}
46+
}
47+
48+
protected override AbstractMemoryBlock GetMemoryBlockImpl(int start, int size)
49+
{
50+
return new ExternalMemoryBlock(this, _memory + start, size);
51+
}
52+
53+
public override Stream GetStream(out StreamConstraints constraints)
54+
{
55+
constraints = new StreamConstraints(null, 0, _size);
56+
return new ReadOnlyUnmanagedMemoryStream(_memory, _size);
57+
}
58+
59+
protected override void Dispose(bool disposing)
60+
{
61+
Debug.Assert(disposing);
62+
63+
// we don't own the memory, just null out the pointer.
64+
_memory = null;
65+
_size = 0;
66+
}
67+
68+
public byte* Pointer
69+
{
70+
get
71+
{
72+
return _memory;
73+
}
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)