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

Fixes primus self seeding generators #964

Merged
merged 3 commits into from
Aug 6, 2019

Conversation

ivg
Copy link
Member

@ivg ivg commented Aug 6, 2019

Primus self seeding generators weren't storing their state and were recreating themselves on every call, which basically turned them into static zero generators.

This PR fixes them, so now we should observe random values read from uninitialized memory (note that our malloc allocator initializes memory with all zeros).

This PR fixes another issue that became apparent after the generator fix - our memory component wasn't memoizing values read from dynamic and static layers, therefore two consequent reads were generating different values. This is akin to the problem in Env fixed in #958.

ivg added 3 commits August 6, 2019 13:17
Memoizes values produced by static or dynamic layers, so that two
consequent reads will yield the same value.
Due to a design error, Primus self-seeding generators never worked as
expected, as they were recreating themselves on each access. The
problem is more a design error, rather than implementation, therefore
the fix is not very beatiful. It is really hard to implement correctly
the `create init` function which has `(int -> t) -> t` type. The proposed
implementation allows only such init that forall `x, y : int`, `init
x` and `init y` generate generators of the same type.

Probably, there is a better solution (by making the Generator type a
Primus component and turning them into higher-order functions), but
since we dropped generators in Primus 2.0 (in favor of a much easier to
use mechanism), I don't think that it is worthwhile to spend more time
on the current implementation.
gen : 'a gen;
}

type 'a wait = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait is a bad name here

We basically have two kinds of generators:

  • context independent (Ready and Static)
  • context dependent

Omitting static for its triviality, the context independent, the context independent has type 'a gen while context dependent has type int -> 'a gen, where int denotes the context (it will be the hash of the machine identifier). Both a paired with the key, which is used to store them in the state. We store a value of type 'a gen in the state. On the first call to the generator (if we don't have the generator stored in the state, then it is the first call), we either take the default state (which we always have) or we use the init function to get the context dependent initial value. Then we just apply the generator and store its in the state. On the next calls, if the generator is in the state we always use it, no matter if it is a context dependent or not.

@gitoleg gitoleg merged commit ff14959 into BinaryAnalysisPlatform:master Aug 6, 2019
@ivg ivg deleted the fixes-primus-generators branch June 10, 2020 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants