2 using System
.Runtime
.InteropServices
;
4 [StructLayout (LayoutKind
.Sequential
)]
7 public winx64_struct1 (byte ia
)
14 [StructLayout (LayoutKind
.Sequential
)]
17 public winx64_struct2 (byte ia
, byte ib
)
27 [StructLayout (LayoutKind
.Sequential
)]
30 public winx64_struct3 (byte ia
, byte ib
, short ic
)
42 [StructLayout (LayoutKind
.Sequential
)]
45 public winx64_struct4 (byte ia
, byte ib
, short ic
, uint id
)
59 [StructLayout (LayoutKind
.Sequential
)]
62 public winx64_struct5 (byte ia
, byte ib
, byte ic
)
74 [StructLayout (LayoutKind
.Sequential
)]
77 public winx64_struct6 (winx64_struct1 ia
, short ib
, byte ic
)
84 public winx64_struct1 a
;
89 [StructLayout (LayoutKind
.Sequential
)]
90 struct winx64_floatStruct
92 public winx64_floatStruct (float ia
, float ib
)
102 [StructLayout (LayoutKind
.Sequential
)]
103 struct winx64_doubleStruct
105 public winx64_doubleStruct (double ia
)
115 [DllImport ("libtest")]
116 static extern int mono_test_Winx64_struct1_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1
var);
118 [DllImport ("libtest")]
119 static extern int mono_test_Winx64_struct2_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct2
var);
121 [DllImport ("libtest")]
122 static extern int mono_test_Winx64_struct3_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct3
var);
124 [DllImport ("libtest")]
125 static extern int mono_test_Winx64_struct4_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct4
var);
127 [DllImport ("libtest")]
128 static extern int mono_test_Winx64_struct5_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct5
var);
130 [DllImport ("libtest")]
131 static extern int mono_test_Winx64_struct6_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct6
var);
133 [DllImport ("libtest")]
134 static extern int mono_test_Winx64_structs_in1 ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var1
,
135 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct2 var2
,
136 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct3 var3
,
137 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct4 var4
);
139 [DllImport ("libtest")]
140 static extern int mono_test_Winx64_structs_in2 ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var1
,
141 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var2
,
142 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var3
,
143 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var4
,
144 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var5
);
146 [DllImport ("libtest")]
147 static extern int mono_test_Winx64_structs_in3 ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var1
,
148 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct5 var2
,
149 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var3
,
150 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct5 var4
,
151 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var5
,
152 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct5 var6
);
154 [DllImport ("libtest")]
155 [return:MarshalAs (UnmanagedType
.Struct
)]
156 static extern winx64_struct1
mono_test_Winx64_struct1_ret ();
158 [DllImport ("libtest")]
159 [return: MarshalAs (UnmanagedType
.Struct
)]
160 static extern winx64_struct2
mono_test_Winx64_struct2_ret ();
162 [DllImport ("libtest")]
163 [return: MarshalAs (UnmanagedType
.Struct
)]
164 static extern winx64_struct3
mono_test_Winx64_struct3_ret ();
166 [DllImport ("libtest")]
167 [return: MarshalAs (UnmanagedType
.Struct
)]
168 static extern winx64_struct4
mono_test_Winx64_struct4_ret ();
170 [DllImport ("libtest")]
171 [return: MarshalAs (UnmanagedType
.Struct
)]
172 static extern winx64_struct5
mono_test_Winx64_struct5_ret ();
174 [DllImport ("libtest")]
175 [return: MarshalAs (UnmanagedType
.Struct
)]
176 static extern winx64_struct1
mono_test_Winx64_struct1_ret_5_args (byte a
, byte b
, byte c
, byte d
, byte e
);
178 [DllImport ("libtest")]
179 [return: MarshalAs (UnmanagedType
.Struct
)]
180 static extern winx64_struct5
mono_test_Winx64_struct5_ret6_args (byte a
, byte b
, byte c
, byte d
, byte e
);
182 [DllImport ("libtest")]
183 static extern int mono_test_Winx64_floatStruct ([MarshalAs (UnmanagedType
.Struct
)] winx64_floatStruct
var);
185 [DllImport ("libtest")]
186 static extern int mono_test_Winx64_doubleStruct ([MarshalAs (UnmanagedType
.Struct
)] winx64_doubleStruct
var);
188 public delegate int managed_struct1_delegate ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1
var);
190 [DllImport ("libtest")]
191 static extern int mono_test_managed_Winx64_struct1_in (managed_struct1_delegate func
);
193 public delegate int managed_struct5_delegate ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct5
var);
195 [DllImport ("libtest")]
196 static extern int mono_test_managed_Winx64_struct5_in (managed_struct5_delegate func
);
198 public delegate int managed_struct1_struct5_delegate (winx64_struct1 var1
, winx64_struct5 var2
,
199 winx64_struct1 var3
, winx64_struct5 var4
,
200 winx64_struct1 var5
, winx64_struct5 var6
);
202 [DllImport ("libtest")]
203 static extern int mono_test_managed_Winx64_struct1_struct5_in (managed_struct1_struct5_delegate func
);
205 [return:MarshalAs (UnmanagedType
.Struct
)]
206 public delegate winx64_struct1
mono_test_Winx64_struct1_ret_delegate ();
208 [DllImport ("libtest")]
209 static extern int mono_test_Winx64_struct1_ret_managed (mono_test_Winx64_struct1_ret_delegate func
);
211 [return: MarshalAs (UnmanagedType
.Struct
)]
212 public delegate winx64_struct5
mono_test_Winx64_struct5_ret_delegate ();
214 [DllImport ("libtest")]
215 static extern int mono_test_Winx64_struct5_ret_managed (mono_test_Winx64_struct5_ret_delegate func
);
218 private static bool enableBroken
= false;
220 static int Main (string[] args
)
222 return TestDriver
.RunTests (typeof (winx64structs
), args
);
225 public static int test_0_In_Args_Value_In_RCX ()
229 winx64_struct1 t_winx64_struct1
= new winx64_struct1 (123);
231 if ((retCode
= mono_test_Winx64_struct1_in (t_winx64_struct1
)) != 0)
232 return 100 + retCode
;
234 winx64_struct2 t_winx64_struct2
= new winx64_struct2 (4, 5);
236 if ((retCode
= mono_test_Winx64_struct2_in (t_winx64_struct2
)) != 0)
237 return 200 + retCode
;
239 winx64_struct3 t_winx64_struct3
= new winx64_struct3 (4, 5, 0x1234);
241 if ((retCode
= mono_test_Winx64_struct3_in (t_winx64_struct3
)) != 0)
242 return 300 + retCode
;
244 winx64_struct4 t_winx64_struct4
= new winx64_struct4 (4, 5, 0x1234, 0x87654321);
246 if ((retCode
= mono_test_Winx64_struct4_in (t_winx64_struct4
)) != 0)
247 return 400 + retCode
;
249 winx64_floatStruct t_winx64_floatStruct
= new winx64_floatStruct (5.5F
, 9.5F
);
251 if ((retCode
= mono_test_Winx64_floatStruct (t_winx64_floatStruct
)) != 0)
252 return 500 + retCode
;
254 winx64_doubleStruct t_winx64_doubleStruct
= new winx64_doubleStruct (5.5F
);
256 if ((retCode
= mono_test_Winx64_doubleStruct (t_winx64_doubleStruct
)) != 0)
257 return 600 + retCode
;
262 public static int test_0_In_Args_Values_In_Multiple_Registers ()
266 winx64_struct1 t_winx64_struct1
= new winx64_struct1 (123);
267 winx64_struct2 t_winx64_struct2
= new winx64_struct2 (4, 5);
268 winx64_struct3 t_winx64_struct3
= new winx64_struct3 (4, 5, 0x1234);
269 winx64_struct4 t_winx64_struct4
= new winx64_struct4 (4, 5, 0x1234, 0x87654321);
271 if ((retCode
= mono_test_Winx64_structs_in1 (t_winx64_struct1
, t_winx64_struct2
,
272 t_winx64_struct3
, t_winx64_struct4
)) != 0)
273 return 100 + retCode
;
279 public static int test_0_Ret_In_RAX ()
281 winx64_struct1 t_winx64_struct1
= mono_test_Winx64_struct1_ret ();
282 if (t_winx64_struct1
.a
!= 123)
285 winx64_struct2 t_winx64_struct2
= mono_test_Winx64_struct2_ret ();
286 if (t_winx64_struct2
.a
!= 4)
288 if (t_winx64_struct2
.b
!= 5)
291 winx64_struct3 t_winx64_struct3
= mono_test_Winx64_struct3_ret ();
292 if (t_winx64_struct3
.a
!= 4)
294 if (t_winx64_struct3
.b
!= 5)
296 if (t_winx64_struct3
.c
!= 0x1234)
299 winx64_struct4 t_winx64_struct4
= mono_test_Winx64_struct4_ret ();
300 if (t_winx64_struct4
.a
!= 4)
302 if (t_winx64_struct4
.b
!= 5)
304 if (t_winx64_struct4
.c
!= 0x1234)
306 if (t_winx64_struct4
.d
!= 0x87654321)
309 t_winx64_struct1
= mono_test_Winx64_struct1_ret_5_args (0x1, 0x0, 0x4, 0x10, 0x40);
310 if (t_winx64_struct1
.a
!= 0x55)
316 public static int test_0_Ret_In_Address ()
318 winx64_struct5 t_winx64_struct5
= mono_test_Winx64_struct5_ret ();
319 if (t_winx64_struct5
.a
!= 4)
321 if (t_winx64_struct5
.b
!= 5)
323 if (t_winx64_struct5
.c
!= 6)
326 t_winx64_struct5
= mono_test_Winx64_struct5_ret6_args (0x1, 0x4, 0x2, 0x8, 0x30);
327 if (t_winx64_struct5
.a
!= 0x5)
329 if (t_winx64_struct5
.b
!= 0xa)
331 if (t_winx64_struct5
.c
!= 0x30)
337 public static int test_0_In_Args_Values_In_Registers_and_Stack ()
341 winx64_struct1 var1
= new winx64_struct1 (1);
342 winx64_struct1 var2
= new winx64_struct1 (2);
343 winx64_struct1 var3
= new winx64_struct1 (3);
344 winx64_struct1 var4
= new winx64_struct1 (4);
345 winx64_struct1 var5
= new winx64_struct1 (5);
347 if ((retCode
= mono_test_Winx64_structs_in2 (var1
, var2
, var3
, var4
, var5
)) != 0)
348 return 100 + retCode
;
353 public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack ()
357 winx64_struct1 var1
= new winx64_struct1 (1);
358 winx64_struct5 var2
= new winx64_struct5 (2, 3, 4);
359 winx64_struct1 var3
= new winx64_struct1 (5);
360 winx64_struct5 var4
= new winx64_struct5 (6, 7, 8);
361 winx64_struct1 var5
= new winx64_struct1 (9);
362 winx64_struct5 var6
= new winx64_struct5 (10, 11, 12);
364 if ((retCode
= mono_test_Winx64_structs_in3 (var1
, var2
, var3
, var4
, var5
, var6
)) != 0)
365 return 100 + retCode
;
370 public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX ()
374 winx64_struct5 t_winx64_struct5
= new winx64_struct5 (4, 5, 6);
375 t_winx64_struct5
.a
= 4;
376 t_winx64_struct5
.b
= 5;
377 t_winx64_struct5
.c
= 6;
379 if ((retCode
= mono_test_Winx64_struct5_in (t_winx64_struct5
)) != 0)
380 return 100 + retCode
;
382 winx64_struct6 t_winx64_struct6
= new winx64_struct6 (new winx64_struct1 (4), 5, 6);
384 if ((retCode
= mono_test_Winx64_struct6_in (t_winx64_struct6
)) != 0)
385 return 200 + retCode
;
390 public static int test_0_In_Args_Value_In_RCX_Managed ()
394 managed_struct1_delegate s1Del
= new managed_struct1_delegate (managed_struct1_test
);
396 if ((retCode
= mono_test_managed_Winx64_struct1_in (s1Del
)) != 0)
397 return 100 + retCode
;
402 public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX_Managed ()
406 managed_struct5_delegate s1Del
= new managed_struct5_delegate (managed_struct5_test
);
408 if ((retCode
= mono_test_managed_Winx64_struct5_in (s1Del
)) != 0)
409 return 100 + retCode
;
414 public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack_Managed ()
418 managed_struct1_struct5_delegate s1Del
=
419 new managed_struct1_struct5_delegate (managed_struct1_struct5_test
);
421 if ((retCode
= mono_test_managed_Winx64_struct1_struct5_in (s1Del
)) != 0)
422 return 100 + retCode
;
427 public static int test_0_Ret_In_RAX_managed ()
431 mono_test_Winx64_struct1_ret_delegate s1Del
=
432 new mono_test_Winx64_struct1_ret_delegate (mono_test_Winx64_struct1_ret_test
);
434 if ((retCode
= mono_test_Winx64_struct1_ret_managed (s1Del
)) != 0)
435 return 100 + retCode
;
440 public static int test_0_Ret_In_Address_managed ()
444 mono_test_Winx64_struct5_ret_delegate s1Del
=
445 new mono_test_Winx64_struct5_ret_delegate (mono_test_Winx64_struct5_ret_test
);
447 if ((retCode
= mono_test_Winx64_struct5_ret_managed (s1Del
)) != 0)
448 return 100 + retCode
;
453 public static int managed_struct1_test (winx64_struct1
var)
461 public static int managed_struct5_test (winx64_struct5
var)
473 public static int managed_struct1_struct5_test (winx64_struct1 var1
, winx64_struct5 var2
,
474 winx64_struct1 var3
, winx64_struct5 var4
,
475 winx64_struct1 var5
, winx64_struct5 var6
)
477 if (var1
.a
!= 1 || var3
.a
!= 5)
479 if (var2
.a
!= 2 || var2
.b
!= 3 || var2
.c
!= 4 ||
480 var4
.a
!= 6 || var4
.b
!= 7 || var4
.c
!= 8)
484 if (var6
.a
!= 10 || var6
.b
!= 11 || var6
.c
!= 12)
490 public static winx64_struct1
mono_test_Winx64_struct1_ret_test ()
492 return new winx64_struct1 (0x45);
495 public static winx64_struct5
mono_test_Winx64_struct5_ret_test ()
497 return new winx64_struct5 (0x12, 0x34, 0x56);