Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Lorensson <lateralusx.github@gmail.com>2019-07-02 15:06:57 +0300
committerGitHub <noreply@github.com>2019-07-02 15:06:57 +0300
commit5fee1d3eea11ddae2f2b3a92bfb03cea7b47c091 (patch)
tree3306e7a60a8572a2881f7fce94b9ca87f5da7001 /msvc/libmini-win32.targets
parentb62878973d7d44cfa749c5dbabfd2f656efd9aba (diff)
Add support for TLS callbacks on Windows. (#15423)
* Add support for TLS callbacks on Windows. Mono runtime depends on DllMain to be called by OS in order to correctly detach threads from the runtime. If this doesn't happen, threads from native thread pools (not owned by runtime) and attached using native->managed callback, won't detach resulting in attached threads no longer running. Since threads are still attached to runtime, next GC will try to suspend the thread and that will fail and that in turn will put the state machine in an incorrect state, bringing down the runtime at next GC (when the thread state is revisited). This problem is currently handled by DllMain, but since DllMain only exist in DLL's, statically link Mono runtime will get us into the above scenario. This commit add support to hook up a TLS callback using the same mechanism used by MSVC linker and c-runtime (also available under MINGW). The callback will be included in a section/segment of an object file and included in final image (DLL or EXE) by linker and called by OS loader, solving the problem with static linked Mono runtime not being able to detach terminating threads. The commit keeps current DllMain method when building a DLL but includes a mechanism making sure we only use one of the callback techniques at runtime, if both have been included in final image. This will simplify the build of libmini since we can always build the object including the callback, regardless how the library will be consumed.
Diffstat (limited to 'msvc/libmini-win32.targets')
-rw-r--r--msvc/libmini-win32.targets1
1 files changed, 1 insertions, 0 deletions
diff --git a/msvc/libmini-win32.targets b/msvc/libmini-win32.targets
index 33639ac2426..6e7e2d2f2d6 100644
--- a/msvc/libmini-win32.targets
+++ b/msvc/libmini-win32.targets
@@ -2,6 +2,7 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="windows_sources">
<ClCompile Include="$(MonoSourceLocation)\mono\mini\mini-windows.c" />
+ <ClCompile Include="$(MonoSourceLocation)\mono\mini\mini-windows-tls-callback.c" />
<ClInclude Include="$(MonoSourceLocation)\mono\mini\mini-windows.h" />
</ItemGroup>
</Project>