Merge "Always update search domain paths."
diff --git a/libc/Android.mk b/libc/Android.mk
index a8581ac..3fac083 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -1390,11 +1390,6 @@
 LOCAL_LDFLAGS_mips64 += -Wl,--version-script,$(LOCAL_PATH)/libc.mips64.map
 LOCAL_LDFLAGS_x86_64 += -Wl,--version-script,$(LOCAL_PATH)/libc.x86_64.map
 
-# We'd really like to do this for all architectures, but since this wasn't done
-# before, these symbols must continue to be exported on LP32 for binary
-# compatibility.
-LOCAL_LDFLAGS_64 := -Wl,--exclude-libs,libgcc.a
-
 # Unfortunately --exclude-libs clobbers our version script, so we have to
 # prevent the build system from using this flag.
 LOCAL_NO_EXCLUDE_LIBS := true
diff --git a/libc/bionic/clone.cpp b/libc/bionic/clone.cpp
index af63977..8281ac8 100644
--- a/libc/bionic/clone.cpp
+++ b/libc/bionic/clone.cpp
@@ -47,7 +47,7 @@
   void* new_tls = NULL;
   int* child_tid = NULL;
 
-  if (!child_stack) {
+  if (fn != nullptr && child_stack == nullptr) {
     errno = EINVAL;
     return -1;
   }
@@ -76,7 +76,16 @@
   pid_t parent_pid = self->invalidate_cached_pid();
 
   // Actually do the clone.
-  int clone_result = __bionic_clone(flags, child_stack, parent_tid, new_tls, child_tid, fn, arg);
+  int clone_result;
+  if (fn != nullptr) {
+    clone_result = __bionic_clone(flags, child_stack, parent_tid, new_tls, child_tid, fn, arg);
+  } else {
+#if defined(__x86_64__) // sys_clone's last two arguments are flipped on x86-64.
+    clone_result = syscall(__NR_clone, flags, child_stack, parent_tid, child_tid, new_tls);
+#else
+    clone_result = syscall(__NR_clone, flags, child_stack, parent_tid, new_tls, child_tid);
+#endif
+  }
 
   // We're the parent, so put our known pid back in place.
   // We leave the child without a cached pid, but:
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp
index 6cfc736..ffe94f4 100644
--- a/libc/bionic/fork.cpp
+++ b/libc/bionic/fork.cpp
@@ -31,8 +31,6 @@
 
 #include "pthread_internal.h"
 
-#define FORK_FLAGS (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD)
-
 int fork() {
   __bionic_atfork_run_prepare();
 
@@ -41,11 +39,13 @@
   // Remember the parent pid and invalidate the cached value while we fork.
   pid_t parent_pid = self->invalidate_cached_pid();
 
-#if defined(__x86_64__) // sys_clone's last two arguments are flipped on x86-64.
-  int result = syscall(__NR_clone, FORK_FLAGS, NULL, NULL, &(self->tid), NULL);
-#else
-  int result = syscall(__NR_clone, FORK_FLAGS, NULL, NULL, NULL, &(self->tid));
-#endif
+  int result = clone(nullptr,
+                     nullptr,
+                     (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD),
+                     nullptr,
+                     nullptr,
+                     nullptr,
+                     &(self->tid));
   if (result == 0) {
     self->set_cached_pid(gettid());
     __bionic_atfork_run_child();
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 7d8e8a8..14e0ab0 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -502,6 +502,9 @@
 
 int pthread_mutex_lock(pthread_mutex_t* mutex_interface) {
 #if !defined(__LP64__)
+    // Some apps depend on being able to pass NULL as a mutex and get EINVAL
+    // back. Don't need to worry about it for LP64 since the ABI is brand new,
+    // but keep compatibility for LP32. http://b/19995172.
     if (mutex_interface == NULL) {
         return EINVAL;
     }
@@ -523,6 +526,9 @@
 
 int pthread_mutex_unlock(pthread_mutex_t* mutex_interface) {
 #if !defined(__LP64__)
+    // Some apps depend on being able to pass NULL as a mutex and get EINVAL
+    // back. Don't need to worry about it for LP64 since the ABI is brand new,
+    // but keep compatibility for LP32. http://b/19995172.
     if (mutex_interface == NULL) {
         return EINVAL;
     }
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
index 266193a..7182ca6 100644
--- a/libc/dns/include/resolv_netid.h
+++ b/libc/dns/include/resolv_netid.h
@@ -101,9 +101,6 @@
 int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int, unsigned, unsigned) __LIBC_HIDDEN__;
 FILE* android_open_proxy(void) __LIBC_HIDDEN__;
 
-/* delete the cache associated with a certain network */
-extern void _resolv_delete_cache_for_net(unsigned netid);
-
 __END_DECLS
 
 #endif /* _RESOLV_NETID_H */
diff --git a/libc/dns/net/getnameinfo.c b/libc/dns/net/getnameinfo.c
index abd1a66..63a347e 100644
--- a/libc/dns/net/getnameinfo.c
+++ b/libc/dns/net/getnameinfo.c
@@ -54,7 +54,6 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <net/if.h>
-#include <net/if_types.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <assert.h>
diff --git a/libc/include/android/dlext.h b/libc/include/android/dlext.h
index 05a27f3..37e4cde 100644
--- a/libc/include/android/dlext.h
+++ b/libc/include/android/dlext.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2014 The Android Open Source Project
-
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -132,70 +132,6 @@
 extern void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo)
   __INTRODUCED_IN(21);
 
-/*
- * Initializes public and anonymous namespaces. The public_ns_sonames is the list of sonames
- * to be included into public namespace separated by colon. Example: "libc.so:libm.so:libdl.so".
- * The libraries in this list should be loaded prior to this call.
- *
- * The anon_ns_library_path is the search path for anonymous namespace. The anonymous namespace
- * is used in the case when linker cannot identify the caller of dlopen/dlsym. This happens
- * for the code not loaded by dynamic linker; for example calls from the mono-compiled code.
- */
-extern bool android_init_namespaces(const char* public_ns_sonames,
-                                    const char* anon_ns_library_path);
-
-
-enum {
-  /* A regular namespace is the namespace with a custom search path that does
-   * not impose any restrictions on the location of native libraries.
-   */
-  ANDROID_NAMESPACE_TYPE_REGULAR = 0,
-
-  /* An isolated namespace requires all the libraries to be on the search path
-   * or under permitted_when_isolated_path. The search path is the union of
-   * ld_library_path and default_library_path.
-   */
-  ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
-
-  /* The shared namespace clones the list of libraries of the caller namespace upon creation
-   * which means that they are shared between namespaces - the caller namespace and the new one
-   * will use the same copy of a library if it was loaded prior to android_create_namespace call.
-   *
-   * Note that libraries loaded after the namespace is created will not be shared.
-   *
-   * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor
-   * permitted_path from the caller's namespace.
-   */
-  ANDROID_NAMESPACE_TYPE_SHARED = 2,
-  ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
-                                           ANDROID_NAMESPACE_TYPE_ISOLATED,
-};
-
-/*
- * Creates new linker namespace.
- * ld_library_path and default_library_path represent the search path
- * for the libraries in the namespace.
- *
- * The libraries in the namespace are searched by folowing order:
- * 1. ld_library_path (Think of this as namespace-local LD_LIBRARY_PATH)
- * 2. In directories specified by DT_RUNPATH of the "needed by" binary.
- * 3. deault_library_path (This of this as namespace-local default library path)
- *
- * When type is ANDROID_NAMESPACE_TYPE_ISOLATED the resulting namespace requires all of
- * the libraries to be on the search path or under the permitted_when_isolated_path;
- * the search_path is ld_library_path:default_library_path. Note that the
- * permitted_when_isolated_path path is not part of the search_path and
- * does not affect the search order. It is a way to allow loading libraries from specific
- * locations when using absolute path.
- * If a library or any of its dependencies are outside of the permitted_when_isolated_path
- * and search_path, and it is not part of the public namespace dlopen will fail.
- */
-extern struct android_namespace_t* android_create_namespace(const char* name,
-                                                            const char* ld_library_path,
-                                                            const char* default_library_path,
-                                                            uint64_t type,
-                                                            const char* permitted_when_isolated_path);
-
 __END_DECLS
 
 #endif /* __ANDROID_DLEXT_H__ */
diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h
index 25a302f..5dc8350 100644
--- a/libc/include/dlfcn.h
+++ b/libc/include/dlfcn.h
@@ -46,8 +46,8 @@
 extern void* dlopen(const char*  filename, int flag);
 extern int dlclose(void*  handle);
 extern const char* dlerror(void);
-extern void* dlsym(void* handle, const char* symbol) __nonnull((2));
-extern void* dlvsym(void* handle, const char* symbol, const char* version) __nonnull((2, 3))
+extern void* dlsym(void* handle, const char* _Nonnull symbol);
+extern void* dlvsym(void* handle, const char* _Nonnull symbol, const char* _Nonnull version)
   __INTRODUCED_IN(24);
 extern int dladdr(const void* addr, Dl_info *info);
 
@@ -80,5 +80,3 @@
 __END_DECLS
 
 #endif /* __DLFCN_H */
-
-
diff --git a/libc/include/net/if_ether.h b/libc/include/net/if_ether.h
index 06cceb1..b1d2bce 100644
--- a/libc/include/net/if_ether.h
+++ b/libc/include/net/if_ether.h
@@ -34,15 +34,9 @@
 #ifndef _NET_IF_ETHER_H_
 #define _NET_IF_ETHER_H_
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
-#ifdef _KERNEL
-#ifdef _KERNEL_OPT
-#include "opt_mbuftrace.h"
-#endif
-#include <sys/mbuf.h>
-#endif
-
 /*
  * Some basic Ethernet constants.
  */
@@ -55,11 +49,6 @@
 #define	ETHER_MAX_LEN_JUMBO 9018 /* maximum jumbo frame len, including CRC */
 
 /*
- * Some Ethernet extensions.
- */
-#define	ETHER_VLAN_ENCAP_LEN 4	/* length of 802.1Q VLAN encapsulation */
-
-/*
  * Ethernet address - 6 octets
  * this is only used by the ethers(3) functions.
  */
@@ -78,37 +67,11 @@
 
 #include <net/ethertypes.h>
 
-#define	ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
-
 #define	ETHERMTU_JUMBO	(ETHER_MAX_LEN_JUMBO - ETHER_HDR_LEN - ETHER_CRC_LEN)
 #define	ETHERMTU	(ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
 #define	ETHERMIN	(ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
 
 /*
- * Compute the maximum frame size based on ethertype (i.e. possible
- * encapsulation) and whether or not an FCS is present.
- */
-#define	ETHER_MAX_FRAME(ifp, etype, hasfcs)				\
-	((ifp)->if_mtu + ETHER_HDR_LEN +				\
-	 ((hasfcs) ? ETHER_CRC_LEN : 0) +				\
-	 (((etype) == ETHERTYPE_VLAN) ? ETHER_VLAN_ENCAP_LEN : 0))
-
-/*
- * Ethernet CRC32 polynomials (big- and little-endian verions).
- */
-#define	ETHER_CRC_POLY_LE	0xedb88320
-#define	ETHER_CRC_POLY_BE	0x04c11db6
-
-#ifndef _STANDALONE
-
-/*
- * Ethernet-specific mbuf flags.
- */
-#define	M_HASFCS	M_LINK0	/* FCS included at end of frame */
-#define	M_PROMISC	M_LINK1	/* this packet is not for us */
-
-#ifdef _KERNEL
-/*
  * Macro to map an IP multicast address to an Ethernet multicast address.
  * The high-order 25 bits of the Ethernet address are statically assigned,
  * and the low-order 23 bits are taken from the low end of the IP address.
@@ -140,76 +103,12 @@
 	(enaddr)[4] = ((u_int8_t *)ip6addr)[14];			\
 	(enaddr)[5] = ((u_int8_t *)ip6addr)[15];			\
 }
-#endif
 
-#define	ETHERCAP_VLAN_MTU	0x00000001	/* VLAN-compatible MTU */
-#define	ETHERCAP_VLAN_HWTAGGING	0x00000002	/* hardware VLAN tag support */
-#define	ETHERCAP_JUMBO_MTU	0x00000004	/* 9000 byte MTU supported */
-
-#ifdef	_KERNEL
-extern const uint8_t etherbroadcastaddr[ETHER_ADDR_LEN];
-extern const uint8_t ethermulticastaddr_slowprotocols[ETHER_ADDR_LEN];
-extern const uint8_t ether_ipmulticast_min[ETHER_ADDR_LEN];
-extern const uint8_t ether_ipmulticast_max[ETHER_ADDR_LEN];
-
-int	ether_ioctl(struct ifnet *, u_long, caddr_t);
-int	ether_addmulti (struct ifreq *, struct ethercom *);
-int	ether_delmulti (struct ifreq *, struct ethercom *);
-int	ether_changeaddr (struct ifreq *, struct ethercom *);
-int	ether_multiaddr(struct sockaddr *, u_int8_t[], u_int8_t[]);
-
-/*
- * Ethernet 802.1Q VLAN structures.
- */
-
-/* add VLAN tag to input/received packet */
-#define	VLAN_INPUT_TAG(ifp, m, vlanid, _errcase)	\
-	do {								\
-                struct m_tag *mtag =					\
-                    m_tag_get(PACKET_TAG_VLAN, sizeof(u_int), M_NOWAIT);\
-                if (mtag == NULL) {					\
-			ifp->if_ierrors++;				\
-                        printf("%s: unable to allocate VLAN tag\n",	\
-                            ifp->if_xname);				\
-                        m_freem(m);					\
-                        _errcase;					\
-                }							\
-                *(u_int *)(mtag + 1) = vlanid;				\
-                m_tag_prepend(m, mtag);					\
-	} while(0)
-
-/* extract VLAN tag from output/trasmit packet */
-#define VLAN_OUTPUT_TAG(ec, m0)			\
-	VLAN_ATTACHED(ec) ? m_tag_find((m0), PACKET_TAG_VLAN, NULL) : NULL
-
-/* extract VLAN ID value from a VLAN tag */
-#define VLAN_TAG_VALUE(mtag)	\
-	((*(u_int *)(mtag + 1)) & 4095)
-
-/* test if any VLAN is configured for this interface */
-#define VLAN_ATTACHED(ec)	((ec)->ec_nvlans > 0)
-
-void	ether_ifattach(struct ifnet *, const u_int8_t *);
-void	ether_ifdetach(struct ifnet *);
-
-char	*ether_sprintf(const u_int8_t *);
-char	*ether_snprintf(char *, size_t, const u_int8_t *);
-
-u_int32_t ether_crc32_le(const u_int8_t *, size_t);
-u_int32_t ether_crc32_be(const u_int8_t *, size_t);
-
-int	ether_nonstatic_aton(u_char *, char *);
-#else
-/*
- * Prototype ethers(3) functions.
- */
-#include <sys/cdefs.h>
 __BEGIN_DECLS
-char* ether_ntoa __P((const struct ether_addr*)) __INTRODUCED_IN(21);
-struct ether_addr* ether_aton __P((const char*)) __INTRODUCED_IN(21);
-__END_DECLS
-#endif
 
-#endif /* _STANDALONE */
+char* ether_ntoa(const struct ether_addr*) __INTRODUCED_IN(21);
+struct ether_addr* ether_aton(const char*) __INTRODUCED_IN(21);
+
+__END_DECLS
 
 #endif /* !_NET_IF_ETHER_H_ */
diff --git a/libc/include/net/if_types.h b/libc/include/net/if_types.h
deleted file mode 100644
index eff6d53..0000000
--- a/libc/include/net/if_types.h
+++ /dev/null
@@ -1,268 +0,0 @@
-/*	$NetBSD: if_types.h,v 1.26 2012/08/05 21:21:41 wiz Exp $	*/
-
-/*
- * Copyright (c) 1989, 1993, 1994
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)if_types.h	8.3 (Berkeley) 4/28/95
- */
-
-#ifndef _NET_IF_TYPES_H_
-#define _NET_IF_TYPES_H_
-
-/*
- * Interface types for benefit of parsing media address headers.
- * This list is derived from the SNMP list of ifTypes, originally
- * documented in RFC1573, now maintained as:
- *
- * <URL:http://www.iana.org/assignments/smi-numbers>
- */
-
-#define	IFT_OTHER	0x1		/* none of the following */
-#define	IFT_1822	0x2		/* old-style arpanet imp */
-#define	IFT_HDH1822	0x3		/* HDH arpanet imp */
-#define	IFT_X25DDN	0x4		/* x25 to imp */
-#define	IFT_X25		0x5		/* PDN X25 interface (RFC877) */
-#define	IFT_ETHER	0x6		/* Ethernet CSMA/CD */
-#define	IFT_ISO88023	0x7		/* CSMA/CD */
-#define	IFT_ISO88024	0x8		/* Token Bus */
-#define	IFT_ISO88025	0x9		/* Token Ring */
-#define	IFT_ISO88026	0xa		/* MAN */
-#define	IFT_STARLAN	0xb
-#define	IFT_P10		0xc		/* Proteon 10MBit ring */
-#define	IFT_P80		0xd		/* Proteon 80MBit ring */
-#define	IFT_HY		0xe		/* Hyperchannel */
-#define	IFT_FDDI	0xf
-#define	IFT_LAPB	0x10
-#define	IFT_SDLC	0x11
-#define	IFT_T1		0x12
-#define	IFT_CEPT	0x13		/* E1 - european T1 */
-#define	IFT_ISDNBASIC	0x14
-#define	IFT_ISDNPRIMARY	0x15
-#define	IFT_PTPSERIAL	0x16		/* Proprietary PTP serial */
-#define	IFT_PPP		0x17		/* RFC 1331 */
-#define	IFT_LOOP	0x18		/* loopback */
-#define	IFT_EON		0x19		/* ISO over IP */
-#define	IFT_XETHER	0x1a		/* obsolete 3MB experimental ethernet */
-#define	IFT_NSIP	0x1b		/* XNS over IP */
-#define	IFT_SLIP	0x1c		/* IP over generic TTY */
-#define	IFT_ULTRA	0x1d		/* Ultra Technologies */
-#define	IFT_DS3		0x1e		/* Generic T3 */
-#define	IFT_SIP		0x1f		/* SMDS */
-#define	IFT_FRELAY	0x20		/* Frame Relay DTE only */
-#define	IFT_RS232	0x21
-#define	IFT_PARA	0x22		/* parallel-port */
-#define	IFT_ARCNET	0x23
-#define	IFT_ARCNETPLUS	0x24
-#define	IFT_ATM		0x25		/* ATM cells */
-#define	IFT_MIOX25	0x26
-#define	IFT_SONET	0x27		/* SONET or SDH */
-#define	IFT_X25PLE	0x28
-#define	IFT_ISO88022LLC	0x29
-#define	IFT_LOCALTALK	0x2a
-#define	IFT_SMDSDXI	0x2b
-#define	IFT_FRELAYDCE	0x2c		/* Frame Relay DCE */
-#define	IFT_V35		0x2d
-#define	IFT_HSSI	0x2e
-#define	IFT_HIPPI	0x2f
-#define	IFT_MODEM	0x30		/* Generic Modem */
-#define	IFT_AAL5	0x31		/* AAL5 over ATM */
-#define	IFT_SONETPATH	0x32
-#define	IFT_SONETVT	0x33
-#define	IFT_SMDSICIP	0x34		/* SMDS InterCarrier Interface */
-#define	IFT_PROPVIRTUAL	0x35		/* Proprietary Virtual/internal */
-#define	IFT_PROPMUX	0x36		/* Proprietary Multiplexing */
-#define IFT_IEEE80212		   0x37 /* 100BaseVG */
-#define IFT_FIBRECHANNEL	   0x38 /* Fibre Channel */
-#define IFT_HIPPIINTERFACE	   0x39 /* HIPPI interfaces	 */
-#define IFT_FRAMERELAYINTERCONNECT 0x3a /* Obsolete, use either 0x20 or 0x2c */
-#define IFT_AFLANE8023		   0x3b /* ATM Emulated LAN for 802.3 */
-#define IFT_AFLANE8025		   0x3c /* ATM Emulated LAN for 802.5 */
-#define IFT_CCTEMUL		   0x3d /* ATM Emulated circuit		  */
-#define IFT_FASTETHER		   0x3e /* Fast Ethernet (100BaseT) */
-#define IFT_ISDN		   0x3f /* ISDN and X.25	    */
-#define IFT_V11			   0x40 /* CCITT V.11/X.21		*/
-#define IFT_V36			   0x41 /* CCITT V.36			*/
-#define IFT_G703AT64K		   0x42 /* CCITT G703 at 64Kbps */
-#define IFT_G703AT2MB		   0x43 /* Obsolete see DS1-MIB */
-#define IFT_QLLC		   0x44 /* SNA QLLC			*/
-#define IFT_FASTETHERFX		   0x45 /* Fast Ethernet (100BaseFX)	*/
-#define IFT_CHANNEL		   0x46 /* channel			*/
-#define IFT_IEEE80211		   0x47 /* radio spread spectrum	*/
-#define IFT_IBM370PARCHAN	   0x48 /* IBM System 360/370 OEMI Channel */
-#define IFT_ESCON		   0x49 /* IBM Enterprise Systems Connection */
-#define IFT_DLSW		   0x4a /* Data Link Switching */
-#define IFT_ISDNS		   0x4b /* ISDN S/T interface */
-#define IFT_ISDNU		   0x4c /* ISDN U interface */
-#define IFT_LAPD		   0x4d /* Link Access Protocol D */
-#define IFT_IPSWITCH		   0x4e /* IP Switching Objects */
-#define IFT_RSRB		   0x4f /* Remote Source Route Bridging */
-#define IFT_ATMLOGICAL		   0x50 /* ATM Logical Port */
-#define IFT_DS0			   0x51 /* Digital Signal Level 0 */
-#define IFT_DS0BUNDLE		   0x52 /* group of ds0s on the same ds1 */
-#define IFT_BSC			   0x53 /* Bisynchronous Protocol */
-#define IFT_ASYNC		   0x54 /* Asynchronous Protocol */
-#define IFT_CNR			   0x55 /* Combat Net Radio */
-#define IFT_ISO88025DTR		   0x56 /* ISO 802.5r DTR */
-#define IFT_EPLRS		   0x57 /* Ext Pos Loc Report Sys */
-#define IFT_ARAP		   0x58 /* Appletalk Remote Access Protocol */
-#define IFT_PROPCNLS		   0x59 /* Proprietary Connectionless Protocol*/
-#define IFT_HOSTPAD		   0x5a /* CCITT-ITU X.29 PAD Protocol */
-#define IFT_TERMPAD		   0x5b /* CCITT-ITU X.3 PAD Facility */
-#define IFT_FRAMERELAYMPI	   0x5c /* Multiproto Interconnect over FR */
-#define IFT_X213		   0x5d /* CCITT-ITU X213 */
-#define IFT_ADSL		   0x5e /* Asymmetric Digital Subscriber Loop */
-#define IFT_RADSL		   0x5f /* Rate-Adapt. Digital Subscriber Loop*/
-#define IFT_SDSL		   0x60 /* Symmetric Digital Subscriber Loop */
-#define IFT_VDSL		   0x61 /* Very H-Speed Digital Subscrib. Loop*/
-#define IFT_ISO88025CRFPINT	   0x62 /* ISO 802.5 CRFP */
-#define IFT_MYRINET		   0x63 /* Myricom Myrinet */
-#define IFT_VOICEEM		   0x64 /* voice recEive and transMit */
-#define IFT_VOICEFXO		   0x65 /* voice Foreign Exchange Office */
-#define IFT_VOICEFXS		   0x66 /* voice Foreign Exchange Station */
-#define IFT_VOICEENCAP		   0x67 /* voice encapsulation */
-#define IFT_VOICEOVERIP		   0x68 /* voice over IP encapsulation */
-#define IFT_ATMDXI		   0x69 /* ATM DXI */
-#define IFT_ATMFUNI		   0x6a /* ATM FUNI */
-#define IFT_ATMIMA		   0x6b /* ATM IMA		      */
-#define IFT_PPPMULTILINKBUNDLE	   0x6c /* PPP Multilink Bundle */
-#define IFT_IPOVERCDLC		   0x6d /* IBM ipOverCdlc */
-#define IFT_IPOVERCLAW		   0x6e /* IBM Common Link Access to Workstn */
-#define IFT_STACKTOSTACK	   0x6f /* IBM stackToStack */
-#define IFT_VIRTUALIPADDRESS	   0x70 /* IBM VIPA */
-#define IFT_MPC			   0x71 /* IBM multi-protocol channel support */
-#define IFT_IPOVERATM		   0x72 /* IBM ipOverAtm */
-#define IFT_ISO88025FIBER	   0x73 /* ISO 802.5j Fiber Token Ring */
-#define IFT_TDLC		   0x74 /* IBM twinaxial data link control */
-#define IFT_GIGABITETHERNET	   0x75 /* Gigabit Ethernet */
-#define IFT_HDLC		   0x76 /* HDLC */
-#define IFT_LAPF		   0x77 /* LAP F */
-#define IFT_V37			   0x78 /* V.37 */
-#define IFT_X25MLP		   0x79 /* Multi-Link Protocol */
-#define IFT_X25HUNTGROUP	   0x7a /* X25 Hunt Group */
-#define IFT_TRANSPHDLC		   0x7b /* Transp HDLC */
-#define IFT_INTERLEAVE		   0x7c /* Interleave channel */
-#define IFT_FAST		   0x7d /* Fast channel */
-#define IFT_IP			   0x7e /* IP (for APPN HPR in IP networks) */
-#define IFT_DOCSCABLEMACLAYER	   0x7f /* CATV Mac Layer */
-#define IFT_DOCSCABLEDOWNSTREAM	   0x80 /* CATV Downstream interface */
-#define IFT_DOCSCABLEUPSTREAM	   0x81 /* CATV Upstream interface */
-#define IFT_A12MPPSWITCH	   0x82	/* Avalon Parallel Processor */
-#define IFT_TUNNEL		   0x83	/* Encapsulation interface */
-#define IFT_COFFEE		   0x84	/* coffee pot */
-#define IFT_CES			   0x85	/* Circiut Emulation Service */
-#define IFT_ATMSUBINTERFACE	   0x86	/* (x)  ATM Sub Interface */
-#define IFT_L2VLAN		   0x87	/* Layer 2 Virtual LAN using 802.1Q */
-#define IFT_L3IPVLAN		   0x88	/* Layer 3 Virtual LAN - IP Protocol */
-#define IFT_L3IPXVLAN		   0x89	/* Layer 3 Virtual LAN - IPX Prot. */
-#define IFT_DIGITALPOWERLINE	   0x8a	/* IP over Power Lines */
-#define IFT_MEDIAMAILOVERIP	   0x8b	/* (xxx)  Multimedia Mail over IP */
-#define IFT_DTM			   0x8c	/* Dynamic synchronous Transfer Mode */
-#define IFT_DCN			   0x8d	/* Data Communications Network */
-#define IFT_IPFORWARD		   0x8e	/* IP Forwarding Interface */
-#define IFT_MSDSL		   0x8f	/* Multi-rate Symmetric DSL */
-#define IFT_IEEE1394		   0x90	/* IEEE1394 High Performance SerialBus*/
-#define IFT_IFGSN		   0x91	/* HIPPI-6400 */
-#define IFT_DVBRCCMACLAYER	   0x92	/* DVB-RCC MAC Layer */
-#define IFT_DVBRCCDOWNSTREAM	   0x93	/* DVB-RCC Downstream Channel */
-#define IFT_DVBRCCUPSTREAM	   0x94	/* DVB-RCC Upstream Channel */
-#define IFT_ATMVIRTUAL		   0x95	/* ATM Virtual Interface */
-#define IFT_MPLSTUNNEL		   0x96	/* MPLS Tunnel Virtual Interface */
-#define IFT_SRP			   0x97	/* Spatial Reuse Protocol */
-#define IFT_VOICEOVERATM	   0x98	/* Voice over ATM */
-#define IFT_VOICEOVERFRAMERELAY	   0x99	/* Voice Over Frame Relay */
-#define IFT_IDSL		   0x9a	/* Digital Subscriber Loop over ISDN */
-#define IFT_COMPOSITELINK	   0x9b	/* Avici Composite Link Interface */
-#define IFT_SS7SIGLINK		   0x9c	/* SS7 Signaling Link */
-#define IFT_PROPWIRELESSP2P	   0x9d	/* Prop. P2P wireless interface */
-#define IFT_FRFORWARD		   0x9e	/* Frame forward Interface */
-#define IFT_RFC1483		   0x9f	/* Multiprotocol over ATM AAL5 */
-#define IFT_USB			   0xa0	/* USB Interface */
-#define IFT_IEEE8023ADLAG	   0xa1	/* IEEE 802.3ad Link Aggregate*/
-#define IFT_BGPPOLICYACCOUNTING	   0xa2	/* BGP Policy Accounting */
-#define IFT_FRF16MFRBUNDLE	   0xa3	/* FRF.16 Multilik Frame Relay*/
-#define IFT_H323GATEKEEPER	   0xa4	/* H323 Gatekeeper */
-#define IFT_H323PROXY		   0xa5	/* H323 Voice and Video Proxy */
-#define IFT_MPLS		   0xa6	/* MPLS */
-#define IFT_MFSIGLINK		   0xa7	/* Multi-frequency signaling link */
-#define IFT_HDSL2		   0xa8	/* High Bit-Rate DSL, 2nd gen. */
-#define IFT_SHDSL		   0xa9	/* Multirate HDSL2 */
-#define IFT_DS1FDL		   0xaa	/* Facility Data Link (4Kbps) on a DS1*/
-#define IFT_POS			   0xab	/* Packet over SONET/SDH Interface */
-#define IFT_DVBASILN		   0xac	/* DVB-ASI Input */
-#define IFT_DVBASIOUT		   0xad	/* DVB-ASI Output */
-#define IFT_PLC			   0xae	/* Power Line Communications */
-#define IFT_NFAS		   0xaf	/* Non-Facility Associated Signaling */
-#define IFT_TR008		   0xb0	/* TROO8 */
-#define IFT_GR303RDT		   0xb1	/* Remote Digital Terminal */
-#define IFT_GR303IDT		   0xb2	/* Integrated Digital Terminal */
-#define IFT_ISUP		   0xb3	/* ISUP */
-#define IFT_PROPDOCSWIRELESSMACLAYER	   0xb4	/* prop/Wireless MAC Layer */
-#define IFT_PROPDOCSWIRELESSDOWNSTREAM	   0xb5	/* prop/Wireless Downstream */
-#define IFT_PROPDOCSWIRELESSUPSTREAM	   0xb6	/* prop/Wireless Upstream */
-#define IFT_HIPERLAN2		   0xb7	/* HIPERLAN Type 2 Radio Interface */
-#define IFT_PROPBWAP2MP		   0xb8	/* PropBroadbandWirelessAccess P2MP*/
-#define IFT_SONETOVERHEADCHANNEL   0xb9	/* SONET Overhead Channel */
-#define IFT_DIGITALWRAPPEROVERHEADCHANNEL  0xba	/* Digital Wrapper Overhead */
-#define IFT_AAL2		   0xbb	/* ATM adaptation layer 2 */
-#define IFT_RADIOMAC		   0xbc	/* MAC layer over radio links */
-#define IFT_ATMRADIO		   0xbd	/* ATM over radio links */
-#define IFT_IMT			   0xbe /* Inter-Machine Trunks */
-#define IFT_MVL			   0xbf /* Multiple Virtual Lines DSL */
-#define IFT_REACHDSL		   0xc0 /* Long Reach DSL */
-#define IFT_FRDLCIENDPT		   0xc1 /* Frame Relay DLCI End Point */
-#define IFT_ATMVCIENDPT		   0xc2 /* ATM VCI End Point */
-#define IFT_OPTICALCHANNEL	   0xc3 /* Optical Channel */
-#define IFT_OPTICALTRANSPORT	   0xc4 /* Optical Transport */
-#define IFT_PROPATM		   0xc5 /* Proprietary ATM */
-#define IFT_VOICEOVERCABLE	   0xc6 /* Voice Over Cable Interface */
-#define IFT_INFINIBAND		   0xc7 /* Infiniband */
-#define IFT_TELINK		   0xc8 /* TE Link */
-#define IFT_Q2931		   0xc9 /* Q.2931 */
-#define IFT_VIRTUALTG		   0xca /* Virtual Trunk Group */
-#define IFT_SIPTG		   0xcb /* SIP Trunk Group */
-#define IFT_SIPSIG		   0xcc /* SIP Signaling */
-#define IFT_DOCSCABLEUPSTREAMCHANNEL 0xcd /* CATV Upstream Channel */
-#define IFT_ECONET		   0xce /* Acorn Econet */
-#define IFT_PON155		   0xcf /* FSAN 155Mb Symetrical PON interface */
-#define IFT_PON622		   0xd0 /* FSAN 622Mb Symetrical PON interface */
-#define IFT_BRIDGE		   0xd1 /* Transparent bridge interface */
-#define IFT_LINEGROUP		   0xd2 /* Interface common to multiple lines */
-#define IFT_VOICEEMFGD		   0xd3 /* voice E&M Feature Group D */
-#define IFT_VOICEFGDEANA	   0xd4 /* voice FGD Exchange Access North American */
-#define IFT_VOICEDID		   0xd5 /* voice Direct Inward Dialing */
-#define IFT_STF			   0xd7	/* 6to4 interface */
-
-/* not based on IANA assignments - how should we treat these? */
-#define IFT_GIF		0xf0
-#define IFT_PVC		0xf1
-#define IFT_FAITH	0xf2
-#define IFT_PFLOG	0xf5		/* Packet filter logging */
-#define IFT_PFSYNC	0xf6		/* Packet filter state syncing */
-#define IFT_CARP	0xf8		/* Common Address Redundancy Protocol */
-
-#endif /* !_NET_IF_TYPES_H_ */
diff --git a/libc/include/netinet/icmp6.h b/libc/include/netinet/icmp6.h
index 6625712..e3e6e9a 100644
--- a/libc/include/netinet/icmp6.h
+++ b/libc/include/netinet/icmp6.h
@@ -107,13 +107,6 @@
 #define ICMP6_MEMBERSHIP_REPORT		131	/* group membership report */
 #define ICMP6_MEMBERSHIP_REDUCTION	132	/* group membership termination */
 
-#ifndef _KERNEL
-/* the followings are for backward compatibility to old KAME apps. */
-#define MLD6_LISTENER_QUERY	MLD_LISTENER_QUERY
-#define MLD6_LISTENER_REPORT	MLD_LISTENER_REPORT
-#define MLD6_LISTENER_DONE	MLD_LISTENER_DONE
-#endif
-
 #define ND_ROUTER_SOLICIT		133	/* router solicitation */
 #define ND_ROUTER_ADVERT		134	/* router advertisement */
 #define ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
@@ -134,12 +127,6 @@
 #define MLD_MTRACE_RESP			200	/* mtrace response(to sender) */
 #define MLD_MTRACE			201	/* mtrace messages */
 
-#ifndef _KERNEL
-/* the followings are for backward compatibility to old KAME apps. */
-#define MLD6_MTRACE_RESP	MLD_MTRACE_RESP
-#define MLD6_MTRACE		MLD_MTRACE
-#endif
-
 #define ICMP6_MAXTYPE			201
 
 #define ICMP6_DST_UNREACH_NOROUTE	0	/* no route to destination */
@@ -185,17 +172,6 @@
 	struct in6_addr		mld_addr; /* multicast address */
 } __packed;
 
-/* definitions to provide backward compatibility to old KAME applications */
-#ifndef _KERNEL
-#define mld6_hdr	mld_hdr
-#define mld6_type	mld_type
-#define mld6_code	mld_code
-#define mld6_cksum	mld_cksum
-#define mld6_maxdelay	mld_maxdelay
-#define mld6_reserved	mld_reserved
-#define mld6_addr	mld_addr
-#endif
-
 /* shortcut macro definitions */
 #define mld_type	mld_icmp6_hdr.icmp6_type
 #define mld_code	mld_icmp6_hdr.icmp6_code
@@ -562,233 +538,4 @@
  * END android-changed
  */
 
-/*
- * Variables related to this implementation
- * of the internet control message protocol version 6.
- */
-
-/*
- * IPv6 ICMP statistics.
- * Each counter is an unsigned 64-bit value.
- */
-#define	ICMP6_STAT_ERROR	0	/* # of calls to icmp6_error */
-#define	ICMP6_STAT_CANTERROR	1	/* no error (old was icmp) */
-#define	ICMP6_STAT_TOOFREQ	2	/* no error (rate limitation) */
-#define	ICMP6_STAT_OUTHIST	3	/* # of output messages */
-		/* space for 256 counters */
-#define	ICMP6_STAT_BADCODE	259	/* icmp6_code out of range */
-#define	ICMP6_STAT_TOOSHORT	260	/* packet < sizeof(struct icmp6_hdr) */
-#define	ICMP6_STAT_CHECKSUM	261	/* bad checksum */
-#define	ICMP6_STAT_BADLEN	262	/* calculated bound mismatch */
-	/*
-	 * number of responses; this member is inherited from the netinet code,
-	 * but for netinet6 code, it is already available in outhist[].
-	 */
-#define	ICMP6_STAT_REFLECT	263
-#define	ICMP6_STAT_INHIST	264	/* # of input messages */
-		/* space for 256 counters */
-#define	ICMP6_STAT_ND_TOOMANYOPT 520	/* too many ND options */
-#define	ICMP6_STAT_OUTERRHIST	521
-		/* space for 13 counters */
-#define	ICMP6_STAT_PMTUCHG	534	/* path MTU changes */
-#define	ICMP6_STAT_ND_BADOPT	535	/* bad ND options */
-#define	ICMP6_STAT_BADNS	536	/* bad neighbor solicititation */
-#define	ICMP6_STAT_BADNA	537	/* bad neighbor advertisement */
-#define	ICMP6_STAT_BADRS	538	/* bad router solicitiation */
-#define	ICMP6_STAT_BADRA	539	/* bad router advertisement */
-#define	ICMP6_STAT_BADREDIRECT	540	/* bad redirect message */
-#define ICMP6_STAT_DROPPED_RAROUTE 541	/* discarded routes from router advertisement */
-
-#define	ICMP6_NSTATS		542
-
-#define	ICMP6_ERRSTAT_DST_UNREACH_NOROUTE	0
-#define	ICMP6_ERRSTAT_DST_UNREACH_ADMIN		1
-#define	ICMP6_ERRSTAT_DST_UNREACH_BEYONDSCOPE	2
-#define	ICMP6_ERRSTAT_DST_UNREACH_ADDR		3
-#define	ICMP6_ERRSTAT_DST_UNREACH_NOPORT	4
-#define	ICMP6_ERRSTAT_PACKET_TOO_BIG		5
-#define	ICMP6_ERRSTAT_TIME_EXCEED_TRANSIT	6
-#define	ICMP6_ERRSTAT_TIME_EXCEED_REASSEMBLY	7
-#define	ICMP6_ERRSTAT_PARAMPROB_HEADER		8
-#define	ICMP6_ERRSTAT_PARAMPROB_NEXTHEADER	9
-#define	ICMP6_ERRSTAT_PARAMPROB_OPTION		10
-#define	ICMP6_ERRSTAT_REDIRECT			11
-#define	ICMP6_ERRSTAT_UNKNOWN			12
-
-/*
- * Names for ICMP sysctl objects
- */
-#define ICMPV6CTL_STATS		1
-#define ICMPV6CTL_REDIRACCEPT	2	/* accept/process redirects */
-#define ICMPV6CTL_REDIRTIMEOUT	3	/* redirect cache time */
-#if 0	/*obsoleted*/
-#define ICMPV6CTL_ERRRATELIMIT	5	/* ICMPv6 error rate limitation */
-#endif
-#define ICMPV6CTL_ND6_PRUNE	6
-#define ICMPV6CTL_ND6_DELAY	8
-#define ICMPV6CTL_ND6_UMAXTRIES	9
-#define ICMPV6CTL_ND6_MMAXTRIES		10
-#define ICMPV6CTL_ND6_USELOOPBACK	11
-/*#define ICMPV6CTL_ND6_PROXYALL	12	obsoleted, do not reuse here */
-#define ICMPV6CTL_NODEINFO	13
-#define ICMPV6CTL_ERRPPSLIMIT	14	/* ICMPv6 error pps limitation */
-#define ICMPV6CTL_ND6_MAXNUDHINT	15
-#define ICMPV6CTL_MTUDISC_HIWAT	16
-#define ICMPV6CTL_MTUDISC_LOWAT	17
-#define ICMPV6CTL_ND6_DEBUG	18
-#define ICMPV6CTL_ND6_DRLIST	19
-#define ICMPV6CTL_ND6_PRLIST	20
-#define	ICMPV6CTL_ND6_MAXQLEN	24
-#define ICMPV6CTL_MAXID		25
-
-#define ICMPV6CTL_NAMES { \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ "rediraccept", CTLTYPE_INT }, \
-	{ "redirtimeout", CTLTYPE_INT }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ "nd6_prune", CTLTYPE_INT }, \
-	{ 0, 0 }, \
-	{ "nd6_delay", CTLTYPE_INT }, \
-	{ "nd6_umaxtries", CTLTYPE_INT }, \
-	{ "nd6_mmaxtries", CTLTYPE_INT }, \
-	{ "nd6_useloopback", CTLTYPE_INT }, \
-	{ 0, 0 }, \
-	{ "nodeinfo", CTLTYPE_INT }, \
-	{ "errppslimit", CTLTYPE_INT }, \
-	{ "nd6_maxnudhint", CTLTYPE_INT }, \
-	{ "mtudisc_hiwat", CTLTYPE_INT }, \
-	{ "mtudisc_lowat", CTLTYPE_INT }, \
-	{ "nd6_debug", CTLTYPE_INT }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ 0, 0 }, \
-	{ "nd6_maxqueuelen", CTLTYPE_INT }, \
-}
-
-#ifdef _KERNEL
-struct	rtentry;
-struct	rttimer;
-struct	in6_multi;
-
-void	icmp6_init(void);
-void	icmp6_paramerror(struct mbuf *, int);
-void	icmp6_error(struct mbuf *, int, int, int);
-void	icmp6_error2(struct mbuf *, int, int, int, struct ifnet *);
-int	icmp6_input(struct mbuf **, int *, int);
-void	icmp6_fasttimo(void);
-void	icmp6_reflect(struct mbuf *, size_t);
-void	icmp6_prepare(struct mbuf *);
-void	icmp6_redirect_input(struct mbuf *, int);
-void	icmp6_redirect_output(struct mbuf *, struct rtentry *);
-int	icmp6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
-
-void	icmp6_statinc(u_int);
-
-struct	ip6ctlparam;
-void	icmp6_mtudisc_update(struct ip6ctlparam *, int);
-void	icmp6_mtudisc_callback_register(void (*)(struct in6_addr *));
-
-/* XXX: is this the right place for these macros? */
-#define icmp6_ifstat_inc(ifp, tag) \
-do {								\
-	if (ifp)						\
-		((struct in6_ifextra *)((ifp)->if_afdata[AF_INET6]))->icmp6_ifstat->tag++; \
-} while (/*CONSTCOND*/ 0)
-
-#define icmp6_ifoutstat_inc(ifp, type, code) \
-do { \
-		icmp6_ifstat_inc(ifp, ifs6_out_msg); \
-		switch(type) { \
-		 case ICMP6_DST_UNREACH: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \
-			 if (code == ICMP6_DST_UNREACH_ADMIN) \
-				 icmp6_ifstat_inc(ifp, ifs6_out_adminprohib); \
-			 break; \
-		 case ICMP6_PACKET_TOO_BIG: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_pkttoobig); \
-			 break; \
-		 case ICMP6_TIME_EXCEEDED: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_timeexceed); \
-			 break; \
-		 case ICMP6_PARAM_PROB: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_paramprob); \
-			 break; \
-		 case ICMP6_ECHO_REQUEST: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_echo); \
-			 break; \
-		 case ICMP6_ECHO_REPLY: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_echoreply); \
-			 break; \
-		 case MLD_LISTENER_QUERY: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_mldquery); \
-			 break; \
-		 case MLD_LISTENER_REPORT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_mldreport); \
-			 break; \
-		 case MLD_LISTENER_DONE: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_mlddone); \
-			 break; \
-		 case ND_ROUTER_SOLICIT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_routersolicit); \
-			 break; \
-		 case ND_ROUTER_ADVERT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_routeradvert); \
-			 break; \
-		 case ND_NEIGHBOR_SOLICIT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit); \
-			 break; \
-		 case ND_NEIGHBOR_ADVERT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert); \
-			 break; \
-		 case ND_REDIRECT: \
-			 icmp6_ifstat_inc(ifp, ifs6_out_redirect); \
-			 break; \
-		} \
-} while (/*CONSTCOND*/ 0)
-
-extern int	icmp6_rediraccept;	/* accept/process redirects */
-extern int	icmp6_redirtimeout;	/* cache time for redirect routes */
-#endif /* _KERNEL */
-
-#ifdef ICMP6_STRINGS
-/* Info: http://www.iana.org/assignments/icmpv6-parameters */
-
-static const char * const icmp6_type_err[] = {
-	"reserved0", "unreach", "packet_too_big", "timxceed", "paramprob",
-	NULL
-};
-
-static const char * const icmp6_type_info[] = {
-	"echo", "echoreply",
-	"mcastlistenq", "mcastlistenrep", "mcastlistendone",
-	"rtsol", "rtadv", "neighsol", "neighadv", "redirect",
-	"routerrenum", "nodeinfoq", "nodeinfor", "invneighsol", "invneighrep",
-	"mcastlistenrep2", "haad_req", "haad_rep",
-	"mobile_psol", "mobile_padv", "cga_sol", "cga_adv",
-	"experimental150", "mcast_rtadv", "mcast_rtsol", "mcast_rtterm",
-	"fmipv6_msg", "rpl_control", NULL
-};
-
-static const char * const icmp6_code_none[] = { "none", NULL };
-
-static const char * const icmp6_code_unreach[] = {
-	"noroute", "admin", "beyondscope", "addr", "port",
-	"srcaddr_policy", "reject_route", "source_route_err", NULL
-};
-
-static const char * const icmp6_code_timxceed[] = {
-	"intrans", "reass", NULL
-};
-
-static const char * const icmp6_code_paramprob[] = {
-	"hdr_field", "nxthdr_type", "option", NULL
-};      
-
-/* not all informational icmps that have codes have a names array */
-#endif
-
 #endif /* !_NETINET_ICMP6_H_ */
diff --git a/libc/include/netinet/in_systm.h b/libc/include/netinet/in_systm.h
index 7e474ba..188268e 100644
--- a/libc/include/netinet/in_systm.h
+++ b/libc/include/netinet/in_systm.h
@@ -54,8 +54,4 @@
 
 typedef u_int32_t n_time;		/* ms since 00:00 GMT, byte rev */
 
-#ifdef _KERNEL
-n_time	 iptime (void);
-#endif
-
 #endif /* !_NETINET_IN_SYSTM_H_ */
diff --git a/libc/include/netinet/ip6.h b/libc/include/netinet/ip6.h
index aa89186..52fcfae 100644
--- a/libc/include/netinet/ip6.h
+++ b/libc/include/netinet/ip6.h
@@ -112,20 +112,6 @@
 #define IP6TOS_ECT		0x02	/* ECN-capable transport */
 #endif
 
-#ifdef _KERNEL
-/*
- * for IPv6 pseudo header checksum
- * XXX nonstandard
- */
-struct ip6_hdr_pseudo {
-	struct in6_addr ip6ph_src;
-	struct in6_addr ip6ph_dst;
-	u_int32_t	ip6ph_len;
-	u_int8_t	ip6ph_zero[3];
-	u_int8_t	ip6ph_nxt;
-} __packed;
-#endif
-
 /*
  * Extension Headers
  */
@@ -271,53 +257,4 @@
 #define IPV6_MMTU	1280	/* minimal MTU and reassembly. 1024 + 256 */
 #define IPV6_MAXPACKET	65535	/* ip6 max packet size without Jumbo payload*/
 
-#ifdef _KERNEL
-/*
- * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
- * "len") is located in single mbuf, on contiguous memory region.
- * The pointer to the region will be returned to pointer variable "val",
- * with type "typ".
- * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
- * very top of mbuf.  GET0 is likely to make memory copy than GET.
- *
- * XXX we're now testing this, needs m_pulldown()
- */
-#define IP6_EXTHDR_GET(val, typ, m, off, len) \
-do {									\
-	struct mbuf *_t;						\
-	int _tmp;							\
-	if ((m)->m_len >= (off) + (len))				\
-		(val) = (typ)(mtod((m), char *) + (off));		\
-	else {								\
-		_t = m_pulldown((m), (off), (len), &_tmp);		\
-		if (_t) {						\
-			if (_t->m_len < _tmp + (len))			\
-				panic("m_pulldown malfunction");	\
-			(val) = (typ)(mtod(_t, char *) + _tmp);	\
-		} else {						\
-			(val) = (typ)NULL;				\
-			(m) = NULL;					\
-		}							\
-	}								\
-} while (/*CONSTCOND*/ 0)
-
-#define IP6_EXTHDR_GET0(val, typ, m, off, len) \
-do {									\
-	struct mbuf *_t;						\
-	if ((off) == 0 && (m)->m_len >= len)				\
-		(val) = (typ)mtod((m), void *);			\
-	else {								\
-		_t = m_pulldown((m), (off), (len), NULL);		\
-		if (_t) {						\
-			if (_t->m_len < (len))				\
-				panic("m_pulldown malfunction");	\
-			(val) = (typ)mtod(_t, void *);			\
-		} else {						\
-			(val) = (typ)NULL;				\
-			(m) = NULL;					\
-		}							\
-	}								\
-} while (/*CONSTCOND*/ 0)
-#endif /*_KERNEL*/
-
 #endif /* !_NETINET_IP6_H_ */
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 2df9b74..b4a48f0 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -135,49 +135,51 @@
 
 int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) __INTRODUCED_IN(21);
 
-int pthread_attr_destroy(pthread_attr_t*) __nonnull((1));
-int pthread_attr_getdetachstate(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getguardsize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
-int pthread_attr_getschedparam(const pthread_attr_t*, struct sched_param*) __nonnull((1, 2));
-int pthread_attr_getschedpolicy(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getscope(const pthread_attr_t*, int*) __nonnull((1, 2));
-int pthread_attr_getstack(const pthread_attr_t*, void**, size_t*) __nonnull((1, 2, 3));
-int pthread_attr_getstacksize(const pthread_attr_t*, size_t*) __nonnull((1, 2));
-int pthread_attr_init(pthread_attr_t*) __nonnull((1));
-int pthread_attr_setdetachstate(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setguardsize(pthread_attr_t*, size_t) __nonnull((1));
-int pthread_attr_setschedparam(pthread_attr_t*, const struct sched_param*) __nonnull((1, 2));
-int pthread_attr_setschedpolicy(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setscope(pthread_attr_t*, int) __nonnull((1));
-int pthread_attr_setstack(pthread_attr_t*, void*, size_t) __nonnull((1));
-int pthread_attr_setstacksize(pthread_attr_t*, size_t) __nonnull((1));
+int pthread_attr_destroy(pthread_attr_t* _Nonnull);
+int pthread_attr_getdetachstate(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getguardsize(const pthread_attr_t* _Nonnull, size_t* _Nonnull);
+int pthread_attr_getschedparam(const pthread_attr_t* _Nonnull, struct sched_param* _Nonnull);
+int pthread_attr_getschedpolicy(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getscope(const pthread_attr_t* _Nonnull, int* _Nonnull);
+int pthread_attr_getstack(const pthread_attr_t* _Nonnull, void** _Nonnull, size_t* _Nonnull);
+int pthread_attr_getstacksize(const pthread_attr_t* _Nonnull, size_t* _Nonnull);
+int pthread_attr_init(pthread_attr_t* _Nonnull);
+int pthread_attr_setdetachstate(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setguardsize(pthread_attr_t* _Nonnull, size_t);
+int pthread_attr_setschedparam(pthread_attr_t* _Nonnull, const struct sched_param* _Nonnull);
+int pthread_attr_setschedpolicy(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setscope(pthread_attr_t* _Nonnull, int);
+int pthread_attr_setstack(pthread_attr_t* _Nonnull, void*, size_t);
+int pthread_attr_setstacksize(pthread_attr_t* _Nonnull, size_t);
 
-int pthread_condattr_destroy(pthread_condattr_t*) __nonnull((1));
-int pthread_condattr_getclock(const pthread_condattr_t*, clockid_t*) __nonnull((1, 2))
+int pthread_condattr_destroy(pthread_condattr_t* _Nonnull);
+int pthread_condattr_getclock(const pthread_condattr_t* _Nonnull, clockid_t* _Nonnull)
   __INTRODUCED_IN(21);
-int pthread_condattr_getpshared(const pthread_condattr_t*, int*) __nonnull((1, 2));
-int pthread_condattr_init(pthread_condattr_t*) __nonnull((1));
-int pthread_condattr_setclock(pthread_condattr_t*, clockid_t) __nonnull((1)) __INTRODUCED_IN(21);
-int pthread_condattr_setpshared(pthread_condattr_t*, int) __nonnull((1));
+int pthread_condattr_getpshared(const pthread_condattr_t* _Nonnull, int* _Nonnull);
+int pthread_condattr_init(pthread_condattr_t* _Nonnull);
+int pthread_condattr_setclock(pthread_condattr_t* _Nonnull, clockid_t) __INTRODUCED_IN(21);
+int pthread_condattr_setpshared(pthread_condattr_t* _Nonnull, int);
 
-int pthread_cond_broadcast(pthread_cond_t*) __nonnull((1));
-int pthread_cond_destroy(pthread_cond_t*) __nonnull((1));
-int pthread_cond_init(pthread_cond_t*, const pthread_condattr_t*) __nonnull((1));
-int pthread_cond_signal(pthread_cond_t*) __nonnull((1));
-int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) __nonnull((1, 2, 3));
-int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*) __nonnull((1, 2));
+int pthread_cond_broadcast(pthread_cond_t* _Nonnull);
+int pthread_cond_destroy(pthread_cond_t* _Nonnull);
+int pthread_cond_init(pthread_cond_t* _Nonnull, const pthread_condattr_t*);
+int pthread_cond_signal(pthread_cond_t* _Nonnull);
+int pthread_cond_timedwait(pthread_cond_t* _Nonnull, pthread_mutex_t* _Nonnull,
+                           const struct timespec* _Nonnull);
+int pthread_cond_wait(pthread_cond_t* _Nonnull, pthread_mutex_t* _Nonnull);
 
-int pthread_create(pthread_t*, pthread_attr_t const*, void *(*)(void*), void*) __nonnull((1, 3));
+int pthread_create(pthread_t* _Nonnull, pthread_attr_t const*,
+                   void* (* _Nonnull start_routine)(void*), void*);
 int pthread_detach(pthread_t);
 void pthread_exit(void*) __noreturn;
 
 int pthread_equal(pthread_t, pthread_t);
 
-int pthread_getattr_np(pthread_t, pthread_attr_t*) __nonnull((2));
+int pthread_getattr_np(pthread_t, pthread_attr_t* _Nonnull);
 
-int pthread_getcpuclockid(pthread_t, clockid_t*) __nonnull((2));
+int pthread_getcpuclockid(pthread_t, clockid_t* _Nonnull);
 
-int pthread_getschedparam(pthread_t, int*, struct sched_param*) __nonnull((2, 3));
+int pthread_getschedparam(pthread_t, int* _Nonnull, struct sched_param* _Nonnull);
 
 void* pthread_getspecific(pthread_key_t);
 
@@ -185,79 +187,71 @@
 
 int pthread_join(pthread_t, void**);
 
-int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1));
+int pthread_key_create(pthread_key_t* _Nonnull, void (*)(void*));
 int pthread_key_delete(pthread_key_t);
 
-int pthread_mutexattr_destroy(pthread_mutexattr_t*) __nonnull((1));
-int pthread_mutexattr_getpshared(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
-int pthread_mutexattr_gettype(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
-int pthread_mutexattr_init(pthread_mutexattr_t*) __nonnull((1));
-int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int) __nonnull((1));
-int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __nonnull((1));
+int pthread_mutexattr_destroy(pthread_mutexattr_t* _Nonnull);
+int pthread_mutexattr_getpshared(const pthread_mutexattr_t* _Nonnull, int* _Nonnull);
+int pthread_mutexattr_gettype(const pthread_mutexattr_t* _Nonnull, int* _Nonnull);
+int pthread_mutexattr_init(pthread_mutexattr_t* _Nonnull);
+int pthread_mutexattr_setpshared(pthread_mutexattr_t* _Nonnull, int);
+int pthread_mutexattr_settype(pthread_mutexattr_t* _Nonnull, int);
 
-int pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1));
-int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1));
-#if !defined(__LP64__)
-int pthread_mutex_lock(pthread_mutex_t*) /* __nonnull((1)) */;
-#else
-int pthread_mutex_lock(pthread_mutex_t*) __nonnull((1));
-#endif
-int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2))
+int pthread_mutex_destroy(pthread_mutex_t* _Nonnull);
+int pthread_mutex_init(pthread_mutex_t* _Nonnull, const pthread_mutexattr_t*);
+int pthread_mutex_lock(pthread_mutex_t* _Nonnull);
+int pthread_mutex_timedlock(pthread_mutex_t* _Nonnull, const struct timespec* _Nonnull)
   __INTRODUCED_IN(21);
-int pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1));
-#if !defined(__LP4__)
-int pthread_mutex_unlock(pthread_mutex_t*) /* __nonnull((1)) */;
-#else
-int pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1));
-#endif
+int pthread_mutex_trylock(pthread_mutex_t* _Nonnull);
+int pthread_mutex_unlock(pthread_mutex_t* _Nonnull);
 
-int pthread_once(pthread_once_t*, void (*)(void)) __nonnull((1, 2));
+int pthread_once(pthread_once_t* _Nonnull, void (* _Nonnull init_routine)(void));
 
-int pthread_rwlockattr_init(pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlockattr_destroy(pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t*, int*) __nonnull((1, 2));
-int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int) __nonnull((1));
-int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t*, int*) __nonnull((1, 2))
+int pthread_rwlockattr_init(pthread_rwlockattr_t* _Nonnull);
+int pthread_rwlockattr_destroy(pthread_rwlockattr_t* _Nonnull);
+int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t* _Nonnull, int* _Nonnull);
+int pthread_rwlockattr_setpshared(pthread_rwlockattr_t* _Nonnull, int);
+int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t* _Nonnull, int* _Nonnull)
   __INTRODUCED_IN(23);
-int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t*, int) __nonnull((1)) __INTRODUCED_IN(23);
+int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t* _Nonnull, int) __INTRODUCED_IN(23);
 
-int pthread_rwlock_destroy(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_init(pthread_rwlock_t*, const pthread_rwlockattr_t*) __nonnull((1));
-int pthread_rwlock_rdlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_timedrdlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
-int pthread_rwlock_timedwrlock(pthread_rwlock_t*, const struct timespec*) __nonnull((1, 2));
-int pthread_rwlock_tryrdlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_trywrlock(pthread_rwlock_t*) __nonnull((1));
-int pthread_rwlock_unlock(pthread_rwlock_t *) __nonnull((1));
-int pthread_rwlock_wrlock(pthread_rwlock_t*) __nonnull((1));
+int pthread_rwlock_destroy(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_init(pthread_rwlock_t* _Nonnull, const pthread_rwlockattr_t*);
+int pthread_rwlock_rdlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_timedrdlock(pthread_rwlock_t* _Nonnull, const struct timespec* _Nonnull);
+int pthread_rwlock_timedwrlock(pthread_rwlock_t* _Nonnull, const struct timespec* _Nonnull);
+int pthread_rwlock_tryrdlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_trywrlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_unlock(pthread_rwlock_t* _Nonnull);
+int pthread_rwlock_wrlock(pthread_rwlock_t* _Nonnull);
 
-int pthread_barrierattr_init(pthread_barrierattr_t* attr) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_barrierattr_destroy(pthread_barrierattr_t* attr) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_barrierattr_getpshared(pthread_barrierattr_t* attr, int* pshared) __nonnull((1, 2))
+int pthread_barrierattr_init(pthread_barrierattr_t* _Nonnull attr) __INTRODUCED_IN(24);
+int pthread_barrierattr_destroy(pthread_barrierattr_t* _Nonnull attr) __INTRODUCED_IN(24);
+int pthread_barrierattr_getpshared(pthread_barrierattr_t* _Nonnull attr, int* _Nonnull pshared)
   __INTRODUCED_IN(24);
-int pthread_barrierattr_setpshared(pthread_barrierattr_t* attr, int pshared) __nonnull((1))
+int pthread_barrierattr_setpshared(pthread_barrierattr_t* _Nonnull attr, int pshared)
   __INTRODUCED_IN(24);
 
-int pthread_barrier_init(pthread_barrier_t*, const pthread_barrierattr_t*, unsigned) __nonnull((1))
+int pthread_barrier_init(pthread_barrier_t* _Nonnull, const pthread_barrierattr_t*, unsigned)
   __INTRODUCED_IN(24);
-int pthread_barrier_destroy(pthread_barrier_t*) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_barrier_wait(pthread_barrier_t*) __nonnull((1)) __INTRODUCED_IN(24);
+int pthread_barrier_destroy(pthread_barrier_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_barrier_wait(pthread_barrier_t* _Nonnull) __INTRODUCED_IN(24);
 
-int pthread_spin_destroy(pthread_spinlock_t*) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_spin_init(pthread_spinlock_t*, int) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_spin_lock(pthread_spinlock_t*) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_spin_trylock(pthread_spinlock_t*) __nonnull((1)) __INTRODUCED_IN(24);
-int pthread_spin_unlock(pthread_spinlock_t*) __nonnull((1)) __INTRODUCED_IN(24);
+int pthread_spin_destroy(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_init(pthread_spinlock_t* _Nonnull, int) __INTRODUCED_IN(24);
+int pthread_spin_lock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_trylock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
+int pthread_spin_unlock(pthread_spinlock_t* _Nonnull) __INTRODUCED_IN(24);
 
 pthread_t pthread_self(void) __pure2;
 
 #if defined(__USE_GNU)
-int pthread_getname_np(pthread_t, char*, size_t) __nonnull((2)) __INTRODUCED_IN_FUTURE;
+int pthread_getname_np(pthread_t, char* _Nonnull, size_t) __INTRODUCED_IN_FUTURE;
 #endif
 /* TODO: this should be __USE_GNU too. */
-int pthread_setname_np(pthread_t, const char*) __nonnull((2));
+int pthread_setname_np(pthread_t, const char* _Nonnull);
 
-int pthread_setschedparam(pthread_t, int, const struct sched_param*) __nonnull((3));
+int pthread_setschedparam(pthread_t, int, const struct sched_param* _Nonnull);
 
 int pthread_setspecific(pthread_key_t, const void*);
 
@@ -287,16 +281,6 @@
         __pthread_cleanup_pop( &__cleanup, (execute)); \
     } while (0);                                       \
 
-
-#if !defined(__LP64__)
-
-// Bionic additions that are deprecated even in the 32-bit ABI.
-int pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) __attribute__((deprecated("use pthread_cond_timedwait instead")));
-
-int pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned) __attribute__((deprecated("use pthread_mutex_timedlock instead")));
-
-#endif /* !defined(__LP64__) */
-
 __END_DECLS
 
 #endif /* _PTHREAD_H_ */
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 4b5e4ac..d9f43de 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -120,10 +120,10 @@
 __BIONIC_LEGACY_INLINE int sigfillset(sigset_t*);
 __BIONIC_LEGACY_INLINE int sigismember(const sigset_t*, int);
 
-extern int sigpending(sigset_t*) __nonnull((1));
+extern int sigpending(sigset_t* _Nonnull);
 extern int sigprocmask(int, const sigset_t*, sigset_t*);
-extern int sigsuspend(const sigset_t*) __nonnull((1));
-extern int sigwait(const sigset_t*, int*) __nonnull((1, 2));
+extern int sigsuspend(const sigset_t* _Nonnull);
+extern int sigwait(const sigset_t* _Nonnull, int* _Nonnull);
 
 extern int sighold(int)
   __attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
diff --git a/libc/include/string.h b/libc/include/string.h
index 3f98af1..f39a86b 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -120,10 +120,10 @@
  */
 
 #if defined(__cplusplus)
-extern "C++" char* basename(char*) __RENAME(__gnu_basename) __nonnull((1));
-extern "C++" const char* basename(const char*) __RENAME(__gnu_basename) __nonnull((1));
+extern "C++" char* basename(char* _Nonnull) __RENAME(__gnu_basename);
+extern "C++" const char* basename(const char* _Nonnull) __RENAME(__gnu_basename);
 #else
-extern char* basename(const char*) __RENAME(__gnu_basename) __nonnull((1)) __INTRODUCED_IN(23);
+extern char* basename(const char* _Nonnull) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
 #endif
 #endif
 
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 3fcf163..7b06967 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -159,6 +159,38 @@
 
 #define __nonnull(args) __attribute__((__nonnull__ args))
 
+/*
+ * _Nonnull is similar to the nonnull attribute in that it will instruct
+ * compilers to warn the user if it can prove that a null argument is being
+ * passed. Unlike the nonnull attribute, this annotation indicated that a value
+ * *should not* be null, not that it *cannot* be null, or even that the behavior
+ * is undefined. The important distinction is that the optimizer will perform
+ * surprising optimizations like the following:
+ *
+ *     void foo(void*) __attribute__(nonnull, 1);
+ *
+ *     int bar(int* p) {
+ *       foo(p);
+ *
+ *       // The following null check will be elided because nonnull attribute
+ *       // means that, since we call foo with p, p can be assumed to not be
+ *       // null. Thus this will crash if we are called with a null pointer.
+ *       if (src != NULL) {
+ *         return *p;
+ *       }
+ *       return 0;
+ *     }
+ *
+ *     int main() {
+ *       return bar(NULL);
+ *     }
+ *
+ * http://clang.llvm.org/docs/AttributeReference.html#nonnull
+ */
+#if !(defined(__clang__) && __has_feature(nullability))
+#define _Nonnull
+#endif
+
 #define __printflike(x, y) __attribute__((__format__(printf, x, y))) __nonnull((x))
 #define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x))
 
diff --git a/libc/include/sys/signalfd.h b/libc/include/sys/signalfd.h
index 5b67822..084a528 100644
--- a/libc/include/sys/signalfd.h
+++ b/libc/include/sys/signalfd.h
@@ -35,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern int signalfd(int fd, const sigset_t* mask, int flags) __nonnull((2)) __INTRODUCED_IN(21);
+extern int signalfd(int fd, const sigset_t* _Nonnull mask, int flags) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/statvfs.h b/libc/include/sys/statvfs.h
index e12f069..1f00b9d 100644
--- a/libc/include/sys/statvfs.h
+++ b/libc/include/sys/statvfs.h
@@ -59,12 +59,12 @@
 #define ST_NODIRATIME  0x0800
 #define ST_RELATIME    0x1000
 
-extern int statvfs(const char* __restrict, struct statvfs* __restrict) __nonnull((1, 2))
+extern int statvfs(const char* __restrict _Nonnull, struct statvfs* __restrict _Nonnull)
   __INTRODUCED_IN(21);
-extern int statvfs64(const char* __restrict, struct statvfs64* __restrict) __nonnull((1, 2))
+extern int statvfs64(const char* __restrict _Nonnull, struct statvfs64* __restrict _Nonnull)
   __INTRODUCED_IN(21);
-extern int fstatvfs(int, struct statvfs*) __nonnull((2)) __INTRODUCED_IN(21);
-extern int fstatvfs64(int, struct statvfs64*) __nonnull((2)) __INTRODUCED_IN(21);
+extern int fstatvfs(int, struct statvfs* _Nonnull) __INTRODUCED_IN(21);
+extern int fstatvfs64(int, struct statvfs64* _Nonnull) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/swap.h b/libc/include/sys/swap.h
index b1f9295..fe14a30 100644
--- a/libc/include/sys/swap.h
+++ b/libc/include/sys/swap.h
@@ -38,8 +38,8 @@
 #define SWAP_FLAG_PRIO_MASK 0x7fff
 #define SWAP_FLAG_PRIO_SHIFT 0
 
-extern int swapon(const char*, int) __nonnull((1)) __INTRODUCED_IN(21);
-extern int swapoff(const char*) __nonnull((1)) __INTRODUCED_IN(21);
+extern int swapon(const char* _Nonnull, int) __INTRODUCED_IN(21);
+extern int swapoff(const char* _Nonnull) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/include/sys/ttydefaults.h b/libc/include/sys/ttydefaults.h
index 405e759..b62aab1 100644
--- a/libc/include/sys/ttydefaults.h
+++ b/libc/include/sys/ttydefaults.h
@@ -84,7 +84,6 @@
 /*
  * #define TTYDEFCHARS to include an array of default control characters.
  */
-#ifdef _KERNEL
 #ifdef TTYDEFCHARS
 const cc_t ttydefchars[NCCS] = {
 	[VEOF] = CEOF,
@@ -109,7 +108,4 @@
 	[19] = _POSIX_VDISABLE,	/* spare */
 };
 #undef TTYDEFCHARS
-#else
-extern const cc_t ttydefchars[NCCS];
 #endif
-#endif /* _KERNEL */
diff --git a/libc/include/sys/vfs.h b/libc/include/sys/vfs.h
index 9f04b28..bf094dc 100644
--- a/libc/include/sys/vfs.h
+++ b/libc/include/sys/vfs.h
@@ -137,10 +137,10 @@
 #define XENIX_SUPER_MAGIC     0x012FF7B4
 #define XFS_SUPER_MAGIC       0x58465342
 
-extern int statfs(const char*, struct statfs*) __nonnull((1, 2));
-extern int statfs64(const char*, struct statfs64*) __nonnull((1, 2)) __INTRODUCED_IN(21);
-extern int fstatfs(int, struct statfs*) __nonnull((2));
-extern int fstatfs64(int, struct statfs64*) __nonnull((2)) __INTRODUCED_IN(21);
+extern int statfs(const char* _Nonnull, struct statfs* _Nonnull);
+extern int statfs64(const char* _Nonnull, struct statfs64* _Nonnull) __INTRODUCED_IN(21);
+extern int fstatfs(int, struct statfs* _Nonnull);
+extern int fstatfs64(int, struct statfs64* _Nonnull) __INTRODUCED_IN(21);
 
 __END_DECLS
 
diff --git a/libc/tools/check-symbols-glibc.py b/libc/tools/check-symbols-glibc.py
index 43531c0..631fd93 100755
--- a/libc/tools/check-symbols-glibc.py
+++ b/libc/tools/check-symbols-glibc.py
@@ -88,7 +88,7 @@
   'strlcpy',
   'sys_signame',
   'wcslcat',
-  'wcslcpy'
+  'wcslcpy',
 ])
 # Some symbols are part of the FORTIFY implementation.
 FORTIFY_stuff = set([
@@ -108,15 +108,16 @@
   '__strlen_chk',
   '__strncpy_chk2',
   '__strrchr_chk',
-  '__umask_chk'
+  '__umask_chk',
   '__write_chk',
 ])
-# Some symbols are used to implement public macros.
+# Some symbols are used to implement public functions/macros.
 macro_stuff = set([
   '__assert2',
   '__errno',
   '__fe_dfl_env',
   '__get_h_errno',
+  '__gnu_strerror_r',
   '__fpclassifyd',
   '__isfinite',
   '__isfinitef',
@@ -132,7 +133,8 @@
 linux_stuff = set([
   'getauxval',
   'gettid',
-  'tgkill'
+  'pthread_gettid_np',
+  'tgkill',
 ])
 # Some standard stuff isn't yet in the versions of glibc we're using.
 std_stuff = set([
@@ -168,6 +170,7 @@
 libresolv_stuff = set([
   '__res_send_setqhook',
   '__res_send_setrhook',
+  '_resolv_delete_cache_for_net',
   '_resolv_flush_cache_for_net',
   '_resolv_set_nameservers_for_net',
   'dn_expand',
diff --git a/libm/Android.mk b/libm/Android.mk
index b07e426..0070bd1 100644
--- a/libm/Android.mk
+++ b/libm/Android.mk
@@ -578,10 +578,5 @@
 
 LOCAL_CXX_STL := none
 
-# We'd really like to do this for all architectures, but since this wasn't done
-# before, these symbols must continue to be exported on LP32 for binary
-# compatibility.
-LOCAL_LDFLAGS_64 := -Wl,--exclude-libs,libgcc.a
-
 include $(BUILD_SHARED_LIBRARY)
 endif
diff --git a/linker/linker.cpp b/linker/linker.cpp
index c193861..edaa6f4 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1867,6 +1867,7 @@
 }
 
 static void soinfo_unload(soinfo* si);
+static void soinfo_unload(soinfo* soinfos[], size_t count);
 
 // TODO: this is slightly unusual way to construct
 // the global group for relocation. Not every RTLD_GLOBAL
@@ -1942,9 +1943,7 @@
 
   auto failure_guard = make_scope_guard([&]() {
     // Housekeeping
-    for (size_t i = 0; i<soinfos_count; ++i) {
-      soinfo_unload(soinfos[i]);
-    }
+    soinfo_unload(soinfos, soinfos_count);
   });
 
   ZipArchiveCache zip_archive_cache;
@@ -2042,13 +2041,18 @@
       if (!si->link_image(global_group, local_group, extinfo)) {
         return false;
       }
-      si->set_linked();
     }
 
     return true;
   });
 
   if (linked) {
+    local_group.for_each([](soinfo* si) {
+      if (!si->is_linked()) {
+        si->set_linked();
+      }
+    });
+
     failure_guard.disable();
   }
 
@@ -2076,12 +2080,6 @@
 }
 
 static void soinfo_unload(soinfo* root) {
-  // Note that the library can be loaded but not linked;
-  // in which case there is no root but we still need
-  // to walk the tree and unload soinfos involved.
-  //
-  // This happens on unsuccessful dlopen, when one of
-  // the DT_NEEDED libraries could not be linked/found.
   if (root->is_linked()) {
     root = root->get_local_group_root();
   }
@@ -2091,84 +2089,112 @@
     return;
   }
 
-  size_t ref_count = root->is_linked() ? root->decrement_ref_count() : 0;
+  soinfo_unload(&root, 1);
+}
 
-  if (ref_count == 0) {
-    soinfo::soinfo_list_t local_unload_list;
-    soinfo::soinfo_list_t external_unload_list;
-    soinfo::soinfo_list_t depth_first_list;
-    depth_first_list.push_back(root);
-    soinfo* si = nullptr;
+static void soinfo_unload(soinfo* soinfos[], size_t count) {
+  // Note that the library can be loaded but not linked;
+  // in which case there is no root but we still need
+  // to walk the tree and unload soinfos involved.
+  //
+  // This happens on unsuccessful dlopen, when one of
+  // the DT_NEEDED libraries could not be linked/found.
+  if (count == 0) {
+    return;
+  }
 
-    while ((si = depth_first_list.pop_front()) != nullptr) {
-      if (local_unload_list.contains(si)) {
-        continue;
-      }
+  soinfo::soinfo_list_t unload_list;
+  for (size_t i = 0; i < count; ++i) {
+    soinfo* si = soinfos[i];
 
-      local_unload_list.push_back(si);
-
-      if (si->has_min_version(0)) {
-        soinfo* child = nullptr;
-        while ((child = si->get_children().pop_front()) != nullptr) {
-          TRACE("%s@%p needs to unload %s@%p", si->get_realpath(), si,
-              child->get_realpath(), child);
-
-          if (local_unload_list.contains(child)) {
-            continue;
-          } else if (child->is_linked() && child->get_local_group_root() != root) {
-            external_unload_list.push_back(child);
-          } else {
-            depth_first_list.push_front(child);
-          }
-        }
+    if (si->can_unload()) {
+      size_t ref_count = si->is_linked() ? si->decrement_ref_count() : 0;
+      if (ref_count == 0) {
+        unload_list.push_back(si);
       } else {
-#if !defined(__work_around_b_24465209__)
-        __libc_fatal("soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
-#else
-        PRINT("warning: soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
-        for_each_dt_needed(si, [&] (const char* library_name) {
-          TRACE("deprecated (old format of soinfo): %s needs to unload %s",
-              si->get_realpath(), library_name);
-
-          soinfo* needed = find_library(si->get_primary_namespace(),
-                                        library_name, RTLD_NOLOAD, nullptr, nullptr);
-
-          if (needed != nullptr) {
-            // Not found: for example if symlink was deleted between dlopen and dlclose
-            // Since we cannot really handle errors at this point - print and continue.
-            PRINT("warning: couldn't find %s needed by %s on unload.",
-                library_name, si->get_realpath());
-            return;
-          } else if (local_unload_list.contains(needed)) {
-            // already visited
-            return;
-          } else if (needed->is_linked() && needed->get_local_group_root() != root) {
-            // external group
-            external_unload_list.push_back(needed);
-          } else {
-            // local group
-            depth_first_list.push_front(needed);
-          }
-        });
-#endif
+        TRACE("not unloading '%s' group, decrementing ref_count to %zd",
+            si->get_realpath(), ref_count);
       }
+    } else {
+      TRACE("not unloading '%s' - the binary is flagged with NODELETE", si->get_realpath());
+      return;
+    }
+  }
+
+  // This is used to identify soinfos outside of the load-group
+  // note that we cannot have > 1 in the array and have any of them
+  // linked. This is why we can safely use the first one.
+  soinfo* root = soinfos[0];
+
+  soinfo::soinfo_list_t local_unload_list;
+  soinfo::soinfo_list_t external_unload_list;
+  soinfo* si = nullptr;
+
+  while ((si = unload_list.pop_front()) != nullptr) {
+    if (local_unload_list.contains(si)) {
+      continue;
     }
 
-    local_unload_list.for_each([](soinfo* si) {
-      si->call_destructors();
-    });
+    local_unload_list.push_back(si);
 
-    while ((si = local_unload_list.pop_front()) != nullptr) {
-      notify_gdb_of_unload(si);
-      soinfo_free(si);
-    }
+    if (si->has_min_version(0)) {
+      soinfo* child = nullptr;
+      while ((child = si->get_children().pop_front()) != nullptr) {
+        TRACE("%s@%p needs to unload %s@%p", si->get_realpath(), si,
+            child->get_realpath(), child);
 
-    while ((si = external_unload_list.pop_front()) != nullptr) {
-      soinfo_unload(si);
+        if (local_unload_list.contains(child)) {
+          continue;
+        } else if (child->is_linked() && child->get_local_group_root() != root) {
+          external_unload_list.push_back(child);
+        } else {
+          unload_list.push_front(child);
+        }
+      }
+    } else {
+#if !defined(__work_around_b_24465209__)
+      __libc_fatal("soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
+#else
+      PRINT("warning: soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
+      for_each_dt_needed(si, [&] (const char* library_name) {
+        TRACE("deprecated (old format of soinfo): %s needs to unload %s",
+            si->get_realpath(), library_name);
+
+        soinfo* needed = find_library(si->get_primary_namespace(),
+                                      library_name, RTLD_NOLOAD, nullptr, nullptr);
+
+        if (needed != nullptr) {
+          // Not found: for example if symlink was deleted between dlopen and dlclose
+          // Since we cannot really handle errors at this point - print and continue.
+          PRINT("warning: couldn't find %s needed by %s on unload.",
+              library_name, si->get_realpath());
+          return;
+        } else if (local_unload_list.contains(needed)) {
+          // already visited
+          return;
+        } else if (needed->is_linked() && needed->get_local_group_root() != root) {
+          // external group
+          external_unload_list.push_back(needed);
+        } else {
+          // local group
+          unload_list.push_front(needed);
+        }
+      });
+#endif
     }
-  } else {
-    TRACE("not unloading '%s' group, decrementing ref_count to %zd",
-        root->get_realpath(), ref_count);
+  }
+
+  local_unload_list.for_each([](soinfo* si) {
+    si->call_destructors();
+  });
+
+  while ((si = local_unload_list.pop_front()) != nullptr) {
+    notify_gdb_of_unload(si);
+    soinfo_free(si);
+  }
+
+  while ((si = external_unload_list.pop_front()) != nullptr) {
+    soinfo_unload(si);
   }
 }
 
@@ -3013,8 +3039,7 @@
 
   if (!is_main_executable() && preinit_array_ != nullptr) {
     // The GNU dynamic linker silently ignores these, but we warn the developer.
-    PRINT("\"%s\": ignoring %zd-entry DT_PREINIT_ARRAY in shared library!",
-          get_realpath(), preinit_array_count_);
+    PRINT("\"%s\": ignoring DT_PREINIT_ARRAY in shared library!", get_realpath());
   }
 
   get_children().for_each([] (soinfo* si) {
diff --git a/linker/linker.h b/linker/linker.h
index 4e2e0b9..1613398 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -470,6 +470,32 @@
 void set_application_target_sdk_version(uint32_t target);
 uint32_t get_application_target_sdk_version();
 
+enum {
+  /* A regular namespace is the namespace with a custom search path that does
+   * not impose any restrictions on the location of native libraries.
+   */
+  ANDROID_NAMESPACE_TYPE_REGULAR = 0,
+
+  /* An isolated namespace requires all the libraries to be on the search path
+   * or under permitted_when_isolated_path. The search path is the union of
+   * ld_library_path and default_library_path.
+   */
+  ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
+
+  /* The shared namespace clones the list of libraries of the caller namespace upon creation
+   * which means that they are shared between namespaces - the caller namespace and the new one
+   * will use the same copy of a library if it was loaded prior to android_create_namespace call.
+   *
+   * Note that libraries loaded after the namespace is created will not be shared.
+   *
+   * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor
+   * permitted_path from the caller's namespace.
+   */
+  ANDROID_NAMESPACE_TYPE_SHARED = 2,
+  ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
+                                           ANDROID_NAMESPACE_TYPE_ISOLATED,
+};
+
 bool init_namespaces(const char* public_ns_sonames, const char* anon_ns_library_path);
 android_namespace_t* create_namespace(const void* caller_addr, const char* name,
                                       const char* ld_library_path, const char* default_library_path,
diff --git a/tests/dlext_private.h b/tests/dlext_private.h
new file mode 100644
index 0000000..8eb86ca
--- /dev/null
+++ b/tests/dlext_private.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ANDROID_DLEXT_NAMESPACES_H__
+#define __ANDROID_DLEXT_NAMESPACES_H__
+
+#include <android/dlext.h>
+
+__BEGIN_DECLS
+
+/*
+ * Initializes public and anonymous namespaces. The public_ns_sonames is the list of sonames
+ * to be included into public namespace separated by colon. Example: "libc.so:libm.so:libdl.so".
+ * The libraries in this list should be loaded prior to this call.
+ *
+ * The anon_ns_library_path is the search path for anonymous namespace. The anonymous namespace
+ * is used in the case when linker cannot identify the caller of dlopen/dlsym. This happens
+ * for the code not loaded by dynamic linker; for example calls from the mono-compiled code.
+ */
+extern bool android_init_namespaces(const char* public_ns_sonames,
+                                    const char* anon_ns_library_path);
+
+
+enum {
+  /* A regular namespace is the namespace with a custom search path that does
+   * not impose any restrictions on the location of native libraries.
+   */
+  ANDROID_NAMESPACE_TYPE_REGULAR = 0,
+
+  /* An isolated namespace requires all the libraries to be on the search path
+   * or under permitted_when_isolated_path. The search path is the union of
+   * ld_library_path and default_library_path.
+   */
+  ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
+
+  /* The shared namespace clones the list of libraries of the caller namespace upon creation
+   * which means that they are shared between namespaces - the caller namespace and the new one
+   * will use the same copy of a library if it was loaded prior to android_create_namespace call.
+   *
+   * Note that libraries loaded after the namespace is created will not be shared.
+   *
+   * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor
+   * permitted_path from the caller's namespace.
+   */
+  ANDROID_NAMESPACE_TYPE_SHARED = 2,
+  ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
+                                           ANDROID_NAMESPACE_TYPE_ISOLATED,
+};
+
+/*
+ * Creates new linker namespace.
+ * ld_library_path and default_library_path represent the search path
+ * for the libraries in the namespace.
+ *
+ * The libraries in the namespace are searched by folowing order:
+ * 1. ld_library_path (Think of this as namespace-local LD_LIBRARY_PATH)
+ * 2. In directories specified by DT_RUNPATH of the "needed by" binary.
+ * 3. deault_library_path (This of this as namespace-local default library path)
+ *
+ * When type is ANDROID_NAMESPACE_TYPE_ISOLATED the resulting namespace requires all of
+ * the libraries to be on the search path or under the permitted_when_isolated_path;
+ * the search_path is ld_library_path:default_library_path. Note that the
+ * permitted_when_isolated_path path is not part of the search_path and
+ * does not affect the search order. It is a way to allow loading libraries from specific
+ * locations when using absolute path.
+ * If a library or any of its dependencies are outside of the permitted_when_isolated_path
+ * and search_path, and it is not part of the public namespace dlopen will fail.
+ */
+extern struct android_namespace_t* android_create_namespace(const char* name,
+                                                            const char* ld_library_path,
+                                                            const char* default_library_path,
+                                                            uint64_t type,
+                                                            const char* permitted_when_isolated_path);
+
+extern void android_set_application_target_sdk_version(uint32_t target);
+
+__END_DECLS
+
+#endif /* __ANDROID_DLEXT_NAMESPACES_H__ */
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 420c934..109bab5 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -34,6 +34,7 @@
 
 #include "TemporaryFile.h"
 #include "utils.h"
+#include "dlext_private.h"
 
 #define ASSERT_DL_NOTNULL(ptr) \
     ASSERT_TRUE(ptr != nullptr) << "dlerror: " << dlerror()
@@ -743,8 +744,6 @@
   dlclose(handle2);
 }
 
-extern "C" void android_set_application_target_sdk_version(uint32_t target);
-
 TEST(dlext, ns_isolated) {
   static const char* root_lib = "libnstest_root_not_isolated.so";
   std::string path = std::string("libc.so:libc++.so:libdl.so:libm.so:") + g_public_lib;
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index d9b2523..52a3252 100755
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -1780,7 +1780,14 @@
 
 TEST(pthread, pthread_mutex_lock_null_32) {
 #if defined(__BIONIC__) && !defined(__LP64__)
-  ASSERT_EQ(EINVAL, pthread_mutex_lock(NULL));
+  // For LP32, the pthread lock/unlock functions allow a NULL mutex and return
+  // EINVAL in that case: http://b/19995172.
+  //
+  // We decorate the public defintion with _Nonnull so that people recompiling
+  // their code with get a warning and might fix their bug, but need to pass
+  // NULL here to test that we remain compatible.
+  pthread_mutex_t* null_value = nullptr;
+  ASSERT_EQ(EINVAL, pthread_mutex_lock(null_value));
 #else
   GTEST_LOG_(INFO) << "This test tests bionic implementation details on 32 bit devices.";
 #endif
@@ -1788,7 +1795,14 @@
 
 TEST(pthread, pthread_mutex_unlock_null_32) {
 #if defined(__BIONIC__) && !defined(__LP64__)
-  ASSERT_EQ(EINVAL, pthread_mutex_unlock(NULL));
+  // For LP32, the pthread lock/unlock functions allow a NULL mutex and return
+  // EINVAL in that case: http://b/19995172.
+  //
+  // We decorate the public defintion with _Nonnull so that people recompiling
+  // their code with get a warning and might fix their bug, but need to pass
+  // NULL here to test that we remain compatible.
+  pthread_mutex_t* null_value = nullptr;
+  ASSERT_EQ(EINVAL, pthread_mutex_unlock(null_value));
 #else
   GTEST_LOG_(INFO) << "This test tests bionic implementation details on 32 bit devices.";
 #endif
diff --git a/tests/sched_test.cpp b/tests/sched_test.cpp
index 92d6c26..a4cffc0 100644
--- a/tests/sched_test.cpp
+++ b/tests/sched_test.cpp
@@ -55,7 +55,8 @@
   // Check that our hand-written clone assembler sets errno correctly on failure.
   uintptr_t fake_child_stack[16];
   errno = 0;
-  ASSERT_EQ(-1, clone(NULL, &fake_child_stack[16], CLONE_THREAD, NULL));
+  // If CLONE_THREAD is set, CLONE_SIGHAND must be set too.
+  ASSERT_EQ(-1, clone(child_fn, &fake_child_stack[16], CLONE_THREAD, NULL));
   ASSERT_EQ(EINVAL, errno);
 }
 
diff --git a/tools/relocation_packer/src/debug.h b/tools/relocation_packer/src/debug.h
index 48be6c1..fdfb795 100644
--- a/tools/relocation_packer/src/debug.h
+++ b/tools/relocation_packer/src/debug.h
@@ -81,26 +81,29 @@
 
 // Make logging severities visible globally.
 typedef relocation_packer::Logger::Severity LogSeverity;
-using LogSeverity::INFO;
-using LogSeverity::WARNING;
-using LogSeverity::ERROR;
-using LogSeverity::FATAL;
 
 // LOG(severity) prints a message with the given severity, and aborts if
 // severity is FATAL.  LOG_IF(severity, predicate) does the same but only if
 // predicate is true.  INT_MIN is guaranteed to be less than or equal to
 // any verbosity level.
-#define LOG(severity) \
-    (relocation_packer::Logger(severity, INT_MIN, true).GetStream())
-#define LOG_IF(severity, predicate) \
-    (relocation_packer::Logger(severity, INT_MIN, (predicate)).GetStream())
+#define LOG(severity)                                                      \
+  (relocation_packer::Logger(relocation_packer::Logger::severity, INT_MIN, \
+                             true)                                         \
+       .GetStream())
+#define LOG_IF(severity, predicate)                                        \
+  (relocation_packer::Logger(relocation_packer::Logger::severity, INT_MIN, \
+                             (predicate))                                  \
+       .GetStream())
 
 // VLOG(level) prints its message as INFO if level is less than or equal to
 // the current verbosity level.
-#define VLOG(level) \
-    (relocation_packer::Logger(INFO, (level), true).GetStream())
-#define VLOG_IF(level, predicate) \
-    (relocation_packer::Logger(INFO, (level), (predicate)).GetStream())
+#define VLOG(level)                                                          \
+  (relocation_packer::Logger(relocation_packer::Logger::INFO, (level), true) \
+       .GetStream())
+#define VLOG_IF(level, predicate)                                      \
+  (relocation_packer::Logger(relocation_packer::Logger::INFO, (level), \
+                             (predicate))                              \
+       .GetStream())
 
 // CHECK(predicate) fails with a FATAL log message if predicate is false.
 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \