Merge "Return back EAI_ADDRFAMILY definition needed for libnl-2.0"
diff --git a/libc/Android.mk b/libc/Android.mk
index 647739e..f4f9c13 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -715,8 +715,7 @@
 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
-# Don't prelink
-LOCAL_PRELINK_MODULE := false
+
 # Don't install on release build
 LOCAL_MODULE_TAGS := eng debug
 
@@ -742,8 +741,7 @@
 LOCAL_SHARED_LIBRARIES := libc
 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
-# Don't prelink
-LOCAL_PRELINK_MODULE := false
+
 # Don't install on release build
 LOCAL_MODULE_TAGS := eng debug
 
diff --git a/libc/arch-x86/bionic/crtbegin_dynamic.S b/libc/arch-x86/bionic/crtbegin_dynamic.S
index 88e7e6a..0a7bc62 100644
--- a/libc/arch-x86/bionic/crtbegin_dynamic.S
+++ b/libc/arch-x86/bionic/crtbegin_dynamic.S
@@ -66,14 +66,7 @@
 1:  .long   __PREINIT_ARRAY__
     .long   __INIT_ARRAY__
     .long   __FINI_ARRAY__
-    .long   __CTOR_LIST__
-      
-# the .ctors section contains a list of pointers to "constructor"
-# functions that need to be called in order during C library initialization,
-# just before the program is being run. This is a C++ requirement
-#
-# the last entry shall be 0, and is defined in crtend.S
-#
+
 	.section .preinit_array, "aw"
 	.globl __PREINIT_ARRAY__
 __PREINIT_ARRAY__:
@@ -89,9 +82,4 @@
 __FINI_ARRAY__:
 	.long -1
 
-	.section .ctors, "aw"
-	.globl __CTOR_LIST__
-__CTOR_LIST__:
-	.long -1
-
 #include "__dso_handle.S"
diff --git a/libc/arch-x86/bionic/crtbegin_so.S b/libc/arch-x86/bionic/crtbegin_so.S
index d879fef..b3a01b5 100644
--- a/libc/arch-x86/bionic/crtbegin_so.S
+++ b/libc/arch-x86/bionic/crtbegin_so.S
@@ -5,15 +5,6 @@
     call __cxa_finalize
     ret
 
-/* we put the _init() function here in case the user files for the shared
- * libs want to drop things into .init section.
- * We then will call our ctors from crtend_so.o */
-.section .init
-.align 4
-.type _init, @function
-.globl _init
-_init:
-
 .section .init_array, "aw"
 .align 4
 .type __INIT_ARRAY__, @object
@@ -29,11 +20,4 @@
     .long -1
     .long _on_dlclose
 
-.section .ctors, "aw"
-.align 4
-.type __CTOR_LIST__, @object
-.globl __CTOR_LIST__
-__CTOR_LIST__:
-        .long -1
-
 #include "__dso_handle.S"
diff --git a/libc/arch-x86/bionic/crtbegin_static.S b/libc/arch-x86/bionic/crtbegin_static.S
index 3f8446e..d5c2430 100644
--- a/libc/arch-x86/bionic/crtbegin_static.S
+++ b/libc/arch-x86/bionic/crtbegin_static.S
@@ -65,7 +65,6 @@
 1:  .long   __PREINIT_ARRAY__
     .long   __INIT_ARRAY__
     .long   __FINI_ARRAY__
-    .long   __CTOR_LIST__
 
 	.section .preinit_array, "aw"
 	.globl __PREINIT_ARRAY__
@@ -82,9 +81,4 @@
 __FINI_ARRAY__:
 	.long -1
 
-	.section .ctors, "aw"
-	.globl __CTOR_LIST__
-__CTOR_LIST__:
-	.long -1
-
 #include "__dso_handle.S"
diff --git a/libc/arch-x86/bionic/crtend.S b/libc/arch-x86/bionic/crtend.S
index 7f5fb66..884ba8b 100644
--- a/libc/arch-x86/bionic/crtend.S
+++ b/libc/arch-x86/bionic/crtend.S
@@ -1,4 +1,3 @@
-	
 	.section .preinit_array, "aw"
 	.long 0
 
@@ -7,7 +6,3 @@
 
 	.section .fini_array, "aw"
 	.long 0
-
-	.section .ctors, "aw"
-	.long 0
-
diff --git a/libc/arch-x86/bionic/crtend_so.S b/libc/arch-x86/bionic/crtend_so.S
index 7fb2280..8c9d419 100644
--- a/libc/arch-x86/bionic/crtend_so.S
+++ b/libc/arch-x86/bionic/crtend_so.S
@@ -1,44 +1,3 @@
-.text
-.align 4
-.type __bionic_call_ctors, @function
-
-/*
- * The CTORS_LIST is marked by -1 (start) and 0 (end).
- * We mark the end of the .ctors section with the __CTOR_END__ section so
- * that we can just iterate backwards from it until we hit -1 and execute
- * all the function pointers. This seems to be the way to do it for SVR4
- * derived systems.
- */
-__bionic_call_ctors:
-    pushl  %esi
-    mov    $__CTOR_END__, %esi
-
-0:
-    /* now grab the next function pointer and check if its -1. If not,
-     * call it, otherwise we're done. We use %esi since it's callee saved.
-     */
-    subl    $4, %esi
-    mov     (%esi), %eax
-    cmp     $0xffffffff, %eax
-    je      1f
-    call    *%eax
-    jmp     0b
-
-1:
-    /* we're done */
-    popl    %esi
-    ret
-
-.section .init
-.align 4
-    call __bionic_call_ctors
-    ret
-
-.section .ctors, "aw", @progbits
-.align 4
-.type __CTOR_END__, @object
-__CTOR_END__:
-    .long 0
 
 .section .init_array, "aw"
     .long 0
diff --git a/libc/bionic/libc_init_common.h b/libc/bionic/libc_init_common.h
index 6016d4d..35050a1 100644
--- a/libc/bionic/libc_init_common.h
+++ b/libc/bionic/libc_init_common.h
@@ -35,7 +35,9 @@
     void (**preinit_array)(void);
     void (**init_array)(void);
     void (**fini_array)(void);
+#ifndef __i386__
     void (**ctors_array)(void);
+#endif
 } structors_array_t;
 
 extern void __libc_init_common(uintptr_t *elfdata);
diff --git a/libc/bionic/libc_init_static.c b/libc/bionic/libc_init_static.c
index 3634c7b..a2c11a9 100644
--- a/libc/bionic/libc_init_static.c
+++ b/libc/bionic/libc_init_static.c
@@ -75,8 +75,10 @@
     /* pre-init array. */
     call_array(structors->preinit_array);
 
+#ifndef __i386__
     /* .ctors section initializers, for non-arm-eabi ABIs */
     call_array(structors->ctors_array);
+#endif
 
     // call static constructors
     call_array(structors->init_array);
diff --git a/libc/bionic/md5.c b/libc/bionic/md5.c
index 1117c3b..ba4aaed 100644
--- a/libc/bionic/md5.c
+++ b/libc/bionic/md5.c
@@ -38,6 +38,7 @@
         "$NetBSD: md5.c,v 1.1.1.4 2002/09/12 12:41:42 joda Exp $");
 #endif
 
+#include <endian.h>
 #include "md5.h"
 #include "hash.h"
 
@@ -178,8 +179,11 @@
 /*
  * From `Performance analysis of MD5' by Joseph D. Touch <touch@isi.edu>
  */
+#if !defined(__BYTE_ORDER) || !defined (__BIG_ENDIAN)
+#error __BYTE_ORDER macros not defined
+#endif
 
-#if defined(WORDS_BIGENDIAN)
+#if __BYTE_ORDER == __BIG_ENDIAN
 static inline u_int32_t
 swap_u_int32_t (u_int32_t t)
 {
@@ -217,7 +221,7 @@
     p += l;
     len -= l;
     if(offset == 64){
-#if defined(WORDS_BIGENDIAN)
+#if __BYTE_ORDER == __BIG_ENDIAN
       int i;
       u_int32_t current[16];
       struct x32 *u = (struct x32*)m->save;
diff --git a/libc/bionic/system_properties.c b/libc/bionic/system_properties.c
index 767baa3..c40950f 100644
--- a/libc/bionic/system_properties.c
+++ b/libc/bionic/system_properties.c
@@ -38,13 +38,14 @@
 #include <sys/select.h>
 #include <sys/types.h>
 #include <netinet/in.h>
+#include <unistd.h>
 
 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
 #include <sys/_system_properties.h>
 
 #include <sys/atomics.h>
 
-static const char property_service_name[] = PROP_SERVICE_NAME;
+static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
 
 static unsigned dummy_props = 0;
 
@@ -152,6 +153,114 @@
     }
 }
 
+
+static int send_prop_msg(prop_msg *msg)
+{
+    struct sockaddr_un addr;
+    socklen_t alen;
+    size_t namelen;
+    int s;
+    int r;
+
+    s = socket(AF_LOCAL, SOCK_STREAM, 0);
+    if(s < 0) {
+        return -1;
+    }
+
+    memset(&addr, 0, sizeof(addr));
+    namelen = strlen(property_service_socket);
+    strlcpy(addr.sun_path, property_service_socket, sizeof addr.sun_path);
+    addr.sun_family = AF_LOCAL;
+    alen = namelen + offsetof(struct sockaddr_un, sun_path) + 1;
+
+    if(TEMP_FAILURE_RETRY(connect(s, (struct sockaddr *) &addr, alen) < 0)) {
+        close(s);
+        return -1;
+    }
+
+    r = TEMP_FAILURE_RETRY(send(s, msg, sizeof(prop_msg), 0));
+
+    if(r == sizeof(prop_msg)) {
+        r = 0;
+    } else {
+        r = -1;
+    }
+
+    close(s);
+    return r;
+}
+
+int __system_property_set(const char *key, const char *value)
+{
+    unsigned old_serial;
+    volatile unsigned *serial;
+    prop_msg msg;
+    int err;
+    prop_area *pa = __system_property_area__;
+    int tries = 0;
+    int update_seen = 0;
+
+    if(key == 0) return -1;
+    if(value == 0) value = "";
+    if(strlen(key) >= PROP_NAME_MAX) return -1;
+    if(strlen(value) >= PROP_VALUE_MAX) return -1;
+
+    memset(&msg, 0, sizeof msg);
+    msg.cmd = PROP_MSG_SETPROP;
+    strlcpy(msg.name, key, sizeof msg.name);
+    strlcpy(msg.value, value, sizeof msg.value);
+
+    /* Note the system properties serial number before we do our update. */
+    const prop_info *pi = __system_property_find(key);
+    if(pi != NULL) {
+        serial = &pi->serial;
+    } else {
+        serial = &pa->serial;
+    }
+    old_serial = *serial;
+
+    err = send_prop_msg(&msg);
+    if(err < 0) {
+        return err;
+    }
+
+    /**
+     * Wait for the shared memory page to be written back and be
+     * visible in our address space before returning to the caller
+     * who might reasonably expect subsequent reads to match what was
+     * just written.
+     *
+     * Sleep 5 ms after failed checks and only wait up to a 500 ms
+     * total, just in case the system property server fails to update
+     * for whatever reason.
+     */
+    do {
+        struct timespec timeout;
+        timeout.tv_sec = 0;
+        timeout.tv_nsec = 2500000;  // 2.5 ms
+
+        if(tries++ > 0) {
+            usleep(2500); // 2.5 ms
+        }
+        __futex_wait(serial, old_serial, &timeout);
+        if(pi != NULL) {
+            unsigned new_serial = *serial;
+            /* Waiting on a specific prop_info to be updated. */
+            if (old_serial != new_serial && !SERIAL_DIRTY(new_serial)) {
+                update_seen = 1;
+            }
+        } else {
+            /* Waiting for a prop_info to be created. */
+            const prop_info *new_pi = __system_property_find(key);
+            if(new_pi != NULL && !SERIAL_DIRTY(new_pi->serial)) {
+                update_seen = 1;
+            }
+        }
+    } while (!update_seen && tries < 100);
+
+    return 0;
+}
+
 int __system_property_wait(const prop_info *pi)
 {
     unsigned n;
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index a43e47c..9d05769 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -103,7 +103,7 @@
 /*
  * Prototypes
  */
-#if __cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -233,7 +233,7 @@
     void*            reserved[4];  /* for future extensibility */
 } pthread_rwlock_t;
 
-#define PTHREAD_RWLOCK_INITIALIZER  { PTHREAD_MUTEX_INITIALIZER, 0, NULL, 0, 0 }
+#define PTHREAD_RWLOCK_INITIALIZER  { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0, 0, 0, { NULL, NULL, NULL, NULL } }
 
 int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
@@ -302,7 +302,7 @@
         __pthread_cleanup_pop( &__cleanup, (execute)); \
     } while (0);
 
-#if __cplusplus
+#ifdef __cplusplus
 } /* extern "C" */
 #endif
 
diff --git a/libc/include/stdint.h b/libc/include/stdint.h
index 237baa2..e791475 100644
--- a/libc/include/stdint.h
+++ b/libc/include/stdint.h
@@ -41,11 +41,6 @@
 #  define  __STDINT_MACROS
 #endif
 
-/* the definitions of STDINT_LIMITS depend on those of STDINT_MACROS */
-#if defined __STDINT_LIMITS && !defined __STDINT_MACROS
-#  define  __STDINT_MACROS
-#endif
-
 #if !defined __STRICT_ANSI__ || __STDC_VERSION__ >= 199901L
 #  define __STDC_INT64__
 #endif
@@ -185,13 +180,14 @@
 #  define UINT_FAST64_MAX UINT64_MAX
 #endif
 
+#define __INT64_C(c)     c ## LL
+#define __UINT64_C(c)     c ## ULL
+
 #ifdef __STDINT_MACROS
-#  define __INT64_C(c)     c ## LL
 #  define INT64_C(c)       __INT64_C(c)
 #  define INT_LEAST64_C(c) INT64_C(c)
 #  define INT_FAST64_C(c)  INT64_C(c)
 
-#  define __UINT64_C(c)     c ## ULL
 #  define UINT64_C(c)       __UINT64_C(c)
 #  define UINT_LEAST64_C(c) UINT64_C(c)
 #  define UINT_FAST64_C(c)  UINT64_C(c)
@@ -211,14 +207,20 @@
 typedef int           intptr_t;
 typedef unsigned int  uintptr_t;
 
+#ifdef __STDINT_LIMITS
 #  define INTPTR_MIN    INT32_MIN
 #  define INTPTR_MAX    INT32_MAX
 #  define UINTPTR_MAX   UINT32_MAX
+#  define PTRDIFF_MIN   INT32_MIN
+#  define PTRDIFF_MAX   INT32_MAX
+#endif
+
+#ifdef __STDINT_MACROS
 #  define INTPTR_C(c)   INT32_C(c)
 #  define UINTPTR_C(c)  UINT32_C(c)
 #  define PTRDIFF_C(c)  INT32_C(c)
-#  define PTRDIFF_MIN   INT32_MIN
-#  define PTRDIFF_MAX   INT32_MAX
+#endif
+
 
 
 /*
@@ -230,24 +232,32 @@
 typedef uint64_t uintmax_t;
 typedef int64_t  intmax_t;
 
-#define INTMAX_MIN	INT64_MIN
-#define INTMAX_MAX	INT64_MAX
-#define UINTMAX_MAX	UINT64_MAX
+#ifdef __STDINT_LIMITS
+#  define INTMAX_MIN	INT64_MIN
+#  define INTMAX_MAX	INT64_MAX
+#  define UINTMAX_MAX	UINT64_MAX
+#endif
 
-#define INTMAX_C(c)	INT64_C(c)
-#define UINTMAX_C(c)	UINT64_C(c)
+#ifdef __STDINT_MACROS
+#  define INTMAX_C(c)	INT64_C(c)
+#  define UINTMAX_C(c)	UINT64_C(c)
+#endif
 
 #else /* !__STDC_INT64__ */
 
 typedef uint32_t  uintmax_t;
 typedef int32_t   intmax_t;
 
-#define  INTMAX_MIN    INT32_MIN
-#define  INTMAX_MAX    INT32_MAX
-#define  UINTMAX_MAX   UINT32_MAX
+#ifdef __STDINT_LIMITS
+#  define  INTMAX_MIN    INT32_MIN
+#  define  INTMAX_MAX    INT32_MAX
+#  define  UINTMAX_MAX   UINT32_MAX
+#endif
 
-#define INTMAX_C(c)	INT32_C(c)
-#define UINTMAX_C(c)	UINT32_C(c)
+#ifdef __STDINT_MACROS
+#  define INTMAX_C(c)	INT32_C(c)
+#  define UINTMAX_C(c)	UINT32_C(c)
+#endif
 
 #endif /* !__STDC_INT64__ */
 
diff --git a/libc/include/sys/system_properties.h b/libc/include/sys/system_properties.h
index 4fdc944..85915b2 100644
--- a/libc/include/sys/system_properties.h
+++ b/libc/include/sys/system_properties.h
@@ -46,6 +46,10 @@
 */
 int __system_property_get(const char *name, char *value);
 
+/* Set a system property by name.
+**/
+int __system_property_set(const char *key, const char *value);
+
 /* Return a pointer to the system property named name, if it
 ** exists, or NULL if there is no such property.  Use 
 ** __system_property_read() to obtain the string value from
diff --git a/libc/kernel/common/linux/nvhdcp.h b/libc/kernel/common/linux/nvhdcp.h
new file mode 100644
index 0000000..d21ea55
--- /dev/null
+++ b/libc/kernel/common/linux/nvhdcp.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _LINUX_NVHDCP_H_
+#define _LINUX_NVHDCP_H_
+#include <linux/fb.h>
+#include <linux/types.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#include <asm/ioctl.h>
+#define TEGRA_NVHDCP_MAX_DEVS 127
+#define TEGRA_NVHDCP_FLAG_AN 0x0001
+#define TEGRA_NVHDCP_FLAG_AKSV 0x0002
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TEGRA_NVHDCP_FLAG_BKSV 0x0004
+#define TEGRA_NVHDCP_FLAG_BSTATUS 0x0008  
+#define TEGRA_NVHDCP_FLAG_CN 0x0010  
+#define TEGRA_NVHDCP_FLAG_CKSV 0x0020  
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TEGRA_NVHDCP_FLAG_DKSV 0x0040  
+#define TEGRA_NVHDCP_FLAG_KP 0x0080  
+#define TEGRA_NVHDCP_FLAG_S 0x0100  
+#define TEGRA_NVHDCP_FLAG_CS 0x0200  
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TEGRA_NVHDCP_FLAG_V 0x0400
+#define TEGRA_NVHDCP_FLAG_MP 0x0800
+#define TEGRA_NVHDCP_FLAG_BKSVLIST 0x1000
+#define TEGRA_NVHDCP_RESULT_SUCCESS 0
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TEGRA_NVHDCP_RESULT_UNSUCCESSFUL 1
+#define TEGRA_NVHDCP_RESULT_PENDING 0x103
+#define TEGRA_NVHDCP_RESULT_LINK_FAILED 0xc0000013
+#define TEGRA_NVHDCP_RESULT_INVALID_PARAMETER 0xc000000d
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TEGRA_NVHDCP_RESULT_INVALID_PARAMETER_MIX 0xc0000030
+#define TEGRA_NVHDCP_RESULT_NO_MEMORY 0xc0000017
+struct tegra_nvhdcp_packet {
+ __u32 value_flags;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 packet_results;
+ __u64 c_n;
+ __u64 c_ksv;
+ __u32 b_status;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 hdcp_status;
+ __u64 cs;
+ __u64 k_prime;
+ __u64 a_n;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 a_ksv;
+ __u64 b_ksv;
+ __u64 d_ksv;
+ __u8 v_prime[20];
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u64 m_prime;
+ __u32 num_bksv_list;
+ __u64 bksv_list[TEGRA_NVHDCP_MAX_DEVS];
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TEGRA_NVHDCP_POLICY_ON_DEMAND 0
+#define TEGRA_NVHDCP_POLICY_ALWAYS_ON 1
+#define TEGRAIO_NVHDCP_ON _IO('F', 0x70)
+#define TEGRAIO_NVHDCP_OFF _IO('F', 0x71)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define TEGRAIO_NVHDCP_SET_POLICY _IOW('F', 0x72, __u32)
+#define TEGRAIO_NVHDCP_READ_M _IOWR('F', 0x73, struct tegra_nvhdcp_packet)
+#define TEGRAIO_NVHDCP_READ_S _IOWR('F', 0x74, struct tegra_nvhdcp_packet)
+#define TEGRAIO_NVHDCP_RENEGOTIATE _IO('F', 0x75)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#endif
+
diff --git a/libc/kernel/common/linux/usb/f_accessory.h b/libc/kernel/common/linux/usb/f_accessory.h
index 84a8917..7ee9b7f 100644
--- a/libc/kernel/common/linux/usb/f_accessory.h
+++ b/libc/kernel/common/linux/usb/f_accessory.h
@@ -24,15 +24,20 @@
 #define USB_ACCESSORY_ADB_PRODUCT_ID 0x2D01
 #define ACCESSORY_STRING_MANUFACTURER 0
 #define ACCESSORY_STRING_MODEL 1
-#define ACCESSORY_STRING_TYPE 2
+#define ACCESSORY_STRING_DESCRIPTION 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ACCESSORY_STRING_VERSION 3
+#define ACCESSORY_STRING_URI 4
+#define ACCESSORY_STRING_SERIAL 5
+#define ACCESSORY_GET_PROTOCOL 51
 #define ACCESSORY_SEND_STRING 52
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ACCESSORY_START 53
 #define ACCESSORY_GET_STRING_MANUFACTURER _IOW('M', 1, char[256])
-/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define ACCESSORY_GET_STRING_MODEL _IOW('M', 2, char[256])
-#define ACCESSORY_GET_STRING_TYPE _IOW('M', 3, char[256])
-#define ACCESSORY_GET_STRING_VERSION _IOW('M', 4, char[256])
-#endif
+#define ACCESSORY_GET_STRING_DESCRIPTION _IOW('M', 3, char[256])
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define ACCESSORY_GET_STRING_VERSION _IOW('M', 4, char[256])
+#define ACCESSORY_GET_STRING_URI _IOW('M', 5, char[256])
+#define ACCESSORY_GET_STRING_SERIAL _IOW('M', 6, char[256])
+#endif
diff --git a/libc/netbsd/net/getaddrinfo.c b/libc/netbsd/net/getaddrinfo.c
index bb6645c..edb4f70 100644
--- a/libc/netbsd/net/getaddrinfo.c
+++ b/libc/netbsd/net/getaddrinfo.c
@@ -541,6 +541,7 @@
 		if (fread(&name_len, sizeof(name_len), 1, proxy) != 1) {
 			break;
 		}
+		name_len = ntohl(name_len);
 		if (name_len != 0) {
 			ai->ai_canonname = (char*) malloc(name_len);
 			if (fread(ai->ai_canonname, name_len, 1, proxy) != 1) {
diff --git a/libc/netbsd/net/getnameinfo.c b/libc/netbsd/net/getnameinfo.c
index 3666443..0b9fe51 100644
--- a/libc/netbsd/net/getnameinfo.c
+++ b/libc/netbsd/net/getnameinfo.c
@@ -64,6 +64,11 @@
 #include <netdb.h>
 #ifdef ANDROID_CHANGES
 #include "resolv_private.h"
+#include <sys/system_properties.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/un.h>
+#include <errno.h>
 #else
 #include <resolv.h>
 #endif
@@ -124,7 +129,93 @@
 	}
 }
 
+#ifdef ANDROID_CHANGES
+/* On success length of the host name is returned. A return
+ * value of 0 means there's no host name associated with
+ * the address. On failure -1 is returned in which case
+ * normal execution flow shall continue. */
+static int
+android_gethostbyaddr_proxy(struct hostent* hp, const char *addr, socklen_t addrLen, int addrFamily) {
 
+	int sock;
+	const int one = 1;
+	struct sockaddr_un proxy_addr;
+	const char* cache_mode = getenv("ANDROID_DNS_MODE");
+	FILE* proxy = NULL;
+	int result = -1;
+
+	if (cache_mode != NULL && strcmp(cache_mode, "local") == 0) {
+		// Don't use the proxy in local mode.  This is used by the
+		// proxy itself.
+		return -1;
+	}
+
+	// Temporary cautious hack to disable the DNS proxy for processes
+	// requesting special treatment.  Ideally the DNS proxy should
+	// accomodate these apps, though.
+	char propname[PROP_NAME_MAX];
+	char propvalue[PROP_VALUE_MAX];
+	snprintf(propname, sizeof(propname), "net.dns1.%d", getpid());
+	if (__system_property_get(propname, propvalue) > 0) {
+		return -1;
+	}
+	// create socket
+	sock = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+	memset(&proxy_addr, 0, sizeof(proxy_addr));
+	proxy_addr.sun_family = AF_UNIX;
+	strlcpy(proxy_addr.sun_path, "/dev/socket/dnsproxyd",
+			sizeof(proxy_addr.sun_path));
+	if (TEMP_FAILURE_RETRY(connect(sock, (const struct sockaddr*) &proxy_addr,
+							sizeof(proxy_addr))) != 0) {
+		close(sock);
+		return -1;
+	}
+
+	// send request to DnsProxyListener
+	proxy = fdopen(sock,"r+");
+	if (proxy == NULL) {
+		goto exit;
+	}
+
+	if (fprintf(proxy, "gethostbyaddr %s %d %d", addr, addrLen, addrFamily) < 0) {
+		goto exit;
+	}
+
+	// literal NULL byte at end, required by FrameworkListener
+	if (fputc(0, proxy) == EOF || fflush(proxy) != 0) {
+		goto exit;
+	}
+
+	result = 0;
+	uint32_t name_len;
+	if (fread(&name_len, sizeof(name_len), 1, proxy) != 1) {
+		goto exit;
+	}
+
+	name_len = ntohl(name_len);
+	if (name_len <= 0) {
+		goto exit;
+	}
+
+	if (fread(hp->h_name, name_len, 1, proxy) != 1) {
+		goto exit;
+	}
+
+	result = name_len;
+
+ exit:
+	if (proxy != NULL) {
+		fclose(proxy);
+	}
+
+	return result;
+}
+#endif
 /*
  * getnameinfo_inet():
  * Format an IPv4 or IPv6 sockaddr into a printable string.
@@ -277,7 +368,21 @@
 			break;
 		}
 	} else {
+#ifdef ANDROID_CHANGES
+		struct hostent android_proxy_hostent;
+		char android_proxy_buf[MAXDNAME];
+		android_proxy_hostent.h_name = android_proxy_buf;
+
+		int hostnamelen = android_gethostbyaddr_proxy(&android_proxy_hostent,
+				addr, afd->a_addrlen, afd->a_af);
+		if (hostnamelen >= 0) {
+			hp = (hostnamelen > 0) ? &android_proxy_hostent : NULL;
+		} else {
+			hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
+		}
+#else
 		hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
+#endif
 
 		if (hp) {
 #if 0
diff --git a/libc/unistd/sigblock.c b/libc/unistd/sigblock.c
index 863d7da..176bc13 100644
--- a/libc/unistd/sigblock.c
+++ b/libc/unistd/sigblock.c
@@ -37,6 +37,7 @@
         sigset_t  the_sigset;
     } in, out;
 
+    sigemptyset(&in.the_sigset);
     in.the_mask = mask;
 
     n = sigprocmask(SIG_BLOCK, &in.the_sigset, &out.the_sigset);
diff --git a/libc/unistd/sigsetmask.c b/libc/unistd/sigsetmask.c
index 4f46458..7842bf1 100644
--- a/libc/unistd/sigsetmask.c
+++ b/libc/unistd/sigsetmask.c
@@ -38,6 +38,7 @@
         sigset_t  the_sigset;
     } in, out;
 
+    sigemptyset(&in.the_sigset);
     in.the_mask = mask;
 
     n = sigprocmask(SIG_SETMASK, &in.the_sigset, &out.the_sigset);
diff --git a/libc/zoneinfo/zoneinfo.dat b/libc/zoneinfo/zoneinfo.dat
index 6b2bada..6e31d38 100644
--- a/libc/zoneinfo/zoneinfo.dat
+++ b/libc/zoneinfo/zoneinfo.dat
Binary files differ
diff --git a/libc/zoneinfo/zoneinfo.idx b/libc/zoneinfo/zoneinfo.idx
index 535251e..3a8bf97 100644
--- a/libc/zoneinfo/zoneinfo.idx
+++ b/libc/zoneinfo/zoneinfo.idx
Binary files differ
diff --git a/libc/zoneinfo/zoneinfo.version b/libc/zoneinfo/zoneinfo.version
index 1bec5a4..9deeb11 100644
--- a/libc/zoneinfo/zoneinfo.version
+++ b/libc/zoneinfo/zoneinfo.version
@@ -1 +1 @@
-2011b
+2011d
diff --git a/linker/Android.mk b/linker/Android.mk
index da311cd..abe5995 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -76,8 +76,6 @@
 LOCAL_MODULE_CLASS := EXECUTABLES
 LOCAL_MODULE_SUFFIX := $(TARGET_EXECUTABLE_SUFFIX)
 
-# Executables are not prelinked.
-LOCAL_PRELINK_MODULE := false
 
 include $(BUILD_SYSTEM)/dynamic_binary.mk
 
diff --git a/linker/arch/x86/begin.S b/linker/arch/x86/begin.S
index d8a39ca..b4427e0 100644
--- a/linker/arch/x86/begin.S
+++ b/linker/arch/x86/begin.S
@@ -44,9 +44,3 @@
         popl   %esp
         jmp    *%eax
 
-.section .ctors, "wa"
-.globl __CTOR_LIST__
-
-__CTOR_LIST__:
-        .long -1
-