source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/PESchedule.cpp@ 516

Last change on this file since 516 was 485, checked in by dai_9181, 17 years ago

プロジェクトのリネームが完了

File size: 2.8 KB
RevLine 
[206]1#include "stdafx.h"
2
[266]3#include <Compiler.h>
4
[4]5#include "../BasicCompiler_Common/common.h"
6
7#ifdef _AMD64_
[485]8#include "../compiler_x64/opcode.h"
[4]9#else
[484]10#include "../compiler_x86/opcode.h"
[4]11#endif
12
13extern HANDLE hHeap;
14
15/////////////////////////////////////////////
16// 再配置スケジュール
17//
18// メモリの再配置は.textセクション、または.dataセクションに行われることが予想される。
19// .textセクション … セクションデータへのポインタ
20// .dataセクション … vtblの再配置
21/////////////////////////////////////////////
22
23CReloc *pobj_Reloc;
24
25CReloc::CReloc(){
26 buffer=0;
27 length=0;
28 NowPageRVAToReloc=0;
29}
30CReloc::~CReloc(){
31 AllFree();
32}
33void CReloc::AllFree(void){
34 if(buffer){
35 HeapDefaultFree(buffer);
36 buffer=0;
37 }
38}
39void CReloc::copy(CReloc *por){
40 AllFree();
41
42 if(por->buffer){
43 buffer=(char *)HeapReAlloc(hHeap,0,buffer,por->length);
44 memcpy(buffer,por->buffer,por->length);
45 }
46 else buffer=0;
47
48 length=por->length;
49
50 NowPageRVAToReloc=por->NowPageRVAToReloc;
51 NowCountAddrToReloc=por->NowCountAddrToReloc;
52
[223]53 codeSectionAddresses = por->codeSectionAddresses;
[4]54
[223]55 dataSectionAddresses = por->dataSectionAddresses;
[4]56}
57
58void CReloc::AddSchedule_CodeSection(DWORD addr){
[266]59 if( !compiler.IsDll() ) return;
[4]60
[223]61 codeSectionAddresses.push_back( addr );
[4]62}
63void CReloc::AddSchedule_DataSection(DWORD addr){
[266]64 if( !compiler.IsDll() ) return;
[4]65
[223]66 dataSectionAddresses.push_back( addr );
[4]67}
68
69void CReloc::__add(DWORD addr){
[266]70 if( !compiler.IsDll() ) return;
[4]71
72 BOOL sw;
73 sw=0;
74 while((addr-(addr%MEM_ALIGNMENT))>NowPageRVAToReloc){
75 NowPageRVAToReloc+=MEM_ALIGNMENT;
76 sw=1;
77 }
78
79 if(sw){
80 //ページを増やす
81 while(length%4){
82 buffer=(char *)HeapReAlloc(hHeap,0,buffer,length+sizeof(WORD));
83 (*(WORD *)(buffer+length))=0;
84 length+=2;
85
86 (*(DWORD *)(buffer+NowCountAddrToReloc))+=sizeof(WORD);
87 }
88
89 buffer=(char *)HeapReAlloc(hHeap,0,buffer,
90 length+
91 sizeof(DWORD)+
92 sizeof(DWORD));
93
94 //Page RVA
95 *(DWORD *)(buffer+length)=NowPageRVAToReloc;
96 length+=sizeof(DWORD);
97
98 NowCountAddrToReloc=length;
99
100 //Block size
101 *(DWORD *)(buffer+length)=sizeof(DWORD)*2;
102 length+=sizeof(DWORD);
103 }
104
105 //リロケーション情報の追加
106 buffer=(char *)HeapReAlloc(hHeap,0,buffer,length+sizeof(WORD));
107 buffer[length]=0;
108 buffer[length+1]=0x30; //=IMAGE_REL_BASED_HIGHLOW
109 (*(WORD *)(buffer+length))|=addr&0x0FFF;
110 length+=2;
111
112 (*(DWORD *)(buffer+NowCountAddrToReloc))+=sizeof(WORD);
113}
114void CReloc::ResetRelocBuffer(void){
115 if(buffer) HeapDefaultFree(buffer);
116
117 buffer=(char *)HeapAlloc(hHeap,0,1);
118 length=0;
119 NowPageRVAToReloc=0;
120
[223]121 BOOST_FOREACH( DWORD addr, codeSectionAddresses )
122 {
[4]123 extern int MemPos_CodeSection;
[223]124 __add(MemPos_CodeSection + addr);
[4]125 }
126
[223]127 BOOST_FOREACH( DWORD addr, dataSectionAddresses )
128 {
[4]129 extern int MemPos_DataSection;
[223]130 __add(MemPos_DataSection + addr);
[4]131 }
132}
Note: See TracBrowser for help on using the repository browser.