+/*
+ * AMD64 marshalling tests.
+ */
+
+typedef struct amd64_struct1 {
+ int i;
+ int j;
+ int k;
+ int l;
+} amd64_struct1;
+
+STDCALL amd64_struct1
+mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
+{
+ s.i ++;
+ s.j ++;
+ s.k ++;
+ s.l ++;
+
+ return s;
+}
+
+typedef struct amd64_struct2 {
+ int i;
+ int j;
+} amd64_struct2;
+
+STDCALL amd64_struct2
+mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
+{
+ s.i ++;
+ s.j ++;
+
+ return s;
+}
+
+typedef struct amd64_struct3 {
+ int i;
+} amd64_struct3;
+
+STDCALL amd64_struct3
+mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
+{
+ s.i ++;
+
+ return s;
+}
+
+typedef struct amd64_struct4 {
+ double d1, d2;
+} amd64_struct4;
+
+STDCALL amd64_struct4
+mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
+{
+ s.d1 ++;
+ s.d2 ++;
+
+ return s;
+}
+
+static guint32 custom_res [2];
+
+STDCALL void*
+mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
+{
+ /* ptr will be freed by CleanupNative, so make a copy */
+ custom_res [0] = 0; /* not allocated by AllocHGlobal */
+ custom_res [1] = ptr [1];
+
+ return &custom_res;
+}
+
+typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
+
+STDCALL int
+mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
+{
+ guint32 buf [2];
+ guint32 res;
+ guint32 *ptr;
+
+ buf [0] = 0;
+ buf [1] = 10;
+
+ ptr = del (&buf);
+
+ res = ptr [1];
+
+#ifdef WIN32
+ /* FIXME: Freed with FreeHGlobal */
+#else
+ g_free (ptr);
+#endif
+
+ return res;
+}
+
+typedef int (STDCALL *ReturnEnumDelegate) (int e);
+
+STDCALL int
+mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
+{
+ return func (1);
+}
+
+typedef struct {
+ int a, b, c;
+ gint64 d;
+} BlittableStruct;
+
+typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
+
+STDCALL int
+mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
+{
+ BlittableStruct ss, res;
+
+ ss.a = 1;
+ ss.b = 2;
+ ss.c = 3;
+ ss.d = 55;
+
+ res = delegate (ss);
+ if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
+ return 1;