From 790d0b601cba52e826c53108a787a0a52d29a02b Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Thu, 16 Sep 2021 17:18:37 +0000 Subject: [PATCH] [vm] Account for Out Of Memory during isolate message deserialization. TEST=run test harness with low heap limit Change-Id: I75d3b2e8461bcf99cc41eb3ad76173bc1976bbd9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213538 Reviewed-by: Alexander Aprelev Commit-Queue: Ryan Macnak --- runtime/vm/longjump.h | 8 +++----- runtime/vm/message_snapshot.cc | 11 ++++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/runtime/vm/longjump.h b/runtime/vm/longjump.h index c551584b95c..60f514b2587 100644 --- a/runtime/vm/longjump.h +++ b/runtime/vm/longjump.h @@ -16,11 +16,9 @@ class Error; class LongJumpScope : public StackResource { public: - LongJumpScope() - : StackResource(ThreadState::Current()), - top_(nullptr), - base_(thread()->long_jump_base()) { - thread()->set_long_jump_base(this); + explicit LongJumpScope(ThreadState* thread = ThreadState::Current()) + : StackResource(thread), top_(nullptr), base_(thread->long_jump_base()) { + thread->set_long_jump_base(this); } ~LongJumpScope() { diff --git a/runtime/vm/message_snapshot.cc b/runtime/vm/message_snapshot.cc index a110b896278..ac2eef3dcd3 100644 --- a/runtime/vm/message_snapshot.cc +++ b/runtime/vm/message_snapshot.cc @@ -3745,7 +3745,7 @@ std::unique_ptr WriteMessage(bool can_send_any_object, volatile bool has_exception = false; { - LongJumpScope jump; + LongJumpScope jump(thread); if (setjmp(*jump.Set()) == 0) { serializer.Serialize(obj); } else { @@ -3820,8 +3820,13 @@ ObjectPtr ReadMessage(Thread* thread, Message* message) { return ReadObjectGraphCopyMessage(thread, message->persistent_handle()); } else { RELEASE_ASSERT(message->IsSnapshot()); - MessageDeserializer deserializer(thread, message); - return deserializer.Deserialize(); + LongJumpScope jump(thread); + if (setjmp(*jump.Set()) == 0) { + MessageDeserializer deserializer(thread, message); + return deserializer.Deserialize(); + } else { + return thread->StealStickyError(); + } } }