Commit 38ec02f7 authored by Bruce Dawson's avatar Bruce Dawson Committed by Commit Bot

Fix fiber-induced shutdown crash

Chrome uses fibers to increase the size of its main thread's stack and
this was found to cause shutdown crashes in some cases, deep inside
msctf.dll and coremessage.dll. It turns out that avoiding these is as
simple as deleting the fibers before quitting.

There is still concern that these crashes were being missed, and it may
be time to start exiting with TerminateProcess (which also solves the
problem) but that is for another day.

Aside: the proper cleanup functions for ConvertThreadToFiberEx and
CreateFiberEx are not documented on MSDN and it is not obvious that they
actually use different cleanup functions. The official examples don't
bother cleaning up, but luckily this sample does:

https://devblogs.microsoft.com/oldnewthing/20200602-00/?p=103819

Testing showed that it was the ::DeleteFiber call which was needed to
avoid the shutdown crash, but both cleanup function calls were retained.

Bug: 981238, 1141408
Change-Id: Ifb3d4dc4d0ea8728e203e654c53f105fca615c02
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2493664
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820285}
parent f9a0027d
...@@ -228,6 +228,10 @@ int main() { ...@@ -228,6 +228,10 @@ int main() {
0, kStackSize, FIBER_FLAG_FLOAT_SWITCH, FiberBinder, &fiber_state); 0, kStackSize, FIBER_FLAG_FLOAT_SWITCH, FiberBinder, &fiber_state);
if (big_stack_fiber) { if (big_stack_fiber) {
::SwitchToFiber(big_stack_fiber); ::SwitchToFiber(big_stack_fiber);
// The fibers must be cleaned up to avoid obscure TLS-related shutdown
// crashes.
::DeleteFiber(big_stack_fiber);
::ConvertFiberToThread();
// Control returns here after Chrome has finished running on FiberMain. // Control returns here after Chrome has finished running on FiberMain.
return fiber_state.fiber_result; return fiber_state.fiber_result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment