Bug 1526653 - Include struct definitions for user_vfp and user_vfp_exc.
authorMike Hommey <mh@glandium.org>
Sat, 1 Jun 2019 00:06:01 +0000 (09:06 +0900)
committerCarsten Schoenert <c.schoenert@t-online.de>
Wed, 6 Apr 2022 18:08:25 +0000 (19:08 +0100)
Gbp-Pq: Topic porting-armhf
Gbp-Pq: Name Bug-1526653-Include-struct-definitions-for-user_vfp-and-u.patch

js/src/wasm/WasmSignalHandlers.cpp

index 1229c30e819b3b938ddb1b104fe0b3328399d2b1..37a82f87b22dc23e6481971cfe947485937b7bed 100644 (file)
@@ -233,6 +233,37 @@ using mozilla::DebugOnly;
 #  error "Don't know how to read/write to the thread state via the mcontext_t."
 #endif
 
+// On ARM Linux, including Android, unaligned FP accesses that were not flagged
+// as unaligned will tend to trap (with SIGBUS) and will need to be emulated.
+//
+// We can only perform this emulation if the system header files provide access
+// to the FP registers.  In particular, <sys/user.h> must have definitions of
+// `struct user_vfp` and `struct user_vfp_exc`, as it does on Android.
+//
+// Those definitions are however not present in the headers of every Linux
+// distro - Raspbian is known to be a problem, for example.  However those
+// distros are tier-3 platforms.
+//
+// If you run into compile problems on a tier-3 platform, you can disable the
+// emulation here.
+
+#if defined(__linux__) && defined(__arm__)
+#  define WASM_EMULATE_ARM_UNALIGNED_FP_ACCESS
+#endif
+
+#ifdef WASM_EMULATE_ARM_UNALIGNED_FP_ACCESS
+struct user_vfp {
+  unsigned long long fpregs[32];
+  unsigned long fpscr;
+};
+
+struct user_vfp_exc {
+  unsigned long fpexc;
+  unsigned long fpinst;
+  unsigned long fpinst2;
+};
+#endif
+
 #if defined(ANDROID)
 // Not all versions of the Android NDK define ucontext_t or mcontext_t.
 // Detect this and provide custom but compatible definitions. Note that these