/home/travis/build/MoarVM/MoarVM/src/core/nativecall.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* The various native call argument types. */ |
2 | 4 | #define MVM_NATIVECALL_ARG_VOID 0 |
3 | 3 | #define MVM_NATIVECALL_ARG_CHAR 2 |
4 | 3 | #define MVM_NATIVECALL_ARG_SHORT 4 |
5 | 3 | #define MVM_NATIVECALL_ARG_INT 6 |
6 | 3 | #define MVM_NATIVECALL_ARG_LONG 8 |
7 | 3 | #define MVM_NATIVECALL_ARG_LONGLONG 10 |
8 | 0 | #define MVM_NATIVECALL_ARG_FLOAT 12 |
9 | 0 | #define MVM_NATIVECALL_ARG_DOUBLE 14 |
10 | 2 | #define MVM_NATIVECALL_ARG_ASCIISTR 16 |
11 | 11 | #define MVM_NATIVECALL_ARG_UTF8STR 18 |
12 | 2 | #define MVM_NATIVECALL_ARG_UTF16STR 20 |
13 | 0 | #define MVM_NATIVECALL_ARG_CSTRUCT 22 |
14 | 0 | #define MVM_NATIVECALL_ARG_CARRAY 24 |
15 | 3 | #define MVM_NATIVECALL_ARG_CALLBACK 26 |
16 | 7 | #define MVM_NATIVECALL_ARG_CPOINTER 28 |
17 | 0 | #define MVM_NATIVECALL_ARG_VMARRAY 30 |
18 | 3 | #define MVM_NATIVECALL_ARG_UCHAR 32 |
19 | 3 | #define MVM_NATIVECALL_ARG_USHORT 34 |
20 | 3 | #define MVM_NATIVECALL_ARG_UINT 36 |
21 | 3 | #define MVM_NATIVECALL_ARG_ULONG 38 |
22 | 3 | #define MVM_NATIVECALL_ARG_ULONGLONG 40 |
23 | 0 | #define MVM_NATIVECALL_ARG_CUNION 42 |
24 | 0 | #define MVM_NATIVECALL_ARG_CPPSTRUCT 44 |
25 | 11 | #define MVM_NATIVECALL_ARG_TYPE_MASK 62 |
26 | | |
27 | | /* Flag for whether we should free a string after passing it or not. */ |
28 | 0 | #define MVM_NATIVECALL_ARG_NO_FREE_STR 0 |
29 | 2 | #define MVM_NATIVECALL_ARG_FREE_STR 1 |
30 | 4 | #define MVM_NATIVECALL_ARG_FREE_STR_MASK 1 |
31 | | /* Flag for whether we need to refresh a CArray after passing or not. */ |
32 | 0 | #define MVM_NATIVECALL_ARG_NO_REFRESH 0 |
33 | 0 | #define MVM_NATIVECALL_ARG_REFRESH 1 |
34 | 0 | #define MVM_NATIVECALL_ARG_REFRESH_MASK 1 |
35 | 2 | #define MVM_NATIVECALL_ARG_NO_RW 0 |
36 | 7 | #define MVM_NATIVECALL_ARG_RW 256 |
37 | 7 | #define MVM_NATIVECALL_ARG_RW_MASK 256 |
38 | | |
39 | | /* Native callback entry. Hung off MVMNativeCallbackCacheHead, which is |
40 | | * a hash owned by the ThreadContext. All MVMNativeCallbacks in a linked |
41 | | * list have the same cuid, which is the key to the CacheHead hash. |
42 | | */ |
43 | | struct MVMNativeCallback { |
44 | | /* The dyncall/libffi callback object. */ |
45 | | void *cb; |
46 | | |
47 | | /* The routine that we will call. */ |
48 | | MVMObject *target; |
49 | | |
50 | | /* The VM instance. */ |
51 | | MVMInstance *instance; |
52 | | |
53 | | /* Return and argument type flags. */ |
54 | | MVMint16 *typeinfos; |
55 | | |
56 | | /* Return and argument types themselves. */ |
57 | | MVMObject **types; |
58 | | |
59 | | /* The number of entries in typeinfos/types. */ |
60 | | MVMint32 num_types; |
61 | | |
62 | | /* The MoarVM callsite object for this call. */ |
63 | | MVMCallsite *cs; |
64 | | |
65 | | #ifdef HAVE_LIBFFI |
66 | | ffi_abi convention; |
67 | | ffi_type **ffi_arg_types; |
68 | | ffi_type *ffi_ret_type; |
69 | | #endif |
70 | | |
71 | | /* The next entry in the linked list */ |
72 | | MVMNativeCallback *next; |
73 | | }; |
74 | | |
75 | | |
76 | | /* A hash of nativecall callbacks. Each entry is a linked |
77 | | * list of MVMNativeCallback sharing the same cuid. |
78 | | * Multiple callbacks with the same cuid get created when |
79 | | * closures are taken and need to be differentiated. |
80 | | */ |
81 | | struct MVMNativeCallbackCacheHead { |
82 | | MVMNativeCallback *head; |
83 | | |
84 | | /* The uthash hash handle inline struct. */ |
85 | | UT_hash_handle hash_handle; |
86 | | }; |
87 | | |
88 | | /* Functions for working with native callsites. */ |
89 | | MVMNativeCallBody * MVM_nativecall_get_nc_body(MVMThreadContext *tc, MVMObject *obj); |
90 | | MVMint16 MVM_nativecall_get_arg_type(MVMThreadContext *tc, MVMObject *info, MVMint16 is_return); |
91 | | MVMint8 MVM_nativecall_build(MVMThreadContext *tc, MVMObject *site, MVMString *lib, |
92 | | MVMString *sym, MVMString *conv, MVMObject *arg_spec, MVMObject *ret_spec); |
93 | | MVMObject * MVM_nativecall_invoke(MVMThreadContext *tc, MVMObject *res_type, |
94 | | MVMObject *site, MVMObject *args); |
95 | | void MVM_nativecall_invoke_jit(MVMThreadContext *tc, MVMObject *site); |
96 | | MVMObject * MVM_nativecall_global(MVMThreadContext *tc, MVMString *lib, MVMString *sym, |
97 | | MVMObject *target_spec, MVMObject *target_type); |
98 | | MVMObject * MVM_nativecall_cast(MVMThreadContext *tc, MVMObject *target_spec, |
99 | | MVMObject *res_type, MVMObject *obj); |
100 | | MVMint64 MVM_nativecall_sizeof(MVMThreadContext *tc, MVMObject *obj); |
101 | | void MVM_nativecall_refresh(MVMThreadContext *tc, MVMObject *cthingy); |
102 | | |
103 | | MVMObject * MVM_nativecall_make_cstruct(MVMThreadContext *tc, MVMObject *type, void *cstruct); |
104 | | MVMObject * MVM_nativecall_make_cppstruct(MVMThreadContext *tc, MVMObject *type, void *cppstruct); |
105 | | MVMObject * MVM_nativecall_make_cunion(MVMThreadContext *tc, MVMObject *type, void *cunion); |
106 | | MVMObject * MVM_nativecall_make_cpointer(MVMThreadContext *tc, MVMObject *type, void *ptr); |
107 | | MVMObject * MVM_nativecall_make_carray(MVMThreadContext *tc, MVMObject *type, void *carray); |
108 | | |
109 | | MVMObject * MVM_nativecall_make_int(MVMThreadContext *tc, MVMObject *type, MVMint64 value); |
110 | | MVMObject * MVM_nativecall_make_uint(MVMThreadContext *tc, MVMObject *type, MVMuint64 value); |
111 | | MVMObject * MVM_nativecall_make_num(MVMThreadContext *tc, MVMObject *type, MVMnum64 value); |
112 | | MVMObject * MVM_nativecall_make_str(MVMThreadContext *tc, MVMObject *type, MVMint16 ret_type, char *cstring); |
113 | | |
114 | | signed char MVM_nativecall_unmarshal_char(MVMThreadContext *tc, MVMObject *value); |
115 | | signed short MVM_nativecall_unmarshal_short(MVMThreadContext *tc, MVMObject *value); |
116 | | signed int MVM_nativecall_unmarshal_int(MVMThreadContext *tc, MVMObject *value); |
117 | | signed long MVM_nativecall_unmarshal_long(MVMThreadContext *tc, MVMObject *value); |
118 | | signed long long MVM_nativecall_unmarshal_longlong(MVMThreadContext *tc, MVMObject *value); |
119 | | unsigned char MVM_nativecall_unmarshal_uchar(MVMThreadContext *tc, MVMObject *value); |
120 | | unsigned short MVM_nativecall_unmarshal_ushort(MVMThreadContext *tc, MVMObject *value); |
121 | | unsigned int MVM_nativecall_unmarshal_uint(MVMThreadContext *tc, MVMObject *value); |
122 | | unsigned long MVM_nativecall_unmarshal_ulong(MVMThreadContext *tc, MVMObject *value); |
123 | | unsigned long long MVM_nativecall_unmarshal_ulonglong(MVMThreadContext *tc, MVMObject *value); |
124 | | float MVM_nativecall_unmarshal_float(MVMThreadContext *tc, MVMObject *value); |
125 | | double MVM_nativecall_unmarshal_double(MVMThreadContext *tc, MVMObject *value); |
126 | | |
127 | | char * MVM_nativecall_unmarshal_string(MVMThreadContext *tc, MVMObject *value, MVMint16 type, MVMint16 *free); |
128 | | void * MVM_nativecall_unmarshal_cstruct(MVMThreadContext *tc, MVMObject *value); |
129 | | void * MVM_nativecall_unmarshal_cppstruct(MVMThreadContext *tc, MVMObject *value); |
130 | | void * MVM_nativecall_unmarshal_cpointer(MVMThreadContext *tc, MVMObject *value); |
131 | | void * MVM_nativecall_unmarshal_carray(MVMThreadContext *tc, MVMObject *value); |
132 | | void * MVM_nativecall_unmarshal_vmarray(MVMThreadContext *tc, MVMObject *value); |
133 | | void * MVM_nativecall_unmarshal_cunion(MVMThreadContext *tc, MVMObject *value); |
134 | | MVMThreadContext * MVM_nativecall_find_thread_context(MVMInstance *instance); |
135 | | MVMJitGraph *MVM_nativecall_jit_graph_for_caller_code( |
136 | | MVMThreadContext *tc, |
137 | | MVMSpeshGraph *sg, |
138 | | MVMNativeCallBody *body, |
139 | | MVMint16 restype, |
140 | | MVMint16 dst, |
141 | | MVMSpeshIns **arg_ins |
142 | | ); |