コード例 #1
0
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;
  }
}
コード例 #2
0
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();
  }
}
コード例 #3
0
uint64_t NyuziGNULDBackend::emitSectionData(const LDSection& pSection,
                                              MemoryRegion& pRegion) const
{
  assert(pRegion.size() && "Size of MemoryRegion is zero!");

  return pRegion.size();
}
コード例 #4
0
/// isMyFormat
bool ELFDynObjReader::isMyFormat(Input &pInput, bool &pContinue) const
{
    assert(pInput.hasMemArea());

    // Don't warning about the frequently requests.
    // MemoryArea has a list of cache to handle this.
    size_t hdr_size = m_pELFReader->getELFHeaderSize();
    if (pInput.memArea()->size() < hdr_size)
        return false;

    MemoryRegion* region = pInput.memArea()->request(pInput.fileOffset(),
                           hdr_size);

    uint8_t* ELF_hdr = region->start();
    bool result = true;
    if (!m_pELFReader->isELF(ELF_hdr)) {
        pContinue = true;
        result = false;
    } else if (Input::DynObj != m_pELFReader->fileType(ELF_hdr)) {
        pContinue = true;
        result = false;
    } else if (!m_pELFReader->isMyEndian(ELF_hdr)) {
        pContinue = false;
        result = false;
    } else if (!m_pELFReader->isMyMachine(ELF_hdr)) {
        pContinue = false;
        result = false;
    }
    pInput.memArea()->release(region);
    return result;
}
コード例 #5
0
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();
}
コード例 #6
0
ファイル: emsa1_bsi.cpp プロジェクト: Amaterasu27/miktex
/*
* EMSA1 BSI Encode Operation
*/
SecureVector<byte> EMSA1_BSI::encoding_of(const MemoryRegion<byte>& msg,
                                          u32bit output_bits,
                                          RandomNumberGenerator&)
   {
   if(msg.size() != hash_ptr()->OUTPUT_LENGTH)
      throw Encoding_Error("EMSA1_BSI::encoding_of: Invalid size for input");

   if(8*msg.size() <= output_bits)
      return msg;

   throw Encoding_Error("EMSA1_BSI::encoding_of: max key input size exceeded");
   }
uint64_t X86GNULDBackend::emitSectionData(const LDSection& pSection,
                                          MemoryRegion& pRegion) const
{
  assert(pRegion.size() && "Size of MemoryRegion is zero!");

  const ELFFileFormat* FileFormat = getOutputFormat();
  assert(FileFormat &&
         "ELFFileFormat is NULL in X86GNULDBackend::emitSectionData!");

  unsigned int EntrySize = 0;
  uint64_t RegionSize = 0;

  if (&pSection == &(FileFormat->getPLT())) {
    assert(m_pPLT && "emitSectionData failed, m_pPLT is NULL!");

    unsigned char* buffer = pRegion.getBuffer();

    m_pPLT->applyPLT0();
    m_pPLT->applyPLT1();
    X86PLT::iterator it = m_pPLT->begin();
    unsigned int plt0_size = llvm::cast<PLTEntryBase>((*it)).size();

    memcpy(buffer, llvm::cast<PLTEntryBase>((*it)).getValue(), plt0_size);
    RegionSize += plt0_size;
    ++it;

    PLTEntryBase* plt1 = 0;
    X86PLT::iterator ie = m_pPLT->end();
    while (it != ie) {
      plt1 = &(llvm::cast<PLTEntryBase>(*it));
      EntrySize = plt1->size();
      memcpy(buffer + RegionSize, plt1->getValue(), EntrySize);
      RegionSize += EntrySize;
      ++it;
    }
  }

  else if (&pSection == &(FileFormat->getGOT())) {
    RegionSize += emitGOTSectionData(pRegion);
  }

  else if (&pSection == &(FileFormat->getGOTPLT())) {
    RegionSize += emitGOTPLTSectionData(pRegion, FileFormat);
  }

  else {
    fatal(diag::unrecognized_output_sectoin)
            << pSection.name()
            << "*****@*****.**";
  }
  return RegionSize;
}
コード例 #8
0
ファイル: tls_server.cpp プロジェクト: BenjaminSchiborr/safe
/*
* Split up and process handshake messages
*/
void TLS_Server::read_handshake(byte rec_type,
                                const MemoryRegion<byte>& rec_buf)
   {
   if(rec_type == HANDSHAKE)
      {
      if(!state)
         state = new Handshake_State;
      state->queue.write(&rec_buf[0], rec_buf.size());
      }

   while(true)
      {
      Handshake_Type type = HANDSHAKE_NONE;
      SecureVector<byte> contents;

      if(rec_type == HANDSHAKE)
         {
         if(state->queue.size() >= 4)
            {
            byte head[4] = { 0 };
            state->queue.peek(head, 4);

            const size_t length = make_u32bit(0, head[1], head[2], head[3]);

            if(state->queue.size() >= length + 4)
               {
               type = static_cast<Handshake_Type>(head[0]);
               contents.resize(length);
               state->queue.read(head, 4);
               state->queue.read(&contents[0], contents.size());
               }
            }
         }
      else if(rec_type == CHANGE_CIPHER_SPEC)
         {
         if(state->queue.size() == 0 && rec_buf.size() == 1 && rec_buf[0] == 1)
            type = HANDSHAKE_CCS;
         else
            throw Decoding_Error("Malformed ChangeCipherSpec message");
         }
      else
         throw Decoding_Error("Unknown message type in handshake processing");

      if(type == HANDSHAKE_NONE)
         break;

      process_handshake_msg(type, contents);

      if(type == HANDSHAKE_CCS || !state)
         break;
      }
   }
コード例 #9
0
/// 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;
  }
}
コード例 #10
0
/// isThinArchive
bool GNUArchiveReader::isThinArchive(Input& pInput) const
{
  assert(pInput.hasMemArea());
  MemoryRegion* region = pInput.memArea()->request(pInput.fileOffset(),
                                                   Archive::MAGIC_LEN);
  const char* str = reinterpret_cast<const char*>(region->getBuffer());

  bool result = false;
  assert(NULL != str);
  if (isThinArchive(str))
    result = true;

  pInput.memArea()->release(region);
  return result;
}
コード例 #11
0
ファイル: ELFDynamic.cpp プロジェクト: aurorarom/JsonUtil
/// emit
void ELFDynamic::emit(const LDSection& pSection, MemoryRegion& pRegion) const
{
  if (pRegion.size() < pSection.size()) {
    llvm::report_fatal_error(llvm::Twine("the given memory is smaller") +
                             llvm::Twine(" than the section's demaind.\n"));
  }

  uint8_t* address = (uint8_t*)pRegion.begin();
  EntryListType::const_iterator entry, entryEnd = m_NeedList.end();
  for (entry = m_NeedList.begin(); entry != entryEnd; ++entry)
    address += (*entry)->emit(address);

  entryEnd = m_EntryList.end();
  for (entry = m_EntryList.begin(); entry != entryEnd; ++entry)
    address += (*entry)->emit(address);
}
コード例 #12
0
//! Returns true if the address filter overlaps \a region.
bool StExecutableImage::AddressFilter::matchesMemoryRegion(const MemoryRegion &region) const
{
    uint32_t firstByte = region.m_address;   // first byte occupied by this region
    uint32_t lastByte = region.endAddress(); // last used byte in this region
    return (firstByte >= m_fromAddress && firstByte <= m_toAddress) ||
           (lastByte >= m_fromAddress && lastByte <= m_toAddress);
}
コード例 #13
0
ファイル: blowfish.cpp プロジェクト: BenjaminSchiborr/safe
/*
* Generate one of the Sboxes
*/
void Blowfish::generate_sbox(MemoryRegion<u32bit>& box,
                             u32bit& L, u32bit& R,
                             const byte salt[16],
                             size_t salt_off) const
   {
   const u32bit* S1 = &S[0];
   const u32bit* S2 = &S[256];
   const u32bit* S3 = &S[512];
   const u32bit* S4 = &S[768];

   for(size_t i = 0; i != box.size(); i += 2)
      {
      L ^= load_be<u32bit>(salt, (i + salt_off) % 4);
      R ^= load_be<u32bit>(salt, (i + salt_off + 1) % 4);

      for(size_t j = 0; j != 16; j += 2)
         {
         L ^= P[j];
         R ^= ((S1[get_byte(0, L)]  + S2[get_byte(1, L)]) ^
                S3[get_byte(2, L)]) + S4[get_byte(3, L)];

         R ^= P[j+1];
         L ^= ((S1[get_byte(0, R)]  + S2[get_byte(1, R)]) ^
                S3[get_byte(2, R)]) + S4[get_byte(3, R)];
         }

      u32bit T = R; R = L ^ P[16]; L = T ^ P[17];
      box[i] = L;
      box[i+1] = R;
      }
   }
コード例 #14
0
static void readSymbolTableEntries(Archive& pArchive, MemoryRegion& pMemRegion)
{
  typedef typename SizeTraits<SIZE>::Offset Offset;

  const Offset* data = reinterpret_cast<const Offset*>(pMemRegion.getBuffer());

  // read the number of symbols
  Offset number = 0;
  if (llvm::sys::IsLittleEndianHost)
    number = mcld::bswap<SIZE>(*data);
  else
    number = *data;

  // set up the pointers for file offset and name offset
  ++data;
  const char* name = reinterpret_cast<const char*>(data + number);

  // add the archive symbols
  for (Offset i = 0; i < number; ++i) {
    if (llvm::sys::IsLittleEndianHost)
      pArchive.addSymbol(name, mcld::bswap<SIZE>(*data));
    else
      pArchive.addSymbol(name, *data);
    name += strlen(name) + 1;
    ++data;
  }
}
コード例 #15
0
// SetUp() will be called immediately before each test.
void ELFReaderTest::SetUp()
{
  Path path(TOPDIR);
  path.append("unittests/test_x86_64.o");

  m_pInput = m_pIRBuilder->ReadInput("test_x86_64", path);
  ASSERT_TRUE(NULL!=m_pInput);

  ASSERT_TRUE(m_pInput->hasMemArea());
  size_t hdr_size = m_pELFReader->getELFHeaderSize();
  MemoryRegion* region = m_pInput->memArea()->request(m_pInput->fileOffset(),
                                                    hdr_size);
  uint8_t* ELF_hdr = region->start();
  bool shdr_result = m_pELFReader->readSectionHeaders(*m_pInput, ELF_hdr);
  m_pInput->memArea()->release(region);
  ASSERT_TRUE(shdr_result);
}
コード例 #16
0
/// readDSO
bool ELFDynObjReader::readDSO(Input& pInput)
{
  assert(pInput.hasMemArea());

  size_t hdr_size = m_pELFReader->getELFHeaderSize();
  MemoryRegion* region = pInput.memArea()->request(pInput.fileOffset(),
                                                   hdr_size);
  uint8_t* ELF_hdr = region->start();

  bool shdr_result = m_pELFReader->readSectionHeaders(pInput, m_Linker, ELF_hdr);
  pInput.memArea()->release(region);

  // read .dynamic to get the correct SONAME
  bool dyn_result = m_pELFReader->readDynamic(pInput);

  return (shdr_result && dyn_result);
}
コード例 #17
0
ファイル: rfc3394.cpp プロジェクト: BenjaminSchiborr/safe
SecureVector<byte> rfc3394_keyunwrap(const MemoryRegion<byte>& key,
                                     const SymmetricKey& kek,
                                     Algorithm_Factory& af)
   {
   if(key.size() < 16 || key.size() % 8 != 0)
      throw std::invalid_argument("Bad input key size for NIST key unwrap");

   std::auto_ptr<BlockCipher> aes(make_aes(kek.length(), af));
   aes->set_key(kek);

   const size_t n = (key.size() - 8) / 8;

   SecureVector<byte> R(n * 8);
   SecureVector<byte> A(16);

   for(size_t i = 0; i != 8; ++i)
      A[i] = key[i];

   copy_mem(&R[0], key.begin() + 8, key.size() - 8);

   for(size_t j = 0; j <= 5; ++j)
      {
      for(size_t i = n; i != 0; --i)
         {
         const u32bit t = (5 - j) * n + i;

         byte t_buf[4] = { 0 };
         store_be(t, t_buf);

         xor_buf(&A[4], &t_buf[0], 4);

         copy_mem(&A[8], &R[8*(i-1)], 8);

         aes->decrypt(&A[0]);

         copy_mem(&R[8*(i-1)], &A[8], 8);
         }
      }

   if(load_be<u64bit>(&A[0], 0) != 0xA6A6A6A6A6A6A6A6)
      throw Integrity_Failure("NIST key unwrap failed");

   return R;
   }
コード例 #18
0
/// computePCBegin - return the address of FDE's pc
/// @ref binutils gold: ehframe.cc:222
uint32_t EhFrameHdr::computePCBegin(const EhFrame::FDE& pFDE,
                                    const MemoryRegion& pEhFrameRegion)
{
    uint8_t fde_encoding = pFDE.getCIE().getFDEEncode();
    unsigned int eh_value = fde_encoding & 0x7;

    // check the size to read in
    if (eh_value == llvm::dwarf::DW_EH_PE_absptr) {
        eh_value = DW_EH_PE_udata4;
    }

    size_t pc_size = 0x0;
    switch (eh_value) {
    case DW_EH_PE_udata2:
        pc_size = 2;
        break;
    case DW_EH_PE_udata4:
        pc_size = 4;
        break;
    case DW_EH_PE_udata8:
        pc_size = 8;
        break;
    default:
        // TODO
        break;
    }

    SizeTraits<32>::Address pc = 0x0;
    const uint8_t* offset = (const uint8_t*) pEhFrameRegion.start() +
                            pFDE.getOffset() +
                            pFDE.getDataStart();
    std::memcpy(&pc, offset, pc_size);

    // adjust the signed value
    bool is_signed = (fde_encoding & llvm::dwarf::DW_EH_PE_signed) != 0x0;
    if (DW_EH_PE_udata2 == eh_value && is_signed)
        pc = (pc ^ 0x8000) - 0x8000;

    // handle eh application
    switch (fde_encoding & 0x70)
    {
    case DW_EH_PE_absptr:
        break;
    case DW_EH_PE_pcrel:
        pc += m_EhFrame.addr() + pFDE.getOffset() + pFDE.getDataStart();
        break;
    case DW_EH_PE_datarel:
        // TODO
        break;
    default:
        // TODO
        break;
    }
    return pc;
}
コード例 #19
0
uint64_t MipsGOTPLT::emit(MemoryRegion& pRegion) {
  uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());

  uint64_t result = 0;
  for (iterator it = begin(), ie = end(); it != ie; ++it, ++buffer) {
    GOTPLTEntry* got = &(llvm::cast<GOTPLTEntry>((*it)));
    *buffer = static_cast<uint32_t>(got->getValue());
    result += got->size();
  }
  return result;
}
コード例 #20
0
ファイル: rfc3394.cpp プロジェクト: BenjaminSchiborr/safe
SecureVector<byte> rfc3394_keywrap(const MemoryRegion<byte>& key,
                                   const SymmetricKey& kek,
                                   Algorithm_Factory& af)
   {
   if(key.size() % 8 != 0)
      throw std::invalid_argument("Bad input key size for NIST key wrap");

   std::auto_ptr<BlockCipher> aes(make_aes(kek.length(), af));
   aes->set_key(kek);

   const size_t n = key.size() / 8;

   SecureVector<byte> R((n + 1) * 8);
   SecureVector<byte> A(16);

   for(size_t i = 0; i != 8; ++i)
      A[i] = 0xA6;

   copy_mem(&R[8], key.begin(), key.size());

   for(size_t j = 0; j <= 5; ++j)
      {
      for(size_t i = 1; i <= n; ++i)
         {
         const u32bit t = (n * j) + i;

         copy_mem(&A[8], &R[8*i], 8);

         aes->encrypt(&A[0]);
         copy_mem(&R[8*i], &A[8], 8);

         byte t_buf[4] = { 0 };
         store_be(t, t_buf);
         xor_buf(&A[4], &t_buf[0], 4);
         }
      }

   copy_mem(&R[0], &A[0], 8);

   return R;
   }
コード例 #21
0
uint64_t AArch64GOT::emit(MemoryRegion& pRegion) {
  uint64_t* buffer = reinterpret_cast<uint64_t*>(pRegion.begin());

  AArch64GOTEntry* got = NULL;
  uint64_t result = 0x0;
  for (iterator it = begin(), ie = end(); it != ie; ++it, ++buffer) {
    got = &(llvm::cast<AArch64GOTEntry>((*it)));
    *buffer = static_cast<uint64_t>(got->getValue());
    result += AArch64GOTEntry::EntrySize;
  }
  return result;
}
コード例 #22
0
uint64_t ARMGNULDBackend::emitSectionData(const Output& pOutput,
                                          const LDSection& pSection,
                                          const MCLDInfo& pInfo,
                                          MemoryRegion& pRegion) const
{
  assert(pRegion.size() && "Size of MemoryRegion is zero!");

  ELFFileFormat* file_format = getOutputFormat(pOutput);

  if (&pSection == m_pAttributes) {
    // FIXME: Currently Emitting .ARM.attributes directly from the input file.
    const llvm::MCSectionData* sect_data = pSection.getSectionData();
    assert(sect_data &&
           "Emit .ARM.attribute failed, MCSectionData doesn't exist!");

    uint8_t* start =
              llvm::cast<MCRegionFragment>(
                     sect_data->getFragmentList().front()).getRegion().start();

    memcpy(pRegion.start(), start, pRegion.size());
    return pRegion.size();
  }

  if (&pSection == &(file_format->getPLT())) {
    assert(NULL != m_pPLT && "emitSectionData failed, m_pPLT is NULL!");
    uint64_t result = m_pPLT->emit(pRegion);
    return result;
  }

  if (&pSection == &(file_format->getGOT())) {
    assert(NULL != m_pGOT && "emitSectionData failed, m_pGOT is NULL!");
    uint64_t result = m_pGOT->emit(pRegion);
    return result;
  }

  llvm::report_fatal_error(llvm::Twine("Unable to emit section `") +
                           pSection.name() +
                           llvm::Twine("'.\n"));
  return 0x0;
}
コード例 #23
0
ファイル: ScriptReader.cpp プロジェクト: rig-project/mclinker
bool ScriptReader::readScript(const LinkerConfig& pConfig,
                              ScriptFile& pScriptFile)
{
  bool result = false;
  std::stringbuf buf;
  Input& input = pScriptFile.input();
  size_t size = input.memArea()->size();
  MemoryRegion* region = input.memArea()->request(input.fileOffset(), size);
  char* str = reinterpret_cast<char*>(region->getBuffer());
  buf.pubsetbuf(str, size);

  std::istream in(&buf);
  ScriptScanner scanner(&in);
  ScriptParser parser(pConfig,
                      pScriptFile,
                      scanner,
                      m_GroupReader);
  result = (0 == parser.parse());;

  input.memArea()->release(region);
  return result;
}
コード例 #24
0
MemoryRegion* MemoryManager::find(const MPtr data, uint bytes)
{
    if ( fileReadOnly )
        panic("MemoryManager", "find", "Searching by contents not available when read-only mode is selected");

    uint cs = _generateChecksum(data, bytes);
    vector<MemoryRegion*> matches = _findByChecksum(cs);
    if ( matches.empty() )
        return 0;

    vector<MemoryRegion*>::const_iterator it = matches.begin();
    for ( ; it != matches.end(); it++ )
    {
        MemoryRegion* mr = *it;
        //if ( mr->data ) 
        if ( !mr->data.empty() )
        {
            // Memory contents are in cache (available)
            if ( mr->compare(data,bytes) )
            {
                _updateCacheMemory(mr);
                return mr;
            }
        }
        else
        {
            // Contents not available (not in cache)
            _loadDataMemory(mr);
            if ( mr->compare(data,bytes) )
            {
                _updateCacheMemory(mr);
                return mr;
            }
            _unloadDataMemory(mr);
        }
    }
    return 0;
}
コード例 #25
0
uint64_t AArch64GNULDBackend::emitSectionData(const LDSection& pSection,
                                              MemoryRegion& pRegion) const {
  assert(pRegion.size() && "Size of MemoryRegion is zero!");

  const ELFFileFormat* file_format = getOutputFormat();

  if (file_format->hasPLT() && (&pSection == &(file_format->getPLT()))) {
    uint64_t result = m_pPLT->emit(pRegion);
    return result;
  }

  if (file_format->hasGOT() && (&pSection == &(file_format->getGOT()))) {
    uint64_t result = m_pGOT->emit(pRegion);
    return result;
  }

  if (file_format->hasGOTPLT() && (&pSection == &(file_format->getGOTPLT()))) {
    uint64_t result = m_pGOT->emit(pRegion);
    return result;
  }

  return pRegion.size();
}
コード例 #26
0
ファイル: MipsAbiFlags.cpp プロジェクト: ChihMin/mclinker
uint64_t MipsAbiFlags::emit(const MipsAbiFlags& pInfo, MemoryRegion& pRegion) {
  auto* buf = reinterpret_cast<ElfMipsAbiFlags*>(pRegion.begin());
  buf->version = 0;
  buf->isa_level = pInfo.m_IsaLevel;
  buf->isa_rev = pInfo.m_IsaRev;
  buf->gpr_size = pInfo.m_GprSize;
  buf->cpr1_size = pInfo.m_Cpr1Size;
  buf->cpr2_size = pInfo.m_Cpr2Size;
  buf->fp_abi = pInfo.m_FpAbi;
  buf->isa_ext = pInfo.m_IsaExt;
  buf->ases = pInfo.m_Ases;
  buf->flags1 = pInfo.m_Flags1;
  buf->flags2 = 0;
  return size();
}
コード例 #27
0
uint64_t ARMGOT::emit(MemoryRegion& pRegion)
{
  uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.getBuffer());

  GOTEntry* got = 0;
  unsigned int entry_size = getEntrySize();
  uint64_t result = 0x0;
  for (iterator it = begin(), ie = end();
       it != ie; ++it, ++buffer) {
      got = &(llvm::cast<GOTEntry>((*it)));
      *buffer = static_cast<uint32_t>(got->getContent());
      result += entry_size;
  }
  return result;
}
コード例 #28
0
ファイル: MipsPLT.cpp プロジェクト: FulcronZ/NyuziToolchain
uint64_t MipsPLT::emit(MemoryRegion& pRegion) {
  uint64_t result = 0x0;
  iterator it = begin();

  unsigned char* buffer = pRegion.begin();
  memcpy(buffer, llvm::cast<MipsPLT0>((*it)).getValue(), MipsPLT0::EntrySize);
  result += MipsPLT0::EntrySize;
  ++it;

  MipsPLTA* plta = 0;
  for (iterator ie = end(); it != ie; ++it) {
    plta = &(llvm::cast<MipsPLTA>(*it));
    memcpy(buffer + result, plta->getValue(), MipsPLTA::EntrySize);
    result += MipsPLTA::EntrySize;
  }
  return result;
}
コード例 #29
0
uint64_t HexagonLDBackend::emitGOTSectionData(MemoryRegion& pRegion) const {
  assert(m_pGOT && "emitGOTSectionData failed, m_pGOT is NULL!");

  uint32_t* buffer = reinterpret_cast<uint32_t*>(pRegion.begin());

  HexagonGOTEntry* got = 0;
  unsigned int EntrySize = HexagonGOTEntry::EntrySize;
  uint64_t RegionSize = 0;

  for (HexagonGOT::iterator it = m_pGOT->begin(), ie = m_pGOT->end(); it != ie;
       ++it, ++buffer) {
    got = &(llvm::cast<HexagonGOTEntry>((*it)));
    *buffer = static_cast<uint32_t>(got->getValue());
    RegionSize += EntrySize;
  }

  return RegionSize;
}
コード例 #30
0
ファイル: ELFAttribute.cpp プロジェクト: aurorarom/JsonUtil
size_t ELFAttribute::emit(MemoryRegion &pRegion) const
{
  // ARM [ABI-addenda], 2.2.3
  uint64_t total_size = 0;

  // Write format-version.
  char* buffer = reinterpret_cast<char*>(pRegion.begin());
  buffer[0] = FormatVersion;
  total_size += FormatVersionFieldSize;

  for (llvm::SmallVectorImpl<Subsection*>::const_iterator
          subsec_it = m_Subsections.begin(), subsec_end = m_Subsections.end();
       subsec_it != subsec_end; ++subsec_it) {
    // Write out subsection.
    total_size += (*subsec_it)->emit(buffer + total_size);
  }

  return total_size;
}