Skip to content

Commit

Permalink
aarch64: Fix closures for win64
Browse files Browse the repository at this point in the history
Cherry-pick of libffi/libffi#606
  • Loading branch information
AndreRH authored and tresf committed Jan 12, 2021
1 parent ffb7e0e commit 2732f2c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions native/libffi/src/aarch64/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ ffi_prep_closure_loc (ffi_closure *closure,
void *user_data,
void *codeloc)
{
if (cif->abi != FFI_SYSV)
if (cif->abi != FFI_SYSV && cif->abi != FFI_WIN64)
return FFI_BAD_ABI;

void (*start)(void);
Expand Down Expand Up @@ -851,7 +851,7 @@ ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif* cif,
{
void (*start)(void);

if (cif->abi != FFI_SYSV)
if (cif->abi != FFI_SYSV && cif->abi != FFI_WIN64)
return FFI_BAD_ABI;

if (cif->flags & AARCH64_FLAG_ARG_V)
Expand Down Expand Up @@ -891,11 +891,18 @@ ffi_closure_SYSV_inner (ffi_cif *cif,
void *stack, void *rvalue, void *struct_rvalue)
{
void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
int i, h, nargs, flags;
int i, h, nargs, flags, isvariadic = 0;
struct arg_state state;

arg_init (&state);

flags = cif->flags;
if (flags & AARCH64_FLAG_VARARG)
{
isvariadic = 1;
flags &= ~AARCH64_FLAG_VARARG;
}

for (i = 0, nargs = cif->nargs; i < nargs; i++)
{
ffi_type *ty = cif->arg_types[i];
Expand Down Expand Up @@ -930,8 +937,7 @@ ffi_closure_SYSV_inner (ffi_cif *cif,
if (h)
{
n = 4 - (h & 3);
#ifdef _WIN32 /* for handling armasm calling convention */
if (cif->is_variadic)
if (cif->abi == FFI_WIN64 && isvariadic)
{
if (state.ngrn + n <= N_X_ARG_REG)
{
Expand All @@ -957,7 +963,6 @@ ffi_closure_SYSV_inner (ffi_cif *cif,
}
else
{
#endif /* for handling armasm calling convention */
if (state.nsrn + n <= N_V_ARG_REG)
{
void *reg = &context->v[state.nsrn];
Expand All @@ -970,9 +975,7 @@ ffi_closure_SYSV_inner (ffi_cif *cif,
avalue[i] = allocate_to_stack(&state, stack,
ty->alignment, s);
}
#ifdef _WIN32 /* for handling armasm calling convention */
}
#endif /* for handling armasm calling convention */
}
else if (s > 16)
{
Expand Down Expand Up @@ -1013,7 +1016,6 @@ ffi_closure_SYSV_inner (ffi_cif *cif,
#endif
}

flags = cif->flags;
if (flags & AARCH64_RET_IN_MEM)
rvalue = struct_rvalue;

Expand Down

0 comments on commit 2732f2c

Please sign in to comment.