summaryrefslogtreecommitdiff
blob: f5eebad9edd78a4f7dd9ee21542c41462b055740 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
https://github.com/libffi/libffi/commit/8e3ef965c2d0015ed129a06d0f11f30c2120a413

From 8e3ef965c2d0015ed129a06d0f11f30c2120a413 Mon Sep 17 00:00:00 2001
From: Anthony Green <green@moxielogic.com>
Date: Fri, 28 Jun 2024 04:07:09 -0400
Subject: [PATCH] Fix struct args (Rainer Orth)

---
 src/sparc/ffi.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/sparc/ffi.c b/src/sparc/ffi.c
index 9e406d0af..cf819ee67 100644
--- a/src/sparc/ffi.c
+++ b/src/sparc/ffi.c
@@ -286,6 +286,8 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
 	      void **avalue, void *closure)
 {
   size_t bytes = cif->bytes;
+  size_t i, nargs = cif->nargs;
+  ffi_type **arg_types = cif->arg_types;
 
   FFI_ASSERT (cif->abi == FFI_V8);
 
@@ -295,6 +297,20 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
       && (cif->flags & SPARC_FLAG_RET_MASK) == SPARC_RET_STRUCT)
     bytes += FFI_ALIGN (cif->rtype->size, 8);
 
+  /* If we have any structure arguments, make a copy so we are passing
+     by value.  */
+  for (i = 0; i < nargs; i++)
+    {
+      ffi_type *at = arg_types[i];
+      int size = at->size;
+      if (at->type == FFI_TYPE_STRUCT)
+        {
+          char *argcopy = alloca (size);
+          memcpy (argcopy, avalue[i], size);
+          avalue[i] = argcopy;
+        }
+    }
+
   ffi_call_v8(cif, fn, rvalue, avalue, -bytes, closure);
 }