Various MSVC-related changes.
This commit is contained in:
committed by
Anthony Green
parent
e1539266e6
commit
0a1ab12a8d
@@ -58,7 +58,8 @@ void ffi_prep_args(char *stack, extended_cif *ecif)
|
||||
|
||||
argp = stack;
|
||||
|
||||
if (ecif->cif->flags == FFI_TYPE_STRUCT
|
||||
if ((ecif->cif->flags == FFI_TYPE_STRUCT
|
||||
|| ecif->cif->flags == FFI_TYPE_MS_STRUCT)
|
||||
#ifdef X86_WIN64
|
||||
&& (ecif->cif->rtype->size != 1 && ecif->cif->rtype->size != 2
|
||||
&& ecif->cif->rtype->size != 4 && ecif->cif->rtype->size != 8)
|
||||
@@ -279,7 +280,10 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cif->flags = FFI_TYPE_STRUCT;
|
||||
if (cif->abi == FFI_MS_CDECL)
|
||||
cif->flags = FFI_TYPE_MS_STRUCT;
|
||||
else
|
||||
cif->flags = FFI_TYPE_STRUCT;
|
||||
/* allocate space for return value pointer */
|
||||
cif->bytes += ALIGN(sizeof(void*), FFI_SIZEOF_ARG);
|
||||
}
|
||||
@@ -349,7 +353,8 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
||||
}
|
||||
#else
|
||||
if (rvalue == NULL
|
||||
&& cif->flags == FFI_TYPE_STRUCT)
|
||||
&& (cif->flags == FFI_TYPE_STRUCT
|
||||
|| cif->flags == FFI_TYPE_MS_STRUCT))
|
||||
{
|
||||
ecif.rvalue = alloca(cif->rtype->size);
|
||||
}
|
||||
@@ -368,6 +373,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
||||
#elif defined(X86_WIN32)
|
||||
case FFI_SYSV:
|
||||
case FFI_STDCALL:
|
||||
case FFI_MS_CDECL:
|
||||
ffi_call_win32(ffi_prep_args, &ecif, cif->abi, cif->bytes, cif->flags,
|
||||
ecif.rvalue, fn);
|
||||
break;
|
||||
@@ -513,7 +519,8 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, void **avalue,
|
||||
argp += sizeof(void *);
|
||||
}
|
||||
#else
|
||||
if ( cif->flags == FFI_TYPE_STRUCT ) {
|
||||
if ( cif->flags == FFI_TYPE_STRUCT
|
||||
|| cif->flags == FFI_TYPE_MS_STRUCT ) {
|
||||
*rvalue = *(void **) argp;
|
||||
argp += sizeof(void *);
|
||||
}
|
||||
@@ -673,6 +680,12 @@ ffi_prep_closure_loc (ffi_closure* closure,
|
||||
&ffi_closure_STDCALL,
|
||||
(void*)codeloc, cif->bytes);
|
||||
}
|
||||
else if (cif->abi == FFI_MS_CDECL)
|
||||
{
|
||||
FFI_INIT_TRAMPOLINE (&closure->tramp[0],
|
||||
&ffi_closure_SYSV,
|
||||
(void*)codeloc);
|
||||
}
|
||||
#endif /* X86_WIN32 */
|
||||
#endif /* !X86_WIN64 */
|
||||
else
|
||||
@@ -762,8 +775,9 @@ ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *fake_avalue)
|
||||
/* If the return value is a struct and we don't have a return */
|
||||
/* value address then we need to make one */
|
||||
|
||||
if ((rvalue == NULL) &&
|
||||
(cif->rtype->type == FFI_TYPE_STRUCT))
|
||||
if (rvalue == NULL
|
||||
&& (cif->flags == FFI_TYPE_STRUCT
|
||||
|| cif->flags == FFI_TYPE_MS_STRUCT))
|
||||
{
|
||||
ecif.rvalue = alloca(cif->rtype->size);
|
||||
}
|
||||
@@ -776,6 +790,7 @@ ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *fake_avalue)
|
||||
#ifdef X86_WIN32
|
||||
case FFI_SYSV:
|
||||
case FFI_STDCALL:
|
||||
case FFI_MS_CDECL:
|
||||
ffi_call_win32(ffi_prep_args_raw, &ecif, cif->abi, cif->bytes, cif->flags,
|
||||
ecif.rvalue, fn);
|
||||
break;
|
||||
|
||||
@@ -80,9 +80,13 @@ typedef enum ffi_abi {
|
||||
FFI_STDCALL,
|
||||
FFI_THISCALL,
|
||||
FFI_FASTCALL,
|
||||
FFI_MS_CDECL,
|
||||
FFI_LAST_ABI,
|
||||
/* TODO: Add fastcall support for the sake of completeness */
|
||||
#ifdef _MSC_VER
|
||||
FFI_DEFAULT_ABI = FFI_MS_CDECL
|
||||
#else
|
||||
FFI_DEFAULT_ABI = FFI_SYSV
|
||||
#endif
|
||||
|
||||
#elif defined(X86_WIN64)
|
||||
FFI_WIN64,
|
||||
@@ -109,6 +113,7 @@ typedef enum ffi_abi {
|
||||
#define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
|
||||
#define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
|
||||
#define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
|
||||
#define FFI_TYPE_MS_STRUCT (FFI_TYPE_LAST + 4)
|
||||
|
||||
#if defined (X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
|
||||
#define FFI_TRAMPOLINE_SIZE 24
|
||||
|
||||
@@ -121,6 +121,7 @@ ca_jumpdata:
|
||||
dd offset ca_retint8 ;; FFI_TYPE_SMALL_STRUCT_1B
|
||||
dd offset ca_retint16 ;; FFI_TYPE_SMALL_STRUCT_2B
|
||||
dd offset ca_retint ;; FFI_TYPE_SMALL_STRUCT_4B
|
||||
dd offset ca_epilogue ;; FFI_TYPE_MS_STRUCT
|
||||
|
||||
ca_retint8:
|
||||
;; Load %ecx with the pointer to storage for the return value
|
||||
@@ -171,8 +172,6 @@ ca_epilogue:
|
||||
ffi_call_win32 ENDP
|
||||
|
||||
ffi_closure_THISCALL PROC NEAR FORCEFRAME
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
sub esp, 40
|
||||
lea edx, [ebp -24]
|
||||
mov [ebp - 12], edx /* resp */
|
||||
@@ -217,6 +216,7 @@ cs_jumpdata:
|
||||
dd offset cs_retint8 ;; FFI_TYPE_SMALL_STRUCT_1B
|
||||
dd offset cs_retint16 ;; FFI_TYPE_SMALL_STRUCT_2B
|
||||
dd offset cs_retint ;; FFI_TYPE_SMALL_STRUCT_4B
|
||||
dd offset cs_retmsstruct ;; FFI_TYPE_MS_STRUCT
|
||||
|
||||
cs_retint8:
|
||||
mov al, [ecx]
|
||||
@@ -252,6 +252,12 @@ cs_retstruct:
|
||||
;; Epilogue code is autogenerated.
|
||||
ret 4
|
||||
|
||||
cs_retmsstruct:
|
||||
;; Caller expects us to return a pointer to the real return value.
|
||||
mov eax, ecx
|
||||
;; Caller doesn't expects us to pop struct return value pointer hidden arg.
|
||||
jmp cs_epilogue
|
||||
|
||||
cs_epilogue:
|
||||
;; Epilogue code is autogenerated.
|
||||
ret
|
||||
@@ -264,19 +270,16 @@ ffi_closure_SYSV ENDP
|
||||
#define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
|
||||
#define CIF_FLAGS_OFFSET 20
|
||||
|
||||
ffi_closure_raw_THISCALL PROC NEAR
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push esi
|
||||
ffi_closure_raw_THISCALL PROC NEAR USES esi FORCEFRAME
|
||||
sub esp, 36
|
||||
mov esi, [eax + RAW_CLOSURE_CIF_OFFSET] ;; closure->cif
|
||||
mov edx, [eax + RAW_CLOSURE_USER_DATA_OFFSET] ;; closure->user_data
|
||||
mov [esp + 12], edx
|
||||
lea edx, [ebp + 12], edx
|
||||
lea edx, [ebp + 12]
|
||||
jmp stubraw
|
||||
ffi_closure_raw_SYSV ENDP
|
||||
ffi_closure_raw_THISCALL ENDP
|
||||
|
||||
ffi_closure_raw_SYSV PROC NEAR USES esi
|
||||
ffi_closure_raw_SYSV PROC NEAR USES esi FORCEFRAME
|
||||
;; the ffi_closure ctx is passed in eax by the trampoline.
|
||||
|
||||
sub esp, 40
|
||||
@@ -284,7 +287,7 @@ ffi_closure_raw_SYSV PROC NEAR USES esi
|
||||
mov edx, [eax + RAW_CLOSURE_USER_DATA_OFFSET] ;; closure->user_data
|
||||
mov [esp + 12], edx ;; user_data
|
||||
lea edx, [ebp + 8]
|
||||
stubraw:
|
||||
stubraw::
|
||||
mov [esp + 8], edx ;; raw_args
|
||||
lea edx, [ebp - 24]
|
||||
mov [esp + 4], edx ;; &res
|
||||
@@ -315,6 +318,7 @@ cr_jumpdata:
|
||||
dd offset cr_retint8 ;; FFI_TYPE_SMALL_STRUCT_1B
|
||||
dd offset cr_retint16 ;; FFI_TYPE_SMALL_STRUCT_2B
|
||||
dd offset cr_retint ;; FFI_TYPE_SMALL_STRUCT_4B
|
||||
dd offset cr_epilogue ;; FFI_TYPE_MS_STRUCT
|
||||
|
||||
cr_retint8:
|
||||
mov al, [ecx]
|
||||
@@ -515,6 +519,7 @@ _ffi_call_win32:
|
||||
.long .Lretstruct1b /* FFI_TYPE_SMALL_STRUCT_1B */
|
||||
.long .Lretstruct2b /* FFI_TYPE_SMALL_STRUCT_2B */
|
||||
.long .Lretstruct4b /* FFI_TYPE_SMALL_STRUCT_4B */
|
||||
.long .Lretstruct /* FFI_TYPE_MS_STRUCT */
|
||||
1:
|
||||
add %ecx, %ecx
|
||||
add %ecx, %ecx
|
||||
@@ -657,6 +662,7 @@ _ffi_closure_SYSV:
|
||||
.long .Lcls_retstruct1 /* FFI_TYPE_SMALL_STRUCT_1B */
|
||||
.long .Lcls_retstruct2 /* FFI_TYPE_SMALL_STRUCT_2B */
|
||||
.long .Lcls_retstruct4 /* FFI_TYPE_SMALL_STRUCT_4B */
|
||||
.long .Lcls_retmsstruct /* FFI_TYPE_MS_STRUCT */
|
||||
|
||||
1:
|
||||
add %eax, %eax
|
||||
@@ -721,6 +727,12 @@ _ffi_closure_SYSV:
|
||||
popl %ebp
|
||||
ret $0x4
|
||||
|
||||
.Lcls_retmsstruct:
|
||||
# Caller expects us to return a pointer to the real return value.
|
||||
mov %ecx, %eax
|
||||
# Caller doesn't expects us to pop struct return value pointer hidden arg.
|
||||
jmp .Lcls_epilogue
|
||||
|
||||
.Lcls_noretval:
|
||||
.Lcls_epilogue:
|
||||
movl %ebp, %esp
|
||||
@@ -798,6 +810,7 @@ _ffi_closure_raw_SYSV:
|
||||
.long .Lrcls_retstruct1 /* FFI_TYPE_SMALL_STRUCT_1B */
|
||||
.long .Lrcls_retstruct2 /* FFI_TYPE_SMALL_STRUCT_2B */
|
||||
.long .Lrcls_retstruct4 /* FFI_TYPE_SMALL_STRUCT_4B */
|
||||
.long .Lrcls_retstruct /* FFI_TYPE_MS_STRUCT */
|
||||
1:
|
||||
add %eax, %eax
|
||||
add %eax, %eax
|
||||
|
||||
Reference in New Issue
Block a user