diff options
author | Dan Bornstein <danfuzz@android.com> | 2011-05-25 13:15:47 -0700 |
---|---|---|
committer | Dan Bornstein <danfuzz@android.com> | 2011-05-25 16:23:03 -0700 |
commit | 9fdbd91288a237eb58e18e4de9c729c3c268c318 (patch) | |
tree | 3dd76752feac32b74906a8b59f0cc974e3db168d /vm/RawDexFile.cpp | |
parent | 43e796a261bec308b44e9e5a627820845812202c (diff) | |
download | android_dalvik-9fdbd91288a237eb58e18e4de9c729c3c268c318.tar.gz android_dalvik-9fdbd91288a237eb58e18e4de9c729c3c268c318.tar.bz2 android_dalvik-9fdbd91288a237eb58e18e4de9c729c3c268c318.zip |
Update dex file magic number.
Even though the dex format was technically resilient with respect to
the addition of new opcodes, consensus is that the errors one sees
when trying to use a new dex file on an old build were sufficiently
inscrutable that it was worth the effort to update the version number
embedded in the dex format magic.
This change updates dx to produce the new version number when extended
opcodes are enabled (which is the default, but may be overridden by
targeting an older API level).
This also updates the vm to recognize and accept both the new current
version number as well as the immediately previous one. Note: It won't
reject an old-version file if it happens to use the new opcodes; that
would just be a gratuitous and pointless failure.
Bug: 4364986
Change-Id: If8febbb0b91c1719df4247bf69c511251362d91f
Diffstat (limited to 'vm/RawDexFile.cpp')
-rw-r--r-- | vm/RawDexFile.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/vm/RawDexFile.cpp b/vm/RawDexFile.cpp index 2c7348198..bec667574 100644 --- a/vm/RawDexFile.cpp +++ b/vm/RawDexFile.cpp @@ -33,7 +33,7 @@ static int copyFileToFile(int destFd, int srcFd, size_t size) { if (lseek(srcFd, 0, SEEK_SET) != 0) { - LOGE("lseek failure (errno %d)\n", errno); + LOGE("lseek failure: %s", strerror(errno)); return -1; } @@ -49,7 +49,7 @@ static int getModTimeAndSize(int fd, u4* modTime, size_t* size) int result = fstat(fd, &buf); if (result < 0) { - LOGE("Unable to determing mod time (errno %d)\n", errno); + LOGE("Unable to determine mod time: %s", strerror(errno)); return -1; } @@ -76,20 +76,16 @@ static int verifyMagicAndGetAdler32(int fd, u4 *adler32) ssize_t amt = read(fd, headerStart, sizeof(headerStart)); if (amt < 0) { - LOGE("Unable to read header (errno %d)\n", errno); + LOGE("Unable to read header: %s", strerror(errno)); return -1; } if (amt != sizeof(headerStart)) { - LOGE("Unable to read full header (only got %d bytes)\n", (int) amt); + LOGE("Unable to read full header (only got %d bytes)", (int) amt); return -1; } - if (memcmp(headerStart, DEX_MAGIC DEX_MAGIC_VERS, 8) != 0) { - LOGE("Unexpected dex magic (0x%02x%02x%02x%02x%02x%02x%02x%02x)\n", - headerStart[0], headerStart[1], headerStart[2], - headerStart[3], headerStart[4], headerStart[5], - headerStart[6], headerStart[7]); + if (!dexHasValidMagic((DexHeader*) (void*) headerStart)) { return -1; } @@ -136,12 +132,12 @@ int dvmRawDexFileOpen(const char* fileName, const char* odexOutputName, dvmSetCloseOnExec(dexFd); if (verifyMagicAndGetAdler32(dexFd, &adler32) < 0) { - LOGE("Error with header for %s\n", fileName); + LOGE("Error with header for %s", fileName); goto bail; } if (getModTimeAndSize(dexFd, &modTime, &fileSize) < 0) { - LOGE("Error with stat for %s\n", fileName); + LOGE("Error with stat for %s", fileName); goto bail; } @@ -159,14 +155,14 @@ int dvmRawDexFileOpen(const char* fileName, const char* odexOutputName, cachedName = strdup(odexOutputName); } - LOGV("dvmRawDexFileOpen: Checking cache for %s (%s)\n", + LOGV("dvmRawDexFileOpen: Checking cache for %s (%s)", fileName, cachedName); optFd = dvmOpenCachedDexFile(fileName, cachedName, modTime, adler32, isBootstrap, &newFile, /*createIfMissing=*/true); if (optFd < 0) { - LOGI("Unable to open or create cache for %s (%s)\n", + LOGI("Unable to open or create cache for %s (%s)", fileName, cachedName); goto bail; } @@ -198,12 +194,12 @@ int dvmRawDexFileOpen(const char* fileName, const char* odexOutputName, } if (!result) { - LOGE("Unable to extract+optimize DEX from '%s'\n", fileName); + LOGE("Unable to extract+optimize DEX from '%s'", fileName); goto bail; } endWhen = dvmGetRelativeTimeUsec(); - LOGD("DEX prep '%s': copy in %dms, rewrite %dms\n", + LOGD("DEX prep '%s': copy in %dms, rewrite %dms", fileName, (int) (copyWhen - startWhen) / 1000, (int) (endWhen - copyWhen) / 1000); @@ -228,7 +224,7 @@ int dvmRawDexFileOpen(const char* fileName, const char* odexOutputName, locked = false; } - LOGV("Successfully opened '%s'\n", fileName); + LOGV("Successfully opened '%s'", fileName); *ppRawDexFile = (RawDexFile*) calloc(1, sizeof(RawDexFile)); (*ppRawDexFile)->cacheFileName = cachedName; @@ -255,7 +251,7 @@ int dvmRawDexFileOpenArray(u1* pBytes, u4 length, RawDexFile** ppRawDexFile) DvmDex* pDvmDex = NULL; if (!dvmPrepareDexInMemory(pBytes, length, &pDvmDex)) { - LOGD("Unable to open raw DEX from array\n"); + LOGD("Unable to open raw DEX from array"); return -1; } assert(pDvmDex != NULL); |