summaryrefslogtreecommitdiff
path: root/util/tlm
diff options
context:
space:
mode:
authorChristian Menard <christian.menard@tu-dresden.de>2017-05-23 18:34:12 +0200
committerChristian Menard <christian.menard@tu-dresden.de>2017-05-30 10:47:54 +0000
commit9c29b5a433ea4fc2a7d2d06ce052b33ce7c4a8c2 (patch)
tree7f3d5f34992e94be55b4fc62e153d037ab8cdaa9 /util/tlm
parent01921763a47d1ed2238ee5d4435edbf752783a95 (diff)
downloadgem5-9c29b5a433ea4fc2a7d2d06ce052b33ce7c4a8c2.tar.xz
misc: check address range in the SystemC example
Using a wrong offset or memory size may lead to segmentation faults. This patch adds an address range check and produces an error message. Change-Id: I79a72c05879266daf61a83367fe4ae386d1958a4 Reviewed-on: https://gem5-review.googlesource.com/3482 Maintainer: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Matthias Jung <jungma@eit.uni-kl.de>
Diffstat (limited to 'util/tlm')
-rw-r--r--util/tlm/examples/slave_port/sc_target.cc12
-rw-r--r--util/tlm/examples/slave_port/sc_target.hh3
2 files changed, 15 insertions, 0 deletions
diff --git a/util/tlm/examples/slave_port/sc_target.cc b/util/tlm/examples/slave_port/sc_target.cc
index c44a27149..152d99ae6 100644
--- a/util/tlm/examples/slave_port/sc_target.cc
+++ b/util/tlm/examples/slave_port/sc_target.cc
@@ -66,6 +66,14 @@ Target::Target(sc_core::sc_module_name name,
}
void
+Target::check_address(unsigned long long int addr)
+{
+ if (addr < offset || addr >= offset + size)
+ SC_REPORT_FATAL("Target", "Address out of range. Did you set an "
+ "appropriate size and offset?");
+}
+
+void
Target::b_transport(tlm::tlm_generic_payload& trans, sc_time& delay)
{
/* Execute the read or write commands */
@@ -75,6 +83,8 @@ Target::b_transport(tlm::tlm_generic_payload& trans, sc_time& delay)
unsigned int
Target::transport_dbg(tlm::tlm_generic_payload& trans)
{
+ check_address(trans.get_address());
+
tlm::tlm_command cmd = trans.get_command();
sc_dt::uint64 adr = trans.get_address() - offset;
unsigned char* ptr = trans.get_data_ptr();
@@ -203,6 +213,8 @@ Target::execute_transaction_process()
void
Target::execute_transaction(tlm::tlm_generic_payload& trans)
{
+ check_address(trans.get_address());
+
tlm::tlm_command cmd = trans.get_command();
sc_dt::uint64 adr = trans.get_address() - offset;
unsigned char* ptr = trans.get_data_ptr();
diff --git a/util/tlm/examples/slave_port/sc_target.hh b/util/tlm/examples/slave_port/sc_target.hh
index 7a2d075d9..a10fb492d 100644
--- a/util/tlm/examples/slave_port/sc_target.hh
+++ b/util/tlm/examples/slave_port/sc_target.hh
@@ -91,6 +91,9 @@ struct Target: sc_module
/** Method process that runs on target_done_event */
void execute_transaction_process();
+ /** Helping function that checks if a requested address is with range */
+ void check_address(unsigned long long int addr);
+
/** Helping Variables **/
unsigned long long int size;
unsigned offset;