Changeset 2890
- Timestamp:
- Nov 21, 2006, 5:33:25 PM (19 years ago)
- Location:
- trunk/kLdr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrModLX.c
r2889 r2890 182 182 uint32_t i; 183 183 int rc; 184 int fCanOptimizeMapping; 185 uint32_t NextRVA; 184 186 *ppModLX = NULL; 185 187 … … 323 325 pModLX->pMod = pMod; 324 326 pModLX->pvMapping = 0; 325 pModLX->cbMapped = Hdr.e32_mpages * Hdr.e32_pagesize;327 pModLX->cbMapped = 0; 326 328 pModLX->f32Reserved = 0; 327 329 … … 404 406 } 405 407 } 406 pModLX->cbMapped = pMod->cSegments 407 ? pModLX->paObjs[pMod->cSegments - 1].o32_base + pModLX->paObjs[pMod->cSegments - 1].o32_size 408 - pModLX->paObjs[pMod->cSegments - 1].o32_size 409 : 0; 408 409 /* 410 * Check if we can optimize the mapping by using a different 411 * object alignment. The linker typically uses 64KB alignment, 412 * we can easily get away with page alignment in most cases. 413 */ 414 fCanOptimizeMapping = !(Hdr.e32_mflags & (E32NOINTFIX | E32SYSDLL)); 415 NextRVA = 0; 410 416 411 417 /* … … 420 426 pMod->aSegments[i].cchName = 0; 421 427 pMod->aSegments[i].offFile = -1; 422 pMod->aSegments[i].cbFile = 0;428 pMod->aSegments[i].cbFile = -1; 423 429 424 430 /* size and addresses */ … … 426 432 pMod->aSegments[i].cb = pModLX->paObjs[i].o32_size; 427 433 pMod->aSegments[i].LinkAddress = pModLX->paObjs[i].o32_base; 428 pMod->aSegments[i].RVA = pModLX->paObjs[i].o32_base - pModLX->paObjs[0].o32_base; 429 pMod->aSegments[i].cbMapped = KLDR_ALIGN_Z(pModLX->paObjs[i].o32_size, 16); 430 if (i + 1 < pMod->cSegments) 431 pMod->aSegments[i].cbMapped = pModLX->paObjs[i + 1].o32_base - pModLX->paObjs[i].o32_base; 434 pMod->aSegments[i].RVA = NextRVA; 435 if (fCanOptimizeMapping) 436 pMod->aSegments[i].cbMapped = KLDR_ALIGN_Z(pModLX->paObjs[i].o32_size, OBJPAGELEN); 437 else 438 pMod->aSegments[i].cbMapped = i + 1 < pMod->cSegments 439 ? pModLX->paObjs[i + 1].o32_base - pModLX->paObjs[i].o32_base 440 : KLDR_ALIGN_Z(pModLX->paObjs[i].o32_size, OBJPAGELEN); 441 NextRVA += pMod->aSegments[i].cbMapped; 432 442 433 443 /* protection */ … … 475 485 } 476 486 487 /* set the mapping size */ 488 pModLX->cbMapped = NextRVA; 489 477 490 /* 478 491 * We're done. … … 488 501 PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData; 489 502 int rc = 0; 490 KLDRMODLX_ASSERT( pModLX->pvMapping);503 KLDRMODLX_ASSERT(!pModLX->pvMapping); 491 504 492 505 if (pMod->pRdr) … … 922 935 kldrModLXResolveBaseAddress(pModLX, &BaseAddress); 923 936 924 return -1;937 return 0; 925 938 } 926 939 … … 1193 1206 case VALID: 1194 1207 if (pMap->o32_pagesize == OBJPAGELEN) 1195 rc = kLdrRdrRead(pRdr, pbPage, OBJPAGELEN, pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift); 1208 rc = kLdrRdrRead(pRdr, pbPage, OBJPAGELEN, 1209 pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift)); 1196 1210 else if (pMap->o32_pagesize < OBJPAGELEN) 1197 1211 { 1198 rc = kLdrRdrRead(pRdr, pbPage, pMap->o32_pagesize, pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift); 1212 rc = kLdrRdrRead(pRdr, pbPage, pMap->o32_pagesize, 1213 pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift)); 1199 1214 kLdrHlpMemSet(pbPage + pMap->o32_pagesize, 0, OBJPAGELEN - pMap->o32_pagesize); 1200 1215 } … … 1220 1235 1221 1236 /* read it and ensure 4 extra zero bytes. */ 1222 rc = kLdrRdrRead(pRdr, pbTmpPage, pMap->o32_pagesize, pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift); 1237 rc = kLdrRdrRead(pRdr, pbTmpPage, pMap->o32_pagesize, 1238 pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift)); 1223 1239 if (rc) 1224 1240 break; … … 1709 1725 { 1710 1726 PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData; 1727 int rc, rc2; 1711 1728 1712 1729 /* … … 1716 1733 return KLDR_ERR_NOT_MAPPED; 1717 1734 1718 /* the file provider does it all */ 1719 return kLdrRdrRefresh(pMod->pRdr, (void *)pModLX->pvMapping, pMod->cSegments, pMod->aSegments); 1735 /* 1736 * Before doing anything we'll have to make all pages writable. 1737 */ 1738 rc = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 1 /* unprotect */); 1739 if (rc) 1740 return rc; 1741 1742 /* 1743 * Load the bits again. 1744 */ 1745 rc = kldrModLXDoLoadBits(pModLX, (void *)pModLX->pvMapping); 1746 1747 /* 1748 * Restore protection. 1749 */ 1750 rc2 = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 0 /* protect */); 1751 if (!rc && rc2) 1752 rc = rc2; 1753 return rc; 1720 1754 } 1721 1755 … … 2061 2095 if (iModule >= pModLX->Hdr.e32_impmodcnt) 2062 2096 return KLDR_ERR_BAD_FIXUP; 2097 #if 1 2098 if (u.prlc->nr_flags & NRICHAIN) 2099 return KLDR_ERR_BAD_FIXUP; 2100 #endif 2063 2101 2064 2102 /* . */ … … 2105 2143 return KLDR_ERR_BAD_FIXUP; 2106 2144 #if 1 2107 if (u.prlc->nr_flags & NR CHAIN)2145 if (u.prlc->nr_flags & NRICHAIN) 2108 2146 return KLDR_ERR_BAD_FIXUP; 2109 2147 #endif … … 2160 2198 * Deal with the 'source' (i.e. the place that should be modified (very logical). 2161 2199 */ 2162 if (!(u.prlc->nr_ flags& NRCHAIN))2200 if (!(u.prlc->nr_stype & NRCHAIN)) 2163 2201 { 2164 2202 rc = kldrModLXDoReloc(pbPage, u.prlc->r32_soff, uValue, fKind); … … 2176 2214 return rc; 2177 2215 } 2216 pb = (const uint8_t *)poffSrc; 2178 2217 } 2179 2218 else -
trunk/kLdr/tstkLdrMod.c
r2878 r2890 79 79 80 80 81 /** 82 * Verbose memcmp(). 83 */ 84 static int TestMemComp(const void *pv1, const void *pv2, size_t cb) 85 { 86 size_t off; 87 const uint8_t *pb1 = (const uint8_t *)pv1; 88 const uint8_t *pb2 = (const uint8_t *)pv2; 89 if (!memcmp(pb1, pb2, cb)) 90 return 0; 91 printf("Mismatching blocks pv1=%p pv2=%p cb=%#x:\n", pv1, pv2, cb); 92 for (off = 0; off < cb; off++) 93 { 94 if (pb1[off] == pb2[off]) 95 continue; 96 printf("%08x %02x != %02x\n", off, pb1[off], pb2[off]); 97 } 98 return memcmp(pb1, pb2, cb); /* lazy */ 99 } 100 81 101 82 102 /** … … 97 117 if (rc) 98 118 return Failure("failed to get image bits, rc=%d (a)", rc); 99 if ( memcmp(pvBits2, pvBits, cbImage))119 if (TestMemComp(pvBits2, pvBits, cbImage)) 100 120 return Failure("relocation test failed, mismatching bits (a)"); 101 121 … … 109 129 if (rc) 110 130 return Failure("failed to relocate, rc=%d (b2)"); 111 if ( memcmp(pvBits2, pvBits, cbImage))131 if (TestMemComp(pvBits2, pvBits, cbImage)) 112 132 return Failure("relocation test failed, mismatching bits (b)"); 113 133 … … 123 143 if (rc) 124 144 return Failure("failed to get image bits, rc=%d (c1)", rc); 125 if ( memcmp(pvBits2, pvBits, cbImage))145 if (TestMemComp(pvBits2, pvBits, cbImage)) 126 146 return Failure("relocation test failed, mismatching bits (c1)"); 127 147 … … 134 154 if (rc) 135 155 return Failure("failed to get image bits, rc=%d (c2)", rc); 136 if ( memcmp(pvBits2, pvBits, cbImage))156 if (TestMemComp(pvBits2, pvBits, cbImage)) 137 157 return Failure("relocation test failed, mismatching bits (c2)"); 138 158 … … 145 165 if (rc) 146 166 return Failure("failed to get image bits, rc=%d (c3)", rc); 147 if ( memcmp(pvBits2, pvBits, cbImage))167 if (TestMemComp(pvBits2, pvBits, cbImage)) 148 168 return Failure("relocation test failed, mismatching bits (c3)"); 149 169 … … 156 176 if (rc) 157 177 return Failure("failed to get image bits, rc=%d (c4)", rc); 158 if ( memcmp(pvBits2, pvBits, cbImage))178 if (TestMemComp(pvBits2, pvBits, cbImage)) 159 179 return Failure("relocation test failed, mismatching bits (c4)"); 160 180 … … 167 187 if (rc) 168 188 return Failure("failed to get image bits, rc=%d (c5)", rc); 169 if ( memcmp(pvBits2, pvBits, cbImage))189 if (TestMemComp(pvBits2, pvBits, cbImage)) 170 190 return Failure("relocation test failed, mismatching bits (c5)"); 171 191
Note:
See TracChangeset
for help on using the changeset viewer.