本文整理汇总了C++中ExtentMap类的典型用法代码示例。如果您正苦于以下问题:C++ ExtentMap类的具体用法?C++ ExtentMap怎么用?C++ ExtentMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExtentMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s
/** Returns a list of parts of a single section that have been referenced. The offsets are relative to the start of the
* section. */
ExtentMap
SgAsmGenericSection::get_referenced_extents() const
{
ExtentMap retval;
if (0==get_size())
return retval;
Extent s(get_offset(), get_size());
const ExtentMap &file_extents = get_file()->get_referenced_extents();
for (ExtentMap::const_iterator i=file_extents.begin(); i!=file_extents.end(); i++) {
Extent e = i->first;
if (e.contained_in(s)) {
retval.insert(Extent(e.first()-get_offset(), e.size()));
} else if (e.left_of(s) || e.right_of(s)) {
/*void*/
} else if (e.contains(s)) {
retval.insert(Extent(0, get_size()));
} else if (e.begins_before(s)) {
retval.insert(Extent(0, e.first()+e.size()-get_offset()));
} else if (e.ends_after(s)) {
retval.insert(Extent(e.first()-get_offset(), get_offset()+get_size()-e.first()));
} else {
assert(!"invalid extent overlap category");
abort();
}
}
return retval;
}
示例2: main
int main(int argc, char **argv)
{
ExtentMap em;
string prefix;
if (argc > 2)
usage(argv[0]);
else if (argc == 2)
prefix = argv[1];
else
prefix = "BRM_state";
idbdatafile::IDBPolicy::configIDBPolicy();
try {
em.load(prefix);
cout << "OK." << endl;
}
catch (exception &e) {
cout << "Load failed." << endl;
return 1;
}
return 0;
}
示例3: get_unreferenced_extents
/** Write holes (unreferenced areas) back to the file */
void
SgAsmGenericSection::unparse_holes(std::ostream &f) const
{
#if 0 /*DEBUGGING*/
ExtentMap holes = get_unreferenced_extents();
fprintf(stderr, "Section \"%s\", 0x%"PRIx64" bytes\n", get_name()->get_string(true).c_str(), get_size());
holes.dump_extents(stderr, " ", "");
#endif
// unparse(f, get_unreferenced_extents());
}
示例4: main
int main(int argc, char** argv)
{
int c;
string pname(argv[0]);
opterr = 0;
while ((c = getopt(argc, argv, "vdh")) != EOF)
switch (c)
{
case 'v':
vflg++;
break;
case 'd':
dflg = true;
break;
case 'h':
case '?':
default:
usage(pname);
return (c == 'h' ? 0 : 1);
break;
}
const Config* cf = Config::makeConfig();
DBRoot = cf->getConfig("SystemConfig", "DBRoot");
pattern = DBRoot + "/[0-9][0-9][0-9].dir/[0-9][0-9][0-9].dir/[0-9][0-9][0-9].dir/FILE[0-9][0-9][0-9].cdf";
if (vflg)
{
cout << "Using DBRoot " << DBRoot << endl;
}
if (access(DBRoot.c_str(), X_OK) != 0)
{
cerr << "Could not scan DBRoot " << DBRoot << '!' << endl;
return 1;
}
ExtentMap em;
extentSize = em.getExtentSize();
if (vflg)
{
cout << "System extent size is " << extentSize << " blocks" << endl;
}
if (nftw(DBRoot.c_str(), walkDB, 64, FTW_PHYS|FTW_ACTIONRETVAL) != 0)
{
cerr << "Error processing files in DBRoot " << DBRoot << '!' << endl;
return 1;
}
return 0;
}
示例5: abort
/** Precipitates individual extents into larger extents by combining individual extents that are separated by an amount less
* than or equal to some specified @p reagent value. Individual elements that would have been adjacent have already
* been combined by the other modifying methods (insert, erase, etc). */
void
ExtentMap::precipitate(rose_addr_t reagent)
{
abort(); // NOT IMPLEMENTED
ExtentMap result;
for (iterator i=begin(); i!=end(); /*void*/) {
ExtentPair left = *i++;
for (/*void*/; i!=end() && left.first+left.second+reagent >= i->first; i++)
left.second = (i->first + i->second) - left.first;
result.insert(left);
}
*this = result;
}
示例6: assert
/** Write just the specified regions back to the file */
void
SgAsmGenericSection::unparse(std::ostream &f, const ExtentMap &map) const
{
for (ExtentMap::const_iterator i=map.begin(); i!=map.end(); ++i) {
Extent e = i->first;
assert(e.first()+e.size() <= get_size());
const unsigned char *extent_data;
if (e.first() >= p_data.size()) {
extent_data = NULL;
} else if (e.first() + e.size() > p_data.size()) {
extent_data = &p_data[e.first()];
} else {
extent_data = &p_data[e.first()];
}
if (extent_data)
write(f, e.first(), e.size(), extent_data);
}
}
示例7: addVectorToDatabase
void
addVectorToDatabase(const SqlDatabase::TransactionPtr &tx, const SignatureVector& vec, const std::string& functionName,
size_t functionId, size_t indexWithinFunction, const std::string& normalizedUnparsedInstructions,
SgAsmx86Instruction* firstInsn[], const std::string& filename, size_t windowSize, size_t stride)
{
++numVectorsGenerated;
vector<uint8_t> compressedCounts = compressVector(vec.getBase(), SignatureVector::Size);
size_t vectorSum = 0;
for (size_t i=0; i<SignatureVector::Size; ++i)
vectorSum += vec[i];
ExtentMap extent;
for (size_t i=0; i<windowSize; ++i)
extent.insert(Extent(firstInsn[i]->get_address(), firstInsn[i]->get_size()));
unsigned char md[16];
MD5((const unsigned char*)normalizedUnparsedInstructions.data(), normalizedUnparsedInstructions.size(), md);
SqlDatabase::StatementPtr cmd = tx->statement("insert into vectors"
// 0 1 2 3 4 5
" (id, function_id, index_within_function, line, last_insn_va, size,"
// 6 7 8
"sum_of_counts, counts_b64, instr_seq_b64)"
" values (?,?,?,?,?,?,?,?,?)");
int vector_id = tx->statement("select coalesce(max(id),0)+1 from vectors")->execute_int(); // 1-origin
cmd->bind(0, vector_id);
cmd->bind(1, functionId);
cmd->bind(2, indexWithinFunction);
cmd->bind(3, firstInsn[0]->get_address());
cmd->bind(4, firstInsn[windowSize-1]->get_address());
cmd->bind(5, extent.size());
cmd->bind(6, vectorSum);
cmd->bind(7, StringUtility::encode_base64(&compressedCounts[0], compressedCounts.size()));
cmd->bind(8, StringUtility::encode_base64(md, 16));
cmd->execute();
}
示例8:
/** Obtains the virtual address of the Hint/Name Table. The Hint/Name Table is an implicit table--the PE file format
* specification talks about such a table, but it is not actually defined anywhere in the PE file. Instead, various Import
* Lookup Table and Import Address Table entries might point to individual Hint/Name pairs, which collectively form an
* implicit Hint/Name Table. There is no requirement that the Hint/Name pairs are contiguous in the address space, and indeed
* they often are not. Therefore, the only way to describe the location of the Hint/Name Table is by a list of addresses.
*
* This function will scan this Import Directory's import items, observe which items make references to Hint/Name pairs that
* have known addresses, and add those areas of virtual memory to the specified extent map. This function returns the number
* of ILT entries that reference a Hint/Name pair. */
size_t
SgAsmPEImportDirectory::hintname_table_extent(ExtentMap &extent/*in,out*/) const
{
size_t retval = 0;
const SgAsmPEImportItemPtrList &imports = get_imports()->get_vector();
for (SgAsmPEImportItemPtrList::const_iterator ii=imports.begin(); ii!=imports.end(); ++ii) {
SgAsmPEImportItem *import = *ii;
if (!import->get_by_ordinal() && import->get_hintname_rva().get_rva()!=0 && import->get_hintname_nalloc()>0) {
size_t nbytes = std::min(import->get_hintname_nalloc(), import->hintname_required_size());
extent.insert(Extent(import->get_hintname_rva().get_va(), nbytes));
++retval;
}
}
return retval;
}
示例9: toAddressIntervalSet
AddressIntervalSet toAddressIntervalSet(const ExtentMap &x) {
AddressIntervalSet retval;
for (ExtentMap::const_iterator iter=x.begin(); iter!=x.end(); ++iter)
retval.insert(toAddressInterval(iter->first));
return retval;
}
示例10: toExtentMap
ExtentMap toExtentMap(const AddressIntervalSet &x) {
ExtentMap retval;
BOOST_FOREACH (const AddressInterval &interval, x.intervals())
retval.insert(toExtent(interval));
return retval;
}
示例11: extentMap_good_1
void extentMap_good_1()
{
ExtentMap em;
int i, err, oid, iterations = 1300; // (EM_INITIAL_SIZE + 3*EM_INCREMENT)
int caughtException = 0, allocdSize;
uint32_t fbo, hwm;
BRM::HWM_t hwm2;
BRM::VER_t txnID;
vector<LBID_t> lbids;
const uint32_t extentSize = em.getExtentSize();
em.load(string("EMImage"));
em.checkConsistency();
for (i = 0; i < iterations; i++)
{
err = em.lookup(static_cast<LBID_t>(i * extentSize), oid, fbo);
CPPUNIT_ASSERT(err == 0);
CPPUNIT_ASSERT(oid == i);
CPPUNIT_ASSERT(fbo == 0);
if (i != 0)
{
err = em.lookup(static_cast<LBID_t>(i * extentSize - 1), oid, fbo);
CPPUNIT_ASSERT(err == 0);
CPPUNIT_ASSERT(oid == i - 1);
CPPUNIT_ASSERT(fbo == extentSize - 1);
}
if (i != iterations - 1)
{
err = em.lookup(static_cast<LBID_t>(i * extentSize + 1), oid, fbo);
CPPUNIT_ASSERT(err == 0);
CPPUNIT_ASSERT(oid == i);
CPPUNIT_ASSERT(fbo == 1);
}
}
em.checkConsistency();
err = em.lookup(static_cast<LBID_t>(i * extentSize), oid, fbo);
CPPUNIT_ASSERT(err == -1);
for (i = 0; i < iterations; i++)
{
err = em.getBulkInsertVars(static_cast<LBID_t>(i * extentSize),
hwm2, txnID);
CPPUNIT_ASSERT(err == 0);
CPPUNIT_ASSERT(hwm2 == 0);
CPPUNIT_ASSERT(txnID == 0);
err = em.setBulkInsertVars(static_cast<LBID_t>(i * extentSize),
i, i + 1);
em.confirmChanges();
CPPUNIT_ASSERT(err == 0);
err = em.getBulkInsertVars(static_cast<LBID_t>(i * extentSize),
hwm2, txnID);
CPPUNIT_ASSERT(err == 0);
CPPUNIT_ASSERT(hwm2 == static_cast<LBID_t>(i));
CPPUNIT_ASSERT(txnID == static_cast<VER_t>(i + 1));
hwm = em.getHWM(i);
CPPUNIT_ASSERT(hwm == 0);
em.setHWM(i, (i > (extentSize - 1) ? extentSize - 1 : i));
em.confirmChanges();
hwm = em.getHWM(i);
CPPUNIT_ASSERT(hwm == static_cast<uint32_t>(i > extentSize - 1 ? extentSize - 1 : i));
}
em.checkConsistency();
#ifdef BRM_DEBUG
caughtException = 0;
try
{
em.setHWM(i, hwm);
}
catch (std::invalid_argument e)
{
caughtException = 1;
}
em.undoChanges();
CPPUNIT_ASSERT(caughtException == 1);
#endif
for (i = 0; i < iterations; i++)
{
em.deleteOID(i);
em.confirmChanges();
}
#ifdef BRM_DEBUG
caughtException = 0;
try
{
em.deleteOID(i);
}
catch (std::invalid_argument& e)
//.........这里部分代码省略.........
示例12: src2addr
rose_addr_t
DwarfLineMapper::src2first_addr(const SrcInfo &srcinfo) const
{
ExtentMap ex = src2addr(srcinfo);
return ex.empty() ? 0 : ex.min();
}
示例13: new_region_stats
Partitioner::RegionStats *
Partitioner::region_statistics(const ExtentMap &addresses)
{
RegionStats *stats = new_region_stats();
assert(stats!=NULL);
size_t nbytes = addresses.size();
if (0==nbytes)
return stats;
stats->add_sample(RegionStats::RA_NBYTES, nbytes);
ExtentMap not_addresses = addresses.invert<ExtentMap>();
Disassembler::AddressSet worklist; // addresses waiting to be disassembled recursively
InstructionMap insns_found; // all the instructions we found herein
ExtentMap insns_extent; // memory used by the instructions we've found
ExtentMap pending = addresses; // addresses we haven't looked at yet
/* Undirected local control flow graph used to count connected components */
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> CFG;
typedef boost::graph_traits<CFG>::vertex_descriptor CFGVertex;
typedef std::map<rose_addr_t, CFGVertex> Addr2Vertex;
CFG cfg;
Addr2Vertex va2id;
/* Statistics */
size_t nstarts=0; // number of times the recursive disassembler was started
size_t nfails=0; // number of disassembler failures
size_t noverlaps=0; // instructions overlapping with a previously found instruction
size_t nincomplete=0; // number of instructions with unknown successors
size_t nfallthrough=0; // number of branches to fall-through address within our "addresses"
size_t ncalls=0; // number of function calls outside our "addresses"
size_t nnoncalls=0; // number of branches to non-functions outside our "addresses"
size_t ninternal=0; // number of non-fallthrough internal branches
while (!pending.empty()) {
rose_addr_t start_va = pending.min();
worklist.insert(start_va);
++nstarts;
while (!worklist.empty()) {
rose_addr_t va = *worklist.begin();
worklist.erase(worklist.begin());
/* Obtain (disassemble) the instruction and make sure it falls entirely within the "addresses" */
Instruction *insn = find_instruction(va);
if (!insn) {
++nfails;
pending.erase(Extent(va));
continue;
}
Extent ie(va, insn->get_size());
if (not_addresses.overlaps(ie)) {
++nfails;
pending.erase(Extent(va));
continue;
}
/* The disassembler can also return an "unknown" instruction when failing, depending on how it is invoked. */
if (insn->node->is_unknown()) {
++nfails;
pending.erase(Extent(va, insn->get_size()));
continue;
}
insns_found.insert(std::make_pair(va, insn));
rose_addr_t fall_through_va = va + insn->get_size();
/* Does this instruction overlap with any we've already found? */
if (insns_extent.overlaps(ie))
++noverlaps;
pending.erase(Extent(va, insn->get_size()));
insns_extent.insert(ie);
/* Find instruction successors by looking only at the instruction itself. This is simpler, but less rigorous
* method than finding successors a basic block at a time. For instance, we'll find both sides of a branch
* instruction even if the more rigorous method determined that one side or the other is always taken. But this is
* probably what we want here anyway for determining whether something looks like code. */
bool complete;
Disassembler::AddressSet succs = insn->get_successors(&complete);
if (!complete)
++nincomplete;
/* Add instruction as vertex to CFG */
std::pair<Addr2Vertex::iterator, bool> inserted = va2id.insert(std::make_pair(va, va2id.size()));
if (inserted.second) {
CFGVertex vertex __attribute__((unused)) = add_vertex(cfg);
assert(vertex==inserted.first->second);
}
/* Classify the various successors. */
for (Disassembler::AddressSet::const_iterator si=succs.begin(); si!=succs.end(); ++si) {
rose_addr_t succ_va = *si;
if (succ_va==fall_through_va) {
++nfallthrough;
if (pending.find(succ_va)!=pending.end())
worklist.insert(succ_va);
/* Add edge to CFG graph */
va2id.insert(std::make_pair(succ_va, va2id.size()));
add_edge(va2id[va], va2id[succ_va], cfg);
//.........这里部分代码省略.........
示例14: extentMap_freelist
void extentMap_freelist()
{
ExtentMap em;
int i, allocdSize, iterations = 1400; // (EM_INITIAL_SIZE + 4*EM_INCREMENT)
vector<LBID_t> lbids;
const int extentSize = em.getExtentSize();
for (i = 0; i < iterations; i++)
{
em.createExtent(extentSize, i, lbids, allocdSize);
em.confirmChanges();
CPPUNIT_ASSERT(lbids.back() == static_cast<LBID_t>(i * extentSize));
}
em.checkConsistency();
//frag the lbid space to blow up the free list
for (i = 0; i < iterations; i += 2)
{
em.deleteOID(i);
em.confirmChanges();
}
em.checkConsistency();
//fill in the holes
for (i = 0; i < iterations; i += 2)
{
em.createExtent(extentSize, i, lbids, allocdSize);
em.confirmChanges();
}
for (i = 0; i < iterations; i += 2)
{
em.deleteOID(i);
em.confirmChanges();
}
for (i = 1; i < iterations; i += 2)
{
em.deleteOID(i);
em.confirmChanges();
}
em.checkConsistency();
}
示例15: ROSE_ASSERT
void
SgAsmGenericFile::shift_extend(SgAsmGenericSection *s, rose_addr_t sa, rose_addr_t sn, AddressSpace space, Elasticity elasticity)
{
ROSE_ASSERT(s!=NULL);
ROSE_ASSERT(s->get_file()==this);
ROSE_ASSERT((space & (ADDRSP_FILE|ADDRSP_MEMORY)) != 0);
const bool debug = false;
static size_t ncalls=0;
char p[256];
if (debug) {
const char *space_s="unknown";
if (space & ADDRSP_FILE) {
space_s = "file";
} else if (space & ADDRSP_MEMORY) {
space_s = "memory";
}
sprintf(p, "SgAsmGenericFile::shift_extend[%" PRIuPTR "]: ", ncalls++);
fprintf(stderr, "%s -- START --\n", p);
fprintf(stderr, "%s S = [%d] \"%s\"\n", p, s->get_id(), s->get_name()->get_string(true).c_str());
fprintf(stderr, "%s %s Sa=0x%08" PRIx64 " (%" PRIu64 "), Sn=0x%08" PRIx64 " (%" PRIu64 ")\n",
p, space_s, sa, sa, sn, sn);
fprintf(stderr, "%s elasticity = %s\n", p, (ELASTIC_NONE==elasticity ? "none" :
ELASTIC_UNREF==elasticity ? "unref" :
ELASTIC_HOLE==elasticity ? "unref+holes" :
"unknown"));
}
/* No-op case */
if (0==sa && 0==sn) {
if (debug) {
fprintf(stderr, "%s No change necessary.\n", p);
fprintf(stderr, "%s -- END --\n", p);
}
return;
}
bool filespace = (space & ADDRSP_FILE)!=0;
bool memspace = (space & ADDRSP_MEMORY)!=0;
rose_addr_t align=1, aligned_sa, aligned_sasn;
SgAsmGenericSectionPtrList neighbors, villagers;
ExtentMap amap; /* address mappings for all extents */
Extent sp;
/* Get a list of all sections that may need to be adjusted. */
SgAsmGenericSectionPtrList all;
switch (elasticity) {
case ELASTIC_NONE:
case ELASTIC_UNREF:
all = filespace ? get_sections() : get_mapped_sections();
break;
case ELASTIC_HOLE:
all = filespace ? get_sections(false) : get_mapped_sections();
break;
}
if (debug) {
fprintf(stderr, "%s Following sections are in 'all' set:\n", p);
for (size_t i=0; i<all.size(); i++) {
Extent ep;
if (filespace) {
ep = all[i]->get_file_extent();
} else {
ROSE_ASSERT(all[i]->is_mapped());
ep = all[i]->get_mapped_preferred_extent();
}
fprintf(stderr, "%s 0x%08" PRIx64 " 0x%08" PRIx64 " 0x%08" PRIx64 " [%d] \"%s\"\n",
p, ep.relaxed_first(), ep.size(), ep.relaxed_first()+ep.size(), all[i]->get_id(),
all[i]->get_name()->get_string(true).c_str());
}
}
for (size_t pass=0; pass<2; pass++) {
if (debug) {
fprintf(stderr, "%s -- %s --\n",
p, 0==pass?"FIRST PASS":"SECOND PASS (after making a larger hole)");
}
/* S offset and size in file or memory address space */
if (filespace) {
sp = s->get_file_extent();
} else if (!memspace || !s->is_mapped()) {
return; /*nothing to do*/
} else {
sp = s->get_mapped_preferred_extent();
}
/* Build address map */
for (size_t i=0; i<all.size(); i++) {
if (filespace) {
amap.insert(all[i]->get_file_extent());
} else {
ROSE_ASSERT(all[i]->is_mapped());
amap.insert(all[i]->get_mapped_preferred_extent());
}
}
if (debug) {
fprintf(stderr, "%s Address map:\n", p);
amap.dump_extents(stderr, (std::string(p)+" ").c_str(), "amap");
fprintf(stderr, "%s Extent of S:\n", p);
//.........这里部分代码省略.........