1 | #pragma once
|
---|
2 |
|
---|
3 | #include <vector>
|
---|
4 |
|
---|
5 | #include <jenga/include/common/Exception.h>
|
---|
6 |
|
---|
7 | #include <BoostSerializationSupport.h>
|
---|
8 |
|
---|
9 | #include <Binary.h>
|
---|
10 |
|
---|
11 | class UserProc;
|
---|
12 |
|
---|
13 | class Schedule
|
---|
14 | {
|
---|
15 | public:
|
---|
16 | enum Type
|
---|
17 | {
|
---|
18 | None = 10000,
|
---|
19 | GlobalVar, // グローバル変数スケジュール
|
---|
20 | DataTable, // データテーブル スケジュール
|
---|
21 | Relocation, // リロケーション情報スケジュール
|
---|
22 | UserProc, // ユーザ定義関数呼び出し側スケジュール
|
---|
23 | AddressOf, // ユーザ定義関数位置スケジュール
|
---|
24 | DllProc, // DLL関数位置スケジュール
|
---|
25 | Vtbl, // vtblスケジュール
|
---|
26 | TypeInfo, // TypeInfoスケジュール
|
---|
27 | };
|
---|
28 |
|
---|
29 | private:
|
---|
30 | Type type;
|
---|
31 | long offset;
|
---|
32 |
|
---|
33 | union{
|
---|
34 | LONG_PTR lpValue;
|
---|
35 | const ::UserProc *pUserProc;
|
---|
36 | const ::DllProc *pDllProc;
|
---|
37 | const ::CClass *pClass;
|
---|
38 | };
|
---|
39 |
|
---|
40 | // XMLシリアライズ用
|
---|
41 | private:
|
---|
42 | friend class boost::serialization::access;
|
---|
43 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
44 | {
|
---|
45 | trace_for_serialize( "serializing - Schedule" );
|
---|
46 |
|
---|
47 | ar & BOOST_SERIALIZATION_NVP( type );
|
---|
48 | ar & BOOST_SERIALIZATION_NVP( offset );
|
---|
49 |
|
---|
50 | switch( type )
|
---|
51 | {
|
---|
52 | case UserProc:
|
---|
53 | case AddressOf:
|
---|
54 | ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
|
---|
55 | break;
|
---|
56 | case DllProc:
|
---|
57 | ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
|
---|
58 | break;
|
---|
59 | case Vtbl:
|
---|
60 | case TypeInfo:
|
---|
61 | ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass));
|
---|
62 | break;
|
---|
63 | default:
|
---|
64 | ar & BOOST_SERIALIZATION_NVP( lpValue );
|
---|
65 | break;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | public:
|
---|
70 | Schedule()
|
---|
71 | {
|
---|
72 | }
|
---|
73 | Schedule( Type type, long offset, LONG_PTR lpValue = 0 )
|
---|
74 | : type( type )
|
---|
75 | , offset( offset )
|
---|
76 | , lpValue( lpValue )
|
---|
77 | {
|
---|
78 | }
|
---|
79 | Schedule( const ::UserProc *pUserProc, long offset )
|
---|
80 | : type( Schedule::UserProc )
|
---|
81 | , offset( offset )
|
---|
82 | , pUserProc( pUserProc )
|
---|
83 | {
|
---|
84 | }
|
---|
85 | Schedule( const ::DllProc *pDllProc, long offset )
|
---|
86 | : type( Schedule::DllProc )
|
---|
87 | , offset( offset )
|
---|
88 | , pDllProc( pDllProc )
|
---|
89 | {
|
---|
90 | }
|
---|
91 | Schedule( const ::CClass *pClass, long offset )
|
---|
92 | : type( Schedule::Vtbl )
|
---|
93 | , offset( offset )
|
---|
94 | , pClass( pClass )
|
---|
95 | {
|
---|
96 | }
|
---|
97 | Schedule( Type type, const ::CClass *pClass, long offset )
|
---|
98 | : type( type )
|
---|
99 | , pClass( pClass )
|
---|
100 | , offset( offset )
|
---|
101 | {
|
---|
102 | }
|
---|
103 | ~Schedule()
|
---|
104 | {
|
---|
105 | }
|
---|
106 |
|
---|
107 | Type GetType() const
|
---|
108 | {
|
---|
109 | return type;
|
---|
110 | }
|
---|
111 | long GetOffset() const
|
---|
112 | {
|
---|
113 | return offset;
|
---|
114 | }
|
---|
115 | LONG_PTR GetLongPtrValue() const
|
---|
116 | {
|
---|
117 | return lpValue;
|
---|
118 | }
|
---|
119 | const ::DllProc &GetDllProc() const
|
---|
120 | {
|
---|
121 | if( type != Schedule::DllProc )
|
---|
122 | {
|
---|
123 | SetError();
|
---|
124 | }
|
---|
125 | return *pDllProc;
|
---|
126 | }
|
---|
127 | const ::UserProc &GetUserProc() const
|
---|
128 | {
|
---|
129 | if( !( type == Schedule::UserProc || type == Schedule::AddressOf ) )
|
---|
130 | {
|
---|
131 | SetError();
|
---|
132 | }
|
---|
133 | return *pUserProc;
|
---|
134 | }
|
---|
135 | const ::CClass &GetClass() const
|
---|
136 | {
|
---|
137 | if( !( type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
|
---|
138 | {
|
---|
139 | SetError();
|
---|
140 | }
|
---|
141 | return *pClass;
|
---|
142 | }
|
---|
143 |
|
---|
144 | void SpecifyAddressOf()
|
---|
145 | {
|
---|
146 | if( type != Schedule::UserProc )
|
---|
147 | {
|
---|
148 | SetError();
|
---|
149 | }
|
---|
150 | type = Schedule::AddressOf;
|
---|
151 | }
|
---|
152 | };
|
---|
153 | typedef std::vector<Schedule> Schedules;
|
---|
154 |
|
---|
155 | #define CODETYPE_SYSTEMPROC 0x0001
|
---|
156 | #define CODETYPE_DEBUGPROC 0x0002
|
---|
157 | class SourceLine
|
---|
158 | {
|
---|
159 | int lineNum;
|
---|
160 | long nativeCodePos;
|
---|
161 | int sourceIndex;
|
---|
162 | long sourceCodePos;
|
---|
163 | DWORD codeType;
|
---|
164 |
|
---|
165 | // XMLシリアライズ用
|
---|
166 | private:
|
---|
167 | friend class boost::serialization::access;
|
---|
168 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
169 | {
|
---|
170 | trace_for_serialize( "serializing - SourceLine" );
|
---|
171 |
|
---|
172 | ar & BOOST_SERIALIZATION_NVP( lineNum );
|
---|
173 | ar & BOOST_SERIALIZATION_NVP( nativeCodePos );
|
---|
174 | ar & BOOST_SERIALIZATION_NVP( sourceIndex );
|
---|
175 | ar & BOOST_SERIALIZATION_NVP( sourceCodePos );
|
---|
176 | ar & BOOST_SERIALIZATION_NVP( codeType );
|
---|
177 | }
|
---|
178 |
|
---|
179 | public:
|
---|
180 | SourceLine( int lineNum, int nativeCodePos, int sourceIndex, int sourceCodePos, DWORD codeType )
|
---|
181 | : lineNum( lineNum )
|
---|
182 | , nativeCodePos( nativeCodePos )
|
---|
183 | , sourceIndex( sourceIndex )
|
---|
184 | , sourceCodePos( sourceCodePos )
|
---|
185 | , codeType( codeType )
|
---|
186 | {
|
---|
187 | }
|
---|
188 | SourceLine()
|
---|
189 | {
|
---|
190 | }
|
---|
191 |
|
---|
192 | int GetLineNum() const
|
---|
193 | {
|
---|
194 | return lineNum;
|
---|
195 | }
|
---|
196 | long GetNativeCodePos() const
|
---|
197 | {
|
---|
198 | return nativeCodePos;
|
---|
199 | }
|
---|
200 | int GetSourceIndex() const
|
---|
201 | {
|
---|
202 | return sourceIndex;
|
---|
203 | }
|
---|
204 | void SetSourceIndex( int sourceIndex )
|
---|
205 | {
|
---|
206 | this->sourceIndex = sourceIndex;
|
---|
207 | }
|
---|
208 | long GetSourceCodePos() const
|
---|
209 | {
|
---|
210 | return sourceCodePos;
|
---|
211 | }
|
---|
212 | void SetSourceCodePos( int sourceCodePos )
|
---|
213 | {
|
---|
214 | this->sourceCodePos = sourceCodePos;
|
---|
215 | }
|
---|
216 | DWORD GetCodeType() const
|
---|
217 | {
|
---|
218 | return codeType;
|
---|
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 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( Binary );
|
---|
247 | ar & BOOST_SERIALIZATION_NVP( schedules );
|
---|
248 | ar & BOOST_SERIALIZATION_NVP( sourceLines );
|
---|
249 | }
|
---|
250 |
|
---|
251 | public:
|
---|
252 | NativeCode()
|
---|
253 | : Binary()
|
---|
254 | {
|
---|
255 | }
|
---|
256 | NativeCode( const NativeCode &nativeCode )
|
---|
257 | : Binary()
|
---|
258 | {
|
---|
259 | PutEx( nativeCode );
|
---|
260 | }
|
---|
261 | NativeCode( const char *codeBuffer, int size )
|
---|
262 | : 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 | {
|
---|
283 | if( scheduleType != Schedule::None )
|
---|
284 | {
|
---|
285 | schedules.push_back( Schedule( scheduleType, GetSize() ) );
|
---|
286 | }
|
---|
287 |
|
---|
288 | Put( l );
|
---|
289 | }
|
---|
290 | void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
|
---|
291 | void PutDllProcSchedule( const DllProc *pDllProc );
|
---|
292 | void PutVtblSchedule( const CClass *pClass );
|
---|
293 |
|
---|
294 | const SourceLines &GetSourceLines() const
|
---|
295 | {
|
---|
296 | return sourceLines;
|
---|
297 | }
|
---|
298 | void NextSourceLine();
|
---|
299 |
|
---|
300 | void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
|
---|
301 | void ResetSourceIndexes( long sourceIndexBase );
|
---|
302 | };
|
---|