that we do not have any state mismatch when the Dart VM is initialzed
and cleaned up multiple times.
TEST=existing unit test in the engine which is failing in a flaky manner
Change-Id: I073ca2b53a8c3d386be46b5222d547a29513714a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207642
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
This relands https://dart-review.googlesource.com/c/sdk/+/205633
but without renaming TARGET_OS_IPHONE to DART_TARGET_OS_IPHONE.
It also changes uses of TARGET_OS_IOS to
DART_TARGET_OS_MACOS_IOS to be consistent with the rest of the
VM.
TargetConditionals.h for XCode 13 defines several
TARGET_OS_* preprocessor symbols that confuse the
Dart build. There is probably a more targeted fix
for this, but renaming the symbols that Dart uses
will also prevent this problem if more symbols
are added to the platform headers in the future.
See: https://github.com/dart-lang/sdk/issues/46499
TEST=It builds.
Change-Id: Ie775c19dd23cfdf5f65e5ebc6ee4ec3a561676fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205860
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
TargetConditionals.h for XCode 13 defines several
TARGET_OS_* preprocessor symbols that confuse the
Dart build. There is probably a more targeted fix
for this, but renaming the symbols that Dart uses
will also prevent this problem if more symbols
are added to the platform headers in the future.
See: https://github.com/dart-lang/sdk/issues/46499
TEST=It builds.
Change-Id: I3b33a03b4a9a14b76d55fe12f8cdefec4b3c3664
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205633
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Prior to this CL, the signal handler finalizer passes a file descriptor
where a signal number is expected.
This went uncaught for awhile since it is innocuous in most cases.
Clearing a signal handler just involves setting it back to the
default. It is not innocuous where the VM chose to override the
default, for example in the case of SIGPIPE. When setting signal
handlers with the dart:io API, if the finalizer for a _NativeSocket
for a signal handler runs, some time later the VM may be killed by
SIGPIPE instead of getting EPIPE from an IO call.
This CL replaces the call in the finalizer with a new call that
expects a file descriptor, and uses the file descriptor to look
up the signal handler that needs to be cleaned up.
Change-Id: I54caa14a556e434872d12fd9acf8c2fcf767b91e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/146080
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
This CL adds a `dart::embedder::Cleanup()` (we already have `dart::embedder::InitOnce()`).
This allows us to allocate the global state and also tear it down.
As a side-effect this will also not allocate those variables if not
needed, which should fix b/151210948
Change-Id: I3c5c619586380bf27ee863ba026bbc631f243d85
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139640
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This CL:
* Moves [Heap]/[SharedClassTable] from [Isolate] to [IsolateGroup], which
will make all isolates in the group use the same heap. The GC will use
the shared class table for object size information.
* Adds support for entering/leaving an isolate group as a helper thread
(e.g. via [Thread::EnterIsolateGroupAsHelper]). The current active
isolate group can be accessed via TLS `IsolateGroup::Current()` or
`Thread::isolate_group_`. When entering as a helper thread there will be
no current isolate.
* Changes the GC to use the above mechanism and ensures GC works without
a currently active isolate. The GC will use information purely available via
[IsolateGroup]. The GC will iterate all isolates within an isolate
group e.g. for scanning roots.
* Makes spawning of new isolates start in their own isolate group.
Once the isolate is fully functional it's heap will be merged into
the original isolate group
* Moves ApiState, containing persistent and weak persistent handles,
from [Isolate] to [IsolateGroup], plus adds appropriate locking.
Issue https://github.com/dart-lang/sdk/issues/36097
Change-Id: Ia8e1d8aa78750e8400864200f4825395a182c004
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126646
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
The loop didn't correctly handle if the fd closed wasn't the last in the
list, instead it would skip an entry and would accidentally consider the
closed entry twice.
The error handling was also wrong, where a file descriptor could be
closed multiple times if an error occured after one of the file
descriptors had already been closed. Additionally the POLLERR and
POLLNVAL conditions were not handled.
Fixes https://github.com/dart-lang/sdk/issues/40441.
Change-Id: I4b4da067bbaf40af329e37ccf45d85f8bbf6c914
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134723
Commit-Queue: Jonas Termansen <sortie@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
On POSIX platforms, execvp was being run wrapped in
`VOID_TEMP_FAILURE_RETRY` which blocked SIGPROF, resulting in SIGPROF
being blocked in the new application. This would cause Dart applications
spawned through dart:io as a new process to not receive profiler ticks.
This should fix the issue where `flutter run -d {linux,macos}` would
result in profiling being broken for the spawned desktop application.
Change-Id: I7b176ce48144bcbca29d4ae63c82599623ce3c35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127451
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Platform::Init (now Platform::InitOnce) was only being called directly
from the CL embedder and could not be invoked via any path in the embedding
API. Platform::InitOnce is now invoked in both dart::bin::BootstrapDartIo and
dart::embedder::InitOnce.
Fixes https://github.com/dart-lang/sdk/issues/37586
Change-Id: I594908895c19e3058f707f920e265e79ca4cecd7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117591
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
This is a security improvement.
On Linux and Android, starting a process with Process.run, Process.runSync
or Process.start would first search the current directory before searching
PATH (Issue [37101][]). Operating systems other than Linux and Android
didn't have this behavior and aren't affected by this vulnerability.
Effectively this puts the current working directory in the front of PATH,
even if it wasn't in the PATH.
This change fixes that vulnerability and only searches the directories in
the PATH environment variable.
Fixes https://github.com/dart-lang/sdk/issues/37101
Change-Id: I05f3137753237f9b3ba4be4eba63ad07a75d865e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105582
Reviewed-by: William Hesse <whesse@google.com>
Change some static_libraries to source_sets to make ODR violations link-time errors.
This is needed to enable (stop suppressing) -fvisibility=hidden in Fuchsia product builds.
Change-Id: I699cec8d4b516beab9cebf9db0a522a7ff99e004
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99822
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
fexecve overwrites argv[0] for cases in which the exec'd binary should
close the fd itself rather than the calling process. This makes it
inappropriate for use in the VM. Instead the VM should use
execveat, however it hasn't been added to the C Library everywhere,
yet.
fixes#30971
Change-Id: I82085f24ded2f0b846d9193ca55903686e1f3585
Reviewed-on: https://dart-review.googlesource.com/10205
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Fuchsia requires the ability to sandbox Isolates w.r.t. file IO.
When a new Isolate starts, Fuchsia will pass the Isolate an object
called a namespace. We can translate the namespace object into a
file descriptor suitable for passing to the *at() family of
POSIX file system calls. The file system calls will then
have visibility only into the specified namespace.
We also plumb Namespaces through on all the other platforms as well to
make the change easier to test and so that in the future we can
implement e.g. per-isolate cwds.
This change adds a new internal class to dart:io called _Namespace,
which is implemented in a patch file. See:
sdk/lib/io/namespace_impl.dart
runtime/bin/namespace_patch.dart
The embedder can set up a non-default namespace by calling
_Namespace._setupNamespace during Isolate setup.
Instances of _Namespace have a native field that holds a pointer
to a native Namespace object. See:
runtime/bin/namespace.h
Calls from e.g. file_impl.dart are now also passed a
_Namespace object. The implementations in e.g. file.cc and
file_linux.cc then extract the namespace, and use it to compute a
file descriptor and path suitable for passing to e.g. openat().
related US-313
R=asiva@google.com, rmacnak@google.com
Review-Url: https://codereview.chromium.org/3007703002 .
Moved the responsibility to provide MaxRSS and CurrentRSS from the VM to
the embedder.
The embedder can opt-it by setting a Dart_GetEmbedderInformation
callback using the public Dart_SetEmbedderInformationCallback API.
The implementation of the Dart_GetEmbedderInformation should mandatory
fill the version field and the ones it is able to fill.
The name field must reference a constant C style string, it will not be
freed by the VM code.
R=zra@google.com
Review-Url: https://codereview.chromium.org/2996803002 .
Like HOST_ARCH_*, HOST_OS_* describes the OS the VM is running on, which may be different from the OS the VM is generating code for during AOT compilation.
Currently we conflate the two when emitting AOT as assembly, and we get away with it because Flutter only uses assembly for targeting iOS and one can only target iOS from a Mac, but we expect to use assembly for Android as well so native tools can unwind Dart frames.
R=zra@google.com
Review-Url: https://codereview.chromium.org/2750843003 .
Somtimes execve() fails and then we fall back to exit(1) in the fork()ed but not
exeve()ed subprocess.
One of the issues is e.g. that we don't want to run LSAN in the fork()ed but not
execve()ed subprocess, the results will be bogus (plus the output of
LSAN is not read on the other side (i.e. the unix pipe is not drained) which
blocks the subprocess indefinitely).
R=vegorov@google.com
Review-Url: https://codereview.chromium.org/2632483002 .
About this CL:
The only purpose of `if (fork() == 0) exit(0)` is to wake up
a thread in the parent process which might be blocked on `wait()`.
There is no need to run atexit() handlers in the `fork()`ed child.
This is a *workaround attempt* for a deadlocked `free()` call inside the
processing of atexit handlers in glibc.
(Side note: There might be better ways of notifying the thread, like sending a
signal to the particular pthread with `pthread_kill` which would make the
`wait()` syscall be interrupted.)
About the issue:
It is still unclear why, in this particular case, the tcmalloc locks should
be hold during the `exit()` call:
* via a static initializer tcmalloc uses
`pthread_atfork(before=ObtainAllLocks(),
after_parent=ReleaseAllLocks(),
after_child=ReleaseAllLocks())`
to register locking & unlocking around `fork()`
* glibc's `fork()` runs the either `after_parent` or `after_child` handlers
(unconditionally) which should free the locks
* the `exit()` call later should be free to malloc/free
The [BUG] describes more in detail how we can hit a tcmalloc deadlock in a
different situation (it's a linux kernel bug).
Namely, if the linux kernel runs OOM during `fork()` and therefore fails to
set the new thread-id. The glibc code hits an assert and tries to allocate
memory before `after_parent`/`after_child` handlers were executed which
deadlocks.
BUG=https://github.com/dart-lang/sdk/issues/28246R=vegorov@google.com
Review-Url: https://codereview.chromium.org/2618723002 .
Now, failing to allocate a buffer for stderr or stdout will generate
an ENOMEM OSError exception.
Also previously, read() returning an error would cause buffers for
stderr and stdout to leak. After this change, they'll be reclaimed.
R=asiva@google.com
Review-Url: https://codereview.chromium.org/2596543002 .
Previously we would compile in implementaitions of native calls for
IO functions that would never be used. This CL provides implementations
that throw a Dart exception if they're called by mistake. It also uses
a DART_IO_DISABLED preprocessor define to clean up the build files and
check that we're not including code we shouldn't.
R=iposva@google.com, johnmccutchan@google.com
Review URL: https://codereview.chromium.org/1839463002 .
Also some style cleanups.
Decided to fix these leaks by using Dart_ScopeAllocate
instead of malloc and new. Leaks are noted in the CL.
I haven't finished looking over all the code in
//runtime/bin yet, but this CL was getting big.
Review URL: https://codereview.chromium.org/1781883002 .