Merge change 24213 into eclair

* changes:
  Fix a bug that prevented the "generic" product builds from working in the emulator.
diff --git a/include/acc/acc.h b/include/acc/acc.h
index af21a46..1182355 100644
--- a/include/acc/acc.h
+++ b/include/acc/acc.h
@@ -77,6 +77,12 @@
 void accGetPragmas(ACCscript* script, ACCsizei* actualStringCount,
                    ACCsizei maxStringCount, ACCchar** strings);
 
+/* Used to implement disassembly */
+
+void accGetProgramBinary(ACCscript* script,
+    ACCvoid** base,
+    ACCsizei* length);
+
 #ifdef __cplusplus
 };
 #endif
diff --git a/libacc/Android.mk b/libacc/Android.mk
index f77e2b3..2b4998e 100644
--- a/libacc/Android.mk
+++ b/libacc/Android.mk
@@ -7,10 +7,6 @@
 LOCAL_MODULE:= libacc
 LOCAL_SRC_FILES := acc.cpp
 
-ifeq ($(TARGET_ARCH),arm)
-LOCAL_SRC_FILES += disassem.cpp
-endif
-
 LOCAL_SHARED_LIBRARIES := libdl libcutils
 
 include $(BUILD_SHARED_LIBRARY)
@@ -24,10 +20,6 @@
 
 LOCAL_CFLAGS := -O0 -g
 
-ifeq ($(TARGET_ARCH),arm)
-LOCAL_SRC_FILES += disassem.cpp
-endif
-
 LOCAL_STATIC_LIBRARIES := libcutils
 LOCAL_LDLIBS := -ldl
 
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index c52b992..81d30ad 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -13,20 +13,20 @@
 
 #include <ctype.h>
 #include <errno.h>
+#include <limits.h>
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
+
 #include <cutils/hashmap.h>
 
 #if defined(__i386__)
 #include <sys/mman.h>
 #endif
 
-#if defined(__arm__)
-#include <unistd.h>
-#endif
 
 #if defined(__arm__)
 #define DEFAULT_ARM_CODEGEN
@@ -39,10 +39,6 @@
 #define PROVIDE_X64_CODEGEN
 #endif
 
-#ifdef PROVIDE_ARM_CODEGEN
-#include "disassem.h"
-#endif
-
 #if (defined(__VFP_FP__) && !defined(__SOFTFP__))
 #define ARM_USE_VFP
 #endif
@@ -55,9 +51,19 @@
 #define LOG_STACK(...) do {} while(0)
 // #define LOG_STACK(...) fprintf (stderr, __VA_ARGS__)
 
-#define ENABLE_ARM_DISASSEMBLY
 // #define PROVIDE_TRACE_CODEGEN
 
+// Uncomment to save input to a text file in DEBUG_DUMP_PATTERN
+// #define DEBUG_SAVE_INPUT_TO_FILE
+
+#ifdef DEBUG_SAVE_INPUT_TO_FILE
+#ifdef ARM_USE_VFP
+#define DEBUG_DUMP_PATTERN "/data/misc/acc_dump/%d.c"
+#else
+#define DEBUG_DUMP_PATTERN "/tmp/acc_dump/%d.c"
+#endif
+#endif
+
 #define assert(b) assertImpl(b, __LINE__)
 
 namespace acc {
@@ -473,11 +479,6 @@
          */
         virtual void adjustStackAfterCall(Type* pDecl, int l, bool isIndirect) = 0;
 
-        /* Print a disassembly of the assembled code to out. Return
-         * non-zero if there is an error.
-         */
-        virtual int disassemble(FILE* out) = 0;
-
         /* Generate a symbol at the current PC. t is the head of a
          * linked list of addresses to patch.
          */
@@ -684,9 +685,9 @@
     public:
         ARMCodeGenerator() {
 #ifdef ARM_USE_VFP
-            LOGD("Using ARM VFP hardware floating point.");
+            // LOGD("Using ARM VFP hardware floating point.");
 #else
-            LOGD("Using ARM soft floating point.");
+            // LOGD("Using ARM soft floating point.");
 #endif
         }
 
@@ -1537,21 +1538,27 @@
 #endif
                     }
                 } else {
-                    assert (r0Tag == TY_DOUBLE);
-                    if (destTag == TY_INT) {
+                    if (r0Tag == TY_DOUBLE) {
+                        if (destTag == TY_INT) {
 #ifdef ARM_USE_VFP
-                        o4(0xEEFD7BC7); // ftosizd s15, d7
-                        o4(0xEE170A90); // fmrs r0, s15
+                            o4(0xEEFD7BC7); // ftosizd s15, d7
+                            o4(0xEE170A90); // fmrs r0, s15
 #else
-                        callRuntime((void*) runtime_double_to_int);
+                            callRuntime((void*) runtime_double_to_int);
 #endif
+                        } else {
+                            if(destTag == TY_FLOAT) {
+#ifdef ARM_USE_VFP
+                                o4(0xEEF77BC7); // fcvtsd s15, d7
+#else
+                                callRuntime((void*) runtime_double_to_float);
+#endif
+                            } else {
+                                incompatibleTypes(pR0Type, pType);
+                            }
+                        }
                     } else {
-                        assert(destTag == TY_FLOAT);
-#ifdef ARM_USE_VFP
-                        o4(0xEEF77BC7); // fcvtsd s15, d7
-#else
-                        callRuntime((void*) runtime_double_to_float);
-#endif
+                        incompatibleTypes(pR0Type, pType);
                     }
                 }
             }
@@ -1747,24 +1754,6 @@
 #endif
         }
 
-        virtual int disassemble(FILE* out) {
-#ifdef ENABLE_ARM_DISASSEMBLY
-            disasmOut = out;
-            disasm_interface_t  di;
-            di.di_readword = disassemble_readword;
-            di.di_printaddr = disassemble_printaddr;
-            di.di_printf = disassemble_printf;
-
-            int base = getBase();
-            int pc = getPC();
-            for(int i = base; i < pc; i += 4) {
-                fprintf(out, "%08x: %08x  ", i, *(int*) i);
-                ::disasm(&di, i, 0);
-            }
-#endif
-            return 0;
-        }
-
         /**
          * alignment (in bytes) for this type of data
          */
@@ -1816,27 +1805,6 @@
         }
 
     private:
-        static FILE* disasmOut;
-
-        static u_int
-        disassemble_readword(u_int address)
-        {
-            return(*((u_int *)address));
-        }
-
-        static void
-        disassemble_printaddr(u_int address)
-        {
-            fprintf(disasmOut, "0x%08x", address);
-        }
-
-        static void
-        disassemble_printf(const char *fmt, ...) {
-            va_list ap;
-            va_start(ap, fmt);
-            vfprintf(disasmOut, fmt, ap);
-            va_end(ap);
-        }
 
         static const int BRANCH_REL_ADDRESS_MASK = 0x00ffffff;
 
@@ -2021,6 +1989,10 @@
             return false;
         }
 
+        void incompatibleTypes(Type* pR0Type, Type* pType) {
+            error("Incompatible types old: %d new: %d", pR0Type->tag, pType->tag);
+        }
+
         size_t rotateRight(size_t n, size_t rotate) {
             return (n >> rotate) | (n << (32 - rotate));
         }
@@ -2762,10 +2734,6 @@
             return 5;
         }
 
-        virtual int disassemble(FILE* out) {
-            return 0;
-        }
-
         /* output a symbol and patch all calls to it */
         virtual void gsym(int t) {
             int n;
@@ -3093,10 +3061,6 @@
             return mpBase->jumpOffset();
         }
 
-        virtual int disassemble(FILE* out) {
-            return mpBase->disassemble(out);
-        }
-
         /* output a symbol and patch all calls to it */
         virtual void gsym(int t) {
             fprintf(stderr, "gsym(%d)\n", t);
@@ -5327,6 +5291,16 @@
         mLocals.add(pDecl);
     }
 
+    bool checkUndeclaredStruct(Type* pBaseType) {
+        if (pBaseType->tag == TY_STRUCT && pBaseType->length < 0) {
+            String temp;
+            decodeToken(temp, pBaseType->structTag, false);
+            error("Undeclared struct %s", temp.getUnwrapped());
+            return true;
+        }
+        return false;
+    }
+
     void localDeclarations(Type* pBaseType) {
         intptr_t a;
 
@@ -5339,6 +5313,9 @@
                 if (!pDecl->id) {
                     break;
                 }
+                if (checkUndeclaredStruct(pDecl)) {
+                    break;
+                }
                 int variableAddress = 0;
                 addLocalSymbol(pDecl);
                 size_t alignment = pGen->alignmentOf(pDecl);
@@ -5436,6 +5413,11 @@
                 continue;
             }
 
+            if (checkUndeclaredStruct(pDecl)) {
+                skip(';');
+                continue;
+            }
+
             if (! isDefined(pDecl->id)) {
                 addGlobalSymbol(pDecl);
             }
@@ -5716,15 +5698,6 @@
         return true;
     }
 
-    int dump(FILE* out) {
-        fwrite(codeBuf.getBase(), 1, codeBuf.getSize(), out);
-        return 0;
-    }
-
-    int disassemble(FILE* out) {
-        return pGen->disassemble(out);
-    }
-
     /* Look through the symbol table to find a symbol.
      * If found, return its value.
      */
@@ -5757,10 +5730,14 @@
         }
     }
 
+    void getProgramBinary(ACCvoid** base, ACCsizei* length) {
+        *base = codeBuf.getBase();
+        *length = (ACCsizei) codeBuf.getSize();
+    }
+
     char* getErrorMessage() {
         return mErrorBuf.getUnwrapped();
     }
-
 };
 
 const char* Compiler::operatorChars =
@@ -5774,10 +5751,6 @@
             2, 2 /* ~ ! */
             };
 
-#ifdef PROVIDE_ARM_CODEGEN
-FILE* Compiler::ARMCodeGenerator::disasmOut;
-#endif
-
 #ifdef PROVIDE_X86_CODEGEN
 const int Compiler::X86CodeGenerator::operatorHelper[] = {
         0x1,     // ++
@@ -5895,6 +5868,29 @@
         dest += len;
     }
     text[totalLength] = '\0';
+
+#ifdef DEBUG_SAVE_INPUT_TO_FILE
+    LOGD("Saving input to file...");
+    int counter;
+    char path[PATH_MAX];
+    for (counter = 0; counter < 4096; counter++) {
+        sprintf(path, DEBUG_DUMP_PATTERN, counter);
+        if(access(path, F_OK) != 0) {
+            break;
+        }
+    }
+    if (counter < 4096) {
+        LOGD("Saving input to file %s", path);
+        FILE* fd = fopen(path, "w");
+        if (fd) {
+            fwrite(text, totalLength, 1, fd);
+            fclose(fd);
+            LOGD("Saved input to file %s", path);
+        } else {
+            LOGD("Could not save. errno: %d", errno);
+        }
+    }
+#endif
 }
 
 extern "C"
@@ -5952,8 +5948,9 @@
 }
 
 extern "C"
-void accDisassemble(ACCscript* script) {
-    script->compiler.disassemble(stderr);
+void accGetProgramBinary(ACCscript* script,
+    ACCvoid** base, ACCsizei* length) {
+    script->compiler.getProgramBinary(base, length);
 }
 
 
diff --git a/libacc/tests/Android.mk b/libacc/tests/Android.mk
index 77e48be..e9fbe03 100644
--- a/libacc/tests/Android.mk
+++ b/libacc/tests/Android.mk
@@ -21,7 +21,8 @@
 LOCAL_MODULE:= acc
 
 LOCAL_SRC_FILES:= \
-	main.cpp
+	main.cpp \
+    disassem.cpp
 
 LOCAL_SHARED_LIBRARIES := \
     libacc
diff --git a/libacc/armreg.h b/libacc/tests/armreg.h
similarity index 100%
rename from libacc/armreg.h
rename to libacc/tests/armreg.h
diff --git a/libacc/disassem.cpp b/libacc/tests/disassem.cpp
similarity index 100%
rename from libacc/disassem.cpp
rename to libacc/tests/disassem.cpp
diff --git a/libacc/disassem.h b/libacc/tests/disassem.h
similarity index 100%
rename from libacc/disassem.h
rename to libacc/tests/disassem.h
diff --git a/libacc/tests/main.cpp b/libacc/tests/main.cpp
index 5e9e816..311fec0 100644
--- a/libacc/tests/main.cpp
+++ b/libacc/tests/main.cpp
@@ -20,6 +20,14 @@
 #include <unistd.h>
 #endif
 
+#if defined(__arm__)
+#define PROVIDE_ARM_DISASSEMBLY
+#endif
+
+#ifdef PROVIDE_ARM_DISASSEMBLY
+#include "disassem.h"
+#endif
+
 #include <acc/acc.h>
 
 
@@ -29,15 +37,57 @@
     return mainFunc(argc, argv);
 }
 
-// Private API for development:
-
-extern "C"
-void accDisassemble(ACCscript* script);
-
 ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) {
     return (ACCvoid*) dlsym(RTLD_DEFAULT, name);
 }
 
+#ifdef PROVIDE_ARM_DISASSEMBLY
+
+static FILE* disasmOut;
+
+static u_int
+disassemble_readword(u_int address)
+{
+    return(*((u_int *)address));
+}
+
+static void
+disassemble_printaddr(u_int address)
+{
+    fprintf(disasmOut, "0x%08x", address);
+}
+
+static void
+disassemble_printf(const char *fmt, ...) {
+    va_list ap;
+    va_start(ap, fmt);
+    vfprintf(disasmOut, fmt, ap);
+    va_end(ap);
+}
+
+static int disassemble(ACCscript* script, FILE* out) {
+    disasmOut = out;
+    disasm_interface_t  di;
+    di.di_readword = disassemble_readword;
+    di.di_printaddr = disassemble_printaddr;
+    di.di_printf = disassemble_printf;
+
+    ACCvoid* base;
+    ACCsizei length;
+
+    accGetProgramBinary(script, &base, &length);
+    unsigned long* pBase = (unsigned long*) base;
+    unsigned long* pEnd = (unsigned long*) (((unsigned char*) base) + length);
+
+    for(unsigned long* pInstruction = pBase; pInstruction < pEnd; pInstruction++) {
+        fprintf(out, "%08x: %08x  ", (int) pInstruction, *pInstruction);
+        ::disasm(&di, (uint) pInstruction, 0);
+    }
+    return 0;
+}
+
+#endif // PROVIDE_ARM_DISASSEMBLY
+
 int main(int argc, char** argv) {
     const char* inFile = NULL;
     bool printListing;
@@ -121,7 +171,9 @@
     }
 
     if (printListing) {
-        accDisassemble(script);
+#ifdef PROVIDE_ARM_DISASSEMBLY
+        disassemble(script, stderr);
+#endif
     }
 
     if (runResults) {
diff --git a/libzipfile/centraldir.c b/libzipfile/centraldir.c
index 0391c09..0e264a3 100644
--- a/libzipfile/centraldir.c
+++ b/libzipfile/centraldir.c
@@ -233,7 +233,7 @@
     len = (buf+bufsize)-p;

     for (i=0; i < file->totalEntryCount; i++) {

         Zipentry* entry = malloc(sizeof(Zipentry));

-        memset(entry, sizeof(Zipentry), 0);

+        memset(entry, 0, sizeof(Zipentry));

 

         err = read_central_directory_entry(file, entry, &p, &len);

         if (err != 0) {

diff --git a/rootdir/init.rc b/rootdir/init.rc
index 8365fd8..5d0c8b5 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -70,27 +70,24 @@
     # storing dumps on platforms which do not have a dedicated dump partition.
    
     mkdir /data/dontpanic
-    # STOPSHIP!
-    chmod 0777 /data/dontpanic
+    chown root system /data/dontpanic
+    chmod 0750 /data/dontpanic
 
     # Collect apanic data, free resources and re-arm trigger
     copy /proc/apanic_console /data/dontpanic/apanic_console
     chown root system /data/dontpanic/apanic_console
-    # STOPSHIP!
-    chmod 0664 /data/dontpanic/apanic_console
+    chmod 0640 /data/dontpanic/apanic_console
 
     copy /proc/apanic_threads /data/dontpanic/apanic_threads
     chown root system /data/dontpanic/apanic_threads
-    # STOPSHIP!
-    chmod 0664 /data/dontpanic/apanic_threads
+    chmod 0640 /data/dontpanic/apanic_threads
 
     write /proc/apanic_console 1
 
     # Collect ramconsole data
     copy /proc/last_kmsg /data/dontpanic/last_kmsg
     chown root system /data/dontpanic/last_kmsg
-    # STOPSHIP!
-    chmod 0664 /data/dontpanic/last_kmsg
+    chmod 0640 /data/dontpanic/last_kmsg
 
     # Same reason as /data above
     mount yaffs2 mtd@cache /cache nosuid nodev
diff --git a/vold/volmgr_vfat.c b/vold/volmgr_vfat.c
index 22e2dcf..4c695e4 100644
--- a/vold/volmgr_vfat.c
+++ b/vold/volmgr_vfat.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 
 #include <sys/mount.h>
+#include <cutils/properties.h>
 
 #include "vold.h"
 #include "volmgr.h"
@@ -108,14 +109,29 @@
     }
 
     /*
-     * The mount masks restrict access so that:
-     * 1. The 'system' user cannot access the SD card at all - 
-     *    (protects system_server from grabbing file references)
-     * 2. Group users can RWX
-     * 3. Others can only RX
+     * Note: This is a temporary hack. If the sampling profiler is enabled,
+     * we make the SD card world-writable so any process can write snapshots.
+     *
+     * TODO: Remove this code once we have a drop box in system_server.
      */
-    rc = mount(devpath, vol->mount_point, "vfat", flags,
-               "utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
+    char value[PROPERTY_VALUE_MAX];
+    property_get("persist.sampling_profiler", value, "");
+    if (value[0] == '1') {
+        LOGW("The SD card is world-writable because the"
+            " 'persist.sampling_profiler' system property is set to '1'.");
+        rc = mount(devpath, vol->mount_point, "vfat", flags,
+                "utf8,uid=1000,gid=1015,fmask=000,dmask=000,shortname=mixed");
+    } else {
+        /*
+         * The mount masks restrict access so that:
+         * 1. The 'system' user cannot access the SD card at all -
+         *    (protects system_server from grabbing file references)
+         * 2. Group users can RWX
+         * 3. Others can only RX
+         */
+        rc = mount(devpath, vol->mount_point, "vfat", flags,
+                "utf8,uid=1000,gid=1015,fmask=702,dmask=702,shortname=mixed");
+    }
 
     if (rc && errno == EROFS) {
         LOGE("vfat_mount(%d:%d, %s): Read only filesystem - retrying mount RO",