Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
60fcdfb
Fix wrong alias-to for tvos AOT packs in net8 workload manifest (#110…
akoeplinger Jan 15, 2025
114532f
[release/9.0] Disable tests targetting http://corefx-net-http11.azure…
rzikm Jan 15, 2025
e781fb7
[release/9.0-staging] Support generic fields in PersistedAssemblyBuil…
github-actions[bot] Jan 15, 2025
f2a1313
Re-enable skiasharp WBT tests (#109232) (#110734)
radekdoulik Jan 16, 2025
f9ffbe0
[release/9.0-staging] Backport test fixes related to BinaryFormatter …
adamsitnik Jan 17, 2025
e84969e
Merge pull request #111565 from carlossanlop/release/9.0
carlossanlop Jan 18, 2025
9efd46e
[release/9.0] [wasi] Disable build in .NET 9 (#108877)
maraf Jan 21, 2025
0b71788
[mono] Disable UnitTest_GVM_TypeLoadException on fullAOT (#111394)
github-actions[bot] Jan 21, 2025
eaea271
Fix `UnsafeAccessor` scenario for modopts/modreqs when comparing fiel…
AaronRobinsonMSFT Jan 24, 2025
28117b9
[release/9.0-staging] [mono] Run runtime-llvm and runtime-ioslike on …
github-actions[bot] Jan 24, 2025
db5ef46
[release/9.0-staging] fix stack 2x2 tensor along dimension 1 (#110053)
github-actions[bot] Jan 28, 2025
ea5e814
[release/9.0-staging] Fix race condition in cleanup of collectible th…
github-actions[bot] Jan 28, 2025
6061b2c
[release/9.0-staging] [iOS] Retrieve device locale in full (specific)…
github-actions[bot] Jan 29, 2025
62d433f
[release/9.0-staging] Add workflow to prevent merging a PR when the `…
github-actions[bot] Jan 29, 2025
99b4e84
Use alternative format (#111444)
github-actions[bot] Jan 30, 2025
77e45d3
Fixed referring to `_LibClang` item (#111696)
jkurdek Jan 31, 2025
6091bce
[release/9.0-staging] Fix UNC paths (#111499)
github-actions[bot] Feb 3, 2025
2e3dd8e
[release/9.0-staging] [mono] [llvm-aot] Fixed storing Vector3 into me…
github-actions[bot] Feb 4, 2025
9c8c625
Remove explicit __compact_unwind entries from x64 assembler (#112204)
filipnavara Feb 5, 2025
b63f899
[release/9.0-staging] Update dependencies from dotnet/xharness (#111606)
dotnet-maestro[bot] Feb 6, 2025
84b3239
[release/9.0-staging] Update dependencies from dotnet/icu (#111519)
dotnet-maestro[bot] Feb 6, 2025
7161e66
[release/9.0-staging] Update dependencies from dotnet/icu (#112121)
dotnet-maestro[bot] Feb 6, 2025
a7bfd90
Update dependencies from https://github.com/dotnet/runtime-assets bui…
dotnet-maestro[bot] Feb 6, 2025
e50cf90
[release/9.0-staging] Fix shimmed implementation of TryGetHashAndRese…
github-actions[bot] Feb 6, 2025
6babc42
Remove Windows 8.1 from test queues (#112056)
agocke Feb 7, 2025
b1413ce
[release/9.0-staging] Update dependencies from dotnet/source-build-re…
dotnet-maestro[bot] Feb 9, 2025
8f76618
[browser] Remove experimental args from NodeJS WBT runner (#111655)
maraf Feb 10, 2025
b9d1938
Update dependencies from https://github.com/dotnet/sdk build 20250115…
dotnet-maestro[bot] Feb 10, 2025
e8c394c
[release/9.0-staging] Update dependencies from dotnet/roslyn-analyzer…
dotnet-maestro[bot] Feb 10, 2025
c5b2668
Update dependencies from https://github.com/dotnet/hotreload-utils bu…
dotnet-maestro[bot] Feb 10, 2025
ccbef33
Update dependencies from https://github.com/dotnet/cecil build 202502…
dotnet-maestro[bot] Feb 10, 2025
85ef657
Update dependencies from https://github.com/dotnet/roslyn build 20250…
dotnet-maestro[bot] Feb 10, 2025
d042fc3
Update dependencies from https://github.com/dotnet/icu build 20250205…
dotnet-maestro[bot] Feb 10, 2025
ca6fe3d
Merge branch 'release/9.0-staging' into merge/release/9.0-to-release/…
carlossanlop Feb 10, 2025
f5a9459
Merge pull request #112219 from dotnet/merge/release/9.0-to-release/9…
carlossanlop Feb 10, 2025
1b9b968
Update dependencies from https://github.com/dotnet/xharness build 202…
dotnet-maestro[bot] Feb 10, 2025
49a1042
[release/9.0-staging] Update dependencies from dotnet/arcade (#111483)
dotnet-maestro[bot] Feb 10, 2025
10a6130
Backport pr 111723 to 9.0 staging (#112322)
StephenMolloy Feb 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[release/9.0-staging] Fix race condition in cleanup of collectible th…
…read static variables (#111275)

* Fix issue 110837

There was a race condition where we could have collected all of the managed state of a LoaderAllocator, but not yet started cleaning up the actual LoaderAllocator object in native code. If a thread which had a TLS variable defined in a code associated with a collectible loader allocator was terminated at that point, then the runtime would crash.

The fix is to detect if the LoaderAllocator managed state is still alive, and if so, do not attempt to clean it up.

* Disable test on NativeAOT

* Update src/tests/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection.cs

Co-authored-by: Copilot <[email protected]>

* Update src/tests/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection.cs

Co-authored-by: Copilot <[email protected]>

* Fix missing adjustment missed by copilot

---------

Co-authored-by: David Wrighton <[email protected]>
Co-authored-by: Copilot <[email protected]>
  • Loading branch information
3 people authored Jan 28, 2025
commit ea5e814ba00d050073c1026e0c6800cb7208e310
6 changes: 4 additions & 2 deletions src/coreclr/vm/threadstatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void FreeLoaderAllocatorHandlesForTLSData(Thread *pThread)
#endif
for (const auto& entry : g_pThreadStaticCollectibleTypeIndices->CollectibleEntries())
{
_ASSERTE((entry.TlsIndex.GetIndexOffset() <= pThread->cLoaderHandles) || allRemainingIndicesAreNotValid);
_ASSERTE((entry.TlsIndex.GetIndexOffset() >= pThread->cLoaderHandles) || !allRemainingIndicesAreNotValid);
if (entry.TlsIndex.GetIndexOffset() >= pThread->cLoaderHandles)
{
#ifndef _DEBUG
Expand All @@ -390,7 +390,9 @@ void FreeLoaderAllocatorHandlesForTLSData(Thread *pThread)
{
if (pThread->pLoaderHandles[entry.TlsIndex.GetIndexOffset()] != (LOADERHANDLE)NULL)
{
entry.pMT->GetLoaderAllocator()->FreeHandle(pThread->pLoaderHandles[entry.TlsIndex.GetIndexOffset()]);
LoaderAllocator *pLoaderAllocator = entry.pMT->GetLoaderAllocator();
if (pLoaderAllocator->IsExposedObjectLive())
pLoaderAllocator->FreeHandle(pThread->pLoaderHandles[entry.TlsIndex.GetIndexOffset()]);
pThread->pLoaderHandles[entry.TlsIndex.GetIndexOffset()] = (LOADERHANDLE)NULL;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using Xunit;

namespace CollectibleThreadStaticShutdownRace
{
public class CollectibleThreadStaticShutdownRace
{
Action? UseTLSStaticFromLoaderAllocator = null;
GCHandle IsLoaderAllocatorLive;
static ulong s_collectibleIndex;

[MethodImpl(MethodImplOptions.NoInlining)]
void CallUseTLSStaticFromLoaderAllocator()
{
UseTLSStaticFromLoaderAllocator!();
UseTLSStaticFromLoaderAllocator = null;
}

[MethodImpl(MethodImplOptions.NoInlining)]
bool CheckLALive()
{
return IsLoaderAllocatorLive.Target != null;
}


void ThreadThatWaitsForLoaderAllocatorToDisappear()
{
CallUseTLSStaticFromLoaderAllocator();
while (CheckLALive())
{
GC.Collect(2);
}
}

void CreateLoaderAllocatorWithTLS()
{
ulong collectibleIndex = s_collectibleIndex++;

var ab =
AssemblyBuilder.DefineDynamicAssembly(
new AssemblyName($"CollectibleDerivedAssembly{collectibleIndex}"),
AssemblyBuilderAccess.RunAndCollect);
var mob = ab.DefineDynamicModule($"CollectibleDerivedModule{collectibleIndex}");
var tb =
mob.DefineType(
$"CollectibleDerived{collectibleIndex}",
TypeAttributes.Class | TypeAttributes.Public,
typeof(object));

{
var fb =
tb.DefineField(
"Field", typeof(int), FieldAttributes.Static);
fb.SetCustomAttribute(typeof(ThreadStaticAttribute).GetConstructors()[0], new byte[0]);

var mb =
tb.DefineMethod(
"Method",
MethodAttributes.Public | MethodAttributes.Static);
var ilg = mb.GetILGenerator();
ilg.Emit(OpCodes.Ldc_I4_1);
ilg.Emit(OpCodes.Stsfld, fb);
ilg.Emit(OpCodes.Ret);
}

Type createdType = tb.CreateType();
UseTLSStaticFromLoaderAllocator = (Action)createdType.GetMethods()[0].CreateDelegate(typeof(Action));
IsLoaderAllocatorLive = GCHandle.Alloc(createdType, GCHandleType.WeakTrackResurrection);
}

void ForceCollectibleTLSStaticToGoThroughThreadTermination()
{
int iteration = 0;
for (int i = 0; i < 10; i++)
{
Console.WriteLine($"Iteration {iteration++}");
var createLAThread = new Thread(CreateLoaderAllocatorWithTLS);
createLAThread.Start();
createLAThread.Join();

var crashThread = new Thread(ThreadThatWaitsForLoaderAllocatorToDisappear);
crashThread.Start();
crashThread.Join();
}

}

[Fact]
public static void TestEntryPoint()
{
new CollectibleThreadStaticShutdownRace().ForceCollectibleTLSStaticToGoThroughThreadTermination();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="CollectibleTLSStaticCollection.cs" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,9 @@
<ExcludeList Include="$(XunitTestBinBase)/Loader/CollectibleAssemblies/ByRefLocals/ByRefLocals/*">
<Issue>https://github.com/dotnet/runtimelab/issues/155: Collectible assemblies</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/Loader/CollectibleAssemblies/Statics/CollectibleTLSStaticCollection/*">
<Issue>https://github.com/dotnet/runtimelab/issues/155: Collectible assemblies</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/Loader/CollectibleAssemblies/Statics/CollectibleStatics/*">
<Issue>https://github.com/dotnet/runtimelab/issues/155: Collectible assemblies</Issue>
</ExcludeList>
Expand Down
Loading