1 /* -----------------------------------------------------------------*-C-*-
2 libffi @VERSION@ - Copyright (c) 1996-1999 Cygnus Solutions
4 $Id: ffi.h.in,v 1.4 2000/02/25 19:13:44 tromey Exp $
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 ``Software''), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
27 /* -------------------------------------------------------------------
28 The basic API is described in the README file.
30 The raw API is designed to bypass some of the argument packing
31 and unpacking on architectures for which it can be avoided.
33 The closure API allows interpreted functions to be packaged up
34 inside a C function pointer, so that they can be called as C functions,
35 with no understanding on the client side that they are interpreted.
36 It can also be used in other cases in which it is necessary to package
37 up a user specified parameter and a function pointer as a single
40 The closure API must be implemented in order to get its functionality,
41 e.g. for use by gij. Routines are provided to emulate the raw API
42 if the underlying platform doesn't allow faster implementation.
44 More details on the raw and cloure API can be found in:
46 http://sourceware.cygnus.com/ml/java-discuss/1999-q3/msg00138.html
50 http://sourceware.cygnus.com/ml/java-discuss/1999-q3/msg00174.html
51 -------------------------------------------------------------------- */
60 /* Specify which architecture libffi is configured for. */
63 /* ---- System configuration information --------------------------------- */
65 #include <fficonfig.h>
67 #if !defined(LIBFFI_ASM)
69 #if defined(FFI_DEBUG)
74 /* ---- Generic type definitions ----------------------------------------- */
77 #define FLOAT64 double
78 #define FLOAT80 long double
80 #define UINT8 unsigned char
81 #define SINT8 signed char
85 #define UINT16 unsigned int
87 #define ffi_type_uint ffi_type_uint16
88 #define ffi_type_sint ffi_type_sint16
93 #define UINT16 unsigned short
95 #define ffi_type_ushort ffi_type_uint16
96 #define ffi_type_sshort ffi_type_sint16
103 #define UINT32 unsigned int
105 #define ffi_type_uint ffi_type_uint32
106 #define ffi_type_sint ffi_type_sint32
109 #if SIZEOF_SHORT == 4
111 #define UINT32 unsigned short
113 #define ffi_type_ushort ffi_type_uint32
114 #define ffi_type_sshort ffi_type_sint32
119 #define UINT32 unsigned long
121 #define ffi_type_ulong ffi_type_uint32
122 #define ffi_type_slong ffi_type_sint32
130 #define UINT64 unsigned int
132 #define ffi_type_uint ffi_type_uint64
133 #define ffi_type_sint ffi_type_sint64
138 #define UINT64 unsigned long
140 #define ffi_type_ulong ffi_type_uint64
141 #define ffi_type_slong ffi_type_sint64
144 #if SIZEOF_LONG_LONG == 8
146 #define UINT64 unsigned long long
147 #define SINT64 long long
148 #define ffi_type_ulong ffi_type_uint64
149 #define ffi_type_slong ffi_type_sint64
155 /* ---- System specific configurations ----------------------------------- */
158 #include <ffi_mips.h>
160 #define SIZEOF_ARG SIZEOF_VOID_P
164 #if defined(__arch64__) || defined(__sparcv9)
171 /* ---- Generic type definitions ----------------------------------------- */
173 #define ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
174 /* The closure code assumes that this works on pointers, i.e. a size_t */
175 /* can hold a pointer. */
177 typedef enum ffi_abi
{
179 /* Leave this for debugging purposes */
182 /* ---- Sparc -------------------- */
188 FFI_DEFAULT_ABI
= FFI_V9
,
190 FFI_DEFAULT_ABI
= FFI_V8
,
194 /* ---- Intel x86 ---------------- */
197 FFI_DEFAULT_ABI
= FFI_SYSV
,
200 /* ---- Intel ia64 ---------------- */
202 FFI_UNIX
, /* Linux and all Unix variants use the same conventions */
203 FFI_DEFAULT_ABI
= FFI_UNIX
,
206 /* ---- Mips --------------------- */
213 /* ---- Alpha -------------------- */
216 FFI_DEFAULT_ABI
= FFI_OSF
,
219 /* ---- Motorola m68k ------------ */
222 FFI_DEFAULT_ABI
= FFI_SYSV
,
225 /* ---- PowerPC ------------------ */
229 FFI_DEFAULT_ABI
= FFI_GCC_SYSV
,
232 /* ---- ARM --------------------- */
235 FFI_DEFAULT_ABI
= FFI_SYSV
,
238 /* Leave this for debugging purposes */
243 typedef struct _ffi_type
246 unsigned short alignment
;
248 /*@null@*/ struct _ffi_type
**elements
;
251 /* These are defined in ffi.c */
252 extern ffi_type ffi_type_void
;
253 extern ffi_type ffi_type_uint8
;
254 extern ffi_type ffi_type_sint8
;
255 extern ffi_type ffi_type_uint16
;
256 extern ffi_type ffi_type_sint16
;
257 extern ffi_type ffi_type_uint32
;
258 extern ffi_type ffi_type_sint32
;
259 extern ffi_type ffi_type_uint64
;
260 extern ffi_type ffi_type_sint64
;
261 extern ffi_type ffi_type_float
;
262 extern ffi_type ffi_type_double
;
263 extern ffi_type ffi_type_longdouble
;
264 extern ffi_type ffi_type_pointer
;
266 /* Characters are 8 bit integral types */
267 #define ffi_type_schar ffi_type_sint8
268 #define ffi_type_uchar ffi_type_uint8
276 typedef unsigned FFI_TYPE
;
281 /*@dependent@*/ ffi_type
**arg_types
;
282 /*@dependent@*/ ffi_type
*rtype
;
287 #if _MIPS_SIM == _ABIN32
288 unsigned rstruct_flag
;
294 /* ---- Definitions for the raw API -------------------------------------- */
300 #define UINT_ARG UINT32
301 #define SINT_ARG SINT32
307 #define UINT_ARG UINT64
308 #define SINT_ARG SINT64
316 char data
[SIZEOF_ARG
];
320 void ffi_raw_call (/*@dependent@*/ ffi_cif
*cif
,
322 /*@out@*/ void *rvalue
,
323 /*@dependent@*/ ffi_raw
*avalue
);
325 void ffi_ptrarray_to_raw (ffi_cif
*cif
, void **args
, ffi_raw
*raw
);
326 void ffi_raw_to_ptrarray (ffi_cif
*cif
, ffi_raw
*raw
, void **args
);
327 size_t ffi_raw_size (ffi_cif
*cif
);
331 /* This is analogous to the raw API, except it uses Java parameter */
332 /* packing, even on 64-bit machines. I.e. on 64-bit machines */
333 /* longs and doubles are followed by an empty 64-bit word. */
335 void ffi_java_raw_call (/*@dependent@*/ ffi_cif
*cif
,
337 /*@out@*/ void *rvalue
,
338 /*@dependent@*/ ffi_raw
*avalue
);
340 void ffi_java_ptrarray_to_raw (ffi_cif
*cif
, void **args
, ffi_raw
*raw
);
341 void ffi_java_raw_to_ptrarray (ffi_cif
*cif
, ffi_raw
*raw
, void **args
);
342 size_t ffi_java_raw_size (ffi_cif
*cif
);
344 #endif /* !NO_JAVA_RAW_API */
346 #endif /* !FFI_NO_RAW_API */
348 /* ---- Definitions for closures ----------------------------------------- */
352 #define FFI_CLOSURES 1 /* x86 supports closures */
353 #define FFI_TRAMPOLINE_SIZE 10
354 #define FFI_NATIVE_RAW_API 1 /* and has native raw api support */
358 #define FFI_CLOSURES 1
359 #define FFI_TRAMPOLINE_SIZE 24 /* Really the following struct, which */
360 /* can be interpreted as a C function */
363 struct ffi_ia64_trampoline_struct
{
364 void * code_pointer
; /* Pointer to ffi_closure_UNIX */
365 void * fake_gp
; /* Pointer to closure, installed as gp */
366 void * real_gp
; /* Real gp value, reinstalled by */
367 /* ffi_closure_UNIX. */
369 #define FFI_NATIVE_RAW_API 0
373 #define FFI_CLOSURES 0
374 #define FFI_NATIVE_RAW_API 0
383 char tramp
[FFI_TRAMPOLINE_SIZE
];
385 void (*fun
)(ffi_cif
*,void*,void**,void*);
390 ffi_prep_closure (ffi_closure
*,
392 void (*fun
)(ffi_cif
*,void*,void**,void*),
398 char tramp
[FFI_TRAMPOLINE_SIZE
];
402 #if !FFI_NATIVE_RAW_API
404 /* if this is enabled, then a raw closure has the same layout
405 as a regular closure. We use this to install an intermediate
406 handler to do the transaltion, void** -> ffi_raw*. */
408 void (*translate_args
)(ffi_cif
*,void*,void**,void*);
413 void (*fun
)(ffi_cif
*,void*,ffi_raw
*,void*);
419 ffi_prep_raw_closure (ffi_raw_closure
*,
421 void (*fun
)(ffi_cif
*,void*,ffi_raw
*,void*),
424 #ifndef NO_JAVA_RAW_API
426 ffi_prep_java_raw_closure (ffi_raw_closure
*,
428 void (*fun
)(ffi_cif
*,void*,ffi_raw
*,void*),
432 #endif /* !FFI_NO_RAW_API */
433 #endif /* FFI_CLOSURES */
435 /* ---- Public interface definition -------------------------------------- */
437 ffi_status
ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif
*cif
,
440 /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type
*rtype
,
441 /*@dependent@*/ ffi_type
**atypes
);
443 void ffi_call(/*@dependent@*/ ffi_cif
*cif
,
445 /*@out@*/ void *rvalue
,
446 /*@dependent@*/ void **avalue
);
448 /* Useful for eliminating compiler warnings */
449 #define FFI_FN(f) ((void (*)())f)
451 /* ---- Definitions shared with assembly code ---------------------------- */
455 #define FFI_TYPE_VOID 0
456 #define FFI_TYPE_INT 1
457 #define FFI_TYPE_FLOAT 2
458 #define FFI_TYPE_DOUBLE 3
459 #if SIZEOF_LONG_DOUBLE == SIZEOF_DOUBLE
460 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
462 #define FFI_TYPE_LONGDOUBLE 4
465 #define FFI_TYPE_UINT8 5 /* If this changes, update ffi_mips.h. */
466 #define FFI_TYPE_SINT8 6 /* If this changes, update ffi_mips.h. */
467 #define FFI_TYPE_UINT16 7
468 #define FFI_TYPE_SINT16 8
469 #define FFI_TYPE_UINT32 9
470 #define FFI_TYPE_SINT32 10
471 #define FFI_TYPE_UINT64 11
472 #define FFI_TYPE_SINT64 12
473 #define FFI_TYPE_STRUCT 13 /* If this changes, update ffi_mips.h. */
474 #define FFI_TYPE_POINTER 14
476 /* This should always refer to the last type code (for sanity checks) */
477 #define FFI_TYPE_LAST FFI_TYPE_POINTER