We now use boost::icl::interval_set internally, consuming extremely lower amounts of memory. boost::icl was introduced with Boost 1.46; Debian 7.0 comes with 1.49, so this dependency should be no problem anymore. Both the class interface and the memory-map file format stay the same. Change-Id: I38e8148384c90aa493984d0f6280817df00f1702
51 lines
939 B
C++
51 lines
939 B
C++
#include <fstream>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <cassert>
|
|
|
|
#include "MemoryMap.hpp"
|
|
|
|
namespace fail {
|
|
|
|
bool MemoryMap::readFromFile(char const * const filename)
|
|
{
|
|
std::ifstream file(filename);
|
|
if (!file.is_open()) {
|
|
return false;
|
|
}
|
|
|
|
std::string buf;
|
|
unsigned guest_addr, guest_len;
|
|
unsigned count = 0;
|
|
|
|
while (getline(file, buf)) {
|
|
std::stringstream ss(buf, std::ios::in);
|
|
ss >> guest_addr >> guest_len;
|
|
add(guest_addr, guest_len);
|
|
count++;
|
|
}
|
|
// assertion kept from original code; usually something's fishy if the file
|
|
// contains no entries
|
|
assert(count > 0);
|
|
return true;
|
|
}
|
|
|
|
bool MemoryMap::writeToFile(char const * const filename)
|
|
{
|
|
std::ofstream file(filename);
|
|
if (!file.is_open()) {
|
|
return false;
|
|
}
|
|
|
|
#ifndef __puma
|
|
for (address_set::iterator it = as.begin();
|
|
it != as.end(); ++it) {
|
|
file << it->lower() << " " << (it->upper() - it->lower() + 1) << "\n";
|
|
}
|
|
#endif
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|