Prevent Mono.Posix from using multiple C runtimes on Windows
authorNiklas Therning <niklas@therning.org>
Tue, 15 Nov 2016 15:22:33 +0000 (16:22 +0100)
committerNiklas Therning <niklas@therning.org>
Wed, 16 Nov 2016 08:14:25 +0000 (09:14 +0100)
commited892ccf27849c082ce6ca46fa8b96d86ca7c329
tree8240e5df0bcd09dfd2b8a84c769e5b22ef758a46
parentf3002a1f72df7165dd42b7abb6d5b1b5ccaa035b
Prevent Mono.Posix from using multiple C runtimes on Windows

Since libMonoPosixHelper.dll is linked against ucrtbase.dll the C runtime
wrapper functions in it will call into ucrtbase.dll. Some pinvokes in
Mono.Unix.Native.Stdlib, however, bind directly to C runtime functions in
msvcrt. This is problematic if a resource (heap memory, file pointer, etc) is
allocated using one C runtime and then operated upon using funcitons form the
other C runtime. E.g., Stdlib.malloc() calls into a wrapper in
libMonoPosixHelper so it will use the ucrtbase heap while Stdlib.free() calls
directly into msvcrt's free() which will abort the process since it's called
with a pointer in an unknown heap.

This commit adds libMonoPosixHelper wrappers for all memory and file related
functions in Stdlib to ensure that all such functions use the same C runtime.

Some of the Mono.Posix tests still fail but at least the test suite doesn't
crash after this change. The test failures will be addressed in a future PR.
mcs/class/Mono.Posix/Mono.Unix.Native/Stdlib.cs
mcs/class/Mono.Posix/Mono.Unix/StdioFileStream.cs
msvc/monoposixhelper.def
support/map.h
support/stdio.c
support/stdlib.c