d0295c873c
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 .
129 lines
3.0 KiB
C++
129 lines
3.0 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(HOST_OS_ANDROID)
|
|
|
|
#include "bin/platform.h"
|
|
|
|
#include <signal.h> // NOLINT
|
|
#include <string.h> // NOLINT
|
|
#include <unistd.h> // NOLINT
|
|
|
|
#include "bin/fdutils.h"
|
|
#include "bin/file.h"
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
const char* Platform::executable_name_ = NULL;
|
|
char* Platform::resolved_executable_name_ = NULL;
|
|
int Platform::script_index_ = 1;
|
|
char** Platform::argv_ = NULL;
|
|
|
|
static void segv_handler(int signal, siginfo_t* siginfo, void* context) {
|
|
Dart_DumpNativeStackTrace(context);
|
|
abort();
|
|
}
|
|
|
|
bool Platform::Initialize() {
|
|
// Turn off the signal handler for SIGPIPE as it causes the process
|
|
// to terminate on writing to a closed pipe. Without the signal
|
|
// handler error EPIPE is set instead.
|
|
struct sigaction act;
|
|
bzero(&act, sizeof(act));
|
|
act.sa_handler = SIG_IGN;
|
|
if (sigaction(SIGPIPE, &act, 0) != 0) {
|
|
perror("Setting signal handler failed");
|
|
return false;
|
|
}
|
|
|
|
act.sa_flags = SA_SIGINFO;
|
|
act.sa_sigaction = &segv_handler;
|
|
if (sigemptyset(&act.sa_mask) != 0) {
|
|
perror("sigemptyset() failed.");
|
|
return false;
|
|
}
|
|
if (sigaddset(&act.sa_mask, SIGPROF) != 0) {
|
|
perror("sigaddset() failed");
|
|
return false;
|
|
}
|
|
if (sigaction(SIGSEGV, &act, NULL) != 0) {
|
|
perror("sigaction() failed.");
|
|
return false;
|
|
}
|
|
if (sigaction(SIGBUS, &act, NULL) != 0) {
|
|
perror("sigaction() failed.");
|
|
return false;
|
|
}
|
|
if (sigaction(SIGTRAP, &act, NULL) != 0) {
|
|
perror("sigaction() failed.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
int Platform::NumberOfProcessors() {
|
|
return sysconf(_SC_NPROCESSORS_ONLN);
|
|
}
|
|
|
|
const char* Platform::OperatingSystem() {
|
|
return "android";
|
|
}
|
|
|
|
const char* Platform::LibraryPrefix() {
|
|
return "lib";
|
|
}
|
|
|
|
const char* Platform::LibraryExtension() {
|
|
return "so";
|
|
}
|
|
|
|
const char* Platform::LocaleName() {
|
|
char* lang = getenv("LANG");
|
|
if (lang == NULL) {
|
|
return "en_US";
|
|
}
|
|
return lang;
|
|
}
|
|
|
|
bool Platform::LocalHostname(char* buffer, intptr_t buffer_length) {
|
|
return gethostname(buffer, buffer_length) == 0;
|
|
}
|
|
|
|
char** Platform::Environment(intptr_t* count) {
|
|
// Using environ directly is only safe as long as we do not
|
|
// provide access to modifying environment variables.
|
|
intptr_t i = 0;
|
|
char** tmp = environ;
|
|
while (*(tmp++) != NULL) {
|
|
i++;
|
|
}
|
|
*count = i;
|
|
char** result;
|
|
result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result)));
|
|
for (intptr_t current = 0; current < i; current++) {
|
|
result[current] = environ[current];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const char* Platform::GetExecutableName() {
|
|
return executable_name_;
|
|
}
|
|
|
|
const char* Platform::ResolveExecutablePath() {
|
|
return File::ReadLink("/proc/self/exe");
|
|
}
|
|
|
|
void Platform::Exit(int exit_code) {
|
|
exit(exit_code);
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(HOST_OS_ANDROID)
|