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

Commit

Permalink
Commit a snapshot of corefxlab source code to ensure patch builds are…
Browse files Browse the repository at this point in the history
… reproducible
  • Loading branch information
Nate McMaster committed Oct 16, 2017
1 parent be4e401 commit 4afa9c8
Show file tree
Hide file tree
Showing 83 changed files with 9,351 additions and 2 deletions.
1 change: 0 additions & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
<MicrosoftAspNetCoreHttpFeaturesPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreHttpFeaturesPackageVersion>
<MicrosoftAspNetCoreHttpPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreHttpPackageVersion>
<MicrosoftAspNetCoreInternalCoreFxLabSourcesPackageVersion>2.0.0-rtm-21470</MicrosoftAspNetCoreInternalCoreFxLabSourcesPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.0.0</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftAspNetCoreWebUtilitiesPackageVersion>2.0.1-rtm-105</MicrosoftAspNetCoreWebUtilitiesPackageVersion>
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.0.0</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
Expand Down
114 changes: 114 additions & 0 deletions shared/corefxlab/SR.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
namespace System
{
// This is generated as part of corefx build process
internal static class SR
{
internal static string ArrayTypeMustBeExactMatch
{
get
{
return System.SR.GetResourceString("ArrayTypeMustBeExactMatch", null);
}
}

internal static string CannotCallEqualsOnSpan
{
get
{
return System.SR.GetResourceString("CannotCallEqualsOnSpan", null);
}
}

internal static string CannotCallGetHashCodeOnSpan
{
get
{
return System.SR.GetResourceString("CannotCallGetHashCodeOnSpan", null);
}
}

internal static string Argument_InvalidTypeWithPointersNotSupported
{
get
{
return System.SR.GetResourceString("Argument_InvalidTypeWithPointersNotSupported", null);
}
}

internal static string Argument_DestinationTooShort
{
get
{
return System.SR.GetResourceString("Argument_DestinationTooShort", null);
}
}

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static bool UsingResourceKeys()
{
return false;
}

internal static string GetResourceString(string resourceKey, string defaultString)
{
return resourceKey;
}

internal static string Format(string resourceFormat, params object[] args)
{
return resourceFormat + string.Join(", ", args);
}

internal static string Format(string resourceFormat, object p1)
{
if (System.SR.UsingResourceKeys())
{
return string.Join(", ", new object[]
{
resourceFormat,
p1
});
}
return string.Format(resourceFormat, p1);
}

internal static string Format(string resourceFormat, object p1, object p2)
{
if (System.SR.UsingResourceKeys())
{
return string.Join(", ", new object[]
{
resourceFormat,
p1,
p2
});
}
return string.Format(resourceFormat, p1, p2);
}

internal static string Format(string resourceFormat, object p1, object p2, object p3)
{
if (System.SR.UsingResourceKeys())
{
return string.Join(", ", new object[]
{
resourceFormat,
p1,
p2,
p3
});
}
return string.Format(resourceFormat, p1, p2, p3);
}
}
}

namespace Microsoft.AspNetCore.Server.Kestrel.Internal.System.Buffers.Internal
{
// We don't want to pull System.Buffers required by ManagedBufferPool implemenation
// and BufferPool depends on ManagedBufferPool.Shared
internal class ManagedBufferPool
{
public static BufferPool Shared { get; } = null;
}
}
115 changes: 115 additions & 0 deletions shared/corefxlab/System.Binary/System/Binary/BufferReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// This file was processed with Internalizer tool and should not be edited manually

using System;
using System.Buffers;
using System.Runtime;

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime;
using System.Runtime.CompilerServices;

namespace Microsoft.AspNetCore.Server.Kestrel.Internal.System.Binary
{
/// <summary>
/// Reads bytes as primitives with specific endianness
/// </summary>
/// <remarks>
/// For native formats, SpanExtensions.Read<T> should be used.
/// Use these helpers when you need to read specific endinanness.
/// </remarks>
public static class BufferReader
{
/// <summary>
/// Reads a structure of type <typeparamref name="T"/> out of a span of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T ReadBigEndian<[Primitive]T>(this ReadOnlySpan<byte> span) where T : struct
=> BitConverter.IsLittleEndian ? UnsafeUtilities.Reverse(span.Read<T>()) : span.Read<T>();

/// <summary>
/// Reads a structure of type <typeparamref name="T"/> out of a span of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T ReadLittleEndian<[Primitive]T>(this ReadOnlySpan<byte> span) where T : struct
=> BitConverter.IsLittleEndian ? span.Read<T>() : UnsafeUtilities.Reverse(span.Read<T>());

/// <summary>
/// Reads a structure of type <typeparamref name="T"/> out of a span of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T ReadBigEndian<[Primitive]T>(this Span<byte> span) where T : struct
=> BitConverter.IsLittleEndian ? UnsafeUtilities.Reverse(span.Read<T>()) : span.Read<T>();

/// <summary>
/// Reads a structure of type <typeparamref name="T"/> out of a span of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T ReadLittleEndian<[Primitive]T>(this Span<byte> span) where T : struct
=> BitConverter.IsLittleEndian ? span.Read<T>() : UnsafeUtilities.Reverse(span.Read<T>());

/// <summary>
/// Reads a structure of type T out of a slice of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Read<[Primitive]T>(this Span<byte> slice)
where T : struct
{
RequiresInInclusiveRange(Unsafe.SizeOf<T>(), (uint)slice.Length);
return Unsafe.ReadUnaligned<T>(ref slice.DangerousGetPinnableReference());
}

/// <summary>
/// Reads a structure of type T out of a slice of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Read<[Primitive]T>(this ReadOnlySpan<byte> slice)
where T : struct
{
RequiresInInclusiveRange(Unsafe.SizeOf<T>(), (uint)slice.Length);
return Unsafe.ReadUnaligned<T>(ref slice.DangerousGetPinnableReference());
}

/// <summary>
/// Reads a structure of type T out of a slice of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryRead<[Primitive]T>(this ReadOnlySpan<byte> slice, out T value)
where T : struct
{
if (Unsafe.SizeOf<T>() > (uint)slice.Length)
{
value = default(T);
return false;
}
value = Unsafe.ReadUnaligned<T>(ref slice.DangerousGetPinnableReference());
return true;
}

/// <summary>
/// Reads a structure of type T out of a slice of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryRead<[Primitive]T>(this Span<byte> slice, out T value)
where T : struct
{
if (Unsafe.SizeOf<T>() > (uint)slice.Length)
{
value = default(T);
return false;
}
value = Unsafe.ReadUnaligned<T>(ref slice.DangerousGetPinnableReference());
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RequiresInInclusiveRange(int start, uint length)
{
if ((uint)start > length)
{
throw new ArgumentOutOfRangeException();
}
}
}
}
68 changes: 68 additions & 0 deletions shared/corefxlab/System.Binary/System/Binary/BufferWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// This file was processed with Internalizer tool and should not be edited manually

using System;
using System.Buffers;
using System.Runtime;

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime;
using System.Runtime.CompilerServices;

namespace Microsoft.AspNetCore.Server.Kestrel.Internal.System.Binary
{
/// <summary>
/// Writes endian-specific primitives into spans.
/// </summary>
/// <remarks>
/// Use these helpers when you need to write specific endinaness.
/// </remarks>
public static class BufferWriter
{
/// <summary>
/// Writes a structure of type T to a span of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteBigEndian<[Primitive]T>(this Span<byte> span, T value) where T : struct
=> span.Write(BitConverter.IsLittleEndian ? UnsafeUtilities.Reverse(value) : value);

/// <summary>
/// Writes a structure of type T to a span of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteLittleEndian<[Primitive]T>(this Span<byte> span, T value) where T : struct
=> span.Write(BitConverter.IsLittleEndian ? value : UnsafeUtilities.Reverse(value));



/// <summary>
/// Writes a structure of type T into a slice of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Write<[Primitive]T>(this Span<byte> slice, T value)
where T : struct
{
if ((uint)Unsafe.SizeOf<T>() > (uint)slice.Length)
{
throw new ArgumentOutOfRangeException();
}
Unsafe.WriteUnaligned<T>(ref slice.DangerousGetPinnableReference(), value);
}

/// <summary>
/// Writes a structure of type T into a slice of bytes.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWrite<[Primitive]T>(this Span<byte> slice, T value)
where T : struct
{
if (Unsafe.SizeOf<T>() > (uint)slice.Length)
{
return false;
}
Unsafe.WriteUnaligned<T>(ref slice.DangerousGetPinnableReference(), value);
return true;
}
}
}
74 changes: 74 additions & 0 deletions shared/corefxlab/System.Binary/System/Binary/UnsafeUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// This file was processed with Internalizer tool and should not be edited manually

using System;
using System.Buffers;
using System.Runtime;

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Runtime.CompilerServices;

namespace Microsoft.AspNetCore.Server.Kestrel.Internal.System.Runtime
{
/// <summary>
/// A collection of unsafe helper methods that we cannot implement in C#.
/// NOTE: these can be used for VeryBadThings(tm), so tread with care...
/// </summary>
internal static class UnsafeUtilities
{
/// <summary>
/// Reverses a primitive value - performs an endianness swap
/// </summary>
public static unsafe T Reverse<[Primitive]T>(T value) where T : struct
{
// note: relying on JIT goodness here!
if (typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte)) {
return value;
}
else if (typeof(T) == typeof(ushort) || typeof(T) == typeof(short)) {
ushort val = 0;
Unsafe.Write(&val, value);
val = (ushort)((val >> 8) | (val << 8));
return Unsafe.Read<T>(&val);
}
else if (typeof(T) == typeof(uint) || typeof(T) == typeof(int)
|| typeof(T) == typeof(float)) {
uint val = 0;
Unsafe.Write(&val, value);
val = (val << 24)
| ((val & 0xFF00) << 8)
| ((val & 0xFF0000) >> 8)
| (val >> 24);
return Unsafe.Read<T>(&val);
}
else if (typeof(T) == typeof(ulong) || typeof(T) == typeof(long)
|| typeof(T) == typeof(double)) {
ulong val = 0;
Unsafe.Write(&val, value);
val = (val << 56)
| ((val & 0xFF00) << 40)
| ((val & 0xFF0000) << 24)
| ((val & 0xFF000000) << 8)
| ((val & 0xFF00000000) >> 8)
| ((val & 0xFF0000000000) >> 24)
| ((val & 0xFF000000000000) >> 40)
| (val >> 56);
return Unsafe.Read<T>(&val);
}
else {
// default implementation
int len = Unsafe.SizeOf<T>();
var val = stackalloc byte[len];
Unsafe.Write(val, value);
int to = len >> 1, dest = len - 1;
for (int i = 0; i < to; i++) {
var tmp = val[i];
val[i] = val[dest];
val[dest--] = tmp;
}
return Unsafe.Read<T>(val);
}
}
}
}
Loading

0 comments on commit 4afa9c8

Please sign in to comment.