--- a/userlibandfileserver/fileserver/sfile/sf_lepoc.cpp Wed Jun 09 11:10:19 2010 +0300
+++ b/userlibandfileserver/fileserver/sfile/sf_lepoc.cpp Mon Jun 21 17:12:14 2010 +0300
@@ -287,9 +287,22 @@
}
}
-// A version that will work in user or supervisor mode
-void MyPrintf(const char* aFmt, ...)
+/**
+It would be nice to be able to print debug information from the various functions
+supervisor-mode functions below. Unfortunately, we can't call RDebug::Printf() or
+any of its relatives in supervisor mode, and of course we can't call the equivalent
+kernel functions even when we're already in supervisor mode, because the entry
+points aren't visible.
+
+So this function just wraps and guards the call to RDebug, so we won't call it
+in SVC mode. The outcome is that trace messages are only generated if using the
+flexible memory model, where the code doesn't actually run in SVC mode anyway.
+*/
+void svPrintf(const char* aFmt, ...)
{
+ if (gExecutesInSupervisorMode)
+ return;
+
VA_LIST list;
VA_START(list, aFmt);
TPtrC8 fmt((const TText8*)aFmt);
@@ -379,15 +392,15 @@
E32Image& exporter = *(E32Image*)aPtr;
// Dump everything potentially useful that we know about the exporter ...
- __LDRTRACE(MyPrintf("RelocateExports: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
+ __LDRTRACE(svPrintf("RelocateExports: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
exporter.iUseCodePaging, exporter.iRomImageHeader, exporter.iHeader));
- __LDRTRACE(MyPrintf(" iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
+ __LDRTRACE(svPrintf(" iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
exporter.iCodeSize, exporter.iTextSize))
- __LDRTRACE(MyPrintf(" iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
+ __LDRTRACE(svPrintf(" iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
exporter.iDataLoadAddress, exporter.iDataRunAddress,
exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
- __LDRTRACE(MyPrintf(" iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
+ __LDRTRACE(svPrintf(" iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
// It turns out that very little of the exporter info is useful! For
@@ -429,7 +442,7 @@
newValue = relocAddr; // unknown - just leave it alone
*destExport++ = newValue;
- __LDRTRACE(MyPrintf("RelocateExports: export %d %08x => %08x %c",
+ __LDRTRACE(svPrintf("RelocateExports: export %d %08x => %08x %c",
exporter.iExportDirCount-i, relocAddr, newValue,
(relocAddr >= codeStart && relocAddr < codeFinish) ? 'C' :
(relocAddr >= dataStart && relocAddr < dataFinish) ? 'D' : 'X'));
@@ -471,39 +484,39 @@
E32Image& exporter = *info.iExporter;
#ifdef _DEBUG
- __LDRTRACE(MyPrintf(">svFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x",
+ __LDRTRACE(svPrintf(">svFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x",
info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter));
// Dump everything potentially useful that we know about the exporter ...
- __LDRTRACE(MyPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
+ __LDRTRACE(svPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
&exporter.iFileName, exporter.iUseCodePaging,
exporter.iRomImageHeader, exporter.iHeader));
- __LDRTRACE(MyPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
+ __LDRTRACE(svPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
exporter.iCodeSize, exporter.iTextSize))
- __LDRTRACE(MyPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
+ __LDRTRACE(svPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
exporter.iDataLoadAddress, exporter.iDataRunAddress,
exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
- __LDRTRACE(MyPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
+ __LDRTRACE(svPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
if (exporter.iRomImageHeader)
{
const TRomImageHeader& rh = *exporter.iRomImageHeader;
- __LDRTRACE(MyPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x",
+ __LDRTRACE(svPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x",
rh.iCodeAddress, rh.iCodeSize, rh.iTextSize));
- __LDRTRACE(MyPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x",
+ __LDRTRACE(svPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x",
rh.iDataAddress, rh.iDataSize, rh.iBssSize));
- __LDRTRACE(MyPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x",
+ __LDRTRACE(svPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x",
rh.iDataBssLinearBase, rh.iTotalDataSize));
}
if (exporter.iHeader)
{
const E32ImageHeader& ih = *exporter.iHeader;
- __LDRTRACE(MyPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x",
+ __LDRTRACE(svPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x",
ih.iCodeBase, ih.iCodeSize, ih.iTextSize));
- __LDRTRACE(MyPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x",
+ __LDRTRACE(svPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x",
ih.iDataBase, ih.iDataSize, ih.iBssSize));
}
#endif // _DEBUG
@@ -538,7 +551,7 @@
newValue = expAddr;
}
- __LDRTRACE(MyPrintf("svFixupImportAddresses: import[%d]@%08x is export[%d] == %08x",
+ __LDRTRACE(svPrintf("svFixupImportAddresses: import[%d]@%08x is export[%d] == %08x",
iat - info.iIat, iat, ordinal, newValue));
// In non-paged code, we can simply replace the ordinals in the IAT with the
@@ -573,39 +586,39 @@
E32Image& exporter = *info.iExporter;
#ifdef _DEBUG
- __LDRTRACE(MyPrintf(">svElfDerivedFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x",
+ __LDRTRACE(svPrintf(">svElfDerivedFixupImportAddresses %d imports, code@%08x, fixup@%08x exporter@%08x",
info.iNumImports, info.iCodeLoadAddress, info.iFixup64, info.iExporter));
// Dump everything potentially useful that we know about the exporter ...
- __LDRTRACE(MyPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
+ __LDRTRACE(svPrintf("%S: paged? %d, iRomImageHeader@%08x, iHeader@%08x",
&exporter.iFileName, exporter.iUseCodePaging,
exporter.iRomImageHeader, exporter.iHeader));
- __LDRTRACE(MyPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
+ __LDRTRACE(svPrintf("iCodeLoadAddress %08x, iCodeRunAddress %08x, iCodeSize %x iTextSize %x",
exporter.iCodeLoadAddress, exporter.iCodeRunAddress,
exporter.iCodeSize, exporter.iTextSize))
- __LDRTRACE(MyPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
+ __LDRTRACE(svPrintf("iDataLoadAddress %08x, iDataRunAddress %08x, iDataSize %x iBssSize %x iTotalDataSize %x",
exporter.iDataLoadAddress, exporter.iDataRunAddress,
exporter.iDataSize, exporter.iBssSize, exporter.iTotalDataSize));
- __LDRTRACE(MyPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
+ __LDRTRACE(svPrintf("iCodeDelta, %x iDataDelta %x, iExportDirEntryDelta %x",
exporter.iCodeDelta, exporter.iDataDelta, exporter.iExportDirEntryDelta));
if (exporter.iRomImageHeader)
{
const TRomImageHeader& rh = *exporter.iRomImageHeader;
- __LDRTRACE(MyPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x",
+ __LDRTRACE(svPrintf("ROM: iCodeAddress %08x, iCodeSize %x, iTextSize %x",
rh.iCodeAddress, rh.iCodeSize, rh.iTextSize));
- __LDRTRACE(MyPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x",
+ __LDRTRACE(svPrintf("ROM: iDataAddress %08x, iDataSize %x, iBssSize %x",
rh.iDataAddress, rh.iDataSize, rh.iBssSize));
- __LDRTRACE(MyPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x",
+ __LDRTRACE(svPrintf("ROM: iDataBssLinearBase %08x, iTotalDataSize %x",
rh.iDataBssLinearBase, rh.iTotalDataSize));
}
if (exporter.iHeader)
{
const E32ImageHeader& ih = *exporter.iHeader;
- __LDRTRACE(MyPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x",
+ __LDRTRACE(svPrintf("HEAD: iCodeBase %08x, iCodeSize %x, iTextSize %x",
ih.iCodeBase, ih.iCodeSize, ih.iTextSize));
- __LDRTRACE(MyPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x",
+ __LDRTRACE(svPrintf("HEAD: iDataBase %08x, iDataSize %x, iBssSize %x",
ih.iDataBase, ih.iDataSize, ih.iBssSize));
}
#endif // _DEBUG
@@ -700,7 +713,7 @@
newValue = expAddr + sectionDelta + adjustment;
}
- __LDRTRACE(MyPrintf("svElfDerivedFixupImportAddresses: import[%d] (%08x:%08x) is export[%d] %08x+%08x => %08x",
+ __LDRTRACE(svPrintf("svElfDerivedFixupImportAddresses: import[%d] (%08x:%08x) is export[%d] %08x+%08x => %08x",
iol - info.iImportOffsetList, codePtr, importInfo, ordinal, expAddr, adjustment, newValue));
// In non-paged code, we can simply replace the ordinals in the IAT with the
@@ -3248,30 +3261,6 @@
}
-/**
-This function is defined because RArray does not natively support
-sorting 64-bit integers.
-
-It is used by FixupDlls to order the import fixup locations in the image
-so they can be organized by page.
-
-@param aLeft 64-bit unsigned integer to compare against aRight.
-@param aRight 64-bit unsigned integer to compare against aLeft.
-@return -1 if aLeft < aRight; 0 if aLeft == aRight; and
- +1 if aLeft > aRight. This conforms to the behavior
- which is expected from a function used by TLinearOrder.
-*/
-static TInt Uint64LinearOrderFunc(const TUint64& aLeft, const TUint64& aRight)
- {
- if (aLeft < aRight)
- return -1;
- else if (aLeft > aRight)
- return 1;
- else
- return 0;
- }
-
-
TUint64* E32Image::ExpandFixups(TInt aNumFixups)
{
__IF_DEBUG(Printf("ExpandFixups,%d+%d", iFixupCount,aNumFixups));
@@ -3315,8 +3304,10 @@
// sort the array in address order, to organize by page
RArray<TUint64> fixup64ToSort(sizeof(TUint64), iFixups, iFixupCount);
- // SortUnsigned doesn't work on TUint64
- fixup64ToSort.Sort(TLinearOrder<TUint64>(Uint64LinearOrderFunc));
+
+ // address is in high word of entry, offset 4
+ fixup64ToSort.SetKeyOffset(4);
+ fixup64ToSort.SortUnsigned();
// now have <address | new-value> pairs, organize into pages.
// Each page is stored as fXXX YYYY ZZZZ where YYYY ZZZZ is written