(c2rust-analyze) Allow calls to UnknownDef KnownFns with known ptr perms#980
Merged
(c2rust-analyze) Allow calls to UnknownDef KnownFns with known ptr perms#980
c2rust-analyze) Allow calls to UnknownDef KnownFns with known ptr perms#980Conversation
…to `FnSig::inputs_and_output`.
… after gather the non-foreign `fn_sigs` rather than waiting until rewriting. This is needed to use these `LFnSig`s for foreign `fn`s during analysis, which is before rewriting.
oinoom
reviewed
Jul 7, 2023
oinoom
reviewed
Jul 7, 2023
oinoom
reviewed
Jul 7, 2023
oinoom
reviewed
Jul 7, 2023
oinoom
reviewed
Jul 7, 2023
oinoom
reviewed
Jul 7, 2023
oinoom
reviewed
Jul 7, 2023
oinoom
reviewed
Jul 7, 2023
| } | ||
|
|
||
| // CHECK-LABEL: final labeling for "known_fn" | ||
| pub fn known_fn() { |
Contributor
There was a problem hiding this comment.
this looks great, are there some more examples you can add here that appear in lighttpd?
Contributor
Author
There was a problem hiding this comment.
Yeah, there'll definitely be more. How many is useful to add here? Are there any particular cases that you think would be helpful to test?
oinoom
reviewed
Jul 7, 2023
1a4b03a to
7e33b68
Compare
…, &'static KnownFn>` set to `all_known_fns()`.
…f `Callee::UnknownDef`.
… before checking each function.
…reign `fn` in `known_fns` as normal local calls now that the `LFnSig`s have ptr perms.
…o `extern "C" fn access` doesn't crash anymore.
7e33b68 to
2c4f487
Compare
spernsteiner
reviewed
Jul 7, 2023
…y`s again, not `<y`s.
…ally the exact meaning of the `Symbol`s.
… for `KnownFn`s. We specifically want the symbol name. These should normally be the same, but symbol name is more correct. As `SymbolName::name` is a `&str`, I changed `GlobalAnalysisCtxt::known_fns` to store `&'static str` keys instead of `Symbol`s. I also abstracted the symbol name lookup in `fn GlobalAnalysisCtxt::known_fn`, so now `known_fns` is also private.
…ore consistent with `Callee::UnknownDef`.
…recompute the initial `Constraint`s for each function. For now this is just filled with `gacx.known_fn_ptr_perms()`.
…ts` to precompute the initial `Constraint`s for each function. For now this is just filled with `gacx.known_fn_ptr_perms()`." This reverts commit 84d8be4. I found a much simpler way of setting these on the `GlobalAssignment`.
…e `GlobalAssignment` (vs. indirectly through `Constraint`s). This makes it `O(n)` instead of `O(n^2)`, which it was when setting it through `Constraint`s in each function, vs. just once now on the `GlobalAssignment`.
…hange in the `GlobalAssignment`.
84e00a0 to
c5444e9
Compare
spernsteiner
approved these changes
Jul 10, 2023
…ady initialized previously. Co-authored-by: spernsteiner <spernsteiner@galois.com>
This was referenced Jul 17, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows
Callee::UnknownDefcalls if they are direct (i.e. not afnptr), call a foreignfn(i.e. from anexternblock), and are aKnownFn(i.e. returned byconst fn all_known_fns). They are treated as normal localfncalls (i.e. they use.visit_local_call, like forCallee::LocalDef) as thePointerIds from theLFnSigs for these foreignfns are constrained by thePermissionSets annotated in theKnownFns. Note that theseLFnSigs for the foreignfns are already created byfn gather_foreign_sigs.I've included a test that checks that a call to
libc'saccesssucceeds without crashing and that the pointer passed to it is successfully inferred to beREAD | OFFSET_ADDfromaccess's known ptr perms, and thus intended to be rewritten as a slice (though it's not actually rewritten since the foreignfncall isFIXED).