public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Grégory Pakosz" <gpakosz@myscript.com>
To: "libffi-discuss@sourceware.org" <libffi-discuss@sourceware.org>
Subject: libffi v3.1 - ffi_closure_alloc on Android ARM
Date: Thu, 30 Oct 2014 20:40:00 -0000	[thread overview]
Message-ID: <1414701601287.95688@myscript.com> (raw)

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).​

                 reply	other threads:[~2014-10-30 20:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1414701601287.95688@myscript.com \
    --to=gpakosz@myscript.com \
    --cc=libffi-discuss@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).