jpayne@69
|
1 /* -----------------------------------------------------------------*-C-*-
|
jpayne@69
|
2 libffi 3.2.1 - Copyright (c) 2011, 2014 Anthony Green
|
jpayne@69
|
3 - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc.
|
jpayne@69
|
4
|
jpayne@69
|
5 Permission is hereby granted, free of charge, to any person
|
jpayne@69
|
6 obtaining a copy of this software and associated documentation
|
jpayne@69
|
7 files (the ``Software''), to deal in the Software without
|
jpayne@69
|
8 restriction, including without limitation the rights to use, copy,
|
jpayne@69
|
9 modify, merge, publish, distribute, sublicense, and/or sell copies
|
jpayne@69
|
10 of the Software, and to permit persons to whom the Software is
|
jpayne@69
|
11 furnished to do so, subject to the following conditions:
|
jpayne@69
|
12
|
jpayne@69
|
13 The above copyright notice and this permission notice shall be
|
jpayne@69
|
14 included in all copies or substantial portions of the Software.
|
jpayne@69
|
15
|
jpayne@69
|
16 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
jpayne@69
|
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
jpayne@69
|
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
jpayne@69
|
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
jpayne@69
|
20 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
jpayne@69
|
21 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
jpayne@69
|
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
jpayne@69
|
23 DEALINGS IN THE SOFTWARE.
|
jpayne@69
|
24
|
jpayne@69
|
25 ----------------------------------------------------------------------- */
|
jpayne@69
|
26
|
jpayne@69
|
27 /* -------------------------------------------------------------------
|
jpayne@69
|
28 The basic API is described in the README file.
|
jpayne@69
|
29
|
jpayne@69
|
30 The raw API is designed to bypass some of the argument packing
|
jpayne@69
|
31 and unpacking on architectures for which it can be avoided.
|
jpayne@69
|
32
|
jpayne@69
|
33 The closure API allows interpreted functions to be packaged up
|
jpayne@69
|
34 inside a C function pointer, so that they can be called as C functions,
|
jpayne@69
|
35 with no understanding on the client side that they are interpreted.
|
jpayne@69
|
36 It can also be used in other cases in which it is necessary to package
|
jpayne@69
|
37 up a user specified parameter and a function pointer as a single
|
jpayne@69
|
38 function pointer.
|
jpayne@69
|
39
|
jpayne@69
|
40 The closure API must be implemented in order to get its functionality,
|
jpayne@69
|
41 e.g. for use by gij. Routines are provided to emulate the raw API
|
jpayne@69
|
42 if the underlying platform doesn't allow faster implementation.
|
jpayne@69
|
43
|
jpayne@69
|
44 More details on the raw and cloure API can be found in:
|
jpayne@69
|
45
|
jpayne@69
|
46 http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
|
jpayne@69
|
47
|
jpayne@69
|
48 and
|
jpayne@69
|
49
|
jpayne@69
|
50 http://gcc.gnu.org/ml/java/1999-q3/msg00174.html
|
jpayne@69
|
51 -------------------------------------------------------------------- */
|
jpayne@69
|
52
|
jpayne@69
|
53 #ifndef LIBFFI_H
|
jpayne@69
|
54 #define LIBFFI_H
|
jpayne@69
|
55
|
jpayne@69
|
56 #ifdef __cplusplus
|
jpayne@69
|
57 extern "C" {
|
jpayne@69
|
58 #endif
|
jpayne@69
|
59
|
jpayne@69
|
60 /* Specify which architecture libffi is configured for. */
|
jpayne@69
|
61 #ifndef X86_64
|
jpayne@69
|
62 #define X86_64
|
jpayne@69
|
63 #endif
|
jpayne@69
|
64
|
jpayne@69
|
65 /* ---- System configuration information --------------------------------- */
|
jpayne@69
|
66
|
jpayne@69
|
67 #include <ffitarget.h>
|
jpayne@69
|
68
|
jpayne@69
|
69 #ifndef LIBFFI_ASM
|
jpayne@69
|
70
|
jpayne@69
|
71 #if defined(_MSC_VER) && !defined(__clang__)
|
jpayne@69
|
72 #define __attribute__(X)
|
jpayne@69
|
73 #endif
|
jpayne@69
|
74
|
jpayne@69
|
75 #include <stddef.h>
|
jpayne@69
|
76 #include <limits.h>
|
jpayne@69
|
77
|
jpayne@69
|
78 /* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example).
|
jpayne@69
|
79 But we can find it either under the correct ANSI name, or under GNU
|
jpayne@69
|
80 C's internal name. */
|
jpayne@69
|
81
|
jpayne@69
|
82 #define FFI_64_BIT_MAX 9223372036854775807
|
jpayne@69
|
83
|
jpayne@69
|
84 #ifdef LONG_LONG_MAX
|
jpayne@69
|
85 # define FFI_LONG_LONG_MAX LONG_LONG_MAX
|
jpayne@69
|
86 #else
|
jpayne@69
|
87 # ifdef LLONG_MAX
|
jpayne@69
|
88 # define FFI_LONG_LONG_MAX LLONG_MAX
|
jpayne@69
|
89 # ifdef _AIX52 /* or newer has C99 LLONG_MAX */
|
jpayne@69
|
90 # undef FFI_64_BIT_MAX
|
jpayne@69
|
91 # define FFI_64_BIT_MAX 9223372036854775807LL
|
jpayne@69
|
92 # endif /* _AIX52 or newer */
|
jpayne@69
|
93 # else
|
jpayne@69
|
94 # ifdef __GNUC__
|
jpayne@69
|
95 # define FFI_LONG_LONG_MAX __LONG_LONG_MAX__
|
jpayne@69
|
96 # endif
|
jpayne@69
|
97 # ifdef _AIX /* AIX 5.1 and earlier have LONGLONG_MAX */
|
jpayne@69
|
98 # ifndef __PPC64__
|
jpayne@69
|
99 # if defined (__IBMC__) || defined (__IBMCPP__)
|
jpayne@69
|
100 # define FFI_LONG_LONG_MAX LONGLONG_MAX
|
jpayne@69
|
101 # endif
|
jpayne@69
|
102 # endif /* __PPC64__ */
|
jpayne@69
|
103 # undef FFI_64_BIT_MAX
|
jpayne@69
|
104 # define FFI_64_BIT_MAX 9223372036854775807LL
|
jpayne@69
|
105 # endif
|
jpayne@69
|
106 # endif
|
jpayne@69
|
107 #endif
|
jpayne@69
|
108
|
jpayne@69
|
109 /* The closure code assumes that this works on pointers, i.e. a size_t */
|
jpayne@69
|
110 /* can hold a pointer. */
|
jpayne@69
|
111
|
jpayne@69
|
112 typedef struct _ffi_type
|
jpayne@69
|
113 {
|
jpayne@69
|
114 size_t size;
|
jpayne@69
|
115 unsigned short alignment;
|
jpayne@69
|
116 unsigned short type;
|
jpayne@69
|
117 struct _ffi_type **elements;
|
jpayne@69
|
118 } ffi_type;
|
jpayne@69
|
119
|
jpayne@69
|
120 #ifndef LIBFFI_HIDE_BASIC_TYPES
|
jpayne@69
|
121 #if SCHAR_MAX == 127
|
jpayne@69
|
122 # define ffi_type_uchar ffi_type_uint8
|
jpayne@69
|
123 # define ffi_type_schar ffi_type_sint8
|
jpayne@69
|
124 #else
|
jpayne@69
|
125 #error "char size not supported"
|
jpayne@69
|
126 #endif
|
jpayne@69
|
127
|
jpayne@69
|
128 #if SHRT_MAX == 32767
|
jpayne@69
|
129 # define ffi_type_ushort ffi_type_uint16
|
jpayne@69
|
130 # define ffi_type_sshort ffi_type_sint16
|
jpayne@69
|
131 #elif SHRT_MAX == 2147483647
|
jpayne@69
|
132 # define ffi_type_ushort ffi_type_uint32
|
jpayne@69
|
133 # define ffi_type_sshort ffi_type_sint32
|
jpayne@69
|
134 #else
|
jpayne@69
|
135 #error "short size not supported"
|
jpayne@69
|
136 #endif
|
jpayne@69
|
137
|
jpayne@69
|
138 #if INT_MAX == 32767
|
jpayne@69
|
139 # define ffi_type_uint ffi_type_uint16
|
jpayne@69
|
140 # define ffi_type_sint ffi_type_sint16
|
jpayne@69
|
141 #elif INT_MAX == 2147483647
|
jpayne@69
|
142 # define ffi_type_uint ffi_type_uint32
|
jpayne@69
|
143 # define ffi_type_sint ffi_type_sint32
|
jpayne@69
|
144 #elif INT_MAX == 9223372036854775807
|
jpayne@69
|
145 # define ffi_type_uint ffi_type_uint64
|
jpayne@69
|
146 # define ffi_type_sint ffi_type_sint64
|
jpayne@69
|
147 #else
|
jpayne@69
|
148 #error "int size not supported"
|
jpayne@69
|
149 #endif
|
jpayne@69
|
150
|
jpayne@69
|
151 #if LONG_MAX == 2147483647
|
jpayne@69
|
152 # if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX
|
jpayne@69
|
153 #error "no 64-bit data type supported"
|
jpayne@69
|
154 # endif
|
jpayne@69
|
155 #elif LONG_MAX != FFI_64_BIT_MAX
|
jpayne@69
|
156 #error "long size not supported"
|
jpayne@69
|
157 #endif
|
jpayne@69
|
158
|
jpayne@69
|
159 #if LONG_MAX == 2147483647
|
jpayne@69
|
160 # define ffi_type_ulong ffi_type_uint32
|
jpayne@69
|
161 # define ffi_type_slong ffi_type_sint32
|
jpayne@69
|
162 #elif LONG_MAX == FFI_64_BIT_MAX
|
jpayne@69
|
163 # define ffi_type_ulong ffi_type_uint64
|
jpayne@69
|
164 # define ffi_type_slong ffi_type_sint64
|
jpayne@69
|
165 #else
|
jpayne@69
|
166 #error "long size not supported"
|
jpayne@69
|
167 #endif
|
jpayne@69
|
168
|
jpayne@69
|
169 /* Need minimal decorations for DLLs to works on Windows. */
|
jpayne@69
|
170 /* GCC has autoimport and autoexport. Rely on Libtool to */
|
jpayne@69
|
171 /* help MSVC export from a DLL, but always declare data */
|
jpayne@69
|
172 /* to be imported for MSVC clients. This costs an extra */
|
jpayne@69
|
173 /* indirection for MSVC clients using the static version */
|
jpayne@69
|
174 /* of the library, but don't worry about that. Besides, */
|
jpayne@69
|
175 /* as a workaround, they can define FFI_BUILDING if they */
|
jpayne@69
|
176 /* *know* they are going to link with the static library. */
|
jpayne@69
|
177 #if defined _MSC_VER && !defined FFI_BUILDING
|
jpayne@69
|
178 #define FFI_EXTERN extern __declspec(dllimport)
|
jpayne@69
|
179 #else
|
jpayne@69
|
180 #define FFI_EXTERN extern
|
jpayne@69
|
181 #endif
|
jpayne@69
|
182
|
jpayne@69
|
183 /* These are defined in types.c */
|
jpayne@69
|
184 FFI_EXTERN ffi_type ffi_type_void;
|
jpayne@69
|
185 FFI_EXTERN ffi_type ffi_type_uint8;
|
jpayne@69
|
186 FFI_EXTERN ffi_type ffi_type_sint8;
|
jpayne@69
|
187 FFI_EXTERN ffi_type ffi_type_uint16;
|
jpayne@69
|
188 FFI_EXTERN ffi_type ffi_type_sint16;
|
jpayne@69
|
189 FFI_EXTERN ffi_type ffi_type_uint32;
|
jpayne@69
|
190 FFI_EXTERN ffi_type ffi_type_sint32;
|
jpayne@69
|
191 FFI_EXTERN ffi_type ffi_type_uint64;
|
jpayne@69
|
192 FFI_EXTERN ffi_type ffi_type_sint64;
|
jpayne@69
|
193 FFI_EXTERN ffi_type ffi_type_float;
|
jpayne@69
|
194 FFI_EXTERN ffi_type ffi_type_double;
|
jpayne@69
|
195 FFI_EXTERN ffi_type ffi_type_pointer;
|
jpayne@69
|
196
|
jpayne@69
|
197 #if 1
|
jpayne@69
|
198 FFI_EXTERN ffi_type ffi_type_longdouble;
|
jpayne@69
|
199 #else
|
jpayne@69
|
200 #define ffi_type_longdouble ffi_type_double
|
jpayne@69
|
201 #endif
|
jpayne@69
|
202
|
jpayne@69
|
203 #ifdef FFI_TARGET_HAS_COMPLEX_TYPE
|
jpayne@69
|
204 FFI_EXTERN ffi_type ffi_type_complex_float;
|
jpayne@69
|
205 FFI_EXTERN ffi_type ffi_type_complex_double;
|
jpayne@69
|
206 #if 1
|
jpayne@69
|
207 FFI_EXTERN ffi_type ffi_type_complex_longdouble;
|
jpayne@69
|
208 #else
|
jpayne@69
|
209 #define ffi_type_complex_longdouble ffi_type_complex_double
|
jpayne@69
|
210 #endif
|
jpayne@69
|
211 #endif
|
jpayne@69
|
212 #endif /* LIBFFI_HIDE_BASIC_TYPES */
|
jpayne@69
|
213
|
jpayne@69
|
214 typedef enum {
|
jpayne@69
|
215 FFI_OK = 0,
|
jpayne@69
|
216 FFI_BAD_TYPEDEF,
|
jpayne@69
|
217 FFI_BAD_ABI
|
jpayne@69
|
218 } ffi_status;
|
jpayne@69
|
219
|
jpayne@69
|
220 typedef unsigned FFI_TYPE;
|
jpayne@69
|
221
|
jpayne@69
|
222 typedef struct {
|
jpayne@69
|
223 ffi_abi abi;
|
jpayne@69
|
224 unsigned nargs;
|
jpayne@69
|
225 ffi_type **arg_types;
|
jpayne@69
|
226 ffi_type *rtype;
|
jpayne@69
|
227 unsigned bytes;
|
jpayne@69
|
228 unsigned flags;
|
jpayne@69
|
229 #ifdef FFI_EXTRA_CIF_FIELDS
|
jpayne@69
|
230 FFI_EXTRA_CIF_FIELDS;
|
jpayne@69
|
231 #endif
|
jpayne@69
|
232 } ffi_cif;
|
jpayne@69
|
233
|
jpayne@69
|
234 #if 0
|
jpayne@69
|
235 /* Used to adjust size/alignment of ffi types. */
|
jpayne@69
|
236 void ffi_prep_types (ffi_abi abi);
|
jpayne@69
|
237 #endif
|
jpayne@69
|
238
|
jpayne@69
|
239 /* Used internally, but overridden by some architectures */
|
jpayne@69
|
240 ffi_status ffi_prep_cif_core(ffi_cif *cif,
|
jpayne@69
|
241 ffi_abi abi,
|
jpayne@69
|
242 unsigned int isvariadic,
|
jpayne@69
|
243 unsigned int nfixedargs,
|
jpayne@69
|
244 unsigned int ntotalargs,
|
jpayne@69
|
245 ffi_type *rtype,
|
jpayne@69
|
246 ffi_type **atypes);
|
jpayne@69
|
247
|
jpayne@69
|
248 /* ---- Definitions for the raw API -------------------------------------- */
|
jpayne@69
|
249
|
jpayne@69
|
250 #ifndef FFI_SIZEOF_ARG
|
jpayne@69
|
251 # if LONG_MAX == 2147483647
|
jpayne@69
|
252 # define FFI_SIZEOF_ARG 4
|
jpayne@69
|
253 # elif LONG_MAX == FFI_64_BIT_MAX
|
jpayne@69
|
254 # define FFI_SIZEOF_ARG 8
|
jpayne@69
|
255 # endif
|
jpayne@69
|
256 #endif
|
jpayne@69
|
257
|
jpayne@69
|
258 #ifndef FFI_SIZEOF_JAVA_RAW
|
jpayne@69
|
259 # define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG
|
jpayne@69
|
260 #endif
|
jpayne@69
|
261
|
jpayne@69
|
262 typedef union {
|
jpayne@69
|
263 ffi_sarg sint;
|
jpayne@69
|
264 ffi_arg uint;
|
jpayne@69
|
265 float flt;
|
jpayne@69
|
266 char data[FFI_SIZEOF_ARG];
|
jpayne@69
|
267 void* ptr;
|
jpayne@69
|
268 } ffi_raw;
|
jpayne@69
|
269
|
jpayne@69
|
270 #if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8
|
jpayne@69
|
271 /* This is a special case for mips64/n32 ABI (and perhaps others) where
|
jpayne@69
|
272 sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */
|
jpayne@69
|
273 typedef union {
|
jpayne@69
|
274 signed int sint;
|
jpayne@69
|
275 unsigned int uint;
|
jpayne@69
|
276 float flt;
|
jpayne@69
|
277 char data[FFI_SIZEOF_JAVA_RAW];
|
jpayne@69
|
278 void* ptr;
|
jpayne@69
|
279 } ffi_java_raw;
|
jpayne@69
|
280 #else
|
jpayne@69
|
281 typedef ffi_raw ffi_java_raw;
|
jpayne@69
|
282 #endif
|
jpayne@69
|
283
|
jpayne@69
|
284
|
jpayne@69
|
285 void ffi_raw_call (ffi_cif *cif,
|
jpayne@69
|
286 void (*fn)(void),
|
jpayne@69
|
287 void *rvalue,
|
jpayne@69
|
288 ffi_raw *avalue);
|
jpayne@69
|
289
|
jpayne@69
|
290 void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
|
jpayne@69
|
291 void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
|
jpayne@69
|
292 size_t ffi_raw_size (ffi_cif *cif);
|
jpayne@69
|
293
|
jpayne@69
|
294 /* This is analogous to the raw API, except it uses Java parameter */
|
jpayne@69
|
295 /* packing, even on 64-bit machines. I.e. on 64-bit machines */
|
jpayne@69
|
296 /* longs and doubles are followed by an empty 64-bit word. */
|
jpayne@69
|
297
|
jpayne@69
|
298 void ffi_java_raw_call (ffi_cif *cif,
|
jpayne@69
|
299 void (*fn)(void),
|
jpayne@69
|
300 void *rvalue,
|
jpayne@69
|
301 ffi_java_raw *avalue);
|
jpayne@69
|
302
|
jpayne@69
|
303 void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw);
|
jpayne@69
|
304 void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args);
|
jpayne@69
|
305 size_t ffi_java_raw_size (ffi_cif *cif);
|
jpayne@69
|
306
|
jpayne@69
|
307 /* ---- Definitions for closures ----------------------------------------- */
|
jpayne@69
|
308
|
jpayne@69
|
309 #if FFI_CLOSURES
|
jpayne@69
|
310
|
jpayne@69
|
311 #ifdef _MSC_VER
|
jpayne@69
|
312 __declspec(align(8))
|
jpayne@69
|
313 #endif
|
jpayne@69
|
314 typedef struct {
|
jpayne@69
|
315 #if 0
|
jpayne@69
|
316 void *trampoline_table;
|
jpayne@69
|
317 void *trampoline_table_entry;
|
jpayne@69
|
318 #else
|
jpayne@69
|
319 char tramp[FFI_TRAMPOLINE_SIZE];
|
jpayne@69
|
320 #endif
|
jpayne@69
|
321 ffi_cif *cif;
|
jpayne@69
|
322 void (*fun)(ffi_cif*,void*,void**,void*);
|
jpayne@69
|
323 void *user_data;
|
jpayne@69
|
324 #ifdef __GNUC__
|
jpayne@69
|
325 } ffi_closure __attribute__((aligned (8)));
|
jpayne@69
|
326 #else
|
jpayne@69
|
327 } ffi_closure;
|
jpayne@69
|
328 # ifdef __sgi
|
jpayne@69
|
329 # pragma pack 0
|
jpayne@69
|
330 # endif
|
jpayne@69
|
331 #endif
|
jpayne@69
|
332
|
jpayne@69
|
333 void *ffi_closure_alloc (size_t size, void **code);
|
jpayne@69
|
334 void ffi_closure_free (void *);
|
jpayne@69
|
335
|
jpayne@69
|
336 ffi_status
|
jpayne@69
|
337 ffi_prep_closure (ffi_closure*,
|
jpayne@69
|
338 ffi_cif *,
|
jpayne@69
|
339 void (*fun)(ffi_cif*,void*,void**,void*),
|
jpayne@69
|
340 void *user_data);
|
jpayne@69
|
341
|
jpayne@69
|
342 ffi_status
|
jpayne@69
|
343 ffi_prep_closure_loc (ffi_closure*,
|
jpayne@69
|
344 ffi_cif *,
|
jpayne@69
|
345 void (*fun)(ffi_cif*,void*,void**,void*),
|
jpayne@69
|
346 void *user_data,
|
jpayne@69
|
347 void*codeloc);
|
jpayne@69
|
348
|
jpayne@69
|
349 #ifdef __sgi
|
jpayne@69
|
350 # pragma pack 8
|
jpayne@69
|
351 #endif
|
jpayne@69
|
352 typedef struct {
|
jpayne@69
|
353 #if 0
|
jpayne@69
|
354 void *trampoline_table;
|
jpayne@69
|
355 void *trampoline_table_entry;
|
jpayne@69
|
356 #else
|
jpayne@69
|
357 char tramp[FFI_TRAMPOLINE_SIZE];
|
jpayne@69
|
358 #endif
|
jpayne@69
|
359 ffi_cif *cif;
|
jpayne@69
|
360
|
jpayne@69
|
361 #if !FFI_NATIVE_RAW_API
|
jpayne@69
|
362
|
jpayne@69
|
363 /* if this is enabled, then a raw closure has the same layout
|
jpayne@69
|
364 as a regular closure. We use this to install an intermediate
|
jpayne@69
|
365 handler to do the transaltion, void** -> ffi_raw*. */
|
jpayne@69
|
366
|
jpayne@69
|
367 void (*translate_args)(ffi_cif*,void*,void**,void*);
|
jpayne@69
|
368 void *this_closure;
|
jpayne@69
|
369
|
jpayne@69
|
370 #endif
|
jpayne@69
|
371
|
jpayne@69
|
372 void (*fun)(ffi_cif*,void*,ffi_raw*,void*);
|
jpayne@69
|
373 void *user_data;
|
jpayne@69
|
374
|
jpayne@69
|
375 } ffi_raw_closure;
|
jpayne@69
|
376
|
jpayne@69
|
377 typedef struct {
|
jpayne@69
|
378 #if 0
|
jpayne@69
|
379 void *trampoline_table;
|
jpayne@69
|
380 void *trampoline_table_entry;
|
jpayne@69
|
381 #else
|
jpayne@69
|
382 char tramp[FFI_TRAMPOLINE_SIZE];
|
jpayne@69
|
383 #endif
|
jpayne@69
|
384
|
jpayne@69
|
385 ffi_cif *cif;
|
jpayne@69
|
386
|
jpayne@69
|
387 #if !FFI_NATIVE_RAW_API
|
jpayne@69
|
388
|
jpayne@69
|
389 /* if this is enabled, then a raw closure has the same layout
|
jpayne@69
|
390 as a regular closure. We use this to install an intermediate
|
jpayne@69
|
391 handler to do the transaltion, void** -> ffi_raw*. */
|
jpayne@69
|
392
|
jpayne@69
|
393 void (*translate_args)(ffi_cif*,void*,void**,void*);
|
jpayne@69
|
394 void *this_closure;
|
jpayne@69
|
395
|
jpayne@69
|
396 #endif
|
jpayne@69
|
397
|
jpayne@69
|
398 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*);
|
jpayne@69
|
399 void *user_data;
|
jpayne@69
|
400
|
jpayne@69
|
401 } ffi_java_raw_closure;
|
jpayne@69
|
402
|
jpayne@69
|
403 ffi_status
|
jpayne@69
|
404 ffi_prep_raw_closure (ffi_raw_closure*,
|
jpayne@69
|
405 ffi_cif *cif,
|
jpayne@69
|
406 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
|
jpayne@69
|
407 void *user_data);
|
jpayne@69
|
408
|
jpayne@69
|
409 ffi_status
|
jpayne@69
|
410 ffi_prep_raw_closure_loc (ffi_raw_closure*,
|
jpayne@69
|
411 ffi_cif *cif,
|
jpayne@69
|
412 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
|
jpayne@69
|
413 void *user_data,
|
jpayne@69
|
414 void *codeloc);
|
jpayne@69
|
415
|
jpayne@69
|
416 ffi_status
|
jpayne@69
|
417 ffi_prep_java_raw_closure (ffi_java_raw_closure*,
|
jpayne@69
|
418 ffi_cif *cif,
|
jpayne@69
|
419 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
|
jpayne@69
|
420 void *user_data);
|
jpayne@69
|
421
|
jpayne@69
|
422 ffi_status
|
jpayne@69
|
423 ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
|
jpayne@69
|
424 ffi_cif *cif,
|
jpayne@69
|
425 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
|
jpayne@69
|
426 void *user_data,
|
jpayne@69
|
427 void *codeloc);
|
jpayne@69
|
428
|
jpayne@69
|
429 #endif /* FFI_CLOSURES */
|
jpayne@69
|
430
|
jpayne@69
|
431 /* ---- Public interface definition -------------------------------------- */
|
jpayne@69
|
432
|
jpayne@69
|
433 ffi_status ffi_prep_cif(ffi_cif *cif,
|
jpayne@69
|
434 ffi_abi abi,
|
jpayne@69
|
435 unsigned int nargs,
|
jpayne@69
|
436 ffi_type *rtype,
|
jpayne@69
|
437 ffi_type **atypes);
|
jpayne@69
|
438
|
jpayne@69
|
439 ffi_status ffi_prep_cif_var(ffi_cif *cif,
|
jpayne@69
|
440 ffi_abi abi,
|
jpayne@69
|
441 unsigned int nfixedargs,
|
jpayne@69
|
442 unsigned int ntotalargs,
|
jpayne@69
|
443 ffi_type *rtype,
|
jpayne@69
|
444 ffi_type **atypes);
|
jpayne@69
|
445
|
jpayne@69
|
446 void ffi_call(ffi_cif *cif,
|
jpayne@69
|
447 void (*fn)(void),
|
jpayne@69
|
448 void *rvalue,
|
jpayne@69
|
449 void **avalue);
|
jpayne@69
|
450
|
jpayne@69
|
451 /* Useful for eliminating compiler warnings */
|
jpayne@69
|
452 #define FFI_FN(f) ((void (*)(void))f)
|
jpayne@69
|
453
|
jpayne@69
|
454 /* ---- Definitions shared with assembly code ---------------------------- */
|
jpayne@69
|
455
|
jpayne@69
|
456 #endif
|
jpayne@69
|
457
|
jpayne@69
|
458 /* If these change, update src/mips/ffitarget.h. */
|
jpayne@69
|
459 #define FFI_TYPE_VOID 0
|
jpayne@69
|
460 #define FFI_TYPE_INT 1
|
jpayne@69
|
461 #define FFI_TYPE_FLOAT 2
|
jpayne@69
|
462 #define FFI_TYPE_DOUBLE 3
|
jpayne@69
|
463 #if 1
|
jpayne@69
|
464 #define FFI_TYPE_LONGDOUBLE 4
|
jpayne@69
|
465 #else
|
jpayne@69
|
466 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
|
jpayne@69
|
467 #endif
|
jpayne@69
|
468 #define FFI_TYPE_UINT8 5
|
jpayne@69
|
469 #define FFI_TYPE_SINT8 6
|
jpayne@69
|
470 #define FFI_TYPE_UINT16 7
|
jpayne@69
|
471 #define FFI_TYPE_SINT16 8
|
jpayne@69
|
472 #define FFI_TYPE_UINT32 9
|
jpayne@69
|
473 #define FFI_TYPE_SINT32 10
|
jpayne@69
|
474 #define FFI_TYPE_UINT64 11
|
jpayne@69
|
475 #define FFI_TYPE_SINT64 12
|
jpayne@69
|
476 #define FFI_TYPE_STRUCT 13
|
jpayne@69
|
477 #define FFI_TYPE_POINTER 14
|
jpayne@69
|
478 #define FFI_TYPE_COMPLEX 15
|
jpayne@69
|
479
|
jpayne@69
|
480 /* This should always refer to the last type code (for sanity checks) */
|
jpayne@69
|
481 #define FFI_TYPE_LAST FFI_TYPE_COMPLEX
|
jpayne@69
|
482
|
jpayne@69
|
483 #ifdef __cplusplus
|
jpayne@69
|
484 }
|
jpayne@69
|
485 #endif
|
jpayne@69
|
486
|
jpayne@69
|
487 #endif
|