check memory boundaries

This commit is contained in:
mariusmonton 2021-02-21 13:47:06 +01:00
parent ef6fe88b9c
commit 5927dade4d
1 changed files with 6 additions and 0 deletions

View File

@ -114,6 +114,7 @@ bool Memory::get_direct_mem_ptr(tlm::tlm_generic_payload &trans,
return false; return false;
} }
// Permit read and write access // Permit read and write access
dmi_data.allow_read_write(); dmi_data.allow_read_write();
@ -133,6 +134,11 @@ unsigned int Memory::transport_dbg(tlm::tlm_generic_payload &trans) {
unsigned char *ptr = trans.get_data_ptr(); unsigned char *ptr = trans.get_data_ptr();
unsigned int len = trans.get_data_length(); unsigned int len = trans.get_data_length();
if (adr >= sc_dt::uint64(SIZE)) {
trans.set_response_status(tlm::TLM_ADDRESS_ERROR_RESPONSE);
return 0;
}
// Calculate the number of bytes to be actually copied // Calculate the number of bytes to be actually copied
unsigned int num_bytes = (len < (SIZE - adr) * 4) ? len : (SIZE - adr) * 4; unsigned int num_bytes = (len < (SIZE - adr) * 4) ? len : (SIZE - adr) * 4;