[vm/isolates] Avoid leaving isolate as part of native message handling.
Letting isolate go seems to be problematic. If this native messaging api is used during runtime call, then original isolate might end up on a different worker os thread causing remembered frame pointer(remembered as part of entering runtime call) to become invalid due to different stack bounds of this new thread. Invalid frame pointer causes immediate assertion failures during stack walk done for GC purposes or for exception handling. TEST=ci, https://dart-review.git.corp.google.com/c/sdk/+/486522/comments/ee54d99f_a5c2a9d4 Change-Id: If69076bb9e107502dfef819de73829d9682bb134 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501220 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
@@ -21,28 +21,6 @@ namespace dart {
|
||||
|
||||
// --- Message sending/receiving from native code ---
|
||||
|
||||
class IsolateLeaveScope {
|
||||
public:
|
||||
explicit IsolateLeaveScope(Isolate* current_isolate)
|
||||
: saved_isolate_(current_isolate) {
|
||||
if (current_isolate != nullptr) {
|
||||
ASSERT(current_isolate == Isolate::Current());
|
||||
Dart_ExitIsolate();
|
||||
}
|
||||
}
|
||||
~IsolateLeaveScope() {
|
||||
if (saved_isolate_ != nullptr) {
|
||||
Dart_Isolate I = reinterpret_cast<Dart_Isolate>(saved_isolate_);
|
||||
Dart_EnterIsolate(I);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Isolate* saved_isolate_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IsolateLeaveScope);
|
||||
};
|
||||
|
||||
class DartApiCallScope : public ValueObject {
|
||||
public:
|
||||
DartApiCallScope() : active_(Dart::SetActiveApiCall()) {}
|
||||
@@ -110,8 +88,6 @@ Dart_NewConcurrentNativePort(const char* name,
|
||||
return ILLEGAL_PORT;
|
||||
}
|
||||
ENTER_API_CALL_OR_RETURN(ILLEGAL_PORT);
|
||||
// Start the native port without a current isolate.
|
||||
IsolateLeaveScope saver(Isolate::Current());
|
||||
|
||||
NativeMessageHandler* nmh =
|
||||
new NativeMessageHandler(name, handler, max_concurrency);
|
||||
@@ -122,9 +98,6 @@ Dart_NewConcurrentNativePort(const char* name,
|
||||
DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) {
|
||||
ENTER_API_CALL_OR_RETURN(false)
|
||||
|
||||
// Close the native port without a current isolate.
|
||||
IsolateLeaveScope saver(Isolate::Current());
|
||||
|
||||
PortHandler* handler = nullptr;
|
||||
const bool was_closed = PortMap::ClosePort(native_port_id, &handler);
|
||||
if (was_closed) {
|
||||
@@ -148,7 +121,6 @@ DART_EXPORT bool Dart_InvokeVMServiceMethod(uint8_t* request_json,
|
||||
|
||||
Isolate* isolate = Isolate::Current();
|
||||
ASSERT(isolate == nullptr || !isolate->is_service_isolate());
|
||||
IsolateLeaveScope saver(isolate);
|
||||
|
||||
// We only allow one isolate reload at a time. If this turns out to be on the
|
||||
// critical path, we can change it to have a global datastructure which is
|
||||
|
||||
@@ -25,12 +25,6 @@ NativeMessageHandler::NativeMessageHandler(const char* name,
|
||||
|
||||
NativeMessageHandler::~NativeMessageHandler() {}
|
||||
|
||||
#if defined(DEBUG)
|
||||
void NativeMessageHandler::CheckAccess() const {
|
||||
ASSERT(Isolate::Current() == nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
class HandleMessage : public ThreadPool::Task {
|
||||
public:
|
||||
|
||||
@@ -28,11 +28,6 @@ class NativeMessageHandler final : public PortHandler {
|
||||
const char* name() const override { return name_.get(); }
|
||||
Dart_NativeMessageHandler func() const { return func_; }
|
||||
|
||||
#if defined(DEBUG)
|
||||
// Check that it is safe to access this handler.
|
||||
void CheckAccess() const override;
|
||||
#endif
|
||||
|
||||
void OnPortClosed(Dart_Port port) override {}
|
||||
|
||||
Isolate* isolate() const override { return nullptr; }
|
||||
|
||||
Reference in New Issue
Block a user