From: Michael Wallner Date: Wed, 21 Oct 2015 19:56:17 +0000 (+0200) Subject: flush X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7eb47ef2fc5655e7196e4e0fbf5104eed8274601;p=m6w6%2Fext-psi flush --- diff --git a/config.m4 b/config.m4 index 8e6c1d1..807670c 100644 --- a/config.m4 +++ b/config.m4 @@ -1,20 +1,23 @@ -PHP_ARG_WITH(psi, whether to enable psi support, -[ --with-psi[[=path to libjit]] - Enable PHP System Interface support]) +PHP_ARG_ENABLE(psi, whether to enable psi support, +[ --enable-psi Enable PHP System Interface support]) +PHP_ARG_WITH(psi-libjit, where to find libjit, +[ --with-psi-libjit=DIR PSI: path to libjit]) +PHP_ARG_WITH(psi-libffi, where to find libjit, +[ --with-psi-libffi=DIR PSI: path to libffi]) if test "$PHP_PSI" != "no"; then AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project) AC_PATH_PROG(LEMON, lemon, ./lemon) PHP_SUBST(LEMON) - + if test -z "$PKG_CONFIG" then AC_PATH_PROG(PKG_CONFIG, pkg-config, false) fi - - export PKG_CONFIG_PATH="/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH" - - AC_CACHE_CHECK(for libffi, PSI_cv_LIBFFI, [ + + export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH" + + AC_CACHE_CHECK(for libffi through pkg-config, PSI_cv_LIBFFI, [ if $PKG_CONFIG --exists libffi then PSI_cv_LIBFFI=true @@ -26,11 +29,38 @@ if test "$PHP_PSI" != "no"; then PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`) PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD) else - AC_MSG_ERROR([Could not find libjit, please provide the base install path]) + AC_CACHE_CHECK(for libffi, PSI_cv_LIBFFI_DIR, [ + for PSI_cv_LIBFFI_DIR in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi} + do + if test -e $PSI_cv_LIBFFI_DIR/include/ffi/ffi.h + then + break + fi + PSI_cv_LIBFFI_DIR= + done]) + if test -n "$PSI_cv_LIBFFI_DIR" + then + PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [ + AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ]) + ], [ + ], -L$PSI_cv_LIBFFI_DIR/$PHP_LIBDIR) + PHP_CHECK_LIBRARY(ffi, ffi_closure_free, [ + AC_DEFINE(PSI_HAVE_FFI_CLOSURE_FREE, 1, [ ]) + ], [ + ], -L$PSI_cv_LIBFFI_DIR/$PHP_LIBDIR) + PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [ + AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ]) + ], [ + ], -L$PSI_cv_LIBFFI_DIR/$PHP_LIBDIR) + PHP_ADD_INCLUDE($PSI_cv_LIBFFI_DIR/include/ffi) + PHP_ADD_LIBRARY_WITH_PATH(ffi, $PSI_cv_LIBFFI_DIR/$PHP_LIBDIR, PSI_SHARED_LIBADD) + else + AC_MSG_WARN([Could not find libffi, please provide the base install path]) + fi fi AC_CACHE_CHECK(for libjit, PSI_cv_LIBJIT_DIR, [ - for PSI_cv_LIBJIT_DIR in $PHP_PSI {/usr{,/local},/opt}{,libjit} + for PSI_cv_LIBJIT_DIR in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit} do if test -e $PSI_cv_LIBJIT_DIR/include/jit/jit.h then @@ -43,9 +73,9 @@ if test "$PHP_PSI" != "no"; then PHP_ADD_INCLUDE($PSI_cv_LIBJIT_DIR/include) PHP_ADD_LIBRARY_WITH_PATH(jit, $PSI_cv_LIBJIT_DIR/$PHP_LIBDIR, PSI_SHARED_LIBADD) else - AC_MSG_ERROR([Could not find libjit, please provide the base install path]) + AC_MSG_WARN([Could not find libjit, please provide the base install path]) fi - + PHP_SUBST(PSI_SHARED_LIBADD) PHP_PSI_SRCDIR=PHP_EXT_SRCDIR(psi) diff --git a/src/libffi.c b/src/libffi.c index 1dbc080..c6df427 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -4,6 +4,11 @@ #include +#ifndef PSI_HAVE_FFI_CLOSURE_ALLOC +# include +# include +#endif + static void handler(ffi_cif *signature, void *_result, void **_args, void *_data); static inline ffi_abi psi_ffi_abi(const char *convention) { @@ -98,6 +103,8 @@ static inline PSI_LibffiData *PSI_LibffiDataAlloc(PSI_LibffiContext *context, im psi_ffi_decl_arg_type(data->impl->decl->func), data->params); ZEND_ASSERT(FFI_OK == rc); + +#ifdef PSI_HAVE_FFI_CLOSURE_ALLOC data->closure = ffi_closure_alloc(sizeof(ffi_closure), &data->code); rc = ffi_prep_closure_loc( data->closure, @@ -106,6 +113,15 @@ static inline PSI_LibffiData *PSI_LibffiDataAlloc(PSI_LibffiContext *context, im data, data->code); ZEND_ASSERT(FFI_OK == rc); +#else + i = getpagesize(); + data->closure = malloc(sizeof(ffi_closure) + i); + data->code = (void *) (((intptr_t) data->closure + i - 1) & ~((intptr_t) i - 1)); + rc = mprotect(data->code, sizeof(ffi_closure), PROT_EXEC|PROT_WRITE); + ZEND_ASSERT(rc == 0); + rc = ffi_prep_closure(data->code, &context->signature, handler, data); + ZEND_ASSERT(FFI_OK == rc); +#endif context->data.list = realloc(context->data.list, ++context->data.count * sizeof(*context->data.list)); context->data.list[context->data.count-1] = data; @@ -115,7 +131,11 @@ static inline PSI_LibffiData *PSI_LibffiDataAlloc(PSI_LibffiContext *context, im static inline void PSI_LibffiDataFree(PSI_LibffiData *data) { free(data->arginfo); +#ifdef PSI_HAVE_FFI_CLOSURE_FREE ffi_closure_free(data->closure); +#else + free(data->closure); +#endif free(data); } diff --git a/src/parser.h b/src/parser.h index ce74067..9709a1d 100644 --- a/src/parser.h +++ b/src/parser.h @@ -70,7 +70,7 @@ typedef struct decl_typedefs { decl_typedef **list; } decl_typedefs; -static decl_typedefs *add_decl_typedef(decl_typedefs *defs, decl_typedef *def) { +static inline decl_typedefs *add_decl_typedef(decl_typedefs *defs, decl_typedef *def) { if (!defs) { defs = calloc(1, sizeof(*defs)); } @@ -681,7 +681,7 @@ typedef struct impls { impl **list; } impls; -static impls *add_impl(impls *impls, impl *impl) { +static inline impls *add_impl(impls *impls, impl *impl) { if (!impls) { impls = calloc(1, sizeof(*impls)); }