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