Files
sdk/runtime/bin/dart_embedder_api_impl.cc
T
Ben Konyi 103d54b304 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>
2019-09-24 20:43:20 +00:00

105 lines
3.4 KiB
C++

// Copyright (c) 2018, 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 "include/dart_embedder_api.h"
#include "bin/dartutils.h"
#include "bin/eventhandler.h"
#include "bin/isolate_data.h"
#include "bin/thread.h"
#include "bin/utils.h"
#include "bin/vmservice_impl.h"
namespace dart {
namespace embedder {
static char* MallocFormatedString(const char* format, ...) {
va_list args;
va_start(args, format);
intptr_t len = vsnprintf(NULL, 0, format, args);
va_end(args);
char* buffer = reinterpret_cast<char*>(malloc(len + 1));
MSAN_UNPOISON(buffer, (len + 1));
va_list args2;
va_start(args2, format);
vsnprintf(buffer, (len + 1), format, args2);
va_end(args2);
return buffer;
}
bool InitOnce(char** error) {
if (!bin::DartUtils::SetOriginalWorkingDirectory()) {
bin::OSError err;
*error = MallocFormatedString("Error determining current directory: %s\n",
err.message());
return false;
}
bin::TimerUtils::InitOnce();
bin::EventHandler::Start();
return true;
}
Dart_Isolate CreateKernelServiceIsolate(const IsolateCreationData& data,
const uint8_t* buffer,
intptr_t buffer_size,
char** error) {
Dart_Isolate kernel_isolate = Dart_CreateIsolateGroupFromKernel(
data.script_uri, data.main, buffer, buffer_size, data.flags,
data.isolate_group_data, data.isolate_data, error);
if (kernel_isolate == nullptr) {
return nullptr;
}
Dart_EnterScope();
Dart_Handle result = Dart_LoadScriptFromKernel(buffer, buffer_size);
if (Dart_IsError(result)) {
*error = strdup(Dart_GetError(result));
Dart_ExitScope();
Dart_ShutdownIsolate();
return nullptr;
}
result = bin::DartUtils::PrepareForScriptLoading(/*is_service_isolate=*/false,
/*trace_loading=*/false);
Dart_ExitScope();
Dart_ExitIsolate();
return kernel_isolate;
}
Dart_Isolate CreateVmServiceIsolate(const IsolateCreationData& data,
const VmServiceConfiguration& config,
const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size,
char** error) {
if (data.flags == nullptr) {
*error = strdup("Expected non-null flags");
return nullptr;
}
data.flags->load_vmservice_library = true;
Dart_Isolate service_isolate = Dart_CreateIsolateGroupFromKernel(
data.script_uri, data.main, kernel_buffer, kernel_buffer_size, data.flags,
data.isolate_group_data, data.isolate_data, error);
if (service_isolate == nullptr) {
return nullptr;
}
Dart_EnterScope();
// Load embedder specific bits and return.
if (!bin::VmService::Setup(config.ip, config.port, config.dev_mode,
config.disable_auth_codes,
config.write_service_info_filename,
/*trace_loading=*/false, config.deterministic)) {
*error = strdup(bin::VmService::GetErrorMessage());
return nullptr;
}
Dart_ExitScope();
Dart_ExitIsolate();
return service_isolate;
}
} // namespace embedder
} // namespace dart