userlibandfileserver/fileserver/sfile/sf_lepoc.cpp
branchRCL_3
changeset 39 2bb754abd467
parent 21 e7d2d738d3c2
equal deleted inserted replaced
36:bbf8bed59bcb 39:2bb754abd467
   285 		ExecuteInSupervisorModeVector = UserSvr::ExecuteInSupervisorMode;
   285 		ExecuteInSupervisorModeVector = UserSvr::ExecuteInSupervisorMode;
   286 		gExecutesInSupervisorMode = ETrue;
   286 		gExecutesInSupervisorMode = ETrue;
   287 		}
   287 		}
   288 	}
   288 	}
   289 
   289 
   290 // A version that will work in user or supervisor mode
   290 /**
   291 void MyPrintf(const char* aFmt, ...)
   291 It would be nice to be able to print debug information from the various functions
   292 	{
   292 supervisor-mode functions below. Unfortunately, we can't call RDebug::Printf() or
       
   293 any of its relatives in supervisor mode, and of course we can't call the equivalent
       
   294 kernel functions even when we're already in supervisor mode, because the entry
       
   295 points aren't visible.
       
   296 
       
   297 So this function just wraps and guards the call to RDebug, so we won't call it
       
   298 in SVC mode. The outcome is that trace messages are only generated if using the
       
   299 flexible memory model, where the code doesn't actually run in SVC mode anyway.
       
   300 */
       
   301 void svPrintf(const char* aFmt, ...)
       
   302 	{
       
   303 	if (gExecutesInSupervisorMode)
       
   304 		return;
       
   305 
   293 	VA_LIST list;
   306 	VA_LIST list;
   294 	VA_START(list, aFmt);
   307 	VA_START(list, aFmt);
   295 	TPtrC8 fmt((const TText8*)aFmt);
   308 	TPtrC8 fmt((const TText8*)aFmt);
   296 	TBuf8<0x100> buf;
   309 	TBuf8<0x100> buf;
   297 	buf.AppendFormatList(fmt, list);
   310 	buf.AppendFormatList(fmt, list);
   377 TInt svRelocateExports(TAny* aPtr)
   390 TInt svRelocateExports(TAny* aPtr)
   378 	{
   391 	{
   379 	E32Image& exporter = *(E32Image*)aPtr;
   392 	E32Image& exporter = *(E32Image*)aPtr;
   380 
   393 
   381 	// Dump everything potentially useful that we know about the exporter ...
   394 	// Dump everything potentially useful that we know about the exporter ...
   382 	__LDRTRACE(MyPrintf("RelocateExports: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
   395 	__LDRTRACE(svPrintf("RelocateExports: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
   383 						exporter.iUseCodePaging, exporter.iRomImageHeader, exporter.iHeader));
   396 						exporter.iUseCodePaging, exporter.iRomImageHeader, exporter.iHeader));
   384 	__LDRTRACE(MyPrintf("  iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
   397 	__LDRTRACE(svPrintf("  iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
   385 						exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
   398 						exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
   386 						exporter.iCodeSize, exporter.iTextSize))
   399 						exporter.iCodeSize, exporter.iTextSize))
   387 	__LDRTRACE(MyPrintf("  iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
   400 	__LDRTRACE(svPrintf("  iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
   388 						exporter.iDataLoadAddress, exporter.iDataRunAddress,
   401 						exporter.iDataLoadAddress, exporter.iDataRunAddress,
   389 						exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
   402 						exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
   390 	__LDRTRACE(MyPrintf("  iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
   403 	__LDRTRACE(svPrintf("  iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
   391 						exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
   404 						exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
   392 
   405 
   393 	// It turns out that very little of the exporter info is useful! For
   406 	// It turns out that very little of the exporter info is useful! For
   394 	// example, the required code and data deltas are NOT those provided
   407 	// example, the required code and data deltas are NOT those provided
   395 	// by the exporter, nor are the load addresses relevant ... :(
   408 	// by the exporter, nor are the load addresses relevant ... :(
   427 			newValue = relocAddr + dataDelta;		// points to data/bss section
   440 			newValue = relocAddr + dataDelta;		// points to data/bss section
   428 		else
   441 		else
   429 			newValue = relocAddr;					// unknown - just leave it alone
   442 			newValue = relocAddr;					// unknown - just leave it alone
   430 		*destExport++ = newValue;
   443 		*destExport++ = newValue;
   431 
   444 
   432 		__LDRTRACE(MyPrintf("RelocateExports: export %d %08x => %08x %c",
   445 		__LDRTRACE(svPrintf("RelocateExports: export %d %08x => %08x %c",
   433 							exporter.iExportDirCount-i, relocAddr, newValue,
   446 							exporter.iExportDirCount-i, relocAddr, newValue,
   434 							(relocAddr >= codeStart && relocAddr < codeFinish) ? 'C' :
   447 							(relocAddr >= codeStart && relocAddr < codeFinish) ? 'C' :
   435 							(relocAddr >= dataStart && relocAddr < dataFinish) ? 'D' : 'X'));
   448 							(relocAddr >= dataStart && relocAddr < dataFinish) ? 'D' : 'X'));
   436 		}
   449 		}
   437 
   450 
   469 	{
   482 	{
   470 	SFixupImportAddressesInfo& info = *(SFixupImportAddressesInfo*)aPtr;
   483 	SFixupImportAddressesInfo& info = *(SFixupImportAddressesInfo*)aPtr;
   471 	E32Image& exporter = *info.iExporter;
   484 	E32Image& exporter = *info.iExporter;
   472 
   485 
   473 #ifdef _DEBUG
   486 #ifdef _DEBUG
   474 	__LDRTRACE(MyPrintf(">svFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x",
   487 	__LDRTRACE(svPrintf(">svFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x",
   475 						info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter));
   488 						info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter));
   476 
   489 
   477 	// Dump everything potentially useful that we know about the exporter ...
   490 	// Dump everything potentially useful that we know about the exporter ...
   478 	__LDRTRACE(MyPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
   491 	__LDRTRACE(svPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
   479 						&exporter.iFileName, exporter.iUseCodePaging,
   492 						&exporter.iFileName, exporter.iUseCodePaging,
   480 						exporter.iRomImageHeader, exporter.iHeader));
   493 						exporter.iRomImageHeader, exporter.iHeader));
   481 	__LDRTRACE(MyPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
   494 	__LDRTRACE(svPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
   482 						exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
   495 						exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
   483 						exporter.iCodeSize, exporter.iTextSize))
   496 						exporter.iCodeSize, exporter.iTextSize))
   484 	__LDRTRACE(MyPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
   497 	__LDRTRACE(svPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
   485 						exporter.iDataLoadAddress, exporter.iDataRunAddress,
   498 						exporter.iDataLoadAddress, exporter.iDataRunAddress,
   486 						exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
   499 						exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
   487 	__LDRTRACE(MyPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
   500 	__LDRTRACE(svPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
   488 						exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
   501 						exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
   489 
   502 
   490 	if (exporter.iRomImageHeader)
   503 	if (exporter.iRomImageHeader)
   491 		{
   504 		{
   492 		const TRomImageHeader& rh = *exporter.iRomImageHeader;
   505 		const TRomImageHeader& rh = *exporter.iRomImageHeader;
   493 		__LDRTRACE(MyPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x",
   506 		__LDRTRACE(svPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x",
   494 							rh.iCodeAddress, rh.iCodeSize, rh.iTextSize));
   507 							rh.iCodeAddress, rh.iCodeSize, rh.iTextSize));
   495 		__LDRTRACE(MyPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x",
   508 		__LDRTRACE(svPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x",
   496 							rh.iDataAddress, rh.iDataSize, rh.iBssSize));
   509 							rh.iDataAddress, rh.iDataSize, rh.iBssSize));
   497 		__LDRTRACE(MyPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x",
   510 		__LDRTRACE(svPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x",
   498 							rh.iDataBssLinearBase, rh.iTotalDataSize));
   511 							rh.iDataBssLinearBase, rh.iTotalDataSize));
   499 		}
   512 		}
   500 
   513 
   501 	if (exporter.iHeader)
   514 	if (exporter.iHeader)
   502 		{
   515 		{
   503 		const E32ImageHeader& ih = *exporter.iHeader;
   516 		const E32ImageHeader& ih = *exporter.iHeader;
   504 		__LDRTRACE(MyPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x",
   517 		__LDRTRACE(svPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x",
   505 							ih.iCodeBase, ih.iCodeSize, ih.iTextSize));
   518 							ih.iCodeBase, ih.iCodeSize, ih.iTextSize));
   506 		__LDRTRACE(MyPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x",
   519 		__LDRTRACE(svPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x",
   507 							ih.iDataBase, ih.iDataSize, ih.iBssSize));
   520 							ih.iDataBase, ih.iDataSize, ih.iBssSize));
   508 		}
   521 		}
   509 #endif // _DEBUG
   522 #endif // _DEBUG
   510 
   523 
   511 	// 'exportDir' points to the address of the 0th ordinal (symbol name data);
   524 	// 'exportDir' points to the address of the 0th ordinal (symbol name data);
   536 				return KErrNotSupported;
   549 				return KErrNotSupported;
   537 			// The new value is just the address of the export, no adjustment needed
   550 			// The new value is just the address of the export, no adjustment needed
   538 			newValue = expAddr;
   551 			newValue = expAddr;
   539 			}
   552 			}
   540 
   553 
   541 		__LDRTRACE(MyPrintf("svFixupImportAddresses: import[%d]@%08x is export[%d] == %08x",
   554 		__LDRTRACE(svPrintf("svFixupImportAddresses: import[%d]@%08x is export[%d] == %08x",
   542 							iat - info.iIat, iat, ordinal, newValue));
   555 							iat - info.iIat, iat, ordinal, newValue));
   543 
   556 
   544 		// In non-paged code, we can simply replace the ordinals in the IAT with the
   557 		// In non-paged code, we can simply replace the ordinals in the IAT with the
   545 		// object addresses to which they refer once and for all. However, in a code
   558 		// object addresses to which they refer once and for all. However, in a code
   546 		// paging system, the IAT may be thrown away and later reloaded from the code
   559 		// paging system, the IAT may be thrown away and later reloaded from the code
   571 	{
   584 	{
   572 	SFixupImportAddressesInfo& info = *(SFixupImportAddressesInfo*)aPtr;
   585 	SFixupImportAddressesInfo& info = *(SFixupImportAddressesInfo*)aPtr;
   573 	E32Image& exporter = *info.iExporter;
   586 	E32Image& exporter = *info.iExporter;
   574 
   587 
   575 #ifdef _DEBUG
   588 #ifdef _DEBUG
   576 	__LDRTRACE(MyPrintf(">svElfDerivedFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x",
   589 	__LDRTRACE(svPrintf(">svElfDerivedFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x",
   577 						info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter));
   590 						info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter));
   578 
   591 
   579 	// Dump everything potentially useful that we know about the exporter ...
   592 	// Dump everything potentially useful that we know about the exporter ...
   580 	__LDRTRACE(MyPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
   593 	__LDRTRACE(svPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
   581 						&exporter.iFileName, exporter.iUseCodePaging,
   594 						&exporter.iFileName, exporter.iUseCodePaging,
   582 						exporter.iRomImageHeader, exporter.iHeader));
   595 						exporter.iRomImageHeader, exporter.iHeader));
   583 	__LDRTRACE(MyPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
   596 	__LDRTRACE(svPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
   584 						exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
   597 						exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
   585 						exporter.iCodeSize, exporter.iTextSize))
   598 						exporter.iCodeSize, exporter.iTextSize))
   586 	__LDRTRACE(MyPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
   599 	__LDRTRACE(svPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
   587 						exporter.iDataLoadAddress, exporter.iDataRunAddress,
   600 						exporter.iDataLoadAddress, exporter.iDataRunAddress,
   588 						exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
   601 						exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
   589 	__LDRTRACE(MyPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
   602 	__LDRTRACE(svPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
   590 						exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
   603 						exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
   591 
   604 
   592 	if (exporter.iRomImageHeader)
   605 	if (exporter.iRomImageHeader)
   593 		{
   606 		{
   594 		const TRomImageHeader& rh = *exporter.iRomImageHeader;
   607 		const TRomImageHeader& rh = *exporter.iRomImageHeader;
   595 		__LDRTRACE(MyPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x",
   608 		__LDRTRACE(svPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x",
   596 							rh.iCodeAddress, rh.iCodeSize, rh.iTextSize));
   609 							rh.iCodeAddress, rh.iCodeSize, rh.iTextSize));
   597 		__LDRTRACE(MyPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x",
   610 		__LDRTRACE(svPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x",
   598 							rh.iDataAddress, rh.iDataSize, rh.iBssSize));
   611 							rh.iDataAddress, rh.iDataSize, rh.iBssSize));
   599 		__LDRTRACE(MyPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x",
   612 		__LDRTRACE(svPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x",
   600 							rh.iDataBssLinearBase, rh.iTotalDataSize));
   613 							rh.iDataBssLinearBase, rh.iTotalDataSize));
   601 		}
   614 		}
   602 
   615 
   603 	if (exporter.iHeader)
   616 	if (exporter.iHeader)
   604 		{
   617 		{
   605 		const E32ImageHeader& ih = *exporter.iHeader;
   618 		const E32ImageHeader& ih = *exporter.iHeader;
   606 		__LDRTRACE(MyPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x",
   619 		__LDRTRACE(svPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x",
   607 							ih.iCodeBase, ih.iCodeSize, ih.iTextSize));
   620 							ih.iCodeBase, ih.iCodeSize, ih.iTextSize));
   608 		__LDRTRACE(MyPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x",
   621 		__LDRTRACE(svPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x",
   609 							ih.iDataBase, ih.iDataSize, ih.iBssSize));
   622 							ih.iDataBase, ih.iDataSize, ih.iBssSize));
   610 		}
   623 		}
   611 #endif // _DEBUG
   624 #endif // _DEBUG
   612 
   625 
   613 	// Here we calculate the bounds of each section of the exporter, as
   626 	// Here we calculate the bounds of each section of the exporter, as
   698 			else
   711 			else
   699 				sectionDelta = dirDelta;			// unknown - assume nonpaged?
   712 				sectionDelta = dirDelta;			// unknown - assume nonpaged?
   700 			newValue = expAddr + sectionDelta + adjustment;
   713 			newValue = expAddr + sectionDelta + adjustment;
   701 			}
   714 			}
   702 
   715 
   703 		__LDRTRACE(MyPrintf("svElfDerivedFixupImportAddresses: import[%d] (%08x:%08x) is export[%d] %08x+%08x => %08x",
   716 		__LDRTRACE(svPrintf("svElfDerivedFixupImportAddresses: import[%d] (%08x:%08x) is export[%d] %08x+%08x => %08x",
   704 							iol - info.iImportOffsetList, codePtr, importInfo, ordinal, expAddr, adjustment, newValue));
   717 							iol - info.iImportOffsetList, codePtr, importInfo, ordinal, expAddr, adjustment, newValue));
   705 
   718 
   706 		// In non-paged code, we can simply replace the ordinals in the IAT with the
   719 		// In non-paged code, we can simply replace the ordinals in the IAT with the
   707 		// object addresses to which they refer once and for all. However, in a code
   720 		// object addresses to which they refer once and for all. However, in a code
   708 		// paging system, the IAT may be thrown away and later reloaded from the code
   721 		// paging system, the IAT may be thrown away and later reloaded from the code
  3246 	__IF_DEBUG(Printf("E32Image::FixupDlls OK"));
  3259 	__IF_DEBUG(Printf("E32Image::FixupDlls OK"));
  3247 	return KErrNone;
  3260 	return KErrNone;
  3248 	}
  3261 	}
  3249 
  3262 
  3250 
  3263 
  3251 /**
       
  3252 This function is defined because RArray does not natively support
       
  3253 sorting 64-bit integers.
       
  3254 
       
  3255 It is used by FixupDlls to order the import fixup locations in the image
       
  3256 so they can be organized by page.
       
  3257 
       
  3258 @param	aLeft			64-bit unsigned integer to compare against aRight.
       
  3259 @param	aRight			64-bit unsigned integer to compare against aLeft.
       
  3260 @return					-1 if aLeft < aRight; 0 if aLeft == aRight; and
       
  3261 						+1 if aLeft > aRight.  This conforms to the behavior
       
  3262 						which is expected from a function used by TLinearOrder.
       
  3263 */
       
  3264 static TInt Uint64LinearOrderFunc(const TUint64& aLeft, const TUint64& aRight)
       
  3265 	{
       
  3266 	if (aLeft < aRight)
       
  3267 		return -1;
       
  3268 	else if (aLeft > aRight)
       
  3269 		return 1;
       
  3270 	else
       
  3271 		return 0;
       
  3272 	}
       
  3273 
       
  3274 
       
  3275 TUint64* E32Image::ExpandFixups(TInt aNumFixups)
  3264 TUint64* E32Image::ExpandFixups(TInt aNumFixups)
  3276 	{
  3265 	{
  3277 	__IF_DEBUG(Printf("ExpandFixups,%d+%d", iFixupCount,aNumFixups));
  3266 	__IF_DEBUG(Printf("ExpandFixups,%d+%d", iFixupCount,aNumFixups));
  3278 	TInt newCount = iFixupCount+aNumFixups;
  3267 	TInt newCount = iFixupCount+aNumFixups;
  3279 	TUint64* fixups = (TUint64*) User::ReAlloc(iFixups, sizeof(TUint64) * newCount);
  3268 	TUint64* fixups = (TUint64*) User::ReAlloc(iFixups, sizeof(TUint64) * newCount);
  3313 		}
  3302 		}
  3314 #endif	// DEBUG
  3303 #endif	// DEBUG
  3315 
  3304 
  3316 	// sort the array in address order, to organize by page
  3305 	// sort the array in address order, to organize by page
  3317 	RArray<TUint64> fixup64ToSort(sizeof(TUint64), iFixups, iFixupCount);
  3306 	RArray<TUint64> fixup64ToSort(sizeof(TUint64), iFixups, iFixupCount);
  3318 	// SortUnsigned doesn't work on TUint64
  3307 
  3319 	fixup64ToSort.Sort(TLinearOrder<TUint64>(Uint64LinearOrderFunc));
  3308 	// address is in high word of entry, offset 4
       
  3309 	fixup64ToSort.SetKeyOffset(4);
       
  3310 	fixup64ToSort.SortUnsigned();
  3320 
  3311 
  3321 	// now have <address | new-value> pairs, organize into pages.
  3312 	// now have <address | new-value> pairs, organize into pages.
  3322 	// Each page is stored as fXXX YYYY ZZZZ where YYYY ZZZZ is written
  3313 	// Each page is stored as fXXX YYYY ZZZZ where YYYY ZZZZ is written
  3323 	// to the word at offset XXX.  (See PREQ1110 Design Sketch v1.0 S3.1.1.2.3.2.)
  3314 	// to the word at offset XXX.  (See PREQ1110 Design Sketch v1.0 S3.1.1.2.3.2.)
  3324 
  3315