From e82854b435ee087e5eb6af926866c9f2d810a5fe Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 8 Feb 2017 19:26:54 +0100 Subject: [PATCH] abi: support for most basic calling conventions --- README.md | 2 +- m4/psi/psi.m4 | 7 +++++++ src/libffi.c | 12 ++++++++++++ src/libjit.c | 6 ++++++ src/types/decl_abi.c | 1 - 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d20134..3b4c478 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ extern char *strerror(int errnum); You may specify a non-standard calling convention in place of `extern`, where `default` and `cdecl` have the same meaning as `extern`. -Additionally recognized calling conventions include: `mscdecl`, `stdcall` and `fastcall`. +Additionally recognized calling conventions include: `stdcall` and `fastcall`. ### Constants diff --git a/m4/psi/psi.m4 b/m4/psi/psi.m4 index 6787834..9bb1a4b 100644 --- a/m4/psi/psi.m4 +++ b/m4/psi/psi.m4 @@ -470,6 +470,13 @@ AC_DEFUN(PSI_CHECK_LIBFFI, [ AC_MSG_WARN([Could not find libffi, please provide the base install path]) fi fi + + save_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS $INCLUDES" + AC_CHECK_DECL(FFI_STDCALL,[AC_DEFINE([HAVE_FFI_STDCALL],[1],[ ])],,[#include "ffi.h"]) + AC_CHECK_DECL(FFI_FASTCALL,[AC_DEFINE([HAVE_FFI_FASTCALL],[1],[ ])],,[#include "ffi.h"]) + CFLAGS=$save_CFLAGS + PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [ PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [ AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ]) diff --git a/src/libffi.c b/src/libffi.c index e859dbd..644b0fe 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -156,6 +156,18 @@ static void psi_ffi_callback(ffi_cif *sig, void *result, void **args, void *data } static inline ffi_abi psi_ffi_abi(const char *convention) { + if (FFI_LAST_ABI - 2 != FFI_FIRST_ABI) { +#ifdef HAVE_FFI_STDCALL + if (!strcasecmp(convention, "stdcall")) { + return FFI_STDCALL; + } +#endif +#ifdef HAVE_FFI_FASTCALL + if (!strcasecmp(convention, "fastcall")) { + return FFI_FASTCALL; + } +#endif + } return FFI_DEFAULT_ABI; } diff --git a/src/libjit.c b/src/libjit.c index 338e8a7..a32742a 100644 --- a/src/libjit.c +++ b/src/libjit.c @@ -36,6 +36,12 @@ static inline jit_type_t psi_jit_decl_arg_type(struct psi_decl_arg *darg); static inline jit_abi_t psi_jit_abi(const char *convention) { + if (!strcasecmp(convention, "stdcall")) { + return jit_abi_stdcall; + } + if (!strcasecmp(convention, "fastcall")) { + return jit_abi_fastcall; + } return jit_abi_cdecl; } static inline jit_type_t psi_jit_token_type(token_t t) diff --git a/src/types/decl_abi.c b/src/types/decl_abi.c index 3db51e6..60ad161 100644 --- a/src/types/decl_abi.c +++ b/src/types/decl_abi.c @@ -56,7 +56,6 @@ static const char * const abi_ccs[] = { "default", /* \ */ "extern", /* > - all the same */ "cdecl", /* / */ - "mscdecl", "stdcall", "fastcall", }; -- 2.30.2