You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
alexmarkov opened this issue
Jun 13, 2019
· 0 comments
Assignees
Labels
area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.crashProcess exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash.gardening
native method Socket_SendTo calls Dart_TypedDataAcquireData to get a direct pointer to a data in the TypedData object.
Direct pointer to data is passed to sendto
GC is triggered and moves TypedData object, protects the memory
sento returns with an error (EFAULT) as it can't access buffer
As Dart_TypedDataAcquireData returns direct pointer to the contents of TypedData object, GC should be disabled until Dart_TypedDataReleaseData is called. But it doesn't happen.
Currently, GC can be called after acquiring direct pointer because:
When leaving DARTSCOPE in Dart_TypedDataAcquireData, there is a safepoint when transitioning from VM state back to native state.
While thread is in native state, it will not be blocked while GC is happening, so GC can theoretically run concurrently with native code between Dart_TypedDataAcquireData and Dart_TypedDataReleaseData.
The following additional asserts can be used to reproduce the error more regularly:
diff --git a/runtime/vm/thread.h b/runtime/vm/thread.h
index 44bb9e6110..ef03c8343b 100644
--- a/runtime/vm/thread.h
+++ b/runtime/vm/thread.h
@@ -738,6 +738,7 @@ class Thread : public ThreadState {
}
void EnterSafepoint() {
+ ASSERT(no_safepoint_scope_depth() == 0);
// First try a fast update of the thread state to indicate it is at a
// safepoint.
if (!TryEnterSafepoint()) {
@@ -767,6 +768,7 @@ class Thread : public ThreadState {
}
void CheckForSafepoint() {
+ ASSERT(no_safepoint_scope_depth() == 0);
if (IsSafepointRequested()) {
BlockForSafepoint();
}
In order to fix this problem, we need to make sure that GC may not happen between Dart_TypedDataAcquireData and Dart_TypedDataReleaseData (if they are called for non-external TypedData).
This can be achieved by introducing a new thread state such as ThreadInNativeNoSafepoints. Safepoints could also take Thread::no_callback_scope_depth() into account.
The text was updated successfully, but these errors were encountered:
alexmarkov
added
area-vm
Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
gardening
crash
Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash.
labels
Jun 13, 2019
area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.crashProcess exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash.gardening
Repro:
The following happens:
As Dart_TypedDataAcquireData returns direct pointer to the contents of TypedData object, GC should be disabled until Dart_TypedDataReleaseData is called. But it doesn't happen.
Currently, GC can be called after acquiring direct pointer because:
The following additional asserts can be used to reproduce the error more regularly:
In order to fix this problem, we need to make sure that GC may not happen between Dart_TypedDataAcquireData and Dart_TypedDataReleaseData (if they are called for non-external TypedData).
This can be achieved by introducing a new thread state such as ThreadInNativeNoSafepoints. Safepoints could also take Thread::no_callback_scope_depth() into account.
/cc @rmacnak-google @a-siva @mkustermann
The text was updated successfully, but these errors were encountered: