Backed out changeset 30e1cfee3545

This commit is contained in:
Taras Glek 2011-01-07 12:01:48 -08:00
parent a603e5efc3
commit 100a2c8682
2 changed files with 12 additions and 92 deletions

View File

@ -61,23 +61,6 @@
#include <sys/mman.h>
#endif
#ifdef XP_WIN
#include <windows.h>
#include "private/pprio.h" // To get PR_ImportFile
#define MOZ_WIN_MEM_TRY_BEGIN __try {
#define MOZ_WIN_MEM_TRY_CATCH(cmd) } \
__except(GetExceptionCode()==EXCEPTION_IN_PAGE_ERROR ? \
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) \
{ \
NS_WARNING("EXCEPTION_IN_PAGE_ERROR in " __FUNCTION__); \
cmd; \
}
#else
#define MOZ_WIN_MEM_TRY_BEGIN {
#define MOZ_WIN_MEM_TRY_CATCH(cmd) }
#endif
#ifdef DEBUG_brendan
# define METERING
# define DEBUG_MUX
@ -585,9 +568,7 @@ nsFastLoadFileReader::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aBytesRead)
return NS_BASE_STREAM_CLOSED;
PRUint32 count = PR_MIN(mFileLen - mFilePos, aCount);
MOZ_WIN_MEM_TRY_BEGIN
memcpy(aBuffer, mFileData+mFilePos, count);
MOZ_WIN_MEM_TRY_CATCH(return NS_ERROR_FAILURE)
*aBytesRead = count;
mFilePos += count;
if (entry) {
@ -617,11 +598,9 @@ nsFastLoadFileReader::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
PRUint32 count = PR_MIN(mFileLen - mFilePos, aCount);
MOZ_WIN_MEM_TRY_BEGIN
// Errors returned from the writer get ignored.
aWriter(this, aClosure, (char*)(mFileData + mFilePos), 0,
count, aResult);
MOZ_WIN_MEM_TRY_CATCH(return NS_ERROR_FAILURE)
mFilePos += count;
if (entry) {
NS_ASSERTION(entry->mBytesLeft >= *aResult,
@ -643,38 +622,10 @@ nsFastLoadFileReader::ComputeChecksum(PRUint32 *aResult)
PRUint32 checksum = 0;
// Skip first 2 fields.
PRUint32 pos = offsetof(nsFastLoadHeader, mVersion);
#ifdef XP_WIN
if (pos != PR_Seek(mFD, pos, PR_SEEK_SET))
return NS_ERROR_FAILURE;
PRUint32 len = 0;
PRUint32 rem = 0;
char buf[64 * 1024];
PRInt32 bytesRead;
while ((bytesRead = PR_Read(mFD, buf + rem, sizeof(buf) - rem)) && bytesRead > 0) {
len += rem + bytesRead;
rem = NS_AccumulateFastLoadChecksum(&checksum,
reinterpret_cast<PRUint8*>(buf),
len,
PR_FALSE);
if (rem)
memmove(buf, buf + len - rem, rem);
}
if (len < 0)
return NS_ERROR_FAILURE;
if (rem) {
NS_AccumulateFastLoadChecksum(&checksum,
reinterpret_cast<PRUint8*>(buf),
rem,
PR_TRUE);
}
#else
NS_AccumulateFastLoadChecksum(&checksum,
mFileData + pos,
mFileLen - pos,
PR_TRUE);
#endif
*aResult = checksum;
return NS_OK;
}
@ -912,26 +863,14 @@ nsresult
nsFastLoadFileReader::Open()
{
nsresult rv;
PRFileDesc *fd; // OS file-descriptor
{
#ifdef XP_WIN
nsAutoString name;
rv = mFile->GetPath(name);
NS_ENSURE_SUCCESS(rv, rv);
HANDLE winFD = ::CreateFileW(name.get(), GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (winFD == INVALID_HANDLE_VALUE)
return NS_ERROR_FAILURE;
fd = PR_ImportFile((PROsfd) winFD);
#else
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(mFile, &rv);
if (NS_FAILED(rv))
return rv;
PRFileDesc *fd; // OS file-descriptor
rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
if (NS_FAILED(rv))
return rv;
#endif
}
PRInt64 size = PR_Available64(fd);
if (size >= PR_INT32_MAX) {
PR_Close(fd);
@ -951,12 +890,8 @@ nsFastLoadFileReader::Open()
}
mFileData = (PRUint8*) PR_MemMap(mFileMap, 0, mFileLen);
#ifdef XP_WIN
mFD = fd;
#else
// At this point the non-mmap file descriptor is no longer needed on non-windows
// At this point the non-mmap file descriptor is no longer needed
PR_Close(fd);
#endif
if (!mFileData)
return NS_ERROR_FAILURE;
@ -965,7 +900,6 @@ nsFastLoadFileReader::Open()
madvise((char *)mFileData, mFileLen, MADV_WILLNEED);
#endif
MOZ_WIN_MEM_TRY_BEGIN
rv = ReadHeader(&mHeader);
if (NS_FAILED(rv))
return rv;
@ -974,22 +908,19 @@ MOZ_WIN_MEM_TRY_BEGIN
rv = ComputeChecksum(&checksum);
if (NS_FAILED(rv))
return rv;
if (checksum != mHeader.mChecksum)
return NS_ERROR_FAILURE;
if (mHeader.mVersion != MFL_FILE_VERSION ||
mHeader.mFooterOffset == 0 ||
mHeader.mFooterOffset == 0 ||
memcmp(mHeader.mMagic, magic, MFL_FILE_MAGIC_SIZE))
return NS_ERROR_UNEXPECTED;
SeekTo(mHeader.mFooterOffset);
rv = ReadFooter(&mFooter);
MOZ_WIN_MEM_TRY_CATCH(return NS_ERROR_FAILURE)
if (NS_FAILED(rv))
if (NS_FAILED(rv))
return rv;
SeekTo(sizeof(nsFastLoadHeader));
@ -1017,14 +948,10 @@ nsFastLoadFileReader::Close()
PR_CloseFileMap(mFileMap);
mFileMap = nsnull;
}
#ifdef XP_WIN
mFD = nsnull;
#endif
mFileLen = 0;
mFilePos = 0;
if (!mFooter.mObjectMap)
return NS_OK;
@ -1924,7 +1851,7 @@ nsresult
nsFastLoadFileWriter::Open()
{
nsresult rv;
if (!mSeekableOutput)
return NS_ERROR_FAILURE;
@ -2009,7 +1936,7 @@ nsFastLoadFileWriter::Close()
rv = mFileIO->GetInputStream(getter_AddRefs(input));
if (NS_FAILED(rv))
return rv;
// Seek the input stream to right after checksum/magic.
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(input);
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET,
@ -2032,7 +1959,7 @@ nsFastLoadFileWriter::Close()
len,
PR_FALSE);
if (rem)
memmove(buf, buf + len - rem, rem);
memcpy(buf, buf + len - rem, rem);
}
if (NS_FAILED(rv))
return rv;
@ -2231,7 +2158,7 @@ nsFastLoadFileWriter::WriteCompoundObject(nsISupports* aObject,
{
nsresult rv;
nsCOMPtr<nsISupports> rootObject(do_QueryInterface(aObject));
// We could assert that |rootObject != aObject|, but that would prevent
// callers who don't know whether they're dealing with the primary
// nsISupports pointer (e.g., they don't know which implementation of

View File

@ -56,7 +56,6 @@
#include "nsIFastLoadService.h"
#include "nsISeekableStream.h"
#include "nsISupportsArray.h"
#include "mozilla/FileUtils.h"
/**
* FastLoad file Object ID (OID) is an identifier for multiply and cyclicly
@ -401,12 +400,6 @@ class nsFastLoadFileReader
PRUint32 mFilePos; // current position within file
PRFileMap *mFileMap;// nspr datastructure for mmap
PRUint8 *mFileData; // pointer to mmaped file
#ifdef XP_WIN
// Using a descriptor avoids having to check for EXCEPTION_IN_PAGE_ERROR
// in ComputeChecksum. Combined with FILE_FLAG_SEQUENTIAL_SCAN
// this speeds up cold IO via kernel readahead.
mozilla::AutoFDClose mFD;
#endif
};
NS_COM nsresult