aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Kamensky <victor.kamensky@linaro.org>2013-08-08 20:37:03 -0700
committerRiku Voipio <riku.voipio@linaro.org>2013-08-20 10:09:59 +0300
commit287759ed7af0d2b2d3dadc5ed87d6b4c72f215ff (patch)
treecbcb5547d9e24babbacf19ce3ba4f4b757bb5f63
parentfc8bf09a48c6e220350727814d2c49d45c80dbf2 (diff)
python libffi: fix arm trampoline to work on arm v7 big endian (be8) case
Since python source base has its own copy of libffi, it fixes the issue here. Note similar fix is committed into separate libffi library. cffi code creates trampoline for python callback function, which is supposed to be called from another C function and it does not take into account that in ARMv7a in big endian mode instructions are still in little endian. Since written by big endian code they have to be byteswapped. Proposed fix uses byteswap codes for instructions. Here is python code snippet that will fail when libffi is used by ctypes in python code (func1 and func2 are C functions): from ctypes import * mylib = CDLL("libmytest.so") func1 = mylib.func1 print func1(1, 2) CBFUNC = CFUNCTYPE(c_int, c_int, c_int) def myfunc2(a, b): return a * a + b * b cb_func = CBFUNC(myfunc2) func2 = mylib.func2 print func2(cb_func, 1, 2) code will produce illegal instruction when func2 will call myfunc2 through trampoline Signed-off-by: Victor Kamensky <victor.kamensky@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
-rw-r--r--meta-bigendian/recipes-devtools/python/python/python_ffi_armeb_be8.patch34
-rw-r--r--meta-bigendian/recipes-devtools/python/python_2.7.3.bbappend3
2 files changed, 37 insertions, 0 deletions
diff --git a/meta-bigendian/recipes-devtools/python/python/python_ffi_armeb_be8.patch b/meta-bigendian/recipes-devtools/python/python/python_ffi_armeb_be8.patch
new file mode 100644
index 00000000..afd090b5
--- /dev/null
+++ b/meta-bigendian/recipes-devtools/python/python/python_ffi_armeb_be8.patch
@@ -0,0 +1,34 @@
+Index: Python-2.7.3/Modules/_ctypes/libffi/src/arm/ffi.c
+===================================================================
+--- Python-2.7.3.orig/Modules/_ctypes/libffi/src/arm/ffi.c
++++ Python-2.7.3/Modules/_ctypes/libffi/src/arm/ffi.c
+@@ -272,7 +272,7 @@ ffi_prep_incoming_args_SYSV(char *stack,
+ }
+
+ /* How to make a trampoline. */
+-
++#if !(defined(__ARMEB__) && defined(__ARM_ARCH_7A__))
+ #define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \
+ ({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
+ unsigned int __fun = (unsigned int)(FUN); \
+@@ -284,7 +284,19 @@ ffi_prep_incoming_args_SYSV(char *stack,
+ *(unsigned int*) &__tramp[16] = __fun; \
+ __clear_cache((&__tramp[0]), (&__tramp[19])); \
+ })
+-
++#else /* armv7 big endian: be8 instructions are still little endian */
++#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \
++({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
++ unsigned int __fun = (unsigned int)(FUN); \
++ unsigned int __ctx = (unsigned int)(CTX); \
++ *(unsigned int*) &__tramp[0] = 0x0f002de9; /* swab(0xe92d000f, 4) - stmfd sp!, {r0-r3} */ \
++ *(unsigned int*) &__tramp[4] = 0x00009fe5; /* swab(0xe59f0000, 4) - ldr r0, [pc] */ \
++ *(unsigned int*) &__tramp[8] = 0x00f09fe5; /* swab(0xe59ff000, 4) - ldr pc, [pc] */ \
++ *(unsigned int*) &__tramp[12] = __ctx; \
++ *(unsigned int*) &__tramp[16] = __fun; \
++ __clear_cache((&__tramp[0]), (&__tramp[19])); \
++ })
++#endif
+
+ /* the cif must already be prep'ed */
+
diff --git a/meta-bigendian/recipes-devtools/python/python_2.7.3.bbappend b/meta-bigendian/recipes-devtools/python/python_2.7.3.bbappend
new file mode 100644
index 00000000..a3dfa9bd
--- /dev/null
+++ b/meta-bigendian/recipes-devtools/python/python_2.7.3.bbappend
@@ -0,0 +1,3 @@
+FILESEXTRAPATHS := "${THISDIR}/${PN}"
+
+SRC_URI += "file://python_ffi_armeb_be8.patch"