1 | // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef RUNTIME_BIN_ELF_LOADER_H_ |
6 | #define RUNTIME_BIN_ELF_LOADER_H_ |
7 | |
8 | #include "../include/dart_api.h" |
9 | |
10 | typedef struct { |
11 | } Dart_LoadedElf; |
12 | |
13 | /// Load an ELF object from a file. |
14 | /// |
15 | /// On success, return a handle to the library which may be used to close it |
16 | /// in Dart_UnloadELF. On error, returns 'nullptr' and sets 'error'. The error |
17 | /// string should not be 'free'-d. |
18 | /// |
19 | /// `file_offset` may be non-zero to read an ELF object embedded inside another |
20 | /// type of file. |
21 | /// |
22 | /// Look up the Dart snapshot symbols "_kVmSnapshotData", |
23 | /// "_kVmSnapshotInstructions", "_kVmIsolateData" and "_kVmIsolateInstructions" |
24 | /// into the respectively named out-parameters. |
25 | /// |
26 | /// Dart_LoadELF_Fd takes ownership of the file descriptor. Dart_LoadELF_Memory |
27 | /// does not take ownership of the memory, but borrows it for the duration of |
28 | /// the call. The memory can be release as soon as Dart_LoadELF_Memory returns. |
29 | #if defined(__Fuchsia__) || defined(__linux__) || defined(__FreeBSD__) |
30 | DART_EXPORT Dart_LoadedElf* Dart_LoadELF_Fd(int fd, |
31 | uint64_t file_offset, |
32 | const char** error, |
33 | const uint8_t** vm_snapshot_data, |
34 | const uint8_t** vm_snapshot_instrs, |
35 | const uint8_t** vm_isolate_data, |
36 | const uint8_t** vm_isolate_instrs); |
37 | #endif |
38 | |
39 | #if !defined(__Fuchsia__) |
40 | /// Please see documentation for Dart_LoadElf_Fd. |
41 | DART_EXPORT Dart_LoadedElf* Dart_LoadELF(const char* filename, |
42 | uint64_t file_offset, |
43 | const char** error, |
44 | const uint8_t** vm_snapshot_data, |
45 | const uint8_t** vm_snapshot_instrs, |
46 | const uint8_t** vm_isolate_data, |
47 | const uint8_t** vm_isolate_instrs); |
48 | #endif |
49 | |
50 | /// Please see documentation for Dart_LoadElf_Fd. |
51 | DART_EXPORT Dart_LoadedElf* Dart_LoadELF_Memory( |
52 | const uint8_t* snapshot, |
53 | uint64_t snapshot_size, |
54 | const char** error, |
55 | const uint8_t** vm_snapshot_data, |
56 | const uint8_t** vm_snapshot_instrs, |
57 | const uint8_t** vm_isolate_data, |
58 | const uint8_t** vm_isolate_instrs); |
59 | |
60 | /// Unloads an ELF object loaded through Dart_LoadELF{_Fd, _Memory}. |
61 | /// |
62 | /// Unlike dlclose(), this does not use reference counting. |
63 | /// Dart_LoadELF{_Fd, _Memory} will return load the target library separately |
64 | /// each time it is called, and the results must be unloaded separately. |
65 | DART_EXPORT void Dart_UnloadELF(Dart_LoadedElf* loaded); |
66 | |
67 | #endif // RUNTIME_BIN_ELF_LOADER_H_ |
68 | |