Commit Graph

89 Commits

Author SHA1 Message Date
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 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
Ryan Macnak 22b72a845c gen_snapshot:
- Don't try to mmap an empty file.
  - Use correct filename for mapping errors.
  - Don't set the root library for core-jit snapshots.
  - Accept hyphen variants of options for entry points and compilation traces.

R=zra@google.com

Review-Url: https://codereview.chromium.org/2928663002 .
2017-06-06 14:31:48 -07:00
Zachary Anderson 8c9c54d833 [dart:io] Don't close stdin with a socket finalizer
If an Isolate touches the 'stdio' getter, a _NativeSocket with
attached finalizer is created for it. Previously, when such an
Isolate exited, the finalizer would close the underlying
file descriptor. This CL changes the finalizer for stdin such
that the native objects will be cleaned up, but the underlying
file descriptor will not be closed. The underlying file
descriptor will now only be closed if the stdin stream
subscription is explicitly canceled.

Accessing the stdin getter after the stream is explicitly
canceled will result in a FileSystemException.

See also: https://github.com/dart-lang/test/issues/583

fixes #29229

R=rmacnak@google.com

Review-Url: https://codereview.chromium.org/2791423002 .
2017-04-04 13:57:42 -07:00
Zach Anderson 141b6351ba [dart:io][windows] Use WriteFile instead of _write
This CL changes File::Write on Windows to call directly to WriteFile()
instead of using _write(). This avoids a number of complexities:
1. Don't need to bother with text vs. binary mode.
2. Don't need to check both errno and GetLastError if _write() fails.
3. Don't need to convert to a wchar_t* for console output since we've
   already set the code page to UTF8.

fixes #29101

R=fschneider@google.com

Review-Url: https://codereview.chromium.org/2761673002 .
2017-03-29 13:19:25 -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
Ryan Macnak 781fd36086 Add an option to gen_snapshot for creating a Makefile describing a snapshot's dependencies. This option may be used when generating any snapshot kind, or without generating a snapshot.
- Factor out MallocGrowableArray from vm to platform.
 - Add File::Print.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2715463003 .
2017-02-23 12:40:48 -08:00
Zach Anderson bc07953866 [dart:io][windows] Make unicode characters display correctly.
This change has two pieces.
- Set the console code page to UTF8.
  - This makes strings printed with print() display correctly
- Set the file translation mode to _O_WTEXT when writing to a
  stdout or stderr that is connected to a console.
  - This makes strings printed with e.g. stdout.writeln()
    display correctly.

fixes #28571

R=asiva@google.com, fschneider@google.com

Review-Url: https://codereview.chromium.org/2698813002 .
2017-02-21 22:47:03 -08:00
Ryan Macnak a317b90d63 Cleanup app snapshots on isolate/vm exit.
R=zra@google.com

Review-Url: https://codereview.chromium.org/2694103004 .
2017-02-16 13:54:57 -08:00
Zachary Anderson 3f5458cdcb [dart:io] Adds functions to set file access and modification time
fixes #27877

R=asiva@google.com, floitsch@google.com

Review-Url: https://codereview.chromium.org/2681683005 .
2017-02-09 09:45:25 -08:00
Zachary Anderson 5e2898887b Standardize errno's from a few dart:io File and Link calls
No new tests because I'm just returning more sensical errors in cases
that were already errors.

Not touching Windows. It's doing its own thing.

fixes #28201, #28202, #28204

R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2612653003 .
2017-01-04 13:09:07 -08:00
Zachary Anderson 1f6c914d67 Signal an error for File.lastModified on a directory
fixes #28173

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2616463004 .
2017-01-04 07:50:35 -08:00
Zachary Anderson 128313ec3c Signal an error for File.length on a directory
fixes #28172

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2615473002 .
2017-01-03 15:06:23 -08:00
Zachary Anderson 2ad9b921be Reland: Make File.create() fail when a directory exists at the same path
related #28170

Review-Url: https://codereview.chromium.org/2594413002 .
2016-12-22 08:12:53 -08:00
Kasper Lund 101552b033 Revert "Make File.create() fail when a directory exists at the same path"
The added test case fails in non-English locales.

This reverts commit f2604a3647.

TBR'ed.

R=zra@google.com
BUG=

Review-Url: https://codereview.chromium.org/2599723002 .
2016-12-22 09:56:45 +01:00
Zach Anderson f2604a3647 Make File.create() fail when a directory exists at the same path
fixes #28170

R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2593913003 .
2016-12-21 15:19:23 -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
Zach Anderson b6ea87c444 [windows] Make most file_win.cc functions use malloc for string conversions.
They have been using Dart_ScopeAllocate(), which makes them impossible
to use outside of a scope.

Also turn on inlining in the GN Debug windows build to match the gyp build
and speed things up a bit.

R=asiva@google.com, rmacnak@google.com

Review URL: https://codereview.chromium.org/2439173002 .
2016-10-21 14:55:37 -07:00
Ryan Macnak 3d00ecdc8f Reapply "Use a single file for app snapshots."
- Don't read script to check for an app snapshot if it is a pipe. Fixes loading source from a pipe.
 - Fix windows and fushsia builds.

R=asiva@google.com

Review URL: https://codereview.chromium.org/2416973003 .
2016-10-14 09:57:54 -07:00
Ryan Macnak 6839a23240 Revert "Use a single file for app snapshots."
This reverts commit 4f8b16df3b.

Review URL: https://codereview.chromium.org/2410303008 .
2016-10-13 15:29:23 -07:00
Ryan Macnak 4f8b16df3b Use a single file for app snapshots.
For blobs, put all four pieces into a single file with a header describing their offsets.
For dynamic libraries, move the vm isolate and isolate pieces into the dynamic library as additional read-only sections.

Automatically detect if the script argument is an app snapshot and initialize the VM appropriately, similar to automatic detection of script snapshots.

R=asiva@google.com

Review URL: https://codereview.chromium.org/2405393002 .
2016-10-13 14:33:56 -07:00
Florian Loitsch 873c6e4688 Don't close stdio/stderr when shutting down.
Fixes #26872.

BUG= http://dartbug.com/26872
R=sgjesse@google.com

Review URL: https://codereview.chromium.org/2204953002 .
2016-08-03 15:30:30 +02:00
Zachary Anderson 678cb048ed Adds blocking file locks.
Fixes #26665

R=sgjesse@google.com

Review URL: https://codereview.chromium.org/2050413002 .
2016-06-13 07:58:09 -07:00
Ryan Macnak f262fad639 Option to output precompiled instructions as a blob for use with mmap instead of assembly for use in a shared library.
BUG=http://dartbug.com/26199
R=fschneider@google.com

Review URL: https://codereview.chromium.org/1915853004 .
2016-04-25 16:19:34 -07:00
Zachary Anderson 218545ba10 Fixes leak of native File objects.
Also employs the same reference counting technique as secure sockets to
avoid the IO Service touching dangling pointers.

R=iposva@google.com

Review URL: https://codereview.chromium.org/1892623002 .
2016-04-20 10:08:37 -07:00
Zachary Anderson 8caa5a6dcb Allow opening a named pipe on MacOS and Linux.
fixes #26237

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/1883293005 .
2016-04-15 11:19:37 -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
Søren Gjesse eaeecf2ed1 Add file modes for opening a file write only
Added two new file modes WRITE_ONLY and WRITE_ONLY_APPEND. The current
file modes WRITE and WRITE_APPEND are kept as the read/write mode with
no change. Kept the same overall handling of create/truncate/append
semantics for the new file modes.

R=ager@google.com, ahe@google.com
BUG=

Review URL: https://codereview.chromium.org//1193653002.
2015-06-18 15:19:26 +02:00
sgjesse@google.com 3f939748cb Fix issue with Link.target and Link.targetSync failing on some file systems
Don't rely on information from lstat64 for the size of the link target. Get
the actual length from just reading the link target.

BUG=http://dartbug.com/21987
R=kustermann@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43066 260f80e4-7a28-3924-810f-c04153c831b5
2015-01-22 10:27:11 +00:00
sgjesse@google.com 218e366f89 Add support for file locking
This adds support for file locking in dart:io.

BUG=http://dartbug.com/17045
R=kustermann@google.com, lrn@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42733 260f80e4-7a28-3924-810f-c04153c831b5
2015-01-09 13:06:37 +00:00
sgjesse@google.com b90c405572 Remove the assumption that stat64 and lstat64 cannot return EINTR on Linux
BUG=http://dartbug.com/21080
R=ajohnsen@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@40671 260f80e4-7a28-3924-810f-c04153c831b5
2014-09-25 07:06:06 +00:00
ajohnsen@google.com 7aed60d005 Show actualy FD for files in Observatory.
BUG=
R=johnmccutchan@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@36656 260f80e4-7a28-3924-810f-c04153c831b5
2014-05-27 09:18:43 +00:00
ajohnsen@google.com 3265fb5d09 Make FileStat have millisecond precisions, for linux, mac and android.
BUG=https://code.google.com/p/dart/issues/detail?id=18442
R=sgjesse@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@35520 260f80e4-7a28-3924-810f-c04153c831b5
2014-04-29 11:38:50 +00:00
ajohnsen@google.com 82f487f92f Fix File:copy FD leak, and add file-closes to some tests.
BUG=
R=sgjesse@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@34961 260f80e4-7a28-3924-810f-c04153c831b5
2014-04-11 07:48:49 +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 0f52be7f63 Make std* blocking file-descriptors.
This will most likely be a performance regression when piping, that
we'll have to look into in the future (copying data through
    message-passing).

BUG=
R=sgjesse@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32715 260f80e4-7a28-3924-810f-c04153c831b5
2014-02-17 10:06:35 +00:00
iposva@google.com 781f737c6a First round of http://dartbug.com/15922:
- Address warnings about 64-bit to 32-bit conversions.
- Remove heap profiler.

R=asiva@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31867 260f80e4-7a28-3924-810f-c04153c831b5
2014-01-16 05:05:35 +00:00
johnmccutchan@google.com 919dc2d6eb * Introduce ThreadInterrupter which calls a TLS set callback when thread is interrupted.
* Threads can only register and unregister themselves with ThreadInterrupter.
* Profiler is no longer involved in interrupting threads. It's just a callback and the buffer.
* Profiler operates lock free using an atomic operation to reserve sample in sample buffer.
* Linux, Mac, and Windows done.

R=asiva@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31170 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-16 18:52:15 +00:00
ajohnsen@google.com d5bfdcf52f Nit fix: 1024 -> KB.
BUG=

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31156 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-16 10:38:12 +00:00
ajohnsen@google.com 33560b188f Add comment to File copy on linux/android.
BUG=
R=sgjesse@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31155 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-16 09:12:48 +00:00
ajohnsen@google.com 0b2c1db64a Add fallback-implementation for sendfile on linux and android.
BUG=

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31134 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-13 14:18:11 +00:00
ajohnsen@google.com 9095324cf6 Fix 64-bit linux build after file-copy change.
BUG=

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31129 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-13 12:42:14 +00:00
ajohnsen@google.com fe6b63d5e4 Add File.copy(Sync) to dart:io.
BUG=
R=sgjesse@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@31125 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-13 12:04:24 +00:00
ajohnsen@google.com 7fef1ff77a Add support for working with large files on unix systems, in dart:io.
BUG=
R=sgjesse@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30399 260f80e4-7a28-3924-810f-c04153c831b5
2013-11-19 11:38:20 +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
cbracken@google.com 43fae66ebf Fixes to get Dart VM compiling on Ubuntu 13.04, Debian Wheezy.
* Convince gcc 4.7.x that len is initialized before use in callers of ReadFileFully()
* Cast RawObject* to intptr_t to avoid strict-aliasing error on gcc 4.7.x
* Replace two calls to strerror_r() with strerror() on Linux. When _GNU_SOURCE is
  defined to be non-zero (as it is on Dart Linux builds), strerror_r() is
  defined to return a char*, which is the correct error string to use. When
  _GNU_SOURCE is zero, the XSI-compliant definition is used and the error
  message is returned in the char* param. Surrounding error logging uses
  strerror() which solves the problem.
* Replace int literals with char literals in test string definition.
* co19 math/tan_A01_t01 passes on Ubuntu 13.04.

Original issues:
https://code.google.com/p/dart/issues/detail?id=12085
https://code.google.com/p/dart/issues/detail?id=8807

BUG=
R=asiva@google.com

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

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@25890 260f80e4-7a28-3924-810f-c04153c831b5
2013-08-07 17:28:04 +00:00