system/core LP64 cleanup.

Fixes -Wint-to-pointer and -Wpointer-to-int warnings, plus various -Wformat
warnings.

Change-Id: I6c5eea6b4273d82d28b8e5d2925f3e5457511b17
diff --git a/debuggerd/crasher.c b/debuggerd/crasher.c
index 0033948..5a2bc3c 100644
--- a/debuggerd/crasher.c
+++ b/debuggerd/crasher.c
@@ -57,13 +57,13 @@
 
 static void *noisy(void *x)
 {
-    char c = (unsigned) x;
+    char c = (uintptr_t) x;
     for(;;) {
         usleep(250*1000);
         write(2, &c, 1);
         if(c == 'C') *((unsigned*) 0) = 42;
     }
-    return 0;
+    return NULL;
 }
 
 static int ctest()
@@ -81,7 +81,7 @@
 
 static void* thread_callback(void* raw_arg)
 {
-    return (void*) do_action((const char*) raw_arg);
+    return (void*) (uintptr_t) do_action((const char*) raw_arg);
 }
 
 static int do_action_on_thread(const char* arg)
@@ -90,7 +90,7 @@
     pthread_create(&t, NULL, thread_callback, (void*) arg);
     void* result = NULL;
     pthread_join(t, &result);
-    return (int) result;
+    return (int) (uintptr_t) result;
 }
 
 __attribute__((noinline)) static int crash3(int a) {
diff --git a/fastbootd/commands.c b/fastbootd/commands.c
index 063e1a6..98b7866 100644
--- a/fastbootd/commands.c
+++ b/fastbootd/commands.c
@@ -124,9 +124,9 @@
         goto error;
     }
 
-    kernel_ptr = (void *)((unsigned) ptr + hdr->page_size);
-    ramdisk_ptr = (void *)((unsigned) kernel_ptr + kernel_actual);
-    second_ptr = (void *)((unsigned) ramdisk_ptr + ramdisk_actual);
+    kernel_ptr = (void *)((uintptr_t) ptr + hdr->page_size);
+    ramdisk_ptr = (void *)((uintptr_t) kernel_ptr + kernel_actual);
+    second_ptr = (void *)((uintptr_t) ramdisk_ptr + ramdisk_actual);
 
     D(INFO, "preparing to boot");
     // Prepares boot physical address. Addresses from header are ignored
diff --git a/fastbootd/commands/boot.c b/fastbootd/commands/boot.c
index 8da9a28..922914b 100644
--- a/fastbootd/commands/boot.c
+++ b/fastbootd/commands/boot.c
@@ -89,10 +89,10 @@
  * Kernel address is not set into kernel_phys
  * Ramdisk is set to position relative to kernel
  */
-int prepare_boot_linux(unsigned kernel_phys, void *kernel_addr, int kernel_size,
-                       unsigned ramdisk_phys, void *ramdisk_addr, int ramdisk_size,
-                       unsigned second_phys, void *second_addr, int second_size,
-                       unsigned atags_phys, void *atags_addr, int atags_size) {
+int prepare_boot_linux(uintptr_t kernel_phys, void *kernel_addr, int kernel_size,
+                       uintptr_t ramdisk_phys, void *ramdisk_addr, int ramdisk_size,
+                       uintptr_t second_phys, void *second_addr, int second_size,
+                       uintptr_t atags_phys, void *atags_addr, int atags_size) {
     struct kexec_segment segment[4];
     int segment_count = 2;
     unsigned entry = START_ADDRESS + KEXEC_ARM_ZIMAGE_OFFSET;
diff --git a/fastbootd/commands/boot.h b/fastbootd/commands/boot.h
index 901c38a..a5efd01 100644
--- a/fastbootd/commands/boot.h
+++ b/fastbootd/commands/boot.h
@@ -40,8 +40,8 @@
 #define KEXEC_TYPE_DEFAULT 0
 #define KEXEC_TYPE_CRASH   1
 
-int prepare_boot_linux(unsigned, void *, int, unsigned, void *, int,
-                       unsigned, void *, int, unsigned, void *, int);
+int prepare_boot_linux(uintptr_t, void *, int, uintptr_t, void *, int,
+                       uintptr_t, void *, int, uintptr_t, void *, int);
 unsigned *create_atags(unsigned *, int, const struct boot_img_hdr *, int *);
 long kexec_load(unsigned int, unsigned long, struct kexec_segment *, unsigned long);
 char *read_atags(const char *, int *);
diff --git a/fastbootd/protocol.c b/fastbootd/protocol.c
index 0086b4a..3908020 100644
--- a/fastbootd/protocol.c
+++ b/fastbootd/protocol.c
@@ -142,7 +142,7 @@
     char response[64];
     ssize_t ret;
 
-    snprintf(response, 64, "DATA%08x", len);
+    snprintf(response, 64, "DATA%08zx", len);
     ret = protocol_handle_write(phandle, response, strlen(response));
     if (ret < 0)
         return;
diff --git a/liblog/tests/benchmark_main.cpp b/liblog/tests/benchmark_main.cpp
index 02df460..090394c 100644
--- a/liblog/tests/benchmark_main.cpp
+++ b/liblog/tests/benchmark_main.cpp
@@ -16,6 +16,7 @@
 
 #include <benchmark.h>
 
+#include <inttypes.h>
 #include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -158,10 +159,10 @@
     sdev = (sqrt((double)nXvariance) / gBenchmarkNum / gBenchmarkNum) + 0.5;
   }
   if (mean > (10000 * sdev)) {
-    printf("%-25s %10llu %10llu%s\n", full_name,
+    printf("%-25s %10" PRIu64 " %10" PRIu64 "%s\n", full_name,
             static_cast<uint64_t>(iterations), mean, throughput);
   } else {
-    printf("%-25s %10llu %10llu(\317\203%llu)%s\n", full_name,
+    printf("%-25s %10" PRIu64 " %10" PRIu64 "(\317\203%" PRIu64 ")%s\n", full_name,
            static_cast<uint64_t>(iterations), mean, sdev, throughput);
   }
   fflush(stdout);
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 9ae8f22..d71d97a 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -15,6 +15,7 @@
  */
 
 #include <fcntl.h>
+#include <inttypes.h>
 #include <signal.h>
 #include <gtest/gtest.h>
 #include <log/log.h>
@@ -85,8 +86,8 @@
 
 static void* ConcurrentPrintFn(void *arg) {
     int ret = __android_log_buf_print(LOG_ID_MAIN, ANDROID_LOG_INFO,
-                                  "TEST__android_log_print", "Concurrent %d",
-                                  reinterpret_cast<int>(arg));
+                                  "TEST__android_log_print", "Concurrent %" PRIuPTR,
+                                  reinterpret_cast<uintptr_t>(arg));
     return reinterpret_cast<void*>(ret);
 }
 
@@ -106,8 +107,9 @@
     for (i=0; i < NUM_CONCURRENT; i++) {
         void* result;
         ASSERT_EQ(0, pthread_join(t[i], &result));
-        if ((0 == ret) && (0 != reinterpret_cast<int>(result))) {
-            ret = reinterpret_cast<int>(result);
+        int this_result = reinterpret_cast<uintptr_t>(result);
+        if ((0 == ret) && (0 != this_result)) {
+            ret = this_result;
         }
     }
     ASSERT_LT(0, ret);
diff --git a/libnl_2/Android.mk b/libnl_2/Android.mk
index deac9de..3721fc6 100644
--- a/libnl_2/Android.mk
+++ b/libnl_2/Android.mk
@@ -26,6 +26,7 @@
 # Static Library
 LOCAL_MODULE := libnl_2
 LOCAL_MODULE_TAGS := optional
+LOCAL_32_BIT_ONLY := true
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
@@ -34,4 +35,5 @@
 LOCAL_SHARED_LIBRARIES:= liblog
 LOCAL_MODULE := libnl_2
 LOCAL_MODULE_TAGS := optional
+LOCAL_32_BIT_ONLY := true
 include $(BUILD_SHARED_LIBRARY)
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index 05fbfba..4722708 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -200,7 +200,7 @@
 }
 
 static int int_hash(void *key) {
-    return (int) key;
+    return (int) (uintptr_t) key;
 }
 
 static bool int_equals(void *keyA, void *keyB) {
@@ -487,7 +487,7 @@
         break;
     case PERM_ANDROID_DATA:
     case PERM_ANDROID_OBB:
-        appid = (appid_t) hashmapGet(fuse->package_to_appid, node->name);
+        appid = (appid_t) (uintptr_t) hashmapGet(fuse->package_to_appid, node->name);
         if (appid != 0) {
             node->uid = multiuser_get_uid(parent->userid, appid);
         }
@@ -511,7 +511,7 @@
     }
 
     appid_t appid = multiuser_get_app_id(hdr->uid);
-    return hashmapContainsKey(fuse->appid_with_rw, (void*) appid);
+    return hashmapContainsKey(fuse->appid_with_rw, (void*) (uintptr_t) appid);
 }
 
 /* Kernel has already enforced everything we returned through
@@ -1621,12 +1621,12 @@
 
         if (sscanf(buf, "%s %d %*d %*s %*s %s", package_name, &appid, gids) == 3) {
             char* package_name_dup = strdup(package_name);
-            hashmapPut(fuse->package_to_appid, package_name_dup, (void*) appid);
+            hashmapPut(fuse->package_to_appid, package_name_dup, (void*) (uintptr_t) appid);
 
             char* token = strtok(gids, ",");
             while (token != NULL) {
                 if (strtoul(token, NULL, 10) == fuse->write_gid) {
-                    hashmapPut(fuse->appid_with_rw, (void*) appid, (void*) 1);
+                    hashmapPut(fuse->appid_with_rw, (void*) (uintptr_t) appid, (void*) (uintptr_t) 1);
                     break;
                 }
                 token = strtok(NULL, ",");