Changeset 5841 for trunk/src/kernel32
- Timestamp:
- May 30, 2001, 8:33:00 PM (24 years ago)
- Location:
- trunk/src/kernel32
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/ccollection.cpp
r5838 r5841 1 /* $Id: ccollection.cpp,v 1. 4 2001-05-30 13:02:55phaller Exp $ */1 /* $Id: ccollection.cpp,v 1.5 2001-05-30 18:29:59 phaller Exp $ */ 2 2 3 3 /* … … 87 87 // shrink the index array to the absolutely necessary size only 88 88 89 if (iInitialized == 0) 90 { 91 // if no elements were allocated, simple remove all data memory 92 if (pEntries) 93 { 94 free(pEntries); 95 pEntries = NULL; 96 } 97 98 return 1; 99 } 100 89 101 // verify if shrink can do anything good 90 102 if ( (iOffset < iUsedOffset) || … … 106 118 int iRelative = iUsedOffset - iOffset; 107 119 108 memcpy(pNewData, 109 pEntries + (iRelative * sizeof(INDEXLOOKUPENTRY)), 110 iRequiredSize * sizeof(INDEXLOOKUPENTRY)); 120 // Note: due to C++ pointer arithmetic, 121 // (pEntries + iRelative) should automatically 122 // increase pEntries by iRelative-times the 123 // sizeof(INDEXLOOKUPENTRY) byte positions! 124 memmove(pNewData, 125 pEntries + iRelative, 126 iRequiredSize * sizeof(INDEXLOOKUPENTRY)); 111 127 112 128 // deferred delete ensures we've always got a valid array … … 153 169 { 154 170 // copy the data, array cannot overlap 155 memmove(pNewData ,171 memmove(pNewData + (iShift * sizeof(INDEXLOOKUPENTRY)), 156 172 pEntries, 157 iSize );173 iSize * sizeof(INDEXLOOKUPENTRY)); 158 174 159 175 // zero out at the beginning or at the end … … 214 230 PINDEXLOOKUPENTRY pTemp = pEntries; 215 231 pEntries = pNewData; 216 free(pTemp); 232 if (pTemp) 233 free(pTemp); 217 234 218 235 iSize = iRequiredSize; … … 236 253 PINDEXLOOKUPENTRY pTemp = pEntries; 237 254 pEntries = pNewData; 238 free(pTemp); 239 255 if (pTemp) 256 free(pTemp); 257 240 258 iSize = iRequiredSize; 241 259 iHigh = iIndex; … … 261 279 if (iIndex > iUsedHigh) 262 280 iUsedHigh = iIndex; 281 282 // used limits are not initialized 283 iInitialized = 1; 263 284 264 285 // insert entry and quit … … 302 323 iUsedOffset = INT_MAX; 303 324 iUsedHigh = INT_MIN; 325 iInitialized = 0; 304 326 } 305 327 … … 318 340 } 319 341 } 320 321 342 322 343 -
trunk/src/kernel32/winimagepeldr_new.cpp
r5837 r5841 1 /* $Id: winimagepeldr_new.cpp,v 1. 1 2001-05-30 08:23:21 sandervlExp $ */1 /* $Id: winimagepeldr_new.cpp,v 1.2 2001-05-30 18:32:15 phaller Exp $ */ 2 2 3 3 /* … … 60 60 //This is very useful during debugging as you'll get lots of exceptions 61 61 //otherwise. 62 63 62 //#ifdef DEBUG 64 63 #define COMMIT_ALL … … 114 113 imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0), 115 114 nrNameExports(0), nrOrdExports(0), 115 #ifdef VERIFY_LOADER 116 nameexports(NULL), ordexports(NULL), 117 curnameexport(NULL), curordexport(NULL), 118 #endif 116 119 memmap(NULL), pFixups(NULL), dwFixupSize(0) 117 120 { … … 145 148 // create objects for fast API lookup 146 149 pLookupOrdinal = new CIndexLookupLimit(0, 65535); 147 pLookupName = new CHashtableLookup( 79);150 pLookupName = new CHashtableLookup(503); 148 151 } 149 152 //****************************************************************************** … … 167 170 if(realBaseAddress) 168 171 DosFreeMem((PVOID)realBaseAddress); 172 173 #ifdef VERIFY_LOADER 174 if(nameexports) 175 free(nameexports); 176 177 if(ordexports) 178 free(ordexports); 179 #endif 169 180 170 181 if(section) … … 1373 1384 // also add the ordinal export to the lookup cache 1374 1385 pLookupOrdinal->addElement(ordinal, (void*)uv); 1386 1387 #ifdef VERIFY_LOADER 1388 ULONG nsize; 1389 1390 if(nameexports == NULL) { 1391 nameExportSize= 4096; 1392 nameexports = (NameExport *)malloc(nameExportSize); 1393 curnameexport = nameexports; 1394 } 1395 nsize = (ULONG)curnameexport - (ULONG)nameexports; 1396 if(nsize + sizeof(NameExport) + strlen(apiname) > nameExportSize) { 1397 nameExportSize += 4096; 1398 char *tmp = (char *)nameexports; 1399 nameexports = (NameExport *)malloc(nameExportSize); 1400 memcpy(nameexports, tmp, nsize); 1401 curnameexport = (NameExport *)((ULONG)nameexports + nsize); 1402 free(tmp); 1403 } 1404 if(fAbsoluteAddress) {//forwarders use absolute address 1405 curnameexport->virtaddr = virtaddr; 1406 } 1407 else curnameexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase); 1408 curnameexport->ordinal = ordinal; 1409 *(ULONG *)curnameexport->name = 0; 1410 strcpy(curnameexport->name, apiname); 1411 1412 curnameexport->nlength = strlen(apiname) + 1; 1413 if(curnameexport->nlength < sizeof(curnameexport->name)) 1414 curnameexport->nlength = sizeof(curnameexport->name); 1415 1416 curnameexport = (NameExport *)((ULONG)curnameexport->name + curnameexport->nlength); 1417 #endif 1375 1418 } 1376 1419 //****************************************************************************** … … 1390 1433 // add ordinal export to the lookup cache 1391 1434 pLookupOrdinal->addElement((int)ordinal, (void*)uv); 1435 1436 1437 #ifdef VERIFY_LOADER 1438 if(ordexports == NULL) { 1439 ordexports = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport)); 1440 curordexport = ordexports; 1441 } 1442 if(fAbsoluteAddress) {//forwarders use absolute address 1443 curordexport->virtaddr = virtaddr; 1444 } 1445 else curordexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase); 1446 1447 curordexport->ordinal = ordinal; 1448 curordexport++; 1449 #endif 1392 1450 } 1393 1451 //****************************************************************************** … … 1803 1861 //****************************************************************************** 1804 1862 //****************************************************************************** 1863 #ifdef VERIFY_LOADER 1864 ULONG Win32PeLdrImage::new_getApi(char *name) 1865 #else 1805 1866 ULONG Win32PeLdrImage::getApi(char *name) 1867 #endif 1806 1868 { 1807 1869 // ordinal export from the lookup cache 1808 void* pNamed = pLookupName->getElement(name); 1809 return (ULONG)pNamed; 1810 } 1811 //****************************************************************************** 1812 //****************************************************************************** 1870 return (ULONG)pLookupName->getElement(name); 1871 } 1872 //****************************************************************************** 1873 //****************************************************************************** 1874 #ifdef VERIFY_LOADER 1875 ULONG Win32PeLdrImage::new_getApi(int ordinal) 1876 #else 1813 1877 ULONG Win32PeLdrImage::getApi(int ordinal) 1878 #endif 1814 1879 { 1815 1880 // ordinal export from the lookup cache 1816 void* pOrdinal = pLookupOrdinal->getElement(ordinal); 1817 return (ULONG)pOrdinal; 1818 } 1881 return (ULONG)pLookupOrdinal->getElement(ordinal); 1882 } 1883 //****************************************************************************** 1884 //****************************************************************************** 1885 #ifdef VERIFY_LOADER 1886 ULONG Win32PeLdrImage::getApi(char *name) 1887 { 1888 ULONG ulVerify1 = new_getApi(name); 1889 ULONG ulVerify2 = old_getApi(name); 1890 1891 if (ulVerify1 != ulVerify2) 1892 dprintf((LOG, 1893 "WinImagePeLdr::getApi(%s) difference: ulVerify1=%08xh, ulVerify2=%08xh\n", 1894 name, 1895 ulVerify1, 1896 ulVerify2)); 1897 1898 return ulVerify2; 1899 } 1900 1901 1902 ULONG Win32PeLdrImage::getApi(int ordinal) 1903 { 1904 ULONG ulVerify1 = new_getApi(ordinal); 1905 ULONG ulVerify2 = old_getApi(ordinal); 1906 1907 if (ulVerify1 != ulVerify2) 1908 dprintf((LOG, 1909 "WinImagePeLdr::getApi(%d) difference: ulVerify1=%08xh, ulVerify2=%08xh\n", 1910 ordinal, 1911 ulVerify1, 1912 ulVerify2)); 1913 1914 return ulVerify2; 1915 } 1916 1917 1918 1919 1920 ULONG Win32PeLdrImage::old_getApi(char *name) 1921 { 1922 ULONG apiaddr, i, apilen; 1923 char *apiname; 1924 char tmp[4]; 1925 NameExport *curexport; 1926 ULONG ulAPIOrdinal; /* api requested by ordinal */ 1927 1928 apilen = strlen(name) + 1; 1929 if(apilen < 4) 1930 { 1931 *(ULONG *)tmp = 0; 1932 strcpy(tmp, name); 1933 apiname = tmp; 1934 apilen = 4; 1935 } 1936 else apiname = name; 1937 1938 curexport = nameexports; 1939 for(i=0; i<nrNameExports; i++) 1940 { 1941 if(apilen == curexport->nlength && 1942 *(ULONG *)curexport->name == *(ULONG *)apiname) 1943 { 1944 if(strcmp(curexport->name, apiname) == 0) 1945 return(curexport->virtaddr); 1946 } 1947 curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength); 1948 } 1949 return(0); 1950 } 1951 //****************************************************************************** 1952 //****************************************************************************** 1953 ULONG Win32PeLdrImage::old_getApi(int ordinal) 1954 { 1955 ULONG apiaddr, i; 1956 OrdExport *curexport; 1957 NameExport *nexport; 1958 1959 curexport = ordexports; 1960 for(i=0;i<nrOrdExports;i++) { 1961 if(curexport->ordinal == ordinal) 1962 return(curexport->virtaddr); 1963 curexport++; 1964 } 1965 //Name exports also contain an ordinal, so check this 1966 nexport = nameexports; 1967 for(i=0;i<nrNameExports;i++) { 1968 if(nexport->ordinal == ordinal) 1969 return(nexport->virtaddr); 1970 1971 nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength); 1972 } 1973 return(0); 1974 } 1975 #endif 1819 1976 //****************************************************************************** 1820 1977 //Returns required OS version for this image -
trunk/src/kernel32/winimagepeldr_new.h
r5837 r5841 1 /* $Id: winimagepeldr_new.h,v 1. 1 2001-05-30 08:23:22 sandervlExp $ */1 /* $Id: winimagepeldr_new.h,v 1.2 2001-05-30 18:32:15 phaller Exp $ */ 2 2 3 3 /* … … 14 14 15 15 #include <winimagebase.h> 16 17 18 // 2001-05-30 PH 19 // to enable sanity checks for the new loader code, 20 // enable this define. 21 //#define VERIFY_LOADER 22 16 23 17 24 #define SINGLE_PAGE 0 //commit single page … … 55 62 } Section; 56 63 64 65 #ifdef VERIFY_LOADER 66 typedef struct { 67 ULONG virtaddr; 68 ULONG ordinal; 69 ULONG nlength; 70 char name[4]; 71 } NameExport; 72 73 typedef struct { 74 ULONG virtaddr; 75 ULONG ordinal; 76 } OrdExport; 77 #endif 78 57 79 class Win32DllBase; 58 80 class Win32MemMap; … … 77 99 virtual ULONG getApi(char *name); 78 100 virtual ULONG getApi(int ordinal); 101 102 #ifdef VERIFY_LOADER 103 virtual ULONG new_getApi(char *name); 104 virtual ULONG new_getApi(int ordinal); 105 virtual ULONG old_getApi(char *name); 106 virtual ULONG old_getApi(int ordinal); 107 #endif 79 108 80 109 virtual ULONG getImageSize(); … … 115 144 BOOL AddForwarder(ULONG virtaddr, char *apiname, ULONG ordinal); 116 145 117 146 Win32DllBase *loadDll(char *pszCurModule); 118 147 119 148 IMAGE_OPTIONAL_HEADER oh; … … 122 151 ULONG nrNameExports, nameExportSize; 123 152 ULONG nrOrdExports; 153 154 #ifdef VERIFY_LOADER 155 NameExport *nameexports, *curnameexport; 156 OrdExport *ordexports, *curordexport; 157 #endif 124 158 125 159 ULONG nrsections, imageSize, imageVirtBase, imageVirtEnd;
Note:
See TracChangeset
for help on using the changeset viewer.