-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
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
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)
#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) {
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,
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;
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);
}