-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support function pointer type #57
Comments
@phosra Out of curiosity, on what platforms would this be unsound? |
Admittedly, such platform would likely be a Harvard architecture platform that doesn't implement POSIX - in practice... it's very unlikely to encounter such a platform, even less so for one with different sizes. Although, it's possible to find maybe a Harvard embedded platform? How that could possibly affect FFI, I suppose it could be useful for interacting with native code after developing and running a new scripting language compiled as a bytecode, such as is done for JavaScript via XS, or Python via CircuitPython. More realistically, although I cannot quite determine whether it's so, but a (future) CHERI Aarch64 Harvard, platform running an OS that doesn't implement POSIX could run into such an issue... still amusingly unlikely! It's more of a "technical" issue. :) |
You are correct that a function pointer cannot necessarily be converted to and from a |
Upstream issue: denoland/deno#15292.
Downstream issue: libffi/libffi#725.
It seems that libffi-rs doesn't provide a function pointer type, but after further investigation, it seems that this is because the C libffi does not support this, so I have opened an issue there too; feel free to subscribe to the downstream issue.
Nonetheless, in the meanwhile, it does seem that libffi-rs misuses
*const c_void
asfn()
, which can still be fixed here.See https://rust-lang.github.io/unsafe-code-guidelines/layout/function-pointers.html and https://c-faq.com/ptrs/generic.html.
Rust claims that Rust's
extern "ABI" fn(...) -> R
has the same size/alignment/etc. as C'svoid (*)()
, and that it may not necessarily map to C'svoid *
.Furthermore, Rust's
fn
documentation requests that code usefn
primitives for FFI.As a result, some present usage here is unsound (on some platforms), such as https://docs.rs/libffi/latest/libffi/low/struct.CodePtr.html.
The text was updated successfully, but these errors were encountered: