Changeset 4065 for branches/GRACE/src/win32k/pe2lx/pe2lx.cpp
- Timestamp:
- Aug 22, 2000, 12:59:40 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GRACE/src/win32k/pe2lx/pe2lx.cpp
r4052 r4065 1 /* $Id: pe2lx.cpp,v 1.18.4. 4 2000-08-20 08:08:47bird Exp $1 /* $Id: pe2lx.cpp,v 1.18.4.5 2000-08-21 22:59:40 bird Exp $ 2 2 * 3 3 * Pe2Lx class implementation. Ring 0 and Ring 3 … … 100 100 #include <versionos2.h> /* Pe2Lx version. */ 101 101 #include "yield.h" /* Yield CPU. */ 102 #include "options.h" /* Win32k options. */ 102 103 103 104 … … 205 206 LXHdr.e32_pagesize = PAGESIZE; 206 207 LXHdr.e32_objtab = sizeof(LXHdr); 208 cLoadedModules++; 207 209 } 208 210 … … 277 279 _res_heapmin(); 278 280 _swp_heapmin(); 281 282 /* 283 * If no Pe2Lx objects left, then invalidate the Odin32Path. 284 * We'll have to do this since we may (theoretically) not receive 285 * a close on a kernel32 handle if loading failes before kernel32 286 * is loaded and the odin32path is determined using ldrOpenPath. 287 * (Ie. no sfnKernel32.) 288 */ 289 if (--cLoadedModules <= 0) 290 invalidateOdin32Path(); 291 #ifdef DEBUG 292 if (cLoadedModules < 0) 293 printIPE(("Pe2Lx::cLoadedModules is %d which is less that zero!\n", cLoadedModules)); 294 #endif 279 295 } 280 296 … … 1729 1745 1730 1746 /** 1747 * Invalidates the odin32path. 1748 * Called by ldrClose when the kernel32 handle is closed. 1749 * @sketch Free path 1750 * nullify path pointer and kernel32 handle. 1751 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 1752 */ 1753 VOID Pe2Lx::invalidateOdin32Path() 1754 { 1755 if (pszOdin32Path != NULL) 1756 { 1757 rfree((void*)pszOdin32Path); 1758 pszOdin32Path = NULL; 1759 } 1760 sfnKernel32 = NULLHANDLE; 1761 } 1762 1763 1764 /** 1731 1765 * Gets the size of the virtual LX-file. 1732 1766 * @returns Size of the virtual LX-file in bytes. … … 4647 4681 4648 4682 4683 4684 /** 4685 * Initiates the odin32path. 4686 * @returns Success indicator. 4687 * @sketch 4688 * @status 4689 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 4690 * @remark 4691 */ 4649 4692 BOOL Pe2Lx::initOdin32Path() 4650 4693 { … … 4661 4704 pMTE = NULL; 4662 4705 rc = ldrFindModule("KERNEL32", 8, CLASS_GLOBAL, &pMTE); 4663 if (rc == NO_ERROR && pMTE != NULL) 4664 { 4665 char *psz = pMTE->mte_swapmte->smte_path; 4666 if (psz != NULL) 4667 { 4668 char * pszEnd = psz + strlen(psz) - 1; 4669 while (pszEnd > psz && *pszEnd != '\\' && *pszEnd != '/' && *pszEnd != ':') 4670 pszEnd--; 4671 pszEnd--; 4672 while (pszEnd > psz && *pszEnd != '\\' && *pszEnd != '/' && *pszEnd != ':') 4673 pszEnd--; 4674 if (pszEnd > psz) 4675 { 4676 char * pszPath = (char*)malloc(pszEnd - psz); 4677 memcpy(pszPath, psz, pszEnd - psz); 4678 pszPath[pszEnd - psz] = '\0'; 4679 4680 if (pszOdin32Path) 4681 free((void*)pszOdin32Path); 4682 pszOdin32Path = pszPath; 4683 sfnKernel32 = pMTE->mte_sfn; 4684 4685 return TRUE; 4686 } 4687 } 4688 } 4706 if (rc == NO_ERROR && pMTE != NULL && pMTE->mte_swapmte != NULL) 4707 { 4708 /* 4709 * We now take the smte_path. Start at the end and skip the filename, 4710 * and one directory up. We assume a fully qualified path is found in 4711 * smte_path. 4712 */ 4713 if (pMTE->mte_swapmte->smte_path != NULL)//paranoia 4714 { 4715 sfnKernel32 = pMTE->mte_sfn; 4716 return setOdin32Path(pMTE->mte_swapmte->smte_path); 4717 } 4718 } 4719 4720 4721 /* 4722 * KERNEL32 isn't loaded. We'll only search the paths if 4723 */ 4724 if (pszOdin32Path != NULL) 4725 return TRUE; 4726 4689 4727 4690 4728 /* 4691 4729 * Try find it searching the LIBPATHs. 4692 * (Don't thing we should use ldrOpenPath since it 4693 * end's up calling ldrOpen - which is overloaded.) 4730 * 4731 * For the time being: 4732 * We'll use ldrOpenPath to do this, but we'll have to 4733 * disable the win32k.sys overloading temporarily. 4694 4734 */ 4735 ldrlv_t lv = {0}; 4736 ULONG ful = 0; 4737 ULONG ul; 4738 4739 ul = options.fNoLoader; 4740 options.fNoLoader = TRUE; 4741 rc = ldrOpenPath("KERNEL32", 8, &lv, &ful); 4742 options.fNoLoader = ul; 4743 if (rc == NO_ERROR) 4744 { 4745 /* 4746 * Set the odin32path according to the kernel32 path we've found. 4747 * (ldrOpen sets ldrpFileNameBuf to the fully qualified path of 4748 * the last opended filed, which in this case is kernel32.dll.) 4749 * We'll close the file handle first of course. 4750 */ 4751 ldrClose(lv.lv_sfn); 4752 return setOdin32Path(ldrpFileNameBuf); 4753 } 4754 4755 return rc == NO_ERROR; 4756 } 4757 4758 4759 4760 /** 4761 * Sets the Odin32Path to the given fully qualified filename of kernel32. 4762 * @returns Success indicator. 4763 * @param psz Fully qualified filename of kernel32 with path. 4764 * @sketch 4765 * @status 4766 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 4767 * @remark 4768 */ 4769 BOOL Pe2Lx::setOdin32Path(const char *psz) 4770 { 4771 const char * pszEnd; 4772 char * pszPath; 4773 4774 /* 4775 * We now take the psz. Start at the end and skip the filename, 4776 * and one directory up. We assume a fully qualified path. 4777 */ 4778 pszEnd = psz + strlen(psz) - 1; 4779 while (pszEnd > psz && *pszEnd != '\\' && *pszEnd != '/' && *pszEnd != ':') 4780 pszEnd--; 4781 pszEnd--; 4782 while (pszEnd > psz && *pszEnd != '\\' && *pszEnd != '/' && *pszEnd != ':') 4783 pszEnd--; 4784 if (pszEnd > psz) 4785 { 4786 /* 4787 * Free old path (if any) and allocate space for a new path. 4788 * Copy the path including the slash. 4789 * Remember the kernel32 filehandle (to be able to invalidate the path). 4790 */ 4791 if (pszOdin32Path) 4792 rfree((void*)pszOdin32Path); 4793 if (*pszEnd == ':') //in case someone installed odin in a root directory. 4794 pszEnd++; 4795 pszEnd++; //include the slash 4796 pszPath = (char*)rmalloc(pszEnd - psz); 4797 if (pszPath == NULL) return FALSE; 4798 memcpy(pszPath, psz, pszEnd - psz); 4799 pszPath[pszEnd - psz] = '\0'; 4800 pszOdin32Path = pszPath; 4801 4802 return TRUE; 4803 } 4695 4804 4696 4805 return FALSE; 4697 4806 } 4807 4808 4698 4809 4699 4810
Note:
See TracChangeset
for help on using the changeset viewer.