Add new export to hostpolicy and hostfxr to redirect error output (dotnet/core-setup#4816)
* Add new export to hostpolicy and hostfxr to redirect error output to a callback
This introduces corehost_set_error_writer and hostfxr_set_error_writer exports.
If set, all errors will be written to the error writer instead of the default stderr.
Tracing is unaffected by this change.
The error writer is set per-thread (thread local).
Only one error writer can be set on a given thread. Subsequent calls to set error
writer will overwrite the previous writer.
hostfxr propagates the custom error writer (if any) to the hostpolicy
for the duration of the calls it makes to hostpolicy.
Added tests to validate the new behavior.
* Remove TODOs which are now resolved with this change
* Fix buffer allocation to work with any string (arbitrary large).
Remove locks on error writer since it's thread local.
* Fix the error formating on Linux
* Fix error formatting on Linux
va_list is not reusable, by definition. On Windows this works since the implementation makes it reusable. but on Linux it's not. So make a copy before calling the printf with it.
Simplify the code, since vsnprintf and _vsnwprintf do in fact behave the same if passed NULL buffer and zero length (calculates the necessary buffer size). So no need for two functions even on Windows.
Commit migrated from https://github.com/dotnet/core-setup/commit/
bfb18700ea2fb0e600a034ac7f719aee2618a87e