mirror of
https://github.com/janet-lang/janet
synced 2025-01-12 08:30:26 +00:00
Address #1037 - move stack hack after arg writing logic to avoid
clobber.
This commit is contained in:
parent
1cebe64664
commit
43c47ac44c
@ -154,6 +154,7 @@ void void_ret_fn(int x) {
|
||||
|
||||
EXPORTER
|
||||
int intintint_fn_2(intintint iii, int i) {
|
||||
fprintf(stderr, "iii.a = %d, iii.b = %d, iii.c = %d, i = %d\n", iii.a, iii.b, iii.c, i);
|
||||
return i * (iii.a + iii.b + iii.c);
|
||||
}
|
||||
|
||||
|
@ -1093,8 +1093,8 @@ static Janet janet_ffi_win64(JanetFFISignature *signature, void *function_pointe
|
||||
ret_mem = alloca(type_size(signature->ret.type));
|
||||
regs[0].integer = (uint64_t) ret_mem;
|
||||
}
|
||||
uint64_t *stack = alloca(signature->stack_count * 8);
|
||||
stack -= 2; /* hack to get proper stack placement */
|
||||
size_t stack_size = signature->stack_count * 8;
|
||||
uint64_t *stack = alloca(stack_size);
|
||||
for (uint32_t i = 0; i < signature->arg_count; i++) {
|
||||
int32_t n = i + 2;
|
||||
JanetFFIMapping arg = signature->args[i];
|
||||
@ -1113,6 +1113,10 @@ static Janet janet_ffi_win64(JanetFFISignature *signature, void *function_pointe
|
||||
}
|
||||
}
|
||||
|
||||
/* hack to get proper stack placement and avoid clobbering from logic above - shift stack down, otherwise we have issues.
|
||||
* Technically, this writes into 16 bytes of unallocated stack memory */
|
||||
if (stack_size) memmove(stack - 2, stack, stack_size);
|
||||
|
||||
switch (signature->variant) {
|
||||
default:
|
||||
janet_panicf("unknown variant %d", signature->variant);
|
||||
|
Loading…
Reference in New Issue
Block a user