Skip to content
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

Enforcing concreteness of pointers with types #392

Open
langston-barrett opened this issue Jan 3, 2020 · 0 comments
Open

Enforcing concreteness of pointers with types #392

langston-barrett opened this issue Jan 3, 2020 · 0 comments

Comments

@langston-barrett
Copy link
Contributor

langston-barrett commented Jan 3, 2020

Concreteness of pointers is an important invariant, and there are at least a few places in Crucible that expect at least concrete allocation numbers, e.g.

Nothing -> return (Left (text "Cannot resolve a symbolic pointer to a function handle:" <$$> ppPtr ptr))

(For another example, see discussion on #376). We should consider using types to enforce/expose/document this invariant. Pointers are represented by an allocation number and an offset, so there's a 2x2 matrix of concrete vs symbolic data.

There are two places in crucible-llvm that I can think of right now that could use this information fruitfully:

  • The function doMalloc always returns concrete pointers.
  • In MemImpl, the memImplGlobalMap should only contain concrete pointers, so doResolveGlobal could return concrete pointers.

There are two ways I can think of to reflect this information at the type level:

Newtypes

We could have up to three newtypes: ConcretePointer, ConcreteAllocationNumber, and ConcreteOffset. I think the above code snippet justifies ConcreteAllocationNumber, I'm not sure if the other two are worth it.

I would expect at least the following API:

  • a smart constructor concretePointer :: LLVMPtr -> Maybe ConcretePointer
  • a getter extractAllocationNumber :: ConcretePointer -> Int

With possibly some additional functions, like clones of doPtrAddOffset that retain the concreteness of the allocation number. This could end up with a reasonable amount of boilerplate if we pursue the full 2x2 matrix.

Type indices

We could also use two type-level indices to LLVMPtr, both with kinds isomorphic to Bool. This would probably enforce the strongest invariants, but this is a very commonly used datatype and the complexity tradeoff might not be worth it, especially since almost everything that uses pointers is polymorphic in their concreteness.

@langston-barrett langston-barrett changed the title Newtype for pointers with concrete allocation numbers Enforcing concreteness of pointers with types Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants