1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! AOT runtime hook.
//!
//! fusevm's AOT model embeds the bincode-serialized `Chunk` in the object and,
//! at load, deserializes it and runs it on a `VM` (`fusevm_aot_run_embedded`).
//! Before running, fusevm calls back into the frontend via the C symbol
//! `fusevm_aot_register_builtins` to install the frontend's subrs and extension
//! handlers. A standalone elisp binary = the AOT object + the elisprs runtime
//! (this hook) + a `main` that calls `fusevm::aot::fusevm_aot_run_embedded()`.
//!
//! NOTE (the elisp-specific catch): elisp chunk constants are `Value::Obj`
//! handles into the ElispHost heap, so they only mean anything if the heap they
//! index is rebuilt first. `elisp --aot` therefore exports the whole arena as a
//! `SerObj` image and parks it in `chunk.names` behind [`crate::host::HEAP_IMAGE_TAG`];
//! the hook below re-imports it before the chunk runs, in arena order, so every
//! handle lands on the object it had at compile time. A user program's interned
//! symbols, quoted data, vectors, records, hash tables, char-tables, bignums and
//! closures all come back this way — they are *not* limited to what the prelude
//! happens to rebuild.
//!
//! The image is the whole contract, so anything it drops is a silent wrong
//! answer rather than an error. Two things it still drops, both deliberate:
//! `Obj::Buffer` / `Obj::Marker` / `Obj::Obarray` become placeholder symbols
//! (they are live runtime state, and the slot exists only to keep arena indices
//! aligned), and a subr is re-created by `install` rather than carried. Closure
//! *source* used to be dropped too — see `SerObj::Closure::arglist`.
use VM;
/// Turn the AOT run's raw exit code into the process exit code, reporting any
/// uncaught elisp error first. `main` (emitted by [`crate::aot`]) pipes
/// `fusevm_aot_run_embedded()`'s return value through here.
///
/// This exists because an elisp error never reaches fusevm's `VMResult`.
/// `host::abort` parks the message in the thread-local host error slot and winds
/// `vm.ip` past the last op, so the VM terminates *normally* and fusevm's AOT
/// driver sees `VMResult::Halted` and returns 0. The interpreted driver reads
/// that slot right after `vm.run()` (`host::run_chunk`); the AOT driver lives in
/// fusevm and cannot. The result, before this hook: EVERY uncaught elisp error
/// in a standalone AOT binary exited 0 with nothing on stdout or stderr —
/// byte-identical to a successful run of a program that prints nothing. A
/// `(error "boom")` binary and a `(princ "")` binary were indistinguishable.
///
/// The message and exit status match the interpreted driver's (`main.rs`:
/// `eprintln!("error: {}", format_error(&e))` + `ExitCode::FAILURE`) so the two
/// execution paths report an identical failure.
///
/// Kept separate from `main` (rather than wrapping `fusevm_aot_run_embedded`
/// in Rust) so this function references no AOT-object-only symbols: it is
/// compiled into the plain `elisprs` rlib too, and pulling in
/// `fusevm_aot_chunk_blob` would leave the ordinary `elisp` binary with
/// undefined symbols at link time.
pub extern "C"
/// Register the elisp subrs + extension handlers on the AOT VM. Required link
/// symbol for a standalone elisp AOT binary.
///
/// # Safety
/// `vm` must be a valid, exclusively-borrowable pointer (fusevm's AOT entry
/// passes one).
pub unsafe extern "C"