Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 4afa9c8

Browse files
author
Nate McMaster
committed
Commit a snapshot of corefxlab source code to ensure patch builds are reproducible
1 parent be4e401 commit 4afa9c8

File tree

83 files changed

+9351
-2
lines changed

Some content is hidden

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

83 files changed

+9351
-2
lines changed

build/dependencies.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
99
<MicrosoftAspNetCoreHttpFeaturesPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreHttpFeaturesPackageVersion>
1010
<MicrosoftAspNetCoreHttpPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreHttpPackageVersion>
11-
<MicrosoftAspNetCoreInternalCoreFxLabSourcesPackageVersion>2.0.0-rtm-21470</MicrosoftAspNetCoreInternalCoreFxLabSourcesPackageVersion>
1211
<MicrosoftAspNetCoreTestingPackageVersion>2.0.0</MicrosoftAspNetCoreTestingPackageVersion>
1312
<MicrosoftAspNetCoreWebUtilitiesPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreWebUtilitiesPackageVersion>
1413
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.0.0</MicrosoftExtensionsLoggingAbstractionsPackageVersion>

shared/corefxlab/SR.cs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
namespace System
2+
{
3+
// This is generated as part of corefx build process
4+
internal static class SR
5+
{
6+
internal static string ArrayTypeMustBeExactMatch
7+
{
8+
get
9+
{
10+
return System.SR.GetResourceString("ArrayTypeMustBeExactMatch", null);
11+
}
12+
}
13+
14+
internal static string CannotCallEqualsOnSpan
15+
{
16+
get
17+
{
18+
return System.SR.GetResourceString("CannotCallEqualsOnSpan", null);
19+
}
20+
}
21+
22+
internal static string CannotCallGetHashCodeOnSpan
23+
{
24+
get
25+
{
26+
return System.SR.GetResourceString("CannotCallGetHashCodeOnSpan", null);
27+
}
28+
}
29+
30+
internal static string Argument_InvalidTypeWithPointersNotSupported
31+
{
32+
get
33+
{
34+
return System.SR.GetResourceString("Argument_InvalidTypeWithPointersNotSupported", null);
35+
}
36+
}
37+
38+
internal static string Argument_DestinationTooShort
39+
{
40+
get
41+
{
42+
return System.SR.GetResourceString("Argument_DestinationTooShort", null);
43+
}
44+
}
45+
46+
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
47+
private static bool UsingResourceKeys()
48+
{
49+
return false;
50+
}
51+
52+
internal static string GetResourceString(string resourceKey, string defaultString)
53+
{
54+
return resourceKey;
55+
}
56+
57+
internal static string Format(string resourceFormat, params object[] args)
58+
{
59+
return resourceFormat + string.Join(", ", args);
60+
}
61+
62+
internal static string Format(string resourceFormat, object p1)
63+
{
64+
if (System.SR.UsingResourceKeys())
65+
{
66+
return string.Join(", ", new object[]
67+
{
68+
resourceFormat,
69+
p1
70+
});
71+
}
72+
return string.Format(resourceFormat, p1);
73+
}
74+
75+
internal static string Format(string resourceFormat, object p1, object p2)
76+
{
77+
if (System.SR.UsingResourceKeys())
78+
{
79+
return string.Join(", ", new object[]
80+
{
81+
resourceFormat,
82+
p1,
83+
p2
84+
});
85+
}
86+
return string.Format(resourceFormat, p1, p2);
87+
}
88+
89+
internal static string Format(string resourceFormat, object p1, object p2, object p3)
90+
{
91+
if (System.SR.UsingResourceKeys())
92+
{
93+
return string.Join(", ", new object[]
94+
{
95+
resourceFormat,
96+
p1,
97+
p2,
98+
p3
99+
});
100+
}
101+
return string.Format(resourceFormat, p1, p2, p3);
102+
}
103+
}
104+
}
105+
106+
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Internal
107+
{
108+
// We don't want to pull System.Buffers required by ManagedBufferPool implemenation
109+
// and BufferPool depends on ManagedBufferPool.Shared
110+
internal class ManagedBufferPool
111+
{
112+
public static BufferPool Shared { get; } = null;
113+
}
114+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// This file was processed with Internalizer tool and should not be edited manually
2+
3+
using System;
4+
using System.Buffers;
5+
using System.Runtime;
6+
7+
// Copyright (c) Microsoft. All rights reserved.
8+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
9+
10+
using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime;
11+
using System.Runtime.CompilerServices;
12+
13+
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.System.Binary
14+
{
15+
/// <summary>
16+
/// Reads bytes as primitives with specific endianness
17+
/// </summary>
18+
/// <remarks>
19+
/// For native formats, SpanExtensions.Read<T> should be used.
20+
/// Use these helpers when you need to read specific endinanness.
21+
/// </remarks>
22+
public static class BufferReader
23+
{
24+
/// <summary>
25+
/// Reads a structure of type <typeparamref name="T"/> out of a span of bytes.
26+
/// </summary>
27+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
28+
public static T ReadBigEndian<[Primitive]T>(this ReadOnlySpan<byte> span) where T : struct
29+
=> BitConverter.IsLittleEndian ? UnsafeUtilities.Reverse(span.Read<T>()) : span.Read<T>();
30+
31+
/// <summary>
32+
/// Reads a structure of type <typeparamref name="T"/> out of a span of bytes.
33+
/// </summary>
34+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
35+
public static T ReadLittleEndian<[Primitive]T>(this ReadOnlySpan<byte> span) where T : struct
36+
=> BitConverter.IsLittleEndian ? span.Read<T>() : UnsafeUtilities.Reverse(span.Read<T>());
37+
38+
/// <summary>
39+
/// Reads a structure of type <typeparamref name="T"/> out of a span of bytes.
40+
/// </summary>
41+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
42+
public static T ReadBigEndian<[Primitive]T>(this Span<byte> span) where T : struct
43+
=> BitConverter.IsLittleEndian ? UnsafeUtilities.Reverse(span.Read<T>()) : span.Read<T>();
44+
45+
/// <summary>
46+
/// Reads a structure of type <typeparamref name="T"/> out of a span of bytes.
47+
/// </summary>
48+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
49+
public static T ReadLittleEndian<[Primitive]T>(this Span<byte> span) where T : struct
50+
=> BitConverter.IsLittleEndian ? span.Read<T>() : UnsafeUtilities.Reverse(span.Read<T>());
51+
52+
/// <summary>
53+
/// Reads a structure of type T out of a slice of bytes.
54+
/// </summary>
55+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
56+
public static T Read<[Primitive]T>(this Span<byte> slice)
57+
where T : struct
58+
{
59+
RequiresInInclusiveRange(Unsafe.SizeOf<T>(), (uint)slice.Length);
60+
return Unsafe.ReadUnaligned<T>(ref slice.DangerousGetPinnableReference());
61+
}
62+
63+
/// <summary>
64+
/// Reads a structure of type T out of a slice of bytes.
65+
/// </summary>
66+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
67+
public static T Read<[Primitive]T>(this ReadOnlySpan<byte> slice)
68+
where T : struct
69+
{
70+
RequiresInInclusiveRange(Unsafe.SizeOf<T>(), (uint)slice.Length);
71+
return Unsafe.ReadUnaligned<T>(ref slice.DangerousGetPinnableReference());
72+
}
73+
74+
/// <summary>
75+
/// Reads a structure of type T out of a slice of bytes.
76+
/// </summary>
77+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
78+
public static bool TryRead<[Primitive]T>(this ReadOnlySpan<byte> slice, out T value)
79+
where T : struct
80+
{
81+
if (Unsafe.SizeOf<T>() > (uint)slice.Length)
82+
{
83+
value = default(T);
84+
return false;
85+
}
86+
value = Unsafe.ReadUnaligned<T>(ref slice.DangerousGetPinnableReference());
87+
return true;
88+
}
89+
90+
/// <summary>
91+
/// Reads a structure of type T out of a slice of bytes.
92+
/// </summary>
93+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
94+
public static bool TryRead<[Primitive]T>(this Span<byte> slice, out T value)
95+
where T : struct
96+
{
97+
if (Unsafe.SizeOf<T>() > (uint)slice.Length)
98+
{
99+
value = default(T);
100+
return false;
101+
}
102+
value = Unsafe.ReadUnaligned<T>(ref slice.DangerousGetPinnableReference());
103+
return true;
104+
}
105+
106+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
107+
public static void RequiresInInclusiveRange(int start, uint length)
108+
{
109+
if ((uint)start > length)
110+
{
111+
throw new ArgumentOutOfRangeException();
112+
}
113+
}
114+
}
115+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// This file was processed with Internalizer tool and should not be edited manually
2+
3+
using System;
4+
using System.Buffers;
5+
using System.Runtime;
6+
7+
// Copyright (c) Microsoft. All rights reserved.
8+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
9+
10+
using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime;
11+
using System.Runtime.CompilerServices;
12+
13+
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.System.Binary
14+
{
15+
/// <summary>
16+
/// Writes endian-specific primitives into spans.
17+
/// </summary>
18+
/// <remarks>
19+
/// Use these helpers when you need to write specific endinaness.
20+
/// </remarks>
21+
public static class BufferWriter
22+
{
23+
/// <summary>
24+
/// Writes a structure of type T to a span of bytes.
25+
/// </summary>
26+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
27+
public static void WriteBigEndian<[Primitive]T>(this Span<byte> span, T value) where T : struct
28+
=> span.Write(BitConverter.IsLittleEndian ? UnsafeUtilities.Reverse(value) : value);
29+
30+
/// <summary>
31+
/// Writes a structure of type T to a span of bytes.
32+
/// </summary>
33+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
34+
public static void WriteLittleEndian<[Primitive]T>(this Span<byte> span, T value) where T : struct
35+
=> span.Write(BitConverter.IsLittleEndian ? value : UnsafeUtilities.Reverse(value));
36+
37+
38+
39+
/// <summary>
40+
/// Writes a structure of type T into a slice of bytes.
41+
/// </summary>
42+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
43+
public static void Write<[Primitive]T>(this Span<byte> slice, T value)
44+
where T : struct
45+
{
46+
if ((uint)Unsafe.SizeOf<T>() > (uint)slice.Length)
47+
{
48+
throw new ArgumentOutOfRangeException();
49+
}
50+
Unsafe.WriteUnaligned<T>(ref slice.DangerousGetPinnableReference(), value);
51+
}
52+
53+
/// <summary>
54+
/// Writes a structure of type T into a slice of bytes.
55+
/// </summary>
56+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
57+
public static bool TryWrite<[Primitive]T>(this Span<byte> slice, T value)
58+
where T : struct
59+
{
60+
if (Unsafe.SizeOf<T>() > (uint)slice.Length)
61+
{
62+
return false;
63+
}
64+
Unsafe.WriteUnaligned<T>(ref slice.DangerousGetPinnableReference(), value);
65+
return true;
66+
}
67+
}
68+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This file was processed with Internalizer tool and should not be edited manually
2+
3+
using System;
4+
using System.Buffers;
5+
using System.Runtime;
6+
7+
// Copyright (c) Microsoft. All rights reserved.
8+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
9+
10+
using System.Runtime.CompilerServices;
11+
12+
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime
13+
{
14+
/// <summary>
15+
/// A collection of unsafe helper methods that we cannot implement in C#.
16+
/// NOTE: these can be used for VeryBadThings(tm), so tread with care...
17+
/// </summary>
18+
internal static class UnsafeUtilities
19+
{
20+
/// <summary>
21+
/// Reverses a primitive value - performs an endianness swap
22+
/// </summary>
23+
public static unsafe T Reverse<[Primitive]T>(T value) where T : struct
24+
{
25+
// note: relying on JIT goodness here!
26+
if (typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte)) {
27+
return value;
28+
}
29+
else if (typeof(T) == typeof(ushort) || typeof(T) == typeof(short)) {
30+
ushort val = 0;
31+
Unsafe.Write(&val, value);
32+
val = (ushort)((val >> 8) | (val << 8));
33+
return Unsafe.Read<T>(&val);
34+
}
35+
else if (typeof(T) == typeof(uint) || typeof(T) == typeof(int)
36+
|| typeof(T) == typeof(float)) {
37+
uint val = 0;
38+
Unsafe.Write(&val, value);
39+
val = (val << 24)
40+
| ((val & 0xFF00) << 8)
41+
| ((val & 0xFF0000) >> 8)
42+
| (val >> 24);
43+
return Unsafe.Read<T>(&val);
44+
}
45+
else if (typeof(T) == typeof(ulong) || typeof(T) == typeof(long)
46+
|| typeof(T) == typeof(double)) {
47+
ulong val = 0;
48+
Unsafe.Write(&val, value);
49+
val = (val << 56)
50+
| ((val & 0xFF00) << 40)
51+
| ((val & 0xFF0000) << 24)
52+
| ((val & 0xFF000000) << 8)
53+
| ((val & 0xFF00000000) >> 8)
54+
| ((val & 0xFF0000000000) >> 24)
55+
| ((val & 0xFF000000000000) >> 40)
56+
| (val >> 56);
57+
return Unsafe.Read<T>(&val);
58+
}
59+
else {
60+
// default implementation
61+
int len = Unsafe.SizeOf<T>();
62+
var val = stackalloc byte[len];
63+
Unsafe.Write(val, value);
64+
int to = len >> 1, dest = len - 1;
65+
for (int i = 0; i < to; i++) {
66+
var tmp = val[i];
67+
val[i] = val[dest];
68+
val[dest--] = tmp;
69+
}
70+
return Unsafe.Read<T>(val);
71+
}
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)