Module rust_cheri_compressed_cap::c_funcs[][src]

Import C functions for CC64,128.

We used to do this separately in cc64.rs and cc128.rs for the 64 and 128 bit versions. This seemed to cause multiple-definition link errors, so now we link all of them in one place.

Normally Rust warns us about using u128, i128 in FFI function arguments, because there isn’t a well-defined ABI. We initially tried to create a repr(C) struct that matched the ABI, but this seems impossible. Clang (as of LLVM-13) defines u128,i128 as built-in types which are passed in two registers. This cannot be replicated exactly by passing a struct - see clang/lib/CodeGen/TargetInfo.cpp: X86_64ABIInfo::classify(), and this godbolt example.

Therefore, we instead use Rust native u128, i128 under the assumption that

  1. Rust is being compiled under LLVM
  2. Rust native u128, i128 are represented with LLVM’s built-in 128-bit types
  3. The C code is also compiled with LLVM, using the built-in 128-bit types.
  4. The versions of LLVM used to compile Rust, C are ABI-compatible for 128-bit types.

Assumption 3 may not be necessary - maintaining compatibility with GCC is in Clang’s interest, so GCC-compiled C may work just as well. Assumption 4 is difficult to check, we’re taking it on faith that LLVM doesn’t do anything silly in the future.

Under all these assumptions, we can safely ignore Rust’s “improper ctypes” warning.

Functions

cc64_compress_mem
cc64_compress_raw
cc64_decompress_mem
cc64_decompress_raw
cc64_extract_bounds_bits
cc64_get_alignment_mask
cc64_get_flags
cc64_get_otype
cc64_get_perms
cc64_get_representable_length
cc64_get_required_alignment
cc64_get_reserved
cc64_get_uperms
cc64_is_representable_cap_exact
cc64_is_representable_new_addr
cc64_make_max_perms_cap
cc64_setbounds
cc64_update_flags
cc64_update_otype
cc64_update_perms
cc64_update_reserved
cc64_update_uperms
cc128_compress_mem
cc128_compress_raw
cc128_decompress_mem
cc128_decompress_raw
cc128_extract_bounds_bits
cc128_get_alignment_mask
cc128_get_flags
cc128_get_otype
cc128_get_perms
cc128_get_representable_length
cc128_get_required_alignment
cc128_get_reserved
cc128_get_uperms
cc128_is_representable_cap_exact
cc128_is_representable_new_addr
cc128_make_max_perms_cap
cc128_setbounds
cc128_update_flags
cc128_update_otype
cc128_update_perms
cc128_update_reserved
cc128_update_uperms