2 using System
.Runtime
.InteropServices
;
4 [AttributeUsage (AttributeTargets
.Method
)]
5 sealed class MonoPInvokeCallbackAttribute
: Attribute
{
6 public MonoPInvokeCallbackAttribute (Type t
) {}
9 [StructLayout (LayoutKind
.Sequential
)]
12 public winx64_struct1 (byte ia
)
19 [StructLayout (LayoutKind
.Sequential
)]
22 public winx64_struct2 (byte ia
, byte ib
)
32 [StructLayout (LayoutKind
.Sequential
)]
35 public winx64_struct3 (byte ia
, byte ib
, short ic
)
47 [StructLayout (LayoutKind
.Sequential
)]
50 public winx64_struct4 (byte ia
, byte ib
, short ic
, uint id
)
64 [StructLayout (LayoutKind
.Sequential
)]
67 public winx64_struct5 (byte ia
, byte ib
, byte ic
)
79 [StructLayout (LayoutKind
.Sequential
)]
82 public winx64_struct6 (winx64_struct1 ia
, short ib
, byte ic
)
89 public winx64_struct1 a
;
94 [StructLayout (LayoutKind
.Sequential
)]
95 struct winx64_floatStruct
97 public winx64_floatStruct (float ia
, float ib
)
107 [StructLayout (LayoutKind
.Sequential
)]
108 struct winx64_doubleStruct
110 public winx64_doubleStruct (double ia
)
120 [DllImport ("libtest")]
121 static extern int mono_test_Winx64_struct1_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1
var);
123 [DllImport ("libtest")]
124 static extern int mono_test_Winx64_struct2_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct2
var);
126 [DllImport ("libtest")]
127 static extern int mono_test_Winx64_struct3_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct3
var);
129 [DllImport ("libtest")]
130 static extern int mono_test_Winx64_struct4_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct4
var);
132 [DllImport ("libtest")]
133 static extern int mono_test_Winx64_struct5_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct5
var);
135 [DllImport ("libtest")]
136 static extern int mono_test_Winx64_struct6_in ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct6
var);
138 [DllImport ("libtest")]
139 static extern int mono_test_Winx64_structs_in1 ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var1
,
140 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct2 var2
,
141 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct3 var3
,
142 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct4 var4
);
144 [DllImport ("libtest")]
145 static extern int mono_test_Winx64_structs_in2 ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var1
,
146 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var2
,
147 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var3
,
148 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var4
,
149 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var5
);
151 [DllImport ("libtest")]
152 static extern int mono_test_Winx64_structs_in3 ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var1
,
153 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct5 var2
,
154 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var3
,
155 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct5 var4
,
156 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct1 var5
,
157 [MarshalAs (UnmanagedType
.Struct
)] winx64_struct5 var6
);
159 [DllImport ("libtest")]
160 [return:MarshalAs (UnmanagedType
.Struct
)]
161 static extern winx64_struct1
mono_test_Winx64_struct1_ret ();
163 [DllImport ("libtest")]
164 [return: MarshalAs (UnmanagedType
.Struct
)]
165 static extern winx64_struct2
mono_test_Winx64_struct2_ret ();
167 [DllImport ("libtest")]
168 [return: MarshalAs (UnmanagedType
.Struct
)]
169 static extern winx64_struct3
mono_test_Winx64_struct3_ret ();
171 [DllImport ("libtest")]
172 [return: MarshalAs (UnmanagedType
.Struct
)]
173 static extern winx64_struct4
mono_test_Winx64_struct4_ret ();
175 [DllImport ("libtest")]
176 [return: MarshalAs (UnmanagedType
.Struct
)]
177 static extern winx64_struct5
mono_test_Winx64_struct5_ret ();
179 [DllImport ("libtest")]
180 [return: MarshalAs (UnmanagedType
.Struct
)]
181 static extern winx64_struct1
mono_test_Winx64_struct1_ret_5_args (byte a
, byte b
, byte c
, byte d
, byte e
);
183 [DllImport ("libtest")]
184 [return: MarshalAs (UnmanagedType
.Struct
)]
185 static extern winx64_struct5
mono_test_Winx64_struct5_ret6_args (byte a
, byte b
, byte c
, byte d
, byte e
);
187 [DllImport ("libtest")]
188 static extern int mono_test_Winx64_floatStruct ([MarshalAs (UnmanagedType
.Struct
)] winx64_floatStruct
var);
190 [DllImport ("libtest")]
191 static extern int mono_test_Winx64_doubleStruct ([MarshalAs (UnmanagedType
.Struct
)] winx64_doubleStruct
var);
193 public delegate int managed_struct1_delegate ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct1
var);
195 [DllImport ("libtest")]
196 static extern int mono_test_managed_Winx64_struct1_in (managed_struct1_delegate func
);
198 public delegate int managed_struct5_delegate ([MarshalAs (UnmanagedType
.Struct
)] winx64_struct5
var);
200 [DllImport ("libtest")]
201 static extern int mono_test_managed_Winx64_struct5_in (managed_struct5_delegate func
);
203 public delegate int managed_struct1_struct5_delegate (winx64_struct1 var1
, winx64_struct5 var2
,
204 winx64_struct1 var3
, winx64_struct5 var4
,
205 winx64_struct1 var5
, winx64_struct5 var6
);
207 [DllImport ("libtest")]
208 static extern int mono_test_managed_Winx64_struct1_struct5_in (managed_struct1_struct5_delegate func
);
210 [return:MarshalAs (UnmanagedType
.Struct
)]
211 public delegate winx64_struct1
mono_test_Winx64_struct1_ret_delegate ();
213 [DllImport ("libtest")]
214 static extern int mono_test_Winx64_struct1_ret_managed (mono_test_Winx64_struct1_ret_delegate func
);
216 [return: MarshalAs (UnmanagedType
.Struct
)]
217 public delegate winx64_struct5
mono_test_Winx64_struct5_ret_delegate ();
219 [DllImport ("libtest")]
220 static extern int mono_test_Winx64_struct5_ret_managed (mono_test_Winx64_struct5_ret_delegate func
);
223 private static bool enableBroken
= false;
225 static int Main (string[] args
)
227 return TestDriver
.RunTests (typeof (winx64structs
), args
);
230 public static int test_0_In_Args_Value_In_RCX ()
234 winx64_struct1 t_winx64_struct1
= new winx64_struct1 (123);
236 if ((retCode
= mono_test_Winx64_struct1_in (t_winx64_struct1
)) != 0)
237 return 100 + retCode
;
239 winx64_struct2 t_winx64_struct2
= new winx64_struct2 (4, 5);
241 if ((retCode
= mono_test_Winx64_struct2_in (t_winx64_struct2
)) != 0)
242 return 200 + retCode
;
244 winx64_struct3 t_winx64_struct3
= new winx64_struct3 (4, 5, 0x1234);
246 if ((retCode
= mono_test_Winx64_struct3_in (t_winx64_struct3
)) != 0)
247 return 300 + retCode
;
249 winx64_struct4 t_winx64_struct4
= new winx64_struct4 (4, 5, 0x1234, 0x87654321);
251 if ((retCode
= mono_test_Winx64_struct4_in (t_winx64_struct4
)) != 0)
252 return 400 + retCode
;
254 winx64_floatStruct t_winx64_floatStruct
= new winx64_floatStruct (5.5F
, 9.5F
);
256 if ((retCode
= mono_test_Winx64_floatStruct (t_winx64_floatStruct
)) != 0)
257 return 500 + retCode
;
259 winx64_doubleStruct t_winx64_doubleStruct
= new winx64_doubleStruct (5.5F
);
261 if ((retCode
= mono_test_Winx64_doubleStruct (t_winx64_doubleStruct
)) != 0)
262 return 600 + retCode
;
267 public static int test_0_In_Args_Values_In_Multiple_Registers ()
271 winx64_struct1 t_winx64_struct1
= new winx64_struct1 (123);
272 winx64_struct2 t_winx64_struct2
= new winx64_struct2 (4, 5);
273 winx64_struct3 t_winx64_struct3
= new winx64_struct3 (4, 5, 0x1234);
274 winx64_struct4 t_winx64_struct4
= new winx64_struct4 (4, 5, 0x1234, 0x87654321);
276 if ((retCode
= mono_test_Winx64_structs_in1 (t_winx64_struct1
, t_winx64_struct2
,
277 t_winx64_struct3
, t_winx64_struct4
)) != 0)
278 return 100 + retCode
;
284 public static int test_0_Ret_In_RAX ()
286 winx64_struct1 t_winx64_struct1
= mono_test_Winx64_struct1_ret ();
287 if (t_winx64_struct1
.a
!= 123)
290 winx64_struct2 t_winx64_struct2
= mono_test_Winx64_struct2_ret ();
291 if (t_winx64_struct2
.a
!= 4)
293 if (t_winx64_struct2
.b
!= 5)
296 winx64_struct3 t_winx64_struct3
= mono_test_Winx64_struct3_ret ();
297 if (t_winx64_struct3
.a
!= 4)
299 if (t_winx64_struct3
.b
!= 5)
301 if (t_winx64_struct3
.c
!= 0x1234)
304 winx64_struct4 t_winx64_struct4
= mono_test_Winx64_struct4_ret ();
305 if (t_winx64_struct4
.a
!= 4)
307 if (t_winx64_struct4
.b
!= 5)
309 if (t_winx64_struct4
.c
!= 0x1234)
311 if (t_winx64_struct4
.d
!= 0x87654321)
314 t_winx64_struct1
= mono_test_Winx64_struct1_ret_5_args (0x1, 0x0, 0x4, 0x10, 0x40);
315 if (t_winx64_struct1
.a
!= 0x55)
321 public static int test_0_Ret_In_Address ()
323 winx64_struct5 t_winx64_struct5
= mono_test_Winx64_struct5_ret ();
324 if (t_winx64_struct5
.a
!= 4)
326 if (t_winx64_struct5
.b
!= 5)
328 if (t_winx64_struct5
.c
!= 6)
331 t_winx64_struct5
= mono_test_Winx64_struct5_ret6_args (0x1, 0x4, 0x2, 0x8, 0x30);
332 if (t_winx64_struct5
.a
!= 0x5)
334 if (t_winx64_struct5
.b
!= 0xa)
336 if (t_winx64_struct5
.c
!= 0x30)
342 public static int test_0_In_Args_Values_In_Registers_and_Stack ()
346 winx64_struct1 var1
= new winx64_struct1 (1);
347 winx64_struct1 var2
= new winx64_struct1 (2);
348 winx64_struct1 var3
= new winx64_struct1 (3);
349 winx64_struct1 var4
= new winx64_struct1 (4);
350 winx64_struct1 var5
= new winx64_struct1 (5);
352 if ((retCode
= mono_test_Winx64_structs_in2 (var1
, var2
, var3
, var4
, var5
)) != 0)
353 return 100 + retCode
;
358 public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack ()
362 winx64_struct1 var1
= new winx64_struct1 (1);
363 winx64_struct5 var2
= new winx64_struct5 (2, 3, 4);
364 winx64_struct1 var3
= new winx64_struct1 (5);
365 winx64_struct5 var4
= new winx64_struct5 (6, 7, 8);
366 winx64_struct1 var5
= new winx64_struct1 (9);
367 winx64_struct5 var6
= new winx64_struct5 (10, 11, 12);
369 if ((retCode
= mono_test_Winx64_structs_in3 (var1
, var2
, var3
, var4
, var5
, var6
)) != 0)
370 return 100 + retCode
;
375 public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX ()
379 winx64_struct5 t_winx64_struct5
= new winx64_struct5 (4, 5, 6);
380 t_winx64_struct5
.a
= 4;
381 t_winx64_struct5
.b
= 5;
382 t_winx64_struct5
.c
= 6;
384 if ((retCode
= mono_test_Winx64_struct5_in (t_winx64_struct5
)) != 0)
385 return 100 + retCode
;
387 winx64_struct6 t_winx64_struct6
= new winx64_struct6 (new winx64_struct1 (4), 5, 6);
389 if ((retCode
= mono_test_Winx64_struct6_in (t_winx64_struct6
)) != 0)
390 return 200 + retCode
;
395 public static int test_0_In_Args_Value_In_RCX_Managed ()
399 managed_struct1_delegate s1Del
= new managed_struct1_delegate (managed_struct1_test
);
401 if ((retCode
= mono_test_managed_Winx64_struct1_in (s1Del
)) != 0)
402 return 100 + retCode
;
407 public static int test_0_In_Args_Value_On_Stack_ADDR_In_RCX_Managed ()
411 managed_struct5_delegate s1Del
= new managed_struct5_delegate (managed_struct5_test
);
413 if ((retCode
= mono_test_managed_Winx64_struct5_in (s1Del
)) != 0)
414 return 100 + retCode
;
419 public static int test_0_In_Args_Values_In_Registers_with_Stack_and_On_Stack_Managed ()
423 managed_struct1_struct5_delegate s1Del
=
424 new managed_struct1_struct5_delegate (managed_struct1_struct5_test
);
426 if ((retCode
= mono_test_managed_Winx64_struct1_struct5_in (s1Del
)) != 0)
427 return 100 + retCode
;
432 public static int test_0_Ret_In_RAX_managed ()
436 mono_test_Winx64_struct1_ret_delegate s1Del
=
437 new mono_test_Winx64_struct1_ret_delegate (mono_test_Winx64_struct1_ret_test
);
439 if ((retCode
= mono_test_Winx64_struct1_ret_managed (s1Del
)) != 0)
440 return 100 + retCode
;
445 public static int test_0_Ret_In_Address_managed ()
449 mono_test_Winx64_struct5_ret_delegate s1Del
=
450 new mono_test_Winx64_struct5_ret_delegate (mono_test_Winx64_struct5_ret_test
);
452 if ((retCode
= mono_test_Winx64_struct5_ret_managed (s1Del
)) != 0)
453 return 100 + retCode
;
458 [MonoPInvokeCallback (typeof (managed_struct1_delegate
))]
459 public static int managed_struct1_test (winx64_struct1
var)
467 [MonoPInvokeCallback (typeof (managed_struct5_delegate
))]
468 public static int managed_struct5_test (winx64_struct5
var)
480 [MonoPInvokeCallback (typeof (managed_struct1_struct5_delegate
))]
481 public static int managed_struct1_struct5_test (winx64_struct1 var1
, winx64_struct5 var2
,
482 winx64_struct1 var3
, winx64_struct5 var4
,
483 winx64_struct1 var5
, winx64_struct5 var6
)
485 if (var1
.a
!= 1 || var3
.a
!= 5)
487 if (var2
.a
!= 2 || var2
.b
!= 3 || var2
.c
!= 4 ||
488 var4
.a
!= 6 || var4
.b
!= 7 || var4
.c
!= 8)
492 if (var6
.a
!= 10 || var6
.b
!= 11 || var6
.c
!= 12)
498 [MonoPInvokeCallback (typeof (mono_test_Winx64_struct1_ret_delegate
))]
499 public static winx64_struct1
mono_test_Winx64_struct1_ret_test ()
501 return new winx64_struct1 (0x45);
504 [MonoPInvokeCallback (typeof (mono_test_Winx64_struct5_ret_delegate
))]
505 public static winx64_struct5
mono_test_Winx64_struct5_ret_test ()
507 return new winx64_struct5 (0x12, 0x34, 0x56);