anvil-sys 1.6.0

Raw bindings to the Anvil plugin API 2 (anvil_plugin.h), the C ABI of the Anvil plugin loader for Europa Universalis IV
Documentation
//! Raw bindings to the Anvil plugin API 2 (`include/anvil/anvil_plugin.h`).
//!
//! The items of `bindings.rs` are generated by `bindgen`; this file adds what a
//! header cannot say: the type of the one function a plugin exports and
//! compile-time checks of the layouts the host and the plugin share.
#![no_std]

#[allow(
    non_camel_case_types,
    non_snake_case,
    non_upper_case_globals,
    clippy::all,
    clippy::pedantic,
    clippy::nursery,
    rustdoc::all
)]
#[rustfmt::skip]
mod bindings;

pub use bindings::*;

/// The type of `anvil_plugin_load`, which every plugin exports (`extern "C"`,
/// not mangled): `#[unsafe(no_mangle)] pub unsafe extern "C" fn anvil_plugin_load(…)`.
pub type AnvilPluginLoadFn =
    unsafe extern "C" fn(host: *const AnvilHost, self_: *mut AnvilPlugin) -> AnvilResult;

// The context is exactly SafetyHook's `Context64`: XMM0-15 (256 bytes), then
// RFLAGS, the 15 general registers, `rsp`, a reserved slot and `rip`.
const _: () = {
    use core::mem::{align_of, offset_of, size_of};
    assert!(size_of::<AnvilCpuContext>() == 408);
    assert!(align_of::<AnvilCpuContext>() == 8);
    assert!(size_of::<AnvilXmm>() == 16);
    assert!(offset_of!(AnvilCpuContext, xmm) == 0);
    assert!(offset_of!(AnvilCpuContext, rflags) == 256);
    assert!(offset_of!(AnvilCpuContext, rax) == 256 + 14 * 8);
    assert!(offset_of!(AnvilCpuContext, rsp) == 256 + 16 * 8);
    assert!(offset_of!(AnvilCpuContext, rip) == 256 + 18 * 8);
    assert!(ANVIL_API_VERSION == 2);
    // Pointer-sized fields: this is an x86-64 interface.
    assert!(size_of::<usize>() == 8);
};