You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
1.1 KiB

use std::ffi::c_void;
pub type CallbackRaw = extern "C" fn (ptr: *mut c_void, data: *mut c_void)->();
extern "C" {
fn _alloca_trampoline(size: usize, cb: Option<CallbackRaw>, data: *mut c_void);
}
/// Call the `_alloca_trampoline` C function.
///
/// # Safety requirements & guarantees
/// * `size` should be small enough to not overflow the stack. A size of 0 is allowed.
/// * `cb` **must** catch any unwinds.
/// * `data` can be `null`, it is passed as the 2nd argument to `cb` as-is.
/// * The first argument to `cb` is guaranteed to be a non-aliased, properly aligned, and non-null pointer with `size` read+writable memory. If `size` is 0, it may dangle.
/// * `cb` is guaranteed to be called unless allocating `size` bytes on the stack causes a stack overflow, in which case the program will terminate.
/// * The data pointed to by `ptr` is guaranteed to be popped from the stack once `cb` returns (even in the case of a `longjmp`, but `panic!()` within the callback is still undefined behaviour).
#[inline(always)] pub unsafe fn alloca_trampoline(size: usize, cb: CallbackRaw, data: *mut c_void)
{
_alloca_trampoline(size, Some(cb), data);
}