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