From 7136ea244f57329cba5d21d6950cfac0040f60de Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 13:53:12 +0300 Subject: [PATCH 01/22] [release/8.0-staging] [STJ] Account for F# CompilationMappingAttribute now supporting multiple declarations. (#115077) * Account for CompilationMappingAttribute supporting multiple declarations. * Update package version --------- Co-authored-by: Eirik Tsarpalis --- .../src/System.Text.Json.csproj | 4 ++-- .../Metadata/FSharpCoreReflectionProxy.cs | 7 +++++-- .../RecordTests.fs | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index fb8f4321a63b92..72aa247909efd2 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -8,8 +8,8 @@ CS8969 true true - false - 5 + true + 6 Provides high-performance and low-allocating types that serialize objects to JavaScript Object Notation (JSON) text and deserialize JSON text to objects, with UTF-8 support built-in. Also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM), that is read-only, for random access of the JSON elements within a structured view of the data. The System.Text.Json library is built-in as part of the shared framework in .NET Runtime. The package can be installed when you need to use it in other target frameworks. diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs index e0bd83a0c1c9bf..835da6e002f905 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/FSharpCoreReflectionProxy.cs @@ -204,7 +204,10 @@ public Func>, TFSharpMap> CreateFSharpMapConstru } private Attribute? GetFSharpCompilationMappingAttribute(Type type) - => type.GetCustomAttribute(_compilationMappingAttributeType, inherit: true); + { + object[] attributes = type.GetCustomAttributes(_compilationMappingAttributeType, inherit: false); + return attributes.Length == 0 ? null : (Attribute)attributes[0]; + } private SourceConstructFlags GetSourceConstructFlags(Attribute compilationMappingAttribute) => _sourceConstructFlagsGetter is null ? SourceConstructFlags.None : (SourceConstructFlags)_sourceConstructFlagsGetter.Invoke(compilationMappingAttribute, null)!; @@ -212,7 +215,7 @@ private SourceConstructFlags GetSourceConstructFlags(Attribute compilationMappin // If the provided type is generated by the F# compiler, returns the runtime FSharp.Core assembly. private static Assembly? GetFSharpCoreAssembly(Type type) { - foreach (Attribute attr in type.GetCustomAttributes(inherit: true)) + foreach (Attribute attr in type.GetCustomAttributes(inherit: false)) { Type attributeType = attr.GetType(); if (attributeType.FullName == CompilationMappingAttributeTypeName) diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.FSharp.Tests/RecordTests.fs b/src/libraries/System.Text.Json/tests/System.Text.Json.FSharp.Tests/RecordTests.fs index d9ac41cbd2b41d..6044b692904ef4 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.FSharp.Tests/RecordTests.fs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.FSharp.Tests/RecordTests.fs @@ -76,3 +76,22 @@ let ``Recursive struct records are supported``() = Assert.Equal("""{"Next":[{"Next":[null]}]}""", json) let deserializedValue = JsonSerializer.Deserialize(json) Assert.Equal(value, deserializedValue) + + +[, "derived")>] +type BaseClass(x : int) = + member _.X = x + +and DerivedClass(x : int, y : bool) = + inherit BaseClass(x) + member _.Y = y + +[] +let ``Support F# class hierarchies`` () = + let value = DerivedClass(42, true) :> BaseClass + let json = JsonSerializer.Serialize(value) + Assert.Equal("""{"$type":"derived","Y":true,"X":42}""", json) + let deserializedValue = JsonSerializer.Deserialize(json) + let derived = Assert.IsType(deserializedValue) + Assert.Equal(42, deserializedValue.X) + Assert.Equal(true, derived.Y) From 99dbb90d119569983b74017be09c2b4fb10b090c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 22 May 2025 16:27:50 -0700 Subject: [PATCH 02/22] throw an exception instead of infinite loop (#115528) Co-authored-by: Maoni0 --- src/coreclr/gc/gc.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index cc562b592112c5..b96b5917358ba5 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -10687,6 +10687,14 @@ size_t gc_heap::sort_mark_list() size_t region_index = get_basic_region_index_for_address (heap_segment_mem (region)); uint8_t* region_limit = heap_segment_allocated (region); + // Due to GC holes, x can point to something in a region that already got freed. And that region's + // allocated would be 0 and cause an infinite loop which is much harder to handle on production than + // simply throwing an exception. + if (region_limit == 0) + { + FATAL_GC_ERROR(); + } + uint8_t*** mark_list_piece_start_ptr = &mark_list_piece_start[region_index]; uint8_t*** mark_list_piece_end_ptr = &mark_list_piece_end[region_index]; #else // USE_REGIONS From 5b4a58814a2227a865f043b658cddedff2e16596 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 27 May 2025 09:05:58 +0200 Subject: [PATCH 03/22] [release/8.0-staging] [DNS] Ignore ObjectDisposedException on CancellationToken Callback (#115841) * Ignore ObjectDisposedException on CancellationToken Callback * Update src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs Co-authored-by: Jan Kotas * Change wording in comment * Update src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs --------- Co-authored-by: Ahmet Ibrahim Aksoy Co-authored-by: Jan Kotas --- .../src/System/Net/NameResolutionPal.Windows.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs index d088a30d6f7445..633d3eddcd465c 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs @@ -437,6 +437,11 @@ public void RegisterForCancellation(CancellationToken cancellationToken) NetEventSource.Info(@this, $"GetAddrInfoExCancel returned error {cancelResult}"); } } + catch (ObjectDisposedException) + { + // There is a race between checking @this._completed and @this.DangerousAddRef and disposing from another thread. + // We lost the race. No further action needed. + } finally { if (needRelease) From de66703ec7d58a8a8a817cc95cf1af743de75436 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 4 Jun 2025 11:00:08 +0200 Subject: [PATCH 04/22] [release/8.0-staging] Fix SysV first/second return register GC info mismatch (#116208) * JIT: Fix SysV first/second return register GC info mismatch when generating calls * Fix struct ReturnKind on SysV AMD64. On SysV AMD64, structs returned in a float and int reg pair were being classified as RT_Scalar_XX. This causes downstream consumers (e.g., HijackFrame::GcScanRoots) to look for obj/byref's in the second int reg. Per the ABI, however, the first float is passed through a float reg and the obj/byref is passed through the _first_ int reg. We now detect and fix this case by skipping the first float type in the ReturnKind encoding and moving the second type into the first. Fix #115815 --------- Co-authored-by: zengandrew <7494393+zengandrew@users.noreply.github.com> --- src/coreclr/jit/codegenxarch.cpp | 12 ++++++ src/coreclr/jit/gcencode.cpp | 17 +++++++- src/coreclr/vm/method.cpp | 9 ++++ .../JitBlue/Runtime_115815/Runtime_115815.cs | 42 +++++++++++++++++++ .../Runtime_115815/Runtime_115815.csproj | 8 ++++ 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_115815/Runtime_115815.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_115815/Runtime_115815.csproj diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 12764affdd92e4..8f397d04ea6a74 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -6173,6 +6173,18 @@ void CodeGen::genCallInstruction(GenTreeCall* call X86_ARG(target_ssize_t stackA { retSize = emitTypeSize(retTypeDesc->GetReturnRegType(0)); secondRetSize = emitTypeSize(retTypeDesc->GetReturnRegType(1)); + + if (retTypeDesc->GetABIReturnReg(1) == REG_INTRET) + { + // If the second return register is REG_INTRET, then the first + // return is expected to be in a SIMD register. + // The emitter has hardcoded belief that retSize corresponds to + // REG_INTRET and secondRetSize to REG_INTRET_1, so fix up the + // situation here. + assert(!EA_IS_GCREF_OR_BYREF(retSize)); + retSize = secondRetSize; + secondRetSize = EA_UNKNOWN; + } } else { diff --git a/src/coreclr/jit/gcencode.cpp b/src/coreclr/jit/gcencode.cpp index 96409d4ce904f9..33a81931fb16dd 100644 --- a/src/coreclr/jit/gcencode.cpp +++ b/src/coreclr/jit/gcencode.cpp @@ -49,8 +49,21 @@ ReturnKind GCInfo::getReturnKind() case 1: return VarTypeToReturnKind(retTypeDesc.GetReturnRegType(0)); case 2: - return GetStructReturnKind(VarTypeToReturnKind(retTypeDesc.GetReturnRegType(0)), - VarTypeToReturnKind(retTypeDesc.GetReturnRegType(1))); + { + var_types first = retTypeDesc.GetReturnRegType(0); + var_types second = retTypeDesc.GetReturnRegType(1); +#ifdef UNIX_AMD64_ABI + if (varTypeUsesFloatReg(first)) + { + // first does not consume an int register in this case so an obj/ref + // in the second ReturnKind would actually be found in the first int reg. + first = second; + second = TYP_UNDEF; + } +#endif // UNIX_AMD64_ABI + return GetStructReturnKind(VarTypeToReturnKind(first), + VarTypeToReturnKind(second)); + } default: #ifdef DEBUG for (unsigned i = 0; i < regCount; i++) diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index 29910d6cb4c1c3..d0a5b289e2b2e2 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -1168,6 +1168,15 @@ ReturnKind MethodDesc::ParseReturnKindFromSig(INDEBUG(bool supportStringConstruc regKinds[i] = RT_Scalar; } } + + if (eeClass->GetEightByteClassification(0) == SystemVClassificationTypeSSE) + { + // Skip over SSE types since they do not consume integer registers. + // An obj/byref in the 2nd eight bytes will be in the first integer register. + regKinds[0] = regKinds[1]; + regKinds[1] = RT_Scalar; + } + ReturnKind structReturnKind = GetStructReturnKind(regKinds[0], regKinds[1]); return structReturnKind; } diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_115815/Runtime_115815.cs b/src/tests/JIT/Regression/JitBlue/Runtime_115815/Runtime_115815.cs new file mode 100644 index 00000000000000..77f42fe7d49453 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_115815/Runtime_115815.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Threading; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using Xunit; + +public class Runtime_115815 +{ + [Fact] + public static void TestEntryPoint() + { + var destination = new KeyValuePair[1_000]; + + // loop to make this method fully interruptible + to get into OSR version + for (int i = 0; i < destination.Length * 1000; i++) + { + destination[i / 1000] = default; + } + + for (int i = 0; i < 5; i++) + { + for (int j = 0; j < destination.Length; j++) + { + destination[j] = GetValue(j); + } + + Thread.Sleep(10); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static KeyValuePair GetValue(int i) + => KeyValuePair.Create(new Container(i.ToString()), (double)i); + + private struct Container + { + public string Name; + public Container(string name) { this.Name = name; } + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_115815/Runtime_115815.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_115815/Runtime_115815.csproj new file mode 100644 index 00000000000000..de6d5e08882e86 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_115815/Runtime_115815.csproj @@ -0,0 +1,8 @@ + + + True + + + + + From 0e6061f0d685d42c98e54880e8ac0197c8dc5a24 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 4 Jun 2025 09:36:44 -0700 Subject: [PATCH 05/22] [release/8.0-staging] Add a parent check to the forward substitution tree walk (#116240) * Add a parent check to forward sub tree walk * More checks --------- Co-authored-by: SingleAccretion --- src/coreclr/jit/forwardsub.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/forwardsub.cpp b/src/coreclr/jit/forwardsub.cpp index 7c1b0316153dfc..75f8b62911abdd 100644 --- a/src/coreclr/jit/forwardsub.cpp +++ b/src/coreclr/jit/forwardsub.cpp @@ -221,7 +221,7 @@ class ForwardSubVisitor final : public GenTreeVisitor // fgGetStubAddrArg cannot handle complex trees (it calls gtClone) // bool isCallTarget = false; - if (parent->IsCall()) + if ((parent != nullptr) && parent->IsCall()) { GenTreeCall* const parentCall = parent->AsCall(); isCallTarget = (parentCall->gtCallType == CT_INDIRECT) && (parentCall->gtCallAddr == node); @@ -319,7 +319,7 @@ class ForwardSubVisitor final : public GenTreeVisitor bool IsCallArg() const { - return m_parentNode->IsCall(); + return (m_parentNode != nullptr) && m_parentNode->IsCall(); } unsigned GetComplexity() const @@ -749,7 +749,7 @@ bool Compiler::fgForwardSubStatement(Statement* stmt) if (fsv.IsCallArg() && fsv.GetNode()->TypeIs(TYP_STRUCT) && !fwdSubNode->OperIs(GT_BLK, GT_LCL_VAR, GT_LCL_FLD, GT_MKREFANY)) { - JITDUMP(" use is a struct arg; fwd sub node is not OBJ/LCL_VAR/LCL_FLD/MKREFANY\n"); + JITDUMP(" use is a struct arg; fwd sub node is not BLK/LCL_VAR/LCL_FLD/MKREFANY\n"); return false; } @@ -772,7 +772,7 @@ bool Compiler::fgForwardSubStatement(Statement* stmt) { GenTree* const parentNode = fsv.GetParentNode(); - if (!parentNode->OperIs(GT_STORE_LCL_VAR)) + if ((parentNode == nullptr) || !parentNode->OperIs(GT_STORE_LCL_VAR)) { JITDUMP(" multi-reg struct node, parent not STORE_LCL_VAR\n"); return false; @@ -794,7 +794,8 @@ bool Compiler::fgForwardSubStatement(Statement* stmt) // for them on all 32 bit targets is a CQ regression due to some bad // interaction between decomposition and RA. // - if (compMethodReturnsMultiRegRetType() && fsv.GetParentNode()->OperIs(GT_RETURN)) + if (compMethodReturnsMultiRegRetType() && (fsv.GetParentNode() != nullptr) && + fsv.GetParentNode()->OperIs(GT_RETURN)) { #if defined(TARGET_X86) if (fwdSubNode->TypeGet() == TYP_LONG) From 5cc544a25ce5d1fd745a7186fabd4155271abed9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Jun 2025 19:56:11 -0700 Subject: [PATCH 06/22] Fix shutdown on foreign thread (#116233) When a foreign thread running in .NET process is killed or crashes due to some hardware exception, the .NET code that performs shutdown gets called and incorrectly expects the thread to be a thread that's registered with the runtime. It calls GetThread on it and then calls a method on the thread. That leads to an assert in debug builds and crash in release ones. The function that is called is not needed for foreign threads though, so the fix is to skip calling it if the GetThreadNULLOk returns NULL (that means the thread is foreign and never registered with the runtime). Co-authored-by: Jan Vorlicek --- src/coreclr/vm/ceemain.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/ceemain.cpp b/src/coreclr/vm/ceemain.cpp index c5dff66b823a44..b23d544ec73760 100644 --- a/src/coreclr/vm/ceemain.cpp +++ b/src/coreclr/vm/ceemain.cpp @@ -554,7 +554,11 @@ void EESocketCleanupHelper(bool isExecutingOnAltStack) if (isExecutingOnAltStack) { - GetThread()->SetExecutingOnAltStack(); + Thread *pThread = GetThreadNULLOk(); + if (pThread) + { + pThread->SetExecutingOnAltStack(); + } } // Close the debugger transport socket first From 6889ee5a6a5c7f8a3e54f3a54b4a53115703b065 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 6 Jun 2025 15:08:55 -0700 Subject: [PATCH 07/22] [release/8.0-staging] in rsa signatures, configure digest before padding mode Co-authored-by: Raphael Catolino --- .../pal_evp_pkey_rsa.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c index 043bf9f9d1edab..fad0b23e45c781 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c @@ -206,6 +206,15 @@ int32_t CryptoNative_RsaEncrypt(EVP_PKEY* pkey, static bool ConfigureSignature(EVP_PKEY_CTX* ctx, RsaPaddingMode padding, const EVP_MD* digest) { + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcast-qual" + if (EVP_PKEY_CTX_set_signature_md(ctx, digest) <= 0) +#pragma clang diagnostic pop + { + return false; + } + if (padding == RsaPaddingPkcs1) { if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) @@ -224,14 +233,6 @@ static bool ConfigureSignature(EVP_PKEY_CTX* ctx, RsaPaddingMode padding, const } } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wcast-qual" - if (EVP_PKEY_CTX_set_signature_md(ctx, digest) <= 0) -#pragma clang diagnostic pop - { - return false; - } - return true; } From 607a335efaffd89de4fc9a0f55897ede83a37d75 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 8 Jun 2025 18:41:58 -0400 Subject: [PATCH 08/22] [release/8.0-staging] Fix PipeStream leak on Windows when pipe is disposed with a pending operation (#116189) * Fix PipeStream cleanup on Windows when pipe is disposed with a pending operation The same pattern occurs in a couple of other places, as well. * Make dispose cancellation unconditional --------- Co-authored-by: Stephen Toub --- .../IO/Pipes/NamedPipeServerStream.Unix.cs | 5 +---- .../IO/Pipes/NamedPipeServerStream.Windows.cs | 6 +++++- .../src/System/IO/Pipes/PipeStream.Windows.cs | 18 +++++++++++++++++- .../src/System/IO/Pipes/PipeStream.cs | 7 +++++-- ...Handle.OverlappedValueTaskSource.Windows.cs | 6 +++++- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs index 40bd09bd89ceb4..e6263872a31a3f 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs @@ -139,10 +139,7 @@ internal override void DisposeCore(bool disposing) if (disposing) { - if (State != PipeState.Closed) - { - _internalTokenSource.Cancel(); - } + _internalTokenSource.Cancel(); } } diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs index c0f066da805214..b986a7342538ba 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs @@ -62,7 +62,11 @@ internal override void TryToReuse(PipeValueTaskSource source) { if (Interlocked.CompareExchange(ref _reusableConnectionValueTaskSource, connectionSource, null) is not null) { - source._preallocatedOverlapped.Dispose(); + source.Dispose(); + } + else if (State == PipeState.Closed) + { + Interlocked.Exchange(ref _reusableConnectionValueTaskSource, null)?.Dispose(); } } } diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs index 453fe1153bd4be..ddff733119a7a8 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs @@ -255,9 +255,25 @@ internal virtual void TryToReuse(PipeValueTaskSource source) if (source is ReadWriteValueTaskSource readWriteSource) { ref ReadWriteValueTaskSource? field = ref readWriteSource._isWrite ? ref _reusableWriteValueTaskSource : ref _reusableReadValueTaskSource; + + // Try to return the instance. If there's already something in the field, then there had been concurrent + // operations and someone else already returned their instance, so just dispose of this one (the "pool" has + // a size of 1). If there's not something there and we're successful in storing our instance, the 99% case is + // this is normal operation, there wasn't a concurrent operation, and we just successfully returned the rented + // instance. However, it could also be because the stream has been disposed, in which case the disposal process + // would have nulled out the field, and since this instance wasn't present when disposal happened, it won't have + // been disposed. Further, disposal won't happen again, so just leaving the instance there will result in its + // resources being leaked. Instead, _after_ returning the instance we then check whether the stream is now + // disposed, and if it is, we then try to re-rent the instance and dispose of it. It's fine if the disposal happens + // after we've stored the instance back and before we check the stream's state, as then this code will be racing + // with disposal and only one of the two will succeed in exchanging out the instance. if (Interlocked.CompareExchange(ref field, readWriteSource, null) is not null) { - source._preallocatedOverlapped.Dispose(); + source.Dispose(); + } + else if (State == PipeState.Closed) + { + Interlocked.Exchange(ref field, null)?.Dispose(); } } } diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.cs index 8e7790d463a314..b9dcc4feb5b744 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.cs @@ -144,6 +144,11 @@ public override Task FlushAsync(CancellationToken cancellationToken) protected override void Dispose(bool disposing) { + // Mark the pipe as closed before calling DisposeCore. That way, other threads that might + // be synchronizing on shared resources disposed of in DisposeCore will be guaranteed to + // see the closed state after that synchronization. + _state = PipeState.Closed; + try { // Nothing will be done differently based on whether we are @@ -159,8 +164,6 @@ protected override void Dispose(bool disposing) { base.Dispose(disposing); } - - _state = PipeState.Closed; } // ********************** Public Properties *********************** // diff --git a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs index c2eab851bd60e2..f8a075cc61c76f 100644 --- a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs @@ -35,7 +35,11 @@ private void TryToReuse(OverlappedValueTaskSource source) if (Interlocked.CompareExchange(ref _reusableOverlappedValueTaskSource, source, null) is not null) { - source._preallocatedOverlapped.Dispose(); + source.Dispose(); + } + else if (IsClosed) + { + Interlocked.Exchange(ref _reusableOverlappedValueTaskSource, null)?.Dispose(); } } From c0390586e2707334a571b9293803b5b6a4916f6e Mon Sep 17 00:00:00 2001 From: vseanreesermsft <78103370+vseanreesermsft@users.noreply.github.com> Date: Mon, 9 Jun 2025 07:35:20 -0700 Subject: [PATCH 09/22] Update branding to 8.0.18 (#116311) --- eng/Versions.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 7238cc0a4196c5..230638d8ce6b08 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,11 +1,11 @@ - 8.0.17 + 8.0.18 8 0 - 17 + 18 8.0.100 7.0.20 6.0.36 From 4bdcdb83a548b89c3abf2408471ff92dca497bb2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 12:23:12 -0300 Subject: [PATCH 10/22] Fix generation of minidump (#115739) Co-authored-by: Thays Grazia Co-authored-by: Tom McDonald --- src/coreclr/vm/method.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index d0a5b289e2b2e2..0b55537c3f9215 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -3798,10 +3798,14 @@ MethodDesc::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) ILCodeVersion ilVersion = pCodeVersionManager->GetActiveILCodeVersion(dac_cast(this)); if (!ilVersion.IsNull()) { - ilVersion.GetActiveNativeCodeVersion(dac_cast(this)); - ilVersion.GetVersionId(); - ilVersion.GetRejitState(); - ilVersion.GetIL(); + EX_TRY + { + ilVersion.GetActiveNativeCodeVersion(dac_cast(this)); + ilVersion.GetVersionId(); + ilVersion.GetRejitState(); + ilVersion.GetIL(); + } + EX_CATCH_RETHROW_ONLY_COR_E_OPERATIONCANCELLED } #endif From f1363e32ed01e27d2a0d3b55bd6aab7259a64072 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 14:36:19 -0500 Subject: [PATCH 11/22] Update dependencies from https://github.com/dotnet/runtime-assets build 20250516.1 (#115676) Microsoft.DotNet.CilStrip.Sources , System.ComponentModel.TypeConverter.TestData , System.Data.Common.TestData , System.Drawing.Common.TestData , System.Formats.Tar.TestData , System.IO.Compression.TestData , System.IO.Packaging.TestData , System.Net.TestData , System.Private.Runtime.UnicodeData , System.Runtime.Numerics.TestData , System.Runtime.TimeZoneData , System.Security.Cryptography.X509Certificates.TestData , System.Text.RegularExpressions.TestData , System.Windows.Extensions.TestData From Version 8.0.0-beta.25211.2 -> To Version 8.0.0-beta.25266.1 Co-authored-by: dotnet-maestro[bot] --- eng/Version.Details.xml | 56 ++++++++++++++++++++--------------------- eng/Versions.props | 28 ++++++++++----------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index eb015ec454d2e0..c1f246fd4acfa8 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -185,57 +185,57 @@ https://github.com/dotnet/arcade c487e860d456cda2580600ad81fd425d3bba21f7 - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f https://github.com/dotnet/llvm-project @@ -358,9 +358,9 @@ https://github.com/dotnet/hotreload-utils 2dd1cedb9d30de03b034d3856c33a2cdf5f42b6c - + https://github.com/dotnet/runtime-assets - 611d6c8595694c9755c9f0cc36ae6018c4c15143 + f223eaeaa143e11a248ee81611819e3803883e6f https://github.com/dotnet/roslyn diff --git a/eng/Versions.props b/eng/Versions.props index 7238cc0a4196c5..4c6680f1fb3152 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -153,20 +153,20 @@ 4.5.0 8.0.0-rc.1.23406.6 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 - 8.0.0-beta.25211.2 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 + 8.0.0-beta.25266.1 1.0.0-prerelease.23566.3 1.0.0-prerelease.23566.3 From c53fe3fe99587a3f0e623001356fe7fa280bfab9 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 19:42:04 +0000 Subject: [PATCH 12/22] Update dependencies from https://github.com/dotnet/hotreload-utils build 20250515.1 (#115623) Microsoft.DotNet.HotReload.Utils.Generator.BuildTool From Version 8.0.0-alpha.0.25214.2 -> To Version 8.0.0-alpha.0.25265.1 Co-authored-by: dotnet-maestro[bot] --- eng/Version.Details.xml | 4 ++-- eng/Versions.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index c1f246fd4acfa8..bcd08d25a670a2 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -354,9 +354,9 @@ https://dev.azure.com/dnceng/internal/_git/dotnet-optimization 67613417f5e1af250e6ddfba79f8f2885d8e90fb - + https://github.com/dotnet/hotreload-utils - 2dd1cedb9d30de03b034d3856c33a2cdf5f42b6c + 6907eb448c5b24e402a45086171ab6c7e2269056 https://github.com/dotnet/runtime-assets diff --git a/eng/Versions.props b/eng/Versions.props index 4c6680f1fb3152..d272487204d520 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -198,7 +198,7 @@ 8.0.0-prerelease.25207.2 8.0.0-prerelease.25207.2 8.0.0-prerelease.25207.2 - 8.0.0-alpha.0.25214.2 + 8.0.0-alpha.0.25265.1 2.4.2 1.0.0 2.4.5 From 1469d4ddcfb0ca37f8b7eeda505b3002e8f0a771 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 14:45:56 -0500 Subject: [PATCH 13/22] Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20250410.2 (#115586) Microsoft.SourceBuild.Intermediate.source-build-reference-packages From Version 8.0.0-alpha.1.25081.5 -> To Version 8.0.0-alpha.1.25210.2 Co-authored-by: dotnet-maestro[bot] --- eng/Version.Details.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index bcd08d25a670a2..8141eba6a93bf2 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -99,9 +99,9 @@ 2b0cca8ad3a88e02fe0878139009ffffde071f1f - + https://github.com/dotnet/source-build-reference-packages - d73fc552386797322e84fa9b2ef5eaa5369de83c + 6ae07097c0f03eb59c8a581faaedcc3f2e4cc42c From 32930178e718d688fcedf48a8361a22a3d2fb997 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 16:35:58 -0500 Subject: [PATCH 14/22] [release/8.0] Update dependencies from dotnet/emsdk (#115655) * Update dependencies from https://github.com/dotnet/emsdk build 20250516.2 Microsoft.SourceBuild.Intermediate.emsdk , Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100 From Version 8.0.17-servicing.25258.1 -> To Version 8.0.17-servicing.25266.2 * Update dependencies from https://github.com/dotnet/emsdk build 20250519.2 Microsoft.SourceBuild.Intermediate.emsdk , Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100 From Version 8.0.17-servicing.25258.1 -> To Version 8.0.17-servicing.25269.2 * Update dependencies from https://github.com/dotnet/emsdk build 20250604.1 Microsoft.SourceBuild.Intermediate.emsdk , Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100 From Version 8.0.17-servicing.25258.1 -> To Version 8.0.18-servicing.25304.1 --------- Co-authored-by: dotnet-maestro[bot] --- NuGet.config | 2 +- eng/Version.Details.xml | 8 ++++---- eng/Versions.props | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NuGet.config b/NuGet.config index dc91f8b941028d..bf140690b22d67 100644 --- a/NuGet.config +++ b/NuGet.config @@ -9,7 +9,7 @@ - + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index eb015ec454d2e0..b1c58d9e0ee97a 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -90,13 +90,13 @@ 45dd3a73dd5b64b010c4251303b3664bb30df029 - + https://github.com/dotnet/emsdk - 2b0cca8ad3a88e02fe0878139009ffffde071f1f + 976b101e5539557c20e2ac39885ac879531bcf82 - + https://github.com/dotnet/emsdk - 2b0cca8ad3a88e02fe0878139009ffffde071f1f + 976b101e5539557c20e2ac39885ac879531bcf82 diff --git a/eng/Versions.props b/eng/Versions.props index 230638d8ce6b08..77141851a49ef0 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -252,7 +252,7 @@ Note: when the name is updated, make sure to update dependency name in eng/pipelines/common/xplat-setup.yml like - DarcDependenciesChanged.Microsoft_NET_Workload_Emscripten_Current_Manifest-8_0_100_Transport --> - 8.0.17 + 8.0.18 $(MicrosoftNETWorkloadEmscriptenCurrentManifest80100Version) 1.1.87-gba258badda From 296fa9ee350cf6a194a6cc65f4d257c8a5f4cdf8 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 23:38:25 +0000 Subject: [PATCH 15/22] Update dependencies from https://github.com/dotnet/xharness build 20250505.2 (#115585) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Microsoft.DotNet.XHarness.CLI , Microsoft.DotNet.XHarness.TestRunners.Common , Microsoft.DotNet.XHarness.TestRunners.Xunit From Version 8.0.0-prerelease.25207.2 -> To Version 8.0.0-prerelease.25255.2 Co-authored-by: dotnet-maestro[bot] Co-authored-by: David CantĂș --- .config/dotnet-tools.json | 2 +- eng/Version.Details.xml | 12 ++++++------ eng/Versions.props | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 7553884106c90f..f6c30fd2ff808e 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -15,7 +15,7 @@ ] }, "microsoft.dotnet.xharness.cli": { - "version": "8.0.0-prerelease.25207.2", + "version": "8.0.0-prerelease.25255.2", "commands": [ "xharness" ] diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 8141eba6a93bf2..97dec2698a431a 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -322,17 +322,17 @@ https://github.com/dotnet/runtime edbd5c769a19798b6955050baccf99e6797d3208 - + https://github.com/dotnet/xharness - 6dbf15dc48cde2bde6f62811ba73241b067b3683 + 5429dfdddde318dd8355c661173da7f2f285ebce - + https://github.com/dotnet/xharness - 6dbf15dc48cde2bde6f62811ba73241b067b3683 + 5429dfdddde318dd8355c661173da7f2f285ebce - + https://github.com/dotnet/xharness - 6dbf15dc48cde2bde6f62811ba73241b067b3683 + 5429dfdddde318dd8355c661173da7f2f285ebce https://github.com/dotnet/arcade diff --git a/eng/Versions.props b/eng/Versions.props index d272487204d520..527713976d2226 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -195,9 +195,9 @@ 1.1.0 17.4.0-preview-20220707-01 - 8.0.0-prerelease.25207.2 - 8.0.0-prerelease.25207.2 - 8.0.0-prerelease.25207.2 + 8.0.0-prerelease.25255.2 + 8.0.0-prerelease.25255.2 + 8.0.0-prerelease.25255.2 8.0.0-alpha.0.25265.1 2.4.2 1.0.0 From cbb1cd14f31f5e59ca9a50370c5d75da0e924019 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 22:12:37 -0500 Subject: [PATCH 16/22] [release/8.0-staging] Link peer's X509 stack handle to parent SSL safe handle (#115379) * Link peer's X509 stack handle to parent SSL safe handle * Update src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs Co-authored-by: Kevin Jones * Add test for dispose parallel with handshake. * Revert "Add test for dispose parallel with handshake." This reverts commit 3cae60bb25a669db2029fd62f6faab13343685a3. * Defer RemoteCertificate assignment after X509 Chain build (#114781) * Defer RemoteCertificate assignment after X509 Chain build * Add comment * Fix SslStreamDisposeTest failures during parallel handshake (#113834) * Fix SslStreamDisposeTest.Dispose_ParallelWithHandshake_ThrowsODE test failures * Fix build * Fix SslStreamDisposeTest for parallel handshake on Unix (#114100) * [Test Failure] SslStreamDisposeTest.Dispose_ParallelWithHandshake_ThrowsODE on Unix Fixes #113833 * fixup! [Test Failure] SslStreamDisposeTest.Dispose_ParallelWithHandshake_ThrowsODE on Unix Fixes #113833 * fixup! fixup! [Test Failure] SslStreamDisposeTest.Dispose_ParallelWithHandshake_ThrowsODE on Unix Fixes #113833 * Update src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamDisposeTest.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix build --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Radek Zikmund Co-authored-by: Radek Zikmund <32671551+rzikm@users.noreply.github.com> Co-authored-by: Kevin Jones Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Interop.Ssl.cs | 9 ++- .../System/Net/Security/SslStream.Protocol.cs | 11 ++-- .../FunctionalTests/SslStreamDisposeTest.cs | 62 +++++++++++++++++++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs index 0848ca5ed21bc4..8ec4cb8521e94a 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs @@ -117,7 +117,14 @@ internal static unsafe ReadOnlySpan SslGetAlpnSelected(SafeSslHandle ssl) internal static partial IntPtr SslGetPeerCertificate(SafeSslHandle ssl); [LibraryImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetPeerCertChain")] - internal static partial SafeSharedX509StackHandle SslGetPeerCertChain(SafeSslHandle ssl); + private static partial SafeSharedX509StackHandle SslGetPeerCertChain_private(SafeSslHandle ssl); + + internal static SafeSharedX509StackHandle SslGetPeerCertChain(SafeSslHandle ssl) + { + return SafeInteriorHandle.OpenInteriorHandle( + SslGetPeerCertChain_private, + ssl); + } [LibraryImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetPeerFinished")] internal static partial int SslGetPeerFinished(SafeSslHandle ssl, IntPtr buf, int count); diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs index 38274fd85acd8d..bc7fae0b4b0ee2 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs @@ -1029,8 +1029,9 @@ internal bool VerifyRemoteCertificate(RemoteCertificateValidationCallback? remot return true; } - _remoteCertificate = certificate; - if (_remoteCertificate == null) + // don't assign to _remoteCertificate yet, this prevents weird exceptions if SslStream is disposed in parallel with X509Chain building + + if (certificate == null) { if (NetEventSource.Log.IsEnabled() && RemoteCertRequired) NetEventSource.Error(this, $"Remote certificate required, but no remote certificate received"); sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNotAvailable; @@ -1072,15 +1073,17 @@ internal bool VerifyRemoteCertificate(RemoteCertificateValidationCallback? remot sslPolicyErrors |= CertificateValidationPal.VerifyCertificateProperties( _securityContext!, chain, - _remoteCertificate, + certificate, _sslAuthenticationOptions.CheckCertName, _sslAuthenticationOptions.IsServer, TargetHostNameHelper.NormalizeHostName(_sslAuthenticationOptions.TargetHost)); } + _remoteCertificate = certificate; + if (remoteCertValidationCallback != null) { - success = remoteCertValidationCallback(this, _remoteCertificate, chain, sslPolicyErrors); + success = remoteCertValidationCallback(this, certificate, chain, sslPolicyErrors); } else { diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamDisposeTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamDisposeTest.cs index de7aa502933b02..9864029c7a0b34 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamDisposeTest.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamDisposeTest.cs @@ -4,6 +4,7 @@ using System.IO; using System.Security.Cryptography.X509Certificates; using System.Threading; +using System.Security.Authentication; using System.Threading.Tasks; using Xunit; @@ -59,6 +60,7 @@ public async Task Dispose_PendingReadAsync_ThrowsODE(bool bufferedRead) using CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(TestConfiguration.PassingTestTimeout); + (SslStream client, SslStream server) = TestHelper.GetConnectedSslStreams(leaveInnerStreamOpen: true); using (client) using (server) @@ -102,5 +104,65 @@ await TestConfiguration.WhenAllOrAnyFailedWithTimeout( await Assert.ThrowsAnyAsync(() => client.ReadAsync(readBuffer, cts.Token).AsTask()); } } + + [Fact] + [OuterLoop("Computationally expensive")] + public async Task Dispose_ParallelWithHandshake_ThrowsODE() + { + using CancellationTokenSource cts = new CancellationTokenSource(); + cts.CancelAfter(TestConfiguration.PassingTestTimeout); + + await Parallel.ForEachAsync(System.Linq.Enumerable.Range(0, 10000), cts.Token, async (i, token) => + { + (Stream clientStream, Stream serverStream) = TestHelper.GetConnectedStreams(); + + using SslStream client = new SslStream(clientStream); + using SslStream server = new SslStream(serverStream); + using X509Certificate2 serverCertificate = Configuration.Certificates.GetServerCertificate(); + using X509Certificate2 clientCertificate = Configuration.Certificates.GetClientCertificate(); + + SslClientAuthenticationOptions clientOptions = new SslClientAuthenticationOptions() + { + TargetHost = Guid.NewGuid().ToString("N"), + RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true, + }; + + SslServerAuthenticationOptions serverOptions = new SslServerAuthenticationOptions() + { + ServerCertificate = serverCertificate, + }; + + var clientTask = Task.Run(() => client.AuthenticateAsClientAsync(clientOptions, cts.Token)); + var serverTask = Task.Run(() => server.AuthenticateAsServerAsync(serverOptions, cts.Token)); + + // Dispose the instances while the handshake is in progress. + client.Dispose(); + server.Dispose(); + + await ValidateExceptionAsync(clientTask); + await ValidateExceptionAsync(serverTask); + }); + + static async Task ValidateExceptionAsync(Task task) + { + try + { + await task; + } + catch (InvalidOperationException ex) when (ex.StackTrace?.Contains("System.IO.StreamBuffer.WriteAsync") ?? true) + { + // Writing to a disposed ConnectedStream (test only, does not happen with NetworkStream) + return; + } + catch (Exception ex) when (ex + is ObjectDisposedException // disposed locally + or IOException // disposed remotely (received unexpected EOF) + or AuthenticationException) // disposed wrapped in AuthenticationException or error from platform library + { + // expected + return; + } + } + } } } From 0a008e2771a2c582a48ec0fe705721beaf9d067b Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 22:37:14 -0500 Subject: [PATCH 17/22] [release/8.0-staging] Update dependencies from dotnet/arcade (#115587) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update dependencies from https://github.com/dotnet/arcade build 20250513.4 Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions From Version 8.0.0-beta.25214.7 -> To Version 8.0.0-beta.25263.4 * Bump MicrosoftDotnetSdkInternalVersion to 8.0.116 --------- Co-authored-by: dotnet-maestro[bot] Co-authored-by: David CantĂș --- eng/Version.Details.xml | 72 +++++++++---------- eng/Versions.props | 32 ++++----- .../templates-official/job/source-build.yml | 2 +- .../job/source-index-stage1.yml | 4 +- .../templates-official/jobs/source-build.yml | 2 +- eng/common/templates/job/source-build.yml | 4 +- .../templates/job/source-index-stage1.yml | 4 +- eng/common/templates/jobs/source-build.yml | 2 +- global.json | 10 +-- 9 files changed, 66 insertions(+), 66 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 97dec2698a431a..c16f38751f730a 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -111,9 +111,9 @@ - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 @@ -121,69 +121,69 @@ 73f0850939d96131c28cf6ea6ee5aacb4da0083a - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 https://github.com/dotnet/runtime-assets @@ -334,9 +334,9 @@ https://github.com/dotnet/xharness 5429dfdddde318dd8355c661173da7f2f285ebce - + https://github.com/dotnet/arcade - c487e860d456cda2580600ad81fd425d3bba21f7 + 20ab70a74d52b68f4271bd946884e24049b14f83 https://dev.azure.com/dnceng/internal/_git/dotnet-optimization diff --git a/eng/Versions.props b/eng/Versions.props index 527713976d2226..b622ef4b514774 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -87,21 +87,21 @@ 8.0.100 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 2.5.1-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 - 8.0.0-beta.25214.7 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 2.5.1-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 + 8.0.0-beta.25263.4 6.0.0-preview.1.102 @@ -269,7 +269,7 @@ 3.1.7 1.0.406601 - 8.0.115 + 8.0.116 $(MicrosoftDotnetSdkInternalVersion) diff --git a/eng/common/templates-official/job/source-build.yml b/eng/common/templates-official/job/source-build.yml index f983033bb028aa..4217d6d8b1481e 100644 --- a/eng/common/templates-official/job/source-build.yml +++ b/eng/common/templates-official/job/source-build.yml @@ -54,7 +54,7 @@ jobs: pool: ${{ if eq(variables['System.TeamProject'], 'public') }}: name: $[replace(replace(eq(contains(coalesce(variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranch'], 'refs/heads/main'), 'release'), 'true'), True, 'NetCore-Svc-Public' ), False, 'NetCore-Public')] - demands: ImageOverride -equals Build.Ubuntu.1804.Amd64.Open + demands: ImageOverride -equals Build.Ubuntu.2204.Amd64.Open ${{ if eq(variables['System.TeamProject'], 'internal') }}: name: $[replace(replace(eq(contains(coalesce(variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranch'], 'refs/heads/main'), 'release'), 'true'), True, 'NetCore1ESPool-Svc-Internal'), False, 'NetCore1ESPool-Internal')] diff --git a/eng/common/templates-official/job/source-index-stage1.yml b/eng/common/templates-official/job/source-index-stage1.yml index 60dfb6b2d1c08f..fb632b71a250b8 100644 --- a/eng/common/templates-official/job/source-index-stage1.yml +++ b/eng/common/templates-official/job/source-index-stage1.yml @@ -1,7 +1,7 @@ parameters: runAsPublic: false - sourceIndexUploadPackageVersion: 2.0.0-20240502.12 - sourceIndexProcessBinlogPackageVersion: 1.0.1-20240129.2 + sourceIndexUploadPackageVersion: 2.0.0-20250425.2 + sourceIndexProcessBinlogPackageVersion: 1.0.1-20250425.2 sourceIndexPackageSource: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json sourceIndexBuildCommand: powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "eng/common/build.ps1 -restore -build -binarylog -ci" preSteps: [] diff --git a/eng/common/templates-official/jobs/source-build.yml b/eng/common/templates-official/jobs/source-build.yml index 5cf6a269c0b62a..b9247be1547b73 100644 --- a/eng/common/templates-official/jobs/source-build.yml +++ b/eng/common/templates-official/jobs/source-build.yml @@ -14,7 +14,7 @@ parameters: # This is the default platform provided by Arcade, intended for use by a managed-only repo. defaultManagedPlatform: name: 'Managed' - container: 'mcr.microsoft.com/dotnet-buildtools/prereqs:centos-stream8' + container: 'mcr.microsoft.com/dotnet-buildtools/prereqs:centos-stream-9-amd64' # Defines the platforms on which to run build jobs. One job is created for each platform, and the # object in this array is sent to the job template as 'platform'. If no platforms are specified, diff --git a/eng/common/templates/job/source-build.yml b/eng/common/templates/job/source-build.yml index c0ff472b697b18..c48f95d93d916e 100644 --- a/eng/common/templates/job/source-build.yml +++ b/eng/common/templates/job/source-build.yml @@ -54,11 +54,11 @@ jobs: pool: ${{ if eq(variables['System.TeamProject'], 'public') }}: name: $[replace(replace(eq(contains(coalesce(variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranch'], 'refs/heads/main'), 'release'), 'true'), True, 'NetCore-Svc-Public' ), False, 'NetCore-Public')] - demands: ImageOverride -equals Build.Ubuntu.1804.Amd64.Open + demands: ImageOverride -equals Build.Ubuntu.2204.Amd64.Open ${{ if eq(variables['System.TeamProject'], 'internal') }}: name: $[replace(replace(eq(contains(coalesce(variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranch'], 'refs/heads/main'), 'release'), 'true'), True, 'NetCore1ESPool-Svc-Internal'), False, 'NetCore1ESPool-Internal')] - demands: ImageOverride -equals Build.Ubuntu.1804.Amd64 + demands: ImageOverride -equals Build.Ubuntu.2204.Amd64 ${{ if ne(parameters.platform.pool, '') }}: pool: ${{ parameters.platform.pool }} diff --git a/eng/common/templates/job/source-index-stage1.yml b/eng/common/templates/job/source-index-stage1.yml index 0b6bb89dc78a7d..8538f44bab28b7 100644 --- a/eng/common/templates/job/source-index-stage1.yml +++ b/eng/common/templates/job/source-index-stage1.yml @@ -1,7 +1,7 @@ parameters: runAsPublic: false - sourceIndexUploadPackageVersion: 2.0.0-20240502.12 - sourceIndexProcessBinlogPackageVersion: 1.0.1-20240129.2 + sourceIndexUploadPackageVersion: 2.0.0-20250425.2 + sourceIndexProcessBinlogPackageVersion: 1.0.1-20250425.2 sourceIndexPackageSource: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json sourceIndexBuildCommand: powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "eng/common/build.ps1 -restore -build -binarylog -ci" preSteps: [] diff --git a/eng/common/templates/jobs/source-build.yml b/eng/common/templates/jobs/source-build.yml index 5f46bfa895c184..3ec997108107bc 100644 --- a/eng/common/templates/jobs/source-build.yml +++ b/eng/common/templates/jobs/source-build.yml @@ -14,7 +14,7 @@ parameters: # This is the default platform provided by Arcade, intended for use by a managed-only repo. defaultManagedPlatform: name: 'Managed' - container: 'mcr.microsoft.com/dotnet-buildtools/prereqs:centos-stream8' + container: 'mcr.microsoft.com/dotnet-buildtools/prereqs:centos-stream-9-amd64' # Defines the platforms on which to run build jobs. One job is created for each platform, and the # object in this array is sent to the job template as 'platform'. If no platforms are specified, diff --git a/global.json b/global.json index b6edc662fa2322..a55368f8197457 100644 --- a/global.json +++ b/global.json @@ -1,16 +1,16 @@ { "sdk": { - "version": "8.0.115", + "version": "8.0.116", "allowPrerelease": true, "rollForward": "major" }, "tools": { - "dotnet": "8.0.115" + "dotnet": "8.0.116" }, "msbuild-sdks": { - "Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.25214.7", - "Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.25214.7", - "Microsoft.DotNet.SharedFramework.Sdk": "8.0.0-beta.25214.7", + "Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.25263.4", + "Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.25263.4", + "Microsoft.DotNet.SharedFramework.Sdk": "8.0.0-beta.25263.4", "Microsoft.Build.NoTargets": "3.7.0", "Microsoft.Build.Traversal": "3.4.0", "Microsoft.NET.Sdk.IL": "8.0.0-rc.1.23406.6" From a4abcd14975f4355dc4cc7f748b323f087231179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Cant=C3=BA?= Date: Mon, 9 Jun 2025 22:54:16 -0500 Subject: [PATCH 18/22] Turn off packages that shipped previous month --- .../src/System.DirectoryServices.Protocols.csproj | 2 +- .../src/System.Net.Http.WinHttpHandler.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj b/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj index eba2fe5b83252c..1abbdcedebe8d8 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj +++ b/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj @@ -4,7 +4,7 @@ true true true - true + false 2 true true diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj index 65ec45bc444f7c..1dd7b656fe5c2d 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj @@ -4,7 +4,7 @@ true true true - true + false 3 Provides a message handler for HttpClient based on the WinHTTP interface of Windows. While similar to HttpClientHandler, it provides developers more granular control over the application's HTTP communication than the HttpClientHandler. From 5f55dc34d077cfe9234bc3bfb9c0a581bbf999a4 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Hoyos Ayala Date: Tue, 10 Jun 2025 23:20:33 +0000 Subject: [PATCH 19/22] Merged PR 50756: [release/8.0] Updated PCA of DAC cert Updated PCA of DAC cert ---- #### AI description (iteration 1) #### PR Classification Certificate update for diagnostic file signing. #### PR Summary This pull request updates the certificate issuer used for signing diagnostic files to the new PCA certificate. - `/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml`: Changed the issuer check from "Microsoft Code Signing PCA 2010" to "Microsoft Code Signing PCA 2024". --- eng/pipelines/coreclr/templates/sign-diagnostic-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml b/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml index 75eee98aeb5db6..a54e637ae693c9 100644 --- a/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml +++ b/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml @@ -69,7 +69,7 @@ steps: } if ($signingCert.Subject -ne "CN=.NET DAC, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" ` - -or $signingCert.Issuer -ne "CN=Microsoft Code Signing PCA 2010, O=Microsoft Corporation, L=Redmond, S=Washington, C=US") + -or $signingCert.Issuer -ne "CN=Microsoft Code Signing PCA 2024, O=Microsoft Corporation, L=Redmond, S=Washington, C=US") { throw "File $file not in expected trust chain." } From 8ddb0cbbe160970c6d07966c795dfa67845c80db Mon Sep 17 00:00:00 2001 From: Juan Sebastian Hoyos Ayala Date: Wed, 11 Jun 2025 04:27:35 +0000 Subject: [PATCH 20/22] Merged PR 50763: [release/8.0] Update signing issuer for DAC cert --- eng/pipelines/coreclr/templates/sign-diagnostic-files.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml b/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml index a54e637ae693c9..0122c2a8dae179 100644 --- a/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml +++ b/eng/pipelines/coreclr/templates/sign-diagnostic-files.yml @@ -69,7 +69,7 @@ steps: } if ($signingCert.Subject -ne "CN=.NET DAC, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" ` - -or $signingCert.Issuer -ne "CN=Microsoft Code Signing PCA 2024, O=Microsoft Corporation, L=Redmond, S=Washington, C=US") + -or $signingCert.Issuer -ne "CN=Microsoft Windows Code Signing PCA 2024, O=Microsoft Corporation, C=US") { throw "File $file not in expected trust chain." } From 5b9ae97b067f098cbbe48d51fcafbad5baf27b50 Mon Sep 17 00:00:00 2001 From: vseanreesermsft <78103370+vseanreesermsft@users.noreply.github.com> Date: Wed, 11 Jun 2025 11:37:51 -0700 Subject: [PATCH 21/22] Merged PR 49480: [internal/release/8.0] Fix issue where libhost scenarios (COM, C++/CLI, custom component host) could try to load coreclr from CWD (#116498) There is a fallback for apps with no .deps.json where the host will consider the app directory for loading coreclr. In component hosting scenarios, we do not have an app path / directory. We were incorrectly going down the path of looking for coreclr next to the empty app directory, which resulted in looking in the current directory. This change skips that path for libhost scenarios. It also adds checks that the paths we determine for loading coreclr, hostpolicy, and hostfxr are absolute. Co-authored-by: Elinor Fung Co-authored-by: Mirroring --- .../NativeHosting/Comhost.cs | 29 +++++++++++++++++ .../NativeHosting/Ijwhost.cs | 28 ++++++++++++++++ .../LoadAssemblyAndGetFunctionPointer.cs | 32 +++++++++++++++++++ ...ns.cs => NativeHostingResultExtensions.cs} | 19 ++++++++++- src/installer/tests/TestUtils/TestArtifact.cs | 14 ++++++++ .../apphost/standalone/hostfxr_resolver.cpp | 5 +++ .../fxr/standalone/hostpolicy_resolver.cpp | 4 +++ src/native/corehost/fxr_resolver.h | 4 +++ .../corehost/hostpolicy/deps_resolver.cpp | 14 ++++++-- .../standalone/coreclr_resolver.cpp | 4 +++ 10 files changed, 149 insertions(+), 4 deletions(-) rename src/installer/tests/HostActivation.Tests/NativeHosting/{FunctionPointerResultExtensions.cs => NativeHostingResultExtensions.cs} (69%) diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs index 4d023023d9791f..5f10c3672fd102 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs @@ -116,6 +116,35 @@ public void ActivateClass_IgnoreAppLocalHostFxr() } } + [Fact] + public void ActivateClass_IgnoreWorkingDirectory() + { + using (TestArtifact cwd = TestArtifact.Create("cwd")) + { + // Validate that hosting components in the working directory will not be used + File.Copy(Binaries.CoreClr.MockPath, Path.Combine(cwd.Location, Binaries.CoreClr.FileName)); + File.Copy(Binaries.HostFxr.MockPath_5_0, Path.Combine(cwd.Location, Binaries.HostFxr.FileName)); + File.Copy(Binaries.HostPolicy.MockPath, Path.Combine(cwd.Location, Binaries.HostPolicy.FileName)); + + string[] args = { + "comhost", + "synchronous", + "1", + sharedState.ComHostPath, + sharedState.ClsidString + }; + sharedState.CreateNativeHostCommand(args, sharedState.ComLibraryFixture.BuiltDotnet.BinPath) + .WorkingDirectory(cwd.Location) + .Execute() + .Should().Pass() + .And.HaveStdOutContaining("New instance of Server created") + .And.HaveStdOutContaining($"Activation of {sharedState.ClsidString} succeeded.") + .And.ResolveHostFxr(sharedState.ComLibraryFixture.BuiltDotnet) + .And.ResolveHostPolicy(sharedState.ComLibraryFixture.BuiltDotnet) + .And.ResolveCoreClr(sharedState.ComLibraryFixture.BuiltDotnet); + } + } + [Fact] public void ActivateClass_ValidateIErrorInfoResult() { diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs index 062e6bcc58130f..9fd2dfa0ee57b5 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs @@ -73,6 +73,34 @@ public void LoadLibrary_ContextConfig(bool load_isolated) } } + [Fact] + public void LoadLibrary_IgnoreWorkingDirectory() + { + using (TestArtifact cwd = TestArtifact.Create("cwd")) + { + // Validate that hosting components in the working directory will not be used + File.Copy(Binaries.CoreClr.MockPath, Path.Combine(cwd.Location, Binaries.CoreClr.FileName)); + File.Copy(Binaries.HostFxr.MockPath_5_0, Path.Combine(cwd.Location, Binaries.HostFxr.FileName)); + File.Copy(Binaries.HostPolicy.MockPath, Path.Combine(cwd.Location, Binaries.HostPolicy.FileName)); + + string [] args = { + "ijwhost", + sharedState.IjwApp.AppDll, + "NativeEntryPoint" + }; + var dotnet = new Microsoft.DotNet.Cli.Build.DotNetCli(sharedState.RepoDirectories.BuiltDotnet); + sharedState.CreateNativeHostCommand(args, sharedState.RepoDirectories.BuiltDotnet) + .WorkingDirectory(cwd.Location) + .Execute() + .Should().Pass() + .And.HaveStdOutContaining("[C++/CLI] NativeEntryPoint: calling managed class") + .And.HaveStdOutContaining("[C++/CLI] ManagedClass: AssemblyLoadContext = \"Default\" System.Runtime.Loader.DefaultAssemblyLoadContext") + .And.ResolveHostFxr(dotnet) + .And.ResolveHostPolicy(dotnet) + .And.ResolveCoreClr(dotnet); + } + } + [Theory] [InlineData(true)] [InlineData(false)] diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs index 653a44eb289677..6fd5be36a99d75 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs @@ -234,6 +234,38 @@ public void CallDelegateOnComponentContext_UnhandledException() .And.ExecuteFunctionPointerWithException(entryPoint, 1); } + [Fact] + public void CallDelegateOnComponentContext_IgnoreWorkingDirectory() + { + using (TestArtifact cwd = TestArtifact.Create("cwd")) + { + // Validate that hosting components in the working directory will not be used + File.Copy(Binaries.CoreClr.MockPath, Path.Combine(cwd.Location, Binaries.CoreClr.FileName)); + File.Copy(Binaries.HostPolicy.MockPath, Path.Combine(cwd.Location, Binaries.HostPolicy.FileName)); + + var component = sharedState.ComponentWithNoDependenciesFixture.TestProject; + string[] args = + { + ComponentLoadAssemblyAndGetFunctionPointerArg, + sharedState.HostFxrPath, + component.RuntimeConfigJson, + component.AppDll, + sharedState.ComponentTypeName, + sharedState.ComponentEntryPoint1, + }; + + var dotnet = new Microsoft.DotNet.Cli.Build.DotNetCli(sharedState.DotNetRoot); + sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) + .WorkingDirectory(cwd.Location) + .Execute() + .Should().Pass() + .And.InitializeContextForConfig(component.RuntimeConfigJson) + .And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint1, 1, 1) + .And.ResolveHostPolicy(dotnet) + .And.ResolveCoreClr(dotnet); + } + } + public class SharedTestState : SharedTestStateBase { public string HostFxrPath { get; } diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/FunctionPointerResultExtensions.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/NativeHostingResultExtensions.cs similarity index 69% rename from src/installer/tests/HostActivation.Tests/NativeHosting/FunctionPointerResultExtensions.cs rename to src/installer/tests/HostActivation.Tests/NativeHosting/NativeHostingResultExtensions.cs index 09fdc52bc186bf..9a0447a219dcb9 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/FunctionPointerResultExtensions.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/NativeHostingResultExtensions.cs @@ -2,10 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.IO; namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting { - internal static class FunctionPointerResultExtensions + internal static class NativeHostingResultExtensions { public static FluentAssertions.AndConstraint ExecuteFunctionPointer(this CommandResultAssertions assertion, string methodName, int callCount, int returnValue) { @@ -47,5 +48,21 @@ public static FluentAssertions.AndConstraint ExecuteWit { return assertion.HaveStdOutContaining($"{assemblyName}: Location = '{location}'"); } + + public static FluentAssertions.AndConstraint ResolveHostFxr(this CommandResultAssertions assertion, Microsoft.DotNet.Cli.Build.DotNetCli dotnet) + { + return assertion.HaveStdErrContaining($"Resolved fxr [{dotnet.GreatestVersionHostFxrFilePath}]"); + } + + public static FluentAssertions.AndConstraint ResolveHostPolicy(this CommandResultAssertions assertion, Microsoft.DotNet.Cli.Build.DotNetCli dotnet) + { + return assertion.HaveStdErrContaining($"{Binaries.HostPolicy.FileName} directory is [{dotnet.GreatestVersionSharedFxPath}]"); + } + + public static FluentAssertions.AndConstraint ResolveCoreClr(this CommandResultAssertions assertion, Microsoft.DotNet.Cli.Build.DotNetCli dotnet) + { + return assertion.HaveStdErrContaining($"CoreCLR path = '{Path.Combine(dotnet.GreatestVersionSharedFxPath, Binaries.CoreClr.FileName)}'") + .And.HaveStdErrContaining($"CoreCLR dir = '{dotnet.GreatestVersionSharedFxPath}{Path.DirectorySeparatorChar}'"); + } } } diff --git a/src/installer/tests/TestUtils/TestArtifact.cs b/src/installer/tests/TestUtils/TestArtifact.cs index c900bba17005c5..23fac7eceec575 100644 --- a/src/installer/tests/TestUtils/TestArtifact.cs +++ b/src/installer/tests/TestUtils/TestArtifact.cs @@ -52,6 +52,20 @@ protected TestArtifact(TestArtifact source) source._copies.Add(this); } + /// + /// Create a new test artifact. + /// + /// Name of the test artifact + /// Test artifact containing no files + public static TestArtifact Create(string name) + { + var (location, parentPath) = GetNewTestArtifactPath(name); + return new TestArtifact(location) + { + DirectoryToDelete = parentPath + }; + } + protected void RegisterCopy(TestArtifact artifact) { _copies.Add(artifact); diff --git a/src/native/corehost/apphost/standalone/hostfxr_resolver.cpp b/src/native/corehost/apphost/standalone/hostfxr_resolver.cpp index 2c244807ac9a94..d06be0719551f5 100644 --- a/src/native/corehost/apphost/standalone/hostfxr_resolver.cpp +++ b/src/native/corehost/apphost/standalone/hostfxr_resolver.cpp @@ -38,6 +38,11 @@ hostfxr_resolver_t::hostfxr_resolver_t(const pal::string_t& app_root) { m_status_code = StatusCode::CoreHostLibMissingFailure; } + else if (!pal::is_path_rooted(m_fxr_path)) + { + // We should always be loading hostfxr from an absolute path + m_status_code = StatusCode::CoreHostLibMissingFailure; + } else if (pal::load_library(&m_fxr_path, &m_hostfxr_dll)) { m_status_code = StatusCode::Success; diff --git a/src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp b/src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp index 67ddd18de3a488..bb0da3238f42b6 100644 --- a/src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp +++ b/src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp @@ -180,6 +180,10 @@ int hostpolicy_resolver::load( return StatusCode::CoreHostLibMissingFailure; } + // We should always be loading hostpolicy from an absolute path + if (!pal::is_path_rooted(host_path)) + return StatusCode::CoreHostLibMissingFailure; + // Load library // We expect to leak hostpolicy - just as we do not unload coreclr, we do not unload hostpolicy if (!pal::load_library(&host_path, &g_hostpolicy)) diff --git a/src/native/corehost/fxr_resolver.h b/src/native/corehost/fxr_resolver.h index 3df6c2de3053d3..ecbf37c12b1ffc 100644 --- a/src/native/corehost/fxr_resolver.h +++ b/src/native/corehost/fxr_resolver.h @@ -44,6 +44,10 @@ int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostPathToConfigCallb return StatusCode::CoreHostLibMissingFailure; } + // We should always be loading hostfxr from an absolute path + if (!pal::is_path_rooted(fxr_path)) + return StatusCode::CoreHostLibMissingFailure; + // Load library if (!pal::load_library(&fxr_path, &fxr)) { diff --git a/src/native/corehost/hostpolicy/deps_resolver.cpp b/src/native/corehost/hostpolicy/deps_resolver.cpp index 66d44f0c17dae0..a00f4dabc71545 100644 --- a/src/native/corehost/hostpolicy/deps_resolver.cpp +++ b/src/native/corehost/hostpolicy/deps_resolver.cpp @@ -830,13 +830,21 @@ bool deps_resolver_t::resolve_probe_dirs( } } - // If the deps file is missing add known locations. - if (!get_app_deps().exists()) + // If the deps file is missing for the app, add known locations. + // For libhost scenarios, there is no app or app path + if (m_host_mode != host_mode_t::libhost && !get_app_deps().exists()) { + assert(!m_app_dir.empty()); + // App local path add_unique_path(asset_type, m_app_dir, &items, output, &non_serviced, core_servicing); - (void) library_exists_in_dir(m_app_dir, LIBCORECLR_NAME, &m_coreclr_path); + if (m_coreclr_path.empty()) + { + // deps_resolver treats being able to get the coreclr path as optional, so we ignore the return value here. + // The caller is responsible for checking whether coreclr path is set and handling as appropriate. + (void) library_exists_in_dir(m_app_dir, LIBCORECLR_NAME, &m_coreclr_path); + } } // Handle any additional deps.json that were specified. diff --git a/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp b/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp index b040c3e8546278..8df8e395e3f259 100644 --- a/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp +++ b/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp @@ -13,6 +13,10 @@ bool coreclr_resolver_t::resolve_coreclr(const pal::string_t& libcoreclr_path, c pal::string_t coreclr_dll_path(libcoreclr_path); append_path(&coreclr_dll_path, LIBCORECLR_NAME); + // We should always be loading coreclr from an absolute path + if (!pal::is_path_rooted(coreclr_dll_path)) + return false; + if (!pal::load_library(&coreclr_dll_path, &coreclr_resolver_contract.coreclr)) { return false; From 1c517b7a1705e11ea489cf80ff9627fd6dd1975a Mon Sep 17 00:00:00 2001 From: Juan Hoyos <19413848+hoyosjs@users.noreply.github.com> Date: Wed, 11 Jun 2025 11:53:46 -0700 Subject: [PATCH 22/22] =?UTF-8?q?Revert=20"Merged=20PR=2049480:=20[interna?= =?UTF-8?q?l/release/8.0]=20Fix=20issue=20where=20libhost=20scena=E2=80=A6?= =?UTF-8?q?"=20(#116553)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5b9ae97b067f098cbbe48d51fcafbad5baf27b50. --- .../NativeHosting/Comhost.cs | 29 ----------------- ....cs => FunctionPointerResultExtensions.cs} | 19 +---------- .../NativeHosting/Ijwhost.cs | 28 ---------------- .../LoadAssemblyAndGetFunctionPointer.cs | 32 ------------------- src/installer/tests/TestUtils/TestArtifact.cs | 14 -------- .../apphost/standalone/hostfxr_resolver.cpp | 5 --- .../fxr/standalone/hostpolicy_resolver.cpp | 4 --- src/native/corehost/fxr_resolver.h | 4 --- .../corehost/hostpolicy/deps_resolver.cpp | 14 ++------ .../standalone/coreclr_resolver.cpp | 4 --- 10 files changed, 4 insertions(+), 149 deletions(-) rename src/installer/tests/HostActivation.Tests/NativeHosting/{NativeHostingResultExtensions.cs => FunctionPointerResultExtensions.cs} (69%) diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs index 5f10c3672fd102..4d023023d9791f 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Comhost.cs @@ -116,35 +116,6 @@ public void ActivateClass_IgnoreAppLocalHostFxr() } } - [Fact] - public void ActivateClass_IgnoreWorkingDirectory() - { - using (TestArtifact cwd = TestArtifact.Create("cwd")) - { - // Validate that hosting components in the working directory will not be used - File.Copy(Binaries.CoreClr.MockPath, Path.Combine(cwd.Location, Binaries.CoreClr.FileName)); - File.Copy(Binaries.HostFxr.MockPath_5_0, Path.Combine(cwd.Location, Binaries.HostFxr.FileName)); - File.Copy(Binaries.HostPolicy.MockPath, Path.Combine(cwd.Location, Binaries.HostPolicy.FileName)); - - string[] args = { - "comhost", - "synchronous", - "1", - sharedState.ComHostPath, - sharedState.ClsidString - }; - sharedState.CreateNativeHostCommand(args, sharedState.ComLibraryFixture.BuiltDotnet.BinPath) - .WorkingDirectory(cwd.Location) - .Execute() - .Should().Pass() - .And.HaveStdOutContaining("New instance of Server created") - .And.HaveStdOutContaining($"Activation of {sharedState.ClsidString} succeeded.") - .And.ResolveHostFxr(sharedState.ComLibraryFixture.BuiltDotnet) - .And.ResolveHostPolicy(sharedState.ComLibraryFixture.BuiltDotnet) - .And.ResolveCoreClr(sharedState.ComLibraryFixture.BuiltDotnet); - } - } - [Fact] public void ActivateClass_ValidateIErrorInfoResult() { diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/NativeHostingResultExtensions.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/FunctionPointerResultExtensions.cs similarity index 69% rename from src/installer/tests/HostActivation.Tests/NativeHosting/NativeHostingResultExtensions.cs rename to src/installer/tests/HostActivation.Tests/NativeHosting/FunctionPointerResultExtensions.cs index 9a0447a219dcb9..09fdc52bc186bf 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/NativeHostingResultExtensions.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/FunctionPointerResultExtensions.cs @@ -2,11 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.IO; namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting { - internal static class NativeHostingResultExtensions + internal static class FunctionPointerResultExtensions { public static FluentAssertions.AndConstraint ExecuteFunctionPointer(this CommandResultAssertions assertion, string methodName, int callCount, int returnValue) { @@ -48,21 +47,5 @@ public static FluentAssertions.AndConstraint ExecuteWit { return assertion.HaveStdOutContaining($"{assemblyName}: Location = '{location}'"); } - - public static FluentAssertions.AndConstraint ResolveHostFxr(this CommandResultAssertions assertion, Microsoft.DotNet.Cli.Build.DotNetCli dotnet) - { - return assertion.HaveStdErrContaining($"Resolved fxr [{dotnet.GreatestVersionHostFxrFilePath}]"); - } - - public static FluentAssertions.AndConstraint ResolveHostPolicy(this CommandResultAssertions assertion, Microsoft.DotNet.Cli.Build.DotNetCli dotnet) - { - return assertion.HaveStdErrContaining($"{Binaries.HostPolicy.FileName} directory is [{dotnet.GreatestVersionSharedFxPath}]"); - } - - public static FluentAssertions.AndConstraint ResolveCoreClr(this CommandResultAssertions assertion, Microsoft.DotNet.Cli.Build.DotNetCli dotnet) - { - return assertion.HaveStdErrContaining($"CoreCLR path = '{Path.Combine(dotnet.GreatestVersionSharedFxPath, Binaries.CoreClr.FileName)}'") - .And.HaveStdErrContaining($"CoreCLR dir = '{dotnet.GreatestVersionSharedFxPath}{Path.DirectorySeparatorChar}'"); - } } } diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs index 9fd2dfa0ee57b5..062e6bcc58130f 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs @@ -73,34 +73,6 @@ public void LoadLibrary_ContextConfig(bool load_isolated) } } - [Fact] - public void LoadLibrary_IgnoreWorkingDirectory() - { - using (TestArtifact cwd = TestArtifact.Create("cwd")) - { - // Validate that hosting components in the working directory will not be used - File.Copy(Binaries.CoreClr.MockPath, Path.Combine(cwd.Location, Binaries.CoreClr.FileName)); - File.Copy(Binaries.HostFxr.MockPath_5_0, Path.Combine(cwd.Location, Binaries.HostFxr.FileName)); - File.Copy(Binaries.HostPolicy.MockPath, Path.Combine(cwd.Location, Binaries.HostPolicy.FileName)); - - string [] args = { - "ijwhost", - sharedState.IjwApp.AppDll, - "NativeEntryPoint" - }; - var dotnet = new Microsoft.DotNet.Cli.Build.DotNetCli(sharedState.RepoDirectories.BuiltDotnet); - sharedState.CreateNativeHostCommand(args, sharedState.RepoDirectories.BuiltDotnet) - .WorkingDirectory(cwd.Location) - .Execute() - .Should().Pass() - .And.HaveStdOutContaining("[C++/CLI] NativeEntryPoint: calling managed class") - .And.HaveStdOutContaining("[C++/CLI] ManagedClass: AssemblyLoadContext = \"Default\" System.Runtime.Loader.DefaultAssemblyLoadContext") - .And.ResolveHostFxr(dotnet) - .And.ResolveHostPolicy(dotnet) - .And.ResolveCoreClr(dotnet); - } - } - [Theory] [InlineData(true)] [InlineData(false)] diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs index 6fd5be36a99d75..653a44eb289677 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs @@ -234,38 +234,6 @@ public void CallDelegateOnComponentContext_UnhandledException() .And.ExecuteFunctionPointerWithException(entryPoint, 1); } - [Fact] - public void CallDelegateOnComponentContext_IgnoreWorkingDirectory() - { - using (TestArtifact cwd = TestArtifact.Create("cwd")) - { - // Validate that hosting components in the working directory will not be used - File.Copy(Binaries.CoreClr.MockPath, Path.Combine(cwd.Location, Binaries.CoreClr.FileName)); - File.Copy(Binaries.HostPolicy.MockPath, Path.Combine(cwd.Location, Binaries.HostPolicy.FileName)); - - var component = sharedState.ComponentWithNoDependenciesFixture.TestProject; - string[] args = - { - ComponentLoadAssemblyAndGetFunctionPointerArg, - sharedState.HostFxrPath, - component.RuntimeConfigJson, - component.AppDll, - sharedState.ComponentTypeName, - sharedState.ComponentEntryPoint1, - }; - - var dotnet = new Microsoft.DotNet.Cli.Build.DotNetCli(sharedState.DotNetRoot); - sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot) - .WorkingDirectory(cwd.Location) - .Execute() - .Should().Pass() - .And.InitializeContextForConfig(component.RuntimeConfigJson) - .And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint1, 1, 1) - .And.ResolveHostPolicy(dotnet) - .And.ResolveCoreClr(dotnet); - } - } - public class SharedTestState : SharedTestStateBase { public string HostFxrPath { get; } diff --git a/src/installer/tests/TestUtils/TestArtifact.cs b/src/installer/tests/TestUtils/TestArtifact.cs index 23fac7eceec575..c900bba17005c5 100644 --- a/src/installer/tests/TestUtils/TestArtifact.cs +++ b/src/installer/tests/TestUtils/TestArtifact.cs @@ -52,20 +52,6 @@ protected TestArtifact(TestArtifact source) source._copies.Add(this); } - /// - /// Create a new test artifact. - /// - /// Name of the test artifact - /// Test artifact containing no files - public static TestArtifact Create(string name) - { - var (location, parentPath) = GetNewTestArtifactPath(name); - return new TestArtifact(location) - { - DirectoryToDelete = parentPath - }; - } - protected void RegisterCopy(TestArtifact artifact) { _copies.Add(artifact); diff --git a/src/native/corehost/apphost/standalone/hostfxr_resolver.cpp b/src/native/corehost/apphost/standalone/hostfxr_resolver.cpp index d06be0719551f5..2c244807ac9a94 100644 --- a/src/native/corehost/apphost/standalone/hostfxr_resolver.cpp +++ b/src/native/corehost/apphost/standalone/hostfxr_resolver.cpp @@ -38,11 +38,6 @@ hostfxr_resolver_t::hostfxr_resolver_t(const pal::string_t& app_root) { m_status_code = StatusCode::CoreHostLibMissingFailure; } - else if (!pal::is_path_rooted(m_fxr_path)) - { - // We should always be loading hostfxr from an absolute path - m_status_code = StatusCode::CoreHostLibMissingFailure; - } else if (pal::load_library(&m_fxr_path, &m_hostfxr_dll)) { m_status_code = StatusCode::Success; diff --git a/src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp b/src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp index bb0da3238f42b6..67ddd18de3a488 100644 --- a/src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp +++ b/src/native/corehost/fxr/standalone/hostpolicy_resolver.cpp @@ -180,10 +180,6 @@ int hostpolicy_resolver::load( return StatusCode::CoreHostLibMissingFailure; } - // We should always be loading hostpolicy from an absolute path - if (!pal::is_path_rooted(host_path)) - return StatusCode::CoreHostLibMissingFailure; - // Load library // We expect to leak hostpolicy - just as we do not unload coreclr, we do not unload hostpolicy if (!pal::load_library(&host_path, &g_hostpolicy)) diff --git a/src/native/corehost/fxr_resolver.h b/src/native/corehost/fxr_resolver.h index ecbf37c12b1ffc..3df6c2de3053d3 100644 --- a/src/native/corehost/fxr_resolver.h +++ b/src/native/corehost/fxr_resolver.h @@ -44,10 +44,6 @@ int load_fxr_and_get_delegate(hostfxr_delegate_type type, THostPathToConfigCallb return StatusCode::CoreHostLibMissingFailure; } - // We should always be loading hostfxr from an absolute path - if (!pal::is_path_rooted(fxr_path)) - return StatusCode::CoreHostLibMissingFailure; - // Load library if (!pal::load_library(&fxr_path, &fxr)) { diff --git a/src/native/corehost/hostpolicy/deps_resolver.cpp b/src/native/corehost/hostpolicy/deps_resolver.cpp index a00f4dabc71545..66d44f0c17dae0 100644 --- a/src/native/corehost/hostpolicy/deps_resolver.cpp +++ b/src/native/corehost/hostpolicy/deps_resolver.cpp @@ -830,21 +830,13 @@ bool deps_resolver_t::resolve_probe_dirs( } } - // If the deps file is missing for the app, add known locations. - // For libhost scenarios, there is no app or app path - if (m_host_mode != host_mode_t::libhost && !get_app_deps().exists()) + // If the deps file is missing add known locations. + if (!get_app_deps().exists()) { - assert(!m_app_dir.empty()); - // App local path add_unique_path(asset_type, m_app_dir, &items, output, &non_serviced, core_servicing); - if (m_coreclr_path.empty()) - { - // deps_resolver treats being able to get the coreclr path as optional, so we ignore the return value here. - // The caller is responsible for checking whether coreclr path is set and handling as appropriate. - (void) library_exists_in_dir(m_app_dir, LIBCORECLR_NAME, &m_coreclr_path); - } + (void) library_exists_in_dir(m_app_dir, LIBCORECLR_NAME, &m_coreclr_path); } // Handle any additional deps.json that were specified. diff --git a/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp b/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp index 8df8e395e3f259..b040c3e8546278 100644 --- a/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp +++ b/src/native/corehost/hostpolicy/standalone/coreclr_resolver.cpp @@ -13,10 +13,6 @@ bool coreclr_resolver_t::resolve_coreclr(const pal::string_t& libcoreclr_path, c pal::string_t coreclr_dll_path(libcoreclr_path); append_path(&coreclr_dll_path, LIBCORECLR_NAME); - // We should always be loading coreclr from an absolute path - if (!pal::is_path_rooted(coreclr_dll_path)) - return false; - if (!pal::load_library(&coreclr_dll_path, &coreclr_resolver_contract.coreclr)) { return false;