Skip to content

Commit 8ff75be

Browse files
[fuchsia] Use the system loader instead of Dart_LoadELF_Fd. (flutter#169534)
Native crash reporting and debugging will work better when they know about the library. This removes the only user of Dart_LoadELF_Fd.
1 parent 5f7f3d0 commit 8ff75be

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

engine/src/flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.cc

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,47 @@ bool ElfSnapshot::Load(fdio_ns_t* namespc, const std::string& path) {
134134
}
135135

136136
bool ElfSnapshot::Load(int dirfd, const std::string& path) {
137-
const int fd = OpenFdExec(path, dirfd);
138-
if (fd < 0) {
137+
fml::UniqueFD fd(OpenFdExec(path, dirfd));
138+
if (!fd.is_valid()) {
139139
FML_LOG(ERROR) << "Failed to open VMO for " << path << " from dir.";
140140
return false;
141141
}
142142
return Load(fd);
143143
}
144144

145-
bool ElfSnapshot::Load(int fd) {
146-
const char* error;
147-
handle_ = Dart_LoadELF_Fd(fd, 0, &error, &vm_data_, &vm_instrs_,
148-
&isolate_data_, &isolate_instrs_);
145+
bool ElfSnapshot::Load(const fml::UniqueFD& fd) {
146+
zx_handle_t vmo = ZX_HANDLE_INVALID;
147+
zx_status_t status = fdio_get_vmo_exec(fd.get(), &vmo);
148+
if (status != ZX_OK) {
149+
FML_LOG(ERROR) << "Failed load ELF: " << zx_status_get_string(status);
150+
return false;
151+
}
152+
handle_ = dlopen_vmo(vmo, RTLD_LAZY);
149153
if (handle_ == nullptr) {
154+
const char* error = dlerror();
150155
FML_LOG(ERROR) << "Failed load ELF: " << error;
151156
return false;
152157
}
158+
159+
vm_data_ =
160+
reinterpret_cast<const uint8_t*>(dlsym(handle_, kVmSnapshotDataCSymbol));
161+
vm_instrs_ = reinterpret_cast<const uint8_t*>(
162+
dlsym(handle_, kVmSnapshotInstructionsCSymbol));
163+
isolate_data_ = reinterpret_cast<const uint8_t*>(
164+
dlsym(handle_, kIsolateSnapshotDataCSymbol));
165+
isolate_instrs_ = reinterpret_cast<const uint8_t*>(
166+
dlsym(handle_, kIsolateSnapshotInstructionsCSymbol));
167+
if (vm_data_ == nullptr || vm_instrs_ == nullptr ||
168+
isolate_data_ == nullptr || isolate_instrs_ == nullptr) {
169+
FML_LOG(ERROR) << "Failed to load ELF symbols";
170+
return false;
171+
}
172+
153173
return true;
154174
}
155175

156176
ElfSnapshot::~ElfSnapshot() {
157-
Dart_UnloadELF(handle_);
177+
dlclose(handle_);
158178
}
159179

160180
} // namespace dart_utils

engine/src/flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <fuchsia/mem/cpp/fidl.h>
99
#include <lib/fdio/namespace.h>
1010

11-
#include "third_party/dart/runtime/bin/elf_loader.h"
11+
#include "flutter/fml/unique_fd.h"
1212

1313
namespace dart_utils {
1414

@@ -33,9 +33,9 @@ class ElfSnapshot {
3333
const uint8_t* IsolateInstrs() const { return isolate_instrs_; }
3434

3535
private:
36-
bool Load(int fd);
36+
bool Load(const fml::UniqueFD& fd);
3737

38-
Dart_LoadedElf* handle_ = nullptr;
38+
void* handle_ = nullptr;
3939

4040
const uint8_t* vm_data_ = nullptr;
4141
const uint8_t* vm_instrs_ = nullptr;

0 commit comments

Comments
 (0)