[224] | 1 | #pragma once
|
---|
| 2 |
|
---|
| 3 | #include <vector>
|
---|
| 4 |
|
---|
[228] | 5 | #include <jenga/include/common/Exception.h>
|
---|
| 6 |
|
---|
[225] | 7 | #include <BoostSerializationSupport.h>
|
---|
| 8 |
|
---|
[287] | 9 | #include <Binary.h>
|
---|
| 10 |
|
---|
[244] | 11 | class UserProc;
|
---|
| 12 |
|
---|
[224] | 13 | class Schedule
|
---|
| 14 | {
|
---|
| 15 | public:
|
---|
| 16 | enum Type
|
---|
| 17 | {
|
---|
[237] | 18 | None = 10000,
|
---|
[225] | 19 | GlobalVar, // グローバル変数スケジュール
|
---|
[237] | 20 | DataTable, // データテーブル スケジュール
|
---|
[225] | 21 | Relocation, // リロケーション情報スケジュール
|
---|
[244] | 22 | UserProc, // ユーザ定義関数呼び出し側スケジュール
|
---|
| 23 | AddressOf, // ユーザ定義関数位置スケジュール
|
---|
[257] | 24 | DllProc, // DLL関数位置スケジュール
|
---|
[282] | 25 | Vtbl, // vtblスケジュール
|
---|
[355] | 26 | TypeInfo, // TypeInfoスケジュール
|
---|
[224] | 27 | };
|
---|
| 28 |
|
---|
| 29 | private:
|
---|
| 30 | Type type;
|
---|
[244] | 31 | long offset;
|
---|
[224] | 32 |
|
---|
[244] | 33 | union{
|
---|
| 34 | LONG_PTR lpValue;
|
---|
| 35 | const ::UserProc *pUserProc;
|
---|
[250] | 36 | const ::DllProc *pDllProc;
|
---|
[282] | 37 | const ::CClass *pClass;
|
---|
[244] | 38 | };
|
---|
| 39 |
|
---|
[224] | 40 | // XMLシリアライズ用
|
---|
| 41 | private:
|
---|
| 42 | friend class boost::serialization::access;
|
---|
| 43 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 44 | {
|
---|
[256] | 45 | trace_for_serialize( "serializing - Schedule" );
|
---|
| 46 |
|
---|
[224] | 47 | ar & BOOST_SERIALIZATION_NVP( type );
|
---|
| 48 | ar & BOOST_SERIALIZATION_NVP( offset );
|
---|
[272] | 49 |
|
---|
| 50 | switch( type )
|
---|
| 51 | {
|
---|
| 52 | case UserProc:
|
---|
| 53 | case AddressOf:
|
---|
[278] | 54 | ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
|
---|
[272] | 55 | break;
|
---|
| 56 | case DllProc:
|
---|
[278] | 57 | ar & boost::serialization::make_nvp("pDllProc", const_cast<::DllProc *&>(pDllProc));
|
---|
[272] | 58 | break;
|
---|
[282] | 59 | case Vtbl:
|
---|
[355] | 60 | case TypeInfo:
|
---|
[282] | 61 | ar & boost::serialization::make_nvp("pClass", const_cast<::CClass *&>(pClass));
|
---|
| 62 | break;
|
---|
[272] | 63 | default:
|
---|
| 64 | ar & BOOST_SERIALIZATION_NVP( lpValue );
|
---|
| 65 | break;
|
---|
| 66 | }
|
---|
[224] | 67 | }
|
---|
| 68 |
|
---|
| 69 | public:
|
---|
| 70 | Schedule()
|
---|
| 71 | {
|
---|
| 72 | }
|
---|
[258] | 73 | Schedule( Type type, long offset, LONG_PTR lpValue = 0 )
|
---|
[224] | 74 | : type( type )
|
---|
| 75 | , offset( offset )
|
---|
[258] | 76 | , lpValue( lpValue )
|
---|
[224] | 77 | {
|
---|
| 78 | }
|
---|
[258] | 79 | Schedule( const ::UserProc *pUserProc, long offset )
|
---|
[244] | 80 | : type( Schedule::UserProc )
|
---|
| 81 | , offset( offset )
|
---|
| 82 | , pUserProc( pUserProc )
|
---|
| 83 | {
|
---|
| 84 | }
|
---|
[258] | 85 | Schedule( const ::DllProc *pDllProc, long offset )
|
---|
[257] | 86 | : type( Schedule::DllProc )
|
---|
[250] | 87 | , offset( offset )
|
---|
| 88 | , pDllProc( pDllProc )
|
---|
| 89 | {
|
---|
| 90 | }
|
---|
[282] | 91 | Schedule( const ::CClass *pClass, long offset )
|
---|
| 92 | : type( Schedule::Vtbl )
|
---|
| 93 | , offset( offset )
|
---|
| 94 | , pClass( pClass )
|
---|
| 95 | {
|
---|
| 96 | }
|
---|
[355] | 97 | Schedule( Type type, const ::CClass *pClass, long offset )
|
---|
| 98 | : type( type )
|
---|
| 99 | , pClass( pClass )
|
---|
| 100 | , offset( offset )
|
---|
| 101 | {
|
---|
| 102 | }
|
---|
[224] | 103 | ~Schedule()
|
---|
| 104 | {
|
---|
| 105 | }
|
---|
[244] | 106 |
|
---|
[257] | 107 | Type GetType() const
|
---|
| 108 | {
|
---|
| 109 | return type;
|
---|
| 110 | }
|
---|
| 111 | long GetOffset() const
|
---|
| 112 | {
|
---|
| 113 | return offset;
|
---|
| 114 | }
|
---|
[258] | 115 | LONG_PTR GetLongPtrValue() const
|
---|
| 116 | {
|
---|
| 117 | return lpValue;
|
---|
| 118 | }
|
---|
[257] | 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 | {
|
---|
[258] | 129 | if( !( type == Schedule::UserProc || type == Schedule::AddressOf ) )
|
---|
[257] | 130 | {
|
---|
| 131 | SetError();
|
---|
| 132 | }
|
---|
| 133 | return *pUserProc;
|
---|
| 134 | }
|
---|
[282] | 135 | const ::CClass &GetClass() const
|
---|
| 136 | {
|
---|
[355] | 137 | if( !( type == Schedule::Vtbl || type == Schedule::TypeInfo ) )
|
---|
[282] | 138 | {
|
---|
| 139 | SetError();
|
---|
| 140 | }
|
---|
| 141 | return *pClass;
|
---|
| 142 | }
|
---|
[257] | 143 |
|
---|
[244] | 144 | void SpecifyAddressOf()
|
---|
| 145 | {
|
---|
| 146 | if( type != Schedule::UserProc )
|
---|
| 147 | {
|
---|
| 148 | SetError();
|
---|
| 149 | }
|
---|
| 150 | type = Schedule::AddressOf;
|
---|
| 151 | }
|
---|
[224] | 152 | };
|
---|
| 153 | typedef std::vector<Schedule> Schedules;
|
---|
| 154 |
|
---|
[263] | 155 | #define CODETYPE_SYSTEMPROC 0x0001
|
---|
| 156 | #define CODETYPE_DEBUGPROC 0x0002
|
---|
| 157 | class SourceLine
|
---|
| 158 | {
|
---|
| 159 | int lineNum;
|
---|
| 160 | long nativeCodePos;
|
---|
[280] | 161 | int sourceIndex;
|
---|
[263] | 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 );
|
---|
[280] | 174 | ar & BOOST_SERIALIZATION_NVP( sourceIndex );
|
---|
[263] | 175 | ar & BOOST_SERIALIZATION_NVP( sourceCodePos );
|
---|
| 176 | ar & BOOST_SERIALIZATION_NVP( codeType );
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | public:
|
---|
[280] | 180 | SourceLine( int lineNum, int nativeCodePos, int sourceIndex, int sourceCodePos, DWORD codeType )
|
---|
[263] | 181 | : lineNum( lineNum )
|
---|
| 182 | , nativeCodePos( nativeCodePos )
|
---|
[280] | 183 | , sourceIndex( sourceIndex )
|
---|
[263] | 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 | }
|
---|
[280] | 200 | int GetSourceIndex() const
|
---|
| 201 | {
|
---|
| 202 | return sourceIndex;
|
---|
| 203 | }
|
---|
| 204 | void SetSourceIndex( int sourceIndex )
|
---|
| 205 | {
|
---|
| 206 | this->sourceIndex = sourceIndex;
|
---|
| 207 | }
|
---|
[263] | 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 |
|
---|
[287] | 231 | class NativeCode : public Binary
|
---|
[224] | 232 | {
|
---|
[263] | 233 | // リンカで解決しなければならないスケジュール
|
---|
[224] | 234 | Schedules schedules;
|
---|
| 235 |
|
---|
[263] | 236 | // ソースコード行番号とネイティブコード位置の対応情報
|
---|
| 237 | SourceLines sourceLines;
|
---|
| 238 |
|
---|
[224] | 239 | // XMLシリアライズ用
|
---|
| 240 | private:
|
---|
| 241 | friend class boost::serialization::access;
|
---|
[287] | 242 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
[224] | 243 | {
|
---|
[256] | 244 | trace_for_serialize( "serializing(load) - NativeCode" );
|
---|
| 245 |
|
---|
[287] | 246 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Binary );
|
---|
[224] | 247 | ar & BOOST_SERIALIZATION_NVP( schedules );
|
---|
[263] | 248 | ar & BOOST_SERIALIZATION_NVP( sourceLines );
|
---|
[224] | 249 | }
|
---|
[256] | 250 |
|
---|
[224] | 251 | public:
|
---|
| 252 | NativeCode()
|
---|
[287] | 253 | : Binary()
|
---|
[224] | 254 | {
|
---|
| 255 | }
|
---|
[276] | 256 | NativeCode( const NativeCode &nativeCode )
|
---|
[287] | 257 | : Binary()
|
---|
[256] | 258 | {
|
---|
[287] | 259 | PutEx( nativeCode );
|
---|
[256] | 260 | }
|
---|
[276] | 261 | NativeCode( const char *codeBuffer, int size )
|
---|
[287] | 262 | : Binary( codeBuffer, size )
|
---|
[252] | 263 | {
|
---|
| 264 | }
|
---|
[224] | 265 | ~NativeCode()
|
---|
| 266 | {
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[256] | 269 | void operator =( const NativeCode &nativeCode )
|
---|
| 270 | {
|
---|
| 271 | Clear();
|
---|
[287] | 272 | PutEx( nativeCode );
|
---|
[256] | 273 | }
|
---|
| 274 |
|
---|
[257] | 275 | const Schedules &GetSchedules() const
|
---|
| 276 | {
|
---|
| 277 | return schedules;
|
---|
| 278 | }
|
---|
[237] | 279 |
|
---|
[287] | 280 | void PutEx( const NativeCode &nativeCode );
|
---|
| 281 | void PutEx( long l, Schedule::Type scheduleType )
|
---|
[253] | 282 | {
|
---|
[224] | 283 | if( scheduleType != Schedule::None )
|
---|
| 284 | {
|
---|
[287] | 285 | schedules.push_back( Schedule( scheduleType, GetSize() ) );
|
---|
[224] | 286 | }
|
---|
| 287 |
|
---|
[287] | 288 | Put( l );
|
---|
[224] | 289 | }
|
---|
[245] | 290 | void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
|
---|
[250] | 291 | void PutDllProcSchedule( const DllProc *pDllProc );
|
---|
[282] | 292 | void PutVtblSchedule( const CClass *pClass );
|
---|
[263] | 293 |
|
---|
[265] | 294 | const SourceLines &GetSourceLines() const
|
---|
| 295 | {
|
---|
| 296 | return sourceLines;
|
---|
| 297 | }
|
---|
[263] | 298 | void NextSourceLine();
|
---|
[273] | 299 |
|
---|
| 300 | void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
|
---|
[280] | 301 | void ResetSourceIndexes( long sourceIndexBase );
|
---|
[224] | 302 | };
|
---|