Prevent ThreadAbort from prematurely ending function calls in catch block (#1837)
authorAlexander Kyte <alexmkyte@gmail.com>
Tue, 29 Nov 2016 02:01:09 +0000 (21:01 -0500)
committerZoltan Varga <vargaz@gmail.com>
Tue, 29 Nov 2016 02:01:09 +0000 (21:01 -0500)
commite659982b7b8f11ecf80919646353ad3c16240697
tree88ec056387cd51328a4019df5d9cddc3f387057a
parent4f738f8b32901425b35dec2e2b553811e7d70ea2
Prevent ThreadAbort from prematurely ending function calls in catch block (#1837)

* [runtime] Fix naming scheme for check if stack grows upward

It was very counter-intutitive to have a file-local preprocessor variable
with a name that sounds like it should have the same truthiness as a given global
preprocessor variable but was defined as the negation of the global variable.

* [runtime] Prevent ThreadAbort from terminating function calls in catch body

ThreadAbortExceptions are special in that if the thread has not
had it's abortion reset, when it reaches the end of a catch block it
must throw.

Consider the situation where a thread has been aborted and the
ThreadAbortException has been caught. If this catch block calls
a method that has a try/catch combination, the current implementation
will throw the ThreadAbortException at the end of the catch in that
function.

Usually you only care that Thread abortions are prompt, but this bug
could result in dramatic program behavior changes when this is combined
with lazy class initialization.

```
Example:
Console.WriteLine inside a thread abort with an uninitialized Console.
```

This fix records the stack pointer when a catch clause is entered, and
only rethrows the abortion if we're exiting a catch clause above or at the
level of the catch clause previously entered.
mono/metadata/object-internals.h
mono/metadata/threads.c
mono/mini/mini-exceptions.c
mono/mini/mini.h
mono/tests/thread6.cs