Merge "Use system property to set dns cache size"
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/arch-x86/bionic/syscall.S b/libc/arch-x86/bionic/syscall.S
index 71abe6b..3cca85c 100644
--- a/libc/arch-x86/bionic/syscall.S
+++ b/libc/arch-x86/bionic/syscall.S
@@ -20,18 +20,15 @@
     .align 4
 
 syscall:
-    push    %eax
     push    %ebx
-    push    %ecx
-    push    %edx
     push    %esi
     push    %edi
-    mov     28(%esp),%eax
-    mov     32(%esp),%ebx
-    mov     36(%esp),%ecx
-    mov     40(%esp),%edx
-    mov     44(%esp),%esi
-    mov     48(%esp),%edi
+    mov     16(%esp),%eax
+    mov     20(%esp),%ebx
+    mov     24(%esp),%ecx
+    mov     28(%esp),%edx
+    mov     32(%esp),%esi
+    mov     36(%esp),%edi
 
     int     $0x80
 
@@ -45,8 +42,5 @@
 1:
     pop    %edi
     pop    %esi
-    pop    %edx
-    pop    %ecx
     pop    %ebx
-    pop    %eax
     ret
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/malloc_debug_common.c b/libc/bionic/malloc_debug_common.c
index ebf0006..b9fcbc4 100644
--- a/libc/bionic/malloc_debug_common.c
+++ b/libc/bionic/malloc_debug_common.c
@@ -84,7 +84,6 @@
         //
         // This is used for sorting, not determination of equality, so we don't
         // need to compare the bit flags.
-        int result;
         if (alloc1 > alloc2) {
             result = -1;
         } else if (alloc1 < alloc2) {
diff --git a/libc/bionic/md5.c b/libc/bionic/md5.c
index 087786f..16674f1 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/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/cdefs.h b/libc/include/sys/cdefs.h
index 9b6da31..92035d4 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -79,7 +79,7 @@
 #define	___STRING(x)	__STRING(x)
 #define	___CONCAT(x,y)	__CONCAT(x,y)
 
-#if __STDC__ || defined(__cplusplus)
+#if defined(__STDC__) || defined(__cplusplus)
 #define	__P(protos)	protos		/* full-blown ANSI C */
 #define	__CONCAT(x,y)	x ## y
 #define	__STRING(x)	#x
@@ -213,7 +213,7 @@
  * C99 defines the restrict type qualifier keyword, which was made available
  * in GCC 2.92.
  */
-#if __STDC_VERSION__ >= 199901L
+#if defined(__STDC__VERSION__) && __STDC_VERSION__ >= 199901L
 #define	__restrict	restrict
 #else
 #if !__GNUC_PREREQ__(2, 92)
@@ -225,7 +225,7 @@
  * C99 defines __func__ predefined identifier, which was made available
  * in GCC 2.95.
  */
-#if !(__STDC_VERSION__ >= 199901L)
+#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
 #if __GNUC_PREREQ__(2, 6)
 #define	__func__	__PRETTY_FUNCTION__
 #elif __GNUC_PREREQ__(2, 4)
diff --git a/libc/kernel/common/linux/if_arp.h b/libc/kernel/common/linux/if_arp.h
index a3df6c8..d8a4001 100644
--- a/libc/kernel/common/linux/if_arp.h
+++ b/libc/kernel/common/linux/if_arp.h
@@ -77,6 +77,7 @@
 
 #define ARPHRD_PHONET 820  
 #define ARPHRD_PHONET_PIPE 821  
+#define ARPHRD_CAIF 822  
 
 #define ARPHRD_VOID 0xFFFF  
 #define ARPHRD_NONE 0xFFFE  
@@ -111,8 +112,7 @@
 #define ATF_NETMASK 0x20  
 #define ATF_DONTPUB 0x40  
 
-struct arphdr
-{
+struct arphdr {
  __be16 ar_hrd;
  __be16 ar_pro;
  unsigned char ar_hln;
@@ -122,3 +122,4 @@
 };
 
 #endif
+
diff --git a/libc/kernel/common/linux/if_link.h b/libc/kernel/common/linux/if_link.h
index e9d77d4..4b83760 100644
--- a/libc/kernel/common/linux/if_link.h
+++ b/libc/kernel/common/linux/if_link.h
@@ -15,8 +15,7 @@
 #include <linux/types.h>
 #include <linux/netlink.h>
 
-struct rtnl_link_stats
-{
+struct rtnl_link_stats {
  __u32 rx_packets;
  __u32 tx_packets;
  __u32 rx_bytes;
@@ -45,8 +44,36 @@
  __u32 tx_compressed;
 };
 
-struct rtnl_link_ifmap
-{
+struct rtnl_link_stats64 {
+ __u64 rx_packets;
+ __u64 tx_packets;
+ __u64 rx_bytes;
+ __u64 tx_bytes;
+ __u64 rx_errors;
+ __u64 tx_errors;
+ __u64 rx_dropped;
+ __u64 tx_dropped;
+ __u64 multicast;
+ __u64 collisions;
+
+ __u64 rx_length_errors;
+ __u64 rx_over_errors;
+ __u64 rx_crc_errors;
+ __u64 rx_frame_errors;
+ __u64 rx_fifo_errors;
+ __u64 rx_missed_errors;
+
+ __u64 tx_aborted_errors;
+ __u64 tx_carrier_errors;
+ __u64 tx_fifo_errors;
+ __u64 tx_heartbeat_errors;
+ __u64 tx_window_errors;
+
+ __u64 rx_compressed;
+ __u64 tx_compressed;
+};
+
+struct rtnl_link_ifmap {
  __u64 mem_start;
  __u64 mem_end;
  __u64 base_addr;
@@ -55,8 +82,7 @@
  __u8 port;
 };
 
-enum
-{
+enum {
  IFLA_UNSPEC,
  IFLA_ADDRESS,
  IFLA_BROADCAST,
@@ -87,6 +113,11 @@
 #define IFLA_LINKINFO IFLA_LINKINFO
  IFLA_NET_NS_PID,
  IFLA_IFALIAS,
+ IFLA_NUM_VF,
+ IFLA_VFINFO_LIST,
+ IFLA_STATS64,
+ IFLA_VF_PORTS,
+ IFLA_PORT_SELF,
  __IFLA_MAX
 };
 
@@ -95,8 +126,7 @@
 #define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
 
-enum
-{
+enum {
  IFLA_INET6_UNSPEC,
  IFLA_INET6_FLAGS,
  IFLA_INET6_CONF,
@@ -109,16 +139,14 @@
 
 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
 
-struct ifla_cacheinfo
-{
+struct ifla_cacheinfo {
  __u32 max_reasm_len;
  __u32 tstamp;
  __u32 reachable_time;
  __u32 retrans_time;
 };
 
-enum
-{
+enum {
  IFLA_INFO_UNSPEC,
  IFLA_INFO_KIND,
  IFLA_INFO_DATA,
@@ -128,8 +156,7 @@
 
 #define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1)
 
-enum
-{
+enum {
  IFLA_VLAN_UNSPEC,
  IFLA_VLAN_ID,
  IFLA_VLAN_FLAGS,
@@ -145,8 +172,7 @@
  __u32 mask;
 };
 
-enum
-{
+enum {
  IFLA_VLAN_QOS_UNSPEC,
  IFLA_VLAN_QOS_MAPPING,
  __IFLA_VLAN_QOS_MAX
@@ -154,10 +180,123 @@
 
 #define IFLA_VLAN_QOS_MAX (__IFLA_VLAN_QOS_MAX - 1)
 
-struct ifla_vlan_qos_mapping
-{
+struct ifla_vlan_qos_mapping {
  __u32 from;
  __u32 to;
 };
 
+enum {
+ IFLA_MACVLAN_UNSPEC,
+ IFLA_MACVLAN_MODE,
+ __IFLA_MACVLAN_MAX,
+};
+
+#define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
+
+enum macvlan_mode {
+ MACVLAN_MODE_PRIVATE = 1,
+ MACVLAN_MODE_VEPA = 2,
+ MACVLAN_MODE_BRIDGE = 4,
+};
+
+enum {
+ IFLA_VF_INFO_UNSPEC,
+ IFLA_VF_INFO,
+ __IFLA_VF_INFO_MAX,
+};
+
+#define IFLA_VF_INFO_MAX (__IFLA_VF_INFO_MAX - 1)
+
+enum {
+ IFLA_VF_UNSPEC,
+ IFLA_VF_MAC,
+ IFLA_VF_VLAN,
+ IFLA_VF_TX_RATE,
+ __IFLA_VF_MAX,
+};
+
+#define IFLA_VF_MAX (__IFLA_VF_MAX - 1)
+
+struct ifla_vf_mac {
+ __u32 vf;
+ __u8 mac[32];
+};
+
+struct ifla_vf_vlan {
+ __u32 vf;
+ __u32 vlan;
+ __u32 qos;
+};
+
+struct ifla_vf_tx_rate {
+ __u32 vf;
+ __u32 rate;
+};
+
+struct ifla_vf_info {
+ __u32 vf;
+ __u8 mac[32];
+ __u32 vlan;
+ __u32 qos;
+ __u32 tx_rate;
+};
+
+enum {
+ IFLA_VF_PORT_UNSPEC,
+ IFLA_VF_PORT,
+ __IFLA_VF_PORT_MAX,
+};
+
+#define IFLA_VF_PORT_MAX (__IFLA_VF_PORT_MAX - 1)
+
+enum {
+ IFLA_PORT_UNSPEC,
+ IFLA_PORT_VF,
+ IFLA_PORT_PROFILE,
+ IFLA_PORT_VSI_TYPE,
+ IFLA_PORT_INSTANCE_UUID,
+ IFLA_PORT_HOST_UUID,
+ IFLA_PORT_REQUEST,
+ IFLA_PORT_RESPONSE,
+ __IFLA_PORT_MAX,
+};
+
+#define IFLA_PORT_MAX (__IFLA_PORT_MAX - 1)
+
+#define PORT_PROFILE_MAX 40
+#define PORT_UUID_MAX 16
+#define PORT_SELF_VF -1
+
+enum {
+ PORT_REQUEST_PREASSOCIATE = 0,
+ PORT_REQUEST_PREASSOCIATE_RR,
+ PORT_REQUEST_ASSOCIATE,
+ PORT_REQUEST_DISASSOCIATE,
+};
+
+enum {
+ PORT_VDP_RESPONSE_SUCCESS = 0,
+ PORT_VDP_RESPONSE_INVALID_FORMAT,
+ PORT_VDP_RESPONSE_INSUFFICIENT_RESOURCES,
+ PORT_VDP_RESPONSE_UNUSED_VTID,
+ PORT_VDP_RESPONSE_VTID_VIOLATION,
+ PORT_VDP_RESPONSE_VTID_VERSION_VIOALTION,
+ PORT_VDP_RESPONSE_OUT_OF_SYNC,
+
+ PORT_PROFILE_RESPONSE_SUCCESS = 0x100,
+ PORT_PROFILE_RESPONSE_INPROGRESS,
+ PORT_PROFILE_RESPONSE_INVALID,
+ PORT_PROFILE_RESPONSE_BADSTATE,
+ PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES,
+ PORT_PROFILE_RESPONSE_ERROR,
+};
+
+struct ifla_port_vsi {
+ __u8 vsi_mgr_id;
+ __u8 vsi_type_id[3];
+ __u8 vsi_type_version;
+ __u8 pad[3];
+};
+
 #endif
+
diff --git a/libc/kernel/common/linux/if_tun.h b/libc/kernel/common/linux/if_tun.h
index c5db4e0..9ed49f1 100644
--- a/libc/kernel/common/linux/if_tun.h
+++ b/libc/kernel/common/linux/if_tun.h
@@ -12,6 +12,10 @@
 #ifndef __IF_TUN_H
 #define __IF_TUN_H
 
+#include <linux/types.h>
+#include <linux/if_ether.h>
+#include <linux/filter.h>
+
 #define TUN_READQ_SIZE 500
 
 #define TUN_TUN_DEV 0x0001 
@@ -23,6 +27,7 @@
 #define TUN_NO_PI 0x0040
 #define TUN_ONE_QUEUE 0x0080
 #define TUN_PERSIST 0x0100 
+#define TUN_VNET_HDR 0x0200
 
 #define TUNSETNOCSUM _IOW('T', 200, int) 
 #define TUNSETDEBUG _IOW('T', 201, int) 
@@ -30,16 +35,43 @@
 #define TUNSETPERSIST _IOW('T', 203, int) 
 #define TUNSETOWNER _IOW('T', 204, int)
 #define TUNSETLINK _IOW('T', 205, int)
+#define TUNSETGROUP _IOW('T', 206, int)
+#define TUNGETFEATURES _IOR('T', 207, unsigned int)
+#define TUNSETOFFLOAD _IOW('T', 208, unsigned int)
+#define TUNSETTXFILTER _IOW('T', 209, unsigned int)
+#define TUNGETIFF _IOR('T', 210, unsigned int)
+#define TUNGETSNDBUF _IOR('T', 211, int)
+#define TUNSETSNDBUF _IOW('T', 212, int)
+#define TUNATTACHFILTER _IOW('T', 213, struct sock_fprog)
+#define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
+#define TUNGETVNETHDRSZ _IOR('T', 215, int)
+#define TUNSETVNETHDRSZ _IOW('T', 216, int)
 
 #define IFF_TUN 0x0001
 #define IFF_TAP 0x0002
 #define IFF_NO_PI 0x1000
 #define IFF_ONE_QUEUE 0x2000
+#define IFF_VNET_HDR 0x4000
+#define IFF_TUN_EXCL 0x8000
 
-struct tun_pi {
- unsigned short flags;
- unsigned short proto;
-};
+#define TUN_F_CSUM 0x01  
+#define TUN_F_TSO4 0x02  
+#define TUN_F_TSO6 0x04  
+#define TUN_F_TSO_ECN 0x08  
+#define TUN_F_UFO 0x10  
+
 #define TUN_PKT_STRIP 0x0001
+struct tun_pi {
+ __u16 flags;
+ __be16 proto;
+};
+
+#define TUN_FLT_ALLMULTI 0x0001  
+struct tun_filter {
+ __u16 flags;
+ __u16 count;
+ __u8 addr[0][ETH_ALEN];
+};
 
 #endif
+
diff --git a/libc/kernel/common/linux/rtnetlink.h b/libc/kernel/common/linux/rtnetlink.h
index e305505..bbd991a 100644
--- a/libc/kernel/common/linux/rtnetlink.h
+++ b/libc/kernel/common/linux/rtnetlink.h
@@ -18,6 +18,10 @@
 #include <linux/if_addr.h>
 #include <linux/neighbour.h>
 
+#define RTNL_FAMILY_IPMR 128
+#define RTNL_FAMILY_IP6MR 129
+#define RTNL_FAMILY_MAX 129
+
 enum {
  RTM_BASE = 16,
 #define RTM_BASE RTM_BASE
@@ -126,8 +130,7 @@
 #define RTM_NR_FAMILIES (RTM_NR_MSGTYPES >> 2)
 #define RTM_FAM(cmd) (((cmd) - RTM_BASE) >> 2)
 
-struct rtattr
-{
+struct rtattr {
  unsigned short rta_len;
  unsigned short rta_type;
 };
@@ -141,8 +144,7 @@
 #define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
 #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
 
-struct rtmsg
-{
+struct rtmsg {
  unsigned char rtm_family;
  unsigned char rtm_dst_len;
  unsigned char rtm_src_len;
@@ -156,8 +158,7 @@
  unsigned rtm_flags;
 };
 
-enum
-{
+enum {
  RTN_UNSPEC,
  RTN_UNICAST,
  RTN_LOCAL,
@@ -191,8 +192,7 @@
 #define RTPROT_NTK 15  
 #define RTPROT_DHCP 16  
 
-enum rt_scope_t
-{
+enum rt_scope_t {
  RT_SCOPE_UNIVERSE=0,
 
  RT_SCOPE_SITE=200,
@@ -206,8 +206,7 @@
 #define RTM_F_EQUALIZE 0x400  
 #define RTM_F_PREFIX 0x800  
 
-enum rt_class_t
-{
+enum rt_class_t {
  RT_TABLE_UNSPEC=0,
 
  RT_TABLE_COMPAT=252,
@@ -217,8 +216,7 @@
  RT_TABLE_MAX=0xFFFFFFFF
 };
 
-enum rtattr_type_t
-{
+enum rtattr_type_t {
  RTA_UNSPEC,
  RTA_DST,
  RTA_SRC,
@@ -235,6 +233,7 @@
  RTA_SESSION,
  RTA_MP_ALGO,
  RTA_TABLE,
+ RTA_MARK,
  __RTA_MAX
 };
 
@@ -243,8 +242,7 @@
 #define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
 #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
 
-struct rtnexthop
-{
+struct rtnexthop {
  unsigned short rtnh_len;
  unsigned char rtnh_flags;
  unsigned char rtnh_hops;
@@ -263,8 +261,7 @@
 #define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
 #define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
 
-struct rta_cacheinfo
-{
+struct rta_cacheinfo {
  __u32 rta_clntref;
  __u32 rta_lastuse;
  __s32 rta_expires;
@@ -277,8 +274,7 @@
  __u32 rta_tsage;
 };
 
-enum
-{
+enum {
  RTAX_UNSPEC,
 #define RTAX_UNSPEC RTAX_UNSPEC
  RTAX_LOCK,
@@ -307,6 +303,8 @@
 #define RTAX_FEATURES RTAX_FEATURES
  RTAX_RTO_MIN,
 #define RTAX_RTO_MIN RTAX_RTO_MIN
+ RTAX_INITRWND,
+#define RTAX_INITRWND RTAX_INITRWND
  __RTAX_MAX
 };
 
@@ -317,8 +315,7 @@
 #define RTAX_FEATURE_TIMESTAMP 0x00000004
 #define RTAX_FEATURE_ALLFRAG 0x00000008
 
-struct rta_session
-{
+struct rta_session {
  __u8 proto;
  __u8 pad1;
  __u16 pad2;
@@ -339,13 +336,11 @@
  } u;
 };
 
-struct rtgenmsg
-{
+struct rtgenmsg {
  unsigned char rtgen_family;
 };
 
-struct ifinfomsg
-{
+struct ifinfomsg {
  unsigned char ifi_family;
  unsigned char __ifi_pad;
  unsigned short ifi_type;
@@ -354,8 +349,7 @@
  unsigned ifi_change;
 };
 
-struct prefixmsg
-{
+struct prefixmsg {
  unsigned char prefix_family;
  unsigned char prefix_pad1;
  unsigned short prefix_pad2;
@@ -376,14 +370,12 @@
 
 #define PREFIX_MAX (__PREFIX_MAX - 1)
 
-struct prefix_cacheinfo
-{
+struct prefix_cacheinfo {
  __u32 preferred_time;
  __u32 valid_time;
 };
 
-struct tcmsg
-{
+struct tcmsg {
  unsigned char tcm_family;
  unsigned char tcm__pad1;
  unsigned short tcm__pad2;
@@ -393,8 +385,7 @@
  __u32 tcm_info;
 };
 
-enum
-{
+enum {
  TCA_UNSPEC,
  TCA_KIND,
  TCA_OPTIONS,
@@ -412,8 +403,7 @@
 #define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
 #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
 
-struct nduseroptmsg
-{
+struct nduseroptmsg {
  unsigned char nduseropt_family;
  unsigned char nduseropt_pad1;
  unsigned short nduseropt_opts_len;
@@ -425,8 +415,7 @@
 
 };
 
-enum
-{
+enum {
  NDUSEROPT_UNSPEC,
  NDUSEROPT_SRCADDR,
  __NDUSEROPT_MAX
@@ -503,8 +492,7 @@
 };
 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
 
-struct tcamsg
-{
+struct tcamsg {
  unsigned char tca_family;
  unsigned char tca__pad1;
  unsigned short tca__pad2;
@@ -515,3 +503,4 @@
 #define TCAA_MAX 1
 
 #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/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
-