Changeset 3400 for trunk/src/kernel32/wprocess.cpp
- Timestamp:
- Apr 16, 2000, 8:49:07 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/wprocess.cpp
r3375 r3400 1 /* $Id: wprocess.cpp,v 1.7 6 2000-04-14 22:35:29 sandervlExp $ */1 /* $Id: wprocess.cpp,v 1.77 2000-04-16 06:49:07 bird Exp $ */ 2 2 3 3 /* … … 12 12 * 13 13 */ 14 15 16 17 /******************************************************************************* 18 * Header Files * 19 *******************************************************************************/ 14 20 #include <odin.h> 15 21 #include <odinwrap.h> … … 32 38 #endif 33 39 40 #include "odin32validate.h" 34 41 #include "exceptutil.h" 35 42 #include "oslibmisc.h" … … 48 55 49 56 50 //****************************************************************************** 51 //****************************************************************************** 57 /****************************************************************************** 58 * Global Variables * 59 ******************************************************************************/ 52 60 BOOL fFreeLibrary = FALSE; 53 61 BOOL fIsOS2Image = FALSE; //TRUE -> Odin32 OS/2 application (not converted!) … … 61 69 static THDB *threadList = 0; 62 70 static VMutex threadListMutex; 71 72 73 63 74 //****************************************************************************** 64 75 //****************************************************************************** … … 354 365 VOID WIN32API ExitProcess(DWORD exitcode) 355 366 { 356 dprintf(("KERNEL32: 357 dprintf(("KERNEL32: 367 dprintf(("KERNEL32: ExitProcess %d\n", exitcode)); 368 dprintf(("KERNEL32: ExitProcess FS = %x\n", GetFS())); 358 369 359 370 SetOS2ExceptionChain(-1); … … 414 425 } 415 426 /******************************************************************************/ 416 /******************************************************************************/ 417 static HINSTANCE iLoadLibraryA(LPCTSTR lpszLibFile, DWORD dwFlags) 418 { 419 char modname[CCHMAXPATH]; 420 HINSTANCE hDll; 421 Win32DllBase *module; 422 423 module = Win32DllBase::findModule((LPSTR)lpszLibFile); 424 if(module) { 425 if(module->isLxDll() && !module->isLoaded() && fPeLoader) { 427 //****************************************************************************** 428 HINSTANCE16 WIN32API LoadLibrary16(LPCTSTR lpszLibFile) 429 { 430 dprintf(("ERROR: LoadLibrary16 %s, not implemented", lpszLibFile)); 431 return 0; 432 } 433 //****************************************************************************** 434 //****************************************************************************** 435 VOID WIN32API FreeLibrary16(HINSTANCE16 hinstance) 436 { 437 dprintf(("ERROR: FreeLibrary16 %x, not implemented", hinstance)); 438 } 439 //****************************************************************************** 440 //****************************************************************************** 441 FARPROC WIN32API GetProcAddress16(HMODULE hModule, LPCSTR lpszProc) 442 { 443 dprintf(("ERROR: GetProcAddress16 %x %x, not implemented", hModule, lpszProc)); 444 return 0; 445 } 446 //****************************************************************************** 447 448 /** 449 * LoadLibraryA can be used to map a DLL module into the calling process's 450 * addressspace. It returns a handle that can be used with GetProcAddress to 451 * get addresses of exported entry points (functions and variables). 452 * 453 * LoadLibraryA can also be used to map executable (.exe) modules into the 454 * address to access resources in the module. However, LoadLibrary can't be 455 * used to run an executable (.exe) module. 456 * 457 * @returns Handle to the library which was loaded. 458 * @param lpszLibFile Pointer to zero ASCII string giving the name of the 459 * executable image (either a Dll or an Exe) which is to be 460 * loaded. 461 * 462 * If no extention is specified the default .DLL extention is 463 * appended to the name. End the filename with an '.' if the 464 * file does not have an extention (and don't want the .DLL 465 * appended). 466 * 467 * If no path is specified, this API will use the Odin32 468 * standard search strategy to find the file. This strategy 469 * is described in the method Win32ImageBase::findDLL. 470 * 471 * This API likes to have backslashes (\), but will probably 472 * accept forward slashes too. Win32 SDK docs says that it 473 * should not contain forward slashes. 474 * 475 * Win32 SDK docs adds: 476 * "The name specified is the file name of the module and 477 * is not related to the name stored in the library module 478 * itself, as specified by the LIBRARY keyword in the 479 * module-definition (.def) file." 480 * 481 * @sketch Call LoadLibraryExA with flags set to 0. 482 * @status Odin32 Completely Implemented. 483 * @author Sander van Leeuwen (sandervl@xs4all.nl) 484 * knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 485 * @remark Forwards to LoadLibraryExA. 486 */ 487 HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile) 488 { 489 HINSTANCE hDll; 490 491 dprintf(("KERNEL32: LoadLibraryA(%s) --> LoadLibraryExA(lpszLibFile, 0, 0)", 492 lpszLibFile)); 493 hDll = LoadLibraryExA(lpszLibFile, 0, 0); 494 dprintf(("KERNEL32: LoadLibraryA(%s) returns 0x%x", 495 lpszLibFile, hDll)); 496 return hDll; 497 } 498 499 500 /** 501 * LoadLibraryW can be used to map a DLL module into the calling process's 502 * addressspace. It returns a handle that can be used with GetProcAddress to 503 * get addresses of exported entry points (functions and variables). 504 * 505 * LoadLibraryW can also be used to map executable (.exe) modules into the 506 * address to access resources in the module. However, LoadLibrary can't be 507 * used to run an executable (.exe) module. 508 * 509 * @returns Handle to the library which was loaded. 510 * @param lpszLibFile Pointer to Unicode string giving the name of 511 * the executable image (either a Dll or an Exe) which is to 512 * be loaded. 513 * 514 * If no extention is specified the default .DLL extention is 515 * appended to the name. End the filename with an '.' if the 516 * file does not have an extention (and don't want the .DLL 517 * appended). 518 * 519 * If no path is specified, this API will use the Odin32 520 * standard search strategy to find the file. This strategy 521 * is described in the method Win32ImageBase::findDLL. 522 * 523 * This API likes to have backslashes (\), but will probably 524 * accept forward slashes too. Win32 SDK docs says that it 525 * should not contain forward slashes. 526 * 527 * Win32 SDK docs adds: 528 * "The name specified is the file name of the module and 529 * is not related to the name stored in the library module 530 * itself, as specified by the LIBRARY keyword in the 531 * module-definition (.def) file." 532 * 533 * @sketch Convert Unicode name to ascii. 534 * Call LoadLibraryExA with flags set to 0. 535 * free ascii string. 536 * @status Odin32 Completely Implemented. 537 * @author Sander van Leeuwen (sandervl@xs4all.nl) 538 * knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 539 * @remark Forwards to LoadLibraryExA. 540 */ 541 HINSTANCE WIN32API LoadLibraryW(LPCWSTR lpszLibFile) 542 { 543 char * pszAsciiLibFile; 544 HINSTANCE hDll; 545 546 pszAsciiLibFile = UnicodeToAsciiString(lpszLibFile); 547 dprintf(("KERNEL32: LoadLibraryW(%s) --> LoadLibraryExA(lpszLibFile, 0, 0)", 548 pszAsciiLibFile)); 549 hDll = LoadLibraryExA(pszAsciiLibFile, NULL, 0); 550 dprintf(("KERNEL32: LoadLibraryW(%s) returns 0x%x", 551 pszAsciiLibFile, hDll)); 552 free(pszAsciiLibFile); 553 554 return hDll; 555 } 556 557 558 /** 559 * LoadLibraryExA can be used to map a DLL module into the calling process's 560 * addressspace. It returns a handle that can be used with GetProcAddress to 561 * get addresses of exported entry points (functions and variables). 562 * 563 * LoadLibraryExA can also be used to map executable (.exe) modules into the 564 * address to access resources in the module. However, LoadLibrary can't be 565 * used to run an executable (.exe) module. 566 * 567 * @returns Handle to the library which was loaded. 568 * @param lpszLibFile Pointer to Unicode string giving the name of 569 * the executable image (either a Dll or an Exe) which is to 570 * be loaded. 571 * 572 * If no extention is specified the default .DLL extention is 573 * appended to the name. End the filename with an '.' if the 574 * file does not have an extention (and don't want the .DLL 575 * appended). 576 * 577 * If no path is specified, this API will use the Odin32 578 * standard search strategy to find the file. This strategy 579 * is described in the method Win32ImageBase::findDLL. 580 * This may be alterned by the LOAD_WITH_ALTERED_SEARCH_PATH 581 * flag, see below. 582 * 583 * This API likes to have backslashes (\), but will probably 584 * accept forward slashes too. Win32 SDK docs says that it 585 * should not contain forward slashes. 586 * 587 * Win32 SDK docs adds: 588 * "The name specified is the file name of the module and 589 * is not related to the name stored in the library module 590 * itself, as specified by the LIBRARY keyword in the 591 * module-definition (.def) file." 592 * 593 * @param hFile Reserved. Must be 0. 594 * 595 * @param dwFlags Flags which specifies the taken when loading the module. 596 * The value 0 makes it identical to LoadLibraryA/W. 597 * 598 * Flags: 599 * 600 * DONT_RESOLVE_DLL_REFERENCES 601 * (WinNT/2K feature): Don't load imported modules and 602 * hence don't resolve imported symbols. 603 * DllMain isn't called either. (Which is obvious since 604 * it may use one of the importe symbols.) 605 * 606 * On the other hand, if this flag is NOT set, the system 607 * load imported modules, resolves imported symbols, calls 608 * DllMain for process and thread init and term (if wished 609 * by the module). 610 * 611 * partially implemented yet - imports are resolved it seems. 612 * 613 * LOAD_LIBRARY_AS_DATAFILE 614 * If this flag is set, the module is mapped into the 615 * address space but is not prepared for execution. Though 616 * it's preparted for resource API. Hence, you'll use this 617 * flag when you want to load a DLL for extracting 618 * messages or resources from it. 619 * 620 * The resulting handle can be used with any Odin32 API 621 * which operates on resources. 622 * (WinNt/2k supports all resource APIs while Win9x don't 623 * support the specialized resource APIs: LoadBitmap, 624 * LoadCursor, LoadIcon, LoadImage, LoadMenu.) 625 * 626 * not implemented yet. 627 * 628 * LOAD_WITH_ALTERED_SEARCH_PATH 629 * If this flag is set and lpszLibFile specifies a path 630 * we'll use an alternative file search strategy to find 631 * imported modules. This stratgy is simply to use the 632 * path of the module being loaded instead of the path 633 * of the executable module as the first location 634 * to search for imported modules. 635 * 636 * If this flag is clear, the standard Odin32 standard 637 * search strategy. See Win32ImageBase::findDll for 638 * further information. 639 * 640 * not implemented yet. 641 * 642 * @status Open32 Partially Implemented. 643 * @author Sander van Leeuwen (sandervl@xs4all.nl) 644 * knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 645 * @remark Forwards to LoadLibraryExA. 646 */ 647 HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags) 648 { 649 HINSTANCE hDll; 650 Win32DllBase * pModule; 651 char szModname[CCHMAXPATH]; 652 BOOL fPath; /* Flags which is set if the */ 653 /* lpszLibFile contains a path. */ 654 BOOL fPE; /* isPEImage return value. */ 655 656 /** @sketch 657 * Some parameter validations is probably useful. 658 */ 659 if (!VALID_PSZ(lpszLibFile)) 660 { 661 dprintf(("KERNEL32: LoadLibraryExA(0x%x, 0x%x, 0x%x): invalid pointer lpszLibFile = 0x%x\n", 662 lpszLibFile, hFile, dwFlags, lpszLibFile)); 663 SetLastError(ERROR_INVALID_PARAMETER); //or maybe ERROR_ACCESS_DENIED is more appropriate? 664 return NULL; 665 } 666 if (!VALID_PSZMAXSIZE(lpszLibFile, CCHMAXPATH)) 667 { 668 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): lpszLibFile string too long, %d\n", 669 lpszLibFile, hFile, dwFlags, strlen(lpszLibFile))); 670 SetLastError(ERROR_INVALID_PARAMETER); 671 return NULL; 672 } 673 if ((dwFlags & ~(DONT_RESOLVE_DLL_REFERENCES | LOAD_WITH_ALTERED_SEARCH_PATH | LOAD_LIBRARY_AS_DATAFILE)) != 0) 674 { 675 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): dwFlags have invalid or unsupported flags\n", 676 lpszLibFile, hFile, dwFlags)); 677 SetLastError(ERROR_INVALID_PARAMETER); 678 } 679 680 681 /** @sketch 682 * First we'll see if the module is allready loaded. 683 * IF allready loaded THEN 684 * IF it's a LX dll which isn't loaded and we're using the PeLoader THEN 685 * Set Load library. 686 * Endif 687 * Inc dynamic reference count. 688 * Inc reference count. 689 * RETURN instance handle. 690 * Endif 691 */ 692 pModule = Win32DllBase::findModule((LPSTR)lpszLibFile); 693 if (pModule) 694 { 695 if (pModule->isLxDll() && !pModule->isLoaded() && fPeLoader) 696 { 426 697 //can happen with i.e. wininet 427 698 //wininet depends on wsock32; when the app loads wsock32 afterwards 428 699 //with LoadLibrary or as a child of another dll, we need to make 429 700 //sure it's loaded once with DosLoadModule 430 module->setLoadLibrary(); 431 } 432 module->incDynamicLib(); 433 module->AddRef(); 434 dprintf(("iLoadLibrary: found %s -> handle %x", lpszLibFile, module->getInstanceHandle())); 435 return module->getInstanceHandle(); 436 } 437 438 strcpy(modname, lpszLibFile); 439 strupr(modname); 440 //rename dll if necessary (i.e. OLE32 -> OLE32OS2) 441 Win32DllBase::renameDll(modname); 442 443 hDll = O32_LoadLibrary(modname); 444 dprintf(("KERNEL32: iLoadLibraryA %s returned %X (%d)\n", 445 lpszLibFile, 446 hDll, 447 GetLastError())); 448 if(hDll) 701 pModule->setLoadLibrary(); 702 } 703 pModule->incDynamicLib(); 704 pModule->AddRef(); 705 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): returns 0x%x. Dll found %s", 706 lpszLibFile, hFile, dwFlags, pModule->getInstanceHandle(), pModule->getFullPath())); 707 return pModule->getInstanceHandle(); 708 } 709 710 711 /** @sketch 712 * Test if lpszLibFile has a path or not. 713 * Copy the lpszLibFile to szModname, rename the dll and uppercase the name. 714 * IF it hasn't a path THEN 715 * Issue a findDll to find the dll/executable to be loaded. 716 * IF the Dll isn't found THEN 717 * Set last error and RETURN. 718 * Endif. 719 * Endif 720 */ 721 fPath = strchr(lpszLibFile, '\\') || strchr(lpszLibFile, '/'); 722 strcpy(szModname, lpszLibFile); 723 Win32DllBase::renameDll(szModname); 724 strupr(szModname); 725 726 if (!fPath) 449 727 { 450 module = Win32DllBase::findModule(hDll); 451 if(module && module->isLxDll() && fPeLoader) { 452 module->setLoadLibrary(); 453 module->AddRef(); 454 } 455 if(module) 456 module->incDynamicLib(); 457 //system dll, converted dll or win32k took care of it 458 return hDll; 459 } 460 461 if(!strstr(modname, ".")) { 462 strcat(modname,".DLL"); 463 } 464 465 if(Win32ImageBase::isPEImage((char *)modname)) 728 char szModName2[CCHMAXPATH]; 729 strcpy(szModName2, szModname); 730 if (!Win32ImageBase::findDll(szModName2, szModname, sizeof(szModname))) 731 { 732 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): module wasn't found. returns NULL", 733 lpszLibFile, hFile, dwFlags)); 734 SetLastError(ERROR_FILE_NOT_FOUND); 735 return NULL; 736 } 737 } 738 739 740 /** @sketch 741 * IF dwFlags == 0 THEN 742 * Try load the executable using LoadLibrary 743 * IF successfully loaded THEN 744 * IF LX dll and is using the PE Loader THEN 745 * Set Load library. 746 * Inc reference count. 747 * Endif 748 * Inc dynamic reference count. 749 * RETURN successfully. 750 * Endif 751 * Endif 752 */ 753 if (dwFlags == 0) 466 754 { 467 module = Win32DllBase::findModule((char *)modname); 468 if(module) {//don't load it again 469 module->incDynamicLib(); 470 module->AddRef(); 471 return module->getInstanceHandle(); 472 } 473 474 Win32PeLdrDll *peldrDll = new Win32PeLdrDll((char *)modname); 475 if(peldrDll == NULL) 476 return(0); 477 478 peldrDll->init(0); 479 if(peldrDll->getError() != NO_ERROR) { 480 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile)); 481 delete(peldrDll); 482 return(0); 483 } 484 if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) { 485 peldrDll->setNoEntryCalls(); 486 } 487 peldrDll->incDynamicLib(); 488 peldrDll->AddRef(); 489 490 if(peldrDll->attachProcess() == FALSE) { 491 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile)); 492 delete(peldrDll); 493 return(0); 494 } 495 return peldrDll->getInstanceHandle(); 496 } 497 else return(0); 498 } 499 //****************************************************************************** 500 //****************************************************************************** 501 HINSTANCE16 WIN32API LoadLibrary16(LPCTSTR lpszLibFile) 502 { 503 dprintf(("ERROR: LoadLibrary16 %s, not implemented", lpszLibFile)); 504 return 0; 505 } 506 //****************************************************************************** 507 //****************************************************************************** 508 VOID WIN32API FreeLibrary16(HINSTANCE16 hinstance) 509 { 510 dprintf(("ERROR: FreeLibrary16 %x, not implemented", hinstance)); 511 } 512 //****************************************************************************** 513 //****************************************************************************** 514 FARPROC WIN32API GetProcAddress16(HMODULE hModule, LPCSTR lpszProc) 515 { 516 dprintf(("ERROR: GetProcAddress16 %x %x, not implemented", hModule, lpszProc)); 517 return 0; 518 } 519 //****************************************************************************** 520 //****************************************************************************** 521 HINSTANCE WIN32API LoadLibraryA(LPCTSTR lpszLibFile) 522 { 523 HINSTANCE hDll; 524 525 dprintf(("KERNEL32: LoadLibraryA(%s)\n", 526 lpszLibFile)); 527 dprintf(("KERNEL32: LoadLibrary %x FS = %x\n", GetCurrentThreadId(), GetFS())); 528 529 hDll = iLoadLibraryA(lpszLibFile, 0); 530 if (hDll == 0) 755 hDll = O32_LoadLibrary(szModname); 756 if (hDll) 757 { 758 /* OS/2 dll, system dll, converted dll or win32k took care of it.*/ 759 pModule = Win32DllBase::findModule(hDll); 760 if (pModule) 761 { 762 if (pModule->isLxDll() && fPeLoader) 763 { 764 pModule->setLoadLibrary(); 765 pModule->AddRef(); 766 } 767 pModule->incDynamicLib(); 768 } 769 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): returns 0x%x. Loaded %s using O32_LoadLibrary.", 770 lpszLibFile, hFile, dwFlags, hDll, szModname)); 771 return hDll; 772 } 773 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): O32_LoadLibrary(%s) failed. LastError=%d", 774 lpszLibFile, hFile, dwFlags, szModname, GetLastError())); 775 } 776 else 777 hDll = NULL; 778 779 780 /** @sketch 781 * If PE image THEN 782 * Check again(!) if the module is allready loaded. 783 * IF Allready loaded THEN 784 * Inc dynamic ref count. 785 * Inc ref count. 786 * hDll <- instance handle. 787 * ELSE 788 * Try load the file using the Win32PeLdrDll class. 789 * <sketch continued further down> 790 * Endif 791 * Try load the file using the peldr. 792 * Else 793 * Set last error. 794 * (hDll is NULL) 795 * Endif 796 * return hDll. 797 */ 798 799 if ((fPE = Win32ImageBase::isPEImage(szModname))) 531 800 { 532 char * pszName; 533 534 // remove path from the image name 535 pszName = strrchr((char *)lpszLibFile, 536 '\\'); 537 if (pszName != NULL) 801 pModule = Win32DllBase::findModule(szModname); /* This should _NEVER_ succeed! */ 802 if (pModule) 538 803 { 539 pszName++; // skip backslash 540 541 // now try again without fully qualified path 542 hDll = iLoadLibraryA(pszName, 0); 543 } 804 pModule->incDynamicLib(); 805 pModule->AddRef(); 806 hDll = pModule->getInstanceHandle(); 807 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): returns 0x%x, Dll found (2) %s", 808 lpszLibFile, hFile, dwFlags, pModule->getInstanceHandle(), pModule->getFullPath())); 809 } 810 else 811 { 812 /* TODO EXE loading - will use the Win32PeLdrRsrcImg for that */ 813 Win32PeLdrDll * peldrDll; 814 815 peldrDll = new Win32PeLdrDll(szModname); 816 if (peldrDll == NULL) 817 { 818 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Failed to created instance of Win32PeLdrDll. returns NULL.", 819 lpszLibFile, hFile, dwFlags)); 820 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 821 return NULL; 822 } 823 824 /** @sketch 825 * Process dwFlags 826 */ 827 if (dwFlags & (DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE)) 828 { 829 peldrDll->setNoEntryCalls(); 830 //peldrDll->setDontProcessImports(); not implemented? 831 } 832 if (dwFlags & LOAD_WITH_ALTERED_SEARCH_PATH) 833 { 834 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Warning dwFlags LOAD_WITH_ALTERED_SEARCH_PATH is not implemented.", 835 lpszLibFile, hFile, dwFlags)); 836 //peldrDll->setLoadWithAlteredSearchPath(); 837 } 838 if (dwFlags & LOAD_LIBRARY_AS_DATAFILE) 839 { 840 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Warning dwFlags LOAD_LIBRARY_AS_DATAFILE is not implemented.", 841 lpszLibFile, hFile, dwFlags)); 842 //peldrDll->setLoadAsDatafile(); 843 } 844 845 /** @sketch 846 * Initiate the peldr DLL. 847 * IF successful init THEN 848 * Inc dynamic ref count. 849 * Inc ref count. 850 * Attach to process 851 * IF successful THEN 852 * hDLL <- instance handle. 853 * ELSE 854 * set last error 855 * delete Win32PeLdrDll instance. 856 * Endif 857 * ELSE 858 * set last error 859 * delete Win32PeLdrDll instance. 860 * Endif. 861 */ 862 if (peldrDll->init(0)) 863 { 864 peldrDll->incDynamicLib(); 865 peldrDll->AddRef(); 866 if (peldrDll->attachProcess()) 867 hDll = peldrDll->getInstanceHandle(); 868 else 869 { 870 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): attachProcess call to Win32PeLdrDll instance failed. returns NULL.", 871 lpszLibFile, hFile, dwFlags)); 872 SetLastError(ERROR_DLL_INIT_FAILED); 873 delete peldrDll; 874 } 875 } 876 else 877 { 878 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x): Failed to init Win32PeLdrDll instance. error=%d returns NULL.", 879 lpszLibFile, hFile, dwFlags, peldrDll->getError())); 880 SetLastError(ERROR_INVALID_EXE_SIGNATURE); 881 delete peldrDll; 882 } 883 } 884 } 885 else 886 { 887 dprintf(("KERNEL32: LoadLibraryExA(%s, 0x%x, 0x%x) library were found (%s) but it's not loadable!", 888 lpszLibFile, hFile, dwFlags, szModname)); 889 SetLastError(ERROR_INVALID_EXE_SIGNATURE); 544 890 } 545 891 546 892 return hDll; 547 893 } 548 //****************************************************************************** 549 //****************************************************************************** 550 HINSTANCE WIN32API LoadLibraryExA(LPCTSTR lpszLibFile, HANDLE hFile, DWORD dwFlags) 551 { 552 HINSTANCE hDll; 553 554 dprintf(("KERNEL32: LoadLibraryExA %s (%X)\n", lpszLibFile, dwFlags)); 555 hDll = iLoadLibraryA(lpszLibFile, dwFlags); 556 if (hDll == 0) 557 { 558 char * pszName; 559 560 // remove path from the image name 561 pszName = strrchr((char *)lpszLibFile, 562 '\\'); 563 if (pszName != NULL) 564 { 565 pszName++; // skip backslash 566 567 // now try again without fully qualified path 568 hDll = iLoadLibraryA(pszName, dwFlags); 569 } 570 } 571 572 return hDll; 573 } 574 //****************************************************************************** 575 //****************************************************************************** 576 HINSTANCE WIN32API LoadLibraryW(LPCWSTR lpModule) 577 { 578 char *asciimodule; 579 HINSTANCE rc; 580 581 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule); 582 dprintf(("KERNEL32: OS2LoadLibraryW %s\n", asciimodule)); 583 rc = LoadLibraryA(asciimodule); 584 free(asciimodule); 585 return(rc); 586 } 587 //****************************************************************************** 588 //****************************************************************************** 589 HINSTANCE WIN32API LoadLibraryExW(LPCWSTR lpModule, HANDLE hFile, DWORD dwFlags) 590 { 591 char *asciimodule; 592 HINSTANCE rc; 593 594 asciimodule = UnicodeToAsciiString((LPWSTR)lpModule); 595 dprintf(("KERNEL32: OS2LoadLibraryExW %s (%d)\n", asciimodule, dwFlags)); 596 rc = LoadLibraryExA(asciimodule, hFile, dwFlags); 597 free(asciimodule); 598 return(rc); 894 895 896 /** 897 * LoadLibraryExW can be used to map a DLL module into the calling process's 898 * addressspace. It returns a handle that can be used with GetProcAddress to 899 * get addresses of exported entry points (functions and variables). 900 * 901 * LoadLibraryExW can also be used to map executable (.exe) modules into the 902 * address to access resources in the module. However, LoadLibrary can't be 903 * used to run an executable (.exe) module. 904 * 905 * @returns Handle to the library which was loaded. 906 * @param lpszLibFile Pointer to Unicode string giving the name of 907 * the executable image (either a Dll or an Exe) which is to 908 * be loaded. 909 * 910 * If no extention is specified the default .DLL extention is 911 * appended to the name. End the filename with an '.' if the 912 * file does not have an extention (and don't want the .DLL 913 * appended). 914 * 915 * If no path is specified, this API will use the Odin32 916 * standard search strategy to find the file. This strategy 917 * is described in the method Win32ImageBase::findDLL. 918 * This may be alterned by the LOAD_WITH_ALTERED_SEARCH_PATH 919 * flag, see below. 920 * 921 * This API likes to have backslashes (\), but will probably 922 * accept forward slashes too. Win32 SDK docs says that it 923 * should not contain forward slashes. 924 * 925 * Win32 SDK docs adds: 926 * "The name specified is the file name of the module and 927 * is not related to the name stored in the library module 928 * itself, as specified by the LIBRARY keyword in the 929 * module-definition (.def) file." 930 * 931 * @param hFile Reserved. Must be 0. 932 * 933 * @param dwFlags Flags which specifies the taken when loading the module. 934 * The value 0 makes it identical to LoadLibraryA/W. 935 * 936 * Flags: 937 * 938 * DONT_RESOLVE_DLL_REFERENCES 939 * (WinNT/2K feature): Don't load imported modules and 940 * hence don't resolve imported symbols. 941 * DllMain isn't called either. (Which is obvious since 942 * it may use one of the importe symbols.) 943 * 944 * On the other hand, if this flag is NOT set, the system 945 * load imported modules, resolves imported symbols, calls 946 * DllMain for process and thread init and term (if wished 947 * by the module). 948 * 949 * LOAD_LIBRARY_AS_DATAFILE 950 * If this flag is set, the module is mapped into the 951 * address space but is not prepared for execution. Though 952 * it's preparted for resource API. Hence, you'll use this 953 * flag when you want to load a DLL for extracting 954 * messages or resources from it. 955 * 956 * The resulting handle can be used with any Odin32 API 957 * which operates on resources. 958 * (WinNt/2k supports all resource APIs while Win9x don't 959 * support the specialized resource APIs: LoadBitmap, 960 * LoadCursor, LoadIcon, LoadImage, LoadMenu.) 961 * 962 * LOAD_WITH_ALTERED_SEARCH_PATH 963 * If this flag is set and lpszLibFile specifies a path 964 * we'll use an alternative file search strategy to find 965 * imported modules. This stratgy is simply to use the 966 * path of the module being loaded instead of the path 967 * of the executable module as the first location 968 * to search for imported modules. 969 * 970 * If this flag is clear, the standard Odin32 standard 971 * search strategy. See Win32ImageBase::findDll for 972 * further information. 973 * 974 * @sketch Convert Unicode name to ascii. 975 * Call LoadLibraryExA. 976 * Free ascii string. 977 * return handle from LoadLibraryExA. 978 * @status Open32 Partially Implemented. 979 * @author Sander van Leeuwen (sandervl@xs4all.nl) 980 * knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 981 * @remark Forwards to LoadLibraryExA. 982 */ 983 HINSTANCE WIN32API LoadLibraryExW(LPCWSTR lpszLibFile, HANDLE hFile, DWORD dwFlags) 984 { 985 char * pszAsciiLibFile; 986 HINSTANCE hDll; 987 988 pszAsciiLibFile = UnicodeToAsciiString(lpszLibFile); 989 dprintf(("KERNEL32: LoadLibraryExW(%s, 0x%x, 0x%x) --> LoadLibraryExA", 990 pszAsciiLibFile, hFile, dwFlags)); 991 hDll = LoadLibraryExA(pszAsciiLibFile, hFile, dwFlags); 992 dprintf(("KERNEL32: LoadLibraryExW(%s, 0x%x, 0x%x) returns 0x%x", 993 pszAsciiLibFile, hFile, dwFlags, hDll)); 994 free(pszAsciiLibFile); 995 996 return hDll; 599 997 } 600 998 //****************************************************************************** … … 610 1008 cmdline = O32_GetCommandLine(); 611 1009 612 dprintf(("KERNEL32: 613 dprintf(("KERNEL32: 1010 dprintf(("KERNEL32: GetCommandLine %s\n", cmdline)); 1011 dprintf(("KERNEL32: FS = %x\n", GetFS())); 614 1012 return(cmdline); 615 1013 } … … 621 1019 char *asciicmdline = NULL; 622 1020 623 dprintf(("KERNEL32: 1021 dprintf(("KERNEL32: FS = %x\n", GetFS())); 624 1022 625 1023 if(UnicodeCmdLine) … … 636 1034 UnicodeCmdLine = (WCHAR *)malloc(strlen(asciicmdline)*2 + 2); 637 1035 AsciiToUnicode(asciicmdline, UnicodeCmdLine); 638 dprintf(("KERNEL32: 1036 dprintf(("KERNEL32: OS2GetCommandLineW: %s\n", asciicmdline)); 639 1037 return(UnicodeCmdLine); 640 1038 } 641 dprintf(("KERNEL32: 1039 dprintf(("KERNEL32: OS2GetCommandLineW: asciicmdline == NULL\n")); 642 1040 return NULL; 643 1041 } … … 680 1078 DWORD rc; 681 1079 682 dprintf(("KERNEL32: 1080 dprintf(("KERNEL32: OSLibGetModuleFileNameW\n")); 683 1081 rc = GetModuleFileNameA(hModule, asciifilename, nSize); 684 1082 if(rc) AsciiToUnicode(asciifilename, lpFileName); … … 731 1129 } 732 1130 733 dprintf(("KERNEL32: 1131 dprintf(("KERNEL32: GetModuleHandle %s returned %X\n", lpszModule, hMod)); 734 1132 return(hMod); 735 1133 } … … 743 1141 astring = UnicodeToAsciiString((LPWSTR)arg1); 744 1142 rc = GetModuleHandleA(astring); 745 dprintf(("KERNEL32: 1143 dprintf(("KERNEL32: OS2GetModuleHandleW %s returned %X\n", astring, rc)); 746 1144 FreeAsciiString(astring); 747 1145 return(rc); … … 813 1211 sprintf(cmdline, "PE.EXE %s", lpCommandLine); 814 1212 } 815 dprintf(("KERNEL32: 1213 dprintf(("KERNEL32: CreateProcess %s\n", cmdline)); 816 1214 rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline,lpProcessAttributes, 817 1215 lpThreadAttributes, bInheritHandles, dwCreationFlags, … … 839 1237 840 1238 if(lpProcessInfo) 841 dprintf(("KERNEL32: 1239 dprintf(("KERNEL32: CreateProcess returned %d hPro:%x hThr:%x pid:%x tid:%x\n", 842 1240 rc, lpProcessInfo->hProcess, lpProcessInfo->hThread, 843 1241 lpProcessInfo->dwProcessId,lpProcessInfo->dwThreadId)); 844 1242 else 845 dprintf(("KERNEL32: 1243 dprintf(("KERNEL32: CreateProcess returned %d\n", rc)); 846 1244 return(rc); 847 1245 } … … 906 1304 ULONG ulAPIOrdinal; 907 1305 908 if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) { 909 winmod = WinExe; 910 } 911 else winmod = (Win32ImageBase *)Win32DllBase::findModule((HINSTANCE)hModule); 912 1306 winmod = Win32ImageBase::findModule(hModule); 913 1307 if(winmod) { 914 1308 ulAPIOrdinal = (ULONG)lpszProc; … … 924 1318 proc = O32_GetProcAddress(hModule, lpszProc); 925 1319 if(HIWORD(lpszProc)) 926 dprintf(("KERNEL32: 927 else dprintf(("KERNEL32: 1320 dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc)); 1321 else dprintf(("KERNEL32: GetProcAddress %x from %X returned %X\n", lpszProc, hModule, proc)); 928 1322 return(proc); 929 1323 }
Note:
See TracChangeset
for help on using the changeset viewer.