From 6e86ac39db90a11a1d2c628514b2912dfc491503 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 7 Nov 2011 17:14:41 -0700 Subject: [PATCH] fix native call marshalling on Apple/ARM When the fourth argument is a 64-bit value on the Apple ARM ABI, it is passed half by register and half on the stack, unlike on Linux where it is passed entirely on the stack. The logic to handle this in arm.h was flawed, and this commit fixes it. --- src/arm.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/arm.h b/src/arm.h index a5285f86c3..42fc44e8bf 100644 --- a/src/arm.h +++ b/src/arm.h @@ -146,18 +146,24 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, switch (argumentTypes[ati]) { case DOUBLE_TYPE: case INT64_TYPE: { - if (gprIndex + Alignment <= GprCount) { // pass argument on registers - if (gprIndex % Alignment) { // 8-byte alignment - memset(gprTable + gprIndex, 0, 4); // probably not necessary, but for good luck - ++gprIndex; + if (gprIndex + Alignment <= GprCount) { // pass argument in register(s) + if (Alignment == 1 + and BytesPerWord < 8 + and gprIndex + Alignment == GprCount) + { + gprTable[gprIndex++] = arguments[ai]; + stack[stackIndex++] = arguments[ai + 1]; + } else { + if (gprIndex % Alignment) { + ++gprIndex; + } + + memcpy(gprTable + gprIndex, arguments + ai, 8); + gprIndex += 8 / BytesPerWord; } - - memcpy(gprTable + gprIndex, arguments + ai, 8); - gprIndex += 8 / BytesPerWord; } else { // pass argument on stack gprIndex = GprCount; - if (stackIndex % Alignment) { // 8-byte alignment - memset(stack + stackIndex, 0, 4); // probably not necessary, but for good luck + if (stackIndex % Alignment) { ++stackIndex; }