Skip to content

Commit

Permalink
Merge branch 'main' into browser_test_mt
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara authored Apr 10, 2024
2 parents cd8a043 + 4d5e5ff commit 8ec5a4b
Show file tree
Hide file tree
Showing 30 changed files with 586 additions and 178 deletions.
3 changes: 3 additions & 0 deletions eng/DotNetBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<!-- Pass through special build modes controlled by properties -->
<InnerBuildArgs Condition="'$(DotNetBuildRuntimeWasmEnableThreads)' == 'true'">$(InnerBuildArgs) /p:WasmEnableThreads=true</InnerBuildArgs>
<InnerBuildArgs Condition="'$(DotNetBuildRuntimeNativeAOTRuntimePack)' == 'true'">$(InnerBuildArgs) $(FlagParameterPrefix)s clr.nativeaotlibs+clr.nativeaotruntime+libs+packs /p:BuildNativeAOTRuntimePack=true /p:SkipLibrariesNativeRuntimePackages=true</InnerBuildArgs>
<InnerBuildArgs Condition="'$(DotNetBuildMonoEnableLLVM)' != ''">$(InnerBuildArgs) /p:MonoEnableLLVM=$(DotNetBuildMonoEnableLLVM)</InnerBuildArgs>
<InnerBuildArgs Condition="'$(DotNetBuildMonoAOTEnableLLVM)' != ''">$(InnerBuildArgs) /p:MonoAOTEnableLLVM=$(DotNetBuildMonoAOTEnableLLVM)</InnerBuildArgs>
<InnerBuildArgs Condition="'$(DotNetBuildMonoBundleLLVMOptimizer)' != ''">$(InnerBuildArgs) /p:MonoBundleLLVMOptimizer=$(DotNetBuildMonoBundleLLVMOptimizer)</InnerBuildArgs>
<InnerBuildArgs Condition="'$(PgoInstrument)' == 'true'">$(InnerBuildArgs) $(FlagParameterPrefix)pgoinstrument</InnerBuildArgs>

<!-- This prop needs to be passed to the inner build manually as the BaseInnerSourceBuildCommand gets overriden above -->
Expand Down
7 changes: 7 additions & 0 deletions eng/pipelines/common/variables.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
parameters:
- name: templatePath
type: string
default: 'templates'

variables:

# These values enable longer delays, configurable number of retries, and special understanding of TCP hang-up
Expand Down Expand Up @@ -54,3 +59,5 @@ variables:
eq(variables['isRollingBuild'], true))) ]

- template: /eng/pipelines/common/perf-variables.yml

- template: /eng/common/${{ parameters.templatePath }}/variables/pool-providers.yml
2 changes: 2 additions & 0 deletions eng/pipelines/runtime-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pr: none

variables:
- template: /eng/pipelines/common/variables.yml
parameters:
templatePath: 'templates-official'
- template: /eng/pipelines/common/internal-variables.yml
parameters:
teamName: dotnet-core-acquisition
Expand Down
12 changes: 10 additions & 2 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5616,8 +5616,16 @@ void Lowering::InsertPInvokeMethodProlog()
call->gtArgs.PushBack(comp, frameAddrArg);
// for x86/arm32 don't pass the secretArg.
#if !defined(TARGET_X86) && !defined(TARGET_ARM)
NewCallArg stubParamArg =
NewCallArg::Primitive(PhysReg(REG_SECRET_STUB_PARAM)).WellKnown(WellKnownArg::SecretStubParam);
GenTree* argNode;
if (comp->info.compPublishStubParam)
{
argNode = comp->gtNewLclvNode(comp->lvaStubArgumentVar, TYP_I_IMPL);
}
else
{
argNode = comp->gtNewIconNode(0, TYP_I_IMPL);
}
NewCallArg stubParamArg = NewCallArg::Primitive(argNode).WellKnown(WellKnownArg::SecretStubParam);
call->gtArgs.PushBack(comp, stubParamArg);
#endif

Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/jit/optcse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4813,8 +4813,12 @@ void CSE_HeuristicCommon::PerformCSE(CSE_Candidate* successfulCandidate)

assert(vnStore->IsVNCompareCheckedBoundArith(oldCmpVN));
vnStore->GetCompareCheckedBoundArithInfo(oldCmpVN, &info);
newCmpArgVN = vnStore->VNForFunc(vnStore->TypeOfVN(info.arrOp), (VNFunc)info.arrOper,
info.arrOp, theConservativeVN);

ValueNum arrOp1 = info.arrOpLHS ? info.arrOp : theConservativeVN;
ValueNum arrOp2 = info.arrOpLHS ? theConservativeVN : info.arrOp;

newCmpArgVN =
vnStore->VNForFunc(vnStore->TypeOfVN(info.arrOp), (VNFunc)info.arrOper, arrOp1, arrOp2);
}
ValueNum newCmpVN = vnStore->VNForFunc(vnStore->TypeOfVN(oldCmpVN), (VNFunc)info.cmpOper,
info.cmpOp, newCmpArgVN);
Expand Down
14 changes: 8 additions & 6 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6669,15 +6669,17 @@ void ValueNumStore::GetCheckedBoundArithInfo(ValueNum vn, CompareCheckedBoundAri
bool isOp1CheckedBound = IsVNCheckedBound(funcArith.m_args[1]);
if (isOp1CheckedBound)
{
info->arrOper = funcArith.m_func;
info->arrOp = funcArith.m_args[0];
info->vnBound = funcArith.m_args[1];
info->arrOper = funcArith.m_func;
info->arrOp = funcArith.m_args[0];
info->vnBound = funcArith.m_args[1];
info->arrOpLHS = true;
}
else
{
info->arrOper = funcArith.m_func;
info->arrOp = funcArith.m_args[1];
info->vnBound = funcArith.m_args[0];
info->arrOper = funcArith.m_func;
info->arrOp = funcArith.m_args[1];
info->vnBound = funcArith.m_args[0];
info->arrOpLHS = false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,14 @@ class ValueNumStore
ValueNum vnBound;
unsigned arrOper;
ValueNum arrOp;
bool arrOpLHS; // arrOp is on the left side of cmpOp expression
unsigned cmpOper;
ValueNum cmpOp;
CompareCheckedBoundArithInfo()
: vnBound(NoVN)
, arrOper(GT_NONE)
, arrOp(NoVN)
, arrOpLHS(false)
, cmpOper(GT_NONE)
, cmpOp(NoVN)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,33 +965,37 @@ private static SizeAndAlignment ComputeInstanceSize(MetadataType type, LayoutInt
{
SizeAndAlignment result;

// Pad the length of structs to be 1 if they are empty so we have no zero-length structures
// Pad the length of structs to be 1 if they are empty, so we have no zero-length structures
if (type.IsValueType && instanceSize == LayoutInt.Zero)
{
instanceSize = LayoutInt.One;
}

TargetDetails target = type.Context.Target;

if (classLayoutSize != 0)
if (type.IsValueType)
{
LayoutInt parentSize;
if (type.IsValueType)
parentSize = new LayoutInt(0);
else
parentSize = type.BaseType.InstanceByteCountUnaligned;

LayoutInt specifiedInstanceSize = parentSize + new LayoutInt(classLayoutSize);
if (classLayoutSize != 0)
{
instanceSize = LayoutInt.Max(new LayoutInt(classLayoutSize), instanceSize);

instanceSize = LayoutInt.Max(specifiedInstanceSize, instanceSize);
}
else
{
if (type.IsValueType)
// Size of a struct with gc references is always expected to be aligned to pointer size
if (type.ContainsGCPointers)
{
instanceSize = LayoutInt.AlignUp(instanceSize, new LayoutInt(target.PointerSize), target);
}
}
else
{
instanceSize = LayoutInt.AlignUp(instanceSize, alignment, target);
}
}
else if (classLayoutSize != 0 && type.IsSequentialLayout && !type.ContainsGCPointers)
{
// For classes, we respect classLayoutSize only for SequentialLayout + no gc fields
LayoutInt specifiedInstanceSize = type.BaseType.InstanceByteCountUnaligned + new LayoutInt(classLayoutSize);
instanceSize = LayoutInt.Max(specifiedInstanceSize, instanceSize);
}

if (type.IsValueType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void TestExplicitLayoutThatIsEmpty()
public void TestExplicitTypeLayoutWithSize()
{
var explicitSizeType = _testModule.GetType("Explicit", "ExplicitSize");
Assert.Equal(48, explicitSizeType.InstanceByteCount.AsInt);
Assert.Equal(32, explicitSizeType.InstanceByteCount.AsInt);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ internal static partial class Interop
{
internal static partial class OpenSsl
{
#if DEBUG
private static readonly string? s_keyLogFile = Environment.GetEnvironmentVariable("SSLKEYLOGFILE");
private static readonly FileStream? s_fileStream = s_keyLogFile != null ? File.Open(s_keyLogFile, FileMode.Append, FileAccess.Write, FileShare.ReadWrite) : null;
#endif
private const string TlsCacheSizeCtxName = "System.Net.Security.TlsCacheSize";
private const string TlsCacheSizeEnvironmentVariable = "DOTNET_SYSTEM_NET_SECURITY_TLSCACHESIZE";
private const SslProtocols FakeAlpnSslProtocol = (SslProtocols)1; // used to distinguish server sessions with ALPN
Expand Down Expand Up @@ -209,12 +205,10 @@ internal static unsafe SafeSslContextHandle AllocateSslContext(SslAuthentication
Ssl.SslCtxSetDefaultOcspCallback(sslCtx);
}
}
#if DEBUG
if (s_fileStream != null)
if (SslKeyLogger.IsEnabled)
{
Ssl.SslCtxSetKeylogCallback(sslCtx, &KeyLogCallback);
}
#endif
}
catch
{
Expand Down Expand Up @@ -757,23 +751,12 @@ private static unsafe void RemoveSessionCallback(IntPtr ctx, IntPtr session)
ctxHandle.RemoveSession(name);
}

#if DEBUG
[UnmanagedCallersOnly]
private static unsafe void KeyLogCallback(IntPtr ssl, char* line)
{
Debug.Assert(s_fileStream != null);
ReadOnlySpan<byte> data = MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)line);
if (data.Length > 0)
{
lock (s_fileStream)
{
s_fileStream.Write(data);
s_fileStream.WriteByte((byte)'\n');
s_fileStream.Flush();
}
}
SslKeyLogger.WriteLineRaw(data);
}
#endif

private static int BioRead(SafeBioHandle bio, Span<byte> buffer, int count)
{
Expand Down
134 changes: 134 additions & 0 deletions src/libraries/Common/src/System/Net/Security/SslKeyLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using System.Net;

internal static class SslKeyLogger
{
private static readonly string? s_keyLogFile = Environment.GetEnvironmentVariable("SSLKEYLOGFILE");
private static readonly FileStream? s_fileStream;

#pragma warning disable CA1810 // Initialize all static fields when declared and remove cctor
static SslKeyLogger()
{
s_fileStream = null;

try
{
#if DEBUG
bool isEnabled = true;
#else
bool isEnabled = AppContext.TryGetSwitch("System.Net.EnableSslKeyLogging", out bool enabled) && enabled;
#endif

if (isEnabled && s_keyLogFile != null)
{
s_fileStream = File.Open(s_keyLogFile, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
}
}
catch (Exception ex)
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Error(null, $"Failed to open SSL key log file '{s_keyLogFile}': {ex}");
}
}
}
#pragma warning restore CA1810

public static bool IsEnabled => s_fileStream != null;

public static void WriteLineRaw(ReadOnlySpan<byte> data)
{
Debug.Assert(s_fileStream != null);
if (s_fileStream == null)
{
return;
}

if (data.Length > 0)
{
lock (s_fileStream)
{
s_fileStream.Write(data);
s_fileStream.WriteByte((byte)'\n');
s_fileStream.Flush();
}
}
}

public static void WriteSecrets(
ReadOnlySpan<byte> clientRandom,
ReadOnlySpan<byte> clientHandshakeTrafficSecret,
ReadOnlySpan<byte> serverHandshakeTrafficSecret,
ReadOnlySpan<byte> clientTrafficSecret0,
ReadOnlySpan<byte> serverTrafficSecret0,
ReadOnlySpan<byte> clientEarlyTrafficSecret)
{
Debug.Assert(s_fileStream != null);
Debug.Assert(!clientRandom.IsEmpty);

if (s_fileStream == null ||
clientRandom.IsEmpty ||

// return early if there is nothing to log
(clientHandshakeTrafficSecret.IsEmpty &&
serverHandshakeTrafficSecret.IsEmpty &&
clientTrafficSecret0.IsEmpty &&
serverTrafficSecret0.IsEmpty &&
clientEarlyTrafficSecret.IsEmpty))
{
return;
}

Span<byte> clientRandomUtf8 = clientRandom.Length <= 1024 ? stackalloc byte[clientRandom.Length * 2] : new byte[clientRandom.Length * 2];
HexEncode(clientRandom, clientRandomUtf8);

lock (s_fileStream)
{
WriteSecretCore("CLIENT_HANDSHAKE_TRAFFIC_SECRET"u8, clientRandomUtf8, clientHandshakeTrafficSecret);
WriteSecretCore("SERVER_HANDSHAKE_TRAFFIC_SECRET"u8, clientRandomUtf8, serverHandshakeTrafficSecret);
WriteSecretCore("CLIENT_TRAFFIC_SECRET_0"u8, clientRandomUtf8, clientTrafficSecret0);
WriteSecretCore("SERVER_TRAFFIC_SECRET_0"u8, clientRandomUtf8, serverTrafficSecret0);
WriteSecretCore("CLIENT_EARLY_TRAFFIC_SECRET"u8, clientRandomUtf8, clientEarlyTrafficSecret);

s_fileStream.Flush();
}
}

private static void WriteSecretCore(ReadOnlySpan<byte> labelUtf8, ReadOnlySpan<byte> clientRandomUtf8, ReadOnlySpan<byte> secret)
{
if (secret.Length == 0)
{
return;
}

// write the secret line in the format {label} {client_random (hex)} {secret (hex)} e.g.
// SERVER_HANDSHAKE_TRAFFIC_SECRET bae582227f0f46ca663cb8c3d62e68cec38c2b947e7c4a9ec6f4e262b5ed5354 48f6bd5b0c8447d97129c6dad080f34c7f9f11ade8eeabb011f33811543411d7ab1013b1374bcd81bfface6a2deef539
int totalLength = labelUtf8.Length + 1 + clientRandomUtf8.Length + 1 + 2 * secret.Length + 1;
Span<byte> line = totalLength <= 1024 ? stackalloc byte[totalLength] : new byte[totalLength];

labelUtf8.CopyTo(line);
line[labelUtf8.Length] = (byte)' ';

clientRandomUtf8.CopyTo(line.Slice(labelUtf8.Length + 1));
line[labelUtf8.Length + 1 + clientRandomUtf8.Length] = (byte)' ';

HexEncode(secret, line.Slice(labelUtf8.Length + 1 + clientRandomUtf8.Length + 1));
line[^1] = (byte)'\n';

s_fileStream!.Write(line);
}

private static void HexEncode(ReadOnlySpan<byte> source, Span<byte> destination)
{
for (int i = 0; i < source.Length; i++)
{
HexConverter.ToBytesBuffer(source[i], destination.Slice(i * 2));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ await LoopbackServer.CreateServerAsync(async (server, url) =>
}, options);
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/29419")]
[Theory]
[InlineData(ClientCertificateOption.Manual)]
[InlineData(ClientCertificateOption.Automatic)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public async Task SendStreamLimitRequestsConcurrently_Succeeds(int streamLimit)
{
await using Http3LoopbackStream stream = await connection.AcceptRequestStreamAsync();
await stream.HandleRequestAsync();
_output.WriteLine($"[{DateTime.Now:HH:mm:ss.fffffff}] Server: Finished request {i}");
}
});

Expand All @@ -156,9 +157,11 @@ public async Task SendStreamLimitRequestsConcurrently_Succeeds(int streamLimit)
};
tasks[i] = client.SendAsync(request);
_output.WriteLine($"[{DateTime.Now:HH:mm:ss.fffffff}] Client: Started request {i}");
});
var responses = await Task.WhenAll(tasks);
_output.WriteLine($"[{DateTime.Now:HH:mm:ss.fffffff}] Client: Got all responses");
foreach (var response in responses)
{
response.Dispose();
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<Compile Include="$(CommonPath)System\Net\Security\TlsAlertMessage.cs" Link="Common\System\Net\Security\TlsAlertMessage.cs" />
<Compile Include="$(CommonPath)System\HexConverter.cs" Link="Common\System\HexConverter.cs" />
<Compile Include="$(CommonPath)System\Net\Security\TargetHostNameHelper.cs" Link="Common\System\Net\Security\TargetHostNameHelper.cs" />
<Compile Include="$(CommonPath)System\Net\Security\SslKeyLogger.cs" Link="Common\System\Net\Security\SslKeyLogger.cs" />
<!-- IP parser -->
<Compile Include="$(CommonPath)System\Net\IPv4AddressHelper.Common.cs" Link="System\Net\IPv4AddressHelper.Common.cs" />
<Compile Include="$(CommonPath)System\Net\IPv6AddressHelper.Common.cs" Link="System\Net\IPv6AddressHelper.Common.cs" />
Expand Down
Loading

0 comments on commit 8ec5a4b

Please sign in to comment.