Changeset 75 in dev for BasicCompiler64/MakePeHdr.cpp
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler64/MakePeHdr.cpp
r73 r75 6 6 // 特殊関数の構造体ポインタ 7 7 //////////////////////////// 8 SubInfo 8 UserProc 9 9 *pSub_System_StartupProgram, 10 10 *pSub_DebugSys_StartProc, … … 136 136 137 137 //関数ポインタ情報を初期化 138 extern P ROCPTRINFO *pProcPtrInfo;138 extern ProcPointer **ppProcPointer; 139 139 extern int ProcPtrInfoNum; 140 p ProcPtrInfo=(PROCPTRINFO*)HeapAlloc(hHeap,0,1);140 ppProcPointer=(ProcPointer **)HeapAlloc(hHeap,0,1); 141 141 ProcPtrInfoNum=0; 142 142 … … 170 170 171 171 if(pSub_System_StartupProgram=GetSubHash("_System_StartupProgram",1)) 172 pSub_System_StartupProgram-> bUse=1;172 pSub_System_StartupProgram->Using(); 173 173 174 174 if(pSub_DebugSys_StartProc=GetSubHash("_DebugSys_StartProc",1)) 175 pSub_DebugSys_StartProc-> bUse=1;175 pSub_DebugSys_StartProc->Using(); 176 176 177 177 if(pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc",1)) 178 pSub_DebugSys_EndProc-> bUse=1;178 pSub_DebugSys_EndProc->Using(); 179 179 180 180 if(pSub_DebugSys_SaveContext=GetSubHash("_DebugSys_SaveContext",1)) 181 pSub_DebugSys_SaveContext-> bUse=1;181 pSub_DebugSys_SaveContext->Using(); 182 182 183 183 if(pSub_System_GetEip=GetSubHash("_System_GetEip",1)){ 184 pSub_System_GetEip-> bUse=1;185 pSub_System_GetEip-> bSystem=1;184 pSub_System_GetEip->Using(); 185 pSub_System_GetEip->ThisIsSystemProc(); 186 186 } 187 187 188 188 if(pSub_System_InitDllGlobalVariables=GetSubHash("_System_InitDllGlobalVariables",1)){ 189 pSub_System_InitDllGlobalVariables-> bUse=1;190 pSub_System_InitDllGlobalVariables-> bSystem=1;189 pSub_System_InitDllGlobalVariables->Using(); 190 pSub_System_InitDllGlobalVariables->ThisIsSystemProc(); 191 191 } 192 192 193 193 if(pSub_System_InitStaticLocalVariables=GetSubHash("_System_InitStaticLocalVariables",1)){ 194 pSub_System_InitStaticLocalVariables-> bUse=1;195 pSub_System_InitStaticLocalVariables-> bSystem=1;194 pSub_System_InitStaticLocalVariables->Using(); 195 pSub_System_InitStaticLocalVariables->ThisIsSystemProc(); 196 196 } 197 197 198 198 if(pSub_System_Call_Destructor_of_GlobalObject=GetSubHash("_System_Call_Destructor_of_GlobalObject",1)){ 199 pSub_System_Call_Destructor_of_GlobalObject-> bUse=1;200 pSub_System_Call_Destructor_of_GlobalObject-> bSystem=1;199 pSub_System_Call_Destructor_of_GlobalObject->Using(); 200 pSub_System_Call_Destructor_of_GlobalObject->ThisIsSystemProc(); 201 201 } 202 202 203 203 if(pSub_System_GetSp=GetSubHash("_System_GetSp",1)){ 204 pSub_System_GetSp-> bUse=1;205 pSub_System_GetSp-> bSystem=1;204 pSub_System_GetSp->Using(); 205 pSub_System_GetSp->ThisIsSystemProc(); 206 206 } 207 207 208 208 if(pSub_pow=GetSubHash("pow",1)) 209 pSub_pow-> bUse=1;209 pSub_pow->Using(); 210 210 211 211 if(pSub_calloc=GetSubHash("calloc",1)) 212 pSub_calloc-> bUse=1;212 pSub_calloc->Using(); 213 213 214 214 if(pSub_realloc=GetSubHash("realloc",1)) 215 pSub_realloc-> bUse=1;215 pSub_realloc->Using(); 216 216 217 217 if(pSub_free=GetSubHash("free",1)) 218 pSub_free-> bUse=1;218 pSub_free->Using(); 219 219 220 220 if( pSub_System_GC_malloc_ForObject = GetSubHash( "_System_GC_malloc_ForObject",1 ) ) 221 pSub_System_GC_malloc_ForObject-> bUse = 1;221 pSub_System_GC_malloc_ForObject->Using(); 222 222 223 223 if( pSub_System_GC_malloc_ForObjectPtr = GetSubHash( "_System_GC_malloc_ForObjectPtr",1 ) ) 224 pSub_System_GC_malloc_ForObjectPtr-> bUse = 1;224 pSub_System_GC_malloc_ForObjectPtr->Using(); 225 225 226 226 if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) ) 227 pSub_System_GC_free_for_SweepingDelete-> bUse = 1;227 pSub_System_GC_free_for_SweepingDelete->Using(); 228 228 229 229 … … 271 271 272 272 cp=-1; 273 extern BOOL bCompilingGlobal; 274 bCompilingGlobal=1; 273 UserProc::CompileStartForGlobalArea(); 275 274 276 275 if(!bDll){ … … 352 351 353 352 //call _System_Call_Destructor_of_GlobalObject 354 extern SubInfo*pSub_System_Call_Destructor_of_GlobalObject;353 extern UserProc *pSub_System_Call_Destructor_of_GlobalObject; 355 354 op_call(pSub_System_Call_Destructor_of_GlobalObject); 356 355 … … 405 404 ///////////////////// 406 405 407 bCompilingGlobal=0;408 409 406 //プロシージャをコンパイル開始 410 407 cp=0; … … 429 426 //////////////////////////////// 430 427 for(i=0;i<MAX_HASH;i++){ 431 extern DECLAREINFO **ppDeclareHash; 432 DECLAREINFO *pdi; 433 pdi=ppDeclareHash[i]; 434 while(pdi){ 435 if(pdi->bUse==0){ 436 pdi=pdi->pNextData; 428 extern DllProc **ppDeclareHash; 429 const DllProc *pDllProc = ppDeclareHash[i]; 430 while(pDllProc){ 431 if( !pDllProc->IsUsing() ){ 432 pDllProc=pDllProc->pNextData; 437 433 continue; 438 434 } … … 440 436 //エラーチェック 441 437 HINSTANCE hLib; 442 hLib=LoadLibrary( pdi->file);438 hLib=LoadLibrary( pDllProc->GetDllFileName().c_str() ); 443 439 if(!hLib){ 444 440 extern char OutputFileName[MAX_PATH]; … … 446 442 _splitpath(OutputFileName,temp2,temp3,NULL,NULL); 447 443 lstrcat(temp2,temp3); 448 lstrcpy(temp3,p di->file);444 lstrcpy(temp3,pDllProc->GetDllFileName().c_str()); 449 445 GetFullPath(temp3,temp2); 450 446 hLib=LoadLibrary(temp3); 451 447 452 448 if(!hLib){ 453 SetError(-106,p di->file,pdi->pos);449 SetError(-106,pDllProc->GetDllFileName().c_str(),pDllProc->GetCodePos()); 454 450 } 455 451 } 456 452 457 453 if(hLib){ 458 if(!GetProcAddress(hLib,p di->alias)){454 if(!GetProcAddress(hLib,pDllProc->GetAlias().c_str())){ 459 455 FreeLibrary(hLib); 460 SetError(-107,p di->alias,pdi->pos);456 SetError(-107,pDllProc->GetAlias(),pDllProc->GetCodePos()); 461 457 } 462 458 FreeLibrary(hLib); 463 459 } 464 460 465 p di=pdi->pNextData;461 pDllProc=pDllProc->pNextData; 466 462 } 467 463 } … … 500 496 ExportNamesLength=lstrlen(lpExportNames)+1; 501 497 502 extern SubInfo**ppSubHash;503 SubInfo *psi,*psi2;498 extern UserProc **ppSubHash; 499 UserProc *pUserProc,*psi2; 504 500 while(1){ 505 501 //辞書順にサーチ 506 502 temporary[0]=0; 507 503 for(i=0,psi2=0;i<MAX_HASH;i++){ 508 p si=ppSubHash[i];509 while(p si){510 if(p si->bExport){504 pUserProc=ppSubHash[i]; 505 while(pUserProc){ 506 if(pUserProc->IsExport()){ 511 507 if(temporary[0]=='\0'){ 512 lstrcpy(temporary,p si->name);513 psi2=p si;508 lstrcpy(temporary,pUserProc->GetName().c_str()); 509 psi2=pUserProc; 514 510 } 515 511 else{ 516 512 i3=lstrlen(temporary); 517 i4= lstrlen(psi->name);513 i4=(int)pUserProc->GetName().size(); 518 514 if(i3<i4) i3=i4; 519 if(memcmp(temporary,p si->name,i3)>0){520 lstrcpy(temporary,p si->name);521 psi2=p si;515 if(memcmp(temporary,pUserProc->GetName().c_str(),i3)>0){ 516 lstrcpy(temporary,pUserProc->GetName().c_str()); 517 psi2=pUserProc; 522 518 } 523 519 } 524 520 } 525 p si=psi->pNextData;521 pUserProc=pUserProc->pNextData; 526 522 } 527 523 } 528 524 if(psi2==0) break; 529 psi=psi2; 530 531 psi->bExport=0; 532 533 if(lstrcmpi(psi->name,"DllMain")==0) 534 DllMain_EntryPoint=psi->CompileAddress; 525 pUserProc=psi2; 526 527 pUserProc->ExportOff(); 528 529 if( pUserProc->GetName() == "DllMain" ){ 530 DllMain_EntryPoint=pUserProc->beginOpAddress; 531 } 535 532 536 533 lpdwExportAddressTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportAddressTable,(ExportNum+1)*sizeof(DWORD)); 537 lpdwExportAddressTable[ExportNum]=p si->CompileAddress;534 lpdwExportAddressTable[ExportNum]=pUserProc->beginOpAddress; 538 535 539 536 lpdwExportNamePointerTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportNamePointerTable,(ExportNum+1)*sizeof(DWORD)); … … 543 540 lpwExportOrdinalTable[ExportNum]=ExportNum; 544 541 545 lstrcpy(lpExportNames+ExportNamesLength,p si->name);542 lstrcpy(lpExportNames+ExportNamesLength,pUserProc->GetName().c_str()); 546 543 ExportNamesLength+=lstrlen(lpExportNames+ExportNamesLength)+1; 547 544 … … 576 573 //インポートDLL情報 577 574 ///////////////////// 578 extern D ECLAREINFO**ppDeclareHash;579 D ECLAREINFO *pdi;575 extern DllProc **ppDeclareHash; 576 DllProc *pDllProc; 580 577 char **ppDllNames; 581 578 int ImportDllNum; … … 613 610 ImportDllNum=0; 614 611 for(i=0;i<MAX_HASH;i++){ 615 pdi=ppDeclareHash[i]; 616 while(pdi){ 617 if(pdi->dwType==DECLARE_STATIC|| 618 pdi->bUse==0){ 619 pdi=pdi->pNextData; 612 const DllProc *pDllProc=ppDeclareHash[i]; 613 while(pDllProc){ 614 if( !pDllProc->IsUsing() ){ 615 pDllProc=pDllProc->pNextData; 620 616 continue; 621 617 } 622 618 623 if( lstrlen(pdi->file)>16){619 if( pDllProc->GetDllFileName().size() > 16 ){ 624 620 SetError(7,NULL,cp); 625 621 break; 626 622 } 627 623 for(i2=0;i2<ImportDllNum;i2++){ 628 if(lstrcmp(ppDllNames[i2],pdi->file)==0) break; 624 if( pDllProc->GetDllFileName() == ppDllNames[i2] ){ 625 break; 626 } 629 627 } 630 628 if(i2==ImportDllNum){ 631 629 ppDllNames=(char **)HeapReAlloc(hHeap,0,ppDllNames,(ImportDllNum+1)*sizeof(char **)); 632 630 ppDllNames[ImportDllNum]=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,16); 633 lstrcpy(ppDllNames[ImportDllNum],p di->file);631 lstrcpy(ppDllNames[ImportDllNum],pDllProc->GetDllFileName().c_str()); 634 632 ImportDllNum++; 635 633 } 636 634 637 p di=pdi->pNextData;635 pDllProc=pDllProc->pNextData; 638 636 } 639 637 } … … 651 649 pImportDescriptor[i].Name=i*0x10; //※すぐ下で再計算 652 650 for(i2=0;i2<MAX_HASH;i2++){ 653 pdi=ppDeclareHash[i2]; 654 while(pdi){ 655 if(pdi->dwType==DECLARE_STATIC|| 656 pdi->bUse==0){ 657 pdi=pdi->pNextData; 651 pDllProc=ppDeclareHash[i2]; 652 while(pDllProc){ 653 if( !pDllProc->IsUsing() ){ 654 pDllProc=pDllProc->pNextData; 658 655 continue; 659 656 } 660 657 661 if( lstrcmp(ppDllNames[i],pdi->file)==0){658 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 662 659 //ルックアップデータのサイズを追加 663 660 LookupSize+=sizeof(_int64); 664 661 } 665 662 666 p di=pdi->pNextData;663 pDllProc=pDllProc->pNextData; 667 664 } 668 665 } … … 691 688 for(i=0,i5=0;i<ImportDllNum;i++){ 692 689 for(i2=0;i2<MAX_HASH;i2++){ 693 pdi=ppDeclareHash[i2]; 694 while(pdi){ 695 if(pdi->dwType==DECLARE_STATIC|| 696 pdi->bUse==0){ 697 pdi=pdi->pNextData; 690 pDllProc=ppDeclareHash[i2]; 691 while(pDllProc){ 692 if( !pDllProc->IsUsing() ){ 693 pDllProc=pDllProc->pNextData; 698 694 continue; 699 695 } 700 696 701 if( lstrcmp(ppDllNames[i],pdi->file)==0){697 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 702 698 //ルックアップの位置をセット(後にインポート アドレス テーブルにセットしなおされる) 703 p di->LookupAddress=i5*sizeof(_int64);699 pDllProc->SetLookupAddress( i5*sizeof(_int64) ); 704 700 705 701 //ルックアップ テーブルの値をセット … … 714 710 pHintTable[HintSize++]=0; 715 711 pHintTable[HintSize++]=0; 716 lstrcpy(pHintTable+HintSize,p di->alias);717 i4= lstrlen(pdi->alias);712 lstrcpy(pHintTable+HintSize,pDllProc->GetAlias().c_str()); 713 i4=(int)pDllProc->GetAlias().size(); 718 714 HintSize+=i4+1; 719 715 if(i4%2==0) pHintTable[HintSize++]=0; … … 725 721 } 726 722 727 p di=pdi->pNextData;723 pDllProc=pDllProc->pNextData; 728 724 } 729 725 } … … 742 738 //グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う 743 739 //(デバッグ情報で利用される) 744 extern int MaxGlobalVarNum;745 extern VARIABLE *GlobalVar;746 740 extern int AllInitGlobalVarSize; 747 for (i=0;i<MaxGlobalVarNum;i++){748 if( GlobalVar[i].offset&0x80000000){749 GlobalVar[i].offset=(GlobalVar[i].offset&0x7FFFFFFF)+AllInitGlobalVarSize;741 foreach( Variable *pVar, globalVars ){ 742 if(pVar->offset&0x80000000){ 743 pVar->offset=(pVar->offset&0x7FFFFFFF)+AllInitGlobalVarSize; 750 744 } 751 745 } … … 997 991 998 992 for(i2=0;i2<MAX_HASH;i2++){ 999 pdi=ppDeclareHash[i2];1000 while(p di){1001 if( pdi->bUse==0){1002 p di=pdi->pNextData;993 const DllProc *pDllProc=ppDeclareHash[i2]; 994 while(pDllProc){ 995 if( !pDllProc->IsUsing() ){ 996 pDllProc=pDllProc->pNextData; 1003 997 continue; 1004 998 } 1005 999 1006 if( lstrcmp(ppDllNames[i],pdi->file)==0){1000 if( pDllProc->GetDllFileName() == ppDllNames[i] ){ 1007 1001 //ルックアップ テーブル 1008 1002 pLookupTable[i5++]+=MemPos_ImportSection; 1009 1003 } 1010 1004 1011 p di=pdi->pNextData;1005 pDllProc=pDllProc->pNextData; 1012 1006 } 1013 1007 } … … 1033 1027 // ※x86はRVAからのオフセット。x64はRPI(実行中アドレス)からのオフセット 1034 1028 for(i=0;i<pobj_ImportAddrSchedule->num;i++){ 1035 D ECLAREINFO *pdi;1036 p di=pobj_ImportAddrSchedule->ppdi[i];1029 DllProc *pDllProc; 1030 pDllProc=pobj_ImportAddrSchedule->ppdi[i]; 1037 1031 *((long *)(OpBuffer+pobj_ImportAddrSchedule->pObpValues[i]))= 1038 1032 MemPos_ImportSection+ 1039 p di->LookupAddress1033 pDllProc->GetLookupAddress() 1040 1034 -(MemPos_CodeSection+pobj_ImportAddrSchedule->pObpValues[i]+sizeof(long)); 1041 1035 } … … 1046 1040 // プロシージャポインタスケジュール 1047 1041 for(i=0;i<pobj_SubAddrSchedule->num;i++){ 1048 if(pobj_SubAddrSchedule->ppsi[i]-> CompileAddress==01049 &&pobj_SubAddrSchedule->ppsi[i]-> EndOpAddr==0){1042 if(pobj_SubAddrSchedule->ppsi[i]->beginOpAddress==0 1043 &&pobj_SubAddrSchedule->ppsi[i]->endOpAddress==0){ 1050 1044 SetError(300,NULL,-1); 1051 1045 } … … 1053 1047 if(pobj_SubAddrSchedule->pbCall[i]){ 1054 1048 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1055 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long));1049 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long)); 1056 1050 } 1057 1051 else{ 1058 1052 *((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))= 1059 pobj_SubAddrSchedule->ppsi[i]-> CompileAddress+ImageBase+MemPos_CodeSection;1053 pobj_SubAddrSchedule->ppsi[i]->beginOpAddress+ImageBase+MemPos_CodeSection; 1060 1054 } 1061 1055 } … … 1098 1092 //グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う 1099 1093 //(デバッグ情報で利用される) 1100 extern int MaxGlobalVarNum; 1101 extern VARIABLE *GlobalVar; 1102 for(i=0;i<MaxGlobalVarNum;i++){ 1103 if(GlobalVar[i].offset&0x80000000){ 1104 GlobalVar[i].offset=(GlobalVar[i].offset&0x7FFFFFFF)+AllInitGlobalVarSize; 1094 foreach( Variable *pVar, globalVars ){ 1095 if(pVar->offset&0x80000000){ 1096 pVar->offset=(pVar->offset&0x7FFFFFFF)+AllInitGlobalVarSize; 1105 1097 } 1106 1098 }
Note:
See TracChangeset
for help on using the changeset viewer.