[vm, ffi] Emit the FFI callback stub as a raw blob and place it in the Fuchsia package.
Any blob in the package can be loaded as an executable VMO. TEST=child CL Bug: https://dartbug.com/52579 Change-Id: I61f7a84453da4da4733c5a70d4d19f0a6652581b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496661 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Alexander Aprelev <aam@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
877ded1a38
commit
e860a9b0fa
@@ -650,6 +650,20 @@ gen_snapshot_action("generate_snapshot_bin") {
|
||||
]
|
||||
}
|
||||
|
||||
gen_snapshot_action("ffi_callback_stub_bin") {
|
||||
deps = [ "../vm:vm_platform_stripped" ]
|
||||
platform_dill = "$root_out_dir/vm_platform_stripped.dill"
|
||||
inputs = [ platform_dill ]
|
||||
outputs = [ "$target_gen_dir/ffi_callback_stub.bin" ]
|
||||
args = [
|
||||
"--deterministic",
|
||||
"--snapshot_kind=ffi-callback-stub",
|
||||
"--ffi_callback_stub=" +
|
||||
rebase_path("$target_gen_dir/ffi_callback_stub.bin", root_build_dir),
|
||||
rebase_path(platform_dill, root_build_dir),
|
||||
]
|
||||
}
|
||||
|
||||
# Generates an assembly file defining a given symbol with the bytes from a
|
||||
# binary file. Places the symbol in a text section if 'executable' is true,
|
||||
# otherwise places the symbol in a read-only data section.
|
||||
|
||||
@@ -459,6 +459,8 @@ typedef Dart_Handle (*Dart_CreateAppAOTSnapshotAndRelocatableObjectType)(
|
||||
typedef Dart_Handle (*Dart_CreateVMAOTSnapshotAsAssemblyType)(
|
||||
Dart_StreamingWriteCallback,
|
||||
void*);
|
||||
typedef Dart_Handle (*Dart_WriteCallbackStubType)(Dart_StreamingWriteCallback,
|
||||
void*);
|
||||
typedef Dart_Handle (*Dart_SortClassesType)();
|
||||
typedef Dart_Handle (*Dart_CreateAppJITSnapshotAsBlobsType)(uint8_t**,
|
||||
intptr_t*,
|
||||
@@ -772,6 +774,7 @@ static Dart_CreateAppAOTSnapshotAndRelocatableObjectType
|
||||
Dart_CreateAppAOTSnapshotAndRelocatableObjectFn = NULL;
|
||||
static Dart_CreateVMAOTSnapshotAsAssemblyType
|
||||
Dart_CreateVMAOTSnapshotAsAssemblyFn = NULL;
|
||||
static Dart_WriteCallbackStubType Dart_WriteCallbackStubFn = NULL;
|
||||
static Dart_SortClassesType Dart_SortClassesFn = NULL;
|
||||
static Dart_CreateAppJITSnapshotAsBlobsType Dart_CreateAppJITSnapshotAsBlobsFn =
|
||||
NULL;
|
||||
@@ -1368,6 +1371,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
Dart_CreateVMAOTSnapshotAsAssemblyFn =
|
||||
(Dart_CreateVMAOTSnapshotAsAssemblyType)GetProcAddress(
|
||||
process, "Dart_CreateVMAOTSnapshotAsAssembly");
|
||||
Dart_WriteCallbackStubFn = (Dart_WriteCallbackStubType)GetProcAddress(
|
||||
process, "Dart_WriteCallbackStub");
|
||||
Dart_SortClassesFn =
|
||||
(Dart_SortClassesType)GetProcAddress(process, "Dart_SortClasses");
|
||||
Dart_CreateAppJITSnapshotAsBlobsFn =
|
||||
@@ -2701,6 +2706,11 @@ Dart_Handle Dart_CreateVMAOTSnapshotAsAssembly(
|
||||
return Dart_CreateVMAOTSnapshotAsAssemblyFn(callback, callback_data);
|
||||
}
|
||||
|
||||
Dart_Handle Dart_WriteCallbackStub(Dart_StreamingWriteCallback callback,
|
||||
void* callback_data) {
|
||||
return Dart_WriteCallbackStubFn(callback, callback_data);
|
||||
}
|
||||
|
||||
Dart_Handle Dart_SortClasses() {
|
||||
return Dart_SortClassesFn();
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ enum SnapshotKind {
|
||||
kAppAOTElf,
|
||||
kAppAOTMachODylib,
|
||||
kVMAOTAssembly,
|
||||
kFfiCallbackStub,
|
||||
};
|
||||
static SnapshotKind snapshot_kind = kCore;
|
||||
|
||||
@@ -93,6 +94,7 @@ static const char* const kSnapshotKindNames[] = {
|
||||
"app-aot-elf",
|
||||
"app-aot-macho-dylib",
|
||||
"vm-aot-assembly",
|
||||
"ffi-callback-stub",
|
||||
nullptr,
|
||||
// clang-format on
|
||||
};
|
||||
@@ -114,7 +116,8 @@ static const char* const kSnapshotKindNames[] = {
|
||||
V(macho_object, macho_object_filename) \
|
||||
V(loading_unit_manifest, loading_unit_manifest_filename) \
|
||||
V(save_debugging_info, debugging_info_filename) \
|
||||
V(save_obfuscation_map, obfuscation_map_filename)
|
||||
V(save_obfuscation_map, obfuscation_map_filename) \
|
||||
V(ffi_callback_stub, ffi_callback_stub_filename)
|
||||
|
||||
#define BOOL_OPTIONS_LIST(V) \
|
||||
V(compile_all, compile_all) \
|
||||
@@ -142,7 +145,8 @@ DEFINE_CB_OPTION(ProcessEnvironmentOption);
|
||||
static bool IsSnapshottingForPrecompilation() {
|
||||
return (snapshot_kind == kAppAOTAssembly) || (snapshot_kind == kAppAOTElf) ||
|
||||
(snapshot_kind == kAppAOTMachODylib) ||
|
||||
(snapshot_kind == kVMAOTAssembly);
|
||||
(snapshot_kind == kVMAOTAssembly) ||
|
||||
(snapshot_kind == kFfiCallbackStub);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
@@ -308,6 +312,14 @@ static int ParseArguments(int argc,
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case kFfiCallbackStub:
|
||||
if (ffi_callback_stub_filename == nullptr) {
|
||||
Syslog::PrintErr(
|
||||
"Building the FFI callback stub blob requires specifying "
|
||||
"an output file for --ffi_callback_stub.\n\n");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!obfuscate && obfuscation_map_filename != nullptr) {
|
||||
@@ -637,6 +649,13 @@ static void CreateAndWritePrecompiledSnapshot() {
|
||||
CHECK_RESULT(result);
|
||||
return;
|
||||
}
|
||||
if (snapshot_kind == kFfiCallbackStub) {
|
||||
File* file = OpenFile(ffi_callback_stub_filename);
|
||||
RefCntReleaseScope<File> rs(file);
|
||||
Dart_Handle result = Dart_WriteCallbackStub(StreamingWriteCallback, file);
|
||||
CHECK_RESULT(result);
|
||||
return;
|
||||
}
|
||||
|
||||
Dart_AotBinaryFormat format;
|
||||
const char* kind_str = nullptr;
|
||||
@@ -834,6 +853,7 @@ static int CreateIsolateAndSnapshot(const CommandLineOptions& inputs) {
|
||||
case kAppAOTElf:
|
||||
case kAppAOTMachODylib:
|
||||
case kVMAOTAssembly:
|
||||
case kFfiCallbackStub:
|
||||
CreateAndWritePrecompiledSnapshot();
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user