@@ -134,27 +134,47 @@ bool ElfSnapshot::Load(fdio_ns_t* namespc, const std::string& path) {
134
134
}
135
135
136
136
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 () ) {
139
139
FML_LOG (ERROR) << " Failed to open VMO for " << path << " from dir." ;
140
140
return false ;
141
141
}
142
142
return Load (fd);
143
143
}
144
144
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);
149
153
if (handle_ == nullptr ) {
154
+ const char * error = dlerror ();
150
155
FML_LOG (ERROR) << " Failed load ELF: " << error;
151
156
return false ;
152
157
}
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
+
153
173
return true ;
154
174
}
155
175
156
176
ElfSnapshot::~ElfSnapshot () {
157
- Dart_UnloadELF (handle_);
177
+ dlclose (handle_);
158
178
}
159
179
160
180
} // namespace dart_utils
0 commit comments