-
Notifications
You must be signed in to change notification settings - Fork 38
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 3 commits
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 |
---|---|---|
|
@@ -53,6 +53,7 @@ | |
#include "etiss/System.h" | ||
#include "etiss/make_unique.h" | ||
#include <fstream> | ||
#include <random> | ||
|
||
#include <cstring> | ||
#include <iostream> | ||
|
@@ -88,8 +89,15 @@ class MemSegment | |
const etiss::uint64 size_; | ||
access_t mode_; | ||
|
||
/// @brief Constructor of Memory Segment | ||
/// @param start_addr Start address of segment | ||
/// @param size Size in bytes | ||
/// @param mode Access Mode (R/W/X) | ||
/// @param name Segment name | ||
/// @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) | ||
etiss::uint8 *mem = nullptr, std::string initString = 0) | ||
: name_(name), start_addr_(start_addr), end_addr_(start_addr + size - 1), size_(size), mode_(mode) | ||
{ | ||
if (mem) | ||
|
@@ -99,10 +107,35 @@ class MemSegment | |
else | ||
{ | ||
mem_ = new etiss::uint8[size]; | ||
memInit(initString); | ||
self_allocated_ = true; | ||
} | ||
} | ||
|
||
// Can be overwritten afterwards with load_elf | ||
void memInit(std::string initString = 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. std::string default argument should be |
||
{ | ||
static std::default_random_engine generator{ static_cast<uint64_t>(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. I would prefer having the seed (optionally) configurable via INI settings. Otherwise it would be quite hard to reproduce bugs,… |
||
std::uniform_int_distribution<int> random_char_{ 0, 255 }; | ||
|
||
if (initString == "") | ||
{ | ||
for (etiss::uint64 i = 0; i < size_; ++i) | ||
{ | ||
mem_[i] = random_char_(generator); | ||
} | ||
} | ||
else | ||
{ | ||
const char* data = initString.c_str(); | ||
for (etiss::uint64 i = 0; i < size_; ++i) | ||
{ | ||
mem_[i] = data[i%strlen(data)]; | ||
} | ||
} | ||
} | ||
|
||
|
||
virtual ~MemSegment(void) | ||
{ | ||
if (self_allocated_ == true) | ||
|
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.
std::string default argument should be
= ""
or removed since it now will be managed by etiss::initialize