Changeset 3834 for branches/GRACE/src/win32k/pe2lx/pe2lx.cpp
- Timestamp:
- Jul 17, 2000, 12:43:41 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GRACE/src/win32k/pe2lx/pe2lx.cpp
r2927 r3834 1 /* $Id: pe2lx.cpp,v 1.18 2000-02-27 02:18:10bird Exp $1 /* $Id: pe2lx.cpp,v 1.18.4.1 2000-07-16 22:43:41 bird Exp $ 2 2 * 3 3 * Pe2Lx class implementation. Ring 0 and Ring 3 … … 670 670 * @param pvBuffer Pointer to buffer where data is to be put. 671 671 * @param cbToRead Bytes to be read. 672 * @param f lFlagFlags which was spesified to the ldrRead call.672 * @param fpBuffer Flags which was spesified to the ldrRead call. 673 673 * @parma pMTE Pointer to MTE which was specified to the ldrRead call. 674 674 * @return NO_ERROR if successful something else if not. … … 676 676 * @author knut st. osmundsen 677 677 */ 678 ULONG Pe2Lx::read(ULONG offLXFile, PVOID pvBuffer, ULONG cbToRead, ULONG flFlags, PMTE pMTE)678 ULONG Pe2Lx::read(ULONG offLXFile, PVOID pvBuffer, ULONG fpBuffer, ULONG cbToRead, PMTE pMTE) 679 679 { 680 680 APIRET rc = NO_ERROR; /* Return code. */ … … 696 696 #endif 697 697 698 printInf((" read(%d, 0x%08x, %d, 0x%08x)\n", offLXFile, pvBuffer, cbToRead, flFlags));698 printInf(("Pe2Lx::read(%d, 0x%08x, 0x%08x, %d)\n", offLXFile, pvBuffer, fpBuffer, cbToRead)); 699 699 700 700 /* Could we skip right to the datapages? */ … … 931 931 /* calc PE offset and size of read. */ 932 932 cbReadVar = min(paObjects[iObj].cbPhysical - offObject, cbToRead); 933 rc = ReadAtF(hFile, offPEFile, pvBuffer, cbReadVar, flFlags, pMTE);933 rc = ReadAtF(hFile, offPEFile, pvBuffer, fpBuffer, cbReadVar, pMTE); 934 934 } 935 935 else … … 938 938 { /* before TIBFix code. */ 939 939 cbReadVar = min(paObjects[iObj].Misc.offTIBFix - offObject, cbToRead); 940 rc = ReadAtF(hFile, offPEFile, pvBuffer, cbReadVar, flFlags, pMTE);940 rc = ReadAtF(hFile, offPEFile, pvBuffer, fpBuffer, cbReadVar, pMTE); 941 941 } 942 942 else … … 959 959 } 960 960 961 NOREF(f lFlags);961 NOREF(fpBuffer); 962 962 NOREF(pMTE); 963 963 return rc; … … 1281 1281 1282 1282 1283 /** 1284 * openPath - opens file eventually searching loader specific paths. 1285 * This method is only called for DLLs. DosLoadModule and Imports. 1286 * 1287 * This base implementation simply calls ldrOpenPath. 1288 * 1289 * @returns OS2 return code. 1290 * pLdrLv->lv_sfn is set to filename handle. 1291 * @param pachModname Pointer to modulename. Not zero terminated! 1292 * @param cchModname Modulename length. 1293 * @param pLdrLv Loader local variables? (Struct from KERNEL.SDF) 1294 * @param pfl Pointer to flags which are passed on to ldrOpen. 1295 * @sketch 1296 * This is roughly what the original ldrOpenPath does: 1297 * if !CLASS_GLOBAL or miniifs then 1298 * ldrOpen(pachModName) 1299 * else 1300 * loop until no more libpath elements 1301 * get next libpath element and add it to the modname. 1302 * try open the modname 1303 * if successfull then break the loop. 1304 * endloop 1305 * endif 1306 */ 1307 ULONG Pe2Lx::openPath(PCHAR pachModname, USHORT cchModname, ldrlv_t *pLdrLv, PULONG pfl) /* (ldrOpenPath) */ 1308 { 1309 #ifdef RING0 1310 1311 /* These defines sets the order the paths and pathlists are examined. */ 1312 #define FINDDLL_EXECUTABLEDIR 1 1313 #define FINDDLL_CURRENTDIR 2 1314 #define FINDDLL_SYSTEM32DIR 3 1315 #define FINDDLL_SYSTEM16DIR 4 1316 #define FINDDLL_WINDIR 5 1317 #define FINDDLL_PATH 6 1318 #define FINDDLL_BEGINLIBPATH 7 1319 #define FINDDLL_LIBPATH 8 1320 #define FINDDLL_ENDLIBPATH 9 1321 #define FINDDLL_FIRST FINDDLL_EXECUTABLEDIR 1322 #define FINDDLL_LAST FINDDLL_ENDLIBPATH 1323 1324 struct 1325 { 1326 char sz[CCHMAXPATH]; 1327 } *pVars; 1328 1329 1330 /* 1331 * Mark the SFN invalid in the case of error. 1332 * Initiate the Odin32 Path static variable. 1333 * Allocate memory for local variables. 1334 */ 1335 pLdrLv->lv_sfn = 0xffff; 1336 initOdin32Path(); 1337 pVar = rmalloc(sizeof(*pVars)); 1338 if (pVar == NULL) 1339 return ERROR_NOT_ENOUGH_MEMORY; 1340 1341 /* init stuff */ 1342 1343 1344 1345 1346 /** @sketch 1347 * Loop thru the paths and pathlists searching them for the filename. 1348 */ 1349 for (iPath = FINDDLL_FIRST; iPath <= FINDDLL_LAST; iPath++) 1350 { 1351 APIRET rc; /* Returncode from OS/2 APIs. */ 1352 const char * pszPath; /* Pointer to the path being examined. */ 1353 1354 /** @sketch 1355 * Get the path/dir to examin. (This is determined by the value if iPath.) 1356 */ 1357 switch (iPath) 1358 { 1359 case FINDDLL_EXECUTABLEDIR: 1360 if (pszAltPath) 1361 pszPath = strcpy(plv->szPath, pszAltPath); 1362 else 1363 { 1364 /* ASSUMES: getFullPath allways returns a fully qualified 1365 * path, ie. with at least one backslash. and that all 1366 * slashes are backslashes! 1367 */ 1368 if (!WinExe) continue; 1369 pszPath = strcpy(plv->szPath, WinExe->getFullPath()); 1370 } 1371 psz = strrchr(plv->szPath, '\\'); 1372 dassert(psz, ("KERNEL32:Win32ImageBase::findDll(%s, 0x%08x, %d): " 1373 "WinExe->getFullPath returned a path not fully qualified: %s", 1374 pszFileName, pszFullName, cchFullName, pszPath)); 1375 if (psz) 1376 *psz = '\0'; 1377 else 1378 continue; 1379 break; 1380 1381 case FINDDLL_CURRENTDIR: 1382 pszPath = "."; 1383 break; 1384 1385 case FINDDLL_SYSTEM32DIR: 1386 pszPath = InternalGetSystemDirectoryA(); 1387 break; 1388 1389 case FINDDLL_SYSTEM16DIR: 1390 #if 1 1391 continue; /* Skip this index */ 1392 #else 1393 pszPath = InternalGetWindowsDirectoryA(); 1394 strcpy(plv->sz2, InternalGetWindowsDirectoryA()); 1395 strcat(plv->sz2, "\SYSTEM"); 1396 break; 1397 #endif 1398 1399 case FINDDLL_WINDIR: 1400 pszPath = InternalGetWindowsDirectoryA(); 1401 break; 1402 1403 case FINDDLL_PATH: 1404 pszPath = getenv("PATH"); 1405 break; 1406 1407 case FINDDLL_BEGINLIBPATH: 1408 rc = DosQueryExtLIBPATH(plv->szPath, BEGIN_LIBPATH); 1409 if (rc != NO_ERROR) 1410 { 1411 dassert(rc == NO_ERROR, ("KERNEL32:Win32ImageBase::findDll(%s, 0x%08x, %d): " 1412 "DosQueryExtLIBPATH failed with rc=%d, iPath=%d", 1413 pszFileName, pszFullName, cchFullName, rc, iPath)); 1414 continue; 1415 } 1416 pszPath = plv->szPath; 1417 break; 1418 1419 case FINDDLL_LIBPATH: 1420 rc = DosQueryHeaderInfo(NULLHANDLE, 0, plv->szPath, sizeof(plv->szPath), QHINF_LIBPATH); 1421 if (rc != NO_ERROR) 1422 { 1423 dassert(rc == NO_ERROR, ("KERNEL32:Win32ImageBase::findDll(%s, 0x%08x, %d): " 1424 "DosQueryHeaderInfo failed with rc=%d, iPath=%d", 1425 pszFileName, pszFullName, cchFullName, rc, iPath)); 1426 continue; 1427 } 1428 pszPath = plv->szPath; 1429 break; 1430 1431 case FINDDLL_ENDLIBPATH: 1432 rc = DosQueryExtLIBPATH(plv->szPath, END_LIBPATH); 1433 if (rc != NO_ERROR) 1434 { 1435 dassert(rc == NO_ERROR, ("KERNEL32:Win32ImageBase::findDll(%s, 0x%08x, %d): " 1436 "DosQueryExtLIBPATH failed with rc=%d, iPath=%d", 1437 pszFileName, pszFullName, cchFullName, rc, iPath)); 1438 continue; 1439 } 1440 pszPath = plv->szPath; 1441 break; 1442 1443 default: /* !internalerror! */ 1444 goto end; 1445 } 1446 1447 1448 /** @sketch 1449 * pszPath is now set to the pathlist to be searched. 1450 * So we'll loop thru all the paths in the list. 1451 */ 1452 while (pszPath != NULL && *pszPath != '\0') 1453 { 1454 HDIR hDir; /* Find handle used when calling FindFirst. */ 1455 ULONG culFiles; /* Number of files to find / found. */ 1456 char * pszNext; /* Pointer to the next pathlist path */ 1457 int cch; /* Length of path (including the slash after the slash is added). */ 1458 1459 /** @sketch 1460 * Find the end of the path. 1461 * Copy the path into the plv->sz buffer. 1462 * Set pszNext. 1463 */ 1464 pszNext = strchr(pszPath, ';'); 1465 if (pszNext != NULL) 1466 { 1467 cch = pszNext - pszPath; 1468 pszNext++; 1469 } 1470 else 1471 cch = strlen(pszPath); 1472 1473 if (cch + cchFileName + 1 >= sizeof(plv->sz)) /* assertion */ 1474 { 1475 dassert(cch + cchFileName + 1 < sizeof(plv->sz), ("KERNEL32:Win32ImageBase::findDll(%s, 0x%08x, %d): " 1476 "cch (%d) + cchFileName (%d) + 1 < sizeof(plv->sz) (%d) - paths too long!, iPath=%d", 1477 pszFileName, pszFullName, cchFullName, cch, cchFileName, sizeof(plv->sz), iPath)); 1478 pszPath = pszNext; 1479 continue; 1480 } 1481 memcpy(plv->sz, pszPath, cch); //arg! Someone made strncpy not work as supposed! 1482 1483 1484 /** @sketch 1485 * Add a '\\' and the filename (pszFullname) to the path; 1486 * then we'll have a fullpath. 1487 */ 1488 plv->sz[cch++] = '\\'; 1489 strcpy(&plv->sz[cch], pszFullName); 1490 1491 1492 /** @sketch 1493 * Use DosFindFirst to check if the file exists. 1494 * IF the file exists THEN 1495 * Query Fullpath using OS/2 API. 1496 * IF unsuccessful THEN return relative name. 1497 * Check that the fullname buffer is large enough. 1498 * Copy the filename found to the fullname buffer. 1499 * ENDIF 1500 * IF successful THEN uppercase the fullname buffer. 1501 * goto end 1502 * ENDIF 1503 */ 1504 hDir = HDIR_CREATE; 1505 culFiles = 1; 1506 rc = DosFindFirst(plv->sz, &hDir, FILE_NORMAL, 1507 &plv->findbuf3, sizeof(plv->findbuf3), 1508 &culFiles, FIL_STANDARD); 1509 DosFindClose(hDir); 1510 if (culFiles >= 1 && rc == NO_ERROR) 1511 { 1512 /* Return full path - we'll currently return a relative path. */ 1513 rc = DosQueryPathInfo(plv->sz, FIL_QUERYFULLNAME, pszFullName, cchFullName); 1514 fRet = rc == NO_ERROR; 1515 if (!fRet) 1516 { 1517 /* Return a relative path - probably better that failing... */ 1518 dassert(rc == NO_ERROR, ("KERNEL32:Win32ImageBase::findDll(%s, 0x%08x, %d): " 1519 "rc = %d", 1520 pszFileName, pszFullName, cchFullName, rc)); 1521 1522 if (cch + cchFileName + 1 <= cchFullName) 1523 { 1524 strcpy(pszFullName, plv->sz); 1525 strcpy(pszFullName + cch, plv->findbuf3.achName); 1526 fRet = TRUE; 1527 } 1528 else 1529 { 1530 dassert(cch + cchFileName + 1 > cchFullName, ("KERNEL32:Win32ImageBase::findDll(%s, 0x%08x, %d): " 1531 "cch (%d) + cchFileName (%d) + 1 < cchFullName (%d); %s", 1532 pszFileName, pszFullName, cchFullName, cch, cchFileName, cchFullName, plv->sz)); 1533 } 1534 } 1535 if (fRet) strupr(pszFullName); 1536 goto end; 1537 } 1538 1539 pszPath = pszNext; 1540 } 1541 } /* for iPath */ 1542 1543 1544 end: 1545 /* 1546 * Cleanup: free local variables. 1547 */ 1548 free(plv); 1549 return fRet; 1550 1551 1552 1553 1554 1555 return ldrOpenPath(pachModname, cchModname, pLdrLv, pfl); 1556 #else 1557 NOREF(pachModname); 1558 NOREF(cchModname); 1559 NOREF(pLdrLv); 1560 NOREF(pfl); 1561 return ERROR_NOT_SUPPORTED; 1562 #endif 1563 } 1564 1565 1566 1567 1283 1568 #ifndef RING0 1284 1569 /** … … 1411 1696 } 1412 1697 #endif 1698 1699 1700 /** 1701 * Is this module an executable? 1702 * @returns TRUE if executable. 1703 * FALSE if not an executable. 1704 * @sketch 1705 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1706 */ 1707 BOOL Pe2Lx::isExe() 1708 { 1709 return ((this->LXHdr.e32_mflags & E32MODMASK) == E32MODEXE); 1710 } 1711 1712 1713 /** 1714 * Is this module an dynamic link library. 1715 * @returns TRUE if dynamic link library. 1716 * FALSE if not a dynamic link library. 1717 * @sketch 1718 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1719 */ 1720 BOOL Pe2Lx::isDll() 1721 { 1722 return ((this->LXHdr.e32_mflags & E32MODMASK) == E32MODDLL); 1723 } 1413 1724 1414 1725
Note:
See TracChangeset
for help on using the changeset viewer.