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
//! Allocator — host_alloc/host_free cross-boundary memory management.
//! These functions back the `HostApi::alloc`/`HostApi::free` fields
//! and are used to allocate memory that crosses the plugin/host boundary.
//! They are NOT exported as standalone C symbols — the only exported symbols are
//! `polyplug_runtime_create` and `polyplug_runtime_destroy`.
use GlobalAlloc;
use Layout;
use System;
/// Allocate memory via the host system allocator.
///
/// Returns null for size=0 or invalid alignment. Calling this function is itself
/// safe; the obligations below concern the returned pointer's lifecycle.
///
/// # Contract
/// To avoid leaks or undefined behaviour with the returned pointer, callers must:
/// - Free it with `polyplug_host_free` using the SAME `size` and `align`.
/// - Not use it after calling `polyplug_host_free`.
pub extern "C"
/// Free memory previously allocated by `polyplug_host_alloc`.
///
/// Passing null or size=0 is a safe no-op.
///
/// # Safety
/// Callers must:
/// - Pass a pointer returned by `polyplug_host_alloc`.
/// - Pass the SAME `size` and `align` used in the original allocation.
/// - Not use the pointer after this call.
/// - Not call this twice with the same pointer.
pub unsafe extern "C"