diff --git a/src/foreign/libffi_msvc/ffi.c b/src/foreign/libffi_msvc/ffi.c index 5c49b39de3..9af6b716d2 100644 --- a/src/foreign/libffi_msvc/ffi.c +++ b/src/foreign/libffi_msvc/ffi.c @@ -26,8 +26,6 @@ OTHER DEALINGS IN THE SOFTWARE. ----------------------------------------------------------------------- */ -#ifndef __x86_64__ - #include #include @@ -143,11 +141,7 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) /*@-declundef@*/ /*@-exportheader@*/ -#ifdef _MSC_VER extern int -#else -extern void -#endif ffi_call_SYSV(void (*)(char *, extended_cif *), /*@out@*/ extended_cif *, unsigned, unsigned, @@ -156,14 +150,9 @@ ffi_call_SYSV(void (*)(char *, extended_cif *), /*@=declundef@*/ /*@=exportheader@*/ -#if defined(X86_WIN32) || defined(_MSC_VER) /*@-declundef@*/ /*@-exportheader@*/ -#ifdef _MSC_VER extern int -#else -extern void -#endif ffi_call_STDCALL(void (*)(char *, extended_cif *), /*@out@*/ extended_cif *, unsigned, unsigned, @@ -171,13 +160,8 @@ ffi_call_STDCALL(void (*)(char *, extended_cif *), void (*fn)()); /*@=declundef@*/ /*@=exportheader@*/ -#endif /* X86_WIN32 || _MSC_VER*/ -#ifdef _MSC_VER int -#else -void -#endif ffi_call(/*@dependent@*/ ffi_cif *cif, void (*fn)(), /*@out@*/ void *rvalue, @@ -206,24 +190,18 @@ ffi_call(/*@dependent@*/ ffi_cif *cif, { case FFI_SYSV: /*@-usedef@*/ -#ifdef _MSC_VER - return -#endif - ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, - cif->flags, ecif.rvalue, fn); + return ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, + cif->flags, ecif.rvalue, fn); /*@=usedef@*/ break; -#if defined(X86_WIN32) || defined(_MSC_VER) + case FFI_STDCALL: /*@-usedef@*/ -#ifdef _MSC_VER - return -#endif - ffi_call_STDCALL(ffi_prep_args, &ecif, cif->bytes, - cif->flags, ecif.rvalue, fn); + return ffi_call_STDCALL(ffi_prep_args, &ecif, cif->bytes, + cif->flags, ecif.rvalue, fn); /*@=usedef@*/ break; -#endif /* X86_WIN32 */ + default: FFI_ASSERT(0); break; @@ -236,23 +214,10 @@ ffi_call(/*@dependent@*/ ffi_cif *cif, static void ffi_prep_incoming_args_SYSV (char *stack, void **ret, void** args, ffi_cif* cif); -#ifndef _MSC_VER -static void ffi_closure_SYSV (ffi_closure *) - __attribute__ ((regparm(1))); -static void ffi_closure_raw_SYSV (ffi_raw_closure *) - __attribute__ ((regparm(1))); -#endif - /* This function is jumped to by the trampoline */ -#ifdef _MSC_VER static void __fastcall ffi_closure_SYSV (ffi_closure *closure, int *argp) -#else -static void -ffi_closure_SYSV (closure) - ffi_closure *closure; -#endif { // this is our return value storage long double res; @@ -262,11 +227,7 @@ ffi_closure_SYSV (closure) void **arg_area; unsigned short rtype; void *resp = (void*)&res; -#ifdef _MSC_VER void *args = &argp[1]; -#else - void *args = __builtin_dwarf_cfa (); -#endif cif = closure->cif; arg_area = (void**) alloca (cif->nargs * sizeof (void*)); @@ -388,10 +349,6 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, /* How to make a trampoline. Derived from gcc/config/i386/i386.c. */ -/* MOV EDX, ESP is 0x8b 0xd4 */ - -#ifdef _MSC_VER - #define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX,BYTES) \ { unsigned char *__tramp = (unsigned char*)(TRAMP); \ unsigned int __fun = (unsigned int)(FUN); \ @@ -400,26 +357,13 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, *(unsigned char*) &__tramp[0] = 0xb9; \ *(unsigned int*) &__tramp[1] = __ctx; /* mov ecx, __ctx */ \ *(unsigned char*) &__tramp[5] = 0x8b; \ - *(unsigned char*) &__tramp[6] = 0xd4; \ + *(unsigned char*) &__tramp[6] = 0xd4; /* mov edx, esp */ \ *(unsigned char*) &__tramp[7] = 0xe8; \ *(unsigned int*) &__tramp[8] = __dis; /* call __fun */ \ *(unsigned char*) &__tramp[12] = 0xC2; /* ret BYTES */ \ *(unsigned short*) &__tramp[13] = BYTES; \ } -#else -#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX,BYTES) \ -({ unsigned char *__tramp = (unsigned char*)(TRAMP); \ - unsigned int __fun = (unsigned int)(FUN); \ - unsigned int __ctx = (unsigned int)(CTX); \ - unsigned int __dis = __fun - ((unsigned int) __tramp + FFI_TRAMPOLINE_SIZE); \ - *(unsigned char*) &__tramp[0] = 0xb8; \ - *(unsigned int*) &__tramp[1] = __ctx; /* movl __ctx, %eax */ \ - *(unsigned char *) &__tramp[5] = 0xe9; \ - *(unsigned int*) &__tramp[6] = __dis; /* jmp __fun */ \ - }) -#endif - /* the cif must already be prep'ed */ ffi_status @@ -433,10 +377,8 @@ ffi_prep_closure (ffi_closure* closure, if (cif->abi == FFI_SYSV) bytes = 0; -#ifdef _MSC_VER else if (cif->abi == FFI_STDCALL) bytes = cif->bytes; -#endif else return FFI_BAD_ABI; @@ -450,5 +392,3 @@ ffi_prep_closure (ffi_closure* closure, return FFI_OK; } - -#endif /* __x86_64__ */ diff --git a/src/foreign/libffi_msvc/ffi.h b/src/foreign/libffi_msvc/ffi.h index b9d31fdae7..203142d9ce 100644 --- a/src/foreign/libffi_msvc/ffi.h +++ b/src/foreign/libffi_msvc/ffi.h @@ -272,11 +272,7 @@ ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype, /*@dependent@*/ ffi_type **atypes); -#ifdef _MSC_VER int -#else -void -#endif ffi_call(/*@dependent@*/ ffi_cif *cif, void (*fn)(), /*@out@*/ void *rvalue, diff --git a/src/foreign/libffi_msvc/ffi_common.h b/src/foreign/libffi_msvc/ffi_common.h index 1b948d54ae..43fb83b481 100644 --- a/src/foreign/libffi_msvc/ffi_common.h +++ b/src/foreign/libffi_msvc/ffi_common.h @@ -13,24 +13,7 @@ extern "C" { #endif #include - -/* Do not move this. Some versions of AIX are very picky about where - this is positioned. */ -#ifdef __GNUC__ -# define alloca __builtin_alloca -#else -# if HAVE_ALLOCA_H -# include -# else -# ifdef _AIX - #pragma alloca -# else -# ifndef alloca /* predefined by HP cc +Olibcalls */ -char *alloca (); -# endif -# endif -# endif -#endif +#include /* Check for the existence of memcpy. */ #if STDC_HEADERS diff --git a/src/foreign/libffi_msvc/fficonfig.h b/src/foreign/libffi_msvc/fficonfig.h index 25b630593d..c14f653ec8 100644 --- a/src/foreign/libffi_msvc/fficonfig.h +++ b/src/foreign/libffi_msvc/fficonfig.h @@ -3,8 +3,10 @@ /* fficonfig.h. Generated automatically by configure. */ /* fficonfig.h.in. Generated automatically from configure.in by autoheader. */ -/* Defines for MSVC */ +/* Define this for MSVC, but not for mingw32! */ +#ifdef _MSC_VER #define __attribute__(x) /* */ +#endif #define alloca _alloca /*----------------------------------------------------------------*/ diff --git a/src/foreign/libffi_msvc/ffitarget.h b/src/foreign/libffi_msvc/ffitarget.h index c9d95bc8d5..78c0c37cae 100644 --- a/src/foreign/libffi_msvc/ffitarget.h +++ b/src/foreign/libffi_msvc/ffitarget.h @@ -43,23 +43,21 @@ typedef enum ffi_abi { FFI_FIRST_ABI = 0, /* ---- Intel x86 Win32 ---------- */ -#if defined(X86_WIN32) || defined(_MSC_VER) FFI_SYSV, FFI_STDCALL, /* TODO: Add fastcall support for the sake of completeness */ FFI_DEFAULT_ABI = FFI_SYSV, -#endif /* ---- Intel x86 and AMD x86-64 - */ -#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__)) - FFI_SYSV, - FFI_UNIX64, /* Unix variants all use the same ABI for x86-64 */ -#ifdef __i386__ - FFI_DEFAULT_ABI = FFI_SYSV, -#else - FFI_DEFAULT_ABI = FFI_UNIX64, -#endif -#endif +/* #if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__)) */ +/* FFI_SYSV, */ +/* FFI_UNIX64,*/ /* Unix variants all use the same ABI for x86-64 */ +/* #ifdef __i386__ */ +/* FFI_DEFAULT_ABI = FFI_SYSV, */ +/* #else */ +/* FFI_DEFAULT_ABI = FFI_UNIX64, */ +/* #endif */ +/* #endif */ FFI_LAST_ABI = FFI_DEFAULT_ABI + 1 } ffi_abi; @@ -73,11 +71,7 @@ typedef enum ffi_abi { #define FFI_TRAMPOLINE_SIZE 24 #define FFI_NATIVE_RAW_API 0 #else -#ifdef _MSC_VER -# define FFI_TRAMPOLINE_SIZE 15 -#else -# define FFI_TRAMPOLINE_SIZE 10 -#endif +#define FFI_TRAMPOLINE_SIZE 15 #define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */ #endif diff --git a/src/foreign/libffi_msvc/prep_cif.c b/src/foreign/libffi_msvc/prep_cif.c index 9edce2f65b..2650fa0525 100644 --- a/src/foreign/libffi_msvc/prep_cif.c +++ b/src/foreign/libffi_msvc/prep_cif.c @@ -147,7 +147,7 @@ ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, else #endif { -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(__MINGW32__) /* Don't know if this is a libffi bug or not. At least on Windows with MSVC, function call parameters are *not* aligned in the same way as structure fields are, they are diff --git a/src/foreign/libffi_msvc/win32.S b/src/foreign/libffi_msvc/win32.S index 40743af589..cc82ab91e2 100644 --- a/src/foreign/libffi_msvc/win32.S +++ b/src/foreign/libffi_msvc/win32.S @@ -41,7 +41,11 @@ _ffi_call_SYSV: pushl %ebp movl %esp,%ebp - + + #THe: save previous %esi, and store the current stack pointer in %esi + pushl %esi + movl %esp,%esi + # Make room for all of the new args. movl 16(%ebp),%ecx subl %ecx,%esp @@ -64,7 +68,9 @@ _ffi_call_SYSV: # Remove the space we pushed for the args movl 16(%ebp),%ecx addl %ecx,%esp - + + sub %esp,%esi # calculate stack pointer difference + # Load %ecx with the return type code movl 20(%ebp),%ecx @@ -125,6 +131,8 @@ retstruct: noretval: epilogue: + movl %esi,%eax # return the stack pointer detlta in %eax + popl %esi # restore previous %esi movl %ebp,%esp popl %ebp ret @@ -139,6 +147,10 @@ _ffi_call_STDCALL: pushl %ebp movl %esp,%ebp + #THe: save previous %esi, and store the current stack pointer in %esi + pushl %esi + movl %esp,%esi + # Make room for all of the new args. movl 16(%ebp),%ecx subl %ecx,%esp @@ -158,6 +170,8 @@ _ffi_call_STDCALL: call *28(%ebp) + sub %esp,%esi # difference in stack + # stdcall functions pop arguments off the stack themselves # Load %ecx with the return type code @@ -220,6 +234,8 @@ sc_retstruct: sc_noretval: sc_epilogue: + movl %esi,%eax # return the stack difference + popl %esi # restore previous %esi value movl %ebp,%esp popl %ebp ret