当前位置: 首页>>代码示例>>C++>>正文


C++ MemoryArea类代码示例

本文整理汇总了C++中MemoryArea的典型用法代码示例。如果您正苦于以下问题:C++ MemoryArea类的具体用法?C++ MemoryArea怎么用?C++ MemoryArea使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MemoryArea类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doRead

bool MainMemoryAccessBase::doRead(uint32_t address, uint32_t* buffer, size_t count)
{
	MemoryArea* cpu = mm->getMemoryArea("CPU");
	if (!cpu)
		return false;

	uint32_t pc = 0;
	cpu->read(0, &pc, 1);

	bool omitFirst = (address & 0x1);
	if (omitFirst) {
		--address;
		++count;
	}
	bool omitLast = (count & 1);
	if (omitLast) {
		++count;
	}

	const hal_id readMacro = devHandle->supportsQuickMemRead() ?
								ID_ReadMemQuick : ID_ReadMemWords;

	HalExecElement* el = new HalExecElement(this->devHandle->checkHalId(readMacro));
	el->appendInputData32(this->getStart() + address);
	el->appendInputData32(static_cast<uint32_t>(count/2));
	el->appendInputData32(pc);

	el->setOutputSize(count);

	ReadElement r(buffer, count, omitFirst, omitLast, 0);
	this->readMap[this->elements.size()] = r;
	this->elements.push_back(el);
	return true;
}
开发者ID:robertinant,项目名称:MSPDebugStack_OS_Package,代码行数:34,代码来源:MainMemoryAccessBase.cpp

示例2: TEST_F

TEST_F( ELFReaderTest, read_symbol_and_rela )
{
  ASSERT_TRUE(m_pInput->hasMemArea());
  ASSERT_TRUE(m_pInput->hasContext());
  m_pInput->setType(Input::Object);

  // -- read symbols
  LDSection* symtab_shdr = m_pInput->context()->getSection(".symtab");
  ASSERT_TRUE(NULL!=symtab_shdr);

  LDSection* strtab_shdr = symtab_shdr->getLink();
  ASSERT_TRUE(NULL!=strtab_shdr);

  MemoryRegion* symtab_region = m_pInput->memArea()->request(
                         m_pInput->fileOffset() + symtab_shdr->offset(),
                         symtab_shdr->size());

  MemoryRegion* strtab_region = m_pInput->memArea()->request(
                         m_pInput->fileOffset() + strtab_shdr->offset(),
                         strtab_shdr->size());
  char* strtab = reinterpret_cast<char*>(strtab_region->start());
  bool result = m_pELFReader->readSymbols(*m_pInput, *m_pIRBuilder,
                                          *symtab_region, strtab);
  ASSERT_TRUE(result);
  ASSERT_EQ("hello.c", std::string(m_pInput->context()->getSymbol(1)->name()));
  ASSERT_EQ("puts", std::string(m_pInput->context()->getSymbol(10)->name()));
  ASSERT_TRUE(NULL==m_pInput->context()->getSymbol(11));
  m_pInput->memArea()->release(symtab_region);
  m_pInput->memArea()->release(strtab_region);

  // -- read relocations
  MemoryArea* mem = m_pInput->memArea();
  LDContext::sect_iterator rs = m_pInput->context()->relocSectBegin();
  ASSERT_TRUE(rs!=m_pInput->context()->relocSectEnd());
  ASSERT_EQ(".rela.text", (*rs)->name());

  uint64_t offset = m_pInput->fileOffset() + (*rs)->offset();
  uint64_t size = (*rs)->size();
  MemoryRegion* region = mem->request(offset, size);
  IRBuilder::CreateRelocData(**rs); /// create relocation data for the header

  ASSERT_EQ(llvm::ELF::SHT_RELA, (*rs)->type());
  ASSERT_TRUE(m_pELFReader->readRela(*m_pInput, **rs, *region));
  mem->release(region);

  const RelocData::RelocationListType &rRelocs =
                          (*rs)->getRelocData()->getRelocationList();
  RelocData::const_iterator rReloc = rRelocs.begin();
  ASSERT_EQ(2, rRelocs.size());
  ASSERT_TRUE(rRelocs.end()!=rReloc);
  ++rReloc; /// test rRelocs[1]
  ASSERT_EQ("puts", std::string(rReloc->symInfo()->name()));
  ASSERT_EQ(llvm::ELF::R_X86_64_PC32, rReloc->type());
  ASSERT_EQ(0x0, rReloc->symValue());
  ASSERT_EQ(-0x4, rReloc->addend());
}
开发者ID:gaojunchen,项目名称:android-4.3-1,代码行数:56,代码来源:ELFReaderTest.cpp

示例3: recordStreamWriteFromMemory

void TraceThreadListener::recordStreamWriteFromMemory(FILE *Stream,
                                                      MemoryArea Area)
{
  ProcessTime = getCIProcessTime();

  EventsOut.write<EventType::FileWriteFromMemory>
                 (ProcessTime,
                  reinterpret_cast<uintptr_t>(Stream),
                  Area.start(),
                  Area.length());
}
开发者ID:mheinsen,项目名称:seec,代码行数:11,代码来源:TraceThreadListener.cpp

示例4: tmp

bool MemoryManagerV3::uploadFunclet(FuncletCode::Type type)
{
	const FuncletCode& funclet = parent->getFunclet(type);
	const uint8_t* code = (uint8_t*)funclet.code();
	const size_t count = funclet.codeSize();

	vector<uint32_t> tmp(code, code + count); // copy funclet into vector
	MemoryArea* ram = this->getMemoryArea("system", 0);

	return ram && ram->write(0, &tmp[0], count) && ram->sync();
}
开发者ID:AlessonDavid,项目名称:libMSP430,代码行数:11,代码来源:MemoryManagerV3.cpp

示例5: FreeEnter

VOID FreeEnter(ADDRINT startAddress, THREADID threadid)
{
	GetLock(&memorySetLock, threadid);
	const MemoryArea area = findMemoryArea(startAddress);
	ADDRINT freeSize = area.size();
	memorySet.erase(area);
	ReleaseLock(&memorySetLock);

	if (freeSize == 0)
		return;

	freeMemoryAddress(startAddress, area.to, threadid);
}
开发者ID:gokhankici,项目名称:datarace,代码行数:13,代码来源:MultiCacheSim_PinDriver.cpp

示例6: BOOST_THROW_EXCEPTION

Module Process::inject(const Library& lib)
{
	if (isInjected(lib))
		BOOST_THROW_EXCEPTION(ex_injection() << e_text("library already in process") << e_library(lib.path()) << e_process(*this));

	// copy the pathname to the remote process
	SIZE_T libPathLen = (lib.path().wstring().size() + 1) * sizeof(wchar_t);
	MemoryArea libFileRemote = alloc(libPathLen, true, MEM_COMMIT, PAGE_READWRITE);
	libFileRemote.write((void*)(lib.path().c_str()));

	PTHREAD_START_ROUTINE loadLibraryW = (PTHREAD_START_ROUTINE)Module::kernel32().getProcAddress("LoadLibraryW");
	/*DWORD exitCode =*/ runInHiddenThread(loadLibraryW, libFileRemote.address());

	return isInjected(lib);
}
开发者ID:guneysu-arsiv,项目名称:injectory,代码行数:15,代码来源:process.cpp

示例7: emitSectionHeader

void ELFObjectWriter::emitSectionHeader(const Module& pModule,
                                        const LinkerConfig& pConfig,
                                        MemoryArea& pOutput) const
{
  typedef typename ELFSizeTraits<SIZE>::Shdr ElfXX_Shdr;

  // emit section header
  unsigned int sectNum = pModule.size();
  unsigned int header_size = sizeof(ElfXX_Shdr) * sectNum;
  MemoryRegion* region = pOutput.request(getLastStartOffset<SIZE>(pModule),
                                         header_size);
  ElfXX_Shdr* shdr = (ElfXX_Shdr*)region->start();

  // Iterate the SectionTable in LDContext
  unsigned int sectIdx = 0;
  unsigned int shstridx = 0; // NULL section has empty name
  for (; sectIdx < sectNum; ++sectIdx) {
    const LDSection *ld_sect   = pModule.getSectionTable().at(sectIdx);
    shdr[sectIdx].sh_name      = shstridx;
    shdr[sectIdx].sh_type      = ld_sect->type();
    shdr[sectIdx].sh_flags     = ld_sect->flag();
    shdr[sectIdx].sh_addr      = ld_sect->addr();
    shdr[sectIdx].sh_offset    = ld_sect->offset();
    shdr[sectIdx].sh_size      = ld_sect->size();
    shdr[sectIdx].sh_addralign = ld_sect->align();
    shdr[sectIdx].sh_entsize   = getSectEntrySize<SIZE>(*ld_sect);
    shdr[sectIdx].sh_link      = getSectLink(*ld_sect, pConfig);
    shdr[sectIdx].sh_info      = getSectInfo(*ld_sect);

    // adjust strshidx
    shstridx += ld_sect->name().size() + 1;
  }
}
开发者ID:rig-project,项目名称:mclinker,代码行数:33,代码来源:ELFObjectWriter.cpp

示例8:

bool MemoryManagerV3::flushAll()
{
	for (unsigned int i = 0; i < this->count(); ++i) 
	{
		MemoryArea* area = this->getMemoryArea(i);
		MemoryCacheCtrl* ctrl = area->getCacheCtrl();
		if (ctrl) 
		{
			if (!ctrl->flush(0, area->getSize()))
				return false;

			ctrl->clear(0, area->getSize());
		}
	}
	return true;
}
开发者ID:AlessonDavid,项目名称:libMSP430,代码行数:16,代码来源:MemoryManagerV3.cpp

示例9: emitProgramHeader

void ELFObjectWriter::emitProgramHeader(MemoryArea& pOutput) const
{
  typedef typename ELFSizeTraits<SIZE>::Ehdr ElfXX_Ehdr;
  typedef typename ELFSizeTraits<SIZE>::Phdr ElfXX_Phdr;

  uint64_t start_offset, phdr_size;

  start_offset = sizeof(ElfXX_Ehdr);
  phdr_size = sizeof(ElfXX_Phdr);
  // Program header must start directly after ELF header
  MemoryRegion *region =
    pOutput.request(start_offset,
                    target().elfSegmentTable().size() * phdr_size);

  ElfXX_Phdr* phdr = (ElfXX_Phdr*)region->start();

  // Iterate the elf segment table in GNULDBackend
  size_t index = 0;
  ELFSegmentFactory::const_iterator seg = target().elfSegmentTable().begin(),
                                 segEnd = target().elfSegmentTable().end();
  for (; seg != segEnd; ++seg, ++index) {
    phdr[index].p_type   = (*seg)->type();
    phdr[index].p_flags  = (*seg)->flag();
    phdr[index].p_offset = (*seg)->offset();
    phdr[index].p_vaddr  = (*seg)->vaddr();
    phdr[index].p_paddr  = (*seg)->paddr();
    phdr[index].p_filesz = (*seg)->filesz();
    phdr[index].p_memsz  = (*seg)->memsz();
    phdr[index].p_align  = (*seg)->align();
  }
}
开发者ID:rig-project,项目名称:mclinker,代码行数:31,代码来源:ELFObjectWriter.cpp

示例10: writeELFHeader

void ELFObjectWriter::writeELFHeader(const LinkerConfig& pConfig,
                                     const Module& pModule,
                                     MemoryArea& pOutput) const
{
  typedef typename ELFSizeTraits<SIZE>::Ehdr ElfXX_Ehdr;
  typedef typename ELFSizeTraits<SIZE>::Shdr ElfXX_Shdr;
  typedef typename ELFSizeTraits<SIZE>::Phdr ElfXX_Phdr;

  // ELF header must start from 0x0
  MemoryRegion *region = pOutput.request(0, sizeof(ElfXX_Ehdr));
  ElfXX_Ehdr* header = (ElfXX_Ehdr*)region->start();

  memcpy(header->e_ident, ElfMagic, EI_MAG3+1);

  header->e_ident[EI_CLASS]      = (SIZE == 32) ? ELFCLASS32 : ELFCLASS64;
  header->e_ident[EI_DATA]       = pConfig.targets().isLittleEndian()?
                                       ELFDATA2LSB : ELFDATA2MSB;
  header->e_ident[EI_VERSION]    = target().getInfo().ELFVersion();
  header->e_ident[EI_OSABI]      = target().getInfo().OSABI();
  header->e_ident[EI_ABIVERSION] = target().getInfo().ABIVersion();

  // FIXME: add processor-specific and core file types.
  switch(pConfig.codeGenType()) {
    case LinkerConfig::Object:
      header->e_type = ET_REL;
      break;
    case LinkerConfig::DynObj:
      header->e_type = ET_DYN;
      break;
    case LinkerConfig::Exec:
      header->e_type = ET_EXEC;
      break;
    default:
      llvm::errs() << "unspported output file type: " << pConfig.codeGenType() << ".\n";
      header->e_type = ET_NONE;
  }
  header->e_machine   = target().getInfo().machine();
  header->e_version   = header->e_ident[EI_VERSION];
  header->e_entry     = getEntryPoint(pConfig, pModule);

  if (LinkerConfig::Object != pConfig.codeGenType())
    header->e_phoff   = sizeof(ElfXX_Ehdr);
  else
    header->e_phoff   = 0x0;

  header->e_shoff     = getLastStartOffset<SIZE>(pModule);
  header->e_flags     = target().getInfo().flags();
  header->e_ehsize    = sizeof(ElfXX_Ehdr);
  header->e_phentsize = sizeof(ElfXX_Phdr);
  header->e_phnum     = target().elfSegmentTable().size();
  header->e_shentsize = sizeof(ElfXX_Shdr);
  header->e_shnum     = pModule.size();
  header->e_shstrndx  = pModule.getSection(".shstrtab")->index();
}
开发者ID:rig-project,项目名称:mclinker,代码行数:54,代码来源:ELFObjectWriter.cpp

示例11: strcpy

/// emitShStrTab - emit section string table
void
ELFObjectWriter::emitShStrTab(const LDSection& pShStrTab,
                              const Module& pModule,
                              MemoryArea& pOutput)
{
  // write out data
  MemoryRegion* region = pOutput.request(pShStrTab.offset(), pShStrTab.size());
  unsigned char* data = region->start();
  size_t shstrsize = 0;
  Module::const_iterator section, sectEnd = pModule.end();
  for (section = pModule.begin(); section != sectEnd; ++section) {
    strcpy((char*)(data + shstrsize), (*section)->name().data());
    shstrsize += (*section)->name().size() + 1;
  }
}
开发者ID:rig-project,项目名称:mclinker,代码行数:16,代码来源:ELFObjectWriter.cpp

示例12: assert

bool ELFObjectReader::readRelocations(Input& pInput)
{
  assert(pInput.hasMemArea());

  MemoryArea* mem = pInput.memArea();
  LDContext::sect_iterator rs, rsEnd = pInput.context()->relocSectEnd();
  for (rs = pInput.context()->relocSectBegin(); rs != rsEnd; ++rs) {
    if (LDFileFormat::Ignore == (*rs)->kind())
      continue;

    uint32_t offset = pInput.fileOffset() + (*rs)->offset();
    uint32_t size = (*rs)->size();
    llvm::StringRef region = mem->request(offset, size);
    IRBuilder::CreateRelocData(**rs); ///< create relocation data for the header
    switch ((*rs)->type()) {
      case llvm::ELF::SHT_RELA: {
        if (!m_pELFReader->readRela(pInput, **rs, region)) {
          return false;
        }
        break;
      }
      case llvm::ELF::SHT_REL: {
        if (!m_pELFReader->readRel(pInput, **rs, region)) {
          return false;
        }
        break;
      }
      default: { ///< should not enter
        return false;
      }
    } // end of switch

  } // end of for all relocation data

  return true;
}
开发者ID:PixNDom,项目名称:android_mediatek_frameworks,代码行数:36,代码来源:ELFObjectReader.cpp

示例13: alloc

void Process::remoteDllMainCall(LPVOID lpModuleEntry, HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	struct DLLMAINCALL dllMainCall = { (DLLMAIN)lpModuleEntry, hModule, ul_reason_for_call, lpReserved };
	SIZE_T DllMainWrapperSize = (SIZE_T)DllMainWrapper_end - (SIZE_T)DllMainWrapper; 

	MemoryArea param          = alloc(sizeof(struct DLLMAINCALL));
	MemoryArea dllCallWrapper = alloc((SIZE_T)((DWORD_PTR)DllMainWrapper_end - (DWORD_PTR)DllMainWrapper));

	param.write((LPCVOID)&dllMainCall, sizeof(struct DLLMAINCALL));
	dllCallWrapper.write((LPCVOID)DllMainWrapper, DllMainWrapperSize);

	runInHiddenThread((LPTHREAD_START_ROUTINE)dllCallWrapper.address(), param.address());
}
开发者ID:hulucc,项目名称:injectory,代码行数:13,代码来源:dllmain_remotecall.cpp

示例14: assert

void EhFrameHdr::emitOutput<32>(MemoryArea& pOutput)
{
    MemoryRegion* ehframehdr_region =
        pOutput.request(m_EhFrameHdr.offset(), m_EhFrameHdr.size());

    MemoryRegion* ehframe_region =
        pOutput.request(m_EhFrame.offset(),
                        m_EhFrame.size());

    uint8_t* data = (uint8_t*)ehframehdr_region->start();
    // version
    data[0] = 1;
    // eh_frame_ptr_enc
    data[1] = DW_EH_PE_pcrel | DW_EH_PE_sdata4;

    // eh_frame_ptr
    uint32_t* eh_frame_ptr = (uint32_t*)(data + 4);
    *eh_frame_ptr = m_EhFrame.addr() - (m_EhFrameHdr.addr() + 4);

    // fde_count
    uint32_t* fde_count = (uint32_t*)(data + 8);
    if (m_EhFrame.hasEhFrame())
        *fde_count = 0;
    else
        *fde_count = m_EhFrame.getEhFrame()->numOfFDEs();

    if (0 != *fde_count) {
        // fde_count_enc
        data[2] = DW_EH_PE_udata4;
        // table_enc
        data[3] = DW_EH_PE_datarel | DW_EH_PE_sdata4;

    }
    else {
        // fde_count_enc
        data[2] = DW_EH_PE_omit;
        // table_enc
        data[3] = DW_EH_PE_omit;
    }

    if (0 != *fde_count) {

        // prepare the binary search table
        typedef std::vector<bit32::Entry> SearchTableType;
        SearchTableType search_table;
        MemoryRegion* ehframe_region =
            pOutput.request(m_EhFrame.offset(), m_EhFrame.size());
        EhFrame::const_fde_iterator fde, fde_end = m_EhFrame.getEhFrame()->fde_end();
        for(fde = m_EhFrame.getEhFrame()->fde_begin(); fde != fde_end; ++fde) {
            assert(*fde != NULL);
            SizeTraits<32>::Offset offset;
            SizeTraits<32>::Address fde_pc;
            SizeTraits<32>::Address fde_addr;
            offset = (*fde)->getOffset();
            fde_pc = computePCBegin(**fde, *ehframe_region);
            fde_addr = m_EhFrame.addr() + offset;
            search_table.push_back(std::make_pair(fde_pc, fde_addr));
        }
        pOutput.release(ehframe_region);

        std::sort(search_table.begin(), search_table.end(), bit32::EntryCompare);

        // write out the binary search table
        uint32_t* bst = (uint32_t*)(data + 12);
        SearchTableType::const_iterator entry, entry_end = search_table.end();
        size_t id = 0;
        for (entry = search_table.begin(); entry != entry_end; ++entry) {
            bst[id++] = (*entry).first - m_EhFrameHdr.addr();
            bst[id++] = (*entry).second - m_EhFrameHdr.addr();
        }
    }
    pOutput.release(ehframehdr_region);
    pOutput.release(ehframe_region);
}
开发者ID:gaojunchen,项目名称:android-4.3-1,代码行数:74,代码来源:EhFrameHdr.cpp

示例15: writeSection

void ELFObjectWriter::writeSection(MemoryArea& pOutput, LDSection *section)
{
  MemoryRegion* region;
  // Request output region
  switch (section->kind()) {
  case LDFileFormat::Note:
    if (section->getSectionData() == NULL)
      return;
    // Fall through
  case LDFileFormat::Regular:
  case LDFileFormat::Relocation:
  case LDFileFormat::Target:
  case LDFileFormat::Debug:
  case LDFileFormat::GCCExceptTable:
  case LDFileFormat::EhFrame: {
    region = pOutput.request(section->offset(), section->size());
    if (NULL == region) {
      llvm::report_fatal_error(llvm::Twine("cannot get enough memory region for output section `") +
                               llvm::Twine(section->name()) +
                               llvm::Twine("'.\n"));
    }
    break;
  }
  case LDFileFormat::Null:
  case LDFileFormat::NamePool:
  case LDFileFormat::BSS:
  case LDFileFormat::MetaData:
  case LDFileFormat::Version:
  case LDFileFormat::EhFrameHdr:
  case LDFileFormat::StackNote:
    // Ignore these sections
    return;
  default:
    llvm::errs() << "WARNING: unsupported section kind: "
                 << section->kind()
                 << " of section "
                 << section->name()
                 << ".\n";
    return;
  }

  // Write out sections with data
  switch(section->kind()) {
  case LDFileFormat::GCCExceptTable:
  case LDFileFormat::EhFrame:
  case LDFileFormat::Regular:
  case LDFileFormat::Debug:
  case LDFileFormat::Note:
    // FIXME: if optimization of exception handling sections is enabled,
    // then we should emit these sections by the other way.
    emitSectionData(*section, *region);
    break;
  case LDFileFormat::Relocation:
    // sort relocation for the benefit of the dynamic linker.
    target().sortRelocation(*section);

    emitRelocation(m_Config, *section, *region);
    break;
  case LDFileFormat::Target:
    target().emitSectionData(*section, *region);
    break;
  default:
    llvm_unreachable("invalid section kind");
  }
}
开发者ID:rig-project,项目名称:mclinker,代码行数:65,代码来源:ELFObjectWriter.cpp


注:本文中的MemoryArea类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。