Fix unloadability races (dotnet/coreclr#21024)
authorJan Vorlicek <janvorli@microsoft.com>
Fri, 16 Nov 2018 18:08:29 +0000 (19:08 +0100)
committerGitHub <noreply@github.com>
Fri, 16 Nov 2018 18:08:29 +0000 (19:08 +0100)
commit9cde770e4f4b925d8cfa2b96e44fe96c8824cdbb
tree90ed562586d8ad5e4c13075cfe546622f734b729
parent12d7b9a19162f6fa11f9a4f49332e41b2a827da7
Fix unloadability races (dotnet/coreclr#21024)

* Fix LoaderAllocator::AllocateHandle

When another thread wins the race in growing the handle table, the code
was not refreshing the slotsUsed local to the new up to date value. This
was leading to overwriting / reusing a live handle.
This change fixes it.

* Embed ThreadLocalBlock in Thread

Instead of allocating ThreadLocalBlock dynamically, embed it in the
Thread. That solves race issue between thread destruction and
LoaderAllocator destruction. The ThreadLocalBlock could have been
deleted during Thread shutdown while the LoaderAllocator's destruction
would be working with it.

Commit migrated from https://github.com/dotnet/coreclr/commit/488d2a70ba59c58b26aa3f4f988a42f6b8927146
15 files changed:
src/coreclr/src/debug/daccess/dacdbiimpl.cpp
src/coreclr/src/debug/daccess/inspect.cpp
src/coreclr/src/debug/daccess/request.cpp
src/coreclr/src/gc/objecthandle.cpp
src/coreclr/src/vm/appdomain.cpp
src/coreclr/src/vm/appdomain.hpp
src/coreclr/src/vm/comsynchronizable.cpp
src/coreclr/src/vm/loaderallocator.cpp
src/coreclr/src/vm/methodtable.h
src/coreclr/src/vm/methodtable.inl
src/coreclr/src/vm/proftoeeinterfaceimpl.cpp
src/coreclr/src/vm/threads.cpp
src/coreclr/src/vm/threads.h
src/coreclr/src/vm/threadstatics.cpp
src/coreclr/src/vm/threadstatics.h