source: trunk/src/gcc/libffi/include/ffi.h.in@ 9

Last change on this file since 9 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 12.7 KB
Line 
1/* -----------------------------------------------------------------*-C-*-
2 libffi @VERSION@ - Copyright (c) 1996-2002 Cygnus Solutions
3
4 Permission is hereby granted, free of charge, to any person obtaining
5 a copy of this software and associated documentation files (the
6 ``Software''), to deal in the Software without restriction, including
7 without limitation the rights to use, copy, modify, merge, publish,
8 distribute, sublicense, and/or sell copies of the Software, and to
9 permit persons to whom the Software is furnished to do so, subject to
10 the following conditions:
11
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
22
23 ----------------------------------------------------------------------- */
24
25/* -------------------------------------------------------------------
26 The basic API is described in the README file.
27
28 The raw API is designed to bypass some of the argument packing
29 and unpacking on architectures for which it can be avoided.
30
31 The closure API allows interpreted functions to be packaged up
32 inside a C function pointer, so that they can be called as C functions,
33 with no understanding on the client side that they are interpreted.
34 It can also be used in other cases in which it is necessary to package
35 up a user specified parameter and a function pointer as a single
36 function pointer.
37
38 The closure API must be implemented in order to get its functionality,
39 e.g. for use by gij. Routines are provided to emulate the raw API
40 if the underlying platform doesn't allow faster implementation.
41
42 More details on the raw and cloure API can be found in:
43
44 http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
45
46 and
47
48 http://gcc.gnu.org/ml/java/1999-q3/msg00174.html
49 -------------------------------------------------------------------- */
50
51#ifndef LIBFFI_H
52#define LIBFFI_H
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58/* Specify which architecture libffi is configured for. */
59#define @TARGET@
60
61/* ---- System configuration information --------------------------------- */
62
63#include <fficonfig.h>
64
65#if !defined(LIBFFI_ASM)
66#include <stddef.h>
67#if defined(FFI_DEBUG)
68#include <stdio.h>
69#endif
70#endif
71
72/* ---- Generic type definitions ----------------------------------------- */
73
74#define FLOAT32 float
75#define FLOAT64 double
76#define FLOAT80 long double
77
78#define UINT8 unsigned char
79#define SINT8 signed char
80
81#if SIZEOF_INT == 2
82
83#define UINT16 unsigned int
84#define SINT16 int
85#define ffi_type_uint ffi_type_uint16
86#define ffi_type_sint ffi_type_sint16
87
88#else
89#if SIZEOF_SHORT == 2
90
91#define UINT16 unsigned short
92#define SINT16 short
93#define ffi_type_ushort ffi_type_uint16
94#define ffi_type_sshort ffi_type_sint16
95
96#endif
97#endif
98
99#if SIZEOF_INT == 4
100
101#define UINT32 unsigned int
102#define SINT32 int
103#define ffi_type_uint ffi_type_uint32
104#define ffi_type_sint ffi_type_sint32
105
106#else
107#if SIZEOF_SHORT == 4
108
109#define UINT32 unsigned short
110#define SINT32 short
111#define ffi_type_ushort ffi_type_uint32
112#define ffi_type_sshort ffi_type_sint32
113
114#else
115#if SIZEOF_LONG == 4
116
117#define UINT32 unsigned long
118#define SINT32 long
119#define ffi_type_ulong ffi_type_uint32
120#define ffi_type_slong ffi_type_sint32
121
122#endif
123#endif
124#endif
125
126#if SIZEOF_INT == 8
127
128#define UINT64 unsigned int
129#define SINT64 int
130#define ffi_type_uint ffi_type_uint64
131#define ffi_type_sint ffi_type_sint64
132
133#else
134#if SIZEOF_LONG == 8
135
136#define UINT64 unsigned long
137#define SINT64 long
138#define ffi_type_ulong ffi_type_uint64
139#define ffi_type_slong ffi_type_sint64
140
141#else
142#if SIZEOF_LONG_LONG == 8
143
144#define UINT64 unsigned long long
145#define SINT64 long long
146#define ffi_type_ulong ffi_type_uint64
147#define ffi_type_slong ffi_type_sint64
148
149#endif
150#endif
151#endif
152
153/* ---- System specific configurations ----------------------------------- */
154
155#ifdef MIPS
156#include <ffi_mips.h>
157#else
158#define SIZEOF_ARG SIZEOF_VOID_P
159#endif
160
161#ifdef SPARC
162#if defined(__arch64__) || defined(__sparcv9)
163#define SPARC64
164#endif
165#endif
166
167#ifndef LIBFFI_ASM
168
169/* ---- Generic type definitions ----------------------------------------- */
170
171#define ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
172/* The closure code assumes that this works on pointers, i.e. a size_t */
173/* can hold a pointer. */
174
175typedef enum ffi_abi {
176
177 /* Leave this for debugging purposes */
178 FFI_FIRST_ABI = 0,
179
180 /* ---- Sparc -------------------- */
181#ifdef SPARC
182 FFI_V8,
183 FFI_V8PLUS,
184 FFI_V9,
185#ifdef SPARC64
186 FFI_DEFAULT_ABI = FFI_V9,
187#else
188 FFI_DEFAULT_ABI = FFI_V8,
189#endif
190#endif
191
192 /* ---- Intel x86 ---------------- */
193#ifdef X86
194 FFI_SYSV,
195 FFI_DEFAULT_ABI = FFI_SYSV,
196#endif
197
198 /* ---- Intel x86 Win32 ---------- */
199#ifdef X86_WIN32
200 FFI_SYSV,
201 FFI_DEFAULT_ABI = FFI_SYSV,
202#endif
203
204 /* ---- Intel ia64 ---------------- */
205#ifdef IA64
206 FFI_UNIX, /* Linux and all Unix variants use the same conventions */
207 FFI_DEFAULT_ABI = FFI_UNIX,
208#endif
209
210 /* ---- Mips --------------------- */
211#ifdef MIPS
212 FFI_O32,
213 FFI_N32,
214 FFI_N64,
215#endif
216
217 /* ---- Alpha -------------------- */
218#ifdef ALPHA
219 FFI_OSF,
220 FFI_DEFAULT_ABI = FFI_OSF,
221#endif
222
223 /* ---- Motorola m68k ------------ */
224#ifdef M68K
225 FFI_SYSV,
226 FFI_DEFAULT_ABI = FFI_SYSV,
227#endif
228
229 /* ---- PowerPC ------------------ */
230#ifdef POWERPC
231 FFI_SYSV,
232 FFI_GCC_SYSV,
233 FFI_DEFAULT_ABI = FFI_GCC_SYSV,
234#endif
235
236#ifdef POWERPC_AIX
237 FFI_AIX,
238 FFI_DARWIN,
239 FFI_DEFAULT_ABI = FFI_AIX,
240#endif
241
242#ifdef POWERPC_DARWIN
243 FFI_AIX,
244 FFI_DARWIN,
245 FFI_DEFAULT_ABI = FFI_DARWIN,
246#endif
247
248 /* ---- ARM --------------------- */
249#ifdef ARM
250 FFI_SYSV,
251 FFI_DEFAULT_ABI = FFI_SYSV,
252#endif
253
254 /* Leave this for debugging purposes */
255 FFI_LAST_ABI
256
257} ffi_abi;
258
259typedef struct _ffi_type
260{
261 size_t size;
262 unsigned short alignment;
263 unsigned short type;
264 /*@null@*/ struct _ffi_type **elements;
265} ffi_type;
266
267/* These are defined in ffi.c */
268extern ffi_type ffi_type_void;
269extern ffi_type ffi_type_uint8;
270extern ffi_type ffi_type_sint8;
271extern ffi_type ffi_type_uint16;
272extern ffi_type ffi_type_sint16;
273extern ffi_type ffi_type_uint32;
274extern ffi_type ffi_type_sint32;
275extern ffi_type ffi_type_uint64;
276extern ffi_type ffi_type_sint64;
277extern ffi_type ffi_type_float;
278extern ffi_type ffi_type_double;
279extern ffi_type ffi_type_longdouble;
280extern ffi_type ffi_type_pointer;
281
282/* Characters are 8 bit integral types */
283#define ffi_type_schar ffi_type_sint8
284#define ffi_type_uchar ffi_type_uint8
285
286typedef enum {
287 FFI_OK = 0,
288 FFI_BAD_TYPEDEF,
289 FFI_BAD_ABI
290} ffi_status;
291
292typedef unsigned FFI_TYPE;
293
294typedef struct {
295 ffi_abi abi;
296 unsigned nargs;
297 /*@dependent@*/ ffi_type **arg_types;
298 /*@dependent@*/ ffi_type *rtype;
299 unsigned bytes;
300 unsigned flags;
301
302#ifdef MIPS
303#if _MIPS_SIM == _ABIN32
304 unsigned rstruct_flag;
305#endif
306#endif
307
308} ffi_cif;
309
310#if SIZEOF_ARG == 4
311typedef UINT32 ffi_arg;
312#else
313#if SIZEOF_ARG == 8
314typedef UINT64 ffi_arg;
315#else
316-- unsupported configuration
317#endif
318#endif
319
320/* ---- Definitions for the raw API -------------------------------------- */
321
322#if !FFI_NO_RAW_API
323
324#if SIZEOF_ARG == 4
325
326#define UINT_ARG UINT32
327#define SINT_ARG SINT32
328
329#endif
330
331#if SIZEOF_ARG == 8
332
333#define UINT_ARG UINT64
334#define SINT_ARG SINT64
335
336#endif
337
338typedef union {
339 SINT_ARG sint;
340 UINT_ARG uint;
341 float flt;
342 char data[SIZEOF_ARG];
343 void* ptr;
344} ffi_raw;
345
346void ffi_raw_call (/*@dependent@*/ ffi_cif *cif,
347 void (*fn)(),
348 /*@out@*/ void *rvalue,
349 /*@dependent@*/ ffi_raw *avalue);
350
351void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
352void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
353size_t ffi_raw_size (ffi_cif *cif);
354
355#if !NO_JAVA_RAW_API
356
357/* This is analogous to the raw API, except it uses Java parameter */
358/* packing, even on 64-bit machines. I.e. on 64-bit machines */
359/* longs and doubles are followed by an empty 64-bit word. */
360
361void ffi_java_raw_call (/*@dependent@*/ ffi_cif *cif,
362 void (*fn)(),
363 /*@out@*/ void *rvalue,
364 /*@dependent@*/ ffi_raw *avalue);
365
366void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
367void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
368size_t ffi_java_raw_size (ffi_cif *cif);
369
370#endif /* !NO_JAVA_RAW_API */
371
372#endif /* !FFI_NO_RAW_API */
373
374/* ---- Definitions for closures ----------------------------------------- */
375
376#ifdef X86
377
378#define FFI_CLOSURES 1 /* x86 supports closures */
379#define FFI_TRAMPOLINE_SIZE 10
380#define FFI_NATIVE_RAW_API 1 /* and has native raw api support */
381
382#elif defined(X86_WIN32)
383
384#define FFI_CLOSURES 1 /* x86 supports closures */
385#define FFI_TRAMPOLINE_SIZE 10
386#define FFI_NATIVE_RAW_API 1 /* and has native raw api support */
387
388#elif defined(IA64)
389
390#define FFI_CLOSURES 1
391#define FFI_TRAMPOLINE_SIZE 24 /* Really the following struct, which */
392 /* can be interpreted as a C function */
393 /* decriptor: */