diff --git a/clients/drcachesim/tracer/instru_offline.cpp b/clients/drcachesim/tracer/instru_offline.cpp index 724eb097ac2..96ff48a21f2 100644 --- a/clients/drcachesim/tracer/instru_offline.cpp +++ b/clients/drcachesim/tracer/instru_offline.cpp @@ -530,8 +530,14 @@ 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(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. @@ -539,11 +545,7 @@ offline_instru_t::record_instr_encodings(void *drcontext, app_pc tag_pc, 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_); } diff --git a/clients/drcachesim/tracer/raw2trace.cpp b/clients/drcachesim/tracer/raw2trace.cpp index 2a00d91060c..b3a44ddd557 100644 --- a/clients/drcachesim/tracer/raw2trace.cpp +++ b/clients/drcachesim/tracer/raw2trace.cpp @@ -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(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; }