Commit a087868
authored
Fix foreign exception handling on Windows (#113323)
* Fix foreign exception handling on Windows
There is a problem in a special case with the new
exception handling:
* A managed code calls a 3rd party native C++ code
* then a C++ exception is thrown in that code
* then it is propagated through managed code
* then it is caught in a 3rd party native C++ code
* then a managed callback is called from the catch handler
* then the exception is rethrown using C++ "throw"
* then it propagates back to the initial managed caller
The problem is as follows:
* When a native exception passes through managed frames and it is
rethrown once a native frame is encountered, the RaiseException
doesn't use the original exception's `EXCEPTION_RECORD`, but creates a
new CLR exception instead.
* When a managed callback called from the native C++ catch handler throws
and catches another exception, the LastThrownObject is cleared.
* When the C++ code in the catch handler rethrows the exception and it
is propagated to managed code, the ProcessCLRException personality
routine is invoked for the first managed frame. It can see that the
exception is a CLR exception, but the LastThrownObject is NULL. It
asserts in debug builds and crashes a bit later in release builds
attempting to dereference the NULL.
The fix is to pass the original `EXCEPTION_RECORD` to the `RaiseException`
in case an external exception is propagated. And use just
`RaiseException` instead of the machinery for regular managed exceptions.
The issue was discovered in Autodesk Revit 2025 that does this kind of
exception propagation.
Close #113158
* Disable the test on Mono
* Fix the problem with C++ exception object in reclaimed stack
* Fix jongjmp accidentally handled as foreign1 parent ac5f930 commit a087868
3 files changed
Lines changed: 110 additions & 6 deletions
File tree
- src
- coreclr/vm
- tests/baseservices/exceptions/exceptioninterop
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5662 | 5662 | | |
5663 | 5663 | | |
5664 | 5664 | | |
5665 | | - | |
5666 | | - | |
5667 | | - | |
5668 | | - | |
5669 | | - | |
| 5665 | + | |
| 5666 | + | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
| 5670 | + | |
| 5671 | + | |
| 5672 | + | |
| 5673 | + | |
| 5674 | + | |
| 5675 | + | |
| 5676 | + | |
5670 | 5677 | | |
5671 | 5678 | | |
5672 | 5679 | | |
| |||
7716 | 7723 | | |
7717 | 7724 | | |
7718 | 7725 | | |
| 7726 | + | |
| 7727 | + | |
| 7728 | + | |
| 7729 | + | |
| 7730 | + | |
| 7731 | + | |
| 7732 | + | |
| 7733 | + | |
| 7734 | + | |
| 7735 | + | |
| 7736 | + | |
| 7737 | + | |
| 7738 | + | |
| 7739 | + | |
| 7740 | + | |
| 7741 | + | |
| 7742 | + | |
| 7743 | + | |
| 7744 | + | |
| 7745 | + | |
| 7746 | + | |
| 7747 | + | |
| 7748 | + | |
| 7749 | + | |
| 7750 | + | |
| 7751 | + | |
7719 | 7752 | | |
7720 | 7753 | | |
7721 | 7754 | | |
| |||
7784 | 7817 | | |
7785 | 7818 | | |
7786 | 7819 | | |
| 7820 | + | |
7787 | 7821 | | |
7788 | 7822 | | |
7789 | 7823 | | |
| |||
7885 | 7919 | | |
7886 | 7920 | | |
7887 | 7921 | | |
| 7922 | + | |
| 7923 | + | |
| 7924 | + | |
| 7925 | + | |
| 7926 | + | |
| 7927 | + | |
| 7928 | + | |
| 7929 | + | |
| 7930 | + | |
| 7931 | + | |
| 7932 | + | |
| 7933 | + | |
| 7934 | + | |
| 7935 | + | |
| 7936 | + | |
| 7937 | + | |
| 7938 | + | |
7888 | 7939 | | |
7889 | 7940 | | |
7890 | 7941 | | |
| |||
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
159 | 196 | | |
Lines changed: 17 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
0 commit comments