[K/N] Fix currentFrame in smaller scope, to avoid gc while having incorrect shadow stack

This commit is contained in:
Pavel Kunyavskiy
2022-03-10 12:18:33 +03:00
committed by Space
parent 779aa75855
commit 42a2ce1610
2 changed files with 12 additions and 7 deletions
@@ -498,6 +498,14 @@ private:
bool reentrant_;
};
class CurrentFrameGuard : Pinned {
public:
CurrentFrameGuard() : frame_(getCurrentFrame()) {}
~CurrentFrameGuard() { SetCurrentFrame(reinterpret_cast<ObjHeader**>(frame_)); }
private:
FrameOverlay* frame_;
};
template <ThreadState state, typename R, typename... Args>
ALWAYS_INLINE inline R CallWithThreadState(R(*function)(Args...), Args... args) {
ThreadStateGuard guard(state);
@@ -1106,21 +1106,18 @@ JobKind Worker::processQueueElement(bool blocking) {
ObjHolder argumentHolder;
ObjHolder resultHolder;
KRef argument = AdoptStablePointer(job.regularJob.argument, argumentHolder.slot());
#if !KONAN_NO_EXCEPTIONS
FrameOverlay* currentFrame = getCurrentFrame();
#else
#error "Exceptions aren't supported!"
#endif
try {
#if KONAN_OBJC_INTEROP
konan::AutoreleasePool autoreleasePool;
#endif
job.regularJob.function(argument, resultHolder.slot());
{
CurrentFrameGuard guard;
job.regularJob.function(argument, resultHolder.slot());
}
argumentHolder.clear();
// Transfer the result.
result = transfer(&resultHolder, job.regularJob.transferMode);
} catch (ExceptionObjHolder& e) {
SetCurrentFrame(reinterpret_cast<ObjHeader**>(currentFrame));
ok = false;
switch (exceptionHandling()) {
case WorkerExceptionHandling::kIgnore: