-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Init each memory region in init script with zero and fix un-freed buffer #138
Changes from 1 commit
cf308d9
9c00cbb
64138b4
03cc16f
1a7de07
6ea7bd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ class MemSegment | |
/// @param mem Pre-allocated Memory (not overwritten with initString) | ||
/// @param initString String for initialization with imple_mem_system.memseg_initelement_ attr/ If not specified random value allocation | ||
MemSegment(etiss::uint64 start_addr, etiss::uint64 size, access_t mode, const std::string name, | ||
etiss::uint8 *mem = nullptr, std::string initString) | ||
etiss::uint8 *mem = nullptr, std::string initString = "", bool InitEleSet = false) | ||
: name_(name), start_addr_(start_addr), end_addr_(start_addr + size - 1), size_(size), mode_(mode) | ||
{ | ||
if (mem) | ||
|
@@ -107,7 +107,8 @@ class MemSegment | |
else | ||
{ | ||
mem_ = new etiss::uint8[size]; | ||
memInit(initString); | ||
if (InitEleSet) | ||
memInit(initString); | ||
self_allocated_ = true; | ||
} | ||
} | ||
|
@@ -118,11 +119,30 @@ class MemSegment | |
static std::default_random_engine generator{ static_cast<uint64_t>(0) }; | ||
std::uniform_int_distribution<int> random_char_{ 0, 255 }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could move these lines to where they are actually needed |
||
|
||
if (initString == "") | ||
if (initString.find("0x") == 0) | ||
{ | ||
initString.erase(initString.begin(),initString.begin()+2); | ||
std::stringstream mem_msg; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
for (etiss::uint64 i = 0; i < size_; ++i) | ||
{ | ||
mem_[i] = random_char_(generator); | ||
const char* dataPtr = initString.substr(i%initString.length(),1).c_str(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reading one hex character at a time will give you only 4 bits, you need 8 |
||
char** endPtr = nullptr; | ||
errno = 0; | ||
uint8_t hexVal = static_cast<uint8_t>(strtol(dataPtr, endPtr, 16)); | ||
mem_[i] = hexVal; | ||
|
||
if (errno != 0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for clarifying. I was a bit confused after the errno=EINVAL option was not triggered with a false "hex val string": e.g |
||
etiss::log(etiss::WARNING, "Hex Value MemSegment input is erronous (typo?)"); | ||
throw "MemSegmentInit for hex value is errnounous"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
} | ||
} | ||
} | ||
else if (initString.find("random") == 0 || initString.find("RANDOM") == 0) | ||
{ | ||
const char* data = initString.c_str(); | ||
for (etiss::uint64 i = 0; i < size_; ++i) | ||
{ | ||
mem_[i] = data[i%strlen(data)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where did the randomizing go? |
||
} | ||
} | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ void SimpleMemSystem::load_segments() { | |
|
||
ss << "simple_mem_system.memseg_initelement_" << std::setw(2) << std::setfill('0') << i; | ||
std::string initString = etiss::cfg().get<std::string>(ss.str(), ""); | ||
bool initEleSet = etiss::cfg().isSet(ss.str()); | ||
std::stringstream().swap(ss); | ||
|
||
ss << "simple_mem_system.memseg_image_" << std::setw(2) << std::setfill('0') << i; | ||
|
@@ -153,16 +154,25 @@ void SimpleMemSystem::load_segments() { | |
|
||
mem_msg << "The memory segment " << i << " is initialized with 0x" << std::hex << length << " bytes from input_image !"; | ||
etiss::log(etiss::INFO, mem_msg.str()); | ||
} else if (initString != "") { | ||
mem_msg << "The memory segment " << i << " is initialized with 0x" << std::hex << length << " elements with value: " << initString; | ||
etiss::log(etiss::INFO, mem_msg.str()); | ||
} else if (initEleSet) { | ||
if (initString.find("random") == 0 || initString.find("RANDOM")== 0) { | ||
mem_msg << "The memory segment " << i << " is initialized with 0x" << std::hex << length << " random bytes !"; | ||
etiss::log(etiss::INFO, mem_msg.str()); | ||
} else if (initString.find("0x") == 0) { | ||
mem_msg << "The memory segment " << i << " is initialized with 0x" << std::hex << length << " elements with hex value: " << initString; | ||
etiss::log(etiss::INFO, mem_msg.str()); | ||
} | ||
else | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: keep formatting consistent |
||
mem_msg << "The memory segment " << i << " is initialized with 0x" << std::hex << length << " elements with the string: " << initString; | ||
etiss::log(etiss::INFO, mem_msg.str()); | ||
} | ||
} else { | ||
mem_msg << "The memory segment " << i << " is initialized with 0x" << std::hex << length << " random values !"; | ||
mem_msg << "The memory segment " << i << " is allocated uninitialized with length 0x" << std::hex << length << " !"; | ||
etiss::log(etiss::INFO, mem_msg.str()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all these conditionals do is print debug messages, move the messages to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well I lacked the local There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, |
||
|
||
|
||
auto mseg = std::make_unique<MemSegment>(origin, length, static_cast<MemSegment::access_t>(access), sname.str(), buf, initString); | ||
auto mseg = std::make_unique<MemSegment>(origin, length, static_cast<MemSegment::access_t>(access), sname.str(), buf, initString, initEleSet); | ||
add_memsegment(mseg, buf, fsize); | ||
delete[] buf; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer having the seed (optionally) configurable via INI settings. Otherwise it would be quite hard to reproduce bugs,…