Skip to main content

anvil_sys/
lib.rs

1//! Raw bindings to the Anvil plugin API 2 (`include/anvil/anvil_plugin.h`).
2//!
3//! The items of `bindings.rs` are generated by `bindgen`; this file adds what a
4//! header cannot say: the type of the one function a plugin exports and
5//! compile-time checks of the layouts the host and the plugin share.
6#![no_std]
7
8#[allow(
9    non_camel_case_types,
10    non_snake_case,
11    non_upper_case_globals,
12    clippy::all,
13    clippy::pedantic,
14    clippy::nursery,
15    rustdoc::all
16)]
17#[rustfmt::skip]
18mod bindings;
19
20pub use bindings::*;
21
22/// The type of `anvil_plugin_load`, which every plugin exports (`extern "C"`,
23/// not mangled): `#[unsafe(no_mangle)] pub unsafe extern "C" fn anvil_plugin_load(…)`.
24pub type AnvilPluginLoadFn =
25    unsafe extern "C" fn(host: *const AnvilHost, self_: *mut AnvilPlugin) -> AnvilResult;
26
27// The context is exactly SafetyHook's `Context64`: XMM0-15 (256 bytes), then
28// RFLAGS, the 15 general registers, `rsp`, a reserved slot and `rip`.
29const _: () = {
30    use core::mem::{align_of, offset_of, size_of};
31    assert!(size_of::<AnvilCpuContext>() == 408);
32    assert!(align_of::<AnvilCpuContext>() == 8);
33    assert!(size_of::<AnvilXmm>() == 16);
34    assert!(offset_of!(AnvilCpuContext, xmm) == 0);
35    assert!(offset_of!(AnvilCpuContext, rflags) == 256);
36    assert!(offset_of!(AnvilCpuContext, rax) == 256 + 14 * 8);
37    assert!(offset_of!(AnvilCpuContext, rsp) == 256 + 16 * 8);
38    assert!(offset_of!(AnvilCpuContext, rip) == 256 + 18 * 8);
39    assert!(ANVIL_API_VERSION == 2);
40    // Pointer-sized fields: this is an x86-64 interface.
41    assert!(size_of::<usize>() == 8);
42};