1 /* -----------------------------------------------------------------*-C-*-
2 libffi @VERSION@ - Copyright (c) 1996-1999 Cygnus Solutions
4 $Id: ffi.h.in,v 1.2 1999/08/09 02:52:58 green 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 ----------------------------------------------------------------------- */
34 /* Specify which architecture libffi is configured for. */
37 /* ---- System configuration information --------------------------------- */
39 #include <fficonfig.h>
41 #if !defined(LIBFFI_ASM)
43 #if defined(FFI_DEBUG)
48 /* ---- Generic type definitions ----------------------------------------- */
51 #define FLOAT64 double
52 #define FLOAT80 long double
54 #define UINT8 unsigned char
55 #define SINT8 signed char
59 #define UINT16 unsigned int
61 #define ffi_type_uint ffi_type_uint16
62 #define ffi_type_sint ffi_type_sint16
67 #define UINT16 unsigned short
69 #define ffi_type_ushort ffi_type_uint16
70 #define ffi_type_sshort ffi_type_sint16
77 #define UINT32 unsigned int
79 #define ffi_type_uint ffi_type_uint32
80 #define ffi_type_sint ffi_type_sint32
85 #define UINT32 unsigned short
87 #define ffi_type_ushort ffi_type_uint32
88 #define ffi_type_sshort ffi_type_sint32
93 #define UINT32 unsigned long
95 #define ffi_type_ulong ffi_type_uint32
96 #define ffi_type_slong ffi_type_sint32
104 #define UINT64 unsigned int
106 #define ffi_type_uint ffi_type_uint64
107 #define ffi_type_sint ffi_type_sint64
112 #define UINT64 unsigned long
114 #define ffi_type_ulong ffi_type_uint64
115 #define ffi_type_slong ffi_type_sint64
118 #if SIZEOF_LONG_LONG == 8
120 #define UINT64 unsigned long long
121 #define SINT64 long long
122 #define ffi_type_ulong ffi_type_uint64
123 #define ffi_type_slong ffi_type_sint64
129 /* ---- System specific configurations ----------------------------------- */
132 #include <ffi_mips.h>
134 #define SIZEOF_ARG SIZEOF_VOID_P
139 /* ---- Generic type definitions ----------------------------------------- */
141 #define ALIGN(v, a) (((((unsigned) (v))-1) | ((a)-1))+1)
143 typedef enum ffi_abi
{
145 /* Leave this for debugging purposes */
148 /* ---- Sparc -------------------- */
151 FFI_DEFAULT_ABI
= FFI_V8
,
156 /* ---- Intel x86 ---------------- */
159 FFI_DEFAULT_ABI
= FFI_SYSV
,
162 /* ---- Mips --------------------- */
169 /* ---- Alpha -------------------- */
172 FFI_DEFAULT_ABI
= FFI_OSF
,
175 /* ---- Motorola m68k ------------ */
178 FFI_DEFAULT_ABI
= FFI_SYSV
,
181 /* ---- PowerPC ------------------ */
185 FFI_DEFAULT_ABI
= FFI_GCC_SYSV
,
188 /* ---- ARM --------------------- */
191 FFI_DEFAULT_ABI
= FFI_SYSV
,
194 /* Leave this for debugging purposes */
199 typedef struct _ffi_type
202 unsigned short alignment
;
204 /*@null@*/ struct _ffi_type
**elements
;
207 /* These are defined in ffi.c */
208 extern ffi_type ffi_type_void
;
209 extern ffi_type ffi_type_uint8
;
210 extern ffi_type ffi_type_sint8
;
211 extern ffi_type ffi_type_uint16
;
212 extern ffi_type ffi_type_sint16
;
213 extern ffi_type ffi_type_uint32
;
214 extern ffi_type ffi_type_sint32
;
215 extern ffi_type ffi_type_uint64
;
216 extern ffi_type ffi_type_sint64
;
217 extern ffi_type ffi_type_float
;
218 extern ffi_type ffi_type_double
;
219 extern ffi_type ffi_type_longdouble
;
220 extern ffi_type ffi_type_pointer
;
222 /* Characters are 8 bit integral types */
223 #define ffi_type_schar ffi_type_sint8
224 #define ffi_type_uchar ffi_type_uint8
232 typedef unsigned FFI_TYPE
;
237 /*@dependent@*/ ffi_type
**arg_types
;
238 /*@dependent@*/ ffi_type
*rtype
;
243 #if _MIPS_SIM == _ABIN32
244 unsigned rstruct_flag
;
250 /* ---- Definitions for the raw API -------------------------------------- */
256 #define UINT_ARG UINT32
257 #define SINT_ARG SINT32
263 #define UINT_ARG UINT64
264 #define SINT_ARG SINT64
271 char data
[SIZEOF_ARG
];
275 void ffi_raw_call (/*@dependent@*/ ffi_cif
*cif
,
277 /*@out@*/ void *rvalue
,
278 /*@dependent@*/ ffi_raw
*avalue
);
280 void ffi_ptrarray_to_raw (ffi_cif
*cif
, void **args
, ffi_raw
*raw
);
281 void ffi_raw_to_ptrarray (ffi_cif
*cif
, ffi_raw
*raw
, void **args
);
282 size_t ffi_raw_size (ffi_cif
*cif
);
287 #endif /* !FFI_NO_RAW_API */
289 /* ---- Definitions for closures ----------------------------------------- */
293 #define FFI_CLOSURES 1 /* x86 supports closures */
294 #define FFI_TRAMPOLINE_SIZE 10
295 #define FFI_NATIVE_RAW_API 1 /* and has native raw api support */
299 #define FFI_CLOSURES 0
300 #define FFI_NATIVE_RAW_API 0
309 char tramp
[FFI_TRAMPOLINE_SIZE
];
311 void (*fun
)(ffi_cif
*,void*,void**,void*);
316 ffi_prep_closure (ffi_closure
*,
318 void (*fun
)(ffi_cif
*,void*,void**,void*),
324 char tramp
[FFI_TRAMPOLINE_SIZE
];
328 #if !FFI_NATIVE_RAW_API
330 /* if this is enabled, then a raw closure has the same layout
331 as a regular closure. We use this to install an intermediate
332 handler to do the transaltion, void** -> ffi_raw*. */
334 void (*translate_args
)(ffi_cif
*,void*,void**,void*);
339 void (*fun
)(ffi_cif
*,void*,ffi_raw
*,void*);
345 ffi_prep_raw_closure (ffi_raw_closure
*,
347 void (*fun
)(ffi_cif
*,void*,ffi_raw
*,void*),
350 #endif /* !FFI_NO_RAW_API */
351 #endif /* FFI_CLOSURES */
353 /* ---- Public interface definition -------------------------------------- */
355 ffi_status
ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif
*cif
,
358 /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type
*rtype
,
359 /*@dependent@*/ ffi_type
**atypes
);
361 void ffi_call(/*@dependent@*/ ffi_cif
*cif
,
363 /*@out@*/ void *rvalue
,
364 /*@dependent@*/ void **avalue
);
366 /* Useful for eliminating compiler warnings */
367 #define FFI_FN(f) ((void (*)())f)
369 /* ---- Definitions shared with assembly code ---------------------------- */
373 #define FFI_TYPE_VOID 0
374 #define FFI_TYPE_INT 1
375 #define FFI_TYPE_FLOAT 2
376 #define FFI_TYPE_DOUBLE 3
377 #if SIZEOF_LONG_DOUBLE == SIZEOF_DOUBLE
378 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
380 #define FFI_TYPE_LONGDOUBLE 4
383 #define FFI_TYPE_UINT8 5 /* If this changes, update ffi_mips.h. */
384 #define FFI_TYPE_SINT8 6 /* If this changes, update ffi_mips.h. */
385 #define FFI_TYPE_UINT16 7
386 #define FFI_TYPE_SINT16 8
387 #define FFI_TYPE_UINT32 9
388 #define FFI_TYPE_SINT32 10
389 #define FFI_TYPE_UINT64 11
390 #define FFI_TYPE_SINT64 12
391 #define FFI_TYPE_STRUCT 13 /* If this changes, update ffi_mips.h. */
392 #define FFI_TYPE_POINTER 14
394 /* This should always refer to the last type code (for sanity checks) */
395 #define FFI_TYPE_LAST FFI_TYPE_POINTER