Exemplo n.º 1
0
// Compute an upper bound of the memory size that is required to load all
// sections
void RuntimeDyldImpl::computeTotalAllocSize(ObjectImage &Obj,
                                            uint64_t &CodeSize,
                                            uint64_t &DataSizeRO,
                                            uint64_t &DataSizeRW) {
  // Compute the size of all sections required for execution
  std::vector<uint64_t> CodeSectionSizes;
  std::vector<uint64_t> ROSectionSizes;
  std::vector<uint64_t> RWSectionSizes;
  uint64_t MaxAlignment = sizeof(void *);

  // Collect sizes of all sections to be loaded;
  // also determine the max alignment of all sections
  for (section_iterator SI = Obj.begin_sections(), SE = Obj.end_sections();
       SI != SE; ++SI) {
    const SectionRef &Section = *SI;

    bool IsRequired;
    Check(Section.isRequiredForExecution(IsRequired));

    // Consider only the sections that are required to be loaded for execution
    if (IsRequired) {
      uint64_t DataSize = 0;
      uint64_t Alignment64 = 0;
      bool IsCode = false;
      bool IsReadOnly = false;
      StringRef Name;
      Check(Section.getSize(DataSize));
      Check(Section.getAlignment(Alignment64));
      Check(Section.isText(IsCode));
      Check(Section.isReadOnlyData(IsReadOnly));
      Check(Section.getName(Name));
      unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL;

      uint64_t StubBufSize = computeSectionStubBufSize(Obj, Section);
      uint64_t SectionSize = DataSize + StubBufSize;

      // The .eh_frame section (at least on Linux) needs an extra four bytes
      // padded
      // with zeroes added at the end.  For MachO objects, this section has a
      // slightly different name, so this won't have any effect for MachO
      // objects.
      if (Name == ".eh_frame")
        SectionSize += 4;

      if (SectionSize > 0) {
        // save the total size of the section
        if (IsCode) {
          CodeSectionSizes.push_back(SectionSize);
        } else if (IsReadOnly) {
          ROSectionSizes.push_back(SectionSize);
        } else {
          RWSectionSizes.push_back(SectionSize);
        }
        // update the max alignment
        if (Alignment > MaxAlignment) {
          MaxAlignment = Alignment;
        }
      }
    }
  }

  // Compute the size of all common symbols
  uint64_t CommonSize = 0;
  for (symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;
       ++I) {
    uint32_t Flags = I->getFlags();
    if (Flags & SymbolRef::SF_Common) {
      // Add the common symbols to a list.  We'll allocate them all below.
      uint64_t Size = 0;
      Check(I->getSize(Size));
      CommonSize += Size;
    }
  }
  if (CommonSize != 0) {
    RWSectionSizes.push_back(CommonSize);
  }

  // Compute the required allocation space for each different type of sections
  // (code, read-only data, read-write data) assuming that all sections are
  // allocated with the max alignment. Note that we cannot compute with the
  // individual alignments of the sections, because then the required size
  // depends on the order, in which the sections are allocated.
  CodeSize = computeAllocationSizeForSections(CodeSectionSizes, MaxAlignment);
  DataSizeRO = computeAllocationSizeForSections(ROSectionSizes, MaxAlignment);
  DataSizeRW = computeAllocationSizeForSections(RWSectionSizes, MaxAlignment);
}
Exemplo n.º 2
0
unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,
                                      const SectionRef &Section, bool IsCode) {

  StringRef data;
  uint64_t Alignment64;
  Check(Section.getContents(data));
  Check(Section.getAlignment(Alignment64));

  unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL;
  bool IsRequired;
  bool IsVirtual;
  bool IsZeroInit;
  bool IsReadOnly;
  uint64_t DataSize;
  unsigned PaddingSize = 0;
  unsigned StubBufSize = 0;
  StringRef Name;
  Check(Section.isRequiredForExecution(IsRequired));
  Check(Section.isVirtual(IsVirtual));
  Check(Section.isZeroInit(IsZeroInit));
  Check(Section.isReadOnlyData(IsReadOnly));
  Check(Section.getSize(DataSize));
  Check(Section.getName(Name));

  StubBufSize = computeSectionStubBufSize(Obj, Section);

  // The .eh_frame section (at least on Linux) needs an extra four bytes padded
  // with zeroes added at the end.  For MachO objects, this section has a
  // slightly different name, so this won't have any effect for MachO objects.
  if (Name == ".eh_frame")
    PaddingSize = 4;

  uintptr_t Allocate;
  unsigned SectionID = Sections.size();
  uint8_t *Addr;
  const char *pData = 0;

  // Some sections, such as debug info, don't need to be loaded for execution.
  // Leave those where they are.
  if (IsRequired) {
    Allocate = DataSize + PaddingSize + StubBufSize;
    Addr = IsCode ? MemMgr->allocateCodeSection(Allocate, Alignment, SectionID,
                                                Name)
                  : MemMgr->allocateDataSection(Allocate, Alignment, SectionID,
                                                Name, IsReadOnly);
    if (!Addr)
      report_fatal_error("Unable to allocate section memory!");

    // Virtual sections have no data in the object image, so leave pData = 0
    if (!IsVirtual)
      pData = data.data();

    // Zero-initialize or copy the data from the image
    if (IsZeroInit || IsVirtual)
      memset(Addr, 0, DataSize);
    else
      memcpy(Addr, pData, DataSize);

    // Fill in any extra bytes we allocated for padding
    if (PaddingSize != 0) {
      memset(Addr + DataSize, 0, PaddingSize);
      // Update the DataSize variable so that the stub offset is set correctly.
      DataSize += PaddingSize;
    }

    DEBUG(dbgs() << "emitSection SectionID: " << SectionID << " Name: " << Name
                 << " obj addr: " << format("%p", pData)
                 << " new addr: " << format("%p", Addr)
                 << " DataSize: " << DataSize << " StubBufSize: " << StubBufSize
                 << " Allocate: " << Allocate << "\n");
    Obj.updateSectionAddress(Section, (uint64_t)Addr);
  } else {
    // Even if we didn't load the section, we need to record an entry for it
    // to handle later processing (and by 'handle' I mean don't do anything
    // with these sections).
    Allocate = 0;
    Addr = 0;
    DEBUG(dbgs() << "emitSection SectionID: " << SectionID << " Name: " << Name
                 << " obj addr: " << format("%p", data.data()) << " new addr: 0"
                 << " DataSize: " << DataSize << " StubBufSize: " << StubBufSize
                 << " Allocate: " << Allocate << "\n");
  }

  Sections.push_back(SectionEntry(Name, Addr, DataSize, (uintptr_t)pData));
  return SectionID;
}
Exemplo n.º 3
0
// Copy the HUB_LOG to the state of the dialog 
void EmHubLogToDlg(HWND hWnd, HUB_LOG *g)
{
	// Validate arguments
	if (hWnd == NULL || g == NULL)
	{
		return;
	}

	CbSelect(hWnd, C_PACKET_SWITCH, g->PacketLogSwitchType);

	Check(hWnd, B_PACKET_0_0, g->PacketLogConfig[0] == 0);
	Check(hWnd, B_PACKET_0_1, g->PacketLogConfig[0] == 1);
	Check(hWnd, B_PACKET_0_2, g->PacketLogConfig[0] == 2);

	Check(hWnd, B_PACKET_1_0, g->PacketLogConfig[1] == 0);
	Check(hWnd, B_PACKET_1_1, g->PacketLogConfig[1] == 1);
	Check(hWnd, B_PACKET_1_2, g->PacketLogConfig[1] == 2);

	Check(hWnd, B_PACKET_2_0, g->PacketLogConfig[2] == 0);
	Check(hWnd, B_PACKET_2_1, g->PacketLogConfig[2] == 1);
	Check(hWnd, B_PACKET_2_2, g->PacketLogConfig[2] == 2);

	Check(hWnd, B_PACKET_3_0, g->PacketLogConfig[3] == 0);
	Check(hWnd, B_PACKET_3_1, g->PacketLogConfig[3] == 1);
	Check(hWnd, B_PACKET_3_2, g->PacketLogConfig[3] == 2);

	Check(hWnd, B_PACKET_4_0, g->PacketLogConfig[4] == 0);
	Check(hWnd, B_PACKET_4_1, g->PacketLogConfig[4] == 1);
	Check(hWnd, B_PACKET_4_2, g->PacketLogConfig[4] == 2);

	Check(hWnd, B_PACKET_5_0, g->PacketLogConfig[5] == 0);
	Check(hWnd, B_PACKET_5_1, g->PacketLogConfig[5] == 1);
	Check(hWnd, B_PACKET_5_2, g->PacketLogConfig[5] == 2);

	Check(hWnd, B_PACKET_6_0, g->PacketLogConfig[6] == 0);
	Check(hWnd, B_PACKET_6_1, g->PacketLogConfig[6] == 1);
	Check(hWnd, B_PACKET_6_2, g->PacketLogConfig[6] == 2);

	Check(hWnd, B_PACKET_7_0, g->PacketLogConfig[7] == 0);
	Check(hWnd, B_PACKET_7_1, g->PacketLogConfig[7] == 1);
	Check(hWnd, B_PACKET_7_2, g->PacketLogConfig[7] == 2);
}
Exemplo n.º 4
0
void CMasternodeMan::CheckAndRemove(bool forceExpiredRemoval)
{
    Check();

    LOCK(cs);

    //remove inactive and outdated
    vector<CMasternode>::iterator it = vMasternodes.begin();
    while(it != vMasternodes.end()){
        if((*it).activeState == CMasternode::MASTERNODE_REMOVE ||
                (*it).activeState == CMasternode::MASTERNODE_VIN_SPENT ||
                (forceExpiredRemoval && (*it).activeState == CMasternode::MASTERNODE_EXPIRED) ||
                (*it).protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) {
            LogPrint("masnernode", "CMasternodeMan: Removing inactive Masternode %s - %i now\n", (*it).addr.ToString(), size() - 1);

            //erase all of the broadcasts we've seen from this vin
            // -- if we missed a few pings and the node was removed, this will allow is to get it back without them 
            //    sending a brand new mnb
            map<uint256, CMasternodeBroadcast>::iterator it3 = mapSeenMasternodeBroadcast.begin();
            while(it3 != mapSeenMasternodeBroadcast.end()){
                if((*it3).second.vin == (*it).vin){
                    masternodeSync.mapSeenSyncMNB.erase((*it3).first);
                    mapSeenMasternodeBroadcast.erase(it3++);
                } else {
                    ++it3;
                }
            }

            // allow us to ask for this masternode again if we see another ping
            map<COutPoint, int64_t>::iterator it2 = mWeAskedForMasternodeListEntry.begin();
            while(it2 != mWeAskedForMasternodeListEntry.end()){
                if((*it2).first == (*it).vin.prevout){
                    mWeAskedForMasternodeListEntry.erase(it2++);
                } else {
                    ++it2;
                }
            }

            it = vMasternodes.erase(it);
        } else {
            ++it;
        }
    }

    // check who's asked for the Masternode list
    map<CNetAddr, int64_t>::iterator it1 = mAskedUsForMasternodeList.begin();
    while(it1 != mAskedUsForMasternodeList.end()){
        if((*it1).second < GetTime()) {
            mAskedUsForMasternodeList.erase(it1++);
        } else {
            ++it1;
        }
    }

    // check who we asked for the Masternode list
    it1 = mWeAskedForMasternodeList.begin();
    while(it1 != mWeAskedForMasternodeList.end()){
        if((*it1).second < GetTime()){
            mWeAskedForMasternodeList.erase(it1++);
        } else {
            ++it1;
        }
    }

    // check which Masternodes we've asked for
    map<COutPoint, int64_t>::iterator it2 = mWeAskedForMasternodeListEntry.begin();
    while(it2 != mWeAskedForMasternodeListEntry.end()){
        if((*it2).second < GetTime()){
            mWeAskedForMasternodeListEntry.erase(it2++);
        } else {
            ++it2;
        }
    }

}
Exemplo n.º 5
0
 void SetLongVal(long val)
     { Check(wxCMD_LINE_VAL_NUMBER); m_longVal = val; m_hasVal = true; }
Exemplo n.º 6
0
 void SetDateVal(const wxDateTime& val)
     { Check(wxCMD_LINE_VAL_DATE); m_dateVal = val; m_hasVal = true; }
Exemplo n.º 7
0
 void GdiContext2D::set_shadowBlur(double v)
 {
     Check();
     shadowBlur = v;
 }
Exemplo n.º 8
0
 const wxString& GetStrVal() const
     { Check(wxCMD_LINE_VAL_STRING); return m_strVal;  }
Exemplo n.º 9
0
 void GdiContext2D::set_shadowColor(const Color& v)
 {
     Check();
     shadowColor = v;
 }
Exemplo n.º 10
0
 void GdiContext2D::set_shadowOffsetY(double v)
 {
     Check();
     shadowOffsetY = v;
 }
Exemplo n.º 11
0
 void GdiContext2D::set_lineWidth(double v)
 {
     Check();
     lineWidth  = v;
 }
Exemplo n.º 12
0
 void GdiContext2D::set_font(const Font& v)
 {
     Check();
     font = v;
 }
Exemplo n.º 13
0
 void GdiContext2D::set_font(const char* v)
 {
     Check();
     font = v;
 }
Exemplo n.º 14
0
 void GdiContext2D::set_textBaseline(const TextBaseline& v)
 {
     Check();
     textBaseline = v;
 }
Exemplo n.º 15
0
void OrthancContext::Redirect(OrthancPluginRestOutput* output,
                              const std::string& s)
{
    Check();
    OrthancPluginRedirect(context_, output, s.c_str());
}
Exemplo n.º 16
0
 long GetLongVal() const
     { Check(wxCMD_LINE_VAL_NUMBER); return m_longVal; }
Exemplo n.º 17
0
void OrthancContext::LogInfo(const std::string& s)
{
    Check();
    OrthancPluginLogInfo(context_, s.c_str());
}
Exemplo n.º 18
0
 const wxDateTime& GetDateVal() const
     { Check(wxCMD_LINE_VAL_DATE);   return m_dateVal; }
Exemplo n.º 19
0
void OrthancContext::Register(const std::string& uri,
                              OrthancPluginRestCallback callback)
{
    Check();
    OrthancPluginRegisterRestCallback(context_, uri.c_str(), callback);
}
Exemplo n.º 20
0
 void SetStrVal(const wxString& val)
     { Check(wxCMD_LINE_VAL_STRING); m_strVal = val; m_hasVal = true; }
Exemplo n.º 21
0
ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
  MutexGuard locked(lock);

  std::unique_ptr<ObjectImage> Obj(InputObject);
  if (!Obj)
    return NULL;

  // Save information about our target
  Arch = (Triple::ArchType)Obj->getArch();
  IsTargetLittleEndian = Obj->getObjectFile()->isLittleEndian();

  // Compute the memory size required to load all sections to be loaded
  // and pass this information to the memory manager
  if (MemMgr->needsToReserveAllocationSpace()) {
    uint64_t CodeSize = 0, DataSizeRO = 0, DataSizeRW = 0;
    computeTotalAllocSize(*Obj, CodeSize, DataSizeRO, DataSizeRW);
    MemMgr->reserveAllocationSpace(CodeSize, DataSizeRO, DataSizeRW);
  }

  // Symbols found in this object
  StringMap<SymbolLoc> LocalSymbols;
  // Used sections from the object file
  ObjSectionToIDMap LocalSections;

  // Common symbols requiring allocation, with their sizes and alignments
  CommonSymbolMap CommonSymbols;
  // Maximum required total memory to allocate all common symbols
  uint64_t CommonSize = 0;

  // Parse symbols
  DEBUG(dbgs() << "Parse symbols:\n");
  for (symbol_iterator I = Obj->begin_symbols(), E = Obj->end_symbols(); I != E;
       ++I) {
    object::SymbolRef::Type SymType;
    StringRef Name;
    Check(I->getType(SymType));
    Check(I->getName(Name));

    uint32_t Flags = I->getFlags();

    bool IsCommon = Flags & SymbolRef::SF_Common;
    if (IsCommon) {
      // Add the common symbols to a list.  We'll allocate them all below.
      uint32_t Align;
      Check(I->getAlignment(Align));
      uint64_t Size = 0;
      Check(I->getSize(Size));
      CommonSize += Size + Align;
      CommonSymbols[*I] = CommonSymbolInfo(Size, Align);
    } else {
      if (SymType == object::SymbolRef::ST_Function ||
          SymType == object::SymbolRef::ST_Data ||
          SymType == object::SymbolRef::ST_Unknown) {
        uint64_t FileOffset;
        StringRef SectionData;
        bool IsCode;
        section_iterator SI = Obj->end_sections();
        Check(I->getFileOffset(FileOffset));
        Check(I->getSection(SI));
        if (SI == Obj->end_sections())
          continue;
        Check(SI->getContents(SectionData));
        Check(SI->isText(IsCode));
        const uint8_t *SymPtr =
            (const uint8_t *)Obj->getData().data() + (uintptr_t)FileOffset;
        uintptr_t SectOffset =
            (uintptr_t)(SymPtr - (const uint8_t *)SectionData.begin());
        unsigned SectionID =
            findOrEmitSection(*Obj, *SI, IsCode, LocalSections);
        LocalSymbols[Name.data()] = SymbolLoc(SectionID, SectOffset);
        DEBUG(dbgs() << "\tFileOffset: " << format("%p", (uintptr_t)FileOffset)
                     << " flags: " << Flags << " SID: " << SectionID
                     << " Offset: " << format("%p", SectOffset));
        GlobalSymbolTable[Name] = SymbolLoc(SectionID, SectOffset);
      }
    }
    DEBUG(dbgs() << "\tType: " << SymType << " Name: " << Name << "\n");
  }

  // Allocate common symbols
  if (CommonSize != 0)
    emitCommonSymbols(*Obj, CommonSymbols, CommonSize, LocalSymbols);

  // Parse and process relocations
  DEBUG(dbgs() << "Parse relocations:\n");
  for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
       SI != SE; ++SI) {
    unsigned SectionID = 0;
    StubMap Stubs;
    section_iterator RelocatedSection = SI->getRelocatedSection();

    if (SI->relocation_empty() && !ProcessAllSections)
      continue;

    bool IsCode = false;
    Check(RelocatedSection->isText(IsCode));
    SectionID =
        findOrEmitSection(*Obj, *RelocatedSection, IsCode, LocalSections);
    DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n");

    for (relocation_iterator I = SI->relocation_begin(),
         E = SI->relocation_end(); I != E;)
      I = processRelocationRef(SectionID, I, *Obj, LocalSections, LocalSymbols,
                               Stubs);
  }

  // Give the subclasses a chance to tie-up any loose ends.
  finalizeLoad(LocalSections);

  return Obj.release();
}
Exemplo n.º 22
0
int LuaC::TimerLib::restart(lua_State *l){
    //Stack: userdata (Timer)
    Timer *t = Check(l, 1);;
    lua_pushinteger(l, t->Restart());
    return 1;
}
Exemplo n.º 23
0
 void GdiContext2D::set_textBaseline(const char* v)
 {
     Check();
     textBaseline = ParseTextBaseline(v);
 }
Exemplo n.º 24
0
int LuaC::TimerLib::stop(lua_State *l){
    //Stack: userdata (Timer)
    Timer *t = Check(l, 1);
    t->Stop();
    return 0;
}
Exemplo n.º 25
0
int LuaC::TimerLib::unpause(lua_State *l){
    //Stack: userdata (Timer)
    Timer *t = Check(l, 1);
    t->Unpause();
    return 0;
}
Exemplo n.º 26
0
BOOL CColumns::Open(UINT nOpenType /* = snapshot */,
					LPCSTR lpszSQL /* = NULL */, DWORD dwOptions /* = none */)
{
#ifdef WIN32

	ASSERT(lpszSQL == NULL);
	RETCODE	nRetCode;

	// Cache state info and allocate hstmt
	SetState(nOpenType,NULL,noDirtyFieldCheck | dwOptions);
	if (!AllocHstmt())
		return FALSE;

	TRY
	{
		OnSetOptions(m_hstmt);
		AllocStatusArrays();

		// call the ODBC catalog function with data member params
		AFX_SQL_ASYNC(this, ::SQLColumns(m_hstmt,
			(m_strQualifierParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strQualifierParam), SQL_NTS,
			(m_strOwnerParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strOwnerParam), SQL_NTS,
			(m_strTableNameParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strTableNameParam), SQL_NTS,
			NULL, SQL_NTS));
		if (!Check(nRetCode))
			ThrowDBException(nRetCode, m_hstmt);

		// Allocate memory and cache info
		AllocAndCacheFieldInfo();
		AllocRowset();

		// Fetch the first row of data
		MoveNext();

		// If EOF, result set is empty, set BOF as well
		m_bBOF = m_bEOF;
	}

	CATCH_ALL(e)
	{
		Close();
		THROW_LAST();
	}
	END_CATCH_ALL

	return TRUE;

#else		// WIN16

	RETCODE nRetCode;
	ASSERT(lpszSQL == NULL);

	// Allocation and opening of database not supported
	if (m_hstmt == SQL_NULL_HSTMT)
	{
		CString strDefaultConnect;
		TRY
		{
			if (m_pDatabase == NULL)
			{
				m_pDatabase = new CDatabase();
				m_bRecordsetDb = TRUE;
			}

			strDefaultConnect = GetDefaultConnect();
			// If not already opened, attempt to open
			if (!m_pDatabase->IsOpen() &&
				!m_pDatabase->Open("", FALSE, FALSE, strDefaultConnect))
				return FALSE;

			AFX_SQL_SYNC(::SQLAllocStmt(m_pDatabase->m_hdbc, &m_hstmt));
			if (!Check(nRetCode))
				ThrowDBException(SQL_INVALID_HANDLE);
		//		return FALSE;					#JB951122
		}
		CATCH_ALL(e)
		{
#ifdef _DEBUG
			if (afxTraceFlags & 0x20)
				TRACE0("Error: CDatabase create for CRecordset failed\n");
#endif // _DEBUG
			strDefaultConnect.Empty();
			if (m_bRecordsetDb)
			{
				DELETE_OBJ (m_pDatabase);
			}
			ASSERT(m_hstmt == SQL_NULL_HSTMT);
			THROW_LAST();
		}
		END_CATCH_ALL
	}
Exemplo n.º 27
0
void CheckListComboPopup::CheckAll(bool check)
{
    for ( unsigned int i = 1; i < GetCount(); i++ )
        Check(i, check);
}
				Object::Status Object::SubmitProcessTask(Sample *sample, UINT32 sidx)
				{
					if (Tracker.IsValid() && !Paused && sample && sidx < Sample::MaxStreams)
						return Check() = Tracker->ProcessImageAsync(sample->Images, &sample->SyncsInter[sidx]);
					else return Check() = PXC_STATUS_HANDLE_INVALID;
				}
				Object::Status Object::SubmitProcessTask(PXCImage *images [], PXCScheduler::SyncPoint **sync)
				{
					if (Tracker.IsValid() && !Paused && images && sync)
						return Check() = Tracker->ProcessImageAsync(images, sync);
					else return Check() = PXC_STATUS_HANDLE_INVALID;
				}
				Object::Status Object::SubmitProcessTask(Sample *sample)
				{
					if (Tracker.IsValid() && !Paused && sample)
						return Check() = Tracker->ProcessImageAsync(sample->Images, &sample->SyncOut);
					else return Check() = PXC_STATUS_HANDLE_INVALID;
				}