diff --git a/Cargo.lock b/Cargo.lock index 8792d90ac5..d66529a464 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -794,9 +794,9 @@ checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libffi" -version = "4.1.1" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7681c6fab541f799a829e44a445a0666cf8d8a6cfebf89419e6aed52c604e87" +checksum = "0444124f3ffd67e1b0b0c661a7f81a278a135eb54aaad4078e79fbc8be50c8a5" dependencies = [ "libc", "libffi-sys", @@ -804,9 +804,9 @@ dependencies = [ [[package]] name = "libffi-sys" -version = "3.3.2" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0d828d367b4450ed08e7d510dc46636cd660055f50d67ac943bfe788767c29" +checksum = "3d722da8817ea580d0669da6babe2262d7b86a1af1103da24102b8bb9c101ce7" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index 12123c260d..8bb4f1c160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ features = ['unprefixed_malloc_on_supported_platforms'] [target.'cfg(unix)'.dependencies] libc = "0.2" # native-lib dependencies -libffi = { version = "4.1.1", optional = true } +libffi = { version = "5.0.0", optional = true } libloading = { version = "0.8", optional = true } serde = { version = "1.0.219", features = ["derive"], optional = true } diff --git a/src/shims/native_lib/ffi.rs b/src/shims/native_lib/ffi.rs index 0badf22bb7..196f43c6f6 100644 --- a/src/shims/native_lib/ffi.rs +++ b/src/shims/native_lib/ffi.rs @@ -9,11 +9,9 @@ use libffi::middle::{Arg as ArgPtr, Cif, Type as FfiType}; /// /// The safety invariants of the foreign function being called must be upheld (if any). pub unsafe fn call(fun: CodePtr, args: &mut [OwnedArg]) -> R { - let arg_ptrs: Vec<_> = args.iter().map(|arg| arg.ptr()).collect(); let cif = Cif::new(args.iter_mut().map(|arg| arg.ty.take().unwrap()), R::reify().into_middle()); - // SAFETY: Caller upholds that the function is safe to call, and since we - // were passed a slice reference we know the `OwnedArg`s won't have been - // dropped by this point. + let arg_ptrs: Vec<_> = args.iter().map(|arg| ArgPtr::new(&*arg.bytes)).collect(); + // SAFETY: Caller upholds that the function is safe to call. unsafe { cif.call(fun, &arg_ptrs) } } @@ -31,16 +29,4 @@ impl OwnedArg { pub fn new(ty: FfiType, bytes: Box<[u8]>) -> Self { Self { ty: Some(ty), bytes } } - - /// Creates a libffi argument pointer pointing to this argument's bytes. - /// NB: Since `libffi::middle::Arg` ignores the lifetime of the reference - /// it's derived from, it is up to the caller to ensure the `OwnedArg` is - /// not dropped before unsafely calling `libffi::middle::Cif::call()`! - fn ptr(&self) -> ArgPtr { - // FIXME: Using `&self.bytes[0]` to reference the whole array is - // definitely unsound under SB, but we're waiting on - // https://github.com/libffi-rs/libffi-rs/commit/112a37b3b6ffb35bd75241fbcc580de40ba74a73 - // to land in a release so that we don't need to do this. - ArgPtr::new(&self.bytes[0]) - } }