Introduce a native-only unwinder build.

Currently libunwind is built to support cross-unwinding [1] by default, which
requires the buffers unw_context_t and unw_cursor_t to be large enough to hold
the vritual register set (VRS) of any supported architecture. This is not
desirable for some platforms where the stack usage of the unwinder needs
to be kept to a minimum (e.g. bare-metal targets). The current patch introduces
a native-only (-DLIBUNWIND_ENABLE_CROSS_UNWINDING=OFF) unwinder variant that
adopts strict sizes for the buffers unw_context_t and unw_cursor_t depending
on the target architecture.

[1] http://www.nongnu.org/libunwind/man/libunwind(3).html#section_4

Change-Id: I380fff9a56c16a0fc520e3b1d8454a34b4a48373

git-svn-id: https://llvm.org/svn/llvm-project/libunwind/trunk@270692 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/config.h b/src/config.h
index 46bb08a..151030c 100644
--- a/src/config.h
+++ b/src/config.h
@@ -119,5 +119,25 @@
   #define _LIBUNWIND_TRACING_UNWINDING logUnwinding()
 #endif
 
+#ifdef __cplusplus
+// Used to fit UnwindCursor and Registers_xxx types against unw_context_t /
+// unw_cursor_t sized memory blocks.
+#if defined(_LIBUNWIND_IS_NATIVE_ONLY)
+# define COMP_OP ==
+#else
+# define COMP_OP <
+#endif
+template <typename _Type, typename _Mem>
+struct check_fit {
+  template <typename T>
+  struct blk_count {
+    static const uint32_t count =
+      (sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t);
+  };
+  static const bool does_fit =
+    (blk_count<_Type>::count COMP_OP blk_count<_Mem>::count);
+};
+#undef COMP_OP
+#endif // __cplusplus
 
 #endif // LIBUNWIND_CONFIG_H