Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Temporary Workarounds for CoreLib Surface Area
Browse files Browse the repository at this point in the history
The UAP System.Private.CoreLib is missing two recent changes and we are blocked consuming it until we get CoreFX UAP. To unbreak the cycle, paper over a couple recent breaking surface area changes in System.Private.CoreLib until we get a new UAP package containing it.  At that point, this commit can be reverted.
  • Loading branch information
nattress committed Mar 1, 2018
1 parent 14a4407 commit d799751
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/System.Net.Security/src/System.Net.Security.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ProjectGuid>{89F37791-6254-4D60-AB96-ACD3CCA0E771}</ProjectGuid>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ILLinkClearInitLocals>true</ILLinkClearInitLocals>
<DefineConstants Condition="'$(TargetGroup)' == 'uap'">$(DefineConstants);uap</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetsOSX)' == 'true' ">
<DefineConstants>$(DefineConstants);SYSNETSECURITY_NO_OPENSSL</DefineConstants>
Expand Down
33 changes: 33 additions & 0 deletions src/System.Net.Security/src/System/Net/Security/SslState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,11 @@ internal void FinishRead(byte[] renegotiateBuffer)
AsyncProtocolRequest request = (AsyncProtocolRequest)_queuedReadStateRequest;
request.Buffer = renegotiateBuffer;
_queuedReadStateRequest = null;
#if uap
ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncResumeHandshakeRead), request);
#else
ThreadPool.QueueUserWorkItem(s => s.sslState.AsyncResumeHandshakeRead(s.request), (sslState: this, request), preferLocal: false);
#endif
}
}
}
Expand Down Expand Up @@ -1382,7 +1386,11 @@ private void HandleQueuedCallback(ref object queuedStateRequest)
taskCompletionSource.SetResult(0);
break;
default:
#if uap
ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncResumeHandshake), obj);
#else
ThreadPool.QueueUserWorkItem(s => s.sslState.AsyncResumeHandshake(s.obj), (sslState: this, obj), preferLocal: false);
#endif
break;
}
}
Expand Down Expand Up @@ -1746,8 +1754,15 @@ private void AsyncResumeHandshake(object state)
//
// Called with no user stack.
//
#if uap
private void AsyncResumeHandshakeRead(object state)
#else
private void AsyncResumeHandshakeRead(AsyncProtocolRequest asyncRequest)
#endif
{
#if uap
AsyncProtocolRequest asyncRequest = (AsyncProtocolRequest)state;
#endif
try
{
if (_pendingReHandshake)
Expand All @@ -1773,6 +1788,24 @@ private void AsyncResumeHandshakeRead(AsyncProtocolRequest asyncRequest)
}
}

#if uap
//
// Called with no user stack.
//
private void CompleteRequestWaitCallback(object state)
{
AsyncProtocolRequest request = (AsyncProtocolRequest)state;

// Force async completion.
if (request.MustCompleteSynchronously)
{
throw new InternalException();
}

request.CompleteRequest(0);
}
#endif

private void RehandshakeCompleteCallback(IAsyncResult result)
{
LazyAsyncResult lazyAsyncResult = (LazyAsyncResult)result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<Compile Include="System\Environment.cs" />
<Compile Include="System\Environment.SpecialFolder.cs" />
<Compile Include="System\Environment.SpecialFolderOption.cs" />
<Compile Include="System\Globalization\Extensions.cs" Condition="'$(TargetGroup)' == 'uapaot'"/>
<Compile Include="System\LoaderOptimization.cs" />
<Compile Include="System\LoaderOptimizationAttribute.cs" />
<Compile Include="System\OperatingSystem.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;

namespace System.Globalization
{
public static class GlobalizationExtensions
{
public static StringComparer GetStringComparer(this CompareInfo compareInfo, CompareOptions options)
{
if (compareInfo == null)
{
throw new ArgumentNullException(nameof(compareInfo));
}

if (options == CompareOptions.Ordinal)
{
return StringComparer.Ordinal;
}

if (options == CompareOptions.OrdinalIgnoreCase)
{
return StringComparer.OrdinalIgnoreCase;
}

if ((options & CultureAwareComparer.ValidCompareMaskOffFlags) != 0)
{
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}

return new CultureAwareComparer(compareInfo, options);
}
}

internal sealed class CultureAwareComparer : StringComparer
{
internal const CompareOptions ValidCompareMaskOffFlags =
~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace |
CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType | CompareOptions.StringSort);

private readonly CompareInfo _compareInfo;
private readonly CompareOptions _options;

internal CultureAwareComparer(CompareInfo compareInfo, CompareOptions options)
{
Debug.Assert((options & ValidCompareMaskOffFlags) == 0);
_compareInfo = compareInfo;
_options = options;
}

public override int Compare(string x, string y)
{
if (Object.ReferenceEquals(x, y)) return 0;
if (x == null) return -1;
if (y == null) return 1;
return _compareInfo.Compare(x, y, _options);
}

public override bool Equals(string x, string y)
{
if (Object.ReferenceEquals(x, y)) return true;
if (x == null || y == null) return false;

return (_compareInfo.Compare(x, y, _options) == 0);
}

public override int GetHashCode(string obj)
{
if (obj == null)
{
throw new ArgumentNullException(nameof(obj));
}

// StringSort used in compare operation and not with the hashing
return _compareInfo.GetHashCode(obj, _options & (~CompareOptions.StringSort));
}

// Equals method for the comparer itself.
public override bool Equals(object obj)
{
CultureAwareComparer comparer = obj as CultureAwareComparer;
return
comparer != null &&
_options == comparer._options &&
_compareInfo.Equals(comparer._compareInfo);
}

public override int GetHashCode()
{
return _compareInfo.GetHashCode() ^ ((int)_options & 0x7FFFFFFF);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public static partial class ThreadPool
public static void GetMinThreads(out int workerThreads, out int completionPortThreads) { throw null; }
public static bool QueueUserWorkItem(System.Threading.WaitCallback callBack) { throw null; }
public static bool QueueUserWorkItem(System.Threading.WaitCallback callBack, object state) { throw null; }
#if uap
public static bool QueueUserWorkItem(System.Threading.WaitCallback callBack, object state, bool preferLocal) { throw null; }
#else
public static bool QueueUserWorkItem<TState>(System.Action<TState> callBack, TState state, bool preferLocal) { throw null; }
#endif
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; }
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; }
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object state, System.TimeSpan timeout, bool executeOnlyOnce) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProjectGuid>{3A5A0D64-7796-4BC2-8288-4B04B97C4A70}</ProjectGuid>
<DefineConstants Condition="'$(TargetGroup)' == 'uap'">$(DefineConstants);uap</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
Expand Down

0 comments on commit d799751

Please sign in to comment.