internal-calls 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. * How to map C# types for use in the C implementation of internal calls
  2. C# type C type
  3. char gunichar2
  4. bool MonoBoolean
  5. sbyte signed char
  6. byte guchar
  7. short gint16
  8. ushort guint16
  9. int gint32
  10. uint guint32
  11. long gint64
  12. ulong guint64
  13. IntPtr/UIntPtr gpointer
  14. object MonoObject*
  15. string MonoString*
  16. For ref and out paramaters you'll use the corresponding pointer type.
  17. Arrays of any type must be described with a MonoArray* and the elements
  18. must be accessed with the mono_array_* macros.
  19. Any other type that has a matching C structure representation, should use
  20. a pointer to the struct instead of a generic MonoObject pointer.
  21. Instance methods that are internal calls will receive as first argument
  22. the instance object, so you must account for it in the C method signature:
  23. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  24. public extern override int GetHashCode ();
  25. becaomes:
  26. gint32 ves_icall_System_String_GetHashCode (MonoString *this);
  27. * How to hook internal calls with the runtime
  28. Once you require an internal call in corlib, you need to create a C
  29. implementation for it and register it in a static table in metadata/icall.c.
  30. Add an entry in the table like:
  31. "System.String::GetHashCode", ves_icall_System_String_GetHashCode,
  32. Note that you need to include the full namespace.name of the class.
  33. If there are overloaded methods, you need also to specify the signature
  34. of _all_ of them:
  35. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  36. public extern override void DoSomething ();
  37. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  38. public extern override void DoSomething (bool useful);
  39. should be mapped with:
  40. "Namespace.ClassName::DoSomething()", ves_icall_Namespace_ClassName_DoSomething,
  41. "Namespace.ClassName::DoSomething(bool)", ves_icall_Namespace_ClassName_DoSomething_bool,