示例#1
0
dword CalculateXkyFileSize(PEFile* pe_file, dword desired_section_alignment, dword desired_header_alignment)
{
	dword size=0;
	IMAGE_SECTION_HEADER* relocs_header = pe_file->GetSectionHeaderByName(RELOC_SECTION_NAME);
	IMAGE_SECTION_HEADER* module_header = pe_file->GetSectionHeaderByName(MODULE_SECTION_NAME);
	
	//Sumamos .module
	size+=AlignTo(module_header->Misc.VirtualSize, desired_header_alignment);

	//Sumamos todas las secciones incluida la cabecera .module menos las reubicaciones y la cabecera
	for(dword i=0; i<pe_file->NumberOfSections(); i++)
	{
		IMAGE_SECTION_HEADER* section_header = pe_file->GetSectionHeaderByIndex(i);
		if(section_header != relocs_header && section_header != module_header)
			size+=AlignTo(pe_file->GetSectionHeaderByIndex(i)->Misc.VirtualSize, desired_section_alignment);
	}

	//Reubicaciones
	dword relocs_size = 0;
	if(relocs_header)
	{
		BYTE* raw_file=pe_file->Raw();
		IMAGE_BASE_RELOCATION* base_relocation = (IMAGE_BASE_RELOCATION*)(raw_file + relocs_header->PointerToRawData);
		while(base_relocation->SizeOfBlock)
		{
			dword elements = (base_relocation->SizeOfBlock - 2*sizeof(DWORD)) / sizeof(WORD);
			BYTE* last_reubication = (((BYTE*)base_relocation) + base_relocation->SizeOfBlock - sizeof(WORD));
			if(!*last_reubication) elements--;

			//Sumamos tantos elementos por su tamaño en el fichero xky
			relocs_size += elements * sizeof(dword);
			
			//Siguiente
			base_relocation = (IMAGE_BASE_RELOCATION*)(((BYTE*)base_relocation) + base_relocation->SizeOfBlock);
		}
	}
	/*
	struct IMG_RELOCATION
	{
	dword relocations_number;
	dword relocations[];
	}
	*/
	relocs_size++;
	relocs_size=AlignTo(relocs_size, desired_section_alignment);

	//Devolvemos
	return size + relocs_size;
}
示例#2
0
void Program::FinalizeSegments () {
    header.a_magic = ZMAGIC;
    header.a_text = RoundUp(textAlloc, PAGSIZ);
    header.a_data = RoundUp(dataAlloc, PAGSIZ);
    header.a_bss = bssAlloc - (header.a_data - dataAlloc);
#ifdef sun
    header.a_machtype = M_68020;
    header.a_entry = PAGSIZ + sizeof(header);
    UpdateSegment(textStart, header.a_entry, N_TEXT);
    UpdateSegment(dataStart, RoundUp(textAlloc, SEGSIZ), N_DATA);
    segPos[N_TEXT] = sizeof(header);
    segPos[N_DATA] = header.a_text;
#endif
#ifdef vax
    UpdateSegment(textStart, 0, N_TEXT);
    UpdateSegment(dataStart, header.a_text, N_DATA);
    segPos[N_TEXT] = PAGSIZ;
    segPos[N_DATA] = segPos[N_TEXT] + header.a_text;
#endif
    UpdateSegment(bssStart, dataStart + dataAlloc, N_BSS);
    segPos[N_BSS] = segPos[N_DATA] + dataAlloc;
    segPos[ANON_SEG] = segPos[N_BSS] + bssAlloc;
    int newAnonStart = AlignTo(WORDSIZE/BYTESIZE, bssStart + bssAlloc);
    if (anonStart != newAnonStart) {
	anonStart = newAnonStart;
	segStart[ANON_SEG] = newAnonStart;
	anonList->NeedToReloc();
    }
}
示例#3
0
UploadContext ResourceUploadBegin(uint64 size)
{
    Assert_(Device != nullptr);

    size = AlignTo(size, 512);
    Assert_(size <= UploadBufferSize);
    Assert_(size > 0);

    ClearFinishedUploads(0);
    while(AllocUploadSubmission(size) == false)
        ClearFinishedUploads(1);

    Assert_(UploadSubmissionUsed > 0);
    const uint64 submissionIdx = (UploadSubmissionStart + (UploadSubmissionUsed - 1)) % MaxUploadSubmissions;
    UploadSubmission& submission = UploadSubmissions[submissionIdx];
    Assert_(submission.Size == size);

    DXCall(submission.CmdAllocator->Reset());
    DXCall(UploadCmdList->Reset(submission.CmdAllocator, nullptr));

    UploadContext context;
    context.CmdList = UploadCmdList;
    context.Resource = UploadBuffer;
    context.CPUAddress = UploadBufferCPUAddr + submission.Offset;
    context.ResourceOffset = submission.Offset;

    return context;
}
示例#4
0
MapResult AcquireTempBufferMem(uint64 size, uint64 alignment)
{
    TempFrameUsed = AlignTo(TempFrameUsed, alignment);
    Assert_(TempFrameUsed + size <= TempBufferSize);

    MapResult result;
    result.CPUAddress = TempFrameCPUMem[CurrFrameIdx] + TempFrameUsed;
    result.GPUAddress = TempFrameGPUMem[CurrFrameIdx] + TempFrameUsed;
    result.ResourceOffset = TempFrameUsed;
    result.Resource = TempFrameBuffers[CurrFrameIdx];

    TempFrameUsed += size;

    return result;
}
TempBuffer TempConstantBuffer(uint64 cbSize, bool makeDescriptor)
{
    Assert_(cbSize > 0);
    MapResult tempMem = DX12::AcquireTempBufferMem(cbSize, ConstantBufferAlignment);
    TempBuffer tempBuffer;
    tempBuffer.CPUAddress = tempMem.CPUAddress;
    tempBuffer.GPUAddress = tempMem.GPUAddress;
    if(makeDescriptor)
    {
        TempDescriptorAlloc cbvAlloc = SRVDescriptorHeap.AllocateTemporary(1);
        D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = { };
        cbvDesc.BufferLocation = tempMem.GPUAddress;
        cbvDesc.SizeInBytes = uint32(AlignTo(cbSize, ConstantBufferAlignment));
        DX12::Device->CreateConstantBufferView(&cbvDesc, cbvAlloc.StartCPUHandle);
        tempBuffer.DescriptorIndex = cbvAlloc.StartIndex;
    }

    return tempBuffer;
}
示例#6
0
void DumpSection(XFile* xky_file, PEFile* pe_file, const char* section_name, dword alignment)
{
	IMAGE_SECTION_HEADER* pe_section_header=pe_file->GetSectionHeaderByName(section_name);
	IMG_SECTION_HEADER* xky_section_header=xky_file->GetSectionHeaderByName(section_name);
	if(pe_section_header && xky_section_header)
	{
		BYTE* pe_section = pe_file->GetSectionByName(section_name);
		xky_section_header->offset = xky_file->CurrentOffset();
		xky_section_header->size = AlignTo(pe_section_header->Misc.VirtualSize, alignment);
		if(pe_section_header->Misc.VirtualSize<pe_section_header->SizeOfRawData)
		{
			xky_file->SequentialWrite(pe_section, pe_section_header->Misc.VirtualSize, alignment);
		}
		else
		{
			xky_file->SequentialWrite(pe_section, pe_section_header->SizeOfRawData, alignment);
			for(DWORD i=0; i<xky_section_header->size - pe_section_header->SizeOfRawData; i++)
			{
				BYTE null_byte = 0;
				xky_file->SequentialWrite(&null_byte, 1);
			}
		}
	}
}