This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libffi v3.1 - ffi_closure_alloc on Android ARM


Hello,

When building libffi for Android ARM, invoking anÂffiÂclosure justÂcrashesÂwith SIGSEGV / SEGV_ACCERR (code 2).


It happens malloc on Android doesn't set PROT_EXEC contrary to Linux. As a consequence, to make closures work on Android, I had to tweak fficonfig.h by adding the following preprocessor  definitions:


#define FFI_MMAP_EXEC_WRIT Â Â Â 1
#define FFI_MMAP_EXEC_SELINUXÂ0

Otherwise, compiled ffi_closure_alloc is the one that just callsÂreturn *code = malloc (size);

Is defining those two preprocessor tokens the recommended way? If not, is there a better way?


Thank you,
Gregory.


PS: Here are the steps I used to build libffi

$Â/opt/android-ndk/build/tools/make-standalone-toolchain.sh --arch=arm --instal-dir=/tmp/android-arm

$ export PATH=/tmp/android-arm/bin:$PATH

$ cd ~/libffi
$ git checkout v3.1
$ mkdir build-android-arm
$ cd build-android-arm
$ ../configureÂ--host=arm-linux-androideabi

And here are the defines in the generatedÂfficonfig.h

#define EH_FRAME_FLAGS "aw"
#define HAVE_ALLOCA 1
#define HAVE_ALLOCA_H 1
#define HAVE_AS_CFI_PSEUDO_OP 1
#define HAVE_DLFCN_H 1
#define HAVE_HIDDEN_VISIBILITY_ATTRIBUTE 1
#define HAVE_INTTYPES_H 1
#define HAVE_MEMCPY 1
#define HAVE_MEMORY_H 1
#define HAVE_MMAP 1
#define HAVE_MMAP_ANON 1
#define HAVE_MMAP_DEV_ZERO 1
#define HAVE_MMAP_FILE 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_SYS_MMAN_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_UNISTD_H 1
#define SIZEOF_DOUBLE 8
#define SIZEOF_LONG_DOUBLE 8
#define SIZEOF_SIZE_T 4
#define STDC_HEADERS 1â


PS2: for the record, Android 2.2 or 2.3's malloc set PROT_EXEC. I'm not sure if behavior changed withÂHoneycomb (3.0â3.2.6), Ice Cream Sandwich (4.0â4.0.4) or Jelly Bean (4.1â4.3.â1).â

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]