mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:44:27 +00:00
Revert "[ VM ] Update embedding API to perform Platform initialization"
This reverts commit 729099cc5b
.
Reason for revert: Causing crashes in google3 after roll (b/270314587).
Original change's description:
> [ VM ] Update embedding API to perform Platform initialization
>
> 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>
TBR=bkonyi@google.com,zra@google.com,kpozin@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I23253631e13d703e9e5384f9ec4ff6b79ef4ef21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118643
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
parent
eb4aaa1b13
commit
103d54b304
14 changed files with 35 additions and 56 deletions
|
@ -7,7 +7,6 @@
|
|||
#include "bin/dartutils.h"
|
||||
#include "bin/eventhandler.h"
|
||||
#include "bin/isolate_data.h"
|
||||
#include "bin/platform.h"
|
||||
#include "bin/thread.h"
|
||||
#include "bin/utils.h"
|
||||
#include "bin/vmservice_impl.h"
|
||||
|
@ -15,7 +14,7 @@
|
|||
namespace dart {
|
||||
namespace embedder {
|
||||
|
||||
static char* MallocFormattedString(const char* format, ...) {
|
||||
static char* MallocFormatedString(const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
intptr_t len = vsnprintf(NULL, 0, format, args);
|
||||
|
@ -33,14 +32,8 @@ static char* MallocFormattedString(const char* format, ...) {
|
|||
bool InitOnce(char** error) {
|
||||
if (!bin::DartUtils::SetOriginalWorkingDirectory()) {
|
||||
bin::OSError err;
|
||||
*error = MallocFormattedString("Error determining current directory: %s\n",
|
||||
err.message());
|
||||
return false;
|
||||
}
|
||||
if (!bin::Platform::InitOnce()) {
|
||||
bin::OSError err;
|
||||
*error = MallocFormattedString("Platform initialization failed: %s\n",
|
||||
err.message());
|
||||
*error = MallocFormatedString("Error determining current directory: %s\n",
|
||||
err.message());
|
||||
return false;
|
||||
}
|
||||
bin::TimerUtils::InitOnce();
|
||||
|
|
|
@ -20,7 +20,6 @@ void BootstrapDartIo() {
|
|||
// Bootstrap 'dart:io' event handler.
|
||||
TimerUtils::InitOnce();
|
||||
EventHandler::Start();
|
||||
Platform::InitOnce();
|
||||
}
|
||||
|
||||
void CleanupDartIo() {
|
||||
|
|
|
@ -853,7 +853,7 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
DartUtils::SetEnvironment(environment);
|
||||
|
||||
if (!Platform::InitOnce()) {
|
||||
if (!Platform::Initialize()) {
|
||||
Syslog::PrintErr("Initialization failed\n");
|
||||
return kErrorExitCode;
|
||||
}
|
||||
|
|
|
@ -879,11 +879,6 @@ static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) {
|
|||
file->Release();
|
||||
}
|
||||
|
||||
static void ShutdownDartIO() {
|
||||
Process::ClearAllSignalHandlers();
|
||||
EventHandler::Stop();
|
||||
}
|
||||
|
||||
bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
|
||||
// Call CreateIsolateGroupAndSetup which creates an isolate and loads up
|
||||
// the specified application script.
|
||||
|
@ -908,7 +903,8 @@ bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) {
|
|||
Syslog::PrintErr("VM cleanup failed: %s\n", error);
|
||||
free(error);
|
||||
}
|
||||
ShutdownDartIO();
|
||||
Process::ClearAllSignalHandlers();
|
||||
EventHandler::Stop();
|
||||
Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode);
|
||||
}
|
||||
main_isolate = isolate;
|
||||
|
@ -1058,13 +1054,9 @@ void main(int argc, char** argv) {
|
|||
bool print_flags_seen = false;
|
||||
bool verbose_debug_seen = false;
|
||||
|
||||
// This call will start the event handler, potentially before all VM state
|
||||
// has been initialized. This shouldn't cause any issues since the thread will
|
||||
// block before doing anything.
|
||||
char* error = nullptr;
|
||||
if (!dart::embedder::InitOnce(&error)) {
|
||||
Syslog::PrintErr("Standalone embedder initialization failed: %s\n", error);
|
||||
free(error);
|
||||
// Perform platform specific initialization.
|
||||
if (!Platform::Initialize()) {
|
||||
Syslog::PrintErr("Initialization failed\n");
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
|
@ -1113,11 +1105,9 @@ void main(int argc, char** argv) {
|
|||
&verbose_debug_seen) < 0) {
|
||||
if (Options::help_option()) {
|
||||
Options::PrintUsage();
|
||||
ShutdownDartIO();
|
||||
Platform::Exit(0);
|
||||
} else if (Options::version_option()) {
|
||||
Options::PrintVersion();
|
||||
ShutdownDartIO();
|
||||
Platform::Exit(0);
|
||||
} else if (print_flags_seen) {
|
||||
// Will set the VM flags, print them out and then we exit as no
|
||||
|
@ -1132,7 +1122,6 @@ void main(int argc, char** argv) {
|
|||
Platform::Exit(0);
|
||||
} else {
|
||||
Options::PrintUsage();
|
||||
ShutdownDartIO();
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
}
|
||||
|
@ -1156,7 +1145,6 @@ void main(int argc, char** argv) {
|
|||
if (shared_blobs == NULL) {
|
||||
Syslog::PrintErr("Failed to load: %s\n",
|
||||
Options::shared_blobs_filename());
|
||||
ShutdownDartIO();
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
const uint8_t* ignored;
|
||||
|
@ -1186,6 +1174,13 @@ void main(int argc, char** argv) {
|
|||
Process::SetExitHook(OnExitHook);
|
||||
}
|
||||
|
||||
char* error = nullptr;
|
||||
if (!dart::embedder::InitOnce(&error)) {
|
||||
Syslog::PrintErr("Standalone embedder initialization failed: %s\n", error);
|
||||
free(error);
|
||||
Platform::Exit(kErrorExitCode);
|
||||
}
|
||||
|
||||
error = Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
|
||||
if (error != NULL) {
|
||||
Syslog::PrintErr("Setting VM flags failed: %s\n", error);
|
||||
|
@ -1259,7 +1254,8 @@ void main(int argc, char** argv) {
|
|||
Syslog::PrintErr("VM cleanup failed: %s\n", error);
|
||||
free(error);
|
||||
}
|
||||
ShutdownDartIO();
|
||||
Process::ClearAllSignalHandlers();
|
||||
EventHandler::Stop();
|
||||
|
||||
delete app_snapshot;
|
||||
delete shared_blobs;
|
||||
|
|
|
@ -13,8 +13,8 @@ namespace bin {
|
|||
|
||||
class Platform {
|
||||
public:
|
||||
// Perform process wide platform specific initialization.
|
||||
static bool InitOnce();
|
||||
// Perform platform specific initialization.
|
||||
static bool Initialize();
|
||||
|
||||
// Returns the number of processors on the machine.
|
||||
static int NumberOfProcessors();
|
||||
|
|
|
@ -37,7 +37,7 @@ static void segv_handler(int signal, siginfo_t* siginfo, void* context) {
|
|||
abort();
|
||||
}
|
||||
|
||||
bool Platform::InitOnce() {
|
||||
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.
|
||||
|
|
|
@ -27,7 +27,7 @@ char* Platform::resolved_executable_name_ = NULL;
|
|||
int Platform::script_index_ = 1;
|
||||
char** Platform::argv_ = NULL;
|
||||
|
||||
bool Platform::InitOnce() {
|
||||
bool Platform::Initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ static void segv_handler(int signal, siginfo_t* siginfo, void* context) {
|
|||
abort();
|
||||
}
|
||||
|
||||
bool Platform::InitOnce() {
|
||||
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.
|
||||
|
|
|
@ -44,7 +44,7 @@ static void segv_handler(int signal, siginfo_t* siginfo, void* context) {
|
|||
abort();
|
||||
}
|
||||
|
||||
bool Platform::InitOnce() {
|
||||
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.
|
||||
|
|
|
@ -103,7 +103,7 @@ class PlatformWin {
|
|||
DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformWin);
|
||||
};
|
||||
|
||||
bool Platform::InitOnce() {
|
||||
bool Platform::Initialize() {
|
||||
PlatformWin::InitOnce();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1024,12 +1024,9 @@ intptr_t Process::SetSignalHandler(intptr_t signal) {
|
|||
}
|
||||
|
||||
void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) {
|
||||
// If the port is illegal there shouldn't be a current isolate and we should
|
||||
// clear all signal handlers. Otherwise, if the port is legal there should be
|
||||
// a current isolate and we should only clear signals for handlers for that
|
||||
// isolate.
|
||||
ASSERT(((port != ILLEGAL_PORT) && (Dart_CurrentIsolate() != NULL)) ||
|
||||
((port == ILLEGAL_PORT) && (Dart_CurrentIsolate() == NULL)));
|
||||
// Either the port is illegal or there is no current isolate, but not both.
|
||||
ASSERT((port != ILLEGAL_PORT) || (Dart_CurrentIsolate() == NULL));
|
||||
ASSERT((port == ILLEGAL_PORT) || (Dart_CurrentIsolate() != NULL));
|
||||
ThreadSignalBlocker blocker(kSignalsCount, kSignals);
|
||||
MutexLocker lock(signal_mutex);
|
||||
SignalInfo* handler = signal_handlers;
|
||||
|
|
|
@ -1020,12 +1020,9 @@ intptr_t Process::SetSignalHandler(intptr_t signal) {
|
|||
}
|
||||
|
||||
void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) {
|
||||
// If the port is illegal there shouldn't be a current isolate and we should
|
||||
// clear all signal handlers. Otherwise, if the port is legal there should be
|
||||
// a current isolate and we should only clear signals for handlers for that
|
||||
// isolate.
|
||||
ASSERT(((port != ILLEGAL_PORT) && (Dart_CurrentIsolate() != NULL)) ||
|
||||
((port == ILLEGAL_PORT) && (Dart_CurrentIsolate() == NULL)));
|
||||
// Either the port is illegal or there is no current isolate, but not both.
|
||||
ASSERT((port != ILLEGAL_PORT) || (Dart_CurrentIsolate() == NULL));
|
||||
ASSERT((port == ILLEGAL_PORT) || (Dart_CurrentIsolate() != NULL));
|
||||
ThreadSignalBlocker blocker(kSignalsCount, kSignals);
|
||||
MutexLocker lock(signal_mutex);
|
||||
SignalInfo* handler = signal_handlers;
|
||||
|
|
|
@ -1052,12 +1052,9 @@ intptr_t Process::SetSignalHandler(intptr_t signal) {
|
|||
}
|
||||
|
||||
void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) {
|
||||
// If the port is illegal there shouldn't be a current isolate and we should
|
||||
// clear all signal handlers. Otherwise, if the port is legal there should be
|
||||
// a current isolate and we should only clear signals for handlers for that
|
||||
// isolate.
|
||||
ASSERT(((port != ILLEGAL_PORT) && (Dart_CurrentIsolate() != NULL)) ||
|
||||
((port == ILLEGAL_PORT) && (Dart_CurrentIsolate() == NULL)));
|
||||
// Either the port is illegal or there is no current isolate, but not both.
|
||||
ASSERT((port != ILLEGAL_PORT) || (Dart_CurrentIsolate() == NULL));
|
||||
ASSERT((port == ILLEGAL_PORT) || (Dart_CurrentIsolate() != NULL));
|
||||
signal = SignalMap(signal);
|
||||
if (signal == -1) {
|
||||
return;
|
||||
|
|
|
@ -293,7 +293,7 @@ static int Main(int argc, const char** argv) {
|
|||
const char** dart_argv = nullptr;
|
||||
|
||||
// Perform platform specific initialization.
|
||||
if (!dart::bin::Platform::InitOnce()) {
|
||||
if (!dart::bin::Platform::Initialize()) {
|
||||
Syslog::PrintErr("Initialization failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue