1 | #pragma once
|
---|
2 |
|
---|
3 | class UserProc;
|
---|
4 | class DllProc;
|
---|
5 | class CClass;
|
---|
6 |
|
---|
7 | class Schedule
|
---|
8 | {
|
---|
9 | public:
|
---|
10 | enum Type
|
---|
11 | {
|
---|
12 | None = 10000,
|
---|
13 | GlobalVar, // グローバル変数スケジュール
|
---|
14 | DataTable, // データテーブル スケジュール
|
---|
15 | CatchAddress, // Catchアドレス スケジュール
|
---|
16 | Relocation, // リロケーション情報スケジュール
|
---|
17 | UserProc, // ユーザ定義関数呼び出し側スケジュール
|
---|
18 | AddressOf, // ユーザ定義関数位置スケジュール
|
---|
19 | DllProc, // DLL関数位置スケジュール
|
---|
20 | ComVtbl, // com_vtblスケジュール
|
---|
21 | Vtbl, // vtblスケジュール
|
---|
22 | TypeInfo, // TypeInfoスケジュール
|
---|
23 | };
|
---|
24 |
|
---|
25 | private:
|
---|
26 | Type type;
|
---|
27 | long offset;
|
---|
28 |
|
---|
29 | union{
|
---|
30 | LONG_PTR lpValue;
|
---|
31 | const ::UserProc *pUserProc;
|
---|
32 | const ::DllProc *pDllProc;
|
---|
33 | const ::CClass *pClass;
|
---|
34 | };
|
---|
35 |
|
---|
36 | // XMLシリアライズ用
|
---|
37 | private:
|
---|
38 | friend class boost::serialization::access;
|
---|
39 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
40 | {
|
---|
41 | trace_for_serialize( "serializing - Schedule" );
|
---|
42 |
|
---|
43 | ar & BOOST_SERIALIZATION_NVP( type );
|
---|
44 | ar & BOOST_SERIALIZATION_NVP( offset );
|
---|
45 |
|
---|
46 | switch( type )
|
---|
47 | {
|
---|
48 | case UserProc:
|
---|
49 | case AddressOf:
|
---|
50 | case CatchAddress:
|
---|
51 | ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
|
---|
52 | break;
|
---|
53 | case DllProc:
|
---|
54 | ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
|
---|
55 | break;
|
---|
56 | case ComVtbl:
|
---|
57 | case Vtbl:
|
---|
58 | case TypeInfo:
|
---|
59 | ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass));
|
---|
60 | break;
|
---|
61 | default:
|
---|
62 | ar & BOOST_SERIALIZATION_NVP( lpValue );
|
---|
63 | break;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public:
|
---|
68 | Schedule()
|
---|
69 | {
|
---|
70 | }
|
---|
71 | Schedule( Type type, long offset, LONG_PTR lpValue = 0 )
|
---|
72 | : type( type )
|
---|
73 | , offset( offset )
|
---|
74 | , lpValue( lpValue )
|
---|
75 | {
|
---|
76 | }
|
---|
77 | Schedule( Schedule::Type type, const ::UserProc *pUserProc, long offset )
|
---|
78 | : type( type )
|
---|
79 | , offset( offset )
|
---|
80 | , pUserProc( pUserProc )
|
---|
81 | {
|
---|
82 | }
|
---|
83 | Schedule( const ::DllProc *pDllProc, long offset )
|
---|
84 | : type( Schedule::DllProc )
|
---|
85 | , offset( offset )
|
---|
86 | , pDllProc( pDllProc )
|
---|
87 | {
|
---|
88 | }
|
---|
89 | Schedule( Type type, const ::CClass *pClass, long offset )
|
---|
90 | : type( type )
|
---|
91 | , pClass( pClass )
|
---|
92 | , offset( offset )
|
---|
93 | {
|
---|
94 | if( !( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
|
---|
95 | {
|
---|
96 | DebugBreak();
|
---|
97 | }
|
---|
98 | }
|
---|
99 | Schedule(Schedule&& y)
|
---|
100 | : type(std::move(y.type))
|
---|
101 | , offset(std::move(y.offset))
|
---|
102 | , lpValue(std::move(y.lpValue))
|
---|
103 | {
|
---|
104 | }
|
---|
105 | Schedule(Schedule const& y)
|
---|
106 | : type(y.type)
|
---|
107 | , offset(y.offset)
|
---|
108 | , lpValue(y.lpValue)
|
---|
109 | {
|
---|
110 | }
|
---|
111 | Schedule& operator =(Schedule&& y)
|
---|
112 | {
|
---|
113 | type = std::move(y.type);
|
---|
114 | offset = std::move(y.offset);
|
---|
115 | lpValue = std::move(y.lpValue);
|
---|
116 | return *this;
|
---|
117 | }
|
---|
118 | Schedule& operator =(Schedule const& y)
|
---|
119 | {
|
---|
120 | return *this = std::move(Schedule(y));
|
---|
121 | }
|
---|
122 | ~Schedule()
|
---|
123 | {
|
---|
124 | }
|
---|
125 |
|
---|
126 | Type GetType() const
|
---|
127 | {
|
---|
128 | return type;
|
---|
129 | }
|
---|
130 | long GetOffset() const
|
---|
131 | {
|
---|
132 | return offset;
|
---|
133 | }
|
---|
134 | LONG_PTR GetLongPtrValue() const
|
---|
135 | {
|
---|
136 | return lpValue;
|
---|
137 | }
|
---|
138 | const ::DllProc &GetDllProc() const;
|
---|
139 | const ::UserProc &GetUserProc() const;
|
---|
140 | const ::CClass &GetClass() const;
|
---|
141 |
|
---|
142 | virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
143 | };
|
---|
144 | typedef std::vector<Schedule> Schedules;
|
---|
145 |
|
---|
146 | #define CODETYPE_SYSTEMPROC 0x0001
|
---|
147 | #define CODETYPE_DEBUGPROC 0x0002
|
---|
148 | class SourceLine
|
---|
149 | {
|
---|
150 | long nativeCodePos;
|
---|
151 | DWORD codeType;
|
---|
152 | SourceCodePosition sourceCodePosition;
|
---|
153 |
|
---|
154 | // XMLシリアライズ用
|
---|
155 | private:
|
---|
156 | friend class boost::serialization::access;
|
---|
157 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
158 | {
|
---|
159 | trace_for_serialize( "serializing - SourceLine" );
|
---|
160 |
|
---|
161 | ar & BOOST_SERIALIZATION_NVP( nativeCodePos );
|
---|
162 | ar & BOOST_SERIALIZATION_NVP( codeType );
|
---|
163 | ar & BOOST_SERIALIZATION_NVP( sourceCodePosition );
|
---|
164 | }
|
---|
165 |
|
---|
166 | public:
|
---|
167 | SourceLine( int nativeCodePos, DWORD codeType, const SourceCodePosition &sourceCodePosition )
|
---|
168 | : nativeCodePos( nativeCodePos )
|
---|
169 | , codeType( codeType )
|
---|
170 | , sourceCodePosition( sourceCodePosition )
|
---|
171 | {
|
---|
172 | }
|
---|
173 | SourceLine()
|
---|
174 | {
|
---|
175 | }
|
---|
176 | SourceLine(SourceLine const& y)
|
---|
177 | : nativeCodePos(y.nativeCodePos)
|
---|
178 | , codeType(y.codeType)
|
---|
179 | , sourceCodePosition(y.sourceCodePosition)
|
---|
180 | {
|
---|
181 | }
|
---|
182 | SourceLine(SourceLine&& y)
|
---|
183 | : nativeCodePos(std::move(y.nativeCodePos))
|
---|
184 | , codeType(std::move(y.codeType))
|
---|
185 | , sourceCodePosition(std::move(y.sourceCodePosition))
|
---|
186 | {
|
---|
187 | }
|
---|
188 | SourceLine& operator =(SourceLine&& y)
|
---|
189 | {
|
---|
190 | nativeCodePos = std::move(y.nativeCodePos);
|
---|
191 | codeType = std::move(y.codeType);
|
---|
192 | sourceCodePosition = std::move(y.sourceCodePosition);
|
---|
193 | return *this;
|
---|
194 | }
|
---|
195 | SourceLine& operator =(SourceLine const& y)
|
---|
196 | {
|
---|
197 | return *this = std::move(SourceLine(y));
|
---|
198 | }
|
---|
199 |
|
---|
200 | long GetNativeCodePos() const
|
---|
201 | {
|
---|
202 | return nativeCodePos;
|
---|
203 | }
|
---|
204 | DWORD GetCodeType() const
|
---|
205 | {
|
---|
206 | return codeType;
|
---|
207 | }
|
---|
208 | const SourceCodePosition &GetSourceCodePosition() const
|
---|
209 | {
|
---|
210 | return sourceCodePosition;
|
---|
211 | }
|
---|
212 | SourceCodePosition &GetSourceCodePosition()
|
---|
213 | {
|
---|
214 | return sourceCodePosition;
|
---|
215 | }
|
---|
216 | void SetSourceCodePosition( const SourceCodePosition &sourceCodePosition )
|
---|
217 | {
|
---|
218 | this->sourceCodePosition = sourceCodePosition;
|
---|
219 | }
|
---|
220 | bool IsInSystemProc() const
|
---|
221 | {
|
---|
222 | return ( (codeType&CODETYPE_SYSTEMPROC) != 0 );
|
---|
223 | }
|
---|
224 | bool IsInDebugProc() const
|
---|
225 | {
|
---|
226 | return ( (codeType&CODETYPE_DEBUGPROC) != 0 );
|
---|
227 | }
|
---|
228 | };
|
---|
229 | typedef std::vector<SourceLine> SourceLines;
|
---|
230 |
|
---|
231 | class NativeCode : public Jenga::Common::Binary
|
---|
232 | {
|
---|
233 | // リンカで解決しなければならないスケジュール
|
---|
234 | Schedules schedules;
|
---|
235 |
|
---|
236 | // ソースコード行番号とネイティブコード位置の対応情報
|
---|
237 | SourceLines sourceLines;
|
---|
238 |
|
---|
239 | // XMLシリアライズ用
|
---|
240 | private:
|
---|
241 | friend class boost::serialization::access;
|
---|
242 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
243 | {
|
---|
244 | trace_for_serialize( "serializing(load) - NativeCode" );
|
---|
245 |
|
---|
246 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Jenga::Common::Binary );
|
---|
247 | ar & BOOST_SERIALIZATION_NVP( schedules );
|
---|
248 | ar & BOOST_SERIALIZATION_NVP( sourceLines );
|
---|
249 | }
|
---|
250 |
|
---|
251 | public:
|
---|
252 | NativeCode()
|
---|
253 | : Jenga::Common::Binary()
|
---|
254 | {
|
---|
255 | }
|
---|
256 | NativeCode( const NativeCode &nativeCode )
|
---|
257 | : Jenga::Common::Binary()
|
---|
258 | {
|
---|
259 | PutEx( nativeCode );
|
---|
260 | }
|
---|
261 | NativeCode( const char *codeBuffer, int size )
|
---|
262 | : Jenga::Common::Binary( codeBuffer, size )
|
---|
263 | {
|
---|
264 | }
|
---|
265 | ~NativeCode()
|
---|
266 | {
|
---|
267 | }
|
---|
268 |
|
---|
269 | void operator =( const NativeCode &nativeCode )
|
---|
270 | {
|
---|
271 | Clear();
|
---|
272 | PutEx( nativeCode );
|
---|
273 | }
|
---|
274 |
|
---|
275 | const Schedules &GetSchedules() const
|
---|
276 | {
|
---|
277 | return schedules;
|
---|
278 | }
|
---|
279 |
|
---|
280 | void PutEx( const NativeCode &nativeCode );
|
---|
281 | void PutEx( long l, Schedule::Type scheduleType );
|
---|
282 | void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
|
---|
283 | void PutCatchAddressSchedule( const UserProc *pUserProc, long codePos );
|
---|
284 | void PutDllProcSchedule( const DllProc *pDllProc );
|
---|
285 | void PutComVtblSchedule( const CClass *pClass );
|
---|
286 | void PutVtblSchedule( const CClass *pClass );
|
---|
287 |
|
---|
288 | const SourceLines &GetSourceLines() const
|
---|
289 | {
|
---|
290 | return sourceLines;
|
---|
291 | }
|
---|
292 | void NextSourceLine( const SourceCodePosition &sourceCodePosition, bool isInSystemProc );
|
---|
293 |
|
---|
294 | void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
|
---|
295 | void ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable );
|
---|
296 |
|
---|
297 | void Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
298 | };
|
---|