flush
authorMichael Wallner <mike@php.net>
Wed, 21 Oct 2015 19:56:17 +0000 (21:56 +0200)
committerMichael Wallner <mike@php.net>
Wed, 21 Oct 2015 19:56:17 +0000 (21:56 +0200)
config.m4
src/libffi.c
src/parser.h

index 8e6c1d121253445a11d50ad0d0fbdbea2392ffda..807670c4c4f955de2c8cbe9f307a25215e24a773 100644 (file)
--- 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)
index 1dbc08010023f1e44d53db044ffb83f45eacf853..c6df4276d0f70dbae707e391a8d93a93f5cbfb23 100644 (file)
@@ -4,6 +4,11 @@
 
 #include <ffi.h>
 
+#ifndef PSI_HAVE_FFI_CLOSURE_ALLOC
+# include <unistd.h>
+# include <sys/mman.h>
+#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);
 }
 
index ce74067db65a94d4ba3f6c9f458a1fda5a3504b8..9709a1d81ee854f4f072f8fd767d4ebbde5ba325 100644 (file)
@@ -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));
        }