From c9598604c6872d87b6c818c92efc4bce357d988c Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 18 Jun 2016 00:18:01 +0300 Subject: unix/alloc: Add option to use uPy's alloc-exec implementation even for libffi. When built for Linux, libffi includes very bloated and workaround exec-alloc implementation required to work around SELinux and other "sekuritee" features which real people don't use. MicroPython has own alloc-exec implementation, used to alloc memory for @micropython.native code. With this option enabled, uPy's implementation will override libffi's. This saves 11K on x86_64 (and that accounts for more than half of the libffi code size). TODO: Possibly, we want to refactor this option to allow either use uPy's implementation even for libffi, or allow to use libffi's implementation even for uPy. --- unix/alloc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'unix/alloc.c') diff --git a/unix/alloc.c b/unix/alloc.c index a0676a0aef..72b9d2a872 100644 --- a/unix/alloc.c +++ b/unix/alloc.c @@ -33,7 +33,7 @@ #include "py/mpstate.h" #include "py/gc.h" -#if MICROPY_EMIT_NATIVE +#if MICROPY_EMIT_NATIVE || (MICROPY_PY_FFI && MICROPY_FORCE_PLAT_ALLOC_EXEC) #if defined(__OpenBSD__) || defined(__MACH__) #define MAP_ANONYMOUS MAP_ANON @@ -85,4 +85,16 @@ void mp_unix_mark_exec(void) { } } -#endif // MICROPY_EMIT_NATIVE +#if MICROPY_FORCE_PLAT_ALLOC_EXEC +void *ffi_closure_alloc(size_t size, void **code) { + mp_uint_t dummy; + mp_unix_alloc_exec(size, code, &dummy); + return *code; +} + +void ffi_closure_free(void *ptr) { + // TODO +} +#endif + +#endif // MICROPY_EMIT_NATIVE || (MICROPY_PY_FFI && MICROPY_FORCE_PLAT_ALLOC_EXEC) -- cgit v1.2.3 From 7c8d76fad34cbb75b9f7faec156e88632631f127 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 18 Jun 2016 00:36:13 +0300 Subject: unix/alloc: Make coverage build and its overzealous warnings happy. --- unix/alloc.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'unix/alloc.c') diff --git a/unix/alloc.c b/unix/alloc.c index 72b9d2a872..04c635ee97 100644 --- a/unix/alloc.c +++ b/unix/alloc.c @@ -86,6 +86,12 @@ void mp_unix_mark_exec(void) { } #if MICROPY_FORCE_PLAT_ALLOC_EXEC +// Provide implementation of libffi ffi_closure_* functions in terms +// of the functions above. On a normal Linux system, this save a lot +// of code size. +void *ffi_closure_alloc(size_t size, void **code); +void ffi_closure_free(void *ptr); + void *ffi_closure_alloc(size_t size, void **code) { mp_uint_t dummy; mp_unix_alloc_exec(size, code, &dummy); @@ -93,6 +99,7 @@ void *ffi_closure_alloc(size_t size, void **code) { } void ffi_closure_free(void *ptr) { + (void)ptr; // TODO } #endif -- cgit v1.2.3