Refresh 64-bit headers and libs

Change-Id: I300537b883705cedbcb6f21fe616f187b54c4afd
diff --git a/ndk/platforms/android-20/arch-arm64/include/fenv.h b/ndk/platforms/android-20/arch-arm64/include/fenv.h
deleted file mode 100644
index 32c3b1d..0000000
--- a/ndk/platforms/android-20/arch-arm64/include/fenv.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
- *
- * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
- */
-
-/*
- * Rewritten for Android.
- *
- * The ARM FPSCR (Floating-point Status and Control Register) described here:
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Chdfafia.html
- * has been split into the FPCR (Floating-point Control Register) and FPSR
- * (Floating-point Status Register) on the ARMv8. These are described briefly in
- * "Procedure Call Standard for the ARM 64-bit Architecture"
- * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
- * section 5.1.2 SIMD and Floating-Point Registers
- */
-
-#ifndef _FENV_H_
-#define _FENV_H_
-
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-typedef __uint32_t fenv_t;
-typedef __uint32_t fexcept_t;
-
-/* Exception flags. */
-#define FE_INVALID    0x01
-#define FE_DIVBYZERO  0x02
-#define FE_OVERFLOW   0x04
-#define FE_UNDERFLOW  0x08
-#define FE_INEXACT    0x10
-#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
-#define _FPSCR_ENABLE_SHIFT 8
-#define _FPSCR_ENABLE_MASK (FE_ALL_EXCEPT << _FPSCR_ENABLE_SHIFT)
-
-/* Rounding modes. */
-#define FE_TONEAREST  0x0
-#define FE_UPWARD     0x1
-#define FE_DOWNWARD   0x2
-#define FE_TOWARDZERO 0x3
-#define _FPSCR_RMODE_SHIFT 22
-
-#define FPCR_IOE    (1 << 8)
-#define FPCR_DZE    (1 << 9)
-#define FPCR_OFE    (1 << 10)
-#define FPCR_UFE    (1 << 11)
-#define FPCR_IXE    (1 << 12)
-#define FPCR_IDE    (1 << 15)
-#define FPCR_LEN    (7 << 16)
-#define FPCR_STRIDE (3 << 20)
-#define FPCR_RMODE  (3 << 22)
-#define FPCR_FZ     (1 << 24)
-#define FPCR_DN     (1 << 25)
-#define FPCR_AHP    (1 << 26)
-#define FPCR_MASK   (FPCR_IOE | \
-                     FPCR_DZE | \
-                     FPCR_OFE | \
-                     FPCR_UFE | \
-                     FPCR_IXE | \
-                     FPCR_IDE | \
-                     FPCR_LEN | \
-                     FPCR_STRIDE | \
-                     FPCR_RMODE | \
-                     FPCR_FZ | \
-                     FPCR_DN | \
-                     FPCR_AHP )
-
-#define FPSR_IOC    (1 << 0)
-#define FPSR_DZC    (1 << 1)
-#define FPSR_OFC    (1 << 2)
-#define FPSR_UFC    (1 << 3)
-#define FPSR_IXC    (1 << 4)
-#define FPSR_IDC    (1 << 7)
-#define FPSR_QC     (1 << 27)
-#define FPSR_V      (1 << 28)
-#define FPSR_C      (1 << 29)
-#define FPSR_Z      (1 << 30)
-#define FPSR_N      (1 << 31)
-#define FPSR_MASK   (FPSR_IOC | \
-                     FPSR_DZC | \
-                     FPSR_OFC | \
-                     FPSR_UFC | \
-                     FPSR_IXC | \
-                     FPSR_IDC | \
-                     FPSR_QC | \
-                     FPSR_V | \
-                     FPSR_C | \
-                     FPSR_Z | \
-                     FPSR_N )
-
-/* Default floating-point environment. */
-extern const fenv_t __fe_dfl_env;
-#define FE_DFL_ENV (&__fe_dfl_env)
-
-static __inline int fegetenv(fenv_t* __envp) {
-    fenv_t _fpcr, _fpsr;
-    __asm__ __volatile__("mrs %0,fpcr" : "=r" (_fpcr));
-    __asm__ __volatile__("mrs %0,fpsr" : "=r" (_fpsr));
-  *__envp = (_fpcr | _fpsr);
-  return 0;
-}
-
-static __inline int fesetenv(const fenv_t* __envp) {
-    fenv_t _fpcr = (*__envp & FPCR_MASK);
-    fenv_t _fpsr = (*__envp & FPSR_MASK);
-    __asm__ __volatile__("msr fpcr,%0" : :"ri" (_fpcr));
-    __asm__ __volatile__("msr fpsr,%0" : :"ri" (_fpsr));
-  return 0;
-}
-
-static __inline int feclearexcept(int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  __fpscr &= ~__excepts;
-  fesetenv(&__fpscr);
-  return 0;
-}
-
-static __inline int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  *__flagp = __fpscr & __excepts;
-  return 0;
-}
-
-static __inline int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  __fpscr &= ~__excepts;
-  __fpscr |= *__flagp & __excepts;
-  fesetenv(&__fpscr);
-  return 0;
-}
-
-static __inline int feraiseexcept(int __excepts) {
-  fexcept_t __ex = __excepts;
-  fesetexceptflag(&__ex, __excepts);
-  return 0;
-}
-
-static __inline int fetestexcept(int __excepts) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  return (__fpscr & __excepts);
-}
-
-static __inline int fegetround(void) {
-  fenv_t _fpscr;
-  fegetenv(&_fpscr);
-  return ((_fpscr >> _FPSCR_RMODE_SHIFT) & 0x3);
-}
-
-static __inline int fesetround(int __round) {
-  fenv_t _fpscr;
-  fegetenv(&_fpscr);
-  _fpscr &= ~(0x3 << _FPSCR_RMODE_SHIFT);
-  _fpscr |= (__round << _FPSCR_RMODE_SHIFT);
-  fesetenv(&_fpscr);
-  return 0;
-}
-
-static __inline int feholdexcept(fenv_t* __envp) {
-  fenv_t __env;
-  fegetenv(&__env);
-  *__envp = __env;
-  __env &= ~(FE_ALL_EXCEPT | _FPSCR_ENABLE_MASK);
-  fesetenv(&__env);
-  return 0;
-}
-
-static __inline int feupdateenv(const fenv_t* __envp) {
-  fexcept_t __fpscr;
-  fegetenv(&__fpscr);
-  fesetenv(__envp);
-  feraiseexcept(__fpscr & FE_ALL_EXCEPT);
-  return 0;
-}
-
-#if __BSD_VISIBLE
-
-static __inline int feenableexcept(int __mask) {
-  fenv_t __old_fpscr, __new_fpscr;
-  fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr | (__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT;
-  fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fedisableexcept(int __mask) {
-  fenv_t __old_fpscr, __new_fpscr;
-  fegetenv(&__old_fpscr);
-  __new_fpscr = __old_fpscr & ~((__mask & FE_ALL_EXCEPT) << _FPSCR_ENABLE_SHIFT);
-  fesetenv(&__new_fpscr);
-  return ((__old_fpscr >> _FPSCR_ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fegetexcept(void) {
-  fenv_t __fpscr;
-  fegetenv(&__fpscr);
-  return ((__fpscr & _FPSCR_ENABLE_MASK) >> _FPSCR_ENABLE_SHIFT);
-}
-
-#endif /* __BSD_VISIBLE */
-
-__END_DECLS
-
-#endif /* !_FENV_H_ */
diff --git a/ndk/platforms/android-20/arch-arm64/include/machine/asm.h b/ndk/platforms/android-20/arch-arm64/include/machine/asm.h
index 3f8b908..4bfabaf 100644
--- a/ndk/platforms/android-20/arch-arm64/include/machine/asm.h
+++ b/ndk/platforms/android-20/arch-arm64/include/machine/asm.h
@@ -38,91 +38,17 @@
 #ifndef _AARCH64_ASM_H_
 #define _AARCH64_ASM_H_
 
-/* TODO: Add cfi directives for creating/restoring FP */
-#ifdef __ELF__
-# define	_C_LABEL(x)	x
-#else
-# ifdef __STDC__
-#  define	_C_LABEL(x)	_ ## x
-# else
-#  define	_C_LABEL(x)	_/**/x
-# endif
-#endif
-#define	_ASM_LABEL(x)	x
-
-#ifdef __STDC__
-# define	__CONCAT(x,y)	x ## y
-# define	__STRING(x)	#x
-#else
-# define	__CONCAT(x,y)	x/**/y
-# define	__STRING(x)	"x"
-#endif
-
 #ifndef _ALIGN_TEXT
-# define	_ALIGN_TEXT	.align 0
+# define _ALIGN_TEXT .align 0
 #endif
 
-#define	_ASM_TYPE_FUNCTION	%function
-#define	_ASM_TYPE_OBJECT	%object
-#define	_ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x: .cfi_startproc
-
-#define	_ASM_SIZE(x)	.size x, .-x;
-
-#define _END(x) \
-	.cfi_endproc; \
-	_ASM_SIZE(x)
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y));
-#define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
-#define	END(y)		_END(_C_LABEL(y))
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
-#define	ASEND(y)	_END(_ASM_LABEL(y))
-
-#ifdef __ELF__
-#define	ENTRY_PRIVATE(y)  ENTRY(y); .hidden _C_LABEL(y)
-#else
-#define	ENTRY_PRIVATE(y)  ENTRY(y)
-#endif
-
-#define	ASMSTR		.asciz
+#undef __bionic_asm_function_type
+#define __bionic_asm_function_type %function
 
 #if defined(__ELF__) && defined(PIC)
-#ifdef __STDC__
-#define	PIC_SYM(x,y)	x ## ( ## y ## )
+#define PIC_SYM(x,y) x ## ( ## y ## )
 #else
-#define	PIC_SYM(x,y)	x/**/(/**/y/**/)
+#define PIC_SYM(x,y) x
 #endif
-#else
-#define	PIC_SYM(x,y)	x
-#endif
-
-#ifdef __ELF__
-#define	RCSID(x)	.section ".ident"; .asciz x
-#else
-#define	RCSID(x)	.text; .asciz x
-#endif
-
-#ifdef __ELF__
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-#endif
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg ## ,30,0,0,0 ;					\
-	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
-#elif defined(__ELF__)
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(sym),1,0,0,0
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(_/**/sym),1,0,0,0
-#endif /* __STDC__ */
 
 #endif /* _AARCH64_ASM_H_ */
-
diff --git a/ndk/platforms/android-20/arch-arm64/include/machine/fenv.h b/ndk/platforms/android-20/arch-arm64/include/machine/fenv.h
new file mode 100644
index 0000000..2efeee3
--- /dev/null
+++ b/ndk/platforms/android-20/arch-arm64/include/machine/fenv.h
@@ -0,0 +1,121 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
+ */
+
+/*
+ * Rewritten for Android.
+ *
+ * The ARM FPSCR (Floating-point Status and Control Register) described here:
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Chdfafia.html
+ * has been split into the FPCR (Floating-point Control Register) and FPSR
+ * (Floating-point Status Register) on the ARMv8. These are described briefly in
+ * "Procedure Call Standard for the ARM 64-bit Architecture"
+ * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
+ * section 5.1.2 SIMD and Floating-Point Registers
+ */
+
+#ifndef _ARM64_FENV_H_
+#define _ARM64_FENV_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+typedef __uint32_t fenv_t;
+typedef __uint32_t fexcept_t;
+
+/* Exception flags. */
+#define FE_INVALID    0x01
+#define FE_DIVBYZERO  0x02
+#define FE_OVERFLOW   0x04
+#define FE_UNDERFLOW  0x08
+#define FE_INEXACT    0x10
+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
+                       FE_OVERFLOW | FE_UNDERFLOW)
+
+#define _FPSCR_ENABLE_SHIFT 8
+#define _FPSCR_ENABLE_MASK  (FE_ALL_EXCEPT << _FPSCR_ENABLE_SHIFT)
+
+/* Rounding modes. */
+#define FE_TONEAREST  0x0
+#define FE_UPWARD     0x1
+#define FE_DOWNWARD   0x2
+#define FE_TOWARDZERO 0x3
+
+#define _FPSCR_RMODE_SHIFT 22
+
+#define FPCR_IOE    (1 << 8)
+#define FPCR_DZE    (1 << 9)
+#define FPCR_OFE    (1 << 10)
+#define FPCR_UFE    (1 << 11)
+#define FPCR_IXE    (1 << 12)
+#define FPCR_IDE    (1 << 15)
+#define FPCR_LEN    (7 << 16)
+#define FPCR_STRIDE (3 << 20)
+#define FPCR_RMODE  (3 << 22)
+#define FPCR_FZ     (1 << 24)
+#define FPCR_DN     (1 << 25)
+#define FPCR_AHP    (1 << 26)
+#define FPCR_MASK   (FPCR_IOE | \
+                     FPCR_DZE | \
+                     FPCR_OFE | \
+                     FPCR_UFE | \
+                     FPCR_IXE | \
+                     FPCR_IDE | \
+                     FPCR_LEN | \
+                     FPCR_STRIDE | \
+                     FPCR_RMODE | \
+                     FPCR_FZ | \
+                     FPCR_DN | \
+                     FPCR_AHP )
+
+#define FPSR_IOC    (1 << 0)
+#define FPSR_DZC    (1 << 1)
+#define FPSR_OFC    (1 << 2)
+#define FPSR_UFC    (1 << 3)
+#define FPSR_IXC    (1 << 4)
+#define FPSR_IDC    (1 << 7)
+#define FPSR_QC     (1 << 27)
+#define FPSR_V      (1 << 28)
+#define FPSR_C      (1 << 29)
+#define FPSR_Z      (1 << 30)
+#define FPSR_N      (1 << 31)
+#define FPSR_MASK   (FPSR_IOC | \
+                     FPSR_DZC | \
+                     FPSR_OFC | \
+                     FPSR_UFC | \
+                     FPSR_IXC | \
+                     FPSR_IDC | \
+                     FPSR_QC | \
+                     FPSR_V | \
+                     FPSR_C | \
+                     FPSR_Z | \
+                     FPSR_N )
+
+__END_DECLS
+
+#endif /* !_ARM64_FENV_H_ */
diff --git a/ndk/platforms/android-20/arch-arm64/lib/libc.a b/ndk/platforms/android-20/arch-arm64/lib/libc.a
index 032edca..78a1e52 100644
--- a/ndk/platforms/android-20/arch-arm64/lib/libc.a
+++ b/ndk/platforms/android-20/arch-arm64/lib/libc.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-arm64/lib/libm.a b/ndk/platforms/android-20/arch-arm64/lib/libm.a
index c076d25..5d4bf27 100644
--- a/ndk/platforms/android-20/arch-arm64/lib/libm.a
+++ b/ndk/platforms/android-20/arch-arm64/lib/libm.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-arm64/lib/libstdc++.a b/ndk/platforms/android-20/arch-arm64/lib/libstdc++.a
index fd78d62..9024b39 100644
--- a/ndk/platforms/android-20/arch-arm64/lib/libstdc++.a
+++ b/ndk/platforms/android-20/arch-arm64/lib/libstdc++.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-arm64/lib/libz.a b/ndk/platforms/android-20/arch-arm64/lib/libz.a
index f1ac08c..2a5f510 100644
--- a/ndk/platforms/android-20/arch-arm64/lib/libz.a
+++ b/ndk/platforms/android-20/arch-arm64/lib/libz.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-mips64/include/asm/signal.h b/ndk/platforms/android-20/arch-mips64/include/asm/signal.h
index 771e31a..53f5015 100644
--- a/ndk/platforms/android-20/arch-mips64/include/asm/signal.h
+++ b/ndk/platforms/android-20/arch-mips64/include/asm/signal.h
@@ -19,10 +19,10 @@
 #ifndef _UAPI_ASM_SIGNAL_H
 #define _UAPI_ASM_SIGNAL_H
 #include <linux/types.h>
-#define _NSIG 128
+#define _KERNEL__NSIG 128
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define _NSIG_BPW (sizeof(unsigned long) * 8)
-#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
+#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW)
 typedef struct {
  unsigned long sig[_NSIG_WORDS];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -72,7 +72,7 @@
 #define SIGXFSZ 31
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIGRTMIN 32
-#define SIGRTMAX _NSIG
+#define SIGRTMAX _KERNEL__NSIG
 #define SA_ONSTACK 0x08000000
 #define SA_RESETHAND 0x80000000
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/ndk/platforms/android-20/arch-mips64/include/fenv.h b/ndk/platforms/android-20/arch-mips64/include/fenv.h
deleted file mode 100644
index ed69cf8..0000000
--- a/ndk/platforms/android-20/arch-mips64/include/fenv.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
- *
- * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
- */
-
-/*
-   Rewritten for Android.
-*/
-
-/* MIPS FPU floating point control register bits.
- *
- * 31-25  -> floating point conditions code bits set by FP compare
- *           instructions
- * 24     -> flush denormalized results to zero instead of
- *           causing unimplemented operation exception.
- * 23     -> Condition bit
- * 22     -> In conjunction with FS detects denormalized
- *           operands and replaces them internally with 0.
- * 21     -> In conjunction with FS forces denormalized operands
- *           to the closest normalized value.
- * 20-18  -> reserved (read as 0, write with 0)
- * 17     -> cause bit for unimplemented operation
- * 16     -> cause bit for invalid exception
- * 15     -> cause bit for division by zero exception
- * 14     -> cause bit for overflow exception
- * 13     -> cause bit for underflow exception
- * 12     -> cause bit for inexact exception
- * 11     -> enable exception for invalid exception
- * 10     -> enable exception for division by zero exception
- *  9     -> enable exception for overflow exception
- *  8     -> enable exception for underflow exception
- *  7     -> enable exception for inexact exception
- *  6     -> flag invalid exception
- *  5     -> flag division by zero exception
- *  4     -> flag overflow exception
- *  3     -> flag underflow exception
- *  2     -> flag inexact exception
- *  1-0   -> rounding control
- *
- *
- * Rounding Control:
- * 00 - rounding to nearest (RN)
- * 01 - rounding toward zero (RZ)
- * 10 - rounding (up) toward plus infinity (RP)
- * 11 - rounding (down)toward minus infinity (RM)
- */
-
-#ifndef _FENV_H_
-#define _FENV_H_
-
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-typedef __uint32_t    fenv_t;
-typedef __uint32_t    fexcept_t;
-
-/* Exception flags */
-#define FE_INVALID      0x40
-#define FE_DIVBYZERO    0x20
-#define FE_OVERFLOW     0x10
-#define FE_UNDERFLOW    0x08
-#define FE_INEXACT      0x04
-#define FE_ALL_EXCEPT   (FE_DIVBYZERO | FE_INEXACT | \
-                         FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
-#define _FCSR_CAUSE_SHIFT  10
-#define _ENABLE_SHIFT 5
-#define _FCSR_ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT)
-
-/* Rounding modes */
-#define FE_TONEAREST    0x0000
-#define FE_TOWARDZERO   0x0001
-#define FE_UPWARD       0x0002
-#define FE_DOWNWARD     0x0003
-#define _FCSR_RMODE_SHIFT 0
-#define _FCSR_RMASK       0x3
-/* Default floating-point environment */
-extern const fenv_t    __fe_dfl_env;
-#define FE_DFL_ENV    (&__fe_dfl_env)
-
-static __inline int fegetenv(fenv_t* __envp) {
-   fenv_t _fcsr = 0;
-#ifdef  __mips_hard_float
-   __asm__ __volatile__("cfc1 %0,$31" : "=r" (_fcsr));
-#endif
-   *__envp = _fcsr;
-   return 0;
-}
-
-static __inline int fesetenv(const fenv_t* __envp) {
-  fenv_t _fcsr = *__envp;
-#ifdef  __mips_hard_float
-  __asm__ __volatile__("ctc1 %0,$31" : : "r" (_fcsr));
-#endif
-  return 0;
-}
-
-static __inline int feclearexcept(int __excepts) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  __excepts &= FE_ALL_EXCEPT;
-  __fcsr &= ~(__excepts | (__excepts << _FCSR_CAUSE_SHIFT));
-  fesetenv(&__fcsr);
-  return 0;
-}
-
-static __inline int fegetexceptflag(fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  *__flagp = __fcsr & __excepts & FE_ALL_EXCEPT;
-  return 0;
-}
-
-static __inline int fesetexceptflag(const fexcept_t* __flagp, int __excepts) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  /* Ensure that flags are all legal */
-  __excepts &= FE_ALL_EXCEPT;
-  __fcsr &= ~__excepts;
-  __fcsr |= *__flagp & __excepts;
-  fesetenv(&__fcsr);
-  return 0;
-}
-
-static __inline int feraiseexcept(int __excepts) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  /* Ensure that flags are all legal */
-  __excepts &= FE_ALL_EXCEPT;
-  /* Cause bit needs to be set as well for generating the exception*/
-  __fcsr |= __excepts | (__excepts << _FCSR_CAUSE_SHIFT);
-  fesetenv(&__fcsr);
-  return 0;
-}
-
-static __inline int fetestexcept(int __excepts) {
-  fexcept_t __FCSR;
-  fegetenv(&__FCSR);
-  return (__FCSR & __excepts & FE_ALL_EXCEPT);
-}
-
-static __inline int fegetround(void) {
-  fenv_t _fcsr;
-  fegetenv(&_fcsr);
-  return (_fcsr & _FCSR_RMASK);
-}
-
-static __inline int fesetround(int __round) {
-  fenv_t _fcsr;
-  fegetenv(&_fcsr);
-  _fcsr &= ~_FCSR_RMASK;
-  _fcsr |= (__round & _FCSR_RMASK ) ;
-  fesetenv(&_fcsr);
-  return 0;
-}
-
-static __inline int feholdexcept(fenv_t* __envp) {
-  fenv_t __env;
-  fegetenv(&__env);
-  *__envp = __env;
-  __env &= ~(FE_ALL_EXCEPT | _FCSR_ENABLE_MASK);
-  fesetenv(&__env);
-  return 0;
-}
-
-static __inline int feupdateenv(const fenv_t* __envp) {
-  fexcept_t __fcsr;
-  fegetenv(&__fcsr);
-  fesetenv(__envp);
-  feraiseexcept(__fcsr & FE_ALL_EXCEPT);
-  return 0;
-}
-
-#if __BSD_VISIBLE
-
-static __inline int feenableexcept(int __mask) {
-  fenv_t __old_fcsr, __new_fcsr;
-  fegetenv(&__old_fcsr);
-  __new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT;
-  fesetenv(&__new_fcsr);
-  return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fedisableexcept(int __mask) {
-  fenv_t __old_fcsr, __new_fcsr;
-  fegetenv(&__old_fcsr);
-  __new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT);
-  fesetenv(&__new_fcsr);
-  return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
-}
-
-static __inline int fegetexcept(void) {
-  fenv_t __fcsr;
-  fegetenv(&__fcsr);
-  return ((__fcsr & _FCSR_ENABLE_MASK) >> _ENABLE_SHIFT);
-}
-
-#endif /* __BSD_VISIBLE */
-
-__END_DECLS
-
-#endif /* !_FENV_H_ */
diff --git a/ndk/platforms/android-20/arch-mips64/include/machine/asm.h b/ndk/platforms/android-20/arch-mips64/include/machine/asm.h
index eabb1bf..5eacde3 100644
--- a/ndk/platforms/android-20/arch-mips64/include/machine/asm.h
+++ b/ndk/platforms/android-20/arch-mips64/include/machine/asm.h
@@ -28,25 +28,24 @@
 #ifndef _MIPS64_ASM_H
 #define _MIPS64_ASM_H
 
-#include <machine/regdef.h>
-
-#ifdef NEED_OLD_RM7KFIX
-#define ITLBNOPFIX      nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
-#else
-#define ITLBNOPFIX      nop;nop;nop;nop
+#ifndef _ALIGN_TEXT
+# define _ALIGN_TEXT .align 4
 #endif
 
+#undef __bionic_asm_custom_entry
+#undef __bionic_asm_custom_end
+#define __bionic_asm_custom_entry(f) .ent f
+#define __bionic_asm_custom_end(f) .end f
+
+#include <machine/regdef.h>
+
 #define	_MIPS_ISA_MIPS1	1	/* R2000/R3000 */
 #define	_MIPS_ISA_MIPS2	2	/* R4000/R6000 */
 #define	_MIPS_ISA_MIPS3	3	/* R4000 */
 #define	_MIPS_ISA_MIPS4	4	/* TFP (R1x000) */
-#ifdef __linux__
 #define	_MIPS_ISA_MIPS5 5
 #define	_MIPS_ISA_MIPS32 6
 #define	_MIPS_ISA_MIPS64 7
-#else
-#define	_MIPS_ISA_MIPS32 32	/* MIPS32 */
-#endif
 
 #if !defined(ABICALLS) && !defined(_NO_ABICALLS)
 #define	ABICALLS	.abicalls
@@ -56,8 +55,6 @@
 	ABICALLS
 #endif
 
-#define _C_LABEL(x) x		/* XXX Obsolete but keep for a while */
-
 #if !defined(__MIPSEL__) && !defined(__MIPSEB__)
 #error "__MIPSEL__ or __MIPSEB__ must be defined"
 #endif
@@ -90,15 +87,6 @@
  */
 #if defined(ABICALLS) && !defined(_KERNEL) && !defined(_STANDALONE)
 
-#ifndef _MIPS_SIM
-#define _MIPS_SIM 1
-#define _ABIO32	1
-#endif
-#ifndef _MIPS_ISA
-#define _MIPS_ISA 2
-#define _MIPS_ISA_MIPS2 2
-#endif
-
 #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
 #define NARGSAVE	4
 
@@ -190,28 +178,6 @@
 #endif
 
 /*
- * Define -pg profile entry code.
- */
-#if defined(XGPROF) || defined(XPROF)
-#define	MCOUNT			\
-	PTR_SUBU sp, sp, 64;	\
-	SAVE_GP(16);		\
-	sd	ra, 56(sp);	\
-	sd	gp, 48(sp);	\
-	.set	noat;		\
-	.set	noreorder;	\
-	move	AT, ra;		\
-	jal	_mcount;	\
-	PTR_SUBU sp, sp, 16;	\
-	ld	ra, 56(sp);	\
-	PTR_ADDU sp, sp, 64;	\
-	.set reorder;		\
-	.set	at;
-#else
-#define	MCOUNT
-#endif
-
-/*
  * LEAF(x, fsize)
  *
  *	Declare a leaf routine.
@@ -221,26 +187,9 @@
 	.globl x;		\
 	.ent x, 0;		\
 x: ;				\
+	.cfi_startproc; \
 	.frame sp, fsize, ra;	\
 	SETUP_GP		\
-	MCOUNT
-
-#define	ALEAF(x)		\
-	.globl	x;		\
-x:
-
-/*
- * NLEAF(x)
- *
- *	Declare a non-profiled leaf routine.
- */
-#define NLEAF(x, fsize)		\
-	.align	3;		\
-	.globl x;		\
-	.ent x, 0;		\
-x: ;				\
-	.frame sp, fsize, ra;	\
-	SETUP_GP
 
 /*
  * NON_LEAF(x)
@@ -252,54 +201,8 @@
 	.globl x;		\
 	.ent x, 0;		\
 x: ;				\
+	.cfi_startproc; \
 	.frame sp, fsize, retpc; \
 	SETUP_GP		\
-	MCOUNT
-
-/*
- * NNON_LEAF(x)
- *
- *	Declare a non-profiled non-leaf routine
- *	(a routine that makes other C calls).
- */
-#define NNON_LEAF(x, fsize, retpc) \
-	.align	3;		\
-	.globl x;		\
-	.ent x, 0;		\
-x: ;				\
-	.frame sp, fsize, retpc	\
-	SETUP_GP
-
-/*
- * END(x)
- *
- *	Mark end of a procedure.
- */
-#define END(x) \
-	.end x
-
-/*
- * Macros to panic and printf from assembly language.
- */
-#define PANIC(msg) \
-	LA	a0, 9f; \
-	jal	panic;	\
-	nop	;	\
-	MSG(msg)
-
-#define	PRINTF(msg) \
-	LA	a0, 9f; \
-	jal	printf; \
-	nop	;	\
-	MSG(msg)
-
-#define	MSG(msg) \
-	.rdata; \
-9:	.asciiz	msg; \
-	.text
-
-#define ASMSTR(str) \
-	.asciiz str; \
-	.align	3
 
 #endif /* !_MIPS_ASM_H */
diff --git a/ndk/platforms/android-20/arch-mips64/include/machine/fenv.h b/ndk/platforms/android-20/arch-mips64/include/machine/fenv.h
new file mode 100644
index 0000000..37f0f9c
--- /dev/null
+++ b/ndk/platforms/android-20/arch-mips64/include/machine/fenv.h
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
+ */
+
+/*
+   Rewritten for Android.
+*/
+
+/* MIPS FPU floating point control register bits.
+ *
+ * 31-25  -> floating point conditions code bits set by FP compare
+ *           instructions
+ * 24     -> flush denormalized results to zero instead of
+ *           causing unimplemented operation exception.
+ * 23     -> Condition bit
+ * 22     -> In conjunction with FS detects denormalized
+ *           operands and replaces them internally with 0.
+ * 21     -> In conjunction with FS forces denormalized operands
+ *           to the closest normalized value.
+ * 20-18  -> reserved (read as 0, write with 0)
+ * 17     -> cause bit for unimplemented operation
+ * 16     -> cause bit for invalid exception
+ * 15     -> cause bit for division by zero exception
+ * 14     -> cause bit for overflow exception
+ * 13     -> cause bit for underflow exception
+ * 12     -> cause bit for inexact exception
+ * 11     -> enable exception for invalid exception
+ * 10     -> enable exception for division by zero exception
+ *  9     -> enable exception for overflow exception
+ *  8     -> enable exception for underflow exception
+ *  7     -> enable exception for inexact exception
+ *  6     -> flag invalid exception
+ *  5     -> flag division by zero exception
+ *  4     -> flag overflow exception
+ *  3     -> flag underflow exception
+ *  2     -> flag inexact exception
+ *  1-0   -> rounding control
+ *
+ *
+ * Rounding Control:
+ * 00 - rounding to nearest (RN)
+ * 01 - rounding toward zero (RZ)
+ * 10 - rounding (up) toward plus infinity (RP)
+ * 11 - rounding (down)toward minus infinity (RM)
+ */
+
+#ifndef _MIPS_FENV_H_
+#define _MIPS_FENV_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+typedef __uint32_t fenv_t;
+typedef __uint32_t fexcept_t;
+
+/* Exception flags */
+#define FE_INVALID    0x40
+#define FE_DIVBYZERO  0x20
+#define FE_OVERFLOW   0x10
+#define FE_UNDERFLOW  0x08
+#define FE_INEXACT    0x04
+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
+                       FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
+
+#define _FCSR_CAUSE_SHIFT 10
+#define _ENABLE_SHIFT     5
+#define _FCSR_ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT)
+
+/* Rounding modes */
+#define FE_TONEAREST  0x0000
+#define FE_TOWARDZERO 0x0001
+#define FE_UPWARD     0x0002
+#define FE_DOWNWARD   0x0003
+
+#define _FCSR_RMODE_SHIFT 0
+#define _FCSR_RMASK       0x3
+
+__END_DECLS
+
+#endif /* !_MIPS_FENV_H_ */
diff --git a/ndk/platforms/android-20/arch-mips64/include/machine/signal.h b/ndk/platforms/android-20/arch-mips64/include/machine/signal.h
index 4efb856..b31715c 100644
--- a/ndk/platforms/android-20/arch-mips64/include/machine/signal.h
+++ b/ndk/platforms/android-20/arch-mips64/include/machine/signal.h
@@ -37,111 +37,15 @@
 #ifndef _MIPS_SIGNAL_H_
 #define _MIPS_SIGNAL_H_
 
-#include <sys/cdefs.h>
-
-#if !defined(__LANGUAGE_ASSEMBLY)
-#include <sys/types.h>
-
-/*
- * Machine-dependent signal definitions
- */
-typedef int sig_atomic_t;
-
-#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
-
-/*
- * Information pushed on stack when a signal is delivered.
- * This is used by the kernel to restore state following
- * execution of the signal handler.  It is also made available
- * to the handler to allow it to restore state properly if
- * a non-standard exit is performed.
- */
-
-#if defined(__ANDROID__)
-
-/*
- * The Linux and OpenBSD sigcontext structures are slightly different
- * This is the Linux O32 ABI compatible sigcontext
- */
-
-struct sigcontext {
-	unsigned int sc_regmask;
-	unsigned int sc_status;
-	unsigned long long sc_pc;
-	unsigned long long sc_regs[32];
-	unsigned long long sc_fpregs[32];
-	unsigned int sc_acx;
-	unsigned int sc_fpc_csr;
-	unsigned int sc_fpc_eir;
-	unsigned int sc_used_math;
-	unsigned int sc_dsp;
-	unsigned long long sc_mdhi;
-	unsigned long long sc_mdlo;
-	unsigned long sc_hi1;
-	unsigned long sc_lo1;
-	unsigned long sc_hi2;
-	unsigned long sc_lo2;
-	unsigned long sc_hi3;
-	unsigned long sc_lo3;
-};
-
-#else
-
-struct	sigcontext {
-	long	sc_onstack;	/* sigstack state to restore */
-	long	 sc_mask;	/* signal mask to restore */
-	__register_t sc_pc;	/* pc at time of signal */
-	__register_t sc_regs[32]; /* processor regs 0 to 31 */
-	__register_t mullo;	/* mullo and mulhi registers... */
-	__register_t mulhi;	/* mullo and mulhi registers... */
-	f_register_t sc_fpregs[33]; /* fp regs 0 to 31 and csr */
-	long	sc_fpused;	/* fp has been used */
-	long	sc_fpc_eir;	/* floating point exception instruction reg */
-	long	xxx[8];		/* XXX reserved */
-};
-#endif
-#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
-
-#else /* __LANGUAGE_ASSEMBLY */
-
-#ifdef __ANDROID__
-
 #define	SC_REGMASK	(0*REGSZ)
 #define	SC_STATUS	(1*REGSZ)
 #define	SC_PC		(2*REGSZ)
 #define	SC_REGS		(SC_PC+8)
 #define	SC_FPREGS	(SC_REGS+32*8)
 #define	SC_ACX		(SC_FPREGS+32*REGSZ_FP)
-#define	SC_FPC_CSR	(SC_ACX+1*REGSZ)
-#define	SC_FPC_EIR	(SC_ACX+2*REGSZ)
 #define	SC_USED_MATH	(SC_ACX+3*REGSZ)
-#define	SC_DSP		(SC_ACX+4*REGSZ)
-#define	SC_MDHI		(SC_ACX+5*REGSZ)
-#define	SC_MDLO		(SC_MDHI+8)
-#define	SC_HI1		(SC_MDLO+8)
-#define	SC_LO1		(SC_HI1+1*REGSZ)
-#define	SC_HI2		(SC_HI1+2*REGSZ)
-#define	SC_LO2		(SC_HI1+3*REGSZ)
-#define	SC_HI3		(SC_HI1+4*REGSZ)
-#define	SC_LO3		(SC_HI1+5*REGSZ)
 /* OpenBSD compatibility */
 #define	SC_MASK		SC_REGMASK
 #define	SC_FPUSED	SC_USED_MATH
 
-#else
-
-#define SC_ONSTACK	(0 * REGSZ)
-#define	SC_MASK		(1 * REGSZ)
-#define	SC_PC		(2 * REGSZ)
-#define	SC_REGS		(3 * REGSZ)
-#define	SC_MULLO	(35 * REGSZ)
-#define	SC_MULHI	(36 * REGSZ)
-#define	SC_FPREGS	(37 * REGSZ)
-#define	SC_FPUSED	(70 * REGSZ)
-#define	SC_FPC_EIR	(71 * REGSZ)
-
-#endif /* __ANDROID__ */
-
-#endif /* __LANGUAGE_ASSEMBLY */
-
 #endif	/* !_MIPS_SIGNAL_H_ */
diff --git a/ndk/platforms/android-20/arch-mips64/lib/libc.a b/ndk/platforms/android-20/arch-mips64/lib/libc.a
index b6f3627..d42fbc3 100644
--- a/ndk/platforms/android-20/arch-mips64/lib/libc.a
+++ b/ndk/platforms/android-20/arch-mips64/lib/libc.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-mips64/lib/libm.a b/ndk/platforms/android-20/arch-mips64/lib/libm.a
index cc37c18..8aef92a 100644
--- a/ndk/platforms/android-20/arch-mips64/lib/libm.a
+++ b/ndk/platforms/android-20/arch-mips64/lib/libm.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-mips64/lib/libstdc++.a b/ndk/platforms/android-20/arch-mips64/lib/libstdc++.a
index 92c3eb6..1816bf5 100644
--- a/ndk/platforms/android-20/arch-mips64/lib/libstdc++.a
+++ b/ndk/platforms/android-20/arch-mips64/lib/libstdc++.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-mips64/lib/libz.a b/ndk/platforms/android-20/arch-mips64/lib/libz.a
index 10cd881..bc977d6 100644
--- a/ndk/platforms/android-20/arch-mips64/lib/libz.a
+++ b/ndk/platforms/android-20/arch-mips64/lib/libz.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-x86_64/include/asm/signal.h b/ndk/platforms/android-20/arch-x86_64/include/asm/signal.h
index bba6bc7..6f5b435 100644
--- a/ndk/platforms/android-20/arch-x86_64/include/asm/signal.h
+++ b/ndk/platforms/android-20/arch-x86_64/include/asm/signal.h
@@ -24,7 +24,7 @@
 #include <linux/time.h>
 #include <linux/compiler.h>
 struct siginfo;
-#define NSIG 32
+#define _KERNEL_NSIG 32
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 typedef unsigned long sigset_t;
 #endif
@@ -72,7 +72,7 @@
 #define SIGUNUSED 31
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIGRTMIN 32
-#define SIGRTMAX _NSIG
+#define SIGRTMAX _KERNEL__NSIG
 #define SA_NOCLDSTOP 0x00000001u
 #define SA_NOCLDWAIT 0x00000002u
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/ndk/platforms/android-20/arch-x86_64/include/asm/stat.h b/ndk/platforms/android-20/arch-x86_64/include/asm/stat.h
index 0998106..04c5569 100644
--- a/ndk/platforms/android-20/arch-x86_64/include/asm/stat.h
+++ b/ndk/platforms/android-20/arch-x86_64/include/asm/stat.h
@@ -102,7 +102,7 @@
  long __linux_unused[3];
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 };
-#define INIT_STRUCT_STAT_PADDING(st) do {   st.__pad0 = 0;   st.__unused[0] = 0;   st.__unused[1] = 0;   st.__unused[2] = 0;  } while (0)
+#define INIT_STRUCT_STAT_PADDING(st) do {   st.__pad0 = 0;   st.__linux_unused[0] = 0;   st.__linux_unused[1] = 0;   st.__linux_unused[2] = 0;  } while (0)
 #endif
 struct __old_kernel_stat {
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/ndk/platforms/android-20/arch-x86_64/include/fenv.h b/ndk/platforms/android-20/arch-x86_64/include/fenv.h
deleted file mode 100644
index c0421c0..0000000
--- a/ndk/platforms/android-20/arch-x86_64/include/fenv.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
- *
- * $FreeBSD: src/lib/msun/i387/fenv.h,v 1.4 2005/03/17 22:21:46 das Exp $
- */
-
-#ifndef	_FENV_H_
-#define	_FENV_H_
-
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-/*                   
- * To preserve binary compatibility with FreeBSD 5.3, we pack the
- * mxcsr into some reserved fields, rather than changing sizeof(fenv_t).
- */
-typedef struct {
-	__uint16_t	__control;
-	__uint16_t      __mxcsr_hi;
-	__uint16_t	__status;
-	__uint16_t      __mxcsr_lo;
-	__uint32_t	__tag;
-	char		__other[16];
-} fenv_t;
-
-typedef	__uint16_t	fexcept_t;
-
-/* Exception flags */
-#define	FE_INVALID	0x01
-#define	FE_DENORMAL	0x02
-#define	FE_DIVBYZERO	0x04
-#define	FE_OVERFLOW	0x08
-#define	FE_UNDERFLOW	0x10
-#define	FE_INEXACT	0x20
-#define	FE_ALL_EXCEPT	(FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \
-			 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
-
-/* Rounding modes */
-#define	FE_TONEAREST	0x0000
-#define	FE_DOWNWARD	0x0400
-#define	FE_UPWARD	0x0800
-#define	FE_TOWARDZERO	0x0c00
-#define	_ROUND_MASK	(FE_TONEAREST | FE_DOWNWARD | \
-			 FE_UPWARD | FE_TOWARDZERO)
-
-/* Default floating-point environment */
-extern const fenv_t	__fe_dfl_env;
-#define	FE_DFL_ENV	(&__fe_dfl_env)
-
-/* C99 floating-point exception functions */
-int feclearexcept(int excepts);
-int fegetexceptflag(fexcept_t *flagp, int excepts);
-int fesetexceptflag(const fexcept_t *flagp, int excepts);
-/* feraiseexcept does not set the inexact flag on overflow/underflow */
-int feraiseexcept(int excepts);
-int fetestexcept(int excepts);
-
-/* C99 rounding control functions */
-int fegetround(void);
-int fesetround(int round);
-
-/* C99 floating-point environment functions */
-int fegetenv(fenv_t *__envp);
-int feholdexcept(fenv_t *__envp);
-int fesetenv(const fenv_t *envp);
-int feupdateenv(const fenv_t *__envp);
-
-#if __BSD_VISIBLE
-/* Additional support functions to set/query floating point traps */
-int feenableexcept(int __mask);
-int fedisableexcept(int __mask);
-int fegetexcept(void);
-
-#endif /* __BSD_VISIBLE */
-
-__END_DECLS
-
-#endif	/* !_FENV_H_ */
diff --git a/ndk/platforms/android-20/arch-x86_64/include/machine/asm.h b/ndk/platforms/android-20/arch-x86_64/include/machine/asm.h
index 310b230..0af6dae 100644
--- a/ndk/platforms/android-20/arch-x86_64/include/machine/asm.h
+++ b/ndk/platforms/android-20/arch-x86_64/include/machine/asm.h
@@ -37,8 +37,6 @@
 #ifndef _AMD64_ASM_H_
 #define _AMD64_ASM_H_
 
-#ifdef __x86_64__
-
 #ifdef __PIC__
 #define PIC_PLT(x)	x@PLT
 #define PIC_GOT(x)	x@GOTPCREL(%rip)
@@ -47,19 +45,6 @@
 #define PIC_GOT(x)	x
 #endif
 
-# define _C_LABEL(x)	x
-#define	_ASM_LABEL(x)	x
-
-#define CVAROFF(x,y)		(_C_LABEL(x)+y)(%rip)
-
-#ifdef __STDC__
-# define __CONCAT(x,y)	x ## y
-# define __STRING(x)	#x
-#else
-# define __CONCAT(x,y)	x/**/y
-# define __STRING(x)	"x"
-#endif
-
 /* let kernels and others override entrypoint alignment */
 #ifndef _ALIGN_TEXT
 # ifdef _STANDALONE
@@ -69,78 +54,4 @@
 # endif
 #endif
 
-#define _ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,@function; x: .cfi_startproc;
-#define _LABEL(x) \
-	.globl x; x:
-
-#ifdef _KERNEL
-/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
-#ifdef __STDC__
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
-#define	IDTVEC_END(name) \
-	.size X ## name, . - X ## name
-#else 
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
-#define	IDTVEC_END(name) \
-	.size X/**/name, . - X/**/name
-#endif /* __STDC__ */ 
-#endif /* _KERNEL */
-
-#ifdef __STDC__
-#define CPUVAR(off)	%gs:CPU_INFO_ ## off
-#else
-#define CPUVAR(off)     %gs:CPU_INFO_/**/off
-#endif
-
-
-#ifdef GPROF
-# define _PROF_PROLOGUE	\
-	pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp
-#else
-# define _PROF_PROLOGUE
-#endif
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
-#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
-#define	ALTENTRY(x)	NENTRY(x)
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	LABEL(y)	_LABEL(_C_LABEL(y))
-#define	END(y)		.cfi_endproc; .size y, . - y
-
-#define	ASMSTR		.asciz
-
-#define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
-
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-
-/*
- * STRONG_ALIAS: create a strong alias.
- */
-#define STRONG_ALIAS(alias,sym)						\
-	.globl alias;							\
-	alias = sym
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning. ## sym;				\
-	.ascii msg;							\
-	.popsection
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning./**/sym;				\
-	.ascii msg;							\
-	.popsection
-#endif /* __STDC__ */
-
-#else	/*	__x86_64__	*/
-
-#include <i386/asm.h>
-
-#endif	/*	__x86_64__	*/
-
 #endif /* !_AMD64_ASM_H_ */
diff --git a/ndk/platforms/android-20/arch-x86_64/include/machine/fenv.h b/ndk/platforms/android-20/arch-x86_64/include/machine/fenv.h
new file mode 100644
index 0000000..f3fabb6
--- /dev/null
+++ b/ndk/platforms/android-20/arch-x86_64/include/machine/fenv.h
@@ -0,0 +1,71 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD: src/lib/msun/i387/fenv.h,v 1.4 2005/03/17 22:21:46 das Exp $
+ */
+
+#ifndef _I387_FENV_H_
+#define _I387_FENV_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+/*
+ * To preserve binary compatibility with FreeBSD 5.3, we pack the
+ * mxcsr into some reserved fields, rather than changing sizeof(fenv_t).
+ */
+typedef struct {
+  __uint16_t __control;
+  __uint16_t __mxcsr_hi;
+  __uint16_t __status;
+  __uint16_t __mxcsr_lo;
+  __uint32_t __tag;
+  char       __other[16];
+} fenv_t;
+
+typedef __uint16_t fexcept_t;
+
+/* Exception flags */
+#define FE_INVALID    0x01
+#define FE_DENORMAL   0x02
+#define FE_DIVBYZERO  0x04
+#define FE_OVERFLOW   0x08
+#define FE_UNDERFLOW  0x10
+#define FE_INEXACT    0x20
+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \
+                       FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
+
+/* Rounding modes */
+#define FE_TONEAREST  0x0000
+#define FE_DOWNWARD   0x0400
+#define FE_UPWARD     0x0800
+#define FE_TOWARDZERO 0x0c00
+#define _ROUND_MASK   (FE_TONEAREST | FE_DOWNWARD | \
+                       FE_UPWARD | FE_TOWARDZERO)
+
+__END_DECLS
+
+#endif /* !I387_FENV_H_ */
diff --git a/ndk/platforms/android-20/arch-x86_64/lib/libc.a b/ndk/platforms/android-20/arch-x86_64/lib/libc.a
index 882588d..5e0267f 100644
--- a/ndk/platforms/android-20/arch-x86_64/lib/libc.a
+++ b/ndk/platforms/android-20/arch-x86_64/lib/libc.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-x86_64/lib/libm.a b/ndk/platforms/android-20/arch-x86_64/lib/libm.a
index 2d8d284..d00c083 100644
--- a/ndk/platforms/android-20/arch-x86_64/lib/libm.a
+++ b/ndk/platforms/android-20/arch-x86_64/lib/libm.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-x86_64/lib/libstdc++.a b/ndk/platforms/android-20/arch-x86_64/lib/libstdc++.a
index a9f332b..91b8ae2 100644
--- a/ndk/platforms/android-20/arch-x86_64/lib/libstdc++.a
+++ b/ndk/platforms/android-20/arch-x86_64/lib/libstdc++.a
Binary files differ
diff --git a/ndk/platforms/android-20/arch-x86_64/lib/libz.a b/ndk/platforms/android-20/arch-x86_64/lib/libz.a
index ba47842..7cb4528 100644
--- a/ndk/platforms/android-20/arch-x86_64/lib/libz.a
+++ b/ndk/platforms/android-20/arch-x86_64/lib/libz.a
Binary files differ
diff --git a/ndk/platforms/android-20/include/arpa/nameser.h b/ndk/platforms/android-20/include/arpa/nameser.h
index 028eadc..a87ac91 100644
--- a/ndk/platforms/android-20/include/arpa/nameser.h
+++ b/ndk/platforms/android-20/include/arpa/nameser.h
@@ -1,41 +1,668 @@
+/*	$NetBSD: nameser.h,v 1.25 2009/04/12 17:07:34 christos Exp $	*/
+
 /*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
+ * Portions Copyright (C) 2004, 2005, 2008, 2009  Internet Systems Consortium, Inc. ("ISC")
+ * Portions Copyright (C) 1996-2003  Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Copyright (c) 1983, 1989, 1993
+ *    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:
- *  * Redistributions of source code must retain the above copyright
+ * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
- *  * 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.
+ * 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 COPYRIGHT HOLDERS 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
- * COPYRIGHT OWNER 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
+ * 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.
  */
-#ifndef _arpa_nameser_h
-#define _arpa_nameser_h
+
+/*
+ *	Id: nameser.h,v 1.16 2009/03/03 01:52:48 each Exp
+ */
+
+#ifndef _ARPA_NAMESER_H_
+#define _ARPA_NAMESER_H_
+
+#define BIND_4_COMPAT
 
 #include <sys/types.h>
 #include <sys/cdefs.h>
 
-/* this header intentionally blank
- *
- * the definitions normally found in <arpa/nameser.h> are
- * really a bunch of resolver's internal declarations that
- * should not be exposed to client code in any way
+/*
+ * Revision information.  This is the release date in YYYYMMDD format.
+ * It can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__NAMESER > 19931104)".  Do not
+ * compare for equality; rather, use it to determine whether your libbind.a
+ * contains a new enough lib/nameser/ to support the feature you need.
  */
 
-#endif /* _arpa_nameser_h */
+#define __NAMESER	20090302	/*%< New interface version stamp. */
+
+/*
+ * Define constants based on RFC0883, RFC1034, RFC 1035
+ */
+#define NS_PACKETSZ	512	/* default UDP packet size */
+#define NS_MAXDNAME	1025	/* maximum domain name (presentation format)*/
+#define NS_MAXMSG	65535	/* maximum message size */
+#define NS_MAXCDNAME	255	/* maximum compressed domain name */
+#define NS_MAXLABEL	63	/* maximum length of domain label */
+#define NS_MAXLABELS	128	/* theoretical max #/labels per domain name */
+#define NS_MAXNNAME	256	/* maximum uncompressed (binary) domain name*/
+#define	NS_MAXPADDR	(sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
+#define NS_HFIXEDSZ	12	/* #/bytes of fixed data in header */
+#define NS_QFIXEDSZ	4	/* #/bytes of fixed data in query */
+#define NS_RRFIXEDSZ	10	/* #/bytes of fixed data in r record */
+#define NS_INT32SZ	4	/* #/bytes of data in a uint32_t */
+#define NS_INT16SZ	2	/* #/bytes of data in a uint16_t */
+#define NS_INT8SZ	1	/* #/bytes of data in a uint8_t */
+#define NS_INADDRSZ	4	/* IPv4 T_A */
+#define NS_IN6ADDRSZ	16	/* IPv6 T_AAAA */
+#define NS_CMPRSFLGS	0xc0	/* Flag bits indicating name compression. */
+#define NS_DEFAULTPORT	53	/* For both TCP and UDP. */
+
+/*
+ * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
+ * in synch with it.
+ */
+typedef enum __ns_sect {
+	ns_s_qd = 0,		/* Query: Question. */
+	ns_s_zn = 0,		/* Update: Zone. */
+	ns_s_an = 1,		/* Query: Answer. */
+	ns_s_pr = 1,		/* Update: Prerequisites. */
+	ns_s_ns = 2,		/* Query: Name servers. */
+	ns_s_ud = 2,		/* Update: Update. */
+	ns_s_ar = 3,		/* Query|Update: Additional records. */
+	ns_s_max = 4
+} ns_sect;
+
+/*
+ * Network name (compressed or not) type.  Equivilent to a pointer when used
+ * in a function prototype.  Can be const'd.
+ */
+typedef u_char ns_nname[NS_MAXNNAME];
+typedef const u_char *ns_nname_ct;
+typedef u_char *ns_nname_t;
+
+struct ns_namemap { ns_nname_ct base; int len; };
+typedef struct ns_namemap *ns_namemap_t;
+typedef const struct ns_namemap *ns_namemap_ct;
+
+/*
+ * This is a message handle.  It is caller allocated and has no dynamic data.
+ * This structure is intended to be opaque to all but ns_parse.c, thus the
+ * leading _'s on the member names.  Use the accessor functions, not the _'s.
+ */
+typedef struct __ns_msg {
+	const u_char	*_msg, *_eom;
+	uint16_t	_id, _flags, _counts[ns_s_max];
+	const u_char	*_sections[ns_s_max];
+	ns_sect		_sect;
+	int		_rrnum;
+	const u_char	*_msg_ptr;
+} ns_msg;
+/*
+ * This is a newmsg handle, used when constructing new messages with
+ * ns_newmsg_init, et al.
+ */
+struct ns_newmsg {
+	ns_msg		msg;
+	const u_char	*dnptrs[25];
+	const u_char	**lastdnptr;
+};
+typedef struct ns_newmsg ns_newmsg;
+
+/* Private data structure - do not use from outside library. */
+struct _ns_flagdata {  int mask, shift;  };
+extern const struct _ns_flagdata _ns_flagdata[];
+
+/* Accessor macros - this is part of the public interface. */
+
+#define ns_msg_id(handle) ((handle)._id + 0)
+#define ns_msg_base(handle) ((handle)._msg + 0)
+#define ns_msg_end(handle) ((handle)._eom + 0)
+#define ns_msg_size(handle) ((size_t)((handle)._eom - (handle)._msg))
+#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
+
+/*
+ * This is a parsed record.  It is caller allocated and has no dynamic data.
+ */
+typedef	struct __ns_rr {
+	char		name[NS_MAXDNAME];
+	uint16_t	type;
+	uint16_t	rr_class;
+	uint32_t	ttl;
+	uint16_t	rdlength;
+	const u_char *	rdata;
+} ns_rr;
+
+/*
+ * Same thing, but using uncompressed network binary names, and real C types.
+ */
+typedef	struct __ns_rr2 {
+	ns_nname	nname;
+	size_t		nnamel;
+	int		type;
+	int		rr_class;
+	u_int		ttl;
+	int		rdlength;
+	const u_char *	rdata;
+} ns_rr2;
+/* Accessor macros - this is part of the public interface. */
+#define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
+#define ns_rr_nname(rr)	((const ns_nname_t)(rr).nname)
+#define ns_rr_nnamel(rr) ((rr).nnamel + 0)
+#define ns_rr_type(rr)	((ns_type)((rr).type + 0))
+#define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0))
+#define ns_rr_ttl(rr)	((u_long)(rr).ttl + 0)
+#define ns_rr_rdlen(rr)	((size_t)(rr).rdlength + 0)
+#define ns_rr_rdata(rr)	((rr).rdata + 0)
+
+/*
+ * These don't have to be in the same order as in the packet flags word,
+ * and they can even overlap in some cases, but they will need to be kept
+ * in synch with ns_parse.c:ns_flagdata[].
+ */
+typedef enum __ns_flag {
+	ns_f_qr,		/* Question/Response. */
+	ns_f_opcode,		/* Operation code. */
+	ns_f_aa,		/* Authoritative Answer. */
+	ns_f_tc,		/* Truncation occurred. */
+	ns_f_rd,		/* Recursion Desired. */
+	ns_f_ra,		/* Recursion Available. */
+	ns_f_z,			/* MBZ. */
+	ns_f_ad,		/* Authentic Data (DNSSEC). */
+	ns_f_cd,		/* Checking Disabled (DNSSEC). */
+	ns_f_rcode,		/* Response code. */
+	ns_f_max
+} ns_flag;
+
+/*
+ * Currently defined opcodes.
+ */
+typedef enum __ns_opcode {
+	ns_o_query = 0,		/* Standard query. */
+	ns_o_iquery = 1,	/* Inverse query (deprecated/unsupported). */
+	ns_o_status = 2,	/* Name server status query (unsupported). */
+				/* Opcode 3 is undefined/reserved. */
+	ns_o_notify = 4,	/* Zone change notification. */
+	ns_o_update = 5,	/* Zone update message. */
+	ns_o_max = 6
+} ns_opcode;
+
+/*
+ * Currently defined response codes.
+ */
+typedef	enum __ns_rcode {
+	ns_r_noerror = 0,	/* No error occurred. */
+	ns_r_formerr = 1,	/* Format error. */
+	ns_r_servfail = 2,	/* Server failure. */
+	ns_r_nxdomain = 3,	/* Name error. */
+	ns_r_notimpl = 4,	/* Unimplemented. */
+	ns_r_refused = 5,	/* Operation refused. */
+	/* these are for BIND_UPDATE */
+	ns_r_yxdomain = 6,	/* Name exists */
+	ns_r_yxrrset = 7,	/* RRset exists */
+	ns_r_nxrrset = 8,	/* RRset does not exist */
+	ns_r_notauth = 9,	/* Not authoritative for zone */
+	ns_r_notzone = 10,	/* Zone of record different from zone section */
+	ns_r_max = 11,
+	/* The following are EDNS extended rcodes */
+	ns_r_badvers = 16,
+	/* The following are TSIG errors */
+	ns_r_badsig = 16,
+	ns_r_badkey = 17,
+	ns_r_badtime = 18
+} ns_rcode;
+
+/* BIND_UPDATE */
+typedef enum __ns_update_operation {
+	ns_uop_delete = 0,
+	ns_uop_add = 1,
+	ns_uop_max = 2
+} ns_update_operation;
+
+/*
+ * This structure is used for TSIG authenticated messages
+ */
+struct ns_tsig_key {
+        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
+        unsigned char *data;
+        int len;
+};
+typedef struct ns_tsig_key ns_tsig_key;
+
+/*
+ * This structure is used for TSIG authenticated TCP messages
+ */
+struct ns_tcp_tsig_state {
+	int counter;
+	struct dst_key *key;
+	void *ctx;
+	unsigned char sig[NS_PACKETSZ];
+	int siglen;
+};
+typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;
+
+#define NS_TSIG_FUDGE 300
+#define NS_TSIG_TCP_COUNT 100
+#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
+
+#define NS_TSIG_ERROR_NO_TSIG -10
+#define NS_TSIG_ERROR_NO_SPACE -11
+#define NS_TSIG_ERROR_FORMERR -12
+
+/*
+ * Currently defined type values for resources and queries.
+ */
+typedef enum __ns_type {
+	ns_t_invalid = 0,	/* Cookie. */
+	ns_t_a = 1,		/* Host address. */
+	ns_t_ns = 2,		/* Authoritative server. */
+	ns_t_md = 3,		/* Mail destination. */
+	ns_t_mf = 4,		/* Mail forwarder. */
+	ns_t_cname = 5,		/* Canonical name. */
+	ns_t_soa = 6,		/* Start of authority zone. */
+	ns_t_mb = 7,		/* Mailbox domain name. */
+	ns_t_mg = 8,		/* Mail group member. */
+	ns_t_mr = 9,		/* Mail rename name. */
+	ns_t_null = 10,		/* Null resource record. */
+	ns_t_wks = 11,		/* Well known service. */
+	ns_t_ptr = 12,		/* Domain name pointer. */
+	ns_t_hinfo = 13,	/* Host information. */
+	ns_t_minfo = 14,	/* Mailbox information. */
+	ns_t_mx = 15,		/* Mail routing information. */
+	ns_t_txt = 16,		/* Text strings. */
+	ns_t_rp = 17,		/* Responsible person. */
+	ns_t_afsdb = 18,	/* AFS cell database. */
+	ns_t_x25 = 19,		/* X_25 calling address. */
+	ns_t_isdn = 20,		/* ISDN calling address. */
+	ns_t_rt = 21,		/* Router. */
+	ns_t_nsap = 22,		/* NSAP address. */
+	ns_t_nsap_ptr = 23,	/* Reverse NSAP lookup (deprecated). */
+	ns_t_sig = 24,		/* Security signature. */
+	ns_t_key = 25,		/* Security key. */
+	ns_t_px = 26,		/* X.400 mail mapping. */
+	ns_t_gpos = 27,		/* Geographical position (withdrawn). */
+	ns_t_aaaa = 28,		/* IPv6 Address. */
+	ns_t_loc = 29,		/* Location Information. */
+	ns_t_nxt = 30,		/* Next domain (security). */
+	ns_t_eid = 31,		/* Endpoint identifier. */
+	ns_t_nimloc = 32,	/* Nimrod Locator. */
+	ns_t_srv = 33,		/* Server Selection. */
+	ns_t_atma = 34,		/* ATM Address */
+	ns_t_naptr = 35,	/* Naming Authority PoinTeR */
+	ns_t_kx = 36,		/* Key Exchange */
+	ns_t_cert = 37,		/* Certification record */
+	ns_t_a6 = 38,		/* IPv6 address (experimental) */
+	ns_t_dname = 39,	/* Non-terminal DNAME */
+	ns_t_sink = 40,		/* Kitchen sink (experimentatl) */
+	ns_t_opt = 41,		/* EDNS0 option (meta-RR) */
+	ns_t_apl = 42,		/* Address prefix list (RFC 3123) */
+	ns_t_ds = 43,		/* Delegation Signer */
+	ns_t_sshfp = 44,	/* SSH Fingerprint */
+	ns_t_ipseckey = 45,	/* IPSEC Key */
+	ns_t_rrsig = 46,	/* RRset Signature */
+	ns_t_nsec = 47,		/* Negative security */
+	ns_t_dnskey = 48,	/* DNS Key */
+	ns_t_dhcid = 49,	/* Dynamic host configuratin identifier */
+	ns_t_nsec3 = 50,	/* Negative security type 3 */
+	ns_t_nsec3param = 51,	/* Negative security type 3 parameters */
+	ns_t_hip = 55,		/* Host Identity Protocol */
+	ns_t_spf = 99,		/* Sender Policy Framework */
+	ns_t_tkey = 249,	/* Transaction key */
+	ns_t_tsig = 250,	/* Transaction signature. */
+	ns_t_ixfr = 251,	/* Incremental zone transfer. */
+	ns_t_axfr = 252,	/* Transfer zone of authority. */
+	ns_t_mailb = 253,	/* Transfer mailbox records. */
+	ns_t_maila = 254,	/* Transfer mail agent records. */
+	ns_t_any = 255,		/* Wildcard match. */
+	ns_t_zxfr = 256,	/* BIND-specific, nonstandard. */
+	ns_t_dlv = 32769,	/* DNSSEC look-aside validatation. */
+	ns_t_max = 65536
+} ns_type;
+
+/* Exclusively a QTYPE? (not also an RTYPE) */
+#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
+		      (t) == ns_t_mailb || (t) == ns_t_maila)
+/* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */
+#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
+/* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */
+#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
+#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
+#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
+		       (t) == ns_t_zxfr)
+
+/*
+ * Values for class field
+ */
+typedef enum __ns_class {
+	ns_c_invalid = 0,	/* Cookie. */
+	ns_c_in = 1,		/* Internet. */
+	ns_c_2 = 2,		/* unallocated/unsupported. */
+	ns_c_chaos = 3,		/* MIT Chaos-net. */
+	ns_c_hs = 4,		/* MIT Hesiod. */
+	/* Query class values which do not appear in resource records */
+	ns_c_none = 254,	/* for prereq. sections in update requests */
+	ns_c_any = 255,		/* Wildcard match. */
+	ns_c_max = 65536
+} ns_class;
+
+/* DNSSEC constants. */
+
+typedef enum __ns_key_types {
+	ns_kt_rsa = 1,		/* key type RSA/MD5 */
+	ns_kt_dh  = 2,		/* Diffie Hellman */
+	ns_kt_dsa = 3,		/* Digital Signature Standard (MANDATORY) */
+	ns_kt_private = 254	/* Private key type starts with OID */
+} ns_key_types;
+
+typedef enum __ns_cert_types {
+	cert_t_pkix = 1,	/* PKIX (X.509v3) */
+	cert_t_spki = 2,	/* SPKI */
+	cert_t_pgp  = 3,	/* PGP */
+	cert_t_url  = 253,	/* URL private type */
+	cert_t_oid  = 254	/* OID private type */
+} ns_cert_types;
+
+/* Flags field of the KEY RR rdata. */
+#define	NS_KEY_TYPEMASK		0xC000	/* Mask for "type" bits */
+#define	NS_KEY_TYPE_AUTH_CONF	0x0000	/* Key usable for both */
+#define	NS_KEY_TYPE_CONF_ONLY	0x8000	/* Key usable for confidentiality */
+#define	NS_KEY_TYPE_AUTH_ONLY	0x4000	/* Key usable for authentication */
+#define	NS_KEY_TYPE_NO_KEY	0xC000	/* No key usable for either; no key */
+/* The type bits can also be interpreted independently, as single bits: */
+#define	NS_KEY_NO_AUTH		0x8000	/* Key unusable for authentication */
+#define	NS_KEY_NO_CONF		0x4000	/* Key unusable for confidentiality */
+#define	NS_KEY_RESERVED2	0x2000	/* Security is *mandatory* if bit=0 */
+#define	NS_KEY_EXTENDED_FLAGS	0x1000	/* reserved - must be zero */
+#define	NS_KEY_RESERVED4	0x0800  /* reserved - must be zero */
+#define	NS_KEY_RESERVED5	0x0400  /* reserved - must be zero */
+#define	NS_KEY_NAME_TYPE	0x0300	/* these bits determine the type */
+#define	NS_KEY_NAME_USER	0x0000	/* key is assoc. with user */
+#define	NS_KEY_NAME_ENTITY	0x0200	/* key is assoc. with entity eg host */
+#define	NS_KEY_NAME_ZONE	0x0100	/* key is zone key */
+#define	NS_KEY_NAME_RESERVED	0x0300	/* reserved meaning */
+#define	NS_KEY_RESERVED8	0x0080  /* reserved - must be zero */
+#define	NS_KEY_RESERVED9	0x0040  /* reserved - must be zero */
+#define	NS_KEY_RESERVED10	0x0020  /* reserved - must be zero */
+#define	NS_KEY_RESERVED11	0x0010  /* reserved - must be zero */
+#define	NS_KEY_SIGNATORYMASK	0x000F	/* key can sign RR's of same name */
+#define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
+				  NS_KEY_RESERVED4 | \
+				  NS_KEY_RESERVED5 | \
+				  NS_KEY_RESERVED8 | \
+				  NS_KEY_RESERVED9 | \
+				  NS_KEY_RESERVED10 | \
+				  NS_KEY_RESERVED11 )
+#define NS_KEY_RESERVED_BITMASK2 0xFFFF /* no bits defined here */
+
+/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
+#define	NS_ALG_MD5RSA		1	/* MD5 with RSA */
+#define	NS_ALG_DH               2	/* Diffie Hellman KEY */
+#define	NS_ALG_DSA              3	/* DSA KEY */
+#define	NS_ALG_DSS              NS_ALG_DSA
+#define	NS_ALG_EXPIRE_ONLY	253	/* No alg, no security */
+#define	NS_ALG_PRIVATE_OID	254	/* Key begins with OID giving alg */
+
+/* Protocol values  */
+/* value 0 is reserved */
+#define NS_KEY_PROT_TLS         1
+#define NS_KEY_PROT_EMAIL       2
+#define NS_KEY_PROT_DNSSEC      3
+#define NS_KEY_PROT_IPSEC       4
+#define NS_KEY_PROT_ANY		255
+
+/* Signatures */
+#define	NS_MD5RSA_MIN_BITS	 512	/* Size of a mod or exp in bits */
+#define	NS_MD5RSA_MAX_BITS	4096
+	/* Total of binary mod and exp */
+#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
+	/* Max length of text sig block */
+#define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
+#define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
+#define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)
+
+#define NS_DSA_SIG_SIZE         41
+#define NS_DSA_MIN_SIZE         213
+#define NS_DSA_MAX_BYTES        405
+
+/* Offsets into SIG record rdata to find various values */
+#define	NS_SIG_TYPE	0	/* Type flags */
+#define	NS_SIG_ALG	2	/* Algorithm */
+#define	NS_SIG_LABELS	3	/* How many labels in name */
+#define	NS_SIG_OTTL	4	/* Original TTL */
+#define	NS_SIG_EXPIR	8	/* Expiration time */
+#define	NS_SIG_SIGNED	12	/* Signature time */
+#define	NS_SIG_FOOT	16	/* Key footprint */
+#define	NS_SIG_SIGNER	18	/* Domain name of who signed it */
+
+/* How RR types are represented as bit-flags in NXT records */
+#define	NS_NXT_BITS 8
+#define	NS_NXT_BIT_SET(  n,p) (p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
+#define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
+#define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
+#define NS_NXT_MAX 127
+
+/*
+ * EDNS0 extended flags and option codes, host order.
+ */
+#define NS_OPT_DNSSEC_OK	0x8000U
+#define NS_OPT_NSID             3
+
+/*
+ * Inline versions of get/put short/long.  Pointer is advanced.
+ */
+#define NS_GET16(s, cp) do { \
+	const u_char *t_cp = (const u_char *)(cp); \
+	(s) = ((uint16_t)t_cp[0] << 8) \
+	    | ((uint16_t)t_cp[1]) \
+	    ; \
+	(cp) += NS_INT16SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_GET32(l, cp) do { \
+	const u_char *t_cp = (const u_char *)(cp); \
+	(l) = ((uint32_t)t_cp[0] << 24) \
+	    | ((uint32_t)t_cp[1] << 16) \
+	    | ((uint32_t)t_cp[2] << 8) \
+	    | ((uint32_t)t_cp[3]) \
+	    ; \
+	(cp) += NS_INT32SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_PUT16(s, cp) do { \
+	uint32_t t_s = (uint32_t)(s); \
+	u_char *t_cp = (u_char *)(cp); \
+	*t_cp++ = t_s >> 8; \
+	*t_cp   = t_s; \
+	(cp) += NS_INT16SZ; \
+} while (/*CONSTCOND*/0)
+
+#define NS_PUT32(l, cp) do { \
+	uint32_t t_l = (uint32_t)(l); \
+	u_char *t_cp = (u_char *)(cp); \
+	*t_cp++ = t_l >> 24; \
+	*t_cp++ = t_l >> 16; \
+	*t_cp++ = t_l >> 8; \
+	*t_cp   = t_l; \
+	(cp) += NS_INT32SZ; \
+} while (/*CONSTCOND*/0)
+
+/*
+ * ANSI C identifier hiding for bind's lib/nameser.
+ */
+#define	ns_msg_getflag		__ns_msg_getflag
+#define ns_get16		__ns_get16
+#define ns_get32		__ns_get32
+#define ns_put16		__ns_put16
+#define ns_put32		__ns_put32
+#define ns_initparse		__ns_initparse
+#define ns_skiprr		__ns_skiprr
+#define ns_parserr		__ns_parserr
+#define ns_parserr2		__ns_parserr2
+#define	ns_sprintrr		__ns_sprintrr
+#define	ns_sprintrrf		__ns_sprintrrf
+#define	ns_format_ttl		__ns_format_ttl
+#define	ns_parse_ttl		__ns_parse_ttl
+#define ns_datetosecs		__ns_datetosecs
+#define	ns_name_ntol		__ns_name_ntol
+#define	ns_name_ntop		__ns_name_ntop
+#define	ns_name_pton		__ns_name_pton
+#define	ns_name_pton2		__ns_name_pton2
+#define	ns_name_unpack		__ns_name_unpack
+#define	ns_name_unpack2		__ns_name_unpack2
+#define	ns_name_pack		__ns_name_pack
+#define	ns_name_compress	__ns_name_compress
+#define	ns_name_uncompress	__ns_name_uncompress
+#define	ns_name_skip		__ns_name_skip
+#define	ns_name_rollback	__ns_name_rollback
+#define	ns_name_length		__ns_name_length
+#define	ns_name_eq		__ns_name_eq
+#define	ns_name_owned		__ns_name_owned
+#define	ns_name_map		__ns_name_map
+#define	ns_name_labels		__ns_name_labels
+#define	ns_sign			__ns_sign
+#define	ns_sign2		__ns_sign2
+#define	ns_sign_tcp		__ns_sign_tcp
+#define	ns_sign_tcp2		__ns_sign_tcp2
+#define	ns_sign_tcp_init	__ns_sign_tcp_init
+#define ns_find_tsig		__ns_find_tsig
+#define	ns_verify		__ns_verify
+#define	ns_verify_tcp		__ns_verify_tcp
+#define	ns_verify_tcp_init	__ns_verify_tcp_init
+#define	ns_samedomain		__ns_samedomain
+#define	ns_subdomain		__ns_subdomain
+#define	ns_makecanon		__ns_makecanon
+#define	ns_samename		__ns_samename
+#define	ns_newmsg_init		__ns_newmsg_init
+#define	ns_newmsg_copy		__ns_newmsg_copy
+#define	ns_newmsg_id		__ns_newmsg_id
+#define	ns_newmsg_flag		__ns_newmsg_flag
+#define	ns_newmsg_q		__ns_newmsg_q
+#define	ns_newmsg_rr		__ns_newmsg_rr
+#define	ns_newmsg_done		__ns_newmsg_done
+#define	ns_rdata_unpack		__ns_rdata_unpack
+#define	ns_rdata_equal		__ns_rdata_equal
+#define	ns_rdata_refers		__ns_rdata_refers
+
+__BEGIN_DECLS
+int		ns_msg_getflag(ns_msg, int);
+uint16_t	ns_get16(const u_char *);
+uint32_t	ns_get32(const u_char *);
+void		ns_put16(uint16_t, u_char *);
+void		ns_put32(uint32_t, u_char *);
+int		ns_initparse(const u_char *, int, ns_msg *);
+int		ns_skiprr(const u_char *, const u_char *, ns_sect, int);
+int		ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
+int		ns_parserr2(ns_msg *, ns_sect, int, ns_rr2 *);
+int		ns_sprintrr(const ns_msg *, const ns_rr *,
+				 const char *, const char *, char *, size_t);
+int		ns_sprintrrf(const u_char *, size_t, const char *,
+				  ns_class, ns_type, u_long, const u_char *,
+				  size_t, const char *, const char *,
+				  char *, size_t);
+int		ns_format_ttl(u_long, char *, size_t);
+int		ns_parse_ttl(const char *, u_long *);
+uint32_t	ns_datetosecs(const char *cp, int *errp);
+int		ns_name_ntol(const u_char *, u_char *, size_t);
+int		ns_name_ntop(const u_char *, char *, size_t);
+int		ns_name_pton(const char *, u_char *, size_t);
+int		ns_name_pton2(const char *, u_char *, size_t, size_t *);
+int		ns_name_unpack(const u_char *, const u_char *,
+				    const u_char *, u_char *, size_t);
+int		ns_name_unpack2(const u_char *, const u_char *,
+				     const u_char *, u_char *, size_t,
+				     size_t *);
+int		ns_name_pack(const u_char *, u_char *, int,
+				  const u_char **, const u_char **);
+int		ns_name_uncompress(const u_char *, const u_char *,
+					const u_char *, char *, size_t);
+int		ns_name_compress(const char *, u_char *, size_t,
+				      const u_char **, const u_char **);
+int		ns_name_skip(const u_char **, const u_char *);
+void		ns_name_rollback(const u_char *, const u_char **,
+				      const u_char **);
+int		ns_sign(u_char *, int *, int, int, void *,
+			     const u_char *, int, u_char *, int *, time_t);
+int		ns_sign2(u_char *, int *, int, int, void *,
+			      const u_char *, int, u_char *, int *, time_t,
+			      u_char **, u_char **);
+ssize_t		ns_name_length(ns_nname_ct, size_t);
+int		ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t);
+int		ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int);
+int		ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int);
+int		ns_name_labels(ns_nname_ct, size_t);
+int		ns_sign_tcp(u_char *, int *, int, int,
+				 ns_tcp_tsig_state *, int);
+int		ns_sign_tcp2(u_char *, int *, int, int,
+				  ns_tcp_tsig_state *, int,
+				  u_char **, u_char **);
+int		ns_sign_tcp_init(void *, const u_char *, int,
+					ns_tcp_tsig_state *);
+u_char		*ns_find_tsig(u_char *, u_char *);
+int		ns_verify(u_char *, int *, void *,
+			       const u_char *, int, u_char *, int *,
+			       time_t *, int);
+int		ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);
+int		ns_verify_tcp_init(void *, const u_char *, int,
+					ns_tcp_tsig_state *);
+int		ns_samedomain(const char *, const char *);
+int		ns_subdomain(const char *, const char *);
+int		ns_makecanon(const char *, char *, size_t);
+int		ns_samename(const char *, const char *);
+int		ns_newmsg_init(u_char *buffer, size_t bufsiz, ns_newmsg *);
+int		ns_newmsg_copy(ns_newmsg *, ns_msg *);
+void		ns_newmsg_id(ns_newmsg *handle, uint16_t id);
+void		ns_newmsg_flag(ns_newmsg *handle, ns_flag flag, u_int value);
+int		ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname,
+			    ns_type qtype, ns_class qclass);
+int		ns_newmsg_rr(ns_newmsg *handle, ns_sect sect,
+			     ns_nname_ct name, ns_type type,
+			     ns_class rr_class, uint32_t ttl,
+			     uint16_t rdlen, const u_char *rdata);
+size_t		ns_newmsg_done(ns_newmsg *handle);
+ssize_t		ns_rdata_unpack(const u_char *, const u_char *, ns_type,
+				const u_char *, size_t, u_char *, size_t);
+int		ns_rdata_equal(ns_type,
+			       const u_char *, size_t,
+			       const u_char *, size_t);
+int		ns_rdata_refers(ns_type,
+				const u_char *, size_t,
+				const u_char *);
+__END_DECLS
+
+#ifdef BIND_4_COMPAT
+#include <arpa/nameser_compat.h>
+#endif
+
+#endif /* !_ARPA_NAMESER_H_ */
diff --git a/ndk/platforms/android-20/include/arpa/nameser_compat.h b/ndk/platforms/android-20/include/arpa/nameser_compat.h
new file mode 100644
index 0000000..e060f60
--- /dev/null
+++ b/ndk/platforms/android-20/include/arpa/nameser_compat.h
@@ -0,0 +1,238 @@
+/*	$NetBSD: nameser_compat.h,v 1.1.1.2 2004/11/07 01:28:27 christos Exp $	*/
+
+/* Copyright (c) 1983, 1989
+ *    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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ * 	This product includes software developed by the University of
+ * 	California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+/*
+ *      from nameser.h	8.1 (Berkeley) 6/2/93
+ *	Id: nameser_compat.h,v 1.8 2006/05/19 02:33:40 marka Exp
+ */
+
+#ifndef _ARPA_NAMESER_COMPAT_
+#define	_ARPA_NAMESER_COMPAT_
+
+#define	__BIND		19950621	/* (DEAD) interface version stamp. */
+
+#include <endian.h>
+
+#ifndef BYTE_ORDER
+#if (BSD >= 199103)
+# include <machine/endian.h>
+#else
+#ifdef __linux__
+# include <endian.h>
+#else
+#define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax, pc) */
+#define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
+#define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp)*/
+
+#if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
+    defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
+    defined(__i386__) || defined(__i386) || defined(__amd64__) || \
+    defined(__x86_64__) || defined(MIPSEL) || defined(_MIPSEL) || \
+    defined(BIT_ZERO_ON_RIGHT) || defined(__alpha__) || defined(__alpha) || \
+    (defined(__Lynx__) && defined(__x86__))
+#define BYTE_ORDER	LITTLE_ENDIAN
+#endif
+
+#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
+    defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
+    defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
+    defined(apollo) || defined(__convex__) || defined(_CRAY) || \
+    defined(__hppa) || defined(__hp9000) || \
+    defined(__hp9000s300) || defined(__hp9000s700) || \
+    defined(__hp3000s900) || defined(__hpux) || defined(MPE) || \
+    defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) ||  \
+    (defined(__Lynx__) && \
+     (defined(__68k__) || defined(__sparc__) || defined(__powerpc__)))
+#define BYTE_ORDER	BIG_ENDIAN
+#endif
+#endif /* __linux */
+#endif /* BSD */
+#endif /* BYTE_ORDER */
+
+#if !defined(BYTE_ORDER) || \
+    (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
+    BYTE_ORDER != PDP_ENDIAN)
+	/* you must determine what the correct bit order is for
+	 * your compiler - the next line is an intentional error
+	 * which will force your compiles to bomb until you fix
+	 * the above macros.
+	 */
+  #error "Undefined or invalid BYTE_ORDER";
+#endif
+
+/*
+ * Structure for query header.  The order of the fields is machine- and
+ * compiler-dependent, depending on the byte/bit order and the layout
+ * of bit fields.  We use bit fields only in int variables, as this
+ * is all ANSI requires.  This requires a somewhat confusing rearrangement.
+ */
+
+typedef struct {
+	unsigned	id :16;		/* query identification number */
+#if BYTE_ORDER == BIG_ENDIAN
+			/* fields in third byte */
+	unsigned	qr: 1;		/* response flag */
+	unsigned	opcode: 4;	/* purpose of message */
+	unsigned	aa: 1;		/* authoritive answer */
+	unsigned	tc: 1;		/* truncated message */
+	unsigned	rd: 1;		/* recursion desired */
+			/* fields in fourth byte */
+	unsigned	ra: 1;		/* recursion available */
+	unsigned	unused :1;	/* unused bits (MBZ as of 4.9.3a3) */
+	unsigned	ad: 1;		/* authentic data from named */
+	unsigned	cd: 1;		/* checking disabled by resolver */
+	unsigned	rcode :4;	/* response code */
+#endif
+#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
+			/* fields in third byte */
+	unsigned	rd :1;		/* recursion desired */
+	unsigned	tc :1;		/* truncated message */
+	unsigned	aa :1;		/* authoritive answer */
+	unsigned	opcode :4;	/* purpose of message */
+	unsigned	qr :1;		/* response flag */
+			/* fields in fourth byte */
+	unsigned	rcode :4;	/* response code */
+	unsigned	cd: 1;		/* checking disabled by resolver */
+	unsigned	ad: 1;		/* authentic data from named */
+	unsigned	unused :1;	/* unused bits (MBZ as of 4.9.3a3) */
+	unsigned	ra :1;		/* recursion available */
+#endif
+			/* remaining bytes */
+	unsigned	qdcount :16;	/* number of question entries */
+	unsigned	ancount :16;	/* number of answer entries */
+	unsigned	nscount :16;	/* number of authority entries */
+	unsigned	arcount :16;	/* number of resource entries */
+} HEADER;
+
+#define PACKETSZ	NS_PACKETSZ
+#define MAXDNAME	NS_MAXDNAME
+#define MAXCDNAME	NS_MAXCDNAME
+#define MAXLABEL	NS_MAXLABEL
+#define	HFIXEDSZ	NS_HFIXEDSZ
+#define QFIXEDSZ	NS_QFIXEDSZ
+#define RRFIXEDSZ	NS_RRFIXEDSZ
+#define	INT32SZ		NS_INT32SZ
+#define	INT16SZ		NS_INT16SZ
+#define	INT8SZ		NS_INT8SZ
+#define	INADDRSZ	NS_INADDRSZ
+#define	IN6ADDRSZ	NS_IN6ADDRSZ
+#define	INDIR_MASK	NS_CMPRSFLGS
+#define NAMESERVER_PORT	NS_DEFAULTPORT
+
+#define S_ZONE		ns_s_zn
+#define S_PREREQ	ns_s_pr
+#define S_UPDATE	ns_s_ud
+#define S_ADDT		ns_s_ar
+
+#define QUERY		ns_o_query
+#define IQUERY		ns_o_iquery
+#define STATUS		ns_o_status
+#define	NS_NOTIFY_OP	ns_o_notify
+#define	NS_UPDATE_OP	ns_o_update
+
+#define NOERROR		ns_r_noerror
+#define FORMERR		ns_r_formerr
+#define SERVFAIL	ns_r_servfail
+#define NXDOMAIN	ns_r_nxdomain
+#define NOTIMP		ns_r_notimpl
+#define REFUSED		ns_r_refused
+#define YXDOMAIN	ns_r_yxdomain
+#define YXRRSET		ns_r_yxrrset
+#define NXRRSET		ns_r_nxrrset
+#define NOTAUTH		ns_r_notauth
+#define NOTZONE		ns_r_notzone
+/*#define BADSIG		ns_r_badsig*/
+/*#define BADKEY		ns_r_badkey*/
+/*#define BADTIME		ns_r_badtime*/
+
+
+#define DELETE		ns_uop_delete
+#define ADD		ns_uop_add
+
+#define T_A		ns_t_a
+#define T_NS		ns_t_ns
+#define T_MD		ns_t_md
+#define T_MF		ns_t_mf
+#define T_CNAME		ns_t_cname
+#define T_SOA		ns_t_soa
+#define T_MB		ns_t_mb
+#define T_MG		ns_t_mg
+#define T_MR		ns_t_mr
+#define T_NULL		ns_t_null
+#define T_WKS		ns_t_wks
+#define T_PTR		ns_t_ptr
+#define T_HINFO		ns_t_hinfo
+#define T_MINFO		ns_t_minfo
+#define T_MX		ns_t_mx
+#define T_TXT		ns_t_txt
+#define	T_RP		ns_t_rp
+#define T_AFSDB		ns_t_afsdb
+#define T_X25		ns_t_x25
+#define T_ISDN		ns_t_isdn
+#define T_RT		ns_t_rt
+#define T_NSAP		ns_t_nsap
+#define T_NSAP_PTR	ns_t_nsap_ptr
+#define	T_SIG		ns_t_sig
+#define	T_KEY		ns_t_key
+#define	T_PX		ns_t_px
+#define	T_GPOS		ns_t_gpos
+#define	T_AAAA		ns_t_aaaa
+#define	T_LOC		ns_t_loc
+#define	T_NXT		ns_t_nxt
+#define	T_EID		ns_t_eid
+#define	T_NIMLOC	ns_t_nimloc
+#define	T_SRV		ns_t_srv
+#define T_ATMA		ns_t_atma
+#define T_NAPTR		ns_t_naptr
+#define T_A6		ns_t_a6
+#define	T_TSIG		ns_t_tsig
+#define	T_IXFR		ns_t_ixfr
+#define T_AXFR		ns_t_axfr
+#define T_MAILB		ns_t_mailb
+#define T_MAILA		ns_t_maila
+#define T_ANY		ns_t_any
+
+#define C_IN		ns_c_in
+#define C_CHAOS		ns_c_chaos
+#define C_HS		ns_c_hs
+/* BIND_UPDATE */
+#define C_NONE		ns_c_none
+#define C_ANY		ns_c_any
+
+#define	GETSHORT		NS_GET16
+#define	GETLONG			NS_GET32
+#define	PUTSHORT		NS_PUT16
+#define	PUTLONG			NS_PUT32
+
+#endif /* _ARPA_NAMESER_COMPAT_ */
diff --git a/ndk/platforms/android-20/include/asm-generic/signal.h b/ndk/platforms/android-20/include/asm-generic/signal.h
index c4c7e00..fe7d9a0 100644
--- a/ndk/platforms/android-20/include/asm-generic/signal.h
+++ b/ndk/platforms/android-20/include/asm-generic/signal.h
@@ -19,10 +19,10 @@
 #ifndef _UAPI__ASM_GENERIC_SIGNAL_H
 #define _UAPI__ASM_GENERIC_SIGNAL_H
 #include <linux/types.h>
-#define _NSIG 64
+#define _KERNEL__NSIG 64
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define _NSIG_BPW __BITS_PER_LONG
-#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
+#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW)
 #define SIGHUP 1
 #define SIGINT 2
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
@@ -68,7 +68,7 @@
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SIGRTMIN 32
 #ifndef SIGRTMAX
-#define SIGRTMAX _NSIG
+#define SIGRTMAX _KERNEL__NSIG
 #endif
 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #define SA_NOCLDSTOP 0x00000001
diff --git a/ndk/platforms/android-20/include/dirent.h b/ndk/platforms/android-20/include/dirent.h
index 129cdfa..bfe4ea4 100644
--- a/ndk/platforms/android-20/include/dirent.h
+++ b/ndk/platforms/android-20/include/dirent.h
@@ -46,27 +46,33 @@
 #define DT_WHT 14
 #endif
 
-struct dirent {
-  uint64_t         d_ino;
-  int64_t          d_off;
-  unsigned short   d_reclen;
-  unsigned char    d_type;
-  char             d_name[256];
-};
+#define __DIRENT64_BODY \
+    uint64_t         d_ino; \
+    int64_t          d_off; \
+    unsigned short   d_reclen; \
+    unsigned char    d_type; \
+    char             d_name[256]; \
+
+struct dirent { __DIRENT64_BODY };
+struct dirent64 { __DIRENT64_BODY };
+
 #define d_fileno d_ino
-#define dirent64 dirent
 
 typedef struct DIR DIR;
 
 extern DIR* opendir(const char*);
 extern DIR* fdopendir(int);
 extern struct dirent* readdir(DIR*);
+extern struct dirent64* readdir64(DIR*);
 extern int readdir_r(DIR*, struct dirent*, struct dirent**);
+extern int readdir64_r(DIR*, struct dirent64*, struct dirent64**);
 extern int closedir(DIR*);
 extern void rewinddir(DIR*);
 extern int dirfd(DIR*);
 extern int alphasort(const struct dirent**, const struct dirent**);
+extern int alphasort64(const struct dirent64**, const struct dirent64**);
 extern int scandir(const char*, struct dirent***, int (*)(const struct dirent*), int (*)(const struct dirent**, const struct dirent**));
+extern int scandir64(const char*, struct dirent64***, int (*)(const struct dirent64*), int (*)(const struct dirent64**, const struct dirent64**));
 extern int getdents(unsigned int, struct dirent*, unsigned int);
 
 __END_DECLS
diff --git a/ndk/platforms/android-20/include/elf.h b/ndk/platforms/android-20/include/elf.h
index 3f2e4f2..7a217b0 100644
--- a/ndk/platforms/android-20/include/elf.h
+++ b/ndk/platforms/android-20/include/elf.h
@@ -28,33 +28,58 @@
 #ifndef _ELF_H
 #define _ELF_H
 
-#include <stdint.h>
 #include <linux/auxvec.h>
+#include <linux/elf.h>
+#include <linux/elf-em.h>
 
-/* TODO: can we switch to <linux/elf.h> instead? http://b/12476126. */
-#include <sys/exec_elf.h>
+#include <machine/elf_machdep.h>
 
 typedef struct {
-  uint32_t a_type;
+  __u32 a_type;
   union {
-    uint32_t a_val;
+    __u32 a_val;
   } a_un;
 } Elf32_auxv_t;
 
 typedef struct {
-  uint64_t a_type;
+  __u64 a_type;
   union {
-    uint64_t a_val;
+    __u64 a_val;
   } a_un;
 } Elf64_auxv_t;
 
-#ifdef __LP64__
-#  define Elf_auxv_t Elf64_auxv_t
-#else
-#  define Elf_auxv_t Elf32_auxv_t
-#endif
+#define DF_ORIGIN     0x00000001
+#define DF_SYMBOLIC   0x00000002
+#define DF_TEXTREL    0x00000004
+#define DF_BIND_NOW   0x00000008
+#define DF_STATIC_TLS 0x00000010
 
-/* <sys/exec_elf.h> doesn't contain any NT_ constants. aarch64 strace needs this one. */
-#define NT_PRSTATUS 1
+#define DT_BIND_NOW 24
+#define DT_INIT_ARRAY 25
+#define DT_FINI_ARRAY 26
+#define DT_INIT_ARRAYSZ 27
+#define DT_FINI_ARRAYSZ 28
+#define DT_RUNPATH 29
+#define DT_FLAGS 30
+/* glibc and BSD disagree for DT_ENCODING; glibc looks wrong. */
+#define DT_PREINIT_ARRAY 32
+#define DT_PREINIT_ARRAYSZ 33
+
+#define ELFOSABI_SYSV 0 /* Synonym for ELFOSABI_NONE used by valgrind. */
+
+#define EM_ARM 40
+#define EM_AARCH64 183
+
+#define PT_GNU_RELRO 0x6474e552
+
+#define STB_LOOS   10
+#define STB_HIOS   12
+#define STB_LOPROC 13
+#define STB_HIPROC 15
+
+#define STT_LOOS   10
+#define STT_HIOS   12
+#define STT_LOPROC 13
+#define STT_HIPROC 15
 
 #endif /* _ELF_H */
diff --git a/ndk/platforms/android-20/include/fcntl.h b/ndk/platforms/android-20/include/fcntl.h
index b7b91f2..779a089 100644
--- a/ndk/platforms/android-20/include/fcntl.h
+++ b/ndk/platforms/android-20/include/fcntl.h
@@ -41,12 +41,19 @@
 #define O_ASYNC  FASYNC
 #endif
 
+#define SYNC_FILE_RANGE_WAIT_BEFORE 1
+#define SYNC_FILE_RANGE_WRITE 2
+#define SYNC_FILE_RANGE_WAIT_AFTER 4
+
 extern int creat(const char*, mode_t);
+extern int creat64(const char*, mode_t);
 extern int fallocate64(int, int, off64_t, off64_t);
 extern int fallocate(int, int, off_t, off_t);
 extern int fcntl(int, int, ...);
 extern int openat(int, const char*, int, ...);
+extern int openat64(int, const char*, int, ...);
 extern int open(const char*, int, ...);
+extern int open64(const char*, int, ...);
 extern int posix_fallocate64(int, off64_t, off64_t);
 extern int posix_fallocate(int, off_t, off_t);
 extern int unlinkat(int, const char*, int);
diff --git a/ndk/platforms/android-20/include/fenv.h b/ndk/platforms/android-20/include/fenv.h
new file mode 100644
index 0000000..6966e0d
--- /dev/null
+++ b/ndk/platforms/android-20/include/fenv.h
@@ -0,0 +1,69 @@
+/*  $OpenBSD: fenv.h,v 1.2 2011/05/25 21:46:49 martynas Exp $ */
+/*  $NetBSD: fenv.h,v 1.2.4.1 2011/02/08 16:18:55 bouyer Exp $  */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#ifndef _FENV_H_
+#define _FENV_H_
+
+#include <sys/cdefs.h>
+#include <machine/fenv.h>
+
+__BEGIN_DECLS
+
+int feclearexcept(int);
+int fegetexceptflag(fexcept_t *, int);
+int feraiseexcept(int);
+int fesetexceptflag(const fexcept_t *, int);
+int fetestexcept(int);
+
+int fegetround(void);
+int fesetround(int);
+
+int fegetenv(fenv_t *);
+int feholdexcept(fenv_t *);
+int fesetenv(const fenv_t *);
+int feupdateenv(const fenv_t *);
+
+int feenableexcept(int);
+int fedisableexcept(int);
+int fegetexcept(void);
+
+/*
+ * The following constant represents the default floating-point environment
+ * (that is, the one installed at program startup) and has type pointer to
+ * const-qualified fenv_t.
+ *
+ * It can be used as an argument to the functions that manage the floating-point
+ * environment, namely fesetenv() and feupdateenv().
+ */
+extern const fenv_t __fe_dfl_env;
+#define FE_DFL_ENV  (&__fe_dfl_env)
+
+__END_DECLS
+
+#endif  /* ! _FENV_H_ */
diff --git a/ndk/platforms/android-20/include/ftw.h b/ndk/platforms/android-20/include/ftw.h
index 3bebea3..af524d0 100644
--- a/ndk/platforms/android-20/include/ftw.h
+++ b/ndk/platforms/android-20/include/ftw.h
@@ -57,6 +57,9 @@
 int	ftw(const char *, int (*)(const char *, const struct stat *, int), int);
 int	nftw(const char *, int (*)(const char *, const struct stat *, int,
 	    struct FTW *), int, int);
+int	ftw64(const char *, int (*)(const char *, const struct stat64 *, int), int);
+int	nftw64(const char *, int (*)(const char *, const struct stat64 *, int,
+	    struct FTW *), int, int);
 __END_DECLS
 
 #endif	/* !_FTW_H */
diff --git a/ndk/platforms/android-20/include/limits.h b/ndk/platforms/android-20/include/limits.h
index b9d4354..471d380 100644
--- a/ndk/platforms/android-20/include/limits.h
+++ b/ndk/platforms/android-20/include/limits.h
@@ -105,9 +105,15 @@
 #define ULONG_LONG_MAX  ULLONG_MAX
 #endif
 
+/* New code should use sysconf(_SC_PAGE_SIZE) instead. */
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
 #ifndef PAGESIZE
-#include <asm/page.h>
 #define  PAGESIZE  PAGE_SIZE
 #endif
 
+/* glibc's PAGE_MASK is the bitwise negation of BSD's! TODO: remove? */
+#define PAGE_MASK (~(PAGE_SIZE - 1))
+
 #endif /* !_LIMITS_H_ */
diff --git a/ndk/platforms/android-20/include/link.h b/ndk/platforms/android-20/include/link.h
index 341fbf1..cb8e139 100644
--- a/ndk/platforms/android-20/include/link.h
+++ b/ndk/platforms/android-20/include/link.h
@@ -33,7 +33,11 @@
 
 __BEGIN_DECLS
 
-#define ElfW(type) Elf_##type
+#if __LP64__
+#define ElfW(type) Elf64_ ## type
+#else
+#define ElfW(type) Elf32_ ## type
+#endif
 
 struct dl_phdr_info {
   ElfW(Addr) dlpi_addr;
@@ -42,13 +46,35 @@
   ElfW(Half) dlpi_phnum;
 };
 
-int dl_iterate_phdr(int (*cb)(struct dl_phdr_info*, size_t, void*), void*);
+int dl_iterate_phdr(int (*)(struct dl_phdr_info*, size_t, void*), void*);
 
 #ifdef __arm__
 typedef long unsigned int* _Unwind_Ptr;
-_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
+_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr, int*);
 #endif
 
+/* Used by the dynamic linker to communicate with the debugger. */
+struct link_map {
+  ElfW(Addr) l_addr;
+  char* l_name;
+  ElfW(Dyn)* l_ld;
+  struct link_map* l_next;
+  struct link_map* l_prev;
+};
+
+/* Used by the dynamic linker to communicate with the debugger. */
+struct r_debug {
+  int32_t r_version;
+  struct link_map* r_map;
+  ElfW(Addr) r_brk;
+  enum {
+    RT_CONSISTENT,
+    RT_ADD,
+    RT_DELETE
+  } r_state;
+  ElfW(Addr) r_ldbase;
+};
+
 __END_DECLS
 
 #endif /* _LINK_H_ */
diff --git a/ndk/platforms/android-20/include/locale.h b/ndk/platforms/android-20/include/locale.h
index 65b5c7d..b6dbfdb 100644
--- a/ndk/platforms/android-20/include/locale.h
+++ b/ndk/platforms/android-20/include/locale.h
@@ -49,11 +49,13 @@
     LC_IDENTIFICATION = 12
 };
 
-extern char *setlocale(int category, const char *locale);
+extern char* setlocale(int, const char*);
 
-/* Make libstdc++-v3 happy.  */
+#if !defined(__LP64__)
+// TODO: LP32 had these bogus declarations but LP64 should have a real struct lconv and localeconv(3).
 struct lconv { };
-struct lconv *localeconv(void);
+struct lconv* localeconv(void);
+#endif
 
 __END_DECLS
 
diff --git a/ndk/platforms/android-20/include/math.h b/ndk/platforms/android-20/include/math.h
index b13eca9..bd0241b 100644
--- a/ndk/platforms/android-20/include/math.h
+++ b/ndk/platforms/android-20/include/math.h
@@ -18,7 +18,6 @@
 #define	_MATH_H_
 
 #include <sys/cdefs.h>
-#include <sys/_types.h>
 #include <limits.h>
 
 /*
@@ -124,8 +123,10 @@
     : (sizeof (x) == sizeof (double)) ? __signbit(x)	\
     : __signbitl(x))
 
-typedef	__double_t	double_t;
-typedef	__float_t	float_t;
+typedef double __double_t;
+typedef __double_t double_t;
+typedef float __float_t;
+typedef __float_t float_t;
 #endif /* __ISO_C_VISIBLE >= 1999 */
 
 /*
diff --git a/ndk/platforms/android-20/include/pthread.h b/ndk/platforms/android-20/include/pthread.h
index c5380be..f93f9e9 100644
--- a/ndk/platforms/android-20/include/pthread.h
+++ b/ndk/platforms/android-20/include/pthread.h
@@ -127,11 +127,13 @@
 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 * attr, size_t stack_size) __nonnull((1));
+int pthread_attr_setstacksize(pthread_attr_t*, size_t stack_size) __nonnull((1));
 
 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_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));
 int pthread_condattr_setpshared(pthread_condattr_t*, int) __nonnull((1));
 
 int pthread_cond_broadcast(pthread_cond_t*) __nonnull((1));
@@ -172,7 +174,7 @@
 int pthread_mutex_destroy(pthread_mutex_t*) __nonnull((1));
 int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __nonnull((1));
 int pthread_mutex_lock(pthread_mutex_t*) __nonnull((1));
-int pthread_mutex_timedlock(pthread_mutex_t*, struct timespec*) __nonnull((1, 2));
+int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) __nonnull((1, 2));
 int pthread_mutex_trylock(pthread_mutex_t*) __nonnull((1));
 int pthread_mutex_unlock(pthread_mutex_t*) __nonnull((1));
 
@@ -232,32 +234,17 @@
 
 #if !defined(__LP64__)
 
-/* Deprecated by POSIX. TODO: support for LP64 but add deprecated attribute instead? */
-int pthread_attr_getstackaddr(const pthread_attr_t*, void**) __nonnull((1, 2)); /* deprecated */
-int pthread_attr_setstackaddr(pthread_attr_t*, void*) __nonnull((1)); /* deprecated */
-
-/* Bionic additions that are deprecated even in the 32-bit ABI. */
+// Bionic additions that are deprecated even in the 32-bit ABI.
+//
+// TODO: Remove them once chromium_org / NFC have switched over.
 int pthread_cond_timedwait_monotonic_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
 int pthread_cond_timedwait_monotonic(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
-#define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC 1
 
-/*
- * Like pthread_cond_timedwait except 'reltime' is relative to the current time.
- * TODO: not like glibc; include in LP64?
- */
-int pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
-#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1
+int pthread_cond_timedwait_relative_np(pthread_cond_t*, pthread_mutex_t*, const struct timespec*) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
+#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1 /* TODO: stop defining this to push LP32 off this API sooner. */
+int pthread_cond_timeout_np(pthread_cond_t*, pthread_mutex_t*, unsigned) /* TODO: __attribute__((deprecated("use pthread_cond_timedwait instead")))*/;
 
-/* TODO: not like glibc; include in LP64? */
-int pthread_cond_timeout_np(pthread_cond_t*, pthread_mutex_t*, unsigned);
-
-/* Like pthread_mutex_lock(), but will wait up to 'msecs' milli-seconds
- * before returning. Same return values as pthread_mutex_trylock though, i.e.
- * returns EBUSY if the lock could not be acquired after the timeout expired.
- *
- * TODO: replace with pthread_mutex_timedlock_np for LP64.
- */
-int pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned);
+int pthread_mutex_lock_timeout_np(pthread_mutex_t*, unsigned) __attribute__((deprecated("use pthread_mutex_timedlock instead")));
 
 #endif /* !defined(__LP64__) */
 
diff --git a/ndk/platforms/android-20/include/search.h b/ndk/platforms/android-20/include/search.h
index e12e49e..1301a08 100644
--- a/ndk/platforms/android-20/include/search.h
+++ b/ndk/platforms/android-20/include/search.h
@@ -10,7 +10,6 @@
 #define _SEARCH_H_
 
 #include <sys/cdefs.h>
-#include <sys/_types.h>
 
 typedef	enum {
 	preorder,
diff --git a/ndk/platforms/android-20/include/signal.h b/ndk/platforms/android-20/include/signal.h
index 0159bf2..267f3e6 100644
--- a/ndk/platforms/android-20/include/signal.h
+++ b/ndk/platforms/android-20/include/signal.h
@@ -51,20 +51,23 @@
 
 typedef int sig_atomic_t;
 
-/* TODO: 64-bit: we should probably #undef the uapi NSIG and add a unit test that NSIG == _NSIG && NSIG >= 64. */
-#ifndef _NSIG
-#  define _NSIG 64
-#endif
-#ifndef NSIG
-#  define NSIG _NSIG
+/* The arm and x86 kernel header files don't define _NSIG. */
+#ifndef _KERNEL__NSIG
+#define _KERNEL__NSIG 64
 #endif
 
+/* Userspace's NSIG is the kernel's _NSIG + 1. */
+#define _NSIG (_KERNEL__NSIG + 1)
+#define NSIG _NSIG
+
 extern const char* const sys_siglist[];
-extern const char* const sys_signame[];
+extern const char* const sys_signame[]; /* BSD compatibility. */
 
 typedef __sighandler_t sig_t; /* BSD compatibility. */
 typedef __sighandler_t sighandler_t; /* glibc compatibility. */
 
+#define si_timerid si_tid /* glibc compatibility. */
+
 #if defined(__LP64__)
 
 struct sigaction {
diff --git a/ndk/platforms/android-20/include/stdint.h b/ndk/platforms/android-20/include/stdint.h
index be49485..1f3d003 100644
--- a/ndk/platforms/android-20/include/stdint.h
+++ b/ndk/platforms/android-20/include/stdint.h
@@ -30,7 +30,28 @@
 #define _STDINT_H
 
 #include <stddef.h>
-#include <sys/_types.h>
+
+typedef __signed char __int8_t;
+typedef unsigned char __uint8_t;
+typedef short __int16_t;
+typedef unsigned short __uint16_t;
+typedef int __int32_t;
+typedef unsigned int __uint32_t;
+#if __LP64__
+typedef long __int64_t;
+typedef unsigned long __uint64_t;
+#else
+typedef long long __int64_t;
+typedef unsigned long long __uint64_t;
+#endif
+
+#if __LP64__
+typedef long __intptr_t;
+typedef unsigned long __uintptr_t;
+#else
+typedef int __intptr_t;
+typedef unsigned int __uintptr_t;
+#endif
 
 typedef __int8_t      int8_t;
 typedef __uint8_t     uint8_t;
@@ -44,40 +65,41 @@
 typedef __int64_t     int64_t;
 typedef __uint64_t    uint64_t;
 
-typedef int8_t        int_least8_t;
-typedef int8_t        int_fast8_t;
+typedef __intptr_t    intptr_t;
+typedef __uintptr_t   uintptr_t;
 
+typedef int8_t        int_least8_t;
 typedef uint8_t       uint_least8_t;
-typedef uint8_t       uint_fast8_t;
 
 typedef int16_t       int_least16_t;
-typedef int32_t       int_fast16_t;
-
 typedef uint16_t      uint_least16_t;
-typedef uint32_t      uint_fast16_t;
 
 typedef int32_t       int_least32_t;
-typedef int32_t       int_fast32_t;
-
 typedef uint32_t      uint_least32_t;
-typedef uint32_t      uint_fast32_t;
 
 typedef int64_t       int_least64_t;
-typedef int64_t       int_fast64_t;
-
 typedef uint64_t      uint_least64_t;
+
+typedef int8_t        int_fast8_t;
+typedef uint8_t       uint_fast8_t;
+
+typedef int64_t       int_fast64_t;
 typedef uint64_t      uint_fast64_t;
 
 #ifdef __LP64__
-typedef long          intptr_t;
-typedef unsigned long uintptr_t;
+typedef int64_t       int_fast16_t;
+typedef uint64_t      uint_fast16_t;
+typedef int64_t       int_fast32_t;
+typedef uint64_t      uint_fast32_t;
 #else
-typedef int           intptr_t;
-typedef unsigned int  uintptr_t;
+typedef int32_t       int_fast16_t;
+typedef uint32_t      uint_fast16_t;
+typedef int32_t       int_fast32_t;
+typedef uint32_t      uint_fast32_t;
 #endif
 
-typedef uint64_t uintmax_t;
-typedef int64_t  intmax_t;
+typedef uint64_t      uintmax_t;
+typedef int64_t       intmax_t;
 
 /* Keep the kernel from trying to define these types... */
 #define __BIT_TYPES_DEFINED__
diff --git a/ndk/platforms/android-20/include/stdio.h b/ndk/platforms/android-20/include/stdio.h
index c241d94..7d30b38 100644
--- a/ndk/platforms/android-20/include/stdio.h
+++ b/ndk/platforms/android-20/include/stdio.h
@@ -359,83 +359,6 @@
 #define	fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
 #endif /* __BSD_VISIBLE */
 
-/*
- * Functions internal to the implementation.
- */
-__BEGIN_DECLS
-int	__srget(FILE *);
-int	__swbuf(int, FILE *);
-__END_DECLS
-
-/*
- * The __sfoo macros are here so that we can
- * define function versions in the C library.
- */
-#define	__sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
-#if defined(__GNUC__)
-static __inline int __sputc(int _c, FILE *_p) {
-	if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
-		return (*_p->_p++ = _c);
-	else
-		return (__swbuf(_c, _p));
-}
-#else
-/*
- * This has been tuned to generate reasonable code on the vax using pcc.
- */
-#define	__sputc(c, p) \
-	(--(p)->_w < 0 ? \
-		(p)->_w >= (p)->_lbfsize ? \
-			(*(p)->_p = (c)), *(p)->_p != '\n' ? \
-				(int)*(p)->_p++ : \
-				__swbuf('\n', p) : \
-			__swbuf((int)(c), p) : \
-		(*(p)->_p = (c), (int)*(p)->_p++))
-#endif
-
-#define	__sfeof(p)	(((p)->_flags & __SEOF) != 0)
-#define	__sferror(p)	(((p)->_flags & __SERR) != 0)
-#define	__sclearerr(p)	((void)((p)->_flags &= ~(__SERR|__SEOF)))
-#define	__sfileno(p)	((p)->_file)
-
-extern	int __isthreaded;
-
-#define	feof(p)		(!__isthreaded ? __sfeof(p) : (feof)(p))
-#define	ferror(p)	(!__isthreaded ? __sferror(p) : (ferror)(p))
-#define	clearerr(p)	(!__isthreaded ? __sclearerr(p) : (clearerr)(p))
-
-#if __POSIX_VISIBLE
-#define	fileno(p)	(!__isthreaded ? __sfileno(p) : (fileno)(p))
-#endif
-
-#define	getc(fp)	(!__isthreaded ? __sgetc(fp) : (getc)(fp))
-
-#if __BSD_VISIBLE
-/*
- * The macro implementations of putc and putc_unlocked are not
- * fully POSIX compliant; they do not set errno on failure
- */
-#define putc(x, fp)	(!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
-#endif /* __BSD_VISIBLE */
-
-#ifndef lint
-#if __POSIX_VISIBLE >= 199506
-#define	getc_unlocked(fp)	__sgetc(fp)
-/*
- * The macro implementations of putc and putc_unlocked are not
- * fully POSIX compliant; they do not set errno on failure
- */
-#if __BSD_VISIBLE
-#define putc_unlocked(x, fp)	__sputc(x, fp)
-#endif /* __BSD_VISIBLE */
-#endif /* __POSIX_VISIBLE >= 199506 */
-#endif /* lint */
-
-#define	getchar()	getc(stdin)
-#define	putchar(x)	putc(x, stdout)
-#define	getchar_unlocked()	getc_unlocked(stdin)
-#define	putchar_unlocked(c)	putc_unlocked(c, stdout)
-
 #ifdef _GNU_SOURCE
 /*
  * glibc defines dprintf(int, const char*, ...), which is poorly named
@@ -470,8 +393,10 @@
 }
 
 #if defined(__clang__)
+#if !defined(WITH_SYNTAX_CHECK)
 #define __wrap_snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__)
 #define snprintf(...) __wrap_snprintf(__VA_ARGS__)
+#endif
 #else
 __BIONIC_FORTIFY_INLINE
 __printflike(3, 4)
@@ -483,8 +408,10 @@
 #endif
 
 #if defined(__clang__)
+#if !defined(WITH_SYNTAX_CHECK)
 #define __wrap_sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__)
 #define sprintf(...) __wrap_sprintf(__VA_ARGS__)
+#endif
 #else
 __BIONIC_FORTIFY_INLINE
 __printflike(2, 3)
diff --git a/ndk/platforms/android-20/include/stdlib.h b/ndk/platforms/android-20/include/stdlib.h
index 72b554f..9b7e6d1 100644
--- a/ndk/platforms/android-20/include/stdlib.h
+++ b/ndk/platforms/android-20/include/stdlib.h
@@ -54,28 +54,23 @@
 extern char* mkdtemp(char*);
 extern char* mktemp(char*) __warnattr("mktemp possibly used unsafely; consider using mkstemp");
 extern int mkstemp(char*);
+extern int mkstemp64(char*);
 
 extern long strtol(const char *, char **, int);
 extern long long strtoll(const char *, char **, int);
 extern unsigned long strtoul(const char *, char **, int);
 extern unsigned long long strtoull(const char *, char **, int);
-extern double strtod(const char *nptr, char **endptr);
 
 extern int posix_memalign(void **memptr, size_t alignment, size_t size);
 
-static __inline__ float strtof(const char *nptr, char **endptr)
-{
-    return (float)strtod(nptr, endptr);
-}
+extern double atof(const char*);
+extern double strtod(const char*, char**);
+extern float strtof(const char*, char**);
+extern long double strtold(const char*, char**);
 
-extern int atoi(const char *) __purefunc;
-extern long atol(const char *) __purefunc;
-extern long long atoll(const char *) __purefunc;
-
-static __inline__ double atof(const char *nptr)
-{
-    return (strtod(nptr, NULL));
-}
+extern int atoi(const char*) __purefunc;
+extern long atol(const char*) __purefunc;
+extern long long atoll(const char*) __purefunc;
 
 extern int abs(int) __pure2;
 extern long labs(long) __pure2;
@@ -152,6 +147,10 @@
 
 extern lldiv_t   lldiv(long long, long long);
 
+/* BSD compatibility. */
+extern const char* getprogname(void);
+extern void setprogname(const char*);
+
 #if 1 /* MISSING FROM BIONIC - ENABLED FOR STLPort and libstdc++-v3 */
 /* make STLPort happy */
 extern int      mblen(const char *, size_t);
diff --git a/ndk/platforms/android-20/include/string.h b/ndk/platforms/android-20/include/string.h
index 37d22c4..f00e291 100644
--- a/ndk/platforms/android-20/include/string.h
+++ b/ndk/platforms/android-20/include/string.h
@@ -42,13 +42,13 @@
 extern void*  memmove(void *, const void *, size_t);
 extern void*  memset(void *, int, size_t);
 extern void*  memmem(const void *, size_t, const void *, size_t) __purefunc;
-extern void   memswap(void *, void *, size_t);
 
 extern char*  index(const char *, int) __purefunc;
 extern char*  strchr(const char *, int) __purefunc;
 extern char* __strchr_chk(const char *, int, size_t);
 
 extern char*  strrchr(const char *, int) __purefunc;
+extern char* __strrchr_chk(const char *, int, size_t);
 
 extern size_t strlen(const char *) __purefunc;
 extern size_t __strlen_chk(const char *, size_t);
@@ -244,6 +244,7 @@
     return __strlen_chk(s, bos);
 }
 
+#if !defined(HAS_STRCHR)
 __BIONIC_FORTIFY_INLINE
 char* strchr(const char *s, int c) {
     size_t bos = __bos(s);
@@ -262,8 +263,7 @@
 
     return __strchr_chk(s, c, bos);
 }
-
-extern char* __strrchr_chk(const char *, int, size_t);
+#endif
 
 __BIONIC_FORTIFY_INLINE
 char* strrchr(const char *s, int c) {
diff --git a/ndk/platforms/android-20/include/sys/_sigdefs.h b/ndk/platforms/android-20/include/sys/_sigdefs.h
index eadf7b9..44d60d9 100644
--- a/ndk/platforms/android-20/include/sys/_sigdefs.h
+++ b/ndk/platforms/android-20/include/sys/_sigdefs.h
@@ -35,67 +35,41 @@
 #error __BIONIC_SIGDEF not defined
 #endif
 
-__BIONIC_SIGDEF(HUP,1,"Hangup")
-__BIONIC_SIGDEF(INT,2,"Interrupt")
-__BIONIC_SIGDEF(QUIT,3,"Quit")
-__BIONIC_SIGDEF(ILL,4,"Illegal instruction")
-__BIONIC_SIGDEF(TRAP,5,"Trap")
-__BIONIC_SIGDEF(ABRT,6,"Aborted")
-#ifdef __mips__
-__BIONIC_SIGDEF(EMT,7,"EMT")
-#else
-__BIONIC_SIGDEF(BUS,7,"Bus error")
+__BIONIC_SIGDEF(SIGHUP,    "Hangup")
+__BIONIC_SIGDEF(SIGINT,    "Interrupt")
+__BIONIC_SIGDEF(SIGQUIT,   "Quit")
+__BIONIC_SIGDEF(SIGILL,    "Illegal instruction")
+__BIONIC_SIGDEF(SIGTRAP,   "Trap")
+__BIONIC_SIGDEF(SIGABRT,   "Aborted")
+#ifdef SIGEMT
+__BIONIC_SIGDEF(SIGEMT,    "EMT")
 #endif
-__BIONIC_SIGDEF(FPE,8,"Floating point exception")
-__BIONIC_SIGDEF(KILL,9,"Killed")
-#ifdef __mips__
-__BIONIC_SIGDEF(BUS,10,"Bus error")
-#else
-__BIONIC_SIGDEF(USR1,10,"User signal 1")
+__BIONIC_SIGDEF(SIGFPE,    "Floating point exception")
+__BIONIC_SIGDEF(SIGKILL,   "Killed")
+__BIONIC_SIGDEF(SIGBUS,    "Bus error")
+__BIONIC_SIGDEF(SIGSEGV,   "Segmentation fault")
+__BIONIC_SIGDEF(SIGPIPE,   "Broken pipe")
+__BIONIC_SIGDEF(SIGALRM,   "Alarm clock")
+__BIONIC_SIGDEF(SIGTERM,   "Terminated")
+__BIONIC_SIGDEF(SIGUSR1,   "User signal 1")
+__BIONIC_SIGDEF(SIGUSR2,   "User signal 2")
+__BIONIC_SIGDEF(SIGCHLD,   "Child exited")
+__BIONIC_SIGDEF(SIGPWR,    "Power failure")
+__BIONIC_SIGDEF(SIGWINCH,  "Window size changed")
+__BIONIC_SIGDEF(SIGURG,    "Urgent I/O condition")
+__BIONIC_SIGDEF(SIGIO,     "I/O possible")
+__BIONIC_SIGDEF(SIGSTOP,   "Stopped (signal)")
+__BIONIC_SIGDEF(SIGTSTP,   "Stopped")
+__BIONIC_SIGDEF(SIGCONT,   "Continue")
+__BIONIC_SIGDEF(SIGTTIN,   "Stopped (tty input)")
+__BIONIC_SIGDEF(SIGTTOU,   "Stopped (tty output)")
+__BIONIC_SIGDEF(SIGVTALRM, "Virtual timer expired")
+__BIONIC_SIGDEF(SIGPROF,   "Profiling timer expired")
+__BIONIC_SIGDEF(SIGXCPU,   "CPU time limit exceeded")
+__BIONIC_SIGDEF(SIGXFSZ,   "File size limit exceeded")
+#if defined(SIGSTKFLT)
+__BIONIC_SIGDEF(SIGSTKFLT, "Stack fault")
 #endif
-__BIONIC_SIGDEF(SEGV,11,"Segmentation fault")
-#ifdef __mips__
-__BIONIC_SIGDEF(SYS,12,"Bad system call")
-#else
-__BIONIC_SIGDEF(USR2,12,"User signal 2")
-#endif
-__BIONIC_SIGDEF(PIPE,13,"Broken pipe")
-__BIONIC_SIGDEF(ALRM,14,"Alarm clock")
-__BIONIC_SIGDEF(TERM,15,"Terminated")
-#ifdef __mips__
-__BIONIC_SIGDEF(USR1,16,"User signal 1")
-__BIONIC_SIGDEF(USR2,17,"User signal 2")
-__BIONIC_SIGDEF(CHLD,18,"Child exited")
-__BIONIC_SIGDEF(PWR,19,"Power failure")
-__BIONIC_SIGDEF(WINCH,20,"Window size changed")
-__BIONIC_SIGDEF(URG,21,"Urgent I/O condition")
-__BIONIC_SIGDEF(IO,22,"I/O possible")
-__BIONIC_SIGDEF(STOP,23,"Stopped (signal)")
-__BIONIC_SIGDEF(TSTP,24,"Stopped")
-__BIONIC_SIGDEF(CONT,25,"Continue")
-__BIONIC_SIGDEF(TTIN,26,"Stopped (tty input)")
-__BIONIC_SIGDEF(TTOU,27,"Stopped (tty output)")
-__BIONIC_SIGDEF(VTALRM,28,"Virtual timer expired")
-__BIONIC_SIGDEF(PROF,29,"Profiling timer expired")
-__BIONIC_SIGDEF(XCPU,30,"CPU time limit exceeded")
-__BIONIC_SIGDEF(XFSZ,31,"File size limit exceeded")
-#else
-__BIONIC_SIGDEF(STKFLT,16,"Stack fault")
-__BIONIC_SIGDEF(CHLD,17,"Child exited")
-__BIONIC_SIGDEF(CONT,18,"Continue")
-__BIONIC_SIGDEF(STOP,19,"Stopped (signal)")
-__BIONIC_SIGDEF(TSTP,20,"Stopped")
-__BIONIC_SIGDEF(TTIN,21,"Stopped (tty input)")
-__BIONIC_SIGDEF(TTOU,22,"Stopped (tty output)")
-__BIONIC_SIGDEF(URG,23,"Urgent I/O condition")
-__BIONIC_SIGDEF(XCPU,24,"CPU time limit exceeded")
-__BIONIC_SIGDEF(XFSZ,25,"File size limit exceeded")
-__BIONIC_SIGDEF(VTALRM,26,"Virtual timer expired")
-__BIONIC_SIGDEF(PROF,27,"Profiling timer expired")
-__BIONIC_SIGDEF(WINCH,28,"Window size changed")
-__BIONIC_SIGDEF(IO,29,"I/O possible")
-__BIONIC_SIGDEF(PWR,30,"Power failure")
-__BIONIC_SIGDEF(SYS,31,"Bad system call")
-#endif
+__BIONIC_SIGDEF(SIGSYS,    "Bad system call")
 
 #undef __BIONIC_SIGDEF
diff --git a/ndk/platforms/android-20/include/sys/_system_properties.h b/ndk/platforms/android-20/include/sys/_system_properties.h
index 5eee7f0..5a681df 100644
--- a/ndk/platforms/android-20/include/sys/_system_properties.h
+++ b/ndk/platforms/android-20/include/sys/_system_properties.h
@@ -139,6 +139,14 @@
         void (*propfn)(const prop_info *pi, void *cookie),
         void *cookie);
 
+/* Initialize the system properties area in read only mode.
+ * Should be done by all processes that need to read system
+ * properties.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+int __system_properties_init();
+
 __END_DECLS
 
 #endif
diff --git a/ndk/platforms/android-20/include/sys/_types.h b/ndk/platforms/android-20/include/sys/_types.h
deleted file mode 100644
index 6bf9c1c..0000000
--- a/ndk/platforms/android-20/include/sys/_types.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*	$OpenBSD: _types.h,v 1.1 2006/01/06 18:53:05 millert Exp $	*/
-
-/*-
- * Copyright (c) 1990, 1993
- *	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.
- *
- *	@(#)types.h	8.3 (Berkeley) 1/5/94
- */
-
-#ifndef _SYS__TYPES_H_
-#define _SYS__TYPES_H_
-
-typedef __signed char __int8_t;
-typedef unsigned char __uint8_t;
-typedef short __int16_t;
-typedef unsigned short __uint16_t;
-typedef int __int32_t;
-typedef unsigned int __uint32_t;
-#if __LP64__
-typedef long __int64_t;
-typedef unsigned long __uint64_t;
-#else
-typedef long long __int64_t;
-typedef unsigned long long __uint64_t;
-#endif
-
-#if __LP64__
-typedef long __intptr_t;
-typedef unsigned long __uintptr_t;
-#else
-typedef int __intptr_t;
-typedef unsigned int __uintptr_t;
-#endif
-
-#if __LP64__
-typedef long __time_t;
-#else
-typedef int __time_t; /* Historical accident. */
-#endif
-
-typedef int __timer_t;
-
-typedef int __clockid_t;
-
-#ifndef __cplusplus
-typedef int __wchar_t;
-#endif
-
-typedef double __double_t;
-typedef float __float_t;
-
-typedef __builtin_va_list __va_list;
-
-typedef	unsigned long	__cpuid_t;	/* CPU id */
-typedef	__uint32_t	__fixpt_t;	/* fixed point number */
-typedef	__uint32_t	__gid_t;	/* group id */
-typedef	__uint32_t	__id_t;		/* may contain pid, uid or gid */
-typedef __uint32_t	__in_addr_t;	/* base type for internet address */
-typedef __uint16_t	__in_port_t;	/* IP port type */
-typedef	__uint32_t	__ino_t;	/* inode number */
-typedef	long		__key_t;	/* IPC key (for Sys V IPC) */
-typedef	__uint32_t	__mode_t;	/* permissions */
-typedef	__uint32_t	__nlink_t;	/* link count */
-typedef	__int32_t	__pid_t;	/* process id */
-typedef __uint64_t	__rlim_t;	/* resource limit */
-typedef __uint16_t	__sa_family_t;	/* sockaddr address family type */
-typedef	__int32_t	__segsz_t;	/* segment size */
-typedef __uint32_t	__socklen_t;	/* length type for network syscalls */
-typedef	__int32_t	__swblk_t;	/* swap offset */
-typedef	__uint32_t	__uid_t;	/* user id */
-typedef	__uint32_t	__useconds_t;	/* microseconds */
-typedef	__int32_t	__suseconds_t;	/* microseconds (signed) */
-
-/*
- * mbstate_t is an opaque object to keep conversion state, during multibyte
- * stream conversions. The content must not be referenced by user programs.
- */
-typedef union {
-	char __mbstate8[128];
-	__int64_t __mbstateL;			/* for alignment */
-} __mbstate_t;
-
-#endif /* !_SYS__TYPES_H_ */
diff --git a/ndk/platforms/android-20/include/sys/exec_elf.h b/ndk/platforms/android-20/include/sys/exec_elf.h
deleted file mode 100644
index d14c596..0000000
--- a/ndk/platforms/android-20/include/sys/exec_elf.h
+++ /dev/null
@@ -1,1287 +0,0 @@
-/*	$NetBSD: exec_elf.h,v 1.131 2013/10/29 00:22:59 christos Exp $	*/
-
-/*-
- * Copyright (c) 1994 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Christos Zoulas.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
- */
-
-#ifndef _SYS_EXEC_ELF_H_
-#define _SYS_EXEC_ELF_H_
-
-/*
- * The current ELF ABI specification is available at:
- *	http://www.sco.com/developers/gabi/
- *
- * Current header definitions are in:
- *	http://www.sco.com/developers/gabi/latest/ch4.eheader.html
- */
-
-#if defined(_KERNEL) || defined(_STANDALONE)
-#include <sys/types.h>
-#else
-#include <inttypes.h>
-#endif /* _KERNEL || _STANDALONE */
-
-#if HAVE_NBTOOL_CONFIG_H
-#include <nbinclude/machine/elf_machdep.h>
-#else
-#include <machine/elf_machdep.h>
-#endif
-
-typedef uint8_t		Elf_Byte;
-
-typedef uint32_t	Elf32_Addr;
-#define ELF32_FSZ_ADDR	4
-typedef uint32_t	Elf32_Off;
-typedef int32_t		Elf32_SOff;
-#define ELF32_FSZ_OFF	4
-typedef int32_t		Elf32_Sword;
-#define ELF32_FSZ_SWORD 4
-typedef uint32_t	Elf32_Word;
-#define ELF32_FSZ_WORD	4
-typedef uint16_t	Elf32_Half;
-#define ELF32_FSZ_HALF	2
-typedef uint64_t	Elf32_Lword;
-#define ELF32_FSZ_LWORD 8
-
-typedef uint64_t	Elf64_Addr;
-#define ELF64_FSZ_ADDR	8
-typedef uint64_t	Elf64_Off;
-typedef int64_t		Elf64_SOff;
-#define ELF64_FSZ_OFF	8
-typedef int32_t		Elf64_Shalf;
-#define ELF64_FSZ_SHALF 4
-
-typedef int32_t		Elf64_Sword;
-#define ELF64_FSZ_SWORD 4
-typedef uint32_t	Elf64_Word;
-#define ELF64_FSZ_WORD	4
-
-typedef int64_t		Elf64_Sxword;
-#define ELF64_FSZ_SXWORD 8
-typedef uint64_t	Elf64_Xword;
-#define ELF64_FSZ_XWORD 8
-typedef uint64_t	Elf64_Lword;
-#define ELF64_FSZ_LWORD 8
-typedef uint16_t	Elf64_Half;
-#define ELF64_FSZ_HALF 2
-
-/*
- * ELF Header
- */
-#define ELF_NIDENT	16
-
-typedef struct {
-	unsigned char	e_ident[ELF_NIDENT];	/* Id bytes */
-	Elf32_Half	e_type;			/* file type */
-	Elf32_Half	e_machine;		/* machine type */
-	Elf32_Word	e_version;		/* version number */
-	Elf32_Addr	e_entry;		/* entry point */
-	Elf32_Off	e_phoff;		/* Program hdr offset */
-	Elf32_Off	e_shoff;		/* Section hdr offset */
-	Elf32_Word	e_flags;		/* Processor flags */
-	Elf32_Half	e_ehsize;		/* sizeof ehdr */
-	Elf32_Half	e_phentsize;		/* Program header entry size */
-	Elf32_Half	e_phnum;		/* Number of program headers */
-	Elf32_Half	e_shentsize;		/* Section header entry size */
-	Elf32_Half	e_shnum;		/* Number of section headers */
-	Elf32_Half	e_shstrndx;		/* String table index */
-} Elf32_Ehdr;
-
-typedef struct {
-	unsigned char	e_ident[ELF_NIDENT];	/* Id bytes */
-	Elf64_Half	e_type;			/* file type */
-	Elf64_Half	e_machine;		/* machine type */
-	Elf64_Word	e_version;		/* version number */
-	Elf64_Addr	e_entry;		/* entry point */
-	Elf64_Off	e_phoff;		/* Program hdr offset */
-	Elf64_Off	e_shoff;		/* Section hdr offset */
-	Elf64_Word	e_flags;		/* Processor flags */
-	Elf64_Half	e_ehsize;		/* sizeof ehdr */
-	Elf64_Half	e_phentsize;		/* Program header entry size */
-	Elf64_Half	e_phnum;		/* Number of program headers */
-	Elf64_Half	e_shentsize;		/* Section header entry size */
-	Elf64_Half	e_shnum;		/* Number of section headers */
-	Elf64_Half	e_shstrndx;		/* String table index */
-} Elf64_Ehdr;
-
-/* e_ident offsets */
-#define EI_MAG0		0	/* '\177' */
-#define EI_MAG1		1	/* 'E'	  */
-#define EI_MAG2		2	/* 'L'	  */
-#define EI_MAG3		3	/* 'F'	  */
-#define EI_CLASS	4	/* File class */
-#define EI_DATA		5	/* Data encoding */
-#define EI_VERSION	6	/* File version */
-#define EI_OSABI	7	/* Operating system/ABI identification */
-#define EI_ABIVERSION	8	/* ABI version */
-#define EI_PAD		9	/* Start of padding bytes up to EI_NIDENT*/
-#define EI_NIDENT	16	/* First non-ident header byte */
-
-/* e_ident[EI_MAG0,EI_MAG3] */
-#define ELFMAG0		0x7f
-#define ELFMAG1		'E'
-#define ELFMAG2		'L'
-#define ELFMAG3		'F'
-#define ELFMAG		"\177ELF"
-#define SELFMAG		4
-
-/* e_ident[EI_CLASS] */
-#define ELFCLASSNONE	0	/* Invalid class */
-#define ELFCLASS32	1	/* 32-bit objects */
-#define ELFCLASS64	2	/* 64-bit objects */
-#define ELFCLASSNUM	3
-
-/* e_ident[EI_DATA] */
-#define ELFDATANONE	0	/* Invalid data encoding */
-#define ELFDATA2LSB	1	/* 2's complement values, LSB first */
-#define ELFDATA2MSB	2	/* 2's complement values, MSB first */
-
-/* e_ident[EI_VERSION] */
-#define EV_NONE		0	/* Invalid version */
-#define EV_CURRENT	1	/* Current version */
-#define EV_NUM		2
-
-/* e_ident[EI_OSABI] */
-#define ELFOSABI_SYSV		0	/* UNIX System V ABI */
-#define ELFOSABI_HPUX		1	/* HP-UX operating system */
-#define ELFOSABI_NETBSD		2	/* NetBSD */
-#define ELFOSABI_LINUX		3	/* GNU/Linux */
-#define ELFOSABI_HURD		4	/* GNU/Hurd */
-#define ELFOSABI_86OPEN		5	/* 86Open */
-#define ELFOSABI_SOLARIS	6	/* Solaris */
-#define ELFOSABI_MONTEREY	7	/* Monterey */
-#define ELFOSABI_IRIX		8	/* IRIX */
-#define ELFOSABI_FREEBSD	9	/* FreeBSD */
-#define ELFOSABI_TRU64		10	/* TRU64 UNIX */
-#define ELFOSABI_MODESTO	11	/* Novell Modesto */
-#define ELFOSABI_OPENBSD	12	/* OpenBSD */
-#define ELFOSABI_OPENVMS	13	/* OpenVMS */
-#define ELFOSABI_NSK		14	/* HP Non-Stop Kernel */
-#define ELFOSABI_AROS		15	/* Amiga Research OS */
-/* Unofficial OSABIs follow */
-#define ELFOSABI_ARM		97	/* ARM */
-#define ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
-
-#define ELFOSABI_NONE		ELFOSABI_SYSV
-#define ELFOSABI_AIX		ELFOSABI_MONTEREY
-
-/* e_type */
-#define ET_NONE		0	/* No file type */
-#define ET_REL		1	/* Relocatable file */
-#define ET_EXEC		2	/* Executable file */
-#define ET_DYN		3	/* Shared object file */
-#define ET_CORE		4	/* Core file */
-#define ET_NUM		5
-
-#define ET_LOOS		0xfe00	/* Operating system specific range */
-#define ET_HIOS		0xfeff
-#define ET_LOPROC	0xff00	/* Processor-specific range */
-#define ET_HIPROC	0xffff
-
-/* e_machine */
-#define EM_NONE		0	/* No machine */
-#define EM_M32		1	/* AT&T WE 32100 */
-#define EM_SPARC	2	/* SPARC */
-#define EM_386		3	/* Intel 80386 */
-#define EM_68K		4	/* Motorola 68000 */
-#define EM_88K		5	/* Motorola 88000 */
-#define EM_486		6	/* Intel 80486 */
-#define EM_860		7	/* Intel 80860 */
-#define EM_MIPS		8	/* MIPS I Architecture */
-#define EM_S370		9	/* Amdahl UTS on System/370 */
-#define EM_MIPS_RS3_LE	10	/* MIPS RS3000 Little-endian */
-			/* 11-14 - Reserved */
-#define EM_RS6000	11	/* IBM RS/6000 XXX reserved */
-#define EM_PARISC	15	/* Hewlett-Packard PA-RISC */
-#define EM_NCUBE	16	/* NCube XXX reserved */
-#define EM_VPP500	17	/* Fujitsu VPP500 */
-#define EM_SPARC32PLUS	18	/* Enhanced instruction set SPARC */
-#define EM_960		19	/* Intel 80960 */
-#define EM_PPC		20	/* PowerPC */
-#define EM_PPC64	21	/* 64-bit PowerPC */
-			/* 22-35 - Reserved */
-#define EM_S390		22	/* System/390 XXX reserved */
-#define EM_V800		36	/* NEC V800 */
-#define EM_FR20		37	/* Fujitsu FR20 */
-#define EM_RH32		38	/* TRW RH-32 */
-#define EM_RCE		39	/* Motorola RCE */
-#define EM_ARM		40	/* Advanced RISC Machines ARM */
-#define EM_ALPHA	41	/* DIGITAL Alpha */
-#define EM_SH		42	/* Hitachi Super-H */
-#define EM_SPARCV9	43	/* SPARC Version 9 */
-#define EM_TRICORE	44	/* Siemens Tricore */
-#define EM_ARC		45	/* Argonaut RISC Core */
-#define EM_H8_300	46	/* Hitachi H8/300 */
-#define EM_H8_300H	47	/* Hitachi H8/300H */
-#define EM_H8S		48	/* Hitachi H8S */
-#define EM_H8_500	49	/* Hitachi H8/500 */
-#define EM_IA_64	50	/* Intel Merced Processor */
-#define EM_MIPS_X	51	/* Stanford MIPS-X */
-#define EM_COLDFIRE	52	/* Motorola Coldfire */
-#define EM_68HC12	53	/* Motorola MC68HC12 */
-#define EM_MMA		54	/* Fujitsu MMA Multimedia Accelerator */
-#define EM_PCP		55	/* Siemens PCP */
-#define EM_NCPU		56	/* Sony nCPU embedded RISC processor */
-#define EM_NDR1		57	/* Denso NDR1 microprocessor */
-#define EM_STARCORE	58	/* Motorola Star*Core processor */
-#define EM_ME16		59	/* Toyota ME16 processor */
-#define EM_ST100	60	/* STMicroelectronics ST100 processor */
-#define EM_TINYJ	61	/* Advanced Logic Corp. TinyJ embedded family processor */
-#define EM_X86_64	62	/* AMD x86-64 architecture */
-#define EM_PDSP		63	/* Sony DSP Processor */
-#define EM_PDP10	64	/* Digital Equipment Corp. PDP-10 */
-#define EM_PDP11	65	/* Digital Equipment Corp. PDP-11 */
-#define EM_FX66		66	/* Siemens FX66 microcontroller */
-#define EM_ST9PLUS	67	/* STMicroelectronics ST9+ 8/16 bit microcontroller */
-#define EM_ST7		68	/* STMicroelectronics ST7 8-bit microcontroller */
-#define EM_68HC16	69	/* Motorola MC68HC16 Microcontroller */
-#define EM_68HC11	70	/* Motorola MC68HC11 Microcontroller */
-#define EM_68HC08	71	/* Motorola MC68HC08 Microcontroller */
-#define EM_68HC05	72	/* Motorola MC68HC05 Microcontroller */
-#define EM_SVX		73	/* Silicon Graphics SVx */
-#define EM_ST19		74	/* STMicroelectronics ST19 8-bit CPU */
-#define EM_VAX		75	/* Digital VAX */
-#define EM_CRIS		76	/* Axis Communications 32-bit embedded processor */
-#define EM_JAVELIN	77	/* Infineon Technologies 32-bit embedded CPU */
-#define EM_FIREPATH	78	/* Element 14 64-bit DSP processor */
-#define EM_ZSP		79	/* LSI Logic's 16-bit DSP processor */
-#define EM_MMIX		80	/* Donald Knuth's educational 64-bit processor */
-#define EM_HUANY	81	/* Harvard's machine-independent format */
-#define EM_PRISM	82	/* SiTera Prism */
-#define EM_AVR		83	/* Atmel AVR 8-bit microcontroller */
-#define EM_FR30		84	/* Fujitsu FR30 */
-#define EM_D10V		85	/* Mitsubishi D10V */
-#define EM_D30V		86	/* Mitsubishi D30V */
-#define EM_V850		87	/* NEC v850 */
-#define EM_M32R		88	/* Mitsubishi M32R */
-#define EM_MN10300	89	/* Matsushita MN10300 */
-#define EM_MN10200	90	/* Matsushita MN10200 */
-#define EM_PJ		91	/* picoJava */
-#define EM_OPENRISC	92	/* OpenRISC 32-bit embedded processor */
-#define EM_ARC_A5	93	/* ARC Cores Tangent-A5 */
-#define EM_XTENSA	94	/* Tensilica Xtensa Architecture */
-#define EM_VIDEOCORE	95	/* Alphamosaic VideoCore processor */
-#define EM_TMM_GPP	96	/* Thompson Multimedia General Purpose Processor */
-#define EM_NS32K	97	/* National Semiconductor 32000 series */
-#define EM_TPC		98	/* Tenor Network TPC processor */
-#define EM_SNP1K	99	/* Trebia SNP 1000 processor */
-#define EM_ST200	100	/* STMicroelectronics ST200 microcontroller */
-#define EM_IP2K		101	/* Ubicom IP2xxx microcontroller family */
-#define EM_MAX		102	/* MAX processor */
-#define EM_CR		103	/* National Semiconductor CompactRISC micorprocessor */
-#define EM_F2MC16	104	/* Fujitsu F2MC16 */
-#define EM_MSP430	105	/* Texas Instruments MSP430 */
-#define EM_BLACKFIN	106	/* Analog Devices Blackfin DSP */
-#define EM_SE_C33	107	/* Seiko Epson S1C33 family */
-#define EM_SEP		108	/* Sharp embedded microprocessor */
-#define EM_ARCA		109	/* Arca RISC microprocessor */
-#define EM_UNICORE	110	/* UNICORE from PKU-Unity Ltd. and MPRC Peking University */
-#define EM_AARCH64	183	/* AArch64 64-bit ARM microprocessor */
-
-/* Unofficial machine types follow */
-#define EM_AVR32	6317	/* used by NetBSD/avr32 */
-#define EM_ALPHA_EXP	36902	/* used by NetBSD/alpha; obsolete */
-#define EM_NUM		36903
-
-/*
- * Program Header
- */
-typedef struct {
-	Elf32_Word	p_type;		/* entry type */
-	Elf32_Off	p_offset;	/* offset */
-	Elf32_Addr	p_vaddr;	/* virtual address */
-	Elf32_Addr	p_paddr;	/* physical address */
-	Elf32_Word	p_filesz;	/* file size */
-	Elf32_Word	p_memsz;	/* memory size */
-	Elf32_Word	p_flags;	/* flags */
-	Elf32_Word	p_align;	/* memory & file alignment */
-} Elf32_Phdr;
-
-typedef struct {
-	Elf64_Word	p_type;		/* entry type */
-	Elf64_Word	p_flags;	/* flags */
-	Elf64_Off	p_offset;	/* offset */
-	Elf64_Addr	p_vaddr;	/* virtual address */
-	Elf64_Addr	p_paddr;	/* physical address */
-	Elf64_Xword	p_filesz;	/* file size */
-	Elf64_Xword	p_memsz;	/* memory size */
-	Elf64_Xword	p_align;	/* memory & file alignment */
-} Elf64_Phdr;
-
-/* p_type */
-#define PT_NULL		0		/* Program header table entry unused */
-#define PT_LOAD		1		/* Loadable program segment */
-#define PT_DYNAMIC	2		/* Dynamic linking information */
-#define PT_INTERP	3		/* Program interpreter */
-#define PT_NOTE		4		/* Auxiliary information */
-#define PT_SHLIB	5		/* Reserved, unspecified semantics */
-#define PT_PHDR		6		/* Entry for header table itself */
-#define PT_TLS		7		/* TLS initialisation image */
-#define PT_NUM		8
-
-#define PT_LOOS		0x60000000	/* OS-specific range */
-
-/* GNU-specific */
-#define PT_GNU_EH_FRAME 0x6474e550	/* EH frame segment */
-#define PT_GNU_STACK	0x6474e551	/* Indicate executable stack */
-#define PT_GNU_RELRO	0x6474e552	/* Make read-only after relocation */
-
-#define PT_HIOS		0x6fffffff
-#define PT_LOPROC	0x70000000	/* Processor-specific range */
-#define PT_HIPROC	0x7fffffff
-
-#define PT_MIPS_REGINFO 0x70000000
-
-/* p_flags */
-#define PF_R		0x4		/* Segment is readable */
-#define PF_W		0x2		/* Segment is writable */
-#define PF_X		0x1		/* Segment is executable */
-
-#define PF_MASKOS	0x0ff00000	/* Operating system specific values */
-#define PF_MASKPROC	0xf0000000	/* Processor-specific values */
-
-/* Extended program header index. */
-#define PN_XNUM		0xffff
-
-/*
- * Section Headers
- */
-typedef struct {
-	Elf32_Word	sh_name;	/* section name (.shstrtab index) */
-	Elf32_Word	sh_type;	/* section type */
-	Elf32_Word	sh_flags;	/* section flags */
-	Elf32_Addr	sh_addr;	/* virtual address */
-	Elf32_Off	sh_offset;	/* file offset */
-	Elf32_Word	sh_size;	/* section size */
-	Elf32_Word	sh_link;	/* link to another */
-	Elf32_Word	sh_info;	/* misc info */
-	Elf32_Word	sh_addralign;	/* memory alignment */
-	Elf32_Word	sh_entsize;	/* table entry size */
-} Elf32_Shdr;
-
-typedef struct {
-	Elf64_Word	sh_name;	/* section name (.shstrtab index) */
-	Elf64_Word	sh_type;	/* section type */
-	Elf64_Xword	sh_flags;	/* section flags */
-	Elf64_Addr	sh_addr;	/* virtual address */
-	Elf64_Off	sh_offset;	/* file offset */
-	Elf64_Xword	sh_size;	/* section size */
-	Elf64_Word	sh_link;	/* link to another */
-	Elf64_Word	sh_info;	/* misc info */
-	Elf64_Xword	sh_addralign;	/* memory alignment */
-	Elf64_Xword	sh_entsize;	/* table entry size */
-} Elf64_Shdr;
-
-/* sh_type */
-#define SHT_NULL	      0		/* Section header table entry unused */
-#define SHT_PROGBITS	      1		/* Program information */
-#define SHT_SYMTAB	      2		/* Symbol table */
-#define SHT_STRTAB	      3		/* String table */
-#define SHT_RELA	      4		/* Relocation information w/ addend */
-#define SHT_HASH	      5		/* Symbol hash table */
-#define SHT_DYNAMIC	      6		/* Dynamic linking information */
-#define SHT_NOTE	      7		/* Auxiliary information */
-#define SHT_NOBITS	      8		/* No space allocated in file image */
-#define SHT_REL		      9		/* Relocation information w/o addend */
-#define SHT_SHLIB	     10		/* Reserved, unspecified semantics */
-#define SHT_DYNSYM	     11		/* Symbol table for dynamic linker */
-#define SHT_INIT_ARRAY	     14		/* Initialization function pointers */
-#define SHT_FINI_ARRAY	     15		/* Termination function pointers */
-#define SHT_PREINIT_ARRAY    16		/* Pre-initialization function ptrs */
-#define SHT_GROUP	     17		/* Section group */
-#define SHT_SYMTAB_SHNDX     18		/* Section indexes (see SHN_XINDEX) */
-#define SHT_NUM		     19
-
-#define SHT_LOOS	     0x60000000 /* Operating system specific range */
-#define SHT_GNU_HASH	     0x6ffffff6 /* GNU style symbol hash table */
-#define SHT_SUNW_move	     0x6ffffffa
-#define SHT_SUNW_syminfo     0x6ffffffc
-#define SHT_SUNW_verdef	     0x6ffffffd /* Versions defined by file */
-#define SHT_GNU_verdef	     SHT_SUNW_verdef
-#define SHT_SUNW_verneed     0x6ffffffe /* Versions needed by file */
-#define SHT_GNU_verneed	     SHT_SUNW_verneed
-#define SHT_SUNW_versym	     0x6fffffff /* Symbol versions */
-#define SHT_GNU_versym	     SHT_SUNW_versym
-#define SHT_HIOS	     0x6fffffff
-#define SHT_LOPROC	     0x70000000 /* Processor-specific range */
-#define SHT_AMD64_UNWIND     0x70000001 /* unwind information */
-#define SHT_ARM_EXIDX	     0x70000001	/* exception index table */
-#define SHT_ARM_PREEMPTMAP   0x70000002 /* BPABI DLL dynamic linking
-					 * pre-emption map */
-#define SHT_ARM_ATTRIBUTES   0x70000003 /* Object file compatibility
-					 * attributes */
-#define SHT_ARM_DEBUGOVERLAY 0x70000004 /* See DBGOVL for details */
-#define SHT_ARM_OVERLAYSECTION 0x70000005
-#define SHT_HIPROC	     0x7fffffff
-#define SHT_LOUSER	     0x80000000 /* Application-specific range */
-#define SHT_HIUSER	     0xffffffff
-
-/* sh_flags */
-#define SHF_WRITE	     0x00000001 /* Contains writable data */
-#define SHF_ALLOC	     0x00000002 /* Occupies memory */
-#define SHF_EXECINSTR	     0x00000004 /* Contains executable insns */
-#define SHF_MERGE	     0x00000010 /* Might be merged */
-#define SHF_STRINGS	     0x00000020 /* Contains nul terminated strings */
-#define SHF_INFO_LINK	     0x00000040 /* "sh_info" contains SHT index */
-#define SHF_LINK_ORDER	     0x00000080 /* Preserve order after combining */
-#define SHF_OS_NONCONFORMING 0x00000100 /* OS specific handling required */
-#define SHF_GROUP	     0x00000200 /* Is member of a group */
-#define SHF_TLS		     0x00000400 /* Holds thread-local data */
-#define SHF_MASKOS	     0x0ff00000 /* Operating system specific values */
-#define SHF_MASKPROC	     0xf0000000 /* Processor-specific values */
-#define SHF_ORDERED	     0x40000000 /* Ordering requirement (Solaris) */
-#define SHF_EXCLUDE	     0x80000000 /* Excluded unless unles ref/alloc
-					   (Solaris).*/
-/*
- * Symbol Table
- */
-typedef struct {
-	Elf32_Word	st_name;	/* Symbol name (.strtab index) */
-	Elf32_Word	st_value;	/* value of symbol */
-	Elf32_Word	st_size;	/* size of symbol */
-	Elf_Byte	st_info;	/* type / binding attrs */
-	Elf_Byte	st_other;	/* unused */
-	Elf32_Half	st_shndx;	/* section index of symbol */
-} Elf32_Sym;
-
-typedef struct {
-	Elf64_Word	st_name;	/* Symbol name (.strtab index) */
-	Elf_Byte	st_info;	/* type / binding attrs */
-	Elf_Byte	st_other;	/* unused */
-	Elf64_Half	st_shndx;	/* section index of symbol */
-	Elf64_Addr	st_value;	/* value of symbol */
-	Elf64_Xword	st_size;	/* size of symbol */
-} Elf64_Sym;
-
-/* Symbol Table index of the undefined symbol */
-#define ELF_SYM_UNDEFINED	0
-
-#define STN_UNDEF		0	/* undefined index */
-
-/* st_info: Symbol Bindings */
-#define STB_LOCAL		0	/* local symbol */
-#define STB_GLOBAL		1	/* global symbol */
-#define STB_WEAK		2	/* weakly defined global symbol */
-#define STB_NUM			3
-
-#define STB_LOOS		10	/* Operating system specific range */
-#define STB_HIOS		12
-#define STB_LOPROC		13	/* Processor-specific range */
-#define STB_HIPROC		15
-
-/* st_info: Symbol Types */
-#define STT_NOTYPE		0	/* Type not specified */
-#define STT_OBJECT		1	/* Associated with a data object */
-#define STT_FUNC		2	/* Associated with a function */
-#define STT_SECTION		3	/* Associated with a section */
-#define STT_FILE		4	/* Associated with a file name */
-#define STT_COMMON		5	/* Uninitialised common block */
-#define STT_TLS			6	/* Thread local data object */
-#define STT_NUM			7
-
-#define STT_LOOS		10	/* Operating system specific range */
-#define STT_HIOS		12
-#define STT_LOPROC		13	/* Processor-specific range */
-#define STT_HIPROC		15
-
-/* st_other: Visibility Types */
-#define STV_DEFAULT		0	/* use binding type */
-#define STV_INTERNAL		1	/* not referenced from outside */
-#define STV_HIDDEN		2	/* not visible, may be used via ptr */
-#define STV_PROTECTED		3	/* visible, not preemptible */
-#define STV_EXPORTED		4
-#define STV_SINGLETON		5
-#define STV_ELIMINATE		6
-
-/* st_info/st_other utility macros */
-#define ELF_ST_BIND(info)		((uint32_t)(info) >> 4)
-#define ELF_ST_TYPE(info)		((uint32_t)(info) & 0xf)
-#define ELF_ST_INFO(bind,type)		((Elf_Byte)(((bind) << 4) | \
-					 ((type) & 0xf)))
-#define ELF_ST_VISIBILITY(other)	((uint32_t)(other) & 3)
-
-/*
- * Special section indexes
- */
-#define SHN_UNDEF	0		/* Undefined section */
-
-#define SHN_LORESERVE	0xff00		/* Reserved range */
-#define SHN_ABS		0xfff1		/*  Absolute symbols */
-#define SHN_COMMON	0xfff2		/*  Common symbols */
-#define SHN_XINDEX	0xffff		/* Escape -- index stored elsewhere */
-#define SHN_HIRESERVE	0xffff
-
-#define SHN_LOPROC	0xff00		/* Processor-specific range */
-#define SHN_HIPROC	0xff1f
-#define SHN_LOOS	0xff20		/* Operating system specific range */
-#define SHN_HIOS	0xff3f
-
-#define SHN_MIPS_ACOMMON 0xff00
-#define SHN_MIPS_TEXT	0xff01
-#define SHN_MIPS_DATA	0xff02
-#define SHN_MIPS_SCOMMON 0xff03
-
-/*
- * Relocation Entries
- */
-typedef struct {
-	Elf32_Word	r_offset;	/* where to do it */
-	Elf32_Word	r_info;		/* index & type of relocation */
-} Elf32_Rel;
-
-typedef struct {
-	Elf32_Word	r_offset;	/* where to do it */
-	Elf32_Word	r_info;		/* index & type of relocation */
-	Elf32_Sword	r_addend;	/* adjustment value */
-} Elf32_Rela;
-
-/* r_info utility macros */
-#define ELF32_R_SYM(info)	((info) >> 8)
-#define ELF32_R_TYPE(info)	((info) & 0xff)
-#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
-
-typedef struct {
-	Elf64_Addr	r_offset;	/* where to do it */
-	Elf64_Xword	r_info;		/* index & type of relocation */
-} Elf64_Rel;
-
-typedef struct {
-	Elf64_Addr	r_offset;	/* where to do it */
-	Elf64_Xword	r_info;		/* index & type of relocation */
-	Elf64_Sxword	r_addend;	/* adjustment value */
-} Elf64_Rela;
-
-/* r_info utility macros */
-#if defined(__mips__)
-#if defined(__MIPSEL__)
-#define ELF64_R_SYM(info)	(((info) >> 0) & 0xffffffff)
-#define ELF64_R_SSYM(info)	(((info) >> 32) & 0xff)
-#define ELF64_R_TYPE3(info)	(((info) >> 40) & 0xff)
-#define ELF64_R_TYPE2(info)	(((info) >> 48) & 0xff)
-#define ELF64_R_TYPE(info)	(((info) >> 56) & 0xff)
-#define ELF64_R_INFO(sym,ssym,type,type2,type3)	\
-        (((type) << 56) + ((type2) << 48) + ((type3) << 40) + ((ssym) << 32) + (sym))
-#else
-#define ELF64_R_SYM(info)	(((info) >> 32) & 0xffffffff)
-#define ELF64_R_SSYM(info)	(((info) >> 24) & 0xff)
-#define ELF64_R_TYPE3(info)	(((info) >> 16) & 0xff)
-#define ELF64_R_TYPE2(info)	(((info) >> 8) & 0xff)
-#define ELF64_R_TYPE(info)	(((info) >> 0) & 0xff)
-#define ELF64_R_INFO(sym,ssym,type,type2,type3)	\
-        (((sym) << 32) + ((ssym) << 24) + ((type3) << 16) + ((type2) << 8) + (type))
-#endif
-#else
-#define ELF64_R_SYM(info)	((info) >> 32)
-#define ELF64_R_TYPE(info)	((info) & 0xffffffff)
-#define ELF64_R_INFO(sym,type)	(((sym) << 32) + (type))
-#endif
-
-/*
- * Move entries
- */
-typedef struct {
-	Elf32_Lword	m_value;	/* symbol value */
-	Elf32_Word	m_info;		/* size + index */
-	Elf32_Word	m_poffset;	/* symbol offset */
-	Elf32_Half	m_repeat;	/* repeat count */
-	Elf32_Half	m_stride;	/* stride info */
-} Elf32_Move;
-
-#define ELF32_M_SYM(info)	((info) >> 8)
-#define ELF32_M_SIZE(info)	((info) & 0xff)
-#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
-
-typedef struct {
-	Elf64_Lword	m_value;	/* symbol value */
-	Elf64_Xword	m_info;		/* size + index */
-	Elf64_Xword	m_poffset;	/* symbol offset */
-	Elf64_Word	m_repeat;	/* repeat count */
-	Elf64_Word	m_stride;	/* stride info */
-} Elf64_Move;
-
-#define ELF64_M_SYM(info)	((info) >> 8)
-#define ELF64_M_SIZE(info)	((info) & 0xff)
-#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
-
-/*
- * Hardware/software capabilities entry
- */
-typedef struct {
-	Elf32_Word		c_tag;	/* entry tag value */
-	union {
-		Elf32_Addr	c_ptr;
-		Elf32_Word	c_val;
-	} c_un;
-} Elf32_Cap;
-
-typedef struct {
-	Elf64_Xword		c_tag;	/* entry tag value */
-	union {
-		Elf64_Addr	c_ptr;
-		Elf64_Xword	c_val;
-	} c_un;
-} Elf64_Cap;
-
-/*
- * Dynamic Section structure array
- */
-typedef struct {
-	Elf32_Word		d_tag;	/* entry tag value */
-	union {
-		Elf32_Addr	d_ptr;
-		Elf32_Word	d_val;
-	} d_un;
-} Elf32_Dyn;
-
-typedef struct {
-	Elf64_Xword		d_tag;	/* entry tag value */
-	union {
-		Elf64_Addr	d_ptr;
-		Elf64_Xword	d_val;
-	} d_un;
-} Elf64_Dyn;
-
-/* d_tag */
-#define DT_NULL		0	/* Marks end of dynamic array */
-#define DT_NEEDED	1	/* Name of needed library (DT_STRTAB offset) */
-#define DT_PLTRELSZ	2	/* Size, in bytes, of relocations in PLT */
-#define DT_PLTGOT	3	/* Address of PLT and/or GOT */
-#define DT_HASH		4	/* Address of symbol hash table */
-#define DT_STRTAB	5	/* Address of string table */
-#define DT_SYMTAB	6	/* Address of symbol table */
-#define DT_RELA		7	/* Address of Rela relocation table */
-#define DT_RELASZ	8	/* Size, in bytes, of DT_RELA table */
-#define DT_RELAENT	9	/* Size, in bytes, of one DT_RELA entry */
-#define DT_STRSZ	10	/* Size, in bytes, of DT_STRTAB table */
-#define DT_SYMENT	11	/* Size, in bytes, of one DT_SYMTAB entry */
-#define DT_INIT		12	/* Address of initialization function */
-#define DT_FINI		13	/* Address of termination function */
-#define DT_SONAME	14	/* Shared object name (DT_STRTAB offset) */
-#define DT_RPATH	15	/* Library search path (DT_STRTAB offset) */
-#define DT_SYMBOLIC	16	/* Start symbol search within local object */
-#define DT_REL		17	/* Address of Rel relocation table */
-#define DT_RELSZ	18	/* Size, in bytes, of DT_REL table */
-#define DT_RELENT	19	/* Size, in bytes, of one DT_REL entry */
-#define DT_PLTREL	20	/* Type of PLT relocation entries */
-#define DT_DEBUG	21	/* Used for debugging; unspecified */
-#define DT_TEXTREL	22	/* Relocations might modify non-writable seg */
-#define DT_JMPREL	23	/* Address of relocations associated with PLT */
-#define DT_BIND_NOW	24	/* Process all relocations at load-time */
-#define DT_INIT_ARRAY	25	/* Address of initialization function array */
-#define DT_FINI_ARRAY	26	/* Size, in bytes, of DT_INIT_ARRAY array */
-#define DT_INIT_ARRAYSZ 27	/* Address of termination function array */
-#define DT_FINI_ARRAYSZ 28	/* Size, in bytes, of DT_FINI_ARRAY array*/
-#define DT_RUNPATH	29	/* overrides DT_RPATH */
-#define DT_FLAGS	30	/* Encodes ORIGIN, SYMBOLIC, TEXTREL, BIND_NOW, STATIC_TLS */
-#define DT_ENCODING	31	/* ??? */
-#define DT_PREINIT_ARRAY 32	/* Address of pre-init function array */
-#define DT_PREINIT_ARRAYSZ 33	/* Size, in bytes, of DT_PREINIT_ARRAY array */
-#define DT_NUM		34
-
-#define DT_LOOS		0x60000000	/* Operating system specific range */
-#define DT_VERSYM	0x6ffffff0	/* Symbol versions */
-#define DT_FLAGS_1	0x6ffffffb	/* ELF dynamic flags */
-#define DT_VERDEF	0x6ffffffc	/* Versions defined by file */
-#define DT_VERDEFNUM	0x6ffffffd	/* Number of versions defined by file */
-#define DT_VERNEED	0x6ffffffe	/* Versions needed by file */
-#define DT_VERNEEDNUM	0x6fffffff	/* Number of versions needed by file */
-#define DT_HIOS		0x6fffffff
-#define DT_LOPROC	0x70000000	/* Processor-specific range */
-#define DT_HIPROC	0x7fffffff
-
-/* Flag values for DT_FLAGS */
-#define DF_ORIGIN	0x00000001	/* uses $ORIGIN */
-#define DF_SYMBOLIC	0x00000002	/* */
-#define DF_TEXTREL	0x00000004	/* */
-#define DF_BIND_NOW	0x00000008	/* */
-#define DF_STATICT_LS	0x00000010	/* */
-
-/* Flag values for DT_FLAGS_1 (incomplete) */
-#define DF_1_BIND_NOW	0x00000001	/* Same as DF_BIND_NOW */
-#define DF_1_NODELETE	0x00000008	/* Set the RTLD_NODELETE for object */
-#define DF_1_INITFIRST	0x00000020	/* Object's init/fini take priority */
-#define DF_1_NOOPEN	0x00000040	/* Do not allow loading on dlopen() */
-
-/*
- * Auxiliary Vectors
- */
-typedef struct {
-	Elf32_Word	a_type;				/* 32-bit id */
-	Elf32_Word	a_v;				/* 32-bit id */
-} Aux32Info;
-
-typedef struct {
-	Elf64_Word	a_type;		/* 32-bit id */
-	Elf64_Xword	a_v;		/* 64-bit id */
-} Aux64Info;
-
-/* BEGIN android-changed: these constants should come from <linux/auxvec.h>. */
-#if 0
-/* a_type */
-#define AT_NULL		0	/* Marks end of array */
-#define AT_IGNORE	1	/* No meaning, a_un is undefined */
-#define AT_EXECFD	2	/* Open file descriptor of object file */
-#define AT_PHDR		3	/* &phdr[0] */
-#define AT_PHENT	4	/* sizeof(phdr[0]) */
-#define AT_PHNUM	5	/* # phdr entries */
-#define AT_PAGESZ	6	/* PAGESIZE */
-#define AT_BASE		7	/* Interpreter base addr */
-#define AT_FLAGS	8	/* Processor flags */
-#define AT_ENTRY	9	/* Entry address of executable */
-#define AT_DCACHEBSIZE	10	/* Data cache block size */
-#define AT_ICACHEBSIZE	11	/* Instruction cache block size */
-#define AT_UCACHEBSIZE	12	/* Unified cache block size */
-#define AT_STACKBASE	13	/* Base address of the main thread */
-
-	/* Vendor specific */
-#define AT_MIPS_NOTELF	10	/* XXX a_val != 0 -> MIPS XCOFF executable */
-
-#define AT_EUID		2000	/* euid (solaris compatible numbers) */
-#define AT_RUID		2001	/* ruid (solaris compatible numbers) */
-#define AT_EGID		2002	/* egid (solaris compatible numbers) */
-#define AT_RGID		2003	/* rgid (solaris compatible numbers) */
-
-	/* Solaris kernel specific */
-#define AT_SUN_LDELF	2004	/* dynamic linker's ELF header */
-#define AT_SUN_LDSHDR	2005	/* dynamic linker's section header */
-#define AT_SUN_LDNAME	2006	/* dynamic linker's name */
-#define AT_SUN_LPGSIZE	2007	/* large pagesize */
-
-	/* Other information */
-#define AT_SUN_PLATFORM 2008	/* sysinfo(SI_PLATFORM) */
-#define AT_SUN_HWCAP	2009	/* process hardware capabilities */
-#define AT_SUN_IFLUSH	2010	/* do we need to flush the instruction cache? */
-#define AT_SUN_CPU	2011	/* CPU name */
-	/* ibcs2 emulation band aid */
-#define AT_SUN_EMUL_ENTRY 2012	/* coff entry point */
-#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
-	/* Executable's fully resolved name */
-#define AT_SUN_EXECNAME 2014
-#endif
-/* END android-changed */
-
-/*
- * Note Headers
- */
-typedef struct {
-	Elf32_Word n_namesz;
-	Elf32_Word n_descsz;
-	Elf32_Word n_type;
-} Elf32_Nhdr;
-
-typedef struct {
-	Elf64_Word n_namesz;
-	Elf64_Word n_descsz;
-	Elf64_Word n_type;
-} Elf64_Nhdr;
-
-#define ELF_NOTE_GNU_NAMESZ		4
-#define ELF_NOTE_GNU_NAME		"GNU\0"
-
-/*
- * GNU-specific note type: ABI tag
- * name: GNU\0
- * namesz: 4
- * desc:
- *	word[0]: OS tag
- *	word[1]: major version
- *	word[2]: minor version
- *	word[3]: teeny version
- * descsz: 16
- */
-/* GNU-specific note name and description sizes */
-#define ELF_NOTE_TYPE_ABI_TAG		1
-#define ELF_NOTE_ABI_NAME		ELF_NOTE_GNU_NAME
-#define ELF_NOTE_ABI_NAMESZ		ELF_NOTE_GNU_NAMESZ
-#define ELF_NOTE_ABI_DESCSZ		16
-/* GNU-specific OS/version value stuff */
-#define ELF_NOTE_ABI_OS_LINUX		0
-#define ELF_NOTE_ABI_OS_HURD		1
-#define ELF_NOTE_ABI_OS_SOLARIS		2
-#define ELF_NOTE_ABI_OS_KFREEBSD	3
-#define ELF_NOTE_ABI_OS_KNETBSD		4
-
-/*
- * GNU-specific note type: Hardware capabilities
- * name: GNU\0
- * namesz: 4
- * desc:
- *	word[0]: Number of entries
- *	word[1]: Bitmask of enabled entries
- *	Followed by a byte id, and a NUL terminated string per entry
- * descsz: variable
- */
-#define ELF_NOTE_TYPE_GNU_HWCAP		2
-
-/*
- * GNU-specific note type: Build ID generated by ld
- * name: GNU\0
- * desc:
- *	word[0..4] SHA1 [default]
- * or
- *	word[0..3] md5 or uuid
- * descsz: 16 or 20
- */
-#define ELF_NOTE_TYPE_GNU_BUILD_ID	3
-
-/* SuSE-specific note type: ABI
- * name: SuSE\0
- * namesz: 5
- * desc:
- *	half[0] = MMmm
- *
- *	M = product major version
- *	m = product minor version
- * descsz: 2
- */
-#define ELF_NOTE_TYPE_SUSE_TAG	1
-/* SuSE-specific note name and description sizes */
-#define ELF_NOTE_SUSE_NAMESZ	5
-#define ELF_NOTE_SUSE_DESCSZ	2
-/* SuSE-specific note name */
-#define ELF_NOTE_SUSE_NAME		"SuSE\0"
-
-/* SuSE-specific note type: version
- * name: SuSE\0\0\0\0
- * namesz: 8
- * desc:
- *	word[0] = VVTTMMmm
- *
- *	V = version of following data
- *	T = product type: [box, sles, nld, whatever]
- *	M = product major version
- *	m = product minor version
- * descsz: 8
- */
-#define ELF_NOTE_TYPE_SUSE_VERSION_TAG	0x45537553	/* SuSE in LE */
-/* SuSE-specific note name and description sizes */
-#define ELF_NOTE_SUSE_VERSION_NAMESZ	8
-#define ELF_NOTE_SUSE_VERSION_DESCSZ	8
-/* SuSE-specific note name */
-#define ELF_NOTE_SUSE_VERSION_NAME		"SuSE\0\0\0\0"
-
-/* NetBSD-specific note type: Emulation name.
- * name: NetBSD\0\0
- * namesz: 8
- * desc:
- *	word[0]: MMmmrrpp00
- *
- *	M = major version
- *	m = minor version
- *	r = release ["",A-Z,Z[A-Z] but numeric]
- *	p = patchlevel
- * descsz: 4
- */
-#define ELF_NOTE_TYPE_NETBSD_TAG	1
-/* NetBSD-specific note name and description sizes */
-#define ELF_NOTE_NETBSD_NAMESZ		7
-#define ELF_NOTE_NETBSD_DESCSZ		4
-/* NetBSD-specific note name */
-#define ELF_NOTE_NETBSD_NAME		"NetBSD\0\0"
-
-/* NetBSD-specific note type: Checksum.
- * There should be 1 NOTE per PT_LOAD section.
- * name: ???
- * namesz: ???
- * desc:
- *	a tuple of <phnum>(16),<chk-type>(16),<chk-value>.
- * descsz: ???
- */
-#define ELF_NOTE_TYPE_CHECKSUM_TAG	2
-#define ELF_NOTE_CHECKSUM_CRC32		1
-#define ELF_NOTE_CHECKSUM_MD5		2
-#define ELF_NOTE_CHECKSUM_SHA1		3
-#define ELF_NOTE_CHECKSUM_SHA256	4
-
-/*
- * NetBSD-specific note type: PaX.
- * There should be 1 NOTE per executable.
- * name: PaX\0
- * namesz: 4
- * desc:
- *	word[0]: capability bitmask
- * descsz: 4
- */
-#define ELF_NOTE_TYPE_PAX_TAG		3
-#define ELF_NOTE_PAX_MPROTECT		0x01	/* Force enable Mprotect */
-#define ELF_NOTE_PAX_NOMPROTECT		0x02	/* Force disable Mprotect */
-#define ELF_NOTE_PAX_GUARD		0x04	/* Force enable Segvguard */
-#define ELF_NOTE_PAX_NOGUARD		0x08	/* Force disable Servguard */
-#define ELF_NOTE_PAX_ASLR		0x10	/* Force enable ASLR */
-#define ELF_NOTE_PAX_NOASLR		0x20	/* Force disable ASLR */
-#define ELF_NOTE_PAX_NAMESZ		4
-#define ELF_NOTE_PAX_NAME		"PaX\0"
-#define ELF_NOTE_PAX_DESCSZ		4
-
-/*
- * NetBSD-specific core file information.
- *
- * NetBSD ELF core files use notes to provide information about
- * the process's state.	 The note name is "NetBSD-CORE" for
- * information that is global to the process, and "NetBSD-CORE@nn",
- * where "nn" is the lwpid of the LWP that the information belongs
- * to (such as register state).
- *
- * We use the following note identifiers:
- *
- *	ELF_NOTE_NETBSD_CORE_PROCINFO
- *		Note is a "netbsd_elfcore_procinfo" structure.
- *
- * We also use ptrace(2) request numbers (the ones that exist in
- * machine-dependent space) to identify register info notes.  The
- * info in such notes is in the same format that ptrace(2) would
- * export that information.
- *
- * Please try to keep the members of this structure nicely aligned,
- * and if you add elements, add them to the end and bump the version.
- */
-
-#define ELF_NOTE_NETBSD_CORE_NAME	"NetBSD-CORE"
-
-#define ELF_NOTE_NETBSD_CORE_PROCINFO	1
-
-#define NETBSD_ELFCORE_PROCINFO_VERSION 1
-
-struct netbsd_elfcore_procinfo {
-	/* Version 1 fields start here. */
-	uint32_t	cpi_version;		/* our version */
-	uint32_t	cpi_cpisize;		/* sizeof(this struct) */
-	uint32_t	cpi_signo;		/* killing signal */
-	uint32_t	cpi_sigcode;		/* signal code */
-	uint32_t	cpi_sigpend[4];		/* pending signals */
-	uint32_t	cpi_sigmask[4];		/* blocked signals */
-	uint32_t	cpi_sigignore[4];	/* ignored signals */
-	uint32_t	cpi_sigcatch[4];	/* caught signals */
-	int32_t		cpi_pid;		/* process ID */
-	int32_t		cpi_ppid;		/* parent process ID */
-	int32_t		cpi_pgrp;		/* process group ID */
-	int32_t		cpi_sid;		/* session ID */
-	uint32_t	cpi_ruid;		/* real user ID */
-	uint32_t	cpi_euid;		/* effective user ID */
-	uint32_t	cpi_svuid;		/* saved user ID */
-	uint32_t	cpi_rgid;		/* real group ID */
-	uint32_t	cpi_egid;		/* effective group ID */
-	uint32_t	cpi_svgid;		/* saved group ID */
-	uint32_t	cpi_nlwps;		/* number of LWPs */
-	int8_t		cpi_name[32];		/* copy of p->p_comm */
-	/* Add version 2 fields below here. */
-	int32_t		cpi_siglwp;	/* LWP target of killing signal */
-};
-
-/*
- * NetBSD-specific note type: MACHINE_ARCH.
- * There should be 1 NOTE per executable.
- * name:	NetBSD\0
- * namesz:	7
- * desc:	string
- * descsz:	variable
- */
-#define ELF_NOTE_TYPE_MARCH_TAG		5
-/* NetBSD-specific note name and description sizes */
-#define ELF_NOTE_MARCH_NAMESZ		ELF_NOTE_NETBSD_NAMESZ
-/* NetBSD-specific note name */
-#define ELF_NOTE_MARCH_NAME		ELF_NOTE_NETBSD_NAME
-
-#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
-#define ELFSIZE ARCH_ELFSIZE
-#endif
-
-#if defined(ELFSIZE)
-#define CONCAT(x,y)	__CONCAT(x,y)
-#define ELFNAME(x)	CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
-#define ELFNAME2(x,y)	CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
-#define ELFNAMEEND(x)	CONCAT(x,CONCAT(_elf,ELFSIZE))
-#define ELFDEFNNAME(x)	CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
-#endif
-
-#if defined(ELFSIZE) && (ELFSIZE == 32)
-#define Elf_Ehdr	Elf32_Ehdr
-#define Elf_Phdr	Elf32_Phdr
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Rel		Elf32_Rel
-#define Elf_Rela	Elf32_Rela
-#define Elf_Dyn		Elf32_Dyn
-#define Elf_Word	Elf32_Word
-#define Elf_Sword	Elf32_Sword
-#define Elf_Half	Elf32_Half
-#define Elf_Addr	Elf32_Addr
-#define Elf_Off		Elf32_Off
-#define Elf_SOff	Elf32_SOff
-#define Elf_Nhdr	Elf32_Nhdr
-#define Elf_Verdef	Elf32_Verdef
-#define Elf_Verdaux	Elf32_Verdaux
-#define Elf_Verneed	Elf32_Verneed
-#define Elf_Vernaux	Elf32_Vernaux
-#define Elf_Versym	Elf32_Versym
-
-#define ELF_R_SYM	ELF32_R_SYM
-#define ELF_R_TYPE	ELF32_R_TYPE
-#define ELFCLASS	ELFCLASS32
-
-#define AuxInfo		Aux32Info
-#elif defined(ELFSIZE) && (ELFSIZE == 64)
-#define Elf_Ehdr	Elf64_Ehdr
-#define Elf_Phdr	Elf64_Phdr
-#define Elf_Shdr	Elf64_Shdr
-#define Elf_Sym		Elf64_Sym
-#define Elf_Rel		Elf64_Rel
-#define Elf_Rela	Elf64_Rela
-#define Elf_Dyn		Elf64_Dyn
-#define Elf_Word	Elf64_Word
-#define Elf_Sword	Elf64_Sword
-#define Elf_Half	Elf64_Half
-#define Elf_Addr	Elf64_Addr
-#define Elf_Off		Elf64_Off
-#define Elf_SOff	Elf64_SOff
-#define Elf_Nhdr	Elf64_Nhdr
-#define Elf_Verdef	Elf64_Verdef
-#define Elf_Verdaux	Elf64_Verdaux
-#define Elf_Verneed	Elf64_Verneed
-#define Elf_Vernaux	Elf64_Vernaux
-#define Elf_Versym	Elf64_Versym
-
-#define ELF_R_SYM	ELF64_R_SYM
-#define ELF_R_TYPE	ELF64_R_TYPE
-#define ELFCLASS	ELFCLASS64
-
-#define AuxInfo		Aux64Info
-#endif
-
-#ifndef Elf_Symindx
-#define Elf_Symindx	uint32_t
-#endif
-
-#define ELF32_ST_BIND(info)		ELF_ST_BIND(info)
-#define ELF32_ST_TYPE(info)		ELF_ST_TYPE(info)
-#define ELF32_ST_INFO(bind,type)	ELF_ST_INFO(bind,type)
-#define ELF32_ST_VISIBILITY(other)	ELF_ST_VISIBILITY(other)
-
-#define ELF64_ST_BIND(info)		ELF_ST_BIND(info)
-#define ELF64_ST_TYPE(info)		ELF_ST_TYPE(info)
-#define ELF64_ST_INFO(bind,type)	ELF_ST_INFO(bind,type)
-#define ELF64_ST_VISIBILITY(other)	ELF_ST_VISIBILITY(other)
-
-typedef struct {
-	Elf32_Half	si_boundto;	/* direct bindings - symbol bound to */
-	Elf32_Half	si_flags;	/* per symbol flags */
-} Elf32_Syminfo;
-
-typedef struct {
-	Elf64_Word	si_boundto;	/* direct bindings - symbol bound to */
-	Elf64_Word	si_flags;	/* per symbol flags */
-} Elf64_Syminfo;
-
-#define SYMINFO_FLG_DIRECT	0x0001	/* symbol ref has direct association
-					   to object containing definition */
-#define SYMINFO_FLG_PASSTHRU	0x0002	/* ignored - see SYMINFO_FLG_FILTER */
-#define SYMINFO_FLG_COPY	0x0004	/* symbol is a copy-reloc */
-#define SYMINFO_FLG_LAZYLOAD	0x0008	/* object containing defn should be
-					   lazily-loaded */
-#define SYMINFO_FLG_DIRECTBIND	0x0010	/* ref should be bound directly to
-					   object containing definition */
-#define SYMINFO_FLG_NOEXTDIRECT 0x0020	/* don't let an external reference
-					   directly bind to this symbol */
-#define SYMINFO_FLG_FILTER	0x0002	/* symbol ref is associated to a */
-#define SYMINFO_FLG_AUXILIARY	0x0040	/*	standard or auxiliary filter */
-
-#define SYMINFO_BT_SELF		0xffff	/* symbol bound to self */
-#define SYMINFO_BT_PARENT	0xfffe	/* symbol bound to parent */
-#define SYMINFO_BT_NONE		0xfffd	/* no special symbol binding */
-#define SYMINFO_BT_EXTERN	0xfffc	/* symbol defined as external */
-#define SYMINFO_BT_LOWRESERVE	0xff00	/* beginning of reserved entries */
-
-#define SYMINFO_NONE		0	/* Syminfo version */
-#define SYMINFO_CURRENT		1
-#define SYMINFO_NUM		2
-
-/*
- * These constants are used for Elf32_Verdef struct's version number.
- */
-#define VER_DEF_NONE		0
-#define VER_DEF_CURRENT		1
-
-/*
- * These constants are used for Elf32_Verdef struct's vd_ndx.
- */
-#define VER_DEF_IDX(x)		VER_NDX(x)
-
-/*
- * These constants are used for Elf32_Verdef struct's vd_flags.
- */
-#define VER_FLG_BASE		0x1
-#define VER_FLG_WEAK		0x2
-
-/*
- * These are used in an Elf32_Versym field.
- */
-#define VER_NDX_LOCAL		0
-#define VER_NDX_GLOBAL		1
-#define VER_NDX_GIVEN		2
-
-/*
- * These constants are used for Elf32_Verneed struct's version number.
- */
-#define VER_NEED_NONE		0
-#define VER_NEED_CURRENT	1
-
-/*
- * These constants are used for Elf32_Vernaux struct's vna_other.
- */
-#define VER_NEED_HIDDEN		VER_NDX_HIDDEN
-#define VER_NEED_IDX(x)		VER_NDX(x)
-
-/* index */
-#define VER_NDX_HIDDEN		0x8000
-#define VER_NDX(x)		((x) & ~VER_NDX_HIDDEN)
-
-/*
- * GNU Extension hidding symbol
- */
-#define VERSYM_HIDDEN		0x8000
-#define VERSYM_VERSION		0x7fff
-
-#define ELF_VER_CHR		'@'
-
-/*
- * These are current size independent.
- */
-
-typedef struct {
-	Elf32_Half	vd_version;	/* version number of structure */
-	Elf32_Half	vd_flags;	/* flags (VER_FLG_*) */
-	Elf32_Half	vd_ndx;		/* version index */
-	Elf32_Half	vd_cnt;		/* number of verdaux entries */
-	Elf32_Word	vd_hash;	/* hash of name */
-	Elf32_Word	vd_aux;		/* offset to verdaux entries */
-	Elf32_Word	vd_next;	/* offset to next verdef */
-} Elf32_Verdef;
-typedef Elf32_Verdef	Elf64_Verdef;
-
-typedef struct {
-	Elf32_Word	vda_name;	/* string table offset of name */
-	Elf32_Word	vda_next;	/* offset to verdaux */
-} Elf32_Verdaux;
-typedef Elf32_Verdaux	Elf64_Verdaux;
-
-typedef struct {
-	Elf32_Half	vn_version;	/* version number of structure */
-	Elf32_Half	vn_cnt;		/* number of vernaux entries */
-	Elf32_Word	vn_file;	/* string table offset of library name*/
-	Elf32_Word	vn_aux;		/* offset to vernaux entries */
-	Elf32_Word	vn_next;	/* offset to next verneed */
-} Elf32_Verneed;
-typedef Elf32_Verneed	Elf64_Verneed;
-
-typedef struct {
-	Elf32_Word	vna_hash;	/* Hash of dependency name */
-	Elf32_Half	vna_flags;	/* flags (VER_FLG_*) */
-	Elf32_Half	vna_other;	/* unused */
-	Elf32_Word	vna_name;	/* string table offset to version name*/
-	Elf32_Word	vna_next;	/* offset to next vernaux */
-} Elf32_Vernaux;
-typedef Elf32_Vernaux	Elf64_Vernaux;
-
-typedef struct {
-	Elf32_Half	vs_vers;
-} Elf32_Versym;
-typedef Elf32_Versym	Elf64_Versym;
-
-#ifdef _KERNEL
-
-#define ELF_AUX_ENTRIES 15	/* Max size of aux array passed to loader */
-#define ELF32_NO_ADDR	(~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
-#define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */
-#define ELF64_NO_ADDR	(~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
-#define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */
-
-#if defined(ELFSIZE) && (ELFSIZE == 64)
-#define ELF_NO_ADDR	ELF64_NO_ADDR
-#define ELF_LINK_ADDR	ELF64_LINK_ADDR
-#elif defined(ELFSIZE) && (ELFSIZE == 32)
-#define ELF_NO_ADDR	ELF32_NO_ADDR
-#define ELF_LINK_ADDR	ELF32_LINK_ADDR
-#endif
-
-#ifndef ELF32_EHDR_FLAGS_OK
-#define ELF32_EHDR_FLAGS_OK(eh) 1
-#endif
-
-#ifndef ELF64_EHDR_FLAGS_OK
-#define ELF64_EHDR_FLAGS_OK(eh) 1
-#endif
-
-#if defined(ELFSIZE) && (ELFSIZE == 64)
-#define ELF_EHDR_FLAGS_OK(eh)	ELF64_EHDR_FLAGS_OK(eh)
-#else
-#define ELF_EHDR_FLAGS_OK(eh)	ELF32_EHDR_FLAGS_OK(eh)
-#endif
-
-#if defined(ELFSIZE)
-struct elf_args {
-	Elf_Addr	arg_entry;	/* program entry point */
-	Elf_Addr	arg_interp;	/* Interpreter load address */
-	Elf_Addr	arg_phaddr;	/* program header address */
-	Elf_Addr	arg_phentsize;	/* Size of program header */
-	Elf_Addr	arg_phnum;	/* Number of program headers */
-};
-#endif
-
-#ifdef _KERNEL_OPT
-#include "opt_execfmt.h"
-#endif
-
-struct ps_strings;
-
-#ifdef EXEC_ELF32
-int	exec_elf32_makecmds(struct lwp *, struct exec_package *);
-int	elf32_copyargs(struct lwp *, struct exec_package *,
-    struct ps_strings *, char **, void *);
-
-int	coredump_elf32(struct lwp *, void *);
-int	coredump_writenote_elf32(struct proc *, void *, Elf32_Nhdr *,
-    const char *, void *);
-
-int	elf32_check_header(Elf32_Ehdr *, int);
-#endif
-
-#ifdef EXEC_ELF64
-int	exec_elf64_makecmds(struct lwp *, struct exec_package *);
-int	elf64_copyargs(struct lwp *, struct exec_package *,
-    struct ps_strings *, char **, void *);
-
-int	coredump_elf64(struct lwp *, void *);
-int	coredump_writenote_elf64(struct proc *, void *, Elf64_Nhdr *,
-    const char *, void *);
-
-int	elf64_check_header(Elf64_Ehdr *, int);
-#endif
-
-#endif /* _KERNEL */
-
-#endif /* !_SYS_EXEC_ELF_H_ */
diff --git a/ndk/platforms/android-20/include/sys/klog.h b/ndk/platforms/android-20/include/sys/klog.h
index 02851d2..acfaa20 100644
--- a/ndk/platforms/android-20/include/sys/klog.h
+++ b/ndk/platforms/android-20/include/sys/klog.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_KLOG_H_
 #define _SYS_KLOG_H_
 
@@ -45,13 +46,6 @@
 #define KLOG_SIZE_UNREAD   9
 #define KLOG_SIZE_BUFFER   10
 
-/* These are deprecated names that were used in earlier bionic releases. Do not use. */
-#define KLOG_DISABLE 6
-#define KLOG_ENABLE 7
-#define KLOG_SETLEVEL 8
-#define KLOG_UNREADSIZE 9
-#define KLOG_WRITE 10
-
 extern int klogctl(int, char *, int);
 
 __END_DECLS
diff --git a/ndk/platforms/android-20/include/sys/mman.h b/ndk/platforms/android-20/include/sys/mman.h
index 7c5f8d7..5a8c985 100644
--- a/ndk/platforms/android-20/include/sys/mman.h
+++ b/ndk/platforms/android-20/include/sys/mman.h
@@ -31,7 +31,6 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 #include <asm/mman.h>
-#include <asm/page.h>
 
 __BEGIN_DECLS
 
@@ -44,23 +43,23 @@
 #define MREMAP_MAYMOVE  1
 #define MREMAP_FIXED    2
 
-extern void*  mmap(void *, size_t, int, int, int, off_t);
-extern void*  mmap64(void *, size_t, int, int, int, off64_t);
-extern int    munmap(void *, size_t);
-extern int    msync(const void *, size_t, int);
-extern int    mprotect(const void *, size_t, int);
-extern void*  mremap(void *, size_t, size_t, unsigned long);
+extern void* mmap(void*, size_t, int, int, int, off_t);
+extern void* mmap64(void*, size_t, int, int, int, off64_t);
+extern int munmap(void*, size_t);
+extern int msync(const void*, size_t, int);
+extern int mprotect(const void*, size_t, int);
+extern void* mremap(void*, size_t, size_t, unsigned long);
 
-extern int    mlockall(int);
-extern int    munlockall(void);
-extern int    mlock(const void *, size_t);
-extern int    munlock(const void *, size_t);
-extern int    madvise(const void *, size_t, int);
+extern int mlockall(int);
+extern int munlockall(void);
+extern int mlock(const void*, size_t);
+extern int munlock(const void*, size_t);
+extern int madvise(const void*, size_t, int);
 
-extern int    mlock(const void *addr, size_t len);
-extern int    munlock(const void *addr, size_t len);
+extern int mlock(const void*, size_t);
+extern int munlock(const void*, size_t);
 
-extern int    mincore(void*  start, size_t  length, unsigned char*  vec);
+extern int mincore(void*, size_t, unsigned char*);
 
 __END_DECLS
 
diff --git a/ndk/platforms/android-20/include/sys/socket.h b/ndk/platforms/android-20/include/sys/socket.h
index 32d98ea..62a5300 100644
--- a/ndk/platforms/android-20/include/sys/socket.h
+++ b/ndk/platforms/android-20/include/sys/socket.h
@@ -43,8 +43,9 @@
 __BEGIN_DECLS
 
 #define sockaddr_storage __kernel_sockaddr_storage
-typedef __sa_family_t sa_family_t;
-typedef int socklen_t;
+typedef unsigned short sa_family_t;
+
+struct timespec;
 
 #ifdef __mips__
 #define SOCK_DGRAM      1
@@ -76,40 +77,45 @@
 };
 
 struct sockaddr {
- sa_family_t sa_family;
- char sa_data[14];
+  sa_family_t sa_family;
+  char sa_data[14];
 };
 
 struct linger {
- int l_onoff;
- int l_linger;
+  int l_onoff;
+  int l_linger;
 };
 
 struct msghdr {
- void * msg_name;
- int msg_namelen;
- struct iovec * msg_iov;
- __kernel_size_t msg_iovlen;
- void * msg_control;
- __kernel_size_t msg_controllen;
- unsigned msg_flags;
+  void* msg_name;
+  socklen_t msg_namelen;
+  struct iovec* msg_iov;
+  size_t msg_iovlen;
+  void* msg_control;
+  size_t msg_controllen;
+  int msg_flags;
+};
+
+struct mmsghdr {
+  struct msghdr msg_hdr;
+  unsigned int msg_len;
 };
 
 struct cmsghdr {
- __kernel_size_t cmsg_len;
- int cmsg_level;
- int cmsg_type;
+  size_t cmsg_len;
+  int cmsg_level;
+  int cmsg_type;
 };
 
 #define __CMSG_NXTHDR(ctl, len, cmsg) __cmsg_nxthdr((ctl),(len),(cmsg))
 #define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg))
 #define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
-#define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
+#define CMSG_DATA(cmsg) ((void*)((char*)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
 #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
 #define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
-#define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ?   (struct cmsghdr *)(ctl) :   (struct cmsghdr *)NULL)
+#define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ?   (struct cmsghdr*)(ctl) :   (struct cmsghdr*)NULL)
 #define CMSG_FIRSTHDR(msg) __CMSG_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen)
-#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) &&   (cmsg)->cmsg_len <= (unsigned long)   ((mhdr)->msg_controllen -   ((char *)(cmsg) - (char *)(mhdr)->msg_control)))
+#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) &&   (cmsg)->cmsg_len <= (unsigned long)   ((mhdr)->msg_controllen -   ((char*)(cmsg) - (char*)(mhdr)->msg_control)))
 
 #ifdef __GNUC__
 #define __KINLINE static __inline__
@@ -119,16 +125,17 @@
 #define __KINLINE static
 #endif
 
-__KINLINE struct cmsghdr * __cmsg_nxthdr(void *__ctl, __kernel_size_t __size, struct cmsghdr *__cmsg) {
- struct cmsghdr * __ptr;
- __ptr = (struct cmsghdr*)(((unsigned char *) __cmsg) + CMSG_ALIGN(__cmsg->cmsg_len));
- if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size)
- return (struct cmsghdr *)0;
- return __ptr;
+__KINLINE struct cmsghdr* __cmsg_nxthdr(void* __ctl, size_t __size, struct cmsghdr* __cmsg) {
+  struct cmsghdr* __ptr;
+  __ptr = (struct cmsghdr*)(((unsigned char*) __cmsg) + CMSG_ALIGN(__cmsg->cmsg_len));
+  if ((unsigned long)((char*)(__ptr+1) - (char*) __ctl) > __size) {
+    return NULL;
+  }
+  return __ptr;
 }
 
-__KINLINE struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr *__cmsg) {
- return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
+__KINLINE struct cmsghdr* cmsg_nxthdr (struct msghdr* __msg, struct cmsghdr* __cmsg) {
+  return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
 }
 
 #define SCM_RIGHTS 0x01
@@ -136,9 +143,9 @@
 #define SCM_SECURITY 0x03
 
 struct ucred {
- __u32 pid;
- __u32 uid;
- __u32 gid;
+  pid_t pid;
+  uid_t uid;
+  gid_t gid;
 };
 
 #define AF_UNSPEC 0
@@ -242,6 +249,9 @@
 #define MSG_ERRQUEUE 0x2000
 #define MSG_NOSIGNAL 0x4000
 #define MSG_MORE 0x8000
+#define MSG_WAITFORONE 0x10000
+#define MSG_FASTOPEN 0x20000000
+#define MSG_CMSG_CLOEXEC 0x40000000
 #define MSG_EOF MSG_FIN
 #define MSG_CMSG_COMPAT 0
 
@@ -277,43 +287,45 @@
 # define __socketcall extern
 #endif
 
-__socketcall int socket(int, int, int);
-__socketcall int bind(int, const struct sockaddr *, int);
-__socketcall int connect(int, const struct sockaddr *, socklen_t);
+__socketcall int accept(int, struct sockaddr*, socklen_t*);
+__socketcall int bind(int, const struct sockaddr*, int);
+__socketcall int connect(int, const struct sockaddr*, socklen_t);
+__socketcall int getpeername(int, struct sockaddr*, socklen_t*);
+__socketcall int getsockname(int, struct sockaddr*, socklen_t*);
+__socketcall int getsockopt(int, int, int, void*, socklen_t*);
 __socketcall int listen(int, int);
-__socketcall int accept(int, struct sockaddr *, socklen_t *);
-__socketcall int getsockname(int, struct sockaddr *, socklen_t *);
-__socketcall int getpeername(int, struct sockaddr *, socklen_t *);
-__socketcall int socketpair(int, int, int, int *);
+__socketcall int recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*);
+__socketcall int recvmsg(int, struct msghdr*, int);
+__socketcall int sendmmsg(int, const struct mmsghdr*, unsigned int, int);
+__socketcall int sendmsg(int, const struct msghdr*, int);
+__socketcall int setsockopt(int, int, int, const void*, socklen_t);
 __socketcall int shutdown(int, int);
-__socketcall int setsockopt(int, int, int, const void *, socklen_t);
-__socketcall int getsockopt(int, int, int, void *, socklen_t *);
-__socketcall int sendmsg(int, const struct msghdr *, unsigned int);
-__socketcall int recvmsg(int, struct msghdr *, unsigned int);
+__socketcall int socket(int, int, int);
+__socketcall int socketpair(int, int, int, int*);
 
-extern  ssize_t  send(int, const void *, size_t, unsigned int);
-extern  ssize_t  recv(int, void *, size_t, unsigned int);
+extern ssize_t send(int, const void*, size_t, int);
+extern ssize_t recv(int, void*, size_t, int);
 
-__socketcall ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
-__socketcall ssize_t recvfrom(int, void *, size_t, unsigned int, const struct sockaddr *, socklen_t *);
+__socketcall ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t);
+__socketcall ssize_t recvfrom(int, void*, size_t, int, const struct sockaddr*, socklen_t*);
 
 #if defined(__BIONIC_FORTIFY)
 __errordecl(__recvfrom_error, "recvfrom called with size bigger than buffer");
-extern ssize_t __recvfrom_chk(int, void*, size_t, size_t, unsigned int, const struct sockaddr*, socklen_t *);
-extern ssize_t __recvfrom_real(int, void *, size_t, unsigned int, const struct sockaddr*, socklen_t*)
+extern ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, const struct sockaddr*, socklen_t*);
+extern ssize_t __recvfrom_real(int, void*, size_t, int, const struct sockaddr*, socklen_t*)
     __asm__(__USER_LABEL_PREFIX__ "recvfrom");
 
 __BIONIC_FORTIFY_INLINE
-ssize_t recvfrom(int fd, void* buf, size_t len, unsigned int flags, const struct sockaddr* src_addr, socklen_t* addrlen) {
+ssize_t recvfrom(int fd, void* buf, size_t len, int flags, const struct sockaddr* src_addr, socklen_t* addr_len) {
   size_t bos = __bos0(buf);
 
 #if !defined(__clang__)
   if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
-    return __recvfrom_real(fd, buf, len, flags, src_addr, addrlen);
+    return __recvfrom_real(fd, buf, len, flags, src_addr, addr_len);
   }
 
   if (__builtin_constant_p(len) && (len <= bos)) {
-    return __recvfrom_real(fd, buf, len, flags, src_addr, addrlen);
+    return __recvfrom_real(fd, buf, len, flags, src_addr, addr_len);
   }
 
   if (__builtin_constant_p(len) && (len > bos)) {
@@ -321,12 +333,12 @@
   }
 #endif
 
-  return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addrlen);
+  return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len);
 }
 
 __BIONIC_FORTIFY_INLINE
-ssize_t recv(int socket, void *buf, size_t buflen, unsigned int flags) {
-  return recvfrom(socket, buf, buflen, flags, NULL, 0);
+ssize_t recv(int socket, void* buf, size_t len, int flags) {
+  return recvfrom(socket, buf, len, flags, NULL, 0);
 }
 
 #endif /* __BIONIC_FORTIFY */
diff --git a/ndk/platforms/android-20/include/sys/stat.h b/ndk/platforms/android-20/include/sys/stat.h
index 37b8dc2..e62e76d 100644
--- a/ndk/platforms/android-20/include/sys/stat.h
+++ b/ndk/platforms/android-20/include/sys/stat.h
@@ -38,101 +38,101 @@
 __BEGIN_DECLS
 
 #if defined(__aarch64__)
-struct stat {
-  unsigned long st_dev;
-  unsigned long st_ino;
-  unsigned int st_mode;
-  unsigned int st_nlink;
-  unsigned int st_uid;
-  unsigned int st_gid;
-  unsigned long st_rdev;
-  unsigned long __pad1;
-  long st_size;
-  int st_blksize;
-  int __pad2;
-  long st_blocks;
-  long st_atime;
-  unsigned long st_atime_nsec;
-  long st_mtime;
-  unsigned long st_mtime_nsec;
-  long st_ctime;
-  unsigned long st_ctime_nsec;
-  unsigned int __unused4;
-  unsigned int __unused5;
-};
+#define __STAT64_BODY \
+  unsigned long st_dev; \
+  unsigned long st_ino; \
+  unsigned int st_mode; \
+  unsigned int st_nlink; \
+  uid_t st_uid; \
+  gid_t st_gid; \
+  unsigned long st_rdev; \
+  unsigned long __pad1; \
+  long st_size; \
+  int st_blksize; \
+  int __pad2; \
+  long st_blocks; \
+  long st_atime; \
+  unsigned long st_atime_nsec; \
+  long st_mtime; \
+  unsigned long st_mtime_nsec; \
+  long st_ctime; \
+  unsigned long st_ctime_nsec; \
+  unsigned int __unused4; \
+  unsigned int __unused5; \
+
 #elif defined(__mips__)
-struct stat {
-  unsigned int st_dev;
-  unsigned int __pad0[3];
-  unsigned long long st_ino;
-  unsigned int st_mode;
-  unsigned int st_nlink;
-  unsigned int st_uid;
-  unsigned int st_gid;
-  unsigned int st_rdev;
-  unsigned int __pad1[3];
-  long long st_size;
-  unsigned int st_atime;
-  unsigned int st_atime_nsec;
-  unsigned int st_mtime;
-  unsigned int st_mtime_nsec;
-  unsigned int st_ctime;
-  unsigned int st_ctime_nsec;
-  unsigned int st_blksize;
-  unsigned int __pad2;
-  unsigned long long st_blocks;
-};
+#define __STAT64_BODY \
+  unsigned int st_dev; \
+  unsigned int __pad0[3]; \
+  unsigned long long st_ino; \
+  unsigned int st_mode; \
+  unsigned int st_nlink; \
+  uid_t st_uid; \
+  gid_t st_gid; \
+  unsigned int st_rdev; \
+  unsigned int __pad1[3]; \
+  long long st_size; \
+  unsigned int st_atime; \
+  unsigned int st_atime_nsec; \
+  unsigned int st_mtime; \
+  unsigned int st_mtime_nsec; \
+  unsigned int st_ctime; \
+  unsigned int st_ctime_nsec; \
+  unsigned int st_blksize; \
+  unsigned int __pad2; \
+  unsigned long long st_blocks; \
+
 #elif defined(__x86_64__)
-struct stat {
-  unsigned long st_dev;
-  unsigned long st_ino;
-  unsigned long st_nlink;
-  unsigned int st_mode;
-  unsigned int st_uid;
-  unsigned int st_gid;
-  unsigned int __pad0;
-  unsigned long st_rdev;
-  long st_size;
-  long st_blksize;
-  long st_blocks;
-  unsigned long st_atime;
-  unsigned long st_atime_nsec;
-  unsigned long st_mtime;
-  unsigned long st_mtime_nsec;
-  unsigned long st_ctime;
-  unsigned long st_ctime_nsec;
-  long __pad3[3];
-};
+#define __STAT64_BODY \
+  unsigned long st_dev; \
+  unsigned long st_ino; \
+  unsigned long st_nlink; \
+  unsigned int st_mode; \
+  uid_t st_uid; \
+  gid_t st_gid; \
+  unsigned int __pad0; \
+  unsigned long st_rdev; \
+  long st_size; \
+  long st_blksize; \
+  long st_blocks; \
+  unsigned long st_atime; \
+  unsigned long st_atime_nsec; \
+  unsigned long st_mtime; \
+  unsigned long st_mtime_nsec; \
+  unsigned long st_ctime; \
+  unsigned long st_ctime_nsec; \
+  long __pad3[3]; \
+
 #else
-struct stat {
-  unsigned long long st_dev;
-  unsigned char __pad0[4];
-  unsigned long __st_ino;
-  unsigned int st_mode;
-  unsigned int st_nlink;
-  unsigned long st_uid;
-  unsigned long st_gid;
-  unsigned long long st_rdev;
-  unsigned char __pad3[4];
-  long long st_size;
-  unsigned long st_blksize;
-  unsigned long long st_blocks;
-  unsigned long st_atime;
-  unsigned long st_atime_nsec;
-  unsigned long st_mtime;
-  unsigned long st_mtime_nsec;
-  unsigned long st_ctime;
-  unsigned long st_ctime_nsec;
-  unsigned long long st_ino;
-};
+#define __STAT64_BODY \
+  unsigned long long st_dev; \
+  unsigned char __pad0[4]; \
+  unsigned long __st_ino; \
+  unsigned int st_mode; \
+  unsigned int st_nlink; \
+  uid_t st_uid; \
+  gid_t st_gid; \
+  unsigned long long st_rdev; \
+  unsigned char __pad3[4]; \
+  long long st_size; \
+  unsigned long st_blksize; \
+  unsigned long long st_blocks; \
+  unsigned long st_atime; \
+  unsigned long st_atime_nsec; \
+  unsigned long st_mtime; \
+  unsigned long st_mtime_nsec; \
+  unsigned long st_ctime; \
+  unsigned long st_ctime_nsec; \
+  unsigned long long st_ino; \
+
 #endif
 
-/* For compatibility with GLibc, we provide macro aliases
- * for the non-Posix nano-seconds accessors.
- */
-#define  st_atimensec  st_atime_nsec
-#define  st_mtimensec  st_mtime_nsec
-#define  st_ctimensec  st_ctime_nsec
+struct stat { __STAT64_BODY };
+struct stat64 { __STAT64_BODY };
+
+#define st_atimensec st_atime_nsec
+#define st_mtimensec st_mtime_nsec
+#define st_ctimensec st_ctime_nsec
 
 #ifdef __USE_BSD
 /* Permission macros provided by glibc for compatibility with BSDs. */
@@ -141,21 +141,26 @@
 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
 #endif
 
-extern int    chmod(const char *, mode_t);
-extern int    fchmod(int, mode_t);
-extern int    mkdir(const char *, mode_t);
+extern int chmod(const char*, mode_t);
+extern int fchmod(int, mode_t);
+extern int mkdir(const char*, mode_t);
 
-extern int    stat(const char *, struct stat *);
-extern int    fstat(int, struct stat *);
-extern int    lstat(const char *, struct stat *);
-extern int    mknod(const char *, mode_t, dev_t);
+extern int fstat(int, struct stat*);
+extern int fstat64(int, struct stat64*);
+extern int fstatat(int, const char*, struct stat*, int);
+extern int fstatat64(int, const char*, struct stat64*, int);
+extern int lstat(const char*, struct stat*);
+extern int lstat64(const char*, struct stat64*);
+extern int stat(const char*, struct stat*);
+extern int stat64(const char*, struct stat64*);
+
+extern int mknod(const char*, mode_t, dev_t);
 extern mode_t umask(mode_t);
 
 #if defined(__BIONIC_FORTIFY)
 
 extern mode_t __umask_chk(mode_t);
-extern mode_t __umask_real(mode_t)
-    __asm__(__USER_LABEL_PREFIX__ "umask");
+extern mode_t __umask_real(mode_t) __asm__(__USER_LABEL_PREFIX__ "umask");
 __errordecl(__umask_invalid_mode, "umask called with invalid mode");
 
 __BIONIC_FORTIFY_INLINE
@@ -172,20 +177,14 @@
 }
 #endif /* defined(__BIONIC_FORTIFY) */
 
-
-#define  stat64    stat
-#define  fstat64   fstat
-#define  lstat64   lstat
-
 extern int mkfifo(const char*, mode_t);
 
 extern int fchmodat(int, const char*, mode_t, int);
-extern int fstatat(int, const char*, struct stat*, int);
 extern int mkdirat(int, const char*, mode_t);
 extern int mknodat(int, const char*, mode_t, dev_t);
 
-# define UTIME_NOW      ((1l << 30) - 1l)
-# define UTIME_OMIT     ((1l << 30) - 2l)
+#define UTIME_NOW  ((1L << 30) - 1L)
+#define UTIME_OMIT ((1L << 30) - 2L)
 extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
 extern int futimens(int fd, const struct timespec times[2]);
 
diff --git a/ndk/platforms/android-20/include/sys/statvfs.h b/ndk/platforms/android-20/include/sys/statvfs.h
index e910c03..3d8179e 100644
--- a/ndk/platforms/android-20/include/sys/statvfs.h
+++ b/ndk/platforms/android-20/include/sys/statvfs.h
@@ -23,19 +23,21 @@
 
 __BEGIN_DECLS
 
-struct statvfs {
-  unsigned long f_bsize;
-  unsigned long f_frsize;
-  fsblkcnt_t    f_blocks;
-  fsblkcnt_t    f_bfree;
-  fsblkcnt_t    f_bavail;
-  fsfilcnt_t    f_files;
-  fsfilcnt_t    f_ffree;
-  fsfilcnt_t    f_favail;
-  unsigned long f_fsid;
-  unsigned long f_flag;
-  unsigned long f_namemax;
-};
+#define __STATVFS64_BODY \
+  unsigned long f_bsize; \
+  unsigned long f_frsize; \
+  fsblkcnt_t    f_blocks; \
+  fsblkcnt_t    f_bfree; \
+  fsblkcnt_t    f_bavail; \
+  fsfilcnt_t    f_files; \
+  fsfilcnt_t    f_ffree; \
+  fsfilcnt_t    f_favail; \
+  unsigned long f_fsid; \
+  unsigned long f_flag; \
+  unsigned long f_namemax; \
+
+struct statvfs { __STATVFS64_BODY };
+struct statvfs64 { __STATVFS64_BODY };
 
 #define ST_RDONLY      0x0001
 #define ST_NOSUID      0x0002
@@ -48,7 +50,9 @@
 #define ST_RELATIME    0x1000
 
 extern int statvfs(const char* __restrict, struct statvfs* __restrict) __nonnull((1, 2));
+extern int statvfs64(const char* __restrict, struct statvfs64* __restrict) __nonnull((1, 2));
 extern int fstatvfs(int, struct statvfs*) __nonnull((2));
+extern int fstatvfs64(int, struct statvfs64*) __nonnull((2));
 
 __END_DECLS
 
diff --git a/ndk/platforms/android-20/include/sys/times.h b/ndk/platforms/android-20/include/sys/times.h
index 1b9b8b2..6ce5b55 100644
--- a/ndk/platforms/android-20/include/sys/times.h
+++ b/ndk/platforms/android-20/include/sys/times.h
@@ -25,6 +25,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #ifndef _SYS_TIMES_H_
 #define _SYS_TIMES_H_
 
@@ -34,7 +35,7 @@
 
 __BEGIN_DECLS
 
-extern clock_t times(struct tms *);
+extern clock_t times(struct tms*);
 
 __END_DECLS
 
diff --git a/ndk/platforms/android-20/include/sys/types.h b/ndk/platforms/android-20/include/sys/types.h
index f8ae813..dc847d2 100644
--- a/ndk/platforms/android-20/include/sys/types.h
+++ b/ndk/platforms/android-20/include/sys/types.h
@@ -35,28 +35,48 @@
 #include <linux/types.h>
 #include <linux/posix_types.h>
 
-/* __kernel_gid_t and __kernel_uid_t are 16 bit for legacy reasons.
- * Android uses __kernel_uid32_t and __kernel_gid32_t instead.
- */
-typedef __kernel_gid32_t gid_t;
-typedef __kernel_uid32_t uid_t;
+/* gids, uids, and pids are all 32-bit. */
+typedef __kernel_gid32_t __gid_t;
+typedef __gid_t gid_t;
+typedef __kernel_uid32_t __uid_t;
+typedef __uid_t uid_t;
+typedef __kernel_pid_t __pid_t;
+typedef __pid_t pid_t;
+typedef uint32_t __id_t;
+typedef __id_t id_t;
 
 typedef unsigned long blkcnt_t;
 typedef unsigned long blksize_t;
 typedef __kernel_caddr_t caddr_t;
 typedef __kernel_clock_t clock_t;
-typedef __kernel_clockid_t clockid_t;
+
+typedef __kernel_clockid_t __clockid_t;
+typedef __clockid_t clockid_t;
+
 typedef __kernel_daddr_t daddr_t;
 typedef unsigned long fsblkcnt_t;
 typedef unsigned long fsfilcnt_t;
-typedef __kernel_ino_t ino_t;
-typedef __kernel_key_t key_t;
-typedef __kernel_mode_t mode_t;
+
+typedef __kernel_mode_t __mode_t;
+typedef __mode_t mode_t;
+
+typedef __kernel_key_t __key_t;
+typedef __key_t key_t;
+
+typedef uint32_t __ino_t;
+typedef __ino_t ino_t;
+
+typedef uint32_t __nlink_t;
 typedef __nlink_t nlink_t;
-typedef __kernel_pid_t pid_t;
-typedef __kernel_suseconds_t suseconds_t;
-typedef __kernel_timer_t timer_t;
-typedef unsigned int useconds_t;
+
+typedef void* __timer_t;
+typedef __timer_t timer_t;
+
+typedef int32_t __suseconds_t;
+typedef __suseconds_t suseconds_t;
+
+typedef uint32_t __useconds_t;
+typedef __useconds_t useconds_t;
 
 #if !defined(__LP64__)
 /* This historical accident means that we had a 32-bit dev_t on 32-bit architectures. */
@@ -66,7 +86,8 @@
 #endif
 
 /* This historical accident means that we had a 32-bit time_t on 32-bit architectures. */
-typedef __kernel_time_t time_t;
+typedef __kernel_time_t __time_t;
+typedef __time_t time_t;
 
 /* This historical accident means that we had a 32-bit off_t on 32-bit architectures. */
 #ifndef _OFF_T_DEFINED_
@@ -76,9 +97,6 @@
 typedef __kernel_loff_t loff_t;
 typedef loff_t off64_t;
 
-/* This one really is meant to be just 32 bits! */
-typedef uint32_t id_t;
-
 /* while POSIX wants these in <sys/types.h>, we
  * declare then in <pthread.h> instead */
 #if 0
@@ -93,6 +111,17 @@
 typedef  .... pthread_t;
 #endif
 
+#if !defined(__LP64__)
+/* This historical accident means that we had a signed socklen_t on 32-bit architectures. */
+typedef int32_t __socklen_t;
+#else
+/* LP64 still has a 32-bit socklen_t. */
+typedef uint32_t __socklen_t;
+#endif
+typedef __socklen_t socklen_t;
+
+typedef __builtin_va_list __va_list;
+
 #ifndef _SSIZE_T_DEFINED_
 #define _SSIZE_T_DEFINED_
 /* Traditionally, bionic's ssize_t was "long int". This caused GCC to emit warnings when you
diff --git a/ndk/platforms/android-20/include/sys/un.h b/ndk/platforms/android-20/include/sys/un.h
index f89ead3..65ffbdc 100644
--- a/ndk/platforms/android-20/include/sys/un.h
+++ b/ndk/platforms/android-20/include/sys/un.h
@@ -28,8 +28,7 @@
 #ifndef _SYS_UN_H_
 #define _SYS_UN_H_
 
-#include <sys/_types.h>
-typedef __sa_family_t sa_family_t;
+typedef unsigned short sa_family_t;
 
 #include <linux/un.h>
 
diff --git a/ndk/platforms/android-20/include/sys/user.h b/ndk/platforms/android-20/include/sys/user.h
index 90cce80..e16b1a5 100644
--- a/ndk/platforms/android-20/include/sys/user.h
+++ b/ndk/platforms/android-20/include/sys/user.h
@@ -30,6 +30,7 @@
 #define _SYS_USER_H_
 
 #include <sys/cdefs.h>
+#include <limits.h> /* For PAGE_SIZE. */
 
 __BEGIN_DECLS
 
diff --git a/ndk/platforms/android-20/include/sys/vfs.h b/ndk/platforms/android-20/include/sys/vfs.h
index fd2655c..cd6044d 100644
--- a/ndk/platforms/android-20/include/sys/vfs.h
+++ b/ndk/platforms/android-20/include/sys/vfs.h
@@ -38,76 +38,74 @@
 typedef struct { int __val[2]; } __fsid_t;
 typedef __fsid_t fsid_t;
 
-#if defined(__LP64__)
-#if defined(__mips__)
-/* 64-bit MIPS */
-struct statfs {
-  uint64_t f_type;
-  uint64_t f_bsize;
-  uint64_t f_frsize; /* Fragment size - unsupported */
-  uint64_t f_blocks;
-  uint64_t f_bfree;
-  uint64_t f_files;
-  uint64_t f_ffree;
-  uint64_t f_bavail;
-  fsid_t f_fsid;
-  uint64_t f_namelen;
-  uint64_t f_flags;
-  uint64_t f_spare[5];
-};
-#else
-struct statfs {
-  uint64_t f_type;
-  uint64_t f_bsize;
-  uint64_t f_blocks;
-  uint64_t f_bfree;
-  uint64_t f_bavail;
-  uint64_t f_files;
-  uint64_t f_ffree;
-  fsid_t f_fsid;
-  uint64_t f_namelen;
-  uint64_t f_frsize;
-  uint64_t f_flags;
-  uint64_t f_spare[4];
-};
-#endif
+#if defined(__aarch64__) || defined(__x86_64__)
+#define __STATFS64_BODY \
+  uint64_t f_type; \
+  uint64_t f_bsize; \
+  uint64_t f_blocks; \
+  uint64_t f_bfree; \
+  uint64_t f_bavail; \
+  uint64_t f_files; \
+  uint64_t f_ffree; \
+  fsid_t f_fsid; \
+  uint64_t f_namelen; \
+  uint64_t f_frsize; \
+  uint64_t f_flags; \
+  uint64_t f_spare[4]; \
+
+#elif defined(__mips__) && defined(__LP64__)
+/* 64-bit MIPS. */
+#define __STATFS64_BODY \
+  uint64_t f_type; \
+  uint64_t f_bsize; \
+  uint64_t f_frsize; /* Fragment size - unsupported. */ \
+  uint64_t f_blocks; \
+  uint64_t f_bfree; \
+  uint64_t f_files; \
+  uint64_t f_ffree; \
+  uint64_t f_bavail; \
+  fsid_t f_fsid; \
+  uint64_t f_namelen; \
+  uint64_t f_flags; \
+  uint64_t f_spare[5]; \
+
 #elif defined(__mips__)
 /* 32-bit MIPS (corresponds to the kernel's statfs64 type). */
-struct statfs {
-  uint32_t f_type;
-  uint32_t f_bsize;
-  uint32_t f_frsize;
-  uint32_t __pad;
-  uint64_t f_blocks;
-  uint64_t f_bfree;
-  uint64_t f_files;
-  uint64_t f_ffree;
-  uint64_t f_bavail;
-  fsid_t f_fsid;
-  uint32_t f_namelen;
-  uint32_t f_flags;
-  uint32_t f_spare[5];
-};
+#define __STATFS64_BODY \
+  uint32_t f_type; \
+  uint32_t f_bsize; \
+  uint32_t f_frsize; \
+  uint32_t __pad; \
+  uint64_t f_blocks; \
+  uint64_t f_bfree; \
+  uint64_t f_files; \
+  uint64_t f_ffree; \
+  uint64_t f_bavail; \
+  fsid_t f_fsid; \
+  uint32_t f_namelen; \
+  uint32_t f_flags; \
+  uint32_t f_spare[5]; \
+
 #else
 /* 32-bit ARM or x86 (corresponds to the kernel's statfs64 type). */
-struct statfs {
-  uint32_t f_type;
-  uint32_t f_bsize;
-  uint64_t f_blocks;
-  uint64_t f_bfree;
-  uint64_t f_bavail;
-  uint64_t f_files;
-  uint64_t f_ffree;
-  fsid_t f_fsid;
-  uint32_t f_namelen;
-  uint32_t f_frsize;
-  uint32_t f_flags;
-  uint32_t f_spare[4];
-};
+#define __STATFS64_BODY \
+  uint32_t f_type; \
+  uint32_t f_bsize; \
+  uint64_t f_blocks; \
+  uint64_t f_bfree; \
+  uint64_t f_bavail; \
+  uint64_t f_files; \
+  uint64_t f_ffree; \
+  fsid_t f_fsid; \
+  uint32_t f_namelen; \
+  uint32_t f_frsize; \
+  uint32_t f_flags; \
+  uint32_t f_spare[4]; \
+
 #endif
 
-/* Source compatibility with glibc. */
-#define statfs64 statfs
+struct statfs { __STATFS64_BODY };
+struct statfs64 { __STATFS64_BODY };
 
 /* Declare that we have the f_namelen, f_frsize, and f_flags fields. */
 #define _STATFS_F_NAMELEN
@@ -160,7 +158,9 @@
 #define  _XIAFS_SUPER_MAGIC    0x012FD16D
 
 extern int statfs(const char*, struct statfs*) __nonnull((1, 2));
+extern int statfs64(const char*, struct statfs64*) __nonnull((1, 2));
 extern int fstatfs(int, struct statfs*) __nonnull((2));
+extern int fstatfs64(int, struct statfs64*) __nonnull((2));
 
 __END_DECLS
 
diff --git a/ndk/platforms/android-20/include/termios.h b/ndk/platforms/android-20/include/termios.h
index 0d44355..b9685ca 100644
--- a/ndk/platforms/android-20/include/termios.h
+++ b/ndk/platforms/android-20/include/termios.h
@@ -31,87 +31,23 @@
 #include <sys/cdefs.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
-#include <stdint.h>
 #include <linux/termios.h>
 
 __BEGIN_DECLS
 
-/* Redefine these to match their ioctl number */
-#undef  TCSANOW
-#define TCSANOW    TCSETS
-
-#undef  TCSADRAIN
-#define TCSADRAIN  TCSETSW
-
-#undef  TCSAFLUSH
-#define TCSAFLUSH  TCSETSF
-
-static __inline__ int tcgetattr(int fd, struct termios *s)
-{
-    return ioctl(fd, TCGETS, s);
-}
-
-static __inline__ int tcsetattr(int fd, int __opt, const struct termios *s)
-{
-    return ioctl(fd, __opt, (void *)s);
-}
-
-static __inline__ int tcflow(int fd, int action)
-{
-    return ioctl(fd, TCXONC, (void *)(intptr_t)action);
-}
-
-static __inline__ int tcflush(int fd, int __queue)
-{
-    return ioctl(fd, TCFLSH, (void *)(intptr_t)__queue);
-}
-
-static __inline__ int tcdrain(int fd)
-{
-    return ioctl(fd, TCSBRK, (void *)(intptr_t)1);
-}
-
-static __inline__ pid_t tcgetsid(int fd)
-{
-    pid_t _pid;
-    return ioctl(fd, TIOCGSID, &_pid) ? (pid_t)-1 : _pid;
-}
-
-static __inline__ int tcsendbreak(int fd, int __duration)
-{
-    return ioctl(fd, TCSBRKP, (void *)(uintptr_t)__duration);
-}
-
-static __inline__ speed_t cfgetospeed(const struct termios *s)
-{
-    return (speed_t)(s->c_cflag & CBAUD);
-}
-
-static __inline__ int cfsetospeed(struct termios *s, speed_t  speed)
-{
-    s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
-    return 0;
-}
-
-static __inline__ speed_t cfgetispeed(const struct termios *s)
-{
-    return (speed_t)(s->c_cflag & CBAUD);
-}
-
-static __inline__ int cfsetispeed(struct termios *s, speed_t  speed)
-{
-    s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD);
-  return 0;
-}
-
-static __inline__ void cfmakeraw(struct termios *s)
-{
-    s->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
-    s->c_oflag &= ~OPOST;
-    s->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
-    s->c_cflag &= ~(CSIZE|PARENB);
-    s->c_cflag |= CS8;
-}
+speed_t cfgetispeed(const struct termios*);
+speed_t cfgetospeed(const struct termios*);
+void cfmakeraw(struct termios*);
+int cfsetispeed(struct termios*, speed_t);
+int cfsetospeed(struct termios*, speed_t);
+int cfsetspeed(struct termios*, speed_t);
+int tcdrain(int);
+int tcflow(int, int);
+int tcflush(int, int);
+int tcgetattr(int, struct termios*);
+pid_t tcgetsid(int);
+int tcsendbreak(int, int);
+int tcsetattr(int, int, const struct termios*);
 
 __END_DECLS
 
diff --git a/ndk/platforms/android-20/include/unistd.h b/ndk/platforms/android-20/include/unistd.h
index 29758f5..d21f23d 100644
--- a/ndk/platforms/android-20/include/unistd.h
+++ b/ndk/platforms/android-20/include/unistd.h
@@ -64,6 +64,7 @@
 
 extern int execv(const char *, char * const *);
 extern int execvp(const char *, char * const *);
+extern int execvpe(const char *, char * const *, char * const *);
 extern int execve(const char *, char * const *, char * const *);
 extern int execl(const char *, const char *, ...);
 extern int execlp(const char *, const char *, ...);
@@ -185,14 +186,15 @@
 
 extern int daemon(int, int);
 
-/* A special syscall that is only available on the ARM, not x86 function. */
-extern int cacheflush(long start, long end, long flags);
+#if defined(__arm__) || (defined(__mips__) && !defined(__LP64__))
+extern int cacheflush(long, long, long);
+    /* __attribute__((deprecated("use __builtin___clear_cache instead"))); */
+#endif
 
 extern pid_t tcgetpgrp(int fd);
 extern int   tcsetpgrp(int fd, pid_t _pid);
 
 #if 0 /* MISSING FROM BIONIC */
-extern int execvpe(const char *, char * const *, char * const *);
 extern int execlpe(const char *, const char *, ...);
 extern int getfsuid(uid_t);
 extern int setfsuid(uid_t);
diff --git a/ndk/platforms/android-20/include/wchar.h b/ndk/platforms/android-20/include/wchar.h
index 76ac02c..32cf127 100644
--- a/ndk/platforms/android-20/include/wchar.h
+++ b/ndk/platforms/android-20/include/wchar.h
@@ -147,6 +147,9 @@
 extern int               wprintf(const wchar_t *, ...);
 extern int               wscanf(const wchar_t *, ...);
 
+extern size_t wcslcat(wchar_t*, const wchar_t*, size_t);
+extern size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
+
 /* No really supported.  These are just for making libstdc++-v3 happy.  */
 typedef void *wctrans_t;
 extern wint_t		 towctrans(wint_t, wctrans_t);