internal-calls 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Internal Call Topics
  2. * Introduction
  3. The Common Language Infrastructure allows for methods to be
  4. implemented in unmanaged code. Unlike the Platform Invocation
  5. services which provide marshalling and unmarshalling of data
  6. from managed to unmanaged and viceversa the Internal calls do
  7. not perform any kind of marshalling.
  8. * Basic Type mapping
  9. The following lists how the C# types are exposed to the C API.
  10. C# type C type
  11. -----------------------------
  12. char gunichar2
  13. bool MonoBoolean
  14. sbyte signed char
  15. byte guchar
  16. short gint16
  17. ushort guint16
  18. int gint32
  19. uint guint32
  20. long gint64
  21. ulong guint64
  22. IntPtr/UIntPtr gpointer
  23. object MonoObject*
  24. string MonoString*
  25. * Pointers
  26. For ref and out paramaters you'll use the corresponding
  27. pointer type.
  28. So if you have a C# type listed as "ref int", you should use
  29. "int *" in your implementation.
  30. * Arrays
  31. Arrays of any type must be described with a MonoArray* and the
  32. elements must be accessed with the mono_array_* macros.
  33. * Other Structures
  34. Any other type that has a matching C structure representation,
  35. should use a pointer to the struct instead of a generic
  36. MonoObject pointer.
  37. * Instance Methods.
  38. Instance methods that are internal calls will receive as first argument
  39. the instance object, so you must account for it in the C method signature:
  40. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  41. public extern override int GetHashCode ();
  42. becomes:
  43. gint32 ves_icall_System_String_GetHashCode (MonoString *this);
  44. * How to hook internal calls with the runtime
  45. Once you require an internal call in corlib, you need to
  46. create a C implementation for it and register it in a
  47. table in metadata/icall-def.h. See the top of that file
  48. for more information.
  49. If there are overloaded methods, you need also to
  50. specify the signature of _all_ of them:
  51. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  52. public extern override void DoSomething ();
  53. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  54. public extern override void DoSomething (bool useful);
  55. should be mapped with the following method names:
  56. "DoSomething()", ves_icall_Namespace_ClassName_DoSomething,
  57. "DoSomething(bool)", ves_icall_Namespace_ClassName_DoSomething_bool,