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

Create a generic Value class that seamlessly wraps both Expr and Number #19

Closed
Boyan-MILANOV opened this issue Dec 26, 2021 · 1 comment · Fixed by #21
Closed

Create a generic Value class that seamlessly wraps both Expr and Number #19

Boyan-MILANOV opened this issue Dec 26, 2021 · 1 comment · Fixed by #21
Assignees
Labels
bindings Python bindings core Maat core internals enhancement New feature or request refactoring Code refactoring & restructuration

Comments

@Boyan-MILANOV
Copy link
Collaborator

Related to #5

More thoughts on having a Value class equivalent to std::variant<Expr, Number>:

  • could be used everywhere in the API, instead of having to duplicate things between Expr and Number/cst_t. That includes:
    • In IRContext and TmpContext instead of maintaining two lists
    • In ProcessedInst::Param
    • In CPU's preprocess_inst and postprocess_inst methods
    • In MemEngine read/write API
    • In Info, RegAccess, MemAccess, ...
  • Should have a is_abstract() and is_concrete() methods
  • Should also have is_concrete, is_concolic, ..., wrappers methods for convenience use
  • Should have the same in-place operators as the Number class, except that they automatically use the internal Number or Expr depending on whether the Value is abstract or concrete. Using in-place operators is a must for performance
  • Should have operators to create Constraints, again mostly just wrappers around Expr operators

Basically we should start off from the current ProcessedInst::Param implementation and build a fully functional Value class on top of it, then progressively start to use Value everywhere.

Implementation notes

  • The class should have near zero overhead for concrete values: just set nullptr for the expression field
  • The class should have efficient creation, including assignment operator, and copy or rvalue reference assignment
  • Since the class contents size will exceed the size of a native integer, and since it will have non-trivial constructors, it should be passed as reference as often as possible
  • They class should be used in-place as much as possible
  • About usage of Value vs Expr in the API:
    • Use Expr when we are sure we are dealing with abstract expressions (like new_symbolic_buffer, ...)
    • Use Value when we are unsure if data is concrete or abstract
    • Typically, we will allow using both Expr and Value when the user inputs symbolic data to the engine (assigning registers, writing memory, creating symbolic buffers, ...), but use mainlyValue when returning information back to the user (reading registers and memory, info field in event callbacks, ...)
@Boyan-MILANOV Boyan-MILANOV added enhancement New feature or request core Maat core internals refactoring Code refactoring & restructuration labels Dec 26, 2021
@Boyan-MILANOV Boyan-MILANOV self-assigned this Dec 26, 2021
@Boyan-MILANOV
Copy link
Collaborator Author

Boyan-MILANOV commented Dec 26, 2021

Todo list to keep track of progress

  • Implement the basic Value class with in-place operations implemented
  • Use Value for core processing in the execution engine
    • Use it for processed inst params
    • Use it as the default in CPU to store regs and temporaries
    • Extend MemEngine API to accept Value arguments
      • Remove the called_by_engine parameters if not useful anymore
    • Use it in info for event callbacks
    • Use it for ABI APIs and emulation callbacks
    • Use it in new_concolic/symbolic_buffer()
  • Once it has been intergrated to most APIs, go through the code once more and remove vestigial uses of Value::as_expr() and Value::as_number()
  • Add overloaded operators on Value for convenience
  • Add python bindings for Value (they should replace Expr)
  • Update python bindings for the API signatures that switched from Expr to Value
  • Update API documentation with Value (and getting started tutorial)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindings Python bindings core Maat core internals enhancement New feature or request refactoring Code refactoring & restructuration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant