示例#1
0
TBool ELFFile::Init(const TText * const aFileName)
//
// Read the ELF file into memory
//
 	{

 	delete [] iFileName;	
	iFileName = new TText[strlen((const char *)aFileName)+1];
	strcpy ((char *)iFileName, (const char *)aFileName);

	TInt error = HFile::Open(iFileName, &iFileHandle);
	if (error!=0)
		return EFalse;

	TInt flength = HFile::GetLength(iFileHandle);

	iElfFile = (Elf32_Ehdr *)HMem::Alloc(0,flength);
	if (!iElfFile)
		{
		Print(EPeError,"Failed to allocate memory to read in file.\n");
		Close();
		return EFalse;
		}

	if (!HFile::Read(iFileHandle,iElfFile,flength))
		{
		Print(EPeError,"Unable to read file %s.\n",iFileName);
		Close();
		return EFalse;
		}

        Close();

	if (!IsValidFileHeader(iElfFile))
		{
		Print(EPeError,"Invalid file header.\n");
		return EFalse;
		}
	// we only support this....for the moment
	iCpu = ECpuArmV4;

	if (!InitHeaders()) return EFalse;
	
	if (!InitDllData()) return EFalse;

	iEntryPoint = iElfFile->e_entry;

	iCodeSize = GetCodeSize();
	iDataSize = GetDataSize();
	iBssSize = GetBssSize();

	iStackReservedSize = 0x2000;
	iStackCommittedSize = 0x2000;

 	iLinkedBase = iCodeSegmentHdr->p_vaddr;
	
	iImageIsDll = iDllData->ImageIsDll();

	return ETrue;
	}
示例#2
0
	/// <summary>Read the full method from the supplied buffer.</summary>
	void Method::ReadMethod(IMAGE_COR_ILMETHOD* pMethod)
	{
		BYTE* pCode;
		auto fatImage = static_cast<COR_ILMETHOD_FAT*>(&pMethod->Fat);
		if (!fatImage->IsFat())
		{
			#ifdef TRACE_ENABLED
			ATLTRACE(_T("TINY"));
			#endif
			auto tinyImage = static_cast<COR_ILMETHOD_TINY*>(&pMethod->Tiny);
			m_header.CodeSize = tinyImage->GetCodeSize();
			pCode = tinyImage->GetCode();
			#ifdef TRACE_ENABLED
			ATLTRACE(_T("TINY(%X) => (%d + 1) : %d"), m_header.CodeSize, m_header.CodeSize, m_header.MaxStack);
			#endif		
		}
		else
		{
			memcpy(&m_header, pMethod, fatImage->Size * sizeof(DWORD));
			pCode = fatImage->GetCode();
			#ifdef TRACE_ENABLED
			ATLTRACE(_T("FAT(%X) => (%d + 12) : %d"), m_header.CodeSize, m_header.CodeSize, m_header.MaxStack);
			#endif
		}
		SetBuffer(pCode);
		ReadBody();
	}
示例#3
0
void CodeGenWorkItem::FinalizeNativeCode(Func *func)
{
    NativeCodeData * data = func->GetNativeCodeDataAllocator()->Finalize();
    NativeCodeData * transferData = func->GetTransferDataAllocator()->Finalize();
    CodeGenNumberChunk * numberChunks = func->GetNumberAllocator()->Finalize();
    this->functionBody->RecordNativeBaseAddress((BYTE *)GetCodeAddress(), GetCodeSize(), data, transferData, numberChunks, GetEntryPoint(), GetLoopNumber());
    func->GetEmitBufferManager()->CompletePreviousAllocation(this->GetAllocation());
}
示例#4
0
void CodeGenWorkItem::RecordNativeCode(Func *func, const BYTE* sourceBuffer)
{
    if (!func->GetEmitBufferManager()->CommitBuffer(this->GetAllocation(), (BYTE *)GetCodeAddress(), GetCodeSize(), sourceBuffer))
    {
        Js::Throw::OutOfMemory();
    }

    this->isAllocationCommitted = true;

#if DBG_DUMP
    if (Type() == JsLoopBodyWorkItemType)
    {
        func->GetEmitBufferManager()->totalBytesLoopBody += GetCodeSize();
    }
#endif
}