Changeset 956 for trunk/src/kernel32/wprocess.cpp
- Timestamp:
- Sep 16, 1999, 1:39:08 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/wprocess.cpp
r712 r956 1 /* $Id: wprocess.cpp,v 1.3 0 1999-08-27 16:51:01sandervl Exp $ */1 /* $Id: wprocess.cpp,v 1.31 1999-09-15 23:38:03 sandervl Exp $ */ 2 2 3 3 /* … … 15 15 #include <string.h> 16 16 17 #include "unicode.h" 18 #include "windll.h" 19 #include "winexe.h" 17 #include <unicode.h> 18 #include <windllbase.h> 19 #include <winexebase.h> 20 #include <windllpeldr.h> 20 21 21 22 #ifdef __IBMCPP__ … … 32 33 #include "mmap.h" 33 34 34 BOOL fExeStarted = FALSE;35 35 BOOL fFreeLibrary = FALSE; 36 36 … … 199 199 return GetFS(); 200 200 } 201 /******************************************************************************/202 //******************************************************************************203 void WIN32API RegisterExe(WIN32EXEENTRY EntryPoint, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,204 LPDWORD TlsIndexAddr, ULONG TlsInitSize,205 ULONG TlsTotalSize, LPVOID TlsAddress,206 LONG Win32TableId, LONG NameTableId, LONG VersionResId,207 LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwReserved)208 {209 if(WinExe != NULL) //should never happen210 delete(WinExe);211 212 CheckVersion(Pe2lxVersion, OSLibGetDllName(hinstance));213 214 if(getenv("WIN32_IOPL2")) {215 io_init1();216 }217 218 Win32Exe *winexe;219 220 winexe = new Win32Exe(hinstance, NameTableId, Win32TableId);221 222 if(winexe) {223 dprintf(("RegisterExe Win32TableId = %x", Win32TableId));224 dprintf(("RegisterExe NameTableId = %x", NameTableId));225 dprintf(("RegisterExe VersionResId = %x", VersionResId));226 dprintf(("RegisterExe Pe2lxVersion = %x", Pe2lxVersion));227 228 winexe->setVersionId(VersionResId);229 winexe->setEntryPoint((ULONG)EntryPoint);230 winexe->setTLSAddress(TlsAddress);231 winexe->setTLSInitSize(TlsInitSize);232 winexe->setTLSTotalSize(TlsTotalSize);233 winexe->setTLSIndexAddr(TlsIndexAddr);234 winexe->setTLSCallBackAddr(TlsCallbackAddr);235 236 winexe->start();237 }238 else {239 eprintf(("Win32Exe creation failed!\n"));240 DebugInt3();241 return;242 }243 }244 //******************************************************************************245 //******************************************************************************246 ULONG WIN32API RegisterDll(WIN32DLLENTRY pfnDllEntry, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,247 LPDWORD TlsIndexAddr, ULONG TlsInitSize,248 ULONG TlsTotalSize, LPVOID TlsAddress,249 LONG Win32TableId, LONG NameTableId, LONG VersionResId,250 LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwAttachType)251 {252 char *name;253 254 Win32Dll *winmod = Win32Dll::findModule(hinstance);255 if(dwAttachType == 0)256 { //Process attach257 if(getenv("WIN32_IOPL2")) {258 io_init1();259 }260 name = OSLibGetDllName(hinstance);261 CheckVersion(Pe2lxVersion, name);262 263 dprintf(("RegisterDll %X %s reason %d\n", hinstance, name, dwAttachType));264 dprintf(("RegisterDll Win32TableId = %x", Win32TableId));265 dprintf(("RegisterDll NameTableId = %x", NameTableId));266 dprintf(("RegisterDll VersionResId = %x", VersionResId));267 dprintf(("RegisterDll Pe2lxVersion = %x", Pe2lxVersion));268 269 if(winmod != NULL) {270 //dll manually loaded by PE loader (Win32Dll::init)271 winmod->OS2DllInit(hinstance, NameTableId, Win32TableId, pfnDllEntry);272 }273 else {274 //converted win32 dll loaded by OS/2 loader275 winmod = new Win32Dll(hinstance, NameTableId, Win32TableId, pfnDllEntry);276 if(winmod == NULL) {277 eprintf(("Failed to allocate module object!\n"));278 DebugInt3();279 return 0; //fail dll load280 }281 }282 winmod->setTLSAddress(TlsAddress);283 winmod->setTLSInitSize(TlsInitSize);284 winmod->setTLSTotalSize(TlsTotalSize);285 winmod->setTLSIndexAddr(TlsIndexAddr);286 winmod->setTLSCallBackAddr(TlsCallbackAddr);287 288 /* @@@PH 1998/03/17 console devices initialization */289 iConsoleDevicesRegister();290 291 //SvL: 19-8-'98292 winmod->AddRef();293 winmod->setVersionId(VersionResId);294 295 winmod->attachProcess();296 }297 else {//process detach298 if(winmod != NULL && !fFreeLibrary) {299 return 0; //don't unload (OS/2 dll unload bug)300 }301 //Runtime environment could already be gone, so don't do this302 // dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n"));303 }304 return 1; //success305 }306 201 //****************************************************************************** 307 202 //****************************************************************************** … … 346 241 BOOL WIN32API FreeLibrary(HINSTANCE hinstance) 347 242 { 348 Win32Dll *winmod;243 Win32DllBase *winmod; 349 244 BOOL rc; 350 245 351 246 dprintf(("FreeLibrary")); 352 winmod = Win32Dll ::findModule(hinstance);247 winmod = Win32DllBase::findModule(hinstance); 353 248 if(winmod) { 354 winmod->Release();355 return(TRUE);249 winmod->Release(); 250 return(TRUE); 356 251 } 357 252 dprintf(("KERNEL32: FreeLibrary %s %X\n", OSLibGetDllName(hinstance), hinstance)); … … 366 261 /******************************************************************************/ 367 262 /******************************************************************************/ 368 static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile )263 static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile, DWORD dwFlags) 369 264 { 370 265 char modname[CCHMAXPATH]; 371 266 HINSTANCE hDll; 372 Win32Dll 267 Win32DllBase *module; 373 268 374 269 hDll = O32_LoadLibrary(lpszLibFile); … … 388 283 } 389 284 390 if(Win32Image::isPEImage((char *)modname)) { 391 module = Win32Dll::findModule((char *)modname); 392 if(module) {//don't load it again 393 module->AddRef(); 394 return module->getInstanceHandle(); 395 } 396 397 module = new Win32Dll((char *)modname); 398 if(module == NULL) 399 return(0); 400 401 module->init(0); 402 if(module->getError() != NO_ERROR) { 403 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile)); 404 delete(module); 405 return(0); 406 } 407 if(module->attachProcess() == FALSE) { 408 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile)); 409 delete(module); 410 return(0); 411 } 412 module->AddRef(); 413 return module->getInstanceHandle(); 414 } 415 else 416 return(0); 417 } 418 419 285 if(Win32ImageBase::isPEImage((char *)modname)) 286 { 287 module = Win32DllBase::findModule((char *)modname); 288 if(module) {//don't load it again 289 module->AddRef(); 290 return module->getInstanceHandle(); 291 } 292 293 Win32PeLdrDll *peldrDll = new Win32PeLdrDll((char *)modname); 294 if(peldrDll == NULL) 295 return(0); 296 297 peldrDll->init(0); 298 if(peldrDll->getError() != NO_ERROR) { 299 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile)); 300 delete(peldrDll); 301 return(0); 302 } 303 if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) { 304 peldrDll->setNoEntryCalls(); 305 } 306 307 if(peldrDll->attachProcess() == FALSE) { 308 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile)); 309 delete(peldrDll); 310 return(0); 311 } 312 peldrDll->AddRef(); 313 return peldrDll->getInstanceHandle(); 314 } 315 else return(0); 316 } 317 //****************************************************************************** 318 //****************************************************************************** 420 319 HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile) 421 320 { … … 425 324 lpszLibFile)); 426 325 427 hDll = iLoadLibraryA(lpszLibFile );326 hDll = iLoadLibraryA(lpszLibFile, 0); 428 327 if (hDll == 0) 429 328 { … … 438 337 439 338 // now try again without fully qualified path 440 hDll = iLoadLibraryA(pszName );339 hDll = iLoadLibraryA(pszName, 0); 441 340 } 442 341 } … … 448 347 HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags) 449 348 { 450 Win32Dll *module; 451 HINSTANCE hDll; 349 HINSTANCE hDll; 452 350 453 351 dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags)); 454 hDll = O32_LoadLibrary(lpszLibFile); 455 if(hDll) { 456 return hDll; //converted dll or win32k took care of it 457 } 458 459 if(Win32Image::isPEImage((char *)lpszLibFile)) { 460 module = Win32Dll::findModule((char *)lpszLibFile); 461 if(module) {//don't load it again 462 module->AddRef(); 463 return module->getInstanceHandle(); 352 hDll = iLoadLibraryA(lpszLibFile, dwFlags); 353 if (hDll == 0) 354 { 355 char * pszName; 356 357 // remove path from the image name 358 pszName = strrchr((char *)lpszLibFile, 359 '\\'); 360 if (pszName != NULL) 361 { 362 pszName++; // skip backslash 363 364 // now try again without fully qualified path 365 hDll = iLoadLibraryA(pszName, dwFlags); 464 366 } 465 466 module = new Win32Dll((char *)lpszLibFile); 467 468 if(module == NULL) 469 return(0); 470 471 module->init(0); 472 if(module->getError() != NO_ERROR) { 473 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile)); 474 delete(module); 475 return(0); 476 } 477 if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) { 478 module->setNoEntryCalls(); 479 } 480 if(module->attachProcess() == FALSE) { 481 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile)); 482 delete(module); 483 return(0); 484 } 485 module->AddRef(); 486 return module->getInstanceHandle(); 487 } 488 return(0); 367 } 368 369 return hDll; 489 370 } 490 371 //****************************************************************************** … … 562 443 { 563 444 DWORD rc; 564 Win32Image *module;445 Win32ImageBase *module; 565 446 char *fpath = NULL; 566 447 567 448 dprintf(("GetModuleFileName %X", hinstModule)); 568 449 if(hinstModule == 0 || hinstModule == -1 || (WinExe && hinstModule == WinExe->getInstanceHandle())) { 569 module = (Win32Image *)WinExe;450 module = (Win32ImageBase *)WinExe; 570 451 } 571 452 else { 572 module = (Win32Image *)Win32Dll::findModule(hinstModule);453 module = (Win32ImageBase *)Win32DllBase::findModule(hinstModule); 573 454 } 574 455 … … 608 489 { 609 490 HANDLE hMod; 610 Win32Dll *windll;491 Win32DllBase *windll; 611 492 char szModule[CCHMAXPATH]; 612 493 BOOL fDllModule = FALSE; … … 636 517 } 637 518 else { 638 windll = Win32Dll ::findModule(szModule);519 windll = Win32DllBase::findModule(szModule); 639 520 if(windll) { 640 521 hMod = windll->getInstanceHandle(); … … 722 603 FARPROC WIN32API GetProcAddress(HMODULE hModule, LPCSTR lpszProc) 723 604 { 724 Win32Dll *winmod;605 Win32DllBase *winmod; 725 606 FARPROC proc; 726 607 ULONG ulAPIOrdinal; 727 608 728 winmod = Win32Dll ::findModule((HINSTANCE)hModule);609 winmod = Win32DllBase::findModule((HINSTANCE)hModule); 729 610 if(winmod) { 730 ulAPIOrdinal = (ULONG)lpszProc; 731 if (ulAPIOrdinal <= 0x0000FFFF) { 732 return (FARPROC)winmod->getApi((int)ulAPIOrdinal); 733 } 734 else return (FARPROC)winmod->getApi((char *)lpszProc); 611 ulAPIOrdinal = (ULONG)lpszProc; 612 if (ulAPIOrdinal <= 0x0000FFFF) { 613 proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal); 614 } 615 else proc = (FARPROC)winmod->getApi((char *)lpszProc); 616 if(proc == 0) { 617 SetLastError(ERROR_PROC_NOT_FOUND); 618 } 619 return proc; 735 620 } 736 621 proc = O32_GetProcAddress(hModule, lpszProc); … … 743 628 BOOL SYSTEM GetVersionStruct(char *modname, char *verstruct, ULONG bufLength) 744 629 { 745 HINSTANCE hinstance;746 Win32Image *winimage;630 HINSTANCE hinstance; 631 Win32ImageBase *winimage; 747 632 748 633 dprintf(("GetVersionStruct")); … … 753 638 } 754 639 if(WinExe && WinExe->getInstanceHandle() == hinstance) { 755 winimage = (Win32Image *)WinExe;640 winimage = (Win32ImageBase *)WinExe; 756 641 } 757 642 else { 758 winimage = (Win32Image *)Win32Dll::findModule(hinstance);643 winimage = (Win32ImageBase *)Win32DllBase::findModule(hinstance); 759 644 if(winimage == NULL) { 760 645 dprintf(("GetVersionStruct can't find Win32Image for %s\n", modname)); … … 762 647 } 763 648 } 764 if(winimage->getVersionId() == -1) { 765 dprintf(("GetVersionStruct: %s has no version resource!\n", modname)); 766 return(FALSE); 767 } 768 return OSLibGetResource(hinstance, winimage->getVersionId(), verstruct, bufLength); 649 return winimage->getVersionStruct(verstruct, bufLength); 769 650 } 770 651 //****************************************************************************** … … 772 653 ULONG SYSTEM GetVersionSize(char *modname) 773 654 { 774 HINSTANCE hinstance;775 Win32Image *winimage;655 HINSTANCE hinstance; 656 Win32ImageBase *winimage; 776 657 777 658 dprintf(("GetVersionSize of %s\n", modname)); 778 659 hinstance = OSLibQueryModuleHandle(modname); 779 660 if(hinstance == 0) { 780 dprintf(("GetVersionSize can't find handle for %s\n", modname));781 return(FALSE);661 dprintf(("GetVersionSize can't find handle for %s\n", modname)); 662 return(FALSE); 782 663 } 783 664 784 665 if(WinExe && WinExe->getInstanceHandle() == hinstance) { 785 winimage = (Win32Image *)WinExe;666 winimage = (Win32ImageBase *)WinExe; 786 667 } 787 668 else { 788 winimage = (Win32Image *)Win32Dll::findModule(hinstance);669 winimage = (Win32ImageBase *)Win32DllBase::findModule(hinstance); 789 670 if(winimage == NULL) { 790 671 dprintf(("GetVersionSize can't find Win32Image for %s\n", modname)); … … 792 673 } 793 674 } 794 if(winimage->getVersionId() == -1) { 795 dprintf(("GetVersionSize: %s has no version resource!\n", modname)); 796 return(FALSE); 797 } 798 ULONG size = OSLibGetResourceSize(hinstance, winimage->getVersionId()); 799 800 dprintf(("Version resource size = %d, id %d\n", size, winimage->getVersionId())); 801 return(size); 675 return winimage->getVersionSize(); 802 676 } 803 677 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.