File indexing completed on 2024-05-18 08:29:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 #ifndef LIBFFI_H
0046 #define LIBFFI_H
0047
0048 #ifdef __cplusplus
0049 extern "C" {
0050 #endif
0051
0052
0053 #ifndef X86_64
0054 #define X86_64
0055 #endif
0056
0057
0058
0059
0060 #define FFI_TYPE_VOID 0
0061 #define FFI_TYPE_INT 1
0062 #define FFI_TYPE_FLOAT 2
0063 #define FFI_TYPE_DOUBLE 3
0064 #if 1
0065 #define FFI_TYPE_LONGDOUBLE 4
0066 #else
0067 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
0068 #endif
0069 #define FFI_TYPE_UINT8 5
0070 #define FFI_TYPE_SINT8 6
0071 #define FFI_TYPE_UINT16 7
0072 #define FFI_TYPE_SINT16 8
0073 #define FFI_TYPE_UINT32 9
0074 #define FFI_TYPE_SINT32 10
0075 #define FFI_TYPE_UINT64 11
0076 #define FFI_TYPE_SINT64 12
0077 #define FFI_TYPE_STRUCT 13
0078 #define FFI_TYPE_POINTER 14
0079 #define FFI_TYPE_COMPLEX 15
0080
0081
0082 #define FFI_TYPE_LAST FFI_TYPE_COMPLEX
0083
0084 #include <ffitarget.h>
0085
0086 #ifndef LIBFFI_ASM
0087
0088 #if defined(_MSC_VER) && !defined(__clang__)
0089 #define __attribute__(X)
0090 #endif
0091
0092 #include <stddef.h>
0093 #include <limits.h>
0094
0095
0096
0097
0098
0099 #define FFI_64_BIT_MAX 9223372036854775807
0100
0101 #ifdef LONG_LONG_MAX
0102 # define FFI_LONG_LONG_MAX LONG_LONG_MAX
0103 #else
0104 # ifdef LLONG_MAX
0105 # define FFI_LONG_LONG_MAX LLONG_MAX
0106 # ifdef _AIX52
0107 # undef FFI_64_BIT_MAX
0108 # define FFI_64_BIT_MAX 9223372036854775807LL
0109 # endif
0110 # else
0111 # ifdef __GNUC__
0112 # define FFI_LONG_LONG_MAX __LONG_LONG_MAX__
0113 # endif
0114 # ifdef _AIX
0115 # ifndef __PPC64__
0116 # if defined (__IBMC__) || defined (__IBMCPP__)
0117 # define FFI_LONG_LONG_MAX LONGLONG_MAX
0118 # endif
0119 # endif
0120 # undef FFI_64_BIT_MAX
0121 # define FFI_64_BIT_MAX 9223372036854775807LL
0122 # endif
0123 # endif
0124 #endif
0125
0126
0127
0128
0129 typedef struct _ffi_type
0130 {
0131 size_t size;
0132 unsigned short alignment;
0133 unsigned short type;
0134 struct _ffi_type **elements;
0135 } ffi_type;
0136
0137
0138
0139
0140
0141
0142
0143 #if defined _MSC_VER
0144 # if defined FFI_BUILDING_DLL
0145 # define FFI_API __declspec(dllexport)
0146 # elif !defined FFI_BUILDING
0147 # define FFI_API __declspec(dllimport)
0148 # else
0149 # define FFI_API
0150 # endif
0151 #else
0152 # define FFI_API
0153 #endif
0154
0155
0156
0157 #if defined LIBFFI_HIDE_BASIC_TYPES
0158 # define FFI_EXTERN FFI_API
0159 #else
0160 # define FFI_EXTERN extern FFI_API
0161 #endif
0162
0163 #ifndef LIBFFI_HIDE_BASIC_TYPES
0164 #if SCHAR_MAX == 127
0165 # define ffi_type_uchar ffi_type_uint8
0166 # define ffi_type_schar ffi_type_sint8
0167 #else
0168 #error "char size not supported"
0169 #endif
0170
0171 #if SHRT_MAX == 32767
0172 # define ffi_type_ushort ffi_type_uint16
0173 # define ffi_type_sshort ffi_type_sint16
0174 #elif SHRT_MAX == 2147483647
0175 # define ffi_type_ushort ffi_type_uint32
0176 # define ffi_type_sshort ffi_type_sint32
0177 #else
0178 #error "short size not supported"
0179 #endif
0180
0181 #if INT_MAX == 32767
0182 # define ffi_type_uint ffi_type_uint16
0183 # define ffi_type_sint ffi_type_sint16
0184 #elif INT_MAX == 2147483647
0185 # define ffi_type_uint ffi_type_uint32
0186 # define ffi_type_sint ffi_type_sint32
0187 #elif INT_MAX == 9223372036854775807
0188 # define ffi_type_uint ffi_type_uint64
0189 # define ffi_type_sint ffi_type_sint64
0190 #else
0191 #error "int size not supported"
0192 #endif
0193
0194 #if LONG_MAX == 2147483647
0195 # if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX
0196 #error "no 64-bit data type supported"
0197 # endif
0198 #elif LONG_MAX != FFI_64_BIT_MAX
0199 #error "long size not supported"
0200 #endif
0201
0202 #if LONG_MAX == 2147483647
0203 # define ffi_type_ulong ffi_type_uint32
0204 # define ffi_type_slong ffi_type_sint32
0205 #elif LONG_MAX == FFI_64_BIT_MAX
0206 # define ffi_type_ulong ffi_type_uint64
0207 # define ffi_type_slong ffi_type_sint64
0208 #else
0209 #error "long size not supported"
0210 #endif
0211
0212
0213 FFI_EXTERN ffi_type ffi_type_void;
0214 FFI_EXTERN ffi_type ffi_type_uint8;
0215 FFI_EXTERN ffi_type ffi_type_sint8;
0216 FFI_EXTERN ffi_type ffi_type_uint16;
0217 FFI_EXTERN ffi_type ffi_type_sint16;
0218 FFI_EXTERN ffi_type ffi_type_uint32;
0219 FFI_EXTERN ffi_type ffi_type_sint32;
0220 FFI_EXTERN ffi_type ffi_type_uint64;
0221 FFI_EXTERN ffi_type ffi_type_sint64;
0222 FFI_EXTERN ffi_type ffi_type_float;
0223 FFI_EXTERN ffi_type ffi_type_double;
0224 FFI_EXTERN ffi_type ffi_type_pointer;
0225
0226 #if 1
0227 FFI_EXTERN ffi_type ffi_type_longdouble;
0228 #else
0229 #define ffi_type_longdouble ffi_type_double
0230 #endif
0231
0232 #ifdef FFI_TARGET_HAS_COMPLEX_TYPE
0233 FFI_EXTERN ffi_type ffi_type_complex_float;
0234 FFI_EXTERN ffi_type ffi_type_complex_double;
0235 #if 1
0236 FFI_EXTERN ffi_type ffi_type_complex_longdouble;
0237 #else
0238 #define ffi_type_complex_longdouble ffi_type_complex_double
0239 #endif
0240 #endif
0241 #endif
0242
0243 typedef enum {
0244 FFI_OK = 0,
0245 FFI_BAD_TYPEDEF,
0246 FFI_BAD_ABI,
0247 FFI_BAD_ARGTYPE
0248 } ffi_status;
0249
0250 typedef struct {
0251 ffi_abi abi;
0252 unsigned nargs;
0253 ffi_type **arg_types;
0254 ffi_type *rtype;
0255 unsigned bytes;
0256 unsigned flags;
0257 #ifdef FFI_EXTRA_CIF_FIELDS
0258 FFI_EXTRA_CIF_FIELDS;
0259 #endif
0260 } ffi_cif;
0261
0262
0263
0264 #ifndef FFI_SIZEOF_ARG
0265 # if LONG_MAX == 2147483647
0266 # define FFI_SIZEOF_ARG 4
0267 # elif LONG_MAX == FFI_64_BIT_MAX
0268 # define FFI_SIZEOF_ARG 8
0269 # endif
0270 #endif
0271
0272 #ifndef FFI_SIZEOF_JAVA_RAW
0273 # define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG
0274 #endif
0275
0276 typedef union {
0277 ffi_sarg sint;
0278 ffi_arg uint;
0279 float flt;
0280 char data[FFI_SIZEOF_ARG];
0281 void* ptr;
0282 } ffi_raw;
0283
0284 #if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8
0285
0286
0287 typedef union {
0288 signed int sint;
0289 unsigned int uint;
0290 float flt;
0291 char data[FFI_SIZEOF_JAVA_RAW];
0292 void* ptr;
0293 } ffi_java_raw;
0294 #else
0295 typedef ffi_raw ffi_java_raw;
0296 #endif
0297
0298
0299 FFI_API
0300 void ffi_raw_call (ffi_cif *cif,
0301 void (*fn)(void),
0302 void *rvalue,
0303 ffi_raw *avalue);
0304
0305 FFI_API void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
0306 FFI_API void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
0307 FFI_API size_t ffi_raw_size (ffi_cif *cif);
0308
0309
0310
0311
0312
0313 #if !FFI_NATIVE_RAW_API
0314 FFI_API
0315 void ffi_java_raw_call (ffi_cif *cif,
0316 void (*fn)(void),
0317 void *rvalue,
0318 ffi_java_raw *avalue) __attribute__((deprecated));
0319 #endif
0320
0321 FFI_API
0322 void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw) __attribute__((deprecated));
0323 FFI_API
0324 void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args) __attribute__((deprecated));
0325 FFI_API
0326 size_t ffi_java_raw_size (ffi_cif *cif) __attribute__((deprecated));
0327
0328
0329
0330 #if FFI_CLOSURES
0331
0332 #ifdef _MSC_VER
0333 __declspec(align(8))
0334 #endif
0335 typedef struct {
0336 #if 0
0337 void *trampoline_table;
0338 void *trampoline_table_entry;
0339 #else
0340 union {
0341 char tramp[FFI_TRAMPOLINE_SIZE];
0342 void *ftramp;
0343 };
0344 #endif
0345 ffi_cif *cif;
0346 void (*fun)(ffi_cif*,void*,void**,void*);
0347 void *user_data;
0348 #if defined(_MSC_VER) && defined(_M_IX86)
0349 void *padding;
0350 #endif
0351 } ffi_closure
0352 #ifdef __GNUC__
0353 __attribute__((aligned (8)))
0354 #endif
0355 ;
0356
0357 #ifndef __GNUC__
0358 # ifdef __sgi
0359 # pragma pack 0
0360 # endif
0361 #endif
0362
0363 FFI_API void *ffi_closure_alloc (size_t size, void **code);
0364 FFI_API void ffi_closure_free (void *);
0365
0366 #if defined(PA_LINUX) || defined(PA_HPUX)
0367 #define FFI_CLOSURE_PTR(X) ((void *)((unsigned int)(X) | 2))
0368 #define FFI_RESTORE_PTR(X) ((void *)((unsigned int)(X) & ~3))
0369 #else
0370 #define FFI_CLOSURE_PTR(X) (X)
0371 #define FFI_RESTORE_PTR(X) (X)
0372 #endif
0373
0374 FFI_API ffi_status
0375 ffi_prep_closure (ffi_closure*,
0376 ffi_cif *,
0377 void (*fun)(ffi_cif*,void*,void**,void*),
0378 void *user_data)
0379 #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 405)
0380 __attribute__((deprecated ("use ffi_prep_closure_loc instead")))
0381 #elif defined(__GNUC__) && __GNUC__ >= 3
0382 __attribute__((deprecated))
0383 #endif
0384 ;
0385
0386 FFI_API ffi_status
0387 ffi_prep_closure_loc (ffi_closure*,
0388 ffi_cif *,
0389 void (*fun)(ffi_cif*,void*,void**,void*),
0390 void *user_data,
0391 void *codeloc);
0392
0393 #ifdef __sgi
0394 # pragma pack 8
0395 #endif
0396 typedef struct {
0397 #if 0
0398 void *trampoline_table;
0399 void *trampoline_table_entry;
0400 #else
0401 char tramp[FFI_TRAMPOLINE_SIZE];
0402 #endif
0403 ffi_cif *cif;
0404
0405 #if !FFI_NATIVE_RAW_API
0406
0407
0408
0409
0410
0411 void (*translate_args)(ffi_cif*,void*,void**,void*);
0412 void *this_closure;
0413
0414 #endif
0415
0416 void (*fun)(ffi_cif*,void*,ffi_raw*,void*);
0417 void *user_data;
0418
0419 } ffi_raw_closure;
0420
0421 typedef struct {
0422 #if 0
0423 void *trampoline_table;
0424 void *trampoline_table_entry;
0425 #else
0426 char tramp[FFI_TRAMPOLINE_SIZE];
0427 #endif
0428
0429 ffi_cif *cif;
0430
0431 #if !FFI_NATIVE_RAW_API
0432
0433
0434
0435
0436
0437 void (*translate_args)(ffi_cif*,void*,void**,void*);
0438 void *this_closure;
0439
0440 #endif
0441
0442 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*);
0443 void *user_data;
0444
0445 } ffi_java_raw_closure;
0446
0447 FFI_API ffi_status
0448 ffi_prep_raw_closure (ffi_raw_closure*,
0449 ffi_cif *cif,
0450 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
0451 void *user_data);
0452
0453 FFI_API ffi_status
0454 ffi_prep_raw_closure_loc (ffi_raw_closure*,
0455 ffi_cif *cif,
0456 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
0457 void *user_data,
0458 void *codeloc);
0459
0460 #if !FFI_NATIVE_RAW_API
0461 FFI_API ffi_status
0462 ffi_prep_java_raw_closure (ffi_java_raw_closure*,
0463 ffi_cif *cif,
0464 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
0465 void *user_data) __attribute__((deprecated));
0466
0467 FFI_API ffi_status
0468 ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
0469 ffi_cif *cif,
0470 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
0471 void *user_data,
0472 void *codeloc) __attribute__((deprecated));
0473 #endif
0474
0475 #endif
0476
0477 #if FFI_GO_CLOSURES
0478
0479 typedef struct {
0480 void *tramp;
0481 ffi_cif *cif;
0482 void (*fun)(ffi_cif*,void*,void**,void*);
0483 } ffi_go_closure;
0484
0485 FFI_API ffi_status ffi_prep_go_closure (ffi_go_closure*, ffi_cif *,
0486 void (*fun)(ffi_cif*,void*,void**,void*));
0487
0488 FFI_API void ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,
0489 void **avalue, void *closure);
0490
0491 #endif
0492
0493
0494
0495 FFI_API
0496 ffi_status ffi_prep_cif(ffi_cif *cif,
0497 ffi_abi abi,
0498 unsigned int nargs,
0499 ffi_type *rtype,
0500 ffi_type **atypes);
0501
0502 FFI_API
0503 ffi_status ffi_prep_cif_var(ffi_cif *cif,
0504 ffi_abi abi,
0505 unsigned int nfixedargs,
0506 unsigned int ntotalargs,
0507 ffi_type *rtype,
0508 ffi_type **atypes);
0509
0510 FFI_API
0511 void ffi_call(ffi_cif *cif,
0512 void (*fn)(void),
0513 void *rvalue,
0514 void **avalue);
0515
0516 FFI_API
0517 ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type,
0518 size_t *offsets);
0519
0520
0521 #define FFI_FN(f) ((void (*)(void))f)
0522
0523
0524
0525 #endif
0526
0527 #ifdef __cplusplus
0528 }
0529 #endif
0530
0531 #endif