Merge pie-platform-release to aosp-master - DO NOT MERGE

Change-Id: I877db669c268caa222a398d36ba090ab04a186da
diff --git a/Android.bp b/Android.bp
index 167f6b0..2a84000 100644
--- a/Android.bp
+++ b/Android.bp
@@ -18,6 +18,7 @@
     name: "libc++abi",
     host_supported: true,
     vendor_available: true,
+    recovery_available: true,
     srcs: [
         "src/abort_message.cpp",
         "src/cxa_aux_runtime.cpp",
@@ -51,6 +52,8 @@
         "-fexceptions",
         "-Wextra",
         "-Wno-unused-function",
+        "-Wno-implicit-fallthrough",
+        // src/cxa_demangle.cpp:2591 -Wimplicit-fallthrough
     ],
     sanitize: {
         never: true,
@@ -92,6 +95,30 @@
             cppflags: ["-DHAVE___CXA_THREAD_ATEXIT_IMPL"],
             enabled: true,
         },
+        windows: {
+            enabled: true,
+            cppflags: [
+                "-D_LIBCPP_HAS_THREAD_API_WIN32",
+                "-D_LIBCXXABI_BUILDING_LIBRARY",
+                "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
+                "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
+            ],
+            exclude_srcs: [
+                "src/cxa_thread_atexit.cpp",
+
+                // Building stdlib_new_delete.cpp in libcxxabi causes
+                // multiple-definition errors against definitions in
+                // libcxx/src/new.cpp on Windows.  This works on Linux and
+                // Android where the functions have 'weak' linkage and are
+                // discarded by the linker.
+                "src/stdlib_new_delete.cpp",
+            ],
+        },
+        windows_x86: {
+            cppflags: [
+                "-fsjlj-exceptions",
+            ],
+        }
     },
 
 }
diff --git a/src/cxa_personality.cpp b/src/cxa_personality.cpp
index 7f857fa..6759d8a 100644
--- a/src/cxa_personality.cpp
+++ b/src/cxa_personality.cpp
@@ -23,6 +23,16 @@
 #include "private_typeinfo.h"
 #include "unwind.h"
 
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+#include <windows.h>
+#include <winnt.h>
+
+extern "C" EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD,
+                                                       void *, PCONTEXT,
+                                                       PDISPATCHER_CONTEXT,
+                                                       _Unwind_Personality_Fn);
+#endif
+
 /*
     Exception Header Layout:
 
@@ -934,12 +944,16 @@
 */
 
 #if !defined(_LIBCXXABI_ARM_EHABI)
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+static _Unwind_Reason_Code __gxx_personality_imp
+#else
 _LIBCXXABI_FUNC_VIS _Unwind_Reason_Code
 #ifdef __USING_SJLJ_EXCEPTIONS__
 __gxx_personality_sj0
 #else
 __gxx_personality_v0
 #endif
+#endif
                     (int version, _Unwind_Action actions, uint64_t exceptionClass,
                      _Unwind_Exception* unwind_exception, _Unwind_Context* context)
 {
@@ -1022,6 +1036,17 @@
     // We were called improperly: neither a phase 1 or phase 2 search
     return _URC_FATAL_PHASE1_ERROR;
 }
+
+#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
+extern "C" EXCEPTION_DISPOSITION
+__gxx_personality_seh0(PEXCEPTION_RECORD ms_exc, void *this_frame,
+                       PCONTEXT ms_orig_context, PDISPATCHER_CONTEXT ms_disp)
+{
+  return _GCC_specific_handler(ms_exc, this_frame, ms_orig_context, ms_disp,
+                               __gxx_personality_imp);
+}
+#endif
+
 #else
 
 extern "C" _Unwind_Reason_Code __gnu_unwind_frame(_Unwind_Exception*,
diff --git a/src/private_typeinfo.cpp b/src/private_typeinfo.cpp
index ef9466e..653c937 100644
--- a/src/private_typeinfo.cpp
+++ b/src/private_typeinfo.cpp
@@ -64,6 +64,7 @@
         return x == y;
     return strcmp(x->name(), y->name()) == 0;
 #else
+    (void) use_strcmp;
     return (x == y) || (strcmp(x->name(), y->name()) == 0);
 #endif
 }