Changeset 2077 for trunk/src/kernel32/wprocess.cpp
- Timestamp:
- Dec 14, 1999, 8:14:28 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/wprocess.cpp
r2053 r2077 1 /* $Id: wprocess.cpp,v 1.5 7 1999-12-10 14:06:12sandervl Exp $ */1 /* $Id: wprocess.cpp,v 1.58 1999-12-14 19:14:28 sandervl Exp $ */ 2 2 3 3 /* … … 8 8 * 9 9 * NOTE: Even though Odin32 OS/2 apps don't switch FS selectors, 10 * we still allocate a TEB to store misc information. 10 * we still allocate a TEB to store misc information. 11 11 * 12 12 * Project Odin Software License can be found in LICENSE.TXT … … 46 46 //****************************************************************************** 47 47 BOOL fFreeLibrary = FALSE; 48 BOOL fIsOS2Image = FALSE; 49 48 BOOL fIsOS2Image = FALSE; //TRUE -> Odin32 OS/2 application (not converted!) 49 //FALSE -> otherwise 50 50 //Process database 51 51 PDB ProcessPDB = {0}; … … 58 58 { 59 59 if(TIBFlatPtr == NULL) 60 60 return 0; 61 61 62 62 return (TEB *)*TIBFlatPtr; … … 70 70 71 71 if(TIBFlatPtr == NULL) 72 72 return 0; 73 73 74 74 winteb = (TEB *)*TIBFlatPtr; 75 75 if(winteb == NULL) { 76 76 return NULL; 77 77 } 78 78 thdb = (THDB *)(winteb+1); … … 92 92 //Allocate one dword to store the flat address of our TEB 93 93 if(fMainThread) { 94 95 96 97 98 99 94 TIBFlatPtr = (DWORD *)OSLibAllocThreadLocalMemory(1); 95 if(TIBFlatPtr == 0) { 96 dprintf(("InitializeTIB: local thread memory alloc failed!!")); 97 DebugInt3(); 98 return NULL; 99 } 100 100 } 101 101 if(OSLibAllocSel(PAGE_SIZE, &tibsel) == FALSE) 102 102 { 103 104 105 103 dprintf(("InitializeTIB: selector alloc failed!!")); 104 DebugInt3(); 105 return NULL; 106 106 } 107 107 winteb = (TEB *)OSLibSelToFlat(tibsel); 108 108 if(winteb == NULL) 109 109 { 110 111 112 110 dprintf(("InitializeTIB: DosSelToFlat failed!!")); 111 DebugInt3(); 112 return NULL; 113 113 } 114 114 memset(winteb, 0, PAGE_SIZE); … … 136 136 if(OSLibGetPIB(PIB_TASKTYPE) == TASKTYPE_PM) 137 137 { 138 138 thdb->flags = 0; //todo gui 139 139 } 140 140 else thdb->flags = 0; //todo textmode … … 142 142 if(fMainThread) 143 143 { 144 144 //todo initialize PDB during process creation 145 145 //todo: initialize TLS array if required 146 146 //TLS in executable always TLS index 0? 147 148 149 150 151 152 153 154 155 156 157 158 147 ProcessTIBSel = tibsel; 148 ProcessPDB.exit_code = 0x103; /* STILL_ACTIVE */ 149 ProcessPDB.threads = 1; 150 ProcessPDB.running_threads = 1; 151 ProcessPDB.ring0_threads = 1; 152 ProcessPDB.system_heap = GetProcessHeap(); 153 ProcessPDB.parent = 0; 154 ProcessPDB.group = &ProcessPDB; 155 ProcessPDB.priority = 8; /* Normal */ 156 ProcessPDB.heap = ProcessPDB.system_heap; /* will be changed later on */ 157 ProcessPDB.next = NULL; 158 ProcessPDB.winver = 0xffff; /* to be determined */ 159 159 ProcessPDB.server_pid = (void *)GetCurrentProcessId(); 160 160 161 161 GetSystemTime(&ProcessPDB.creationTime); 162 162 163 163 /* Initialize the critical section */ … … 182 182 winteb = (TEB *)*TIBFlatPtr; 183 183 if(winteb) { 184 185 186 187 188 189 190 191 184 thdb = (THDB *)(winteb+1); 185 orgtibsel = thdb->OrgTIBSel; 186 187 //Restore our original FS selector 188 SetFS(orgtibsel); 189 190 //And free our own 191 OSLibFreeSel(thdb->teb_sel); 192 192 } 193 193 else dprintf(("Already destroyed TIB")); … … 214 214 //we don't switch FS selectors 215 215 if(fIsOS2Image) { 216 216 return; 217 217 } 218 218 219 219 winteb = (TEB *)*TIBFlatPtr; 220 220 if(winteb) { 221 222 223 224 225 221 thdb = (THDB *)(winteb+1); 222 orgtibsel = thdb->OrgTIBSel; 223 224 //Restore our original FS selector 225 SetFS(orgtibsel); 226 226 } 227 227 } … … 237 237 //we don't switch FS selectors 238 238 if(fIsOS2Image) { 239 239 return GetFS(); 240 240 } 241 241 242 242 winteb = (TEB *)*TIBFlatPtr; 243 243 if(winteb) { 244 245 246 247 248 244 thdb = (THDB *)(winteb+1); 245 win32tibsel = thdb->teb_sel; 246 247 //Restore our win32 FS selector 248 return SetReturnFS(win32tibsel); 249 249 } 250 250 else { 251 252 253 254 255 256 257 258 259 260 261 262 251 //we didn't create this thread, so allocate a selector now 252 //NOTE: Possible memory leak (i.e. DART threads in WINMM) 253 winteb = InitializeTIB(); 254 if(winteb == NULL) { 255 DebugInt3(); 256 return GetFS(); 257 } 258 thdb = (THDB *)(winteb+1); 259 win32tibsel = thdb->teb_sel; 260 261 //Restore our win32 FS selector 262 return SetReturnFS(win32tibsel); 263 263 } 264 264 // nested calls are OK, OS2ToWinCallback for instance … … 289 289 290 290 Win32DllExitList(0); 291 291 292 292 //Note: Needs to be done after Win32DllExitList (destruction of exe + dll objects) 293 293 //Flush and delete all open memory mapped files … … 316 316 winmod = Win32DllBase::findModule(hinstance); 317 317 if(winmod) { 318 319 318 winmod->Release(); 319 return(TRUE); 320 320 } 321 321 dprintf(("KERNEL32: FreeLibrary %s %X\n", OSLibGetDllName(hinstance), hinstance)); … … 338 338 module = Win32DllBase::findModule((LPSTR)lpszLibFile); 339 339 if(module) { 340 341 342 340 module->AddRef(); 341 dprintf(("iLoadLibrary: found %s -> handle %x", lpszLibFile, module->getInstanceHandle())); 342 return module->getInstanceHandle(); 343 343 } 344 344 … … 359 359 360 360 if(!strstr(modname, ".")) { 361 361 strcat(modname,".DLL"); 362 362 } 363 363 364 364 if(Win32ImageBase::isPEImage((char *)modname)) 365 365 { 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 366 module = Win32DllBase::findModule((char *)modname); 367 if(module) {//don't load it again 368 module->AddRef(); 369 return module->getInstanceHandle(); 370 } 371 372 Win32PeLdrDll *peldrDll = new Win32PeLdrDll((char *)modname); 373 if(peldrDll == NULL) 374 return(0); 375 376 peldrDll->init(0); 377 if(peldrDll->getError() != NO_ERROR) { 378 dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile)); 379 delete(peldrDll); 380 return(0); 381 } 382 if(dwFlags & DONT_RESOLVE_DLL_REFERENCES) { 383 peldrDll->setNoEntryCalls(); 384 } 385 386 if(peldrDll->attachProcess() == FALSE) { 387 dprintf(("LoadLibary %s failed (::attachProcess)\n", lpszLibFile)); 388 delete(peldrDll); 389 return(0); 390 } 391 peldrDll->AddRef(); 392 return peldrDll->getInstanceHandle(); 393 393 } 394 394 else return(0); … … 528 528 dprintf(("GetModuleFileName %X", hinstModule)); 529 529 if(hinstModule == 0 || hinstModule == -1 || (WinExe && hinstModule == WinExe->getInstanceHandle())) { 530 530 module = (Win32ImageBase *)WinExe; 531 531 } 532 532 else { 533 533 module = (Win32ImageBase *)Win32DllBase::findModule(hinstModule); 534 534 } 535 535 536 536 if(module) { 537 537 fpath = module->getFullPath(); 538 538 } 539 539 if(fpath) { 540 541 542 540 //SvL: 13-9-98: +1 541 rc = min(strlen(fpath)+1, cchPath); 542 strncpy(lpszPath, fpath, rc); 543 543 } 544 544 else rc = O32_GetModuleFileName(hinstModule, lpszPath, cchPath); … … 574 574 575 575 if(lpszModule == NULL) { 576 577 578 elsehMod = -1;576 if(WinExe) 577 hMod = WinExe->getInstanceHandle(); 578 else hMod = -1; 579 579 } 580 580 else { 581 582 583 584 585 586 587 588 581 strcpy(szModule, OSLibStripPath((char *)lpszModule)); 582 strupr(szModule); 583 if(strstr(szModule, ".DLL")) { 584 fDllModule = TRUE; 585 } 586 else { 587 if(!strstr(szModule, ".")) { 588 //if there's no extension or trainling dot, we 589 589 //assume it's a dll (see Win32 SDK docs) 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 590 fDllModule = TRUE; 591 } 592 } 593 char *dot = strstr(szModule, "."); 594 if(dot) 595 *dot = 0; 596 597 if(!fDllModule && WinExe && !strcmpi(szModule, WinExe->getModuleName())) { 598 hMod = WinExe->getInstanceHandle(); 599 } 600 else { 601 windll = Win32DllBase::findModule(szModule); 602 if(windll) { 603 hMod = windll->getInstanceHandle(); 604 } 605 else hMod = OSLibiGetModuleHandleA((char *)lpszModule); 606 } 607 607 } 608 608 … … 634 634 { 635 635 BOOL rc; 636 char *cmdline; 637 BOOL fAllocStr = FALSE; 636 char *cmdline = NULL; 638 637 639 638 dprintf(("KERNEL32: CreateProcessA %s cline:%s inherit:%d cFlags:%x Env:%x CurDir:%s StartupFlags:%x\n", … … 645 644 lpEnvironment, lpCurrentDirectory, lpStartupInfo, 646 645 lpProcessInfo) == TRUE) 647 646 return(TRUE); 648 647 649 648 //probably a win32 exe, so run it in the pe loader 650 649 if(lpApplicationName) { 651 if(lpCommandLine) { 652 cmdline = (char *)malloc(strlen(lpApplicationName)+strlen(lpCommandLine) + 16); 653 sprintf(cmdline, "PE.EXE %s %s", lpApplicationName, lpCommandLine); 654 fAllocStr = TRUE; 655 } 656 else { 657 cmdline = (char *)malloc(strlen(lpApplicationName) + 16); 658 sprintf(cmdline, "PE.EXE %s", lpApplicationName); 659 fAllocStr = TRUE; 660 } 650 if(lpCommandLine) { 651 //skip exe name in lpCommandLine 652 while(*lpCommandLine != 0 && *lpCommandLine != ' ') 653 lpCommandLine++; 654 655 if(*lpCommandLine != 0) { 656 lpCommandLine++; 657 } 658 cmdline = (char *)malloc(strlen(lpApplicationName)+strlen(lpCommandLine) + 16); 659 sprintf(cmdline, "PE.EXE %s %s", lpApplicationName, lpCommandLine); 660 } 661 else { 662 cmdline = (char *)malloc(strlen(lpApplicationName) + 16); 663 sprintf(cmdline, "PE.EXE %s", lpApplicationName); 664 } 661 665 } 662 666 else { 663 667 cmdline = (char *)malloc(strlen(lpCommandLine) + 16); 664 668 sprintf(cmdline, "PE.EXE %s", lpCommandLine); 665 fAllocStr = TRUE;666 669 } 667 670 dprintf(("KERNEL32: CreateProcess %s\n", cmdline)); … … 670 673 lpEnvironment, lpCurrentDirectory, lpStartupInfo, 671 674 lpProcessInfo); 672 if( fAllocStr)673 675 if(cmdline) 676 free(cmdline); 674 677 675 678 if(lpProcessInfo) … … 697 700 astring2 = UnicodeToAsciiString(arg2); 698 701 astring3 = UnicodeToAsciiString((LPWSTR)arg8); 699 // NOTE: This will not work as is (needs UNICODE support)700 702 rc = CreateProcessA(astring1, astring2, arg3, arg4, arg5, arg6, arg7, 701 703 astring3, (LPSTARTUPINFOA)arg9, arg10); … … 715 717 startinfo.dwFlags = nCmdShow; 716 718 if(CreateProcessA(NULL, (LPSTR)lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, 717 &startinfo, &procinfo) == FALSE) 719 &startinfo, &procinfo) == FALSE) 718 720 { 719 721 return 0; 720 722 } 721 723 return procinfo.hProcess; //correct? … … 730 732 731 733 if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) { 732 734 winmod = WinExe; 733 735 } 734 736 else winmod = (Win32ImageBase *)Win32DllBase::findModule((HINSTANCE)hModule); 735 737 736 738 if(winmod) { 737 738 739 740 741 742 743 744 745 739 ulAPIOrdinal = (ULONG)lpszProc; 740 if (ulAPIOrdinal <= 0x0000FFFF) { 741 proc = (FARPROC)winmod->getApi((int)ulAPIOrdinal); 742 } 743 else proc = (FARPROC)winmod->getApi((char *)lpszProc); 744 if(proc == 0) { 745 SetLastError(ERROR_PROC_NOT_FOUND); 746 } 747 return proc; 746 748 } 747 749 proc = O32_GetProcAddress(hModule, lpszProc); 748 if(HIWORD(lpszProc)) 749 750 if(HIWORD(lpszProc)) 751 dprintf(("KERNEL32: GetProcAddress %s from %X returned %X\n", lpszProc, hModule, proc)); 750 752 else dprintf(("KERNEL32: GetProcAddress %x from %X returned %X\n", lpszProc, hModule, proc)); 751 753 return(proc); … … 761 763 dprintf(("GetVersionStruct of module %s", lpszModName)); 762 764 if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) { 763 765 winimage = (Win32ImageBase *)WinExe; 764 766 } 765 767 else { 766 767 if(winimage == NULL)768 winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName); 769 if(winimage == NULL) 768 770 { 769 770 771 772 773 774 775 if(Win32ImageBase::isPEImage(modname) == FALSE) 771 char modname[CCHMAXPATH]; 772 773 strcpy(modname, lpszModName); 774 //rename dll if necessary (i.e. OLE32 -> OLE32OS2) 775 Win32DllBase::renameDll(modname); 776 777 if(Win32ImageBase::isPEImage(modname) == FALSE) 776 778 { 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 779 HINSTANCE hInstance; 780 781 //must be an LX dll, just load it (app will probably load it anyway) 782 hInstance = LoadLibraryA(modname); 783 if(hInstance == 0) 784 return 0; 785 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance); 786 if(winimage) { 787 return winimage->getVersionStruct(verstruct, bufLength); 788 } 789 return 0; 790 } 791 //SvL: Try to load it 792 rsrcimg = new Win32PeLdrRsrcImg(modname); 793 if(rsrcimg == NULL) 794 return 0; 795 796 rsrcimg->init(0); 797 if(rsrcimg->getError() != NO_ERROR) 798 { 799 dprintf(("GetVersionStruct can't load %s\n", modname)); 800 delete rsrcimg; 801 return(FALSE); 802 } 803 BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength); 804 delete rsrcimg; 805 return rc; 806 } 805 807 } 806 808 return winimage->getVersionStruct(verstruct, bufLength); … … 816 818 817 819 if(WinExe && !stricmp(WinExe->getFullPath(), lpszModName)) { 818 820 winimage = (Win32ImageBase *)WinExe; 819 821 } 820 822 else { 821 822 if(winimage == NULL)823 winimage = (Win32ImageBase *)Win32DllBase::findModule(lpszModName); 824 if(winimage == NULL) 823 825 { 824 825 826 827 828 829 830 if(Win32ImageBase::isPEImage(modname) == FALSE) 826 char modname[CCHMAXPATH]; 827 828 strcpy(modname, lpszModName); 829 //rename dll if necessary (i.e. OLE32 -> OLE32OS2) 830 Win32DllBase::renameDll(modname); 831 832 if(Win32ImageBase::isPEImage(modname) == FALSE) 831 833 { 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 834 HINSTANCE hInstance; 835 836 //must be an LX dll, just load it (app will probably load it anyway) 837 hInstance = LoadLibraryA(modname); 838 if(hInstance == 0) 839 return 0; 840 winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance); 841 if(winimage) { 842 return winimage->getVersionSize(); 843 } 844 return 0; 845 } 846 847 //SvL: Try to load it 848 rsrcimg = new Win32PeLdrRsrcImg(modname); 849 if(rsrcimg == NULL) 850 return 0; 851 852 rsrcimg->init(0); 853 if(rsrcimg->getError() != NO_ERROR) 854 { 855 dprintf(("GetVersionSize can't load %s\n", modname)); 856 delete rsrcimg; 857 return(FALSE); 858 } 859 int size = rsrcimg->getVersionSize(); 860 delete rsrcimg; 861 return size; 862 } 861 863 } 862 864 return winimage->getVersionSize();
Note:
See TracChangeset
for help on using the changeset viewer.