Avoid publishing interpreter frame with invalid IP#129795
Conversation
|
/azp run runtime-interpreter |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli, @kg |
|
/azp run runtime-interpreter |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@janvorli Miraculously, this actually fixed the failing test. It would be great if you could reproduce the failure and validate the theory, but I believe the fix is simplistic enough anyway and it doesn't impact any hot path. |
| pFrame->pNext = pChildFrame; | ||
| // We make sure that a new frame can't be seen with invalid ip/next when a stack | ||
| // overflow is triggered at a location outside of our control. | ||
| VolatileStoreWithoutBarrier(&pChildFrame->ip, (const int32_t*)nullptr); |
There was a problem hiding this comment.
I just wish there was a less verbose way when we really need just a compiler barrier between the other fields writes and the pNext field write. But I understand that since compiler barrier like _ReadWriteBarrier on Windows is deprecated, we will have to live with that.
There was a problem hiding this comment.
Yeah, this is what mono was doing with mono_compiler_barrier. Apparently there is the cross platform std::atomic_signal_fence(std::memory_order_acq_rel) which should achieve these everywhere and might be a good alternative.
There was a problem hiding this comment.
Ah, it seems we could use that one. It doesn't seem to contradict any of the rules in https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/clr-code-guide.md#211-using-standard-headers.
When we need to obtain a new
InterpMethodContextFramefor called method execution, we try to obtain a preallocated one from the list. If there is none, then we just allocate a new one withallocaand initialize the fields, including theipto 0 initially. The problem is that the compiler is free to reorder this initialization in whichever way it considers optimal. If a stack overflow gets triggered at some point during execution (at a location that we don't normally expect), the unwinder might actually observe a pushed interp frame that has a non-null junk ip. We fix this by making sure the ip is properly zeroed before we publish the new interpreter frame on the list. Order is achieved just via compiler barriers.Should fix
stackoverflowtesteron win-arm64.