Commit e27f70b8cf2a537bef84b2cb29ad8ea6209a11b8

Anthony Green 2018-04-08T18:25:34

Fix case where callback arg value is split across regs and stack

diff --git a/src/moxie/ffi.c b/src/moxie/ffi.c
index 0846b27..21144e8 100644
--- a/src/moxie/ffi.c
+++ b/src/moxie/ffi.c
@@ -215,7 +215,18 @@ void ffi_closure_eabi (unsigned arg1, unsigned arg2, unsigned arg3,
 	  break;
 	default:
 	  /* This is an 8-byte value.  */
-	  avalue[i] = ptr;
+	  if (ptr == (char *) &register_args[5])
+	    {
+	      /* The value is split across two locations */
+	      unsigned *ip = alloca(8);
+	      avalue[i] = ip;
+	      ip[0] = *(unsigned *) ptr;
+	      ip[1] = *(unsigned *) stack_args;
+	    }
+	  else
+	    {
+	      avalue[i] = ptr;
+	    }
 	  ptr += 4;
 	  break;
 	}
@@ -223,9 +234,9 @@ void ffi_closure_eabi (unsigned arg1, unsigned arg2, unsigned arg3,
 
       /* If we've handled more arguments than fit in registers,
 	 start looking at the those passed on the stack.  */
-      if (ptr == &register_args[6])
+      if (ptr == (char *) &register_args[6])
 	ptr = stack_args;
-      else if (ptr == &register_args[7])
+      else if (ptr == (char *) &register_args[7])
 	ptr = stack_args + 4;
     }