immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.81k stars 220 forks source link

(`c2rust-analyze`) Allow calls to `UnknownDef` `KnownFn`s with known ptr perms #980

Closed kkysen closed 1 year ago

kkysen commented 1 year ago

This allows Callee::UnknownDef calls if they are direct (i.e. not a fn ptr), call a foreign fn (i.e. from an extern block), and are a KnownFn (i.e. returned by const fn all_known_fns). They are treated as normal local fn calls (i.e. they use .visit_local_call, like for Callee::LocalDef) as the PointerIds from the LFnSigs for these foreign fns are constrained by the PermissionSets annotated in the KnownFns. Note that these LFnSigs for the foreign fns are already created by fn gather_foreign_sigs.

I've included a test that checks that a call to libc's access succeeds without crashing and that the pointer passed to it is successfully inferred to be READ | OFFSET_ADD from access's known ptr perms, and thus intended to be rewritten as a slice (though it's not actually rewritten since the foreign fn call is FIXED).