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>
Fri, 12 May 2023 16:30:14 +0000 (17:30 +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 67d18a9ebb738586c42003903ac922e8b4f752ae..8420b878a38da635b06b14da8317cc77b220ba35 100644 (file)
@@ -243,7 +243,38 @@ using mozilla::DebugOnly;
         "Don't know how to read/write to the thread state via the mcontext_t."
 #  endif
 
-#  if defined(ANDROID)
+// 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
 // follow the GLibc naming convention to access register values from