File capnproto-0.5.3-big-endian-async-unix.patch of Package capnproto

Description:  Fix UnixEventPort value on 32-bit big endian arch
 toRegularSiginfo attempts to convert signalfd_siginfo.ssi_ptr (a 64-bit
 integer across all architectures) to a pointer. On 32-bit big endian
 architectures, sival_int/sival_ptr will be stored in the high 32-bits
 of the ssi_ptr value.

 Prior to this change, the value was "lost" as we cast away the high
 bits of ssi_ptr in the conversion to a 32-bit pointer.

 This fixes AsyncUnixTest::SignalWith{,Pointer}Value on affected archs.

Author: Tom Lee <debian@tomlee.co>
Forwarded: https://github.com/sandstorm-io/capnproto/pull/260
Last-Update: 2015-11-07
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/configure.ac
+++ b/configure.ac
@@ -52,6 +52,19 @@
 AC_LANG([C++])
 AX_CXX_COMPILE_STDCXX_11
 
+AC_C_BIGENDIAN([CXXFLAGS="$CXXFLAGS -D_KJ_BIGENDIAN=1"],
+               [CXXFLAGS="$CXXFLAGS -D_KJ_BIGENDIAN=0"],
+               [AC_MSG_WARN([could not determine system endianness: assuming little endian])
+                CXXFLAGS="$CXXFLAGS -D_KJ_BIGENDIAN=0"])
+
+AC_CHECK_SIZEOF([void*])
+AC_MSG_CHECKING([architecture pointer size])
+AS_IF([test "x$ac_cv_sizeof_voidp" = "x8"],
+      [CXXFLAGS="$CXXFLAGS -D_KJ_64BIT=1"
+       AC_MSG_RESULT([64-bit])],
+      [CXXFLAGS="$CXXFLAGS -D_KJ_64BIT=0"
+       AC_MSG_RESULT([32-bit])])
+
 AS_CASE("${host_os}", *mingw*, [
     # We don't use pthreads on MinGW.
     PTHREAD_CFLAGS="-mthreads"
--- a/src/kj/async-unix.c++
+++ b/src/kj/async-unix.c++
@@ -458,7 +458,11 @@
         // we write the pointer, we'll end up with the right value for the int? Presumably the
         // two fields of signalfd_siginfo are actually extracted from one of these unions
         // originally, so actually contain redundant data? Better write some tests...
+#if _KJ_BIGENDIAN && !_KJ_64BIT
+        result.si_ptr = reinterpret_cast<void*>(static_cast<uintptr_t>(siginfo.ssi_ptr >> 32));
+#else
         result.si_ptr = reinterpret_cast<void*>(static_cast<uintptr_t>(siginfo.ssi_ptr));
+#endif
         break;
 
       case SI_TIMER: