summaryrefslogtreecommitdiffstats
path: root/libdex
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2011-05-05 00:01:58 -0700
committerBrian Carlstrom <bdc@google.com>2011-05-05 14:49:03 -0700
commitbbf31b58c50fb892423b7fef0d8c1093bd0c1a6c (patch)
treeda5cb21f3c53e2b67ef6046e722a15ac4db8da9e /libdex
parent00ceb87d1c57ccee59966be4deef1292a049285c (diff)
parenta17fcc1899d097ee5e6722740d5a60ad3f0313e5 (diff)
downloadandroid_dalvik-bbf31b58c50fb892423b7fef0d8c1093bd0c1a6c.tar.gz
android_dalvik-bbf31b58c50fb892423b7fef0d8c1093bd0c1a6c.tar.bz2
android_dalvik-bbf31b58c50fb892423b7fef0d8c1093bd0c1a6c.zip
Merge remote branch 'goog/dalvik-dev' into dalvik-dev-to-master
Change-Id: I99c4289bd34f63b0b970b6ed0fa992b44e805393
Diffstat (limited to 'libdex')
-rw-r--r--libdex/Android.mk36
-rw-r--r--libdex/CmdUtils.cpp (renamed from libdex/CmdUtils.c)4
-rw-r--r--libdex/CmdUtils.h4
-rw-r--r--libdex/DexCatch.cpp (renamed from libdex/DexCatch.c)0
-rw-r--r--libdex/DexCatch.h8
-rw-r--r--libdex/DexClass.cpp (renamed from libdex/DexClass.c)4
-rw-r--r--libdex/DexClass.h16
-rw-r--r--libdex/DexDataMap.cpp (renamed from libdex/DexDataMap.c)2
-rw-r--r--libdex/DexDataMap.h4
-rw-r--r--libdex/DexDebugInfo.cpp (renamed from libdex/DexDebugInfo.c)101
-rw-r--r--libdex/DexDebugInfo.h6
-rw-r--r--libdex/DexFile.cpp (renamed from libdex/DexFile.c)0
-rw-r--r--libdex/DexFile.h118
-rw-r--r--libdex/DexInlines.cpp (renamed from libdex/DexInlines.c)0
-rw-r--r--libdex/DexOpcodes.cpp (renamed from libdex/DexOpcodes.c)0
-rw-r--r--libdex/DexOpcodes.h4
-rw-r--r--libdex/DexOptData.cpp (renamed from libdex/DexOptData.c)2
-rw-r--r--libdex/DexProto.cpp (renamed from libdex/DexProto.c)2
-rw-r--r--libdex/DexProto.h14
-rw-r--r--libdex/DexSwapVerify.cpp (renamed from libdex/DexSwapVerify.c)85
-rw-r--r--libdex/DexUtf.cpp (renamed from libdex/DexUtf.c)0
-rw-r--r--libdex/InstrUtils.cpp (renamed from libdex/InstrUtils.c)0
-rw-r--r--libdex/InstrUtils.h16
-rw-r--r--libdex/Leb128.cpp (renamed from libdex/Leb128.c)0
-rw-r--r--libdex/OptInvocation.cpp (renamed from libdex/OptInvocation.c)0
-rw-r--r--libdex/OptInvocation.h8
-rw-r--r--libdex/SysUtil.cpp (renamed from libdex/SysUtil.c)0
-rw-r--r--libdex/SysUtil.h4
-rw-r--r--libdex/ZipArchive.cpp (renamed from libdex/ZipArchive.c)52
-rw-r--r--libdex/ZipArchive.h10
-rw-r--r--libdex/sha1.cpp (renamed from libdex/sha1.c)4
-rw-r--r--libdex/sha1.h6
32 files changed, 262 insertions, 248 deletions
diff --git a/libdex/Android.mk b/libdex/Android.mk
index 26f84d657..bb8d03b96 100644
--- a/libdex/Android.mk
+++ b/libdex/Android.mk
@@ -15,24 +15,24 @@
LOCAL_PATH:= $(call my-dir)
dex_src_files := \
- CmdUtils.c \
- DexCatch.c \
- DexClass.c \
- DexDataMap.c \
- DexDebugInfo.c \
- DexFile.c \
- DexInlines.c \
- DexOptData.c \
- DexOpcodes.c \
- DexProto.c \
- DexSwapVerify.c \
- DexUtf.c \
- InstrUtils.c \
- Leb128.c \
- OptInvocation.c \
- sha1.c \
- SysUtil.c \
- ZipArchive.c
+ CmdUtils.cpp \
+ DexCatch.cpp \
+ DexClass.cpp \
+ DexDataMap.cpp \
+ DexDebugInfo.cpp \
+ DexFile.cpp \
+ DexInlines.cpp \
+ DexOptData.cpp \
+ DexOpcodes.cpp \
+ DexProto.cpp \
+ DexSwapVerify.cpp \
+ DexUtf.cpp \
+ InstrUtils.cpp \
+ Leb128.cpp \
+ OptInvocation.cpp \
+ sha1.cpp \
+ SysUtil.cpp \
+ ZipArchive.cpp
dex_include_files := \
dalvik \
diff --git a/libdex/CmdUtils.c b/libdex/CmdUtils.cpp
index ecb53e86d..ff737a362 100644
--- a/libdex/CmdUtils.c
+++ b/libdex/CmdUtils.cpp
@@ -197,7 +197,7 @@ UnzipToFileResult dexOpenAndMap(const char* fileName, const char* tempFileName,
*/
sysChangeMapAccess(pMap->addr, pMap->length, true, pMap);
- if (dexSwapAndVerifyIfNecessary(pMap->addr, pMap->length)) {
+ if (dexSwapAndVerifyIfNecessary((u1*) pMap->addr, pMap->length)) {
fprintf(stderr, "ERROR: Failed structural verification of '%s'\n",
fileName);
goto bail;
@@ -213,7 +213,7 @@ UnzipToFileResult dexOpenAndMap(const char* fileName, const char* tempFileName,
/*
* Success! Close the file and return with the start/length in pMap.
*/
- result = 0;
+ result = kUTFRSuccess;
bail:
if (fd >= 0)
diff --git a/libdex/CmdUtils.h b/libdex/CmdUtils.h
index 7a8528710..62ce73a25 100644
--- a/libdex/CmdUtils.h
+++ b/libdex/CmdUtils.h
@@ -32,7 +32,7 @@
#define _LIBDEX_CMDUTILS
/* encode the result of unzipping to a file */
-typedef enum UnzipToFileResult {
+enum UnzipToFileResult {
kUTFRSuccess = 0,
kUTFRGenericFailure,
kUTFRBadArgs,
@@ -40,7 +40,7 @@ typedef enum UnzipToFileResult {
kUTFRNoClassesDex,
kUTFROutputFileProblem,
kUTFRBadZip,
-} UnzipToFileResult;
+};
/*
* Map the specified DEX file read-only (possibly after expanding it into a
diff --git a/libdex/DexCatch.c b/libdex/DexCatch.cpp
index ed97e87d9..ed97e87d9 100644
--- a/libdex/DexCatch.c
+++ b/libdex/DexCatch.cpp
diff --git a/libdex/DexCatch.h b/libdex/DexCatch.h
index c0eec7c57..19ea54129 100644
--- a/libdex/DexCatch.h
+++ b/libdex/DexCatch.h
@@ -27,10 +27,10 @@
/*
* Catch handler entry, used while iterating over catch_handler_items.
*/
-typedef struct DexCatchHandler {
+struct DexCatchHandler {
u4 typeIdx; /* type index of the caught exception type */
u4 address; /* handler address */
-} DexCatchHandler;
+};
/* Get the first handler offset for the given DexCode.
* It's not 0 because the handlers list is prefixed with its size
@@ -44,12 +44,12 @@ u4 dexGetHandlersSize(const DexCode* pCode);
* Iterator over catch handler data. This structure should be treated as
* opaque.
*/
-typedef struct DexCatchIterator {
+struct DexCatchIterator {
const u1* pEncodedData;
bool catchesAll;
u4 countRemaining;
DexCatchHandler handler;
-} DexCatchIterator;
+};
/* Initialize a DexCatchIterator to emptiness. This mostly exists to
* squelch innocuous warnings. */
diff --git a/libdex/DexClass.c b/libdex/DexClass.cpp
index 8a59e09fd..552229cc4 100644
--- a/libdex/DexClass.c
+++ b/libdex/DexClass.cpp
@@ -106,7 +106,7 @@ DexClassData* dexReadAndVerifyClassData(const u1** pData, const u1* pLimit) {
u4 lastIndex;
if (*pData == NULL) {
- DexClassData* result = malloc(sizeof(DexClassData));
+ DexClassData* result = (DexClassData*) malloc(sizeof(DexClassData));
memset(result, 0, sizeof(*result));
return result;
}
@@ -121,7 +121,7 @@ DexClassData* dexReadAndVerifyClassData(const u1** pData, const u1* pLimit) {
(header.directMethodsSize * sizeof(DexMethod)) +
(header.virtualMethodsSize * sizeof(DexMethod));
- DexClassData* result = malloc(resultSize);
+ DexClassData* result = (DexClassData*) malloc(resultSize);
u1* ptr = ((u1*) result) + sizeof(DexClassData);
bool okay = true;
u4 i;
diff --git a/libdex/DexClass.h b/libdex/DexClass.h
index 3d1e11be5..d2d92c00b 100644
--- a/libdex/DexClass.h
+++ b/libdex/DexClass.h
@@ -25,36 +25,36 @@
#include "Leb128.h"
/* expanded form of a class_data_item header */
-typedef struct DexClassDataHeader {
+struct DexClassDataHeader {
u4 staticFieldsSize;
u4 instanceFieldsSize;
u4 directMethodsSize;
u4 virtualMethodsSize;
-} DexClassDataHeader;
+};
/* expanded form of encoded_field */
-typedef struct DexField {
+struct DexField {
u4 fieldIdx; /* index to a field_id_item */
u4 accessFlags;
-} DexField;
+};
/* expanded form of encoded_method */
-typedef struct DexMethod {
+struct DexMethod {
u4 methodIdx; /* index to a method_id_item */
u4 accessFlags;
u4 codeOff; /* file offset to a code_item */
-} DexMethod;
+};
/* expanded form of class_data_item. Note: If a particular item is
* absent (e.g., no static fields), then the corresponding pointer
* is set to NULL. */
-typedef struct DexClassData {
+struct DexClassData {
DexClassDataHeader header;
DexField* staticFields;
DexField* instanceFields;
DexMethod* directMethods;
DexMethod* virtualMethods;
-} DexClassData;
+};
/* Read and verify the header of a class_data_item. This updates the
* given data pointer to point past the end of the read data and
diff --git a/libdex/DexDataMap.c b/libdex/DexDataMap.cpp
index a9d429e18..33135ed1c 100644
--- a/libdex/DexDataMap.c
+++ b/libdex/DexDataMap.cpp
@@ -41,7 +41,7 @@ DexDataMap* dexDataMapAlloc(u4 maxCount) {
return NULL;
}
- map = malloc(size);
+ map = (DexDataMap*) malloc(size);
if (map == NULL) {
return NULL;
diff --git a/libdex/DexDataMap.h b/libdex/DexDataMap.h
index fa556d5aa..359d3adae 100644
--- a/libdex/DexDataMap.h
+++ b/libdex/DexDataMap.h
@@ -23,12 +23,12 @@
#include "DexFile.h"
-typedef struct DexDataMap {
+struct DexDataMap {
u4 count; /* number of items currently in the map */
u4 max; /* maximum number of items that may be held */
u4* offsets; /* array of item offsets */
u2* types; /* corresponding array of item types */
-} DexDataMap;
+};
/*
* Allocate and initialize a DexDataMap. Returns NULL on failure.
diff --git a/libdex/DexDebugInfo.c b/libdex/DexDebugInfo.cpp
index 43765f7db..cbb58d478 100644
--- a/libdex/DexDebugInfo.c
+++ b/libdex/DexDebugInfo.cpp
@@ -109,13 +109,13 @@ static const char* readTypeIdx(const DexFile* pDexFile,
}
}
-typedef struct LocalInfo {
+struct LocalInfo {
const char *name;
const char *descriptor;
const char *signature;
u2 startAddress;
bool live;
-} LocalInfo;
+};
static void emitLocalCbIfLive(void *cnxt, int reg, u4 endAddress,
LocalInfo *localInReg, DexDebugNewLocalCb localCb)
@@ -129,34 +129,32 @@ static void emitLocalCbIfLive(void *cnxt, int reg, u4 endAddress,
}
}
-// TODO optimize localCb == NULL case
-void dexDecodeDebugInfo(
+static void invalidStream(const char* classDescriptor, const DexProto* proto) {
+ IF_LOGE() {
+ char* methodDescriptor = dexProtoCopyMethodDescriptor(proto);
+ LOGE("Invalid debug info stream. class %s; proto %s",
+ classDescriptor, methodDescriptor);
+ free(methodDescriptor);
+ }
+}
+
+static void dexDecodeDebugInfo0(
const DexFile* pDexFile,
const DexCode* pCode,
const char* classDescriptor,
u4 protoIdx,
u4 accessFlags,
DexDebugNewPositionCb posCb, DexDebugNewLocalCb localCb,
- void* cnxt)
+ void* cnxt,
+ const u1* stream,
+ LocalInfo* localInReg)
{
- const u1 *stream = dexGetDebugInfoStream(pDexFile, pCode);
- u4 line;
- u4 parametersSize;
- u4 address = 0;
- LocalInfo localInReg[pCode->registersSize];
- u4 insnsSize = pCode->insnsSize;
DexProto proto = { pDexFile, protoIdx };
-
- memset(localInReg, 0, sizeof(LocalInfo) * pCode->registersSize);
-
- if (stream == NULL) {
- goto end;
- }
-
- line = readUnsignedLeb128(&stream);
- parametersSize = readUnsignedLeb128(&stream);
-
+ u4 insnsSize = pCode->insnsSize;
+ u4 line = readUnsignedLeb128(&stream);
+ u4 parametersSize = readUnsignedLeb128(&stream);
u2 argReg = pCode->registersSize - pCode->insSize;
+ u4 address = 0;
if ((accessFlags & ACC_STATIC) == 0) {
/*
@@ -184,7 +182,8 @@ void dexDecodeDebugInfo(
int reg;
if ((argReg >= pCode->registersSize) || (descriptor == NULL)) {
- goto invalid_stream;
+ invalidStream(classDescriptor, &proto);
+ return;
}
name = readStringIdx(pDexFile, &stream);
@@ -215,7 +214,7 @@ void dexDecodeDebugInfo(
switch (opcode) {
case DBG_END_SEQUENCE:
- goto end;
+ return;
case DBG_ADVANCE_PC:
address += readUnsignedLeb128(&stream);
@@ -228,10 +227,13 @@ void dexDecodeDebugInfo(
case DBG_START_LOCAL:
case DBG_START_LOCAL_EXTENDED:
reg = readUnsignedLeb128(&stream);
- if (reg > pCode->registersSize) goto invalid_stream;
+ if (reg > pCode->registersSize) {
+ invalidStream(classDescriptor, &proto);
+ return;
+ }
// Emit what was previously there, if anything
- emitLocalCbIfLive (cnxt, reg, address,
+ emitLocalCbIfLive(cnxt, reg, address,
localInReg, localCb);
localInReg[reg].name = readStringIdx(pDexFile, &stream);
@@ -248,7 +250,10 @@ void dexDecodeDebugInfo(
case DBG_END_LOCAL:
reg = readUnsignedLeb128(&stream);
- if (reg > pCode->registersSize) goto invalid_stream;
+ if (reg > pCode->registersSize) {
+ invalidStream(classDescriptor, &proto);
+ return;
+ }
emitLocalCbIfLive (cnxt, reg, address, localInReg, localCb);
localInReg[reg].live = false;
@@ -256,11 +261,15 @@ void dexDecodeDebugInfo(
case DBG_RESTART_LOCAL:
reg = readUnsignedLeb128(&stream);
- if (reg > pCode->registersSize) goto invalid_stream;
+ if (reg > pCode->registersSize) {
+ invalidStream(classDescriptor, &proto);
+ return;
+ }
if (localInReg[reg].name == NULL
|| localInReg[reg].descriptor == NULL) {
- goto invalid_stream;
+ invalidStream(classDescriptor, &proto);
+ return;
}
/*
@@ -290,28 +299,36 @@ void dexDecodeDebugInfo(
if (done) {
// early exit
- goto end;
+ return;
}
}
break;
}
}
}
+}
-end:
- {
- int reg;
- for (reg = 0; reg < pCode->registersSize; reg++) {
- emitLocalCbIfLive (cnxt, reg, insnsSize, localInReg, localCb);
- }
+// TODO optimize localCb == NULL case
+void dexDecodeDebugInfo(
+ const DexFile* pDexFile,
+ const DexCode* pCode,
+ const char* classDescriptor,
+ u4 protoIdx,
+ u4 accessFlags,
+ DexDebugNewPositionCb posCb, DexDebugNewLocalCb localCb,
+ void* cnxt)
+{
+ const u1* stream = dexGetDebugInfoStream(pDexFile, pCode);
+ LocalInfo localInReg[pCode->registersSize];
+
+ memset(localInReg, 0, sizeof(LocalInfo) * pCode->registersSize);
+
+ if (stream != NULL) {
+ dexDecodeDebugInfo0(pDexFile, pCode, classDescriptor, protoIdx, accessFlags,
+ posCb, localCb, cnxt, stream, localInReg);
}
- return;
-invalid_stream:
- IF_LOGE() {
- char* methodDescriptor = dexProtoCopyMethodDescriptor(&proto);
- LOGE("Invalid debug info stream. class %s; proto %s",
- classDescriptor, methodDescriptor);
- free(methodDescriptor);
+ for (int reg = 0; reg < pCode->registersSize; reg++) {
+ emitLocalCbIfLive(cnxt, reg, pCode->insnsSize, localInReg, localCb);
}
}
diff --git a/libdex/DexDebugInfo.h b/libdex/DexDebugInfo.h
index f23e36568..9ab67f5d7 100644
--- a/libdex/DexDebugInfo.h
+++ b/libdex/DexDebugInfo.h
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#ifndef _LIBDEX_DEXDEBUGINFO
-#define _LIBDEX_DEXDEBUGINFO
-
/*
* Handling of method debug info in a .dex file.
*/
+#ifndef _LIBDEX_DEXDEBUGINFO
+#define _LIBDEX_DEXDEBUGINFO
+
#include "DexFile.h"
/*
diff --git a/libdex/DexFile.c b/libdex/DexFile.cpp
index 4f3bf5630..4f3bf5630 100644
--- a/libdex/DexFile.c
+++ b/libdex/DexFile.cpp
diff --git a/libdex/DexFile.h b/libdex/DexFile.h
index 45f9a9119..4a090e148 100644
--- a/libdex/DexFile.h
+++ b/libdex/DexFile.h
@@ -73,7 +73,7 @@ enum {
/*
* Enumeration of all the primitive types.
*/
-typedef enum PrimitiveType {
+enum PrimitiveType {
PRIM_NOT = 0, /* value is a reference type, not a primitive type */
PRIM_VOID = 1,
PRIM_BOOLEAN = 2,
@@ -84,7 +84,7 @@ typedef enum PrimitiveType {
PRIM_LONG = 7,
PRIM_FLOAT = 8,
PRIM_DOUBLE = 9,
-} PrimitiveType;
+};
/*
* access flags and masks; the "standard" ones are all <= 0x4000
@@ -206,7 +206,7 @@ enum {
/*
* Direct-mapped "header_item" struct.
*/
-typedef struct DexHeader {
+struct DexHeader {
u1 magic[8]; /* includes version number */
u4 checksum; /* adler32 checksum */
u1 signature[kSHA1DigestLen]; /* SHA-1 hash */
@@ -230,71 +230,71 @@ typedef struct DexHeader {
u4 classDefsOff;
u4 dataSize;
u4 dataOff;
-} DexHeader;
+};
/*
* Direct-mapped "map_item".
*/
-typedef struct DexMapItem {
- u2 type; /* type code (see kDexType* above) */
- u2 unused;
- u4 size; /* count of items of the indicated type */
- u4 offset; /* file offset to the start of data */
-} DexMapItem;
+struct DexMapItem {
+ u2 type; /* type code (see kDexType* above) */
+ u2 unused;
+ u4 size; /* count of items of the indicated type */
+ u4 offset; /* file offset to the start of data */
+};
/*
* Direct-mapped "map_list".
*/
-typedef struct DexMapList {
+struct DexMapList {
u4 size; /* #of entries in list */
DexMapItem list[1]; /* entries */
-} DexMapList;
+};
/*
* Direct-mapped "string_id_item".
*/
-typedef struct DexStringId {
- u4 stringDataOff; /* file offset to string_data_item */
-} DexStringId;
+struct DexStringId {
+ u4 stringDataOff; /* file offset to string_data_item */
+};
/*
* Direct-mapped "type_id_item".
*/
-typedef struct DexTypeId {
+struct DexTypeId {
u4 descriptorIdx; /* index into stringIds list for type descriptor */
-} DexTypeId;
+};
/*
* Direct-mapped "field_id_item".
*/
-typedef struct DexFieldId {
+struct DexFieldId {
u2 classIdx; /* index into typeIds list for defining class */
u2 typeIdx; /* index into typeIds for field type */
u4 nameIdx; /* index into stringIds for field name */
-} DexFieldId;
+};
/*
* Direct-mapped "method_id_item".
*/
-typedef struct DexMethodId {
+struct DexMethodId {
u2 classIdx; /* index into typeIds list for defining class */
u2 protoIdx; /* index into protoIds for method prototype */
u4 nameIdx; /* index into stringIds for method name */
-} DexMethodId;
+};
/*
* Direct-mapped "proto_id_item".
*/
-typedef struct DexProtoId {
+struct DexProtoId {
u4 shortyIdx; /* index into stringIds for shorty descriptor */
u4 returnTypeIdx; /* index into typeIds list for return type */
u4 parametersOff; /* file offset to type_list for parameter types */
-} DexProtoId;
+};
/*
* Direct-mapped "class_def_item".
*/
-typedef struct DexClassDef {
+struct DexClassDef {
u4 classIdx; /* index into typeIds for this class */
u4 accessFlags;
u4 superclassIdx; /* index into typeIds for superclass */
@@ -303,22 +303,22 @@ typedef struct DexClassDef {
u4 annotationsOff; /* file offset to annotations_directory_item */
u4 classDataOff; /* file offset to class_data_item */
u4 staticValuesOff; /* file offset to DexEncodedArray */
-} DexClassDef;
+};
/*
* Direct-mapped "type_item".
*/
-typedef struct DexTypeItem {
+struct DexTypeItem {
u2 typeIdx; /* index into typeIds */
-} DexTypeItem;
+};
/*
* Direct-mapped "type_list".
*/
-typedef struct DexTypeList {
+struct DexTypeList {
u4 size; /* #of entries in list */
DexTypeItem list[1]; /* entries */
-} DexTypeList;
+};
/*
* Direct-mapped "code_item".
@@ -327,7 +327,7 @@ typedef struct DexTypeList {
* "debugInfo" is used when displaying an exception stack trace or
* debugging. An offset of zero indicates that there are no entries.
*/
-typedef struct DexCode {
+struct DexCode {
u2 registersSize;
u2 insSize;
u2 outsSize;
@@ -339,29 +339,29 @@ typedef struct DexCode {
/* followed by try_item[triesSize] */
/* followed by uleb128 handlersSize */
/* followed by catch_handler_item[handlersSize] */
-} DexCode;
+};
/*
* Direct-mapped "try_item".
*/
-typedef struct DexTry {
+struct DexTry {
u4 startAddr; /* start address, in 16-bit code units */
u2 insnCount; /* instruction count, in 16-bit code units */
u2 handlerOff; /* offset in encoded handler data to handlers */
-} DexTry;
+};
/*
* Link table. Currently undefined.
*/
-typedef struct DexLink {
+struct DexLink {
u1 bleargh;
-} DexLink;
+};
/*
* Direct-mapped "annotations_directory_item".
*/
-typedef struct DexAnnotationsDirectoryItem {
+struct DexAnnotationsDirectoryItem {
u4 classAnnotationsOff; /* offset to DexAnnotationSetItem */
u4 fieldsSize; /* count of DexFieldAnnotationsItem */
u4 methodsSize; /* count of DexMethodAnnotationsItem */
@@ -369,73 +369,73 @@ typedef struct DexAnnotationsDirectoryItem {
/* followed by DexFieldAnnotationsItem[fieldsSize] */
/* followed by DexMethodAnnotationsItem[methodsSize] */
/* followed by DexParameterAnnotationsItem[parametersSize] */
-} DexAnnotationsDirectoryItem;
+};
/*
* Direct-mapped "field_annotations_item".
*/
-typedef struct DexFieldAnnotationsItem {
+struct DexFieldAnnotationsItem {
u4 fieldIdx;
u4 annotationsOff; /* offset to DexAnnotationSetItem */
-} DexFieldAnnotationsItem;
+};
/*
* Direct-mapped "method_annotations_item".
*/
-typedef struct DexMethodAnnotationsItem {
+struct DexMethodAnnotationsItem {
u4 methodIdx;
u4 annotationsOff; /* offset to DexAnnotationSetItem */
-} DexMethodAnnotationsItem;
+};
/*
* Direct-mapped "parameter_annotations_item".
*/
-typedef struct DexParameterAnnotationsItem {
+struct DexParameterAnnotationsItem {
u4 methodIdx;
u4 annotationsOff; /* offset to DexAnotationSetRefList */
-} DexParameterAnnotationsItem;
+};
/*
* Direct-mapped "annotation_set_ref_item".
*/
-typedef struct DexAnnotationSetRefItem {
+struct DexAnnotationSetRefItem {
u4 annotationsOff; /* offset to DexAnnotationSetItem */
-} DexAnnotationSetRefItem;
+};
/*
* Direct-mapped "annotation_set_ref_list".
*/
-typedef struct DexAnnotationSetRefList {
+struct DexAnnotationSetRefList {
u4 size;
DexAnnotationSetRefItem list[1];
-} DexAnnotationSetRefList;
+};
/*
* Direct-mapped "annotation_set_item".
*/
-typedef struct DexAnnotationSetItem {
+struct DexAnnotationSetItem {
u4 size;
u4 entries[1]; /* offset to DexAnnotationItem */
-} DexAnnotationSetItem;
+};
/*
* Direct-mapped "annotation_item".
*
* NOTE: this structure is byte-aligned.
*/
-typedef struct DexAnnotationItem {
+struct DexAnnotationItem {
u1 visibility;
u1 annotation[1]; /* data in encoded_annotation format */
-} DexAnnotationItem;
+};
/*
* Direct-mapped "encoded_array".
*
* NOTE: this structure is byte-aligned.
*/
-typedef struct DexEncodedArray {
+struct DexEncodedArray {
u1 array[1]; /* data in encoded_array format */
-} DexEncodedArray;
+};
/*
* Lookup table for classes. It provides a mapping from class name to
@@ -446,7 +446,7 @@ typedef struct DexEncodedArray {
* a hash table with direct pointers to the items, but because it's shared
* there's less of a penalty for using a fairly sparse table.
*/
-typedef struct DexClassLookup {
+struct DexClassLookup {
int size; // total size, including "size"
int numEntries; // size of table[]; always power of 2
struct {
@@ -454,7 +454,7 @@ typedef struct DexClassLookup {
int classDescriptorOffset; // in bytes, from start of DEX
int classDefOffset; // in bytes, from start of DEX
} table[1];
-} DexClassLookup;
+};
/*
* Header added by DEX optimization pass. Values are always written in
@@ -464,7 +464,7 @@ typedef struct DexClassLookup {
*
* Try to keep this simple and fixed-size.
*/
-typedef struct DexOptHeader {
+struct DexOptHeader {
u1 magic[8]; /* includes version number */
u4 dexOffset; /* file offset of DEX header */
@@ -478,7 +478,7 @@ typedef struct DexOptHeader {
u4 checksum; /* adler32 checksum covering deps/opt */
/* pad for 64-bit alignment if necessary */
-} DexOptHeader;
+};
#define DEX_OPT_FLAG_BIG (1<<1) /* swapped to big-endian */
@@ -490,7 +490,7 @@ typedef struct DexOptHeader {
* Code should regard DexFile as opaque, using the API calls provided here
* to access specific structures.
*/
-typedef struct DexFile {
+struct DexFile {
/* directly-mapped "opt" header */
const DexOptHeader* pOptHeader;
@@ -519,7 +519,7 @@ typedef struct DexFile {
/* additional app-specific data structures associated with the DEX */
//void* auxData;
-} DexFile;
+};
/*
* Utility function -- rounds up to the nearest power of 2.
diff --git a/libdex/DexInlines.c b/libdex/DexInlines.cpp
index cbedb6267..cbedb6267 100644
--- a/libdex/DexInlines.c
+++ b/libdex/DexInlines.cpp
diff --git a/libdex/DexOpcodes.c b/libdex/DexOpcodes.cpp
index 50254a7e6..50254a7e6 100644
--- a/libdex/DexOpcodes.c
+++ b/libdex/DexOpcodes.cpp
diff --git a/libdex/DexOpcodes.h b/libdex/DexOpcodes.h
index 07188b2d0..d8dc9a7b6 100644
--- a/libdex/DexOpcodes.h
+++ b/libdex/DexOpcodes.h
@@ -66,7 +66,7 @@
* can find the next instruction" aren't possible. (This is
* correctable, but probably not useful.)
*/
-typedef enum Opcode {
+enum Opcode {
// BEGIN(libdex-opcode-enum); GENERATED AUTOMATICALLY BY opcode-gen
OP_NOP = 0x00,
OP_MOVE = 0x01,
@@ -581,7 +581,7 @@ typedef enum Opcode {
OP_SPUT_OBJECT_VOLATILE_JUMBO = 0x1fe,
OP_THROW_VERIFICATION_ERROR_JUMBO = 0x1ff,
// END(libdex-opcode-enum)
-} Opcode;
+};
/*
* Macro used to generate a computed goto table for use in implementing
diff --git a/libdex/DexOptData.c b/libdex/DexOptData.cpp
index 10a4b5d29..131b6566f 100644
--- a/libdex/DexOptData.c
+++ b/libdex/DexOptData.cpp
@@ -50,7 +50,7 @@ bool dexParseOptData(const u1* data, size_t length, DexFile* pDexFile)
{
const void* pOptStart = data + pDexFile->pOptHeader->optOffset;
const void* pOptEnd = data + length;
- const u4* pOpt = pOptStart;
+ const u4* pOpt = (const u4*) pOptStart;
u4 optLength = (const u1*) pOptEnd - (const u1*) pOptStart;
/*
diff --git a/libdex/DexProto.c b/libdex/DexProto.cpp
index 25ab400d1..06c59b37d 100644
--- a/libdex/DexProto.c
+++ b/libdex/DexProto.cpp
@@ -45,7 +45,7 @@ void dexStringCacheAlloc(DexStringCache* pCache, size_t length) {
pCache->value = pCache->buffer;
pCache->allocatedSize = 0;
} else {
- pCache->value = malloc(length);
+ pCache->value = (char*) malloc(length);
pCache->allocatedSize = length;
}
}
diff --git a/libdex/DexProto.h b/libdex/DexProto.h
index 50d4bf330..591c27440 100644
--- a/libdex/DexProto.h
+++ b/libdex/DexProto.h
@@ -30,11 +30,11 @@
* generally return a string that is valid until the next
* time the same DexStringCache is used.
*/
-typedef struct DexStringCache {
+struct DexStringCache {
char* value; /* the latest value */
size_t allocatedSize; /* size of the allocated buffer, if allocated */
char buffer[120]; /* buffer used to hold small-enough results */
-} DexStringCache;
+};
/*
* Make sure that the given cache can hold a string of the given length,
@@ -76,10 +76,10 @@ char* dexStringCacheAbandon(DexStringCache* pCache, const char* value);
* Method prototype structure, which refers to a protoIdx in a
* particular DexFile.
*/
-typedef struct DexProto {
+struct DexProto {
const DexFile* dexFile; /* file the idx refers to */
u4 protoIdx; /* index into proto_ids table of dexFile */
-} DexProto;
+};
/*
* Set the given DexProto to refer to the prototype of the given MethodId.
@@ -199,12 +199,12 @@ int dexProtoCompareToParameterDescriptors(const DexProto* proto,
* Single-thread prototype parameter iterator. This structure holds a
* pointer to a prototype and its parts, along with a cursor.
*/
-typedef struct DexParameterIterator {
+struct DexParameterIterator {
const DexProto* proto;
const DexTypeList* parameters;
int parameterCount;
int cursor;
-} DexParameterIterator;
+};
/*
* Initialize the given DexParameterIterator to be at the start of the
@@ -226,6 +226,4 @@ u4 dexParameterIteratorNextIndex(DexParameterIterator* pIterator);
const char* dexParameterIteratorNextDescriptor(
DexParameterIterator* pIterator);
-
-
#endif /*_LIBDEX_DEXPROTO*/
diff --git a/libdex/DexSwapVerify.c b/libdex/DexSwapVerify.cpp
index 5fd3f0906..ea05e0c7a 100644
--- a/libdex/DexSwapVerify.c
+++ b/libdex/DexSwapVerify.cpp
@@ -68,7 +68,7 @@ static u8 endianSwapU8(u8 value) {
/*
* Some information we pass around to help verify values.
*/
-typedef struct CheckState {
+struct CheckState {
const DexHeader* pHeader;
const u1* fileStart;
const u1* fileEnd; // points to fileStart + fileLen
@@ -84,7 +84,7 @@ typedef struct CheckState {
u4* pDefinedClassBits;
const void* previousItem; // set during section iteration
-} CheckState;
+};
/*
* Return the file offset of the given pointer.
@@ -131,8 +131,8 @@ static inline bool checkPtrRange(const CheckState* state,
* Assumes "const CheckState* state".
*/
#define CHECK_OFFSET_RANGE(_start, _end) { \
- const u1* _startPtr = filePointer(state, (_start)); \
- const u1* _endPtr = filePointer(state, (_end)); \
+ const u1* _startPtr = (const u1*) filePointer(state, (_start)); \
+ const u1* _endPtr = (const u1*) filePointer(state, (_end)); \
if (!checkPtrRange(state, _startPtr, _endPtr, \
#_start ".." #_end)) { \
return 0; \
@@ -332,7 +332,7 @@ static bool checkHeaderSection(const CheckState* state, u4 sectionOffset,
return false;
}
- const DexHeader* pHeader = filePointer(state, 0);
+ const DexHeader* pHeader = (const DexHeader*) filePointer(state, 0);
*endOffset = pHeader->headerSize;
return true;
}
@@ -536,7 +536,7 @@ static bool checkMapSection(const CheckState* state, u4 sectionOffset,
return false;
}
- const DexMapList* pMap = filePointer(state, sectionOffset);
+ const DexMapList* pMap = (const DexMapList*) filePointer(state, sectionOffset);
*endOffset =
sectionOffset + sizeof(u4) + (pMap->size * sizeof(DexMapItem));
@@ -545,7 +545,7 @@ static bool checkMapSection(const CheckState* state, u4 sectionOffset,
/* Perform byte-swapping and intra-item verification on string_id_item. */
static void* swapStringIdItem(const CheckState* state, void* ptr) {
- DexStringId* item = ptr;
+ DexStringId* item = (DexStringId*) ptr;
CHECK_PTR_RANGE(item, item + 1);
SWAP_OFFSET4(item->stringDataOff);
@@ -555,14 +555,14 @@ static void* swapStringIdItem(const CheckState* state, void* ptr) {
/* Perform cross-item verification of string_id_item. */
static void* crossVerifyStringIdItem(const CheckState* state, void* ptr) {
- const DexStringId* item = ptr;
+ const DexStringId* item = (const DexStringId*) ptr;
if (!dexDataMapVerify(state->pDataMap,
item->stringDataOff, kDexTypeStringDataItem)) {
return NULL;
}
- const DexStringId* item0 = state->previousItem;
+ const DexStringId* item0 = (const DexStringId*) state->previousItem;
if (item0 != NULL) {
// Check ordering.
const char* s0 = dexGetStringData(state->pDexFile, item0);
@@ -578,7 +578,7 @@ static void* crossVerifyStringIdItem(const CheckState* state, void* ptr) {
/* Perform byte-swapping and intra-item verification on type_id_item. */
static void* swapTypeIdItem(const CheckState* state, void* ptr) {
- DexTypeId* item = ptr;
+ DexTypeId* item = (DexTypeId*) ptr;
CHECK_PTR_RANGE(item, item + 1);
SWAP_INDEX4(item->descriptorIdx, state->pHeader->stringIdsSize);
@@ -588,7 +588,7 @@ static void* swapTypeIdItem(const CheckState* state, void* ptr) {
/* Perform cross-item verification of type_id_item. */
static void* crossVerifyTypeIdItem(const CheckState* state, void* ptr) {
- const DexTypeId* item = ptr;
+ const DexTypeId* item = (const DexTypeId*) ptr;
const char* descriptor =
dexStringById(state->pDexFile, item->descriptorIdx);
@@ -597,7 +597,7 @@ static void* crossVerifyTypeIdItem(const CheckState* state, void* ptr) {
return NULL;
}
- const DexTypeId* item0 = state->previousItem;
+ const DexTypeId* item0 = (const DexTypeId*) state->previousItem;
if (item0 != NULL) {
// Check ordering. This relies on string_ids being in order.
if (item0->descriptorIdx >= item->descriptorIdx) {
@@ -612,7 +612,7 @@ static void* crossVerifyTypeIdItem(const CheckState* state, void* ptr) {
/* Perform byte-swapping and intra-item verification on proto_id_item. */
static void* swapProtoIdItem(const CheckState* state, void* ptr) {
- DexProtoId* item = ptr;
+ DexProtoId* item = (DexProtoId*) ptr;
CHECK_PTR_RANGE(item, item + 1);
SWAP_INDEX4(item->shortyIdx, state->pHeader->stringIdsSize);
@@ -669,7 +669,7 @@ static bool shortyDescMatch(char shorty, const char* descriptor, bool
/* Perform cross-item verification of proto_id_item. */
static void* crossVerifyProtoIdItem(const CheckState* state, void* ptr) {
- const DexProtoId* item = ptr;
+ const DexProtoId* item = (const DexProtoId*) ptr;
const char* shorty =
dexStringById(state->pDexFile, item->shortyIdx);
@@ -715,7 +715,7 @@ static void* crossVerifyProtoIdItem(const CheckState* state, void* ptr) {
return NULL;
}
- const DexProtoId* item0 = state->previousItem;
+ const DexProtoId* item0 = (const DexProtoId*) state->previousItem;
if (item0 != NULL) {
// Check ordering. This relies on type_ids being in order.
if (item0->returnTypeIdx > item->returnTypeIdx) {
@@ -762,7 +762,7 @@ static void* crossVerifyProtoIdItem(const CheckState* state, void* ptr) {
/* Perform byte-swapping and intra-item verification on field_id_item. */
static void* swapFieldIdItem(const CheckState* state, void* ptr) {
- DexFieldId* item = ptr;
+ DexFieldId* item = (DexFieldId*) ptr;
CHECK_PTR_RANGE(item, item + 1);
SWAP_INDEX2(item->classIdx, state->pHeader->typeIdsSize);
@@ -774,7 +774,7 @@ static void* swapFieldIdItem(const CheckState* state, void* ptr) {
/* Perform cross-item verification of field_id_item. */
static void* crossVerifyFieldIdItem(const CheckState* state, void* ptr) {
- const DexFieldId* item = ptr;
+ const DexFieldId* item = (const DexFieldId*) ptr;
const char* s;
s = dexStringByTypeIdx(state->pDexFile, item->classIdx);
@@ -795,7 +795,7 @@ static void* crossVerifyFieldIdItem(const CheckState* state, void* ptr) {
return NULL;
}
- const DexFieldId* item0 = state->previousItem;
+ const DexFieldId* item0 = (const DexFieldId*) state->previousItem;
if (item0 != NULL) {
// Check ordering. This relies on the other sections being in order.
bool done = false;
@@ -834,7 +834,7 @@ static void* crossVerifyFieldIdItem(const CheckState* state, void* ptr) {
/* Perform byte-swapping and intra-item verification on method_id_item. */
static void* swapMethodIdItem(const CheckState* state, void* ptr) {
- DexMethodId* item = ptr;
+ DexMethodId* item = (DexMethodId*) ptr;
CHECK_PTR_RANGE(item, item + 1);
SWAP_INDEX2(item->classIdx, state->pHeader->typeIdsSize);
@@ -846,7 +846,7 @@ static void* swapMethodIdItem(const CheckState* state, void* ptr) {
/* Perform cross-item verification of method_id_item. */
static void* crossVerifyMethodIdItem(const CheckState* state, void* ptr) {
- const DexMethodId* item = ptr;
+ const DexMethodId* item = (const DexMethodId*) ptr;
const char* s;
s = dexStringByTypeIdx(state->pDexFile, item->classIdx);
@@ -861,7 +861,7 @@ static void* crossVerifyMethodIdItem(const CheckState* state, void* ptr) {
return NULL;
}
- const DexMethodId* item0 = state->previousItem;
+ const DexMethodId* item0 = (const DexMethodId*) state->previousItem;
if (item0 != NULL) {
// Check ordering. This relies on the other sections being in order.
bool done = false;
@@ -900,7 +900,7 @@ static void* crossVerifyMethodIdItem(const CheckState* state, void* ptr) {
/* Perform byte-swapping and intra-item verification on class_def_item. */
static void* swapClassDefItem(const CheckState* state, void* ptr) {
- DexClassDef* item = ptr;
+ DexClassDef* item = (DexClassDef*) ptr;
CHECK_PTR_RANGE(item, item + 1);
SWAP_INDEX4(item->classIdx, state->pHeader->typeIdsSize);
@@ -928,7 +928,7 @@ static bool verifyClassDataIsForDef(const CheckState* state, u4 offset,
return true;
}
- const u1* data = filePointer(state, offset);
+ const u1* data = (const u1*) filePointer(state, offset);
DexClassData* classData = dexReadAndVerifyClassData(&data, NULL);
if (classData == NULL) {
@@ -957,7 +957,8 @@ static bool verifyAnnotationsDirectoryIsForDef(const CheckState* state,
return true;
}
- const DexAnnotationsDirectoryItem* dir = filePointer(state, offset);
+ const DexAnnotationsDirectoryItem* dir =
+ (const DexAnnotationsDirectoryItem*) filePointer(state, offset);
u4 annoDefiner = findFirstAnnotationsDirectoryDefiner(state, dir);
return (annoDefiner == definerIdx) || (annoDefiner == kDexNoIndex);
@@ -965,7 +966,7 @@ static bool verifyAnnotationsDirectoryIsForDef(const CheckState* state,
/* Perform cross-item verification of class_def_item. */
static void* crossVerifyClassDefItem(const CheckState* state, void* ptr) {
- const DexClassDef* item = ptr;
+ const DexClassDef* item = (const DexClassDef*) ptr;
u4 classIdx = item->classIdx;
const char* descriptor = dexStringByTypeIdx(state->pDexFile, classIdx);
@@ -1146,7 +1147,7 @@ static u1* swapParameterAnnotations(const CheckState* state, u4 count,
/* Perform byte-swapping and intra-item verification on
* annotations_directory_item. */
static void* swapAnnotationsDirectoryItem(const CheckState* state, void* ptr) {
- DexAnnotationsDirectoryItem* item = ptr;
+ DexAnnotationsDirectoryItem* item = (DexAnnotationsDirectoryItem*) ptr;
CHECK_PTR_RANGE(item, item + 1);
SWAP_OFFSET4(item->classAnnotationsOff);
@@ -1276,7 +1277,7 @@ static u4 findFirstAnnotationsDirectoryDefiner(const CheckState* state,
/* Perform cross-item verification of annotations_directory_item. */
static void* crossVerifyAnnotationsDirectoryItem(const CheckState* state,
void* ptr) {
- const DexAnnotationsDirectoryItem* item = ptr;
+ const DexAnnotationsDirectoryItem* item = (const DexAnnotationsDirectoryItem*) ptr;
u4 definingClass = findFirstAnnotationsDirectoryDefiner(state, item);
if (!dexDataMapVerify0Ok(state->pDataMap,
@@ -1316,7 +1317,7 @@ static void* crossVerifyAnnotationsDirectoryItem(const CheckState* state,
/* Perform byte-swapping and intra-item verification on type_list. */
static void* swapTypeList(const CheckState* state, void* ptr)
{
- DexTypeList* pTypeList = ptr;
+ DexTypeList* pTypeList = (DexTypeList*) ptr;
DexTypeItem* pType;
u4 count;
@@ -1337,7 +1338,7 @@ static void* swapTypeList(const CheckState* state, void* ptr)
/* Perform byte-swapping and intra-item verification on
* annotation_set_ref_list. */
static void* swapAnnotationSetRefList(const CheckState* state, void* ptr) {
- DexAnnotationSetRefList* list = ptr;
+ DexAnnotationSetRefList* list = (DexAnnotationSetRefList*) ptr;
DexAnnotationSetRefItem* item;
u4 count;
@@ -1358,7 +1359,7 @@ static void* swapAnnotationSetRefList(const CheckState* state, void* ptr) {
/* Perform cross-item verification of annotation_set_ref_list. */
static void* crossVerifyAnnotationSetRefList(const CheckState* state,
void* ptr) {
- const DexAnnotationSetRefList* list = ptr;
+ const DexAnnotationSetRefList* list = (const DexAnnotationSetRefList*) ptr;
const DexAnnotationSetRefItem* item = list->list;
int count = list->size;
@@ -1376,7 +1377,7 @@ static void* crossVerifyAnnotationSetRefList(const CheckState* state,
/* Perform byte-swapping and intra-item verification on
* annotation_set_item. */
static void* swapAnnotationSetItem(const CheckState* state, void* ptr) {
- DexAnnotationSetItem* set = ptr;
+ DexAnnotationSetItem* set = (DexAnnotationSetItem*) ptr;
u4* item;
u4 count;
@@ -1403,7 +1404,7 @@ static u4 annotationItemTypeIdx(const DexAnnotationItem* item) {
/* Perform cross-item verification of annotation_set_item. */
static void* crossVerifyAnnotationSetItem(const CheckState* state, void* ptr) {
- const DexAnnotationSetItem* set = ptr;
+ const DexAnnotationSetItem* set = (const DexAnnotationSetItem*) ptr;
int count = set->size;
u4 lastIdx = 0;
bool first = true;
@@ -1545,7 +1546,7 @@ static bool verifyClassDataItem0(const CheckState* state,
/* Perform intra-item verification on class_data_item. */
static void* intraVerifyClassDataItem(const CheckState* state, void* ptr) {
- const u1* data = ptr;
+ const u1* data = (const u1*) ptr;
DexClassData* classData = dexReadAndVerifyClassData(&data, state->fileEnd);
if (classData == NULL) {
@@ -1598,7 +1599,7 @@ static u4 findFirstClassDataDefiner(const CheckState* state,
/* Perform cross-item verification of class_data_item. */
static void* crossVerifyClassDataItem(const CheckState* state, void* ptr) {
- const u1* data = ptr;
+ const u1* data = (const u1*) ptr;
DexClassData* classData = dexReadAndVerifyClassData(&data, state->fileEnd);
u4 definingClass = findFirstClassDataDefiner(state, classData);
bool okay = true;
@@ -1798,7 +1799,7 @@ static void* swapTriesAndCatches(const CheckState* state, DexCode* code) {
/* Perform byte-swapping and intra-item verification on code_item. */
static void* swapCodeItem(const CheckState* state, void* ptr) {
- DexCode* item = ptr;
+ DexCode* item = (DexCode*) ptr;
u2* insns;
u4 count;
@@ -1858,7 +1859,7 @@ static void* swapCodeItem(const CheckState* state, void* ptr) {
/* Perform intra-item verification on string_data_item. */
static void* intraVerifyStringDataItem(const CheckState* state, void* ptr) {
const u1* fileEnd = state->fileEnd;
- const u1* data = ptr;
+ const u1* data = (const u1*) ptr;
bool okay = true;
u4 utf16Size = readAndVerifyUnsignedLeb128(&data, fileEnd, &okay);
u4 i;
@@ -1959,7 +1960,7 @@ static void* intraVerifyStringDataItem(const CheckState* state, void* ptr) {
/* Perform intra-item verification on debug_info_item. */
static void* intraVerifyDebugInfoItem(const CheckState* state, void* ptr) {
const u1* fileEnd = state->fileEnd;
- const u1* data = ptr;
+ const u1* data = (const u1*) ptr;
bool okay = true;
u4 i;
@@ -2341,7 +2342,7 @@ static void* intraVerifyEncodedArrayItem(const CheckState* state, void* ptr) {
/* Perform intra-item verification on annotation_item. */
static void* intraVerifyAnnotationItem(const CheckState* state, void* ptr) {
- const u1* data = ptr;
+ const u1* data = (const u1*) ptr;
CHECK_PTR_RANGE(data, data + 1);
@@ -2362,7 +2363,7 @@ static void* intraVerifyAnnotationItem(const CheckState* state, void* ptr) {
/* Perform cross-item verification on annotation_item. */
static void* crossVerifyAnnotationItem(const CheckState* state, void* ptr) {
- const u1* data = ptr;
+ const u1* data = (const u1*) ptr;
// Skip the visibility byte.
data++;
@@ -2393,10 +2394,10 @@ static bool iterateSectionWithOptionalUpdate(CheckState* state,
for (i = 0; i < count; i++) {
u4 newOffset = (offset + alignmentMask) & ~alignmentMask;
- u1* ptr = filePointer(state, newOffset);
+ u1* ptr = (u1*) filePointer(state, newOffset);
if (offset < newOffset) {
- ptr = filePointer(state, offset);
+ ptr = (u1*) filePointer(state, offset);
if (offset < newOffset) {
CHECK_OFFSET_RANGE(offset, newOffset);
while (offset < newOffset) {
@@ -2523,7 +2524,7 @@ static bool swapEverythingButHeaderAndMap(CheckState* state,
if (lastOffset < sectionOffset) {
CHECK_OFFSET_RANGE(lastOffset, sectionOffset);
- const u1* ptr = filePointer(state, lastOffset);
+ const u1* ptr = (const u1*) filePointer(state, lastOffset);
while (lastOffset < sectionOffset) {
if (*ptr != '\0') {
LOGE("Non-zero padding 0x%02x before section start @ %x\n",
diff --git a/libdex/DexUtf.c b/libdex/DexUtf.cpp
index df49d1831..df49d1831 100644
--- a/libdex/DexUtf.c
+++ b/libdex/DexUtf.cpp
diff --git a/libdex/InstrUtils.c b/libdex/InstrUtils.cpp
index 3770c6da0..3770c6da0 100644
--- a/libdex/InstrUtils.c
+++ b/libdex/InstrUtils.cpp
diff --git a/libdex/InstrUtils.h b/libdex/InstrUtils.h
index f09429cf0..187fd5c6b 100644
--- a/libdex/InstrUtils.h
+++ b/libdex/InstrUtils.h
@@ -29,7 +29,7 @@
* See the file opcode-gen/README.txt for information about updating
* opcodes and instruction formats.
*/
-typedef enum {
+enum InstructionFormat {
kFmt00x = 0, // unknown format (also used for "breakpoint" opcode)
kFmt10x, // op
kFmt12x, // op vA, vB
@@ -67,13 +67,13 @@ typedef enum {
kFmt41c, // exop vAAAA, thing@BBBBBBBB
kFmt52c, // exop vAAAA, vBBBB, thing@CCCCCCCC
kFmt5rc, // exop {vCCCC .. v(CCCC+AAAA-1)}, thing@BBBBBBBB
-} InstructionFormat;
+};
/*
* Types of indexed reference that are associated with opcodes whose
* formats include such an indexed reference (e.g., 21c and 35c).
*/
-typedef enum {
+enum InstructionIndexType {
kIndexUnknown = 0,
kIndexNone, // has no index
kIndexVaries, // "It depends." Used for throw-verification-error
@@ -84,7 +84,7 @@ typedef enum {
kIndexInlineMethod, // inline method index (for inline linked methods)
kIndexVtableOffset, // vtable offset (for static linked methods)
kIndexFieldOffset // field offset (for static linked fields)
-} InstructionIndexType;
+};
/*
* Instruction width implied by an opcode's format; a value in the
@@ -117,12 +117,12 @@ enum OpcodeFlagsBits {
* that works for both C and C++, but in the mean time, this will
* suffice.
*/
-typedef struct InstructionInfoTables {
+struct InstructionInfoTables {
u1* formats; /* InstructionFormat elements */
u1* indexTypes; /* InstructionIndexType elements */
OpcodeFlags* flags;
InstructionWidth* widths;
-} InstructionInfoTables;
+};
/*
* Global InstructionInfoTables struct.
@@ -132,7 +132,7 @@ extern InstructionInfoTables gDexOpcodeInfo;
/*
* Holds the contents of a decoded instruction.
*/
-typedef struct DecodedInstruction {
+struct DecodedInstruction {
u4 vA;
u4 vB;
u8 vB_wide; /* for kFmt51l */
@@ -140,7 +140,7 @@ typedef struct DecodedInstruction {
u4 arg[5]; /* vC/D/E/F/G in invoke or filled-new-array */
Opcode opcode;
InstructionIndexType indexType;
-} DecodedInstruction;
+};
/*
* Return the instruction width of the specified opcode, or 0 if not defined.
diff --git a/libdex/Leb128.c b/libdex/Leb128.cpp
index ed09e19aa..ed09e19aa 100644
--- a/libdex/Leb128.c
+++ b/libdex/Leb128.cpp
diff --git a/libdex/OptInvocation.c b/libdex/OptInvocation.cpp
index df5f8d99f..df5f8d99f 100644
--- a/libdex/OptInvocation.c
+++ b/libdex/OptInvocation.cpp
diff --git a/libdex/OptInvocation.h b/libdex/OptInvocation.h
index 0352eb423..e44ce544f 100644
--- a/libdex/OptInvocation.h
+++ b/libdex/OptInvocation.h
@@ -20,10 +20,6 @@
#ifndef _LIBDEX_OPTINVOCATION
#define _LIBDEX_OPTINVOCATION
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* Utility routines, used by the VM.
*/
@@ -31,8 +27,4 @@ char* dexOptGenerateCacheFileName(const char* fileName,
const char* subFileName);
int dexOptCreateEmptyHeader(int fd);
-#ifdef __cplusplus
-};
-#endif
-
#endif /*_LIBDEX_OPTINVOCATION*/
diff --git a/libdex/SysUtil.c b/libdex/SysUtil.cpp
index 951ca1d8a..951ca1d8a 100644
--- a/libdex/SysUtil.c
+++ b/libdex/SysUtil.cpp
diff --git a/libdex/SysUtil.h b/libdex/SysUtil.h
index 4de028974..e297dc05d 100644
--- a/libdex/SysUtil.h
+++ b/libdex/SysUtil.h
@@ -36,13 +36,13 @@
/*
* Use this to keep track of mapped segments.
*/
-typedef struct MemMapping {
+struct MemMapping {
void* addr; /* start of data */
size_t length; /* length of data */
void* baseAddr; /* page-aligned base address */
size_t baseLength; /* length of mapping */
-} MemMapping;
+};
/*
* Copy a map.
diff --git a/libdex/ZipArchive.c b/libdex/ZipArchive.cpp
index dd9dce4c2..29b665ed7 100644
--- a/libdex/ZipArchive.c
+++ b/libdex/ZipArchive.cpp
@@ -141,27 +141,16 @@ static u4 get4LE(unsigned char const* pSrc)
return result;
}
-/*
- * Find the zip Central Directory and memory-map it.
- *
- * On success, returns 0 after populating fields from the EOCD area:
- * mDirectoryOffset
- * mDirectoryMap
- * mNumEntries
- */
-static int mapCentralDirectory(int fd, const char* debugFileName,
- ZipArchive* pArchive)
+static int mapCentralDirectory0(int fd, const char* debugFileName,
+ ZipArchive* pArchive, u1* scanBuf)
{
- u1* scanBuf = NULL;
- int result = -1;
-
/*
* Get and test file length.
*/
off_t fileLength = lseek(fd, 0, SEEK_END);
if (fileLength < kEOCDLen) {
LOGV("Zip: length %ld is too small to be zip\n", (long) fileLength);
- goto bail;
+ return -1;
}
/*
@@ -184,12 +173,12 @@ static int mapCentralDirectory(int fd, const char* debugFileName,
scanBuf = (u1*) malloc(readAmount);
if (lseek(fd, searchStart, SEEK_SET) != searchStart) {
LOGW("Zip: seek %ld failed: %s\n", (long) searchStart, strerror(errno));
- goto bail;
+ return -1;
}
ssize_t actual = TEMP_FAILURE_RETRY(read(fd, scanBuf, readAmount));
if (actual != (ssize_t) readAmount) {
LOGW("Zip: read %zd failed: %s\n", readAmount, strerror(errno));
- goto bail;
+ return -1;
}
/*
@@ -207,7 +196,7 @@ static int mapCentralDirectory(int fd, const char* debugFileName,
}
if (i < 0) {
LOGD("Zip: EOCD not found, %s is not zip\n", debugFileName);
- goto bail;
+ return -1;
}
off_t eocdOffset = searchStart + i;
@@ -226,11 +215,11 @@ static int mapCentralDirectory(int fd, const char* debugFileName,
if ((long long) dirOffset + (long long) dirSize > (long long) eocdOffset) {
LOGW("Zip: bad offsets (dir %ld, size %u, eocd %ld)\n",
(long) dirOffset, dirSize, (long) eocdOffset);
- goto bail;
+ return -1;
}
if (numEntries == 0) {
LOGW("Zip: empty archive?\n");
- goto bail;
+ return -1;
}
LOGV("+++ numEntries=%d dirSize=%d dirOffset=%d\n",
@@ -244,15 +233,34 @@ static int mapCentralDirectory(int fd, const char* debugFileName,
&pArchive->mDirectoryMap) != 0)
{
LOGW("Zip: cd map failed\n");
- goto bail;
+ return -1;
}
pArchive->mNumEntries = numEntries;
pArchive->mDirectoryOffset = dirOffset;
- result = 0;
+ return 0;
+}
+
+/*
+ * Find the zip Central Directory and memory-map it.
+ *
+ * On success, returns 0 after populating fields from the EOCD area:
+ * mDirectoryOffset
+ * mDirectoryMap
+ * mNumEntries
+ */
+static int mapCentralDirectory(int fd, const char* debugFileName,
+ ZipArchive* pArchive)
+{
+ u1* scanBuf = (u1*) malloc(kMaxEOCDSearch);
+
+ if (scanBuf == NULL) {
+ return -1;
+ }
+
+ int result = mapCentralDirectory0(fd, debugFileName, pArchive, scanBuf);
-bail:
free(scanBuf);
return result;
}
diff --git a/libdex/ZipArchive.h b/libdex/ZipArchive.h
index bf4edf972..8d15cf6da 100644
--- a/libdex/ZipArchive.h
+++ b/libdex/ZipArchive.h
@@ -23,7 +23,6 @@
#include "SysUtil.h"
#include "DexFile.h" // need DEX_INLINE
-
/*
* Trivial typedef to ensure that ZipEntry is not treated as a simple
* integer. We use NULL to indicate an invalid value.
@@ -33,11 +32,10 @@ typedef void* ZipEntry;
/*
* One entry in the hash table.
*/
-typedef struct ZipHashEntry {
+struct ZipHashEntry {
const char* name;
unsigned short nameLen;
- //unsigned int hash;
-} ZipHashEntry;
+};
/*
* Read-only Zip archive.
@@ -58,7 +56,7 @@ typedef struct ZipHashEntry {
* every page that the Central Directory touches. Easier to tuck a copy
* of the string length into the hash table entry.
*/
-typedef struct ZipArchive {
+struct ZipArchive {
/* open Zip archive */
int mFd;
@@ -75,7 +73,7 @@ typedef struct ZipArchive {
*/
int mHashTableSize;
ZipHashEntry* mHashTable;
-} ZipArchive;
+};
/* Zip compression methods we support */
enum {
diff --git a/libdex/sha1.c b/libdex/sha1.cpp
index dc7e30ae7..15a81cca3 100644
--- a/libdex/sha1.c
+++ b/libdex/sha1.cpp
@@ -136,10 +136,10 @@ static void SHA1Transform(unsigned long state[5],
const unsigned char buffer[64])
{
unsigned long a, b, c, d, e;
-typedef union {
+union CHAR64LONG16 {
unsigned char c[64];
unsigned long l[16];
-} CHAR64LONG16;
+};
CHAR64LONG16* block;
#ifdef SHA1HANDSOFF
static unsigned char workspace[64];
diff --git a/libdex/sha1.h b/libdex/sha1.h
index 65cf667cd..f18a8c0b3 100644
--- a/libdex/sha1.h
+++ b/libdex/sha1.h
@@ -1,14 +1,14 @@
/*
- * See "sha1.c" for author info.
+ * See "sha1.cpp" for author info.
*/
#ifndef _DALVIK_SHA1
#define _DALVIK_SHA1
-typedef struct {
+struct SHA1_CTX {
unsigned long state[5];
unsigned long count[2];
unsigned char buffer[64];
-} SHA1_CTX;
+};
#define HASHSIZE 20