Skip to content

Releases: tremwil/closure-ffi

v5.1.2

08 Feb 16:37

Choose a tag to compare

Added

  • Calling convention marker types are no longer limited by operating system, but purely target architecture.
  • CI tests for additional targets: armv7 (soft and hard float) and thumbv7 Linux

Fixed

  • C-variadic calling convention support (was broken by changes to the nightly feature)
  • Linker errors on x86 for platforms that don't allow absolute relocations in code sections
  • Make global_jit_alloc-written code compatible with default_jit_alloc. With this configuration,
    the allocator provided by the global_jit_alloc! macro will be ignored.

v5.0.1

29 Oct 00:00

Choose a tag to compare

Fixed

  • Use forked iced-x86 crate to avoid conflicts with dependents using it with the std feature. This is temporary until a new iced version is released to allow std and no_std features to be enabled at the same time.

v5.0.0

20 Oct 00:30

Choose a tag to compare

Breaking Changes

  • Compiling with a Thumb JSON target file will now require Nightly Rust.
  • With the addition of the safe_jit feature, compiling with --no-default-features will now error
    unless the no_safe_jit feature is explicitly enabled to prevent accidentally forgetting to enable safe_jit.
  • Strengthened trait bounds on FnPtr::CC to make some APIs more ergonomic. This is technically a breaking change but is realistically harmless, as FnPtr should not be implemented by the end user.
  • Changed the JitAlloc blanket impl from &J for all J: JitAlloc to any type implementing Deref<Target = J>. This is more general and avoids having to write forwarding impls when putting a JitAlloc in a LazyLock, for example, but may break some downstream JitAlloc wrappers.

Added

  • Thunk generation is now fully safe thanks to the safe_jit feature, which uses a disassembler to properly relocate the prologue code instead of assuming it is trivially relocatable. This brings an end to this crate's UB issues.

  • Support for the efiapi and Rust calling conventions.

Fixed

  • global_jit_alloc macro ambiguous parsing for the unsafe block variant.
  • Incorrect relocation of thunk prologues on i686-unknown-linux-gnu.

Removed

  • i686-specific Windows calling conventions from x64 Windows targets.

v4.1.0

24 Sep 10:47

Choose a tag to compare

Changed

  • Thunk generation modified to be a zero-cost abstraction: For functions items and non-capturing closures, constructing a BareFn* type will not allocate or emit code. Instead, it will use a compile-time template that conjures an instance of the ZST to invoke it.
  • Added changelog to the documentation.
  • Added UB warning to the documentation.

v4.0.0

22 Sep 16:09

Choose a tag to compare

This update adds the scaffolding required to implement "higher order" transformations on bare function thunks. For example, it is now possible to write a function that synchonizes an generic FnMutThunk implementation while printing its return value:

use closure_ffi::{thunk_factory, traits::{FnPtr, FnThunk, FnMutThunk}};

fn lock_and_debug<B: FnPtr, F: Send>(fun: F) -> impl FnThunk<B> + Sync
where
    for<'a, 'b, 'c> B::Ret<'a, 'b, 'c>: core::fmt::Debug,
    (cc::C, F): FnMutThunk<B>,
{
    let locked = std::sync::Mutex::new((cc::C, fun));
    thunk_factory::make_sync(move |args| unsafe {
        let ret = locked.lock().unwrap().call_mut(args);
        println!("value: {ret:?}");
        ret
    })
}

This is particularly useful for hooking libraries.

Breaking Changes

  • Removed where Self: 'a + 'b + 'c bounds on FnPtr::Args and FnPtr::Ret
  • Regression in the expressivity of bare_hrtb!(): Now requires a 'static bound on certain generic parameters
  • removed zero-variant enum from FnPtr::Args for extern variaric functions to be able to implement the new trait functions. FnPtr::call now const panics instead of being impossible to call for them.

Added

  • FnPtr::make_*_thunk functions that can create a Fn*Thunk implementation from a closure with tuple-packed arguments.
  • FnOnceThunk::call_once, FnMutThunk::call_mut and FnThunk::call for invoking the underlying closure with tuple-packed arguments.
  • thunk_factory module for creating Fn*Thunk implementations that satisfy combinations of Send and Sync bounds.

Fixed

  • libc dependency not compatible with no_std on Linux ARM targets

v3.0.1

21 Jun 08:55

Choose a tag to compare

Fixed

  • docs.rs build

v3.0.0

20 Jun 23:33

Choose a tag to compare

Breaking Changes

  • ToBoxedUnsize has been renamed to ToBoxedDyn is now an unsafe trait. See the documentation for the
    new invariants.
  • Send and Sync impl bounds on BareFn are now stricter to catch more unsafety.
  • Major overhaul of feature flags. See README to view the changes.

Added

  • UntypedBareFn* types that erase the bare function type entirely. Can be used to store
    BareFn* wrappers of different types in a data structure.
  • coverage unstable feature to support the -C instrument-coverage rustc flag.

Changed

  • Change thunk assembly magic numbers/sentinel values to sequences that are guaranteed to not be emitted by the compiler.
    Thanks to @Dasaav-dsv for the help.
  • Move the arch/feature compile_error checks into the build script for better errors.
  • Dual license under Apache-2.0 and MIT.

v2.4.0

09 Jun 01:06

Choose a tag to compare

Added

  • c_variadic feature to add partial support for C variadic functions.

v2.3.0

30 May 18:31
d74b895

Choose a tag to compare

Added

  • tuple_trait feature to add a core::marker::Tuple bound to FnPtr::Args, allowing better
    interoperability with other Nightly features such as fn_traits and unboxed_closures.

Changed

  • use dep:crate optional dependency toggles to prevent implicit dependency named features.
    This is technically a breaking change, but as these features are not documented I have decided
    to not bump the major version.

v2.2.0

30 May 01:36
232a833

Choose a tag to compare

Fixed

  • bundled_jit_alloc should now work on i686-pc-windows-msvc without linker errors

Changed

  • Bundled JIT allocator now uses jit-allocator2, a maintained fork of jit-allocator which fixes a linker issue on i686-pc-windows-msvc.