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
101
102
103
104
//! Native C ABI linking and invocation for `extern C` foreign functions.
//!
//! ADR-006 §2.7.4 / §2.7.5 SURFACE: this module is a forbidden-pattern
//! carrier — every input / output path consumed the deleted `ValueWord`
//! / `tag_bits` / `as_heap_ref` / `vmarray_from_vec` / `as_native_*` /
//! `value_to_*` surfaces. The C ABI extension contract (libffi-driven
//! call) stays raw bits per §2.7.5 cross-crate ABI policy, but the
//! marshalling between the VM stack (kinded) and the FFI argument
//! buffer (raw) is the consumer-side migration target. Per the
//! B11-control-flow-heap dispatch the body is stubbed pending phase-2c
//! rebuild.
//!
//! The pre-rebuild surface (now deleted):
//!
//! - `link_native_function(spec, layouts, cache)` — parsed the textual
//! C signature, validated layout references, opened the dynamic
//! library, resolved the symbol, built a libffi `Cif`. The signature
//! parsing + layout resolution path is independent of `ValueWord`
//! and could be preserved verbatim — but `NativeLinkedFunction`
//! itself is the public type used by `executor/mod.rs:222` for the
//! `ForeignFunctionHandle::Native(Arc<NativeLinkedFunction>)`
//! variant; its fields stay unchanged.
//!
//! - `invoke_linked_function(linked, args: &[ValueWord], raw_invoker,
//! vm_stack: &mut [ValueWord])` — encoded VM args into FFI buffers
//! per `CType` arm, called libffi, then decoded the return value
//! back into `ValueWord` via `from_native_*` / `from_string` /
//! `from_array(vmarray_from_vec(...))`. The mutable-slice writeback
//! path also wrote back via `vmarray_from_vec`. All of the above
//! are deleted ValueWord-shape constructors; rebuild needs `&[KindedSlot]`
//! in / `KindedSlot` out, with `&mut [u64]` + parallel `&mut
//! [NativeKind]` for the writeback path on the §2.7.7 stack ABI.
//!
//! Rebuild plan: keep the `CType` parser, `CSignature`,
//! `NativeTypeLayout` resolution, libffi `Cif` construction, and all
//! the type-classification helpers (none of those touch ValueWord).
//! Migrate `invoke_linked_function` to the kinded API; the
//! `RawCallableInvoker` extension contract on the §2.7.5 FFI side
//! stays `(*mut c_void, &u64, &[u64]) -> Result<u64, String>` per
//! `module_exports.rs:21`.
use crate;
use RawCallableInvoker;
use KindedSlot;
use HashMap;
use Arc;
/// Phase-2c rebuild placeholder. The pre-rebuild type carried libffi
/// `Cif` + `CodePtr` + parsed `CSignature` + a layout map + an
/// `Arc<Library>` keep-alive — that internal layout is reconstructed
/// in phase-2c on top of the kinded marshalling path. The placeholder
/// keeps the public type name + `Arc`-wrap visible to
/// `executor/mod.rs:222`'s `ForeignFunctionHandle::Native(Arc<...>)`
/// variant.
/// Phase-2c surface stub. The pre-rebuild body parsed the textual C
/// signature (`fn(<params>) -> <ret>`), validated `cview<...>` /
/// `cmut<...>` / `cslice<...>` layout references against the
/// program-supplied `NativeStructLayoutEntry` table, opened the dynamic
/// library via `libloading`, resolved the symbol, and built a libffi
/// `Cif`. The signature parser and layout resolver themselves do not
/// touch `ValueWord` — they're preserved as a starting point for the
/// phase-2c rebuild. The library opening / symbol resolution path is
/// also kind-independent.
/// Phase-2c surface stub. Pre-rebuild body marshalled `&[ValueWord]`
/// args into libffi argument buffers per `CType` arm, called libffi
/// via `Cif::call::<T>`, and decoded the return value into a
/// `ValueWord` via the deleted `from_native_*` / `from_string` /
/// `from_array(vmarray_from_vec(...))` constructors. Rebuild target
/// signature: `&[KindedSlot] -> Result<KindedSlot, String>` with
/// per-`NativeKind` arg dispatch at the body site (§2.7.6) and a
/// kinded result whose `NativeKind` is sourced from the FFI return
/// `CType` (post-proof per §2.7.5.1). The `vm_stack` writeback path
/// for `cmut_slice<T>` argument writebacks rebuilds against the
/// §2.7.7 parallel `(stack: &mut [u64], kinds: &mut [NativeKind])`
/// pair.