/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 | 2 | #define MVM_NATIVECALL_ARG_VOID 0 |
3 | 0 | #define MVM_NATIVECALL_ARG_CHAR 2 |
4 | 0 | #define MVM_NATIVECALL_ARG_SHORT 4 |
5 | 0 | #define MVM_NATIVECALL_ARG_INT 6 |
6 | 0 | #define MVM_NATIVECALL_ARG_LONG 8 |
7 | 0 | #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 | 4 | #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 | 3 | #define MVM_NATIVECALL_ARG_CPOINTER 28 |
17 | 0 | #define MVM_NATIVECALL_ARG_VMARRAY 30 |
18 | 0 | #define MVM_NATIVECALL_ARG_UCHAR 32 |
19 | 0 | #define MVM_NATIVECALL_ARG_USHORT 34 |
20 | 0 | #define MVM_NATIVECALL_ARG_UINT 36 |
21 | 0 | #define MVM_NATIVECALL_ARG_ULONG 38 |
22 | 0 | #define MVM_NATIVECALL_ARG_ULONGLONG 40 |
23 | 0 | #define MVM_NATIVECALL_ARG_CUNION 42 |
24 | 0 | #define MVM_NATIVECALL_ARG_CPPSTRUCT 44 |
25 | 5 | #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 | 2 | #define MVM_NATIVECALL_ARG_FREE_STR_MASK 1 |
31 | 2 | #define MVM_NATIVECALL_ARG_NO_RW 0 |
32 | 4 | #define MVM_NATIVECALL_ARG_RW 256 |
33 | 4 | #define MVM_NATIVECALL_ARG_RW_MASK 256 |
34 | | |
35 | | /* Native callback entry. Hung off MVMNativeCallbackCacheHead, which is |
36 | | * a hash owned by the ThreadContext. All MVMNativeCallbacks in a linked |
37 | | * list have the same cuid, which is the key to the CacheHead hash. |
38 | | */ |
39 | | struct MVMNativeCallback { |
40 | | /* The dyncall/libffi callback object. */ |
41 | | void *cb; |
42 | | |
43 | | /* The routine that we will call. */ |
44 | | MVMObject *target; |
45 | | |
46 | | /* Thread context we expect to run the callback on. */ |
47 | | MVMThreadContext *tc; |
48 | | |
49 | | /* Return and argument type flags. */ |
50 | | MVMint16 *typeinfos; |
51 | | |
52 | | /* Return and argument types themselves. */ |
53 | | MVMObject **types; |
54 | | |
55 | | /* The number of entries in typeinfos/types. */ |
56 | | MVMint32 num_types; |
57 | | |
58 | | /* The MoarVM callsite object for this call. */ |
59 | | MVMCallsite *cs; |
60 | | |
61 | | #ifdef HAVE_LIBFFI |
62 | | ffi_abi convention; |
63 | | ffi_type **ffi_arg_types; |
64 | | ffi_type *ffi_ret_type; |
65 | | #endif |
66 | | |
67 | | /* The next entry in the linked list */ |
68 | | MVMNativeCallback *next; |
69 | | }; |
70 | | |
71 | | |
72 | | /* A hash of nativecall callbacks. Each entry is a linked |
73 | | * list of MVMNativeCallback sharing the same cuid. |
74 | | * Multiple callbacks with the same cuid get created when |
75 | | * closures are taken and need to be differentiated. |
76 | | */ |
77 | | struct MVMNativeCallbackCacheHead { |
78 | | MVMNativeCallback *head; |
79 | | |
80 | | /* The uthash hash handle inline struct. */ |
81 | | UT_hash_handle hash_handle; |
82 | | }; |
83 | | |
84 | | /* Functions for working with native callsites. */ |
85 | | MVMNativeCallBody * MVM_nativecall_get_nc_body(MVMThreadContext *tc, MVMObject *obj); |
86 | | MVMint16 MVM_nativecall_get_arg_type(MVMThreadContext *tc, MVMObject *info, MVMint16 is_return); |
87 | | void MVM_nativecall_build(MVMThreadContext *tc, MVMObject *site, MVMString *lib, |
88 | | MVMString *sym, MVMString *conv, MVMObject *arg_spec, MVMObject *ret_spec); |
89 | | MVMObject * MVM_nativecall_invoke(MVMThreadContext *tc, MVMObject *res_type, |
90 | | MVMObject *site, MVMObject *args); |
91 | | MVMObject * MVM_nativecall_global(MVMThreadContext *tc, MVMString *lib, MVMString *sym, |
92 | | MVMObject *target_spec, MVMObject *target_type); |
93 | | MVMObject * MVM_nativecall_cast(MVMThreadContext *tc, MVMObject *target_spec, |
94 | | MVMObject *res_type, MVMObject *obj); |
95 | | MVMint64 MVM_nativecall_sizeof(MVMThreadContext *tc, MVMObject *obj); |
96 | | void MVM_nativecall_refresh(MVMThreadContext *tc, MVMObject *cthingy); |
97 | | |
98 | | MVMObject * MVM_nativecall_make_cstruct(MVMThreadContext *tc, MVMObject *type, void *cstruct); |
99 | | MVMObject * MVM_nativecall_make_cppstruct(MVMThreadContext *tc, MVMObject *type, void *cppstruct); |
100 | | MVMObject * MVM_nativecall_make_cunion(MVMThreadContext *tc, MVMObject *type, void *cunion); |
101 | | MVMObject * MVM_nativecall_make_cpointer(MVMThreadContext *tc, MVMObject *type, void *ptr); |
102 | | MVMObject * MVM_nativecall_make_carray(MVMThreadContext *tc, MVMObject *type, void *carray); |
103 | | |
104 | | MVMObject * MVM_nativecall_make_int(MVMThreadContext *tc, MVMObject *type, MVMint64 value); |
105 | | MVMObject * MVM_nativecall_make_uint(MVMThreadContext *tc, MVMObject *type, MVMuint64 value); |
106 | | MVMObject * MVM_nativecall_make_num(MVMThreadContext *tc, MVMObject *type, MVMnum64 value); |
107 | | MVMObject * MVM_nativecall_make_str(MVMThreadContext *tc, MVMObject *type, MVMint16 ret_type, char *cstring); |
108 | | |
109 | | signed char MVM_nativecall_unmarshal_char(MVMThreadContext *tc, MVMObject *value); |
110 | | signed short MVM_nativecall_unmarshal_short(MVMThreadContext *tc, MVMObject *value); |
111 | | signed int MVM_nativecall_unmarshal_int(MVMThreadContext *tc, MVMObject *value); |
112 | | signed long MVM_nativecall_unmarshal_long(MVMThreadContext *tc, MVMObject *value); |
113 | | signed long long MVM_nativecall_unmarshal_longlong(MVMThreadContext *tc, MVMObject *value); |
114 | | unsigned char MVM_nativecall_unmarshal_uchar(MVMThreadContext *tc, MVMObject *value); |
115 | | unsigned short MVM_nativecall_unmarshal_ushort(MVMThreadContext *tc, MVMObject *value); |
116 | | unsigned int MVM_nativecall_unmarshal_uint(MVMThreadContext *tc, MVMObject *value); |
117 | | unsigned long MVM_nativecall_unmarshal_ulong(MVMThreadContext *tc, MVMObject *value); |
118 | | unsigned long long MVM_nativecall_unmarshal_ulonglong(MVMThreadContext *tc, MVMObject *value); |
119 | | float MVM_nativecall_unmarshal_float(MVMThreadContext *tc, MVMObject *value); |
120 | | double MVM_nativecall_unmarshal_double(MVMThreadContext *tc, MVMObject *value); |
121 | | |
122 | | char * MVM_nativecall_unmarshal_string(MVMThreadContext *tc, MVMObject *value, MVMint16 type, MVMint16 *free); |
123 | | void * MVM_nativecall_unmarshal_cstruct(MVMThreadContext *tc, MVMObject *value); |
124 | | void * MVM_nativecall_unmarshal_cppstruct(MVMThreadContext *tc, MVMObject *value); |
125 | | void * MVM_nativecall_unmarshal_cpointer(MVMThreadContext *tc, MVMObject *value); |
126 | | void * MVM_nativecall_unmarshal_carray(MVMThreadContext *tc, MVMObject *value); |
127 | | void * MVM_nativecall_unmarshal_vmarray(MVMThreadContext *tc, MVMObject *value); |
128 | | void * MVM_nativecall_unmarshal_cunion(MVMThreadContext *tc, MVMObject *value); |