MEM: Fatal when no port can be found for an address
This patch adds a check in the findPort method to ensure that an invalid port id is never returned. Previously this could happen if no default port was set, and no address matched the request, in which case -1 was returned causing a SEGFAULT when using the id to index in the port array. To clean things up further a symbolic name is added for the invalid port id.
This commit is contained in:
parent
e121708e08
commit
ef4af8cec8
2 changed files with 17 additions and 10 deletions
|
@ -56,8 +56,9 @@
|
||||||
Bus::Bus(const BusParams *p)
|
Bus::Bus(const BusParams *p)
|
||||||
: MemObject(p), busId(p->bus_id), clock(p->clock),
|
: MemObject(p), busId(p->bus_id), clock(p->clock),
|
||||||
headerCycles(p->header_cycles), width(p->width), tickNextIdle(0),
|
headerCycles(p->header_cycles), width(p->width), tickNextIdle(0),
|
||||||
drainEvent(NULL), busIdle(this), inRetry(false), defaultPortId(-1),
|
drainEvent(NULL), busIdle(this), inRetry(false),
|
||||||
useDefaultRange(p->use_default_range), defaultBlockSize(p->block_size),
|
defaultPortId(INVALID_PORT_ID), useDefaultRange(p->use_default_range),
|
||||||
|
defaultBlockSize(p->block_size),
|
||||||
cachedBlockSize(0), cachedBlockSizeValid(false)
|
cachedBlockSize(0), cachedBlockSizeValid(false)
|
||||||
{
|
{
|
||||||
//width, clock period, and header cycles must be positive
|
//width, clock period, and header cycles must be positive
|
||||||
|
@ -76,7 +77,7 @@ Bus::getPort(const std::string &if_name, int idx)
|
||||||
std::string portName;
|
std::string portName;
|
||||||
int id = interfaces.size();
|
int id = interfaces.size();
|
||||||
if (if_name == "default") {
|
if (if_name == "default") {
|
||||||
if (defaultPortId == -1) {
|
if (defaultPortId == INVALID_PORT_ID) {
|
||||||
defaultPortId = id;
|
defaultPortId = id;
|
||||||
portName = csprintf("%s-default", name());
|
portName = csprintf("%s-default", name());
|
||||||
} else
|
} else
|
||||||
|
@ -301,7 +302,7 @@ Bus::findPort(Addr addr)
|
||||||
int dest_id;
|
int dest_id;
|
||||||
|
|
||||||
dest_id = checkPortCache(addr);
|
dest_id = checkPortCache(addr);
|
||||||
if (dest_id != -1)
|
if (dest_id != INVALID_PORT_ID)
|
||||||
return dest_id;
|
return dest_id;
|
||||||
|
|
||||||
// Check normal port ranges
|
// Check normal port ranges
|
||||||
|
@ -321,13 +322,16 @@ Bus::findPort(Addr addr)
|
||||||
return defaultPortId;
|
return defaultPortId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (defaultPortId != INVALID_PORT_ID) {
|
||||||
panic("Unable to find destination for addr %#llx\n", addr);
|
DPRINTF(Bus, "Unable to find destination for addr %#llx, "
|
||||||
|
"will use default port\n", addr);
|
||||||
|
return defaultPortId;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINTF(Bus, "Unable to find destination for addr %#llx, "
|
// we should use the range for the default port and it did not
|
||||||
"will use default port\n", addr);
|
// match, or the default port is not set
|
||||||
return defaultPortId;
|
fatal("Unable to find destination for addr %#llx on bus %s\n", addr,
|
||||||
|
name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@ class Bus : public MemObject
|
||||||
return portCache[2].id;
|
return portCache[2].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return INVALID_PORT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clears the earliest entry of the cache and inserts a new port entry
|
// Clears the earliest entry of the cache and inserts a new port entry
|
||||||
|
@ -317,6 +317,9 @@ class Bus : public MemObject
|
||||||
/** Port that handles requests that don't match any of the interfaces.*/
|
/** Port that handles requests that don't match any of the interfaces.*/
|
||||||
short defaultPortId;
|
short defaultPortId;
|
||||||
|
|
||||||
|
/** A symbolic name for a port id that denotes no port. */
|
||||||
|
static const short INVALID_PORT_ID = -1;
|
||||||
|
|
||||||
/** If true, use address range provided by default device. Any
|
/** If true, use address range provided by default device. Any
|
||||||
address not handled by another port and not in default device's
|
address not handled by another port and not in default device's
|
||||||
range will cause a fatal error. If false, just send all
|
range will cause a fatal error. If false, just send all
|
||||||
|
|
Loading…
Reference in a new issue