From a0eddff5de5f71e5f9fdb7402f0cc0c920c5cb1e Mon Sep 17 00:00:00 2001 From: Andy Street Date: Thu, 4 Feb 2016 08:38:17 -0800 Subject: [PATCH] Force stack alignment on x86 devices Summary: public JSC enforces a stack-alignment that wasn't always being provided on x86 builds. See D2886997. Reviewed By: foghina Differential Revision: D2900982 fb-gh-sync-id: 3f8dffcc1c528a4c21d7ed0b17e49d87761b1df7 --- ReactAndroid/src/main/jni/react/JSCHelpers.h | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/jni/react/JSCHelpers.h b/ReactAndroid/src/main/jni/react/JSCHelpers.h index 7ac633075ce414..de3bfbacbf15fa 100644 --- a/ReactAndroid/src/main/jni/react/JSCHelpers.h +++ b/ReactAndroid/src/main/jni/react/JSCHelpers.h @@ -20,6 +20,25 @@ JSValueRef makeJSCException( JSContextRef ctx, const char* exception_text); -JSValueRef evaluateScript(JSContextRef context, JSStringRef script, JSStringRef source, const char *cachePath = nullptr); +#ifdef __i386__ +// The Android x86 ABI states that the NDK toolchain assumes 16 byte stack +// alignment: http://developer.android.com/ndk/guides/x86.html JSC checks for +// stack alignment, and fails with SIGTRAP if it is not. Empirically, the +// google android x86 emulator does not provide this alignment, and so JSC +// calls may crash. All checked calls go through here, so the attribute here +// is added to force alignment and prevent crashes. + +JSValueRef evaluateScript( + JSContextRef ctx, + JSStringRef script, + JSStringRef sourceURL, + const char* cachePath = nullptr) __attribute__((force_align_arg_pointer)); +#else +JSValueRef evaluateScript( + JSContextRef ctx, + JSStringRef script, + JSStringRef sourceURL, + const char* cachePath = nullptr); +#endif } }