Skip to content

Commit

Permalink
Skip writing zero sized encoding blocks to encoding file.
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav92003 committed Nov 22, 2023
1 parent c7c5575 commit 045fd47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions clients/drcachesim/tracer/instru_offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,20 +530,22 @@ offline_instru_t::record_instr_encodings(void *drcontext, app_pc tag_pc,
DR_ASSERT(buf < encoding_buf_start_ + encoding_buf_sz_);
}

DR_ASSERT(buf >= buf_start + sizeof(encoding_entry_t));
if (buf == buf_start + sizeof(encoding_entry_t)) {
// If the given ilist has no app instr, we skip writing anything to the
// encoding file.
dr_mutex_unlock(encoding_lock_);
return;
}
encoding_entry_t *enc = reinterpret_cast<encoding_entry_t *>(buf_start);
DR_ASSERT(buf > buf_start);
enc->length = buf - buf_start;
enc->id = per_block->id;
// We put the ARM vs Thumb mode into the modoffs to ensure proper decoding.
enc->start_pc = reinterpret_cast<uint64_t>(
dr_app_pc_as_jump_target(instr_get_isa_mode(instrlist_first(ilist)), tag_pc));
log_(2, "%s: Recorded %zu bytes for id " UINT64_FORMAT_STRING " @ %p\n", __FUNCTION__,
enc->length, enc->id, tag_pc);
// TODO i#2062: If the ilist does not have any app instr, we still somehow need to
// write an entry to the encoding file. For now we keep this behavior. This
// reproduces on the tool.drcacheoff.getretaddr_record_replace_retaddr test.
DR_ASSERT(enc->length >= sizeof(encoding_entry_t));
encoding_length_ += enc->length;
encoding_length_ += (enc->length - sizeof(encoding_entry_t));
encoding_buf_ptr_ += enc->length;
dr_mutex_unlock(encoding_lock_);
}
Expand Down
4 changes: 2 additions & 2 deletions clients/drcachesim/tracer/raw2trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ module_mapper_t::do_encoding_parsing()
uint64_t cumulative_encoding_length = 0;
while (map_at < map_end) {
encoding_entry_t *entry = reinterpret_cast<encoding_entry_t *>(map_at);
if (entry->length < sizeof(encoding_entry_t))
if (entry->length <= sizeof(encoding_entry_t))
return "Encoding file is corrupted";
if (map_at + entry->length > map_end)
return "Encoding file is truncated";
cum_block_enc_len_to_encoding_id_[cumulative_encoding_length] = entry->id;
cumulative_encoding_length += entry->length;
cumulative_encoding_length += (entry->length - sizeof(encoding_entry_t));
encodings_[entry->id] = entry;
map_at += entry->length;
}
Expand Down

0 comments on commit 045fd47

Please sign in to comment.