Commit Graph

59 Commits

Author SHA1 Message Date
asiva 26cab0a4db [VM/IO] The exit code handler thread should not try to get the exit codes for detached child processes. Currently we end up in a tight loop in the exit code handler when detached processes are created.
Change-Id: I0eb207c4421d9e22e62ffd5a53478cf1553a3188
Reviewed-on: https://dart-review.googlesource.com/c/78701
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2018-10-08 23:22:19 +00:00
Zachary Anderson 6523896c6f [dart:io] Adds ProcessStartMode.INHERIT_STDIO
Adds a ProcessStartMode in which the child process inherits the stdio
handles from the parent.

Change-Id: Ibe7b8ae08caccaed827ae0a911a3cced7803cb6b
Reviewed-on: https://dart-review.googlesource.com/36362
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
2018-01-23 22:50:06 +00:00
Zachary Anderson 0951ab163b [dart:io] Don't use fexecve. It is weird.
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>
2017-10-03 20:15:03 +00:00
Zachary Anderson d0295c873c [dart:io] Namespaces for file IO
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 .
2017-08-30 09:34:36 -07:00
Zachary Anderson 747868f2b1 [dart:io] Remove DART_IO_DISABLED
This was only used by Dartium.

Review-Url: https://codereview.chromium.org/3009523002 .
2017-08-24 11:17:52 -07:00
Carlo Bernaschina 0cbbeeb288 Restore "Add current rss and embedder name to Observatory"
Made benchmark_test.cc independent from Service by using the
implementation of MaxRSS from bin::Process

Related https://github.com/dart-lang/sdk/commit/ce736d3ef009bf334a92d5b7d354fc0b04805b4f

R=bkonyi@google.com
TBR=rmacnak@google.com

Review-Url: https://codereview.chromium.org/2994223002 .
2017-08-14 17:02:30 -07:00
Carlo Bernaschina 2f5a59e658 Revert "Add current rss and embedder name to Observatory"
This reverts commit ce736d3ef0.

TBR=zra@google.com

Review-Url: https://codereview.chromium.org/2999933002 .
2017-08-14 15:45:13 -07:00
Carlo Bernaschina ce736d3ef0 Add current rss and embedder name to Observatory
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 .
2017-08-14 15:22:46 -07:00
Zachary Anderson 6cd8a79078 VM: Re-format to use at most one newline between functions
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2974233002 .
2017-07-13 08:08:37 -07:00
Zachary Anderson 4ecf748d5e [dart:io] Fixes a crash in VM shutdown when signals are watched
This CL fixes a crash in VM shutdown which is triggered by Dart programs
that throw unhandled exceptions while watching OS signals.

fixes #30033

R=rmacnak@google.com

Review-Url: https://codereview.chromium.org/2961993002 .
2017-06-28 11:05:07 -07:00
Erik Corry 029b1cb948 Spelling fixes e to i.
R=kevmoo@google.com
BUG=

Review-Url: https://codereview.chromium.org/2957593002 .
2017-06-24 13:41:39 +02:00
Zachary Anderson 9ce608e89d [dart:io] Adds ProcessInfo.{max,current}Rss. Adds OS::MaxRSS on Fuchsia.
R=rmacnak@google.com

Review-Url: https://codereview.chromium.org/2822943002 .
2017-04-17 14:41:40 -07:00
Ryan Macnak 877284947b Rename TARGET_OS_* to HOST_OS_*.
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 .
2017-03-15 13:11:05 -07:00
Martin Kustermann 5dc73cacd2 VM: Avoid running atexit() handlers during exit() of a failed subprocess spawn
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 .
2017-01-12 14:20:34 +01:00
Martin Kustermann e0a427a957 Workaround attempt for timeout flakiness: Avoid running atexit() handlers in fork()ed process on linux
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/28246
R=vegorov@google.com

Review-Url: https://codereview.chromium.org/2618723002 .
2017-01-05 13:56:01 +01:00
Zach Anderson 2b48261764 Fix Process.runSync error handling.
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 .
2016-12-21 09:10:40 -08:00
Zachary Anderson 479a97b129 clang-format runtime/bin
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2480793002 .
2016-11-04 12:30:56 -07:00
Ryan Macnak 4d65db8a95 Don't use IsolateData for the exit hook as multiple embedders share the dart/bin while using different isolate data structures.
Issue flutter/flutter#6506

R=asiva@google.com

Review URL: https://codereview.chromium.org/2463923002 .
2016-10-31 15:56:25 -07:00
Zachary Anderson 7308e58c3f Really remove io support when dart:io is unsupported.
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 .
2016-03-29 11:22:03 -07:00
Zachary Anderson 45661a7091 Cleanup in //runtime/bin
R=iposva@google.com

Review URL: https://codereview.chromium.org/1800863002 .
2016-03-16 10:01:00 -07:00
Zachary Anderson c75a817ee0 Fixes some memory leaks in //runtime/bin
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 .
2016-03-14 11:08:52 -07:00
John McCutchan aaf37ad035 Landing patch set 7 from https://codereview.chromium.org/1450113003/
Review URL: https://codereview.chromium.org/1466523002 .
2015-11-19 14:18:52 -08:00
John McCutchan 28e416b1f4 Revert "Avoid strerror_r portability issues"
This reverts commit ca81c1732b.
2015-11-17 16:34:25 -08:00
John McCutchan ca81c1732b Avoid strerror_r portability issues
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/1450113003 .
2015-11-17 15:23:47 -08:00
Anders Johnsen 9a01a22e96 Revert "Clean up process spawning."
This reverts commits
- bbdc57ebf6
- bd25e641f2
- 5cc8fca131
- ed72caa3cd

BUG=

Review URL: https://codereview.chromium.org//1182423003.
2015-06-15 15:26:56 +02:00
Anders Johnsen bbdc57ebf6 Clean up process spawning.
Pass environment as argument to execvpe and use _exit instead of exit
(so fork/vfork can be used interchangeable).

BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//1156313004.
2015-06-10 10:42:54 +02:00
ajohnsen@google.com ab6f8cc118 Make all of stdout/stderr/stdin pipes close-on-exec when spawing child processes.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//1076093004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45370 260f80e4-7a28-3924-810f-c04153c831b5
2015-04-23 07:37:53 +00:00
sgjesse@google.com 9aa4805e21 Add an option for starting a detached process with stdio connected
R=lrn@google.com, kustermann@google.com
BUG=

Review URL: https://codereview.chromium.org//890633002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43393 260f80e4-7a28-3924-810f-c04153c831b5
2015-02-03 13:38:38 +00:00
sgjesse@google.com 042462d69b Refactor the process creation code on POSIX platforms
This moved the process creation code to a class, and splits the
single function used before into several methods operation on instance
variables.

The refactor revealed at least one leaked file descriptor.

R=kustermann@google.com
BUG=

Review URL: https://codereview.chromium.org//884143002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43280 260f80e4-7a28-3924-810f-c04153c831b5
2015-01-29 13:06:40 +00:00
sgjesse@google.com f1b1e4a8db Aling process implementation and fix bugs
Aling the code for dart:io process as much as possible between Linux,
Mac OS and Android prior to refactiring the code.

On Mac OS file descriptors where not closed corrently. On Linux EINTR
was not expected for all calls.

R=kustermann@google.com, kunstemann@google.com
BUG=

Review URL: https://codereview.chromium.org//882093002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43274 260f80e4-7a28-3924-810f-c04153c831b5
2015-01-29 11:54:54 +00:00
sgjesse@google.com 417ee299b3 Port the support for starting a detached process to Android.
This is the Android part of r43070.

TBR=kustermann@google.com
BUG=

Review URL: https://codereview.chromium.org//864293003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43072 260f80e4-7a28-3924-810f-c04153c831b5
2015-01-22 13:16:07 +00:00
iposva@google.com 5a383e7add - Make sure that the threads for dart::bin are in the correct namespace.
R=asiva@google.com

Review URL: https://codereview.chromium.org//471743002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@39233 260f80e4-7a28-3924-810f-c04153c831b5
2014-08-14 00:06:04 +00:00
iposva@google.com 14ecdbd66a - Separate the thread implementation used in bin/ and vm/
to allow us to make VM specific changes.

R=asiva@google.com

Review URL: https://codereview.chromium.org//463993002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@39172 260f80e4-7a28-3924-810f-c04153c831b5
2014-08-12 23:19:53 +00:00
ajohnsen@google.com 6906b3ba5f Fix listening for multiple signals.
BUG=https://code.google.com/p/dart/issues/detail?id=18793
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//285023002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@36153 260f80e4-7a28-3924-810f-c04153c831b5
2014-05-14 09:36:03 +00:00
ajohnsen@google.com 03429c2ee6 Allow internal usage of SIGQUIT signal listening.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//262463002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@35616 260f80e4-7a28-3924-810f-c04153c831b5
2014-05-01 08:01:09 +00:00
ajohnsen@google.com ca58691974 Mark pipe as close-on-exec.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//251403004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@35354 260f80e4-7a28-3924-810f-c04153c831b5
2014-04-24 07:34:07 +00:00
ajohnsen@google.com 0c157cd31e Move signal_blocker to platform and use it by default in TEMP_FAILURE_RETRY.
BUG=http://code.google.com/p/dart/issues/detail?id=16927
R=johnmccutchan@google.com, sgjesse@google.com

Review URL: https://codereview.chromium.org//165723007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33745 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-17 13:51:11 +00:00
ajohnsen@google.com 36ba03fd0c Use signal-block around fork() to avoid we block it.
This issue is seen on a single-core VM.

BUG=https://code.google.com/p/dart/issues/detail?id=17217
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org//176933006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33219 260f80e4-7a28-3924-810f-c04153c831b5
2014-03-03 15:38:22 +00:00
ajohnsen@google.com 2f60129fb0 Document ProcessSignal::watch.
We now also allow watching for SIGTERM.

BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//149253013

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32416 260f80e4-7a28-3924-810f-c04153c831b5
2014-02-07 09:41:38 +00:00
ajohnsen@google.com 3bc42be527 Block other signals while handling a signal.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//118713003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31331 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-20 12:12:17 +00:00
ajohnsen@google.com 38d0fad2c7 Signal handling, take 2.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//119093007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31276 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-19 15:07:48 +00:00
ajohnsen@google.com f24f568571 Revert "Signal handling."
This reverts commit r31270.

BUG=

Review URL: https://codereview.chromium.org//105083009

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31275 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-19 14:03:15 +00:00
ajohnsen@google.com e8d9794c70 Signal handling.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//108003009

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31270 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-19 13:08:26 +00:00
ajohnsen@google.com 1cd800214f Always wait for child processes when forked, even if the process failed.
BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//23494048

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27384 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-11 14:29:23 +00:00
ajohnsen@google.com 6949a7bd08 Simplify process exit-code handling on Posix, take 2.
As in https://codereview.chromium.org/24024007, except the monitor->Wait
is now called in a loop with a guard, to ensure we actually do get notified.

Also, now correctly exiting the thread if we have no more child
processes, using the initialize/terminate mutex as guard.

BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//23717038

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27380 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-11 13:05:13 +00:00
ajohnsen@google.com bce63cccc9 Revert "Simplify process exit-code handling on Posix."
This reverts commit f1b1ba410e964b0f787513f245faf8b457c9331a.

BUG=

Review URL: https://codereview.chromium.org//23536032

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27251 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-06 15:02:31 +00:00
ajohnsen@google.com 5e4135c731 Simplify process exit-code handling on Posix.
We now only use waitpid and not signals. When we exit, we perform a
small fork-and-exit to interrupt waitpid, so it can exit the thread.

BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//24024007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27247 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-06 13:08:34 +00:00
sgjesse@google.com f235a79d0d Remove ASSERT which was reported as a race by ThreadSanitizer
R=whesse@google.com
BUG=

Review URL: https://codereview.chromium.org//23903007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27131 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-04 13:52:59 +00:00
whesse@google.com 6de4e020f2 Fix android compilation by copying process_linux.cc to process_android.cc.
These files, in runtime/bin, are the native functions supporting the dart:io
Process class.  The android version hadn't been updated when the linux version was changed.

BUG=
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//23428002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26642 260f80e4-7a28-3924-810f-c04153c831b5
2013-08-26 12:28:08 +00:00
cbracken@google.com a6ace331f3 Replaced strerror() calls with threadsafe strerror_r().
Mac/Android use the XSI-compliant definition of strerror_r() which stores the message in the passed-in buffer.

Linux uses the GNU-specific definition of strerror_r() which takes a buffer and returns the message in a char* (which may or may not be the passed-in buffer).

BUG=
R=iposva@google.com

Review URL: https://codereview.chromium.org//22634003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25943 260f80e4-7a28-3924-810f-c04153c831b5
2013-08-08 20:24:05 +00:00