Skip to content

Update block along with the block cache #115

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions libipt/src/pt_block_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
static int pt_blk_proceed_trailing_event(struct pt_block_decoder *,
struct pt_block *);

static int pt_blk_proceed_no_event_cached(struct pt_block_decoder *decoder,
struct pt_block *block,
struct pt_block_cache *bcache,
const struct pt_mapped_section *msec);
static int pt_blk_set_trig_anchor(struct pt_block_decoder *decoder)
{
if (!decoder)
Expand Down Expand Up @@ -2431,12 +2435,14 @@ pt_blk_proceed_no_event_fill_cache(struct pt_block_decoder *decoder,
if (status < 0)
return status;


int valid_cache = pt_bce_is_valid(bce);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please declare variables at the beginning of the function. We also need to find a better name, because valid_cache refers to an older cache entry that might have been updated when we use the variable. E.g. keep_filling, or just fill.

/* If we don't have a valid cache entry, yet, fill the cache some more.
*
* On our way back, we add a cache entry for this instruction based on
* the cache entry of the succeeding instruction.
*/
if (!pt_bce_is_valid(bce)) {
if (!valid_cache) {
/* If we exceeded the maximum number of allowed steps, we insert
* a trampoline to the next instruction.
*
Expand Down Expand Up @@ -2515,7 +2521,14 @@ pt_blk_proceed_no_event_fill_cache(struct pt_block_decoder *decoder,
* Cache updates are atomic so even if the two versions were not
* identical, we wouldn't care because they are both correct.
*/
return pt_bcache_add(bcache, ioff, bce);
status = pt_bcache_add(bcache, ioff, bce);
if (status < 0)
return status;

if (valid_cache)
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd need some comment explaining that we can only proceed with the new cache entry if we have not filled the block.

return pt_blk_proceed_no_event_cached(decoder, block,
bcache, msec);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please indent until the opening parenthesis using tabs (tab width 8) as far as possible, then switching to spaces.

Let's also add an empty line between the two returns.

return status;
}

/* Proceed at a potentially truncated instruction.
Expand Down