codekingpro/portable-devtools
114k
1/* -----------------------------------------------------------------*-C-*-2 libffi 3.5.23 - Copyright (c) 2011, 2014, 2019, 2021, 2022, 2024, 2025 Anthony Green4 - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc.5 6 Permission is hereby granted, free of charge, to any person7 obtaining a copy of this software and associated documentation8 files (the ``Software''), to deal in the Software without9 restriction, including without limitation the rights to use, copy,10 modify, merge, publish, distribute, sublicense, and/or sell copies11 of the Software, and to permit persons to whom the Software is12 furnished to do so, subject to the following conditions:13 14 The above copyright notice and this permission notice shall be15 included in all copies or substantial portions of the Software.16 17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT21 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,22 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER24 DEALINGS IN THE SOFTWARE.25 26 ----------------------------------------------------------------------- */27 28/* -------------------------------------------------------------------29 Most of the API is documented in doc/libffi.texi.30 31 The raw API is designed to bypass some of the argument packing and32 unpacking on architectures for which it can be avoided. Routines33 are provided to emulate the raw API if the underlying platform34 doesn't allow faster implementation.35 36 More details on the raw API can be found in:37 38 http://gcc.gnu.org/ml/java/1999-q3/msg00138.html39 40 and41 42 http://gcc.gnu.org/ml/java/1999-q3/msg00174.html43 -------------------------------------------------------------------- */44 45#ifndef LIBFFI_H46#define LIBFFI_H47 48#ifdef __cplusplus49extern "C" {50#endif51 52/* Specify which architecture libffi is configured for. */53#ifndef X86_WIN6454#define X86_WIN6455#endif56 57/* ---- System configuration information --------------------------------- */58 59/* If these change, update src/mips/ffitarget.h. */60#define FFI_TYPE_VOID 061#define FFI_TYPE_INT 162#define FFI_TYPE_FLOAT 263#define FFI_TYPE_DOUBLE 364#if 065#define FFI_TYPE_LONGDOUBLE 466#else67#define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE68#endif69#define FFI_TYPE_UINT8 570#define FFI_TYPE_SINT8 671#define FFI_TYPE_UINT16 772#define FFI_TYPE_SINT16 873#define FFI_TYPE_UINT32 974#define FFI_TYPE_SINT32 1075#define FFI_TYPE_UINT64 1176#define FFI_TYPE_SINT64 1277#define FFI_TYPE_STRUCT 1378#define FFI_TYPE_POINTER 1479#define FFI_TYPE_COMPLEX 1580 81/* This should always refer to the last type code (for sanity checks). */82#define FFI_TYPE_LAST FFI_TYPE_COMPLEX83 84#include <ffitarget.h>85 86#ifndef LIBFFI_ASM87 88#if defined(_MSC_VER) && !defined(__clang__)89#define __attribute__(X)90#endif91 92#include <stddef.h>93#include <limits.h>94 95/* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example).96 But we can find it either under the correct ANSI name, or under GNU97 C's internal name. */98 99#define FFI_64_BIT_MAX 9223372036854775807100 101#ifdef LONG_LONG_MAX102# define FFI_LONG_LONG_MAX LONG_LONG_MAX103#else104# ifdef LLONG_MAX105# define FFI_LONG_LONG_MAX LLONG_MAX106# ifdef _AIX52 /* or newer has C99 LLONG_MAX */107# undef FFI_64_BIT_MAX108# define FFI_64_BIT_MAX 9223372036854775807LL109# endif /* _AIX52 or newer */110# else111# ifdef __GNUC__112# define FFI_LONG_LONG_MAX __LONG_LONG_MAX__113# endif114# ifdef _AIX /* AIX 5.1 and earlier have LONGLONG_MAX */115# ifndef __PPC64__116# if defined (__IBMC__) || defined (__IBMCPP__)117# define FFI_LONG_LONG_MAX LONGLONG_MAX118# endif119# endif /* __PPC64__ */120# undef FFI_64_BIT_MAX121# define FFI_64_BIT_MAX 9223372036854775807LL122# endif123# endif124#endif125 126/* The closure code assumes that this works on pointers, i.e. a size_t127 can hold a pointer. */128 129typedef struct _ffi_type130{131 size_t size;132 unsigned short alignment;133 unsigned short type;134 struct _ffi_type **elements;135} ffi_type;136 137/* Need minimal decorations for DLLs to work on Windows. GCC has138 autoimport and autoexport. Always mark externally visible symbols139 as dllimport for MSVC clients, even if it means an extra indirection140 when using the static version of the library.141 Besides, as a workaround, they can define FFI_BUILDING if they142 *know* they are going to link with the static library. */143#if defined _MSC_VER && !defined(FFI_STATIC_BUILD)144# if defined FFI_BUILDING_DLL /* Building libffi.DLL with msvcc.sh */145# define FFI_API __declspec(dllexport)146# else /* Importing libffi.DLL */147# define FFI_API __declspec(dllimport)148# endif149#else150# define FFI_API151#endif152 153/* The externally visible type declarations also need the MSVC DLL154 decorations, or they will not be exported from the object file. */155#if defined LIBFFI_HIDE_BASIC_TYPES156# define FFI_EXTERN FFI_API157#else158# define FFI_EXTERN extern FFI_API159#endif160 161#ifndef LIBFFI_HIDE_BASIC_TYPES162#if SCHAR_MAX == 127163# define ffi_type_uchar ffi_type_uint8164# define ffi_type_schar ffi_type_sint8165#else166 #error "char size not supported"167#endif168 169#if SHRT_MAX == 32767170# define ffi_type_ushort ffi_type_uint16171# define ffi_type_sshort ffi_type_sint16172#elif SHRT_MAX == 2147483647173# define ffi_type_ushort ffi_type_uint32174# define ffi_type_sshort ffi_type_sint32175#else176 #error "short size not supported"177#endif178 179#if INT_MAX == 32767180# define ffi_type_uint ffi_type_uint16181# define ffi_type_sint ffi_type_sint16182#elif INT_MAX == 2147483647183# define ffi_type_uint ffi_type_uint32184# define ffi_type_sint ffi_type_sint32185#elif INT_MAX == 9223372036854775807186# define ffi_type_uint ffi_type_uint64187# define ffi_type_sint ffi_type_sint64188#else189 #error "int size not supported"190#endif191 192#if LONG_MAX == 2147483647193# if FFI_LONG_LONG_MAX != FFI_64_BIT_MAX194 #error "no 64-bit data type supported"195# endif196#elif LONG_MAX != FFI_64_BIT_MAX197 #error "long size not supported"198#endif199 200#if LONG_MAX == 2147483647201# define ffi_type_ulong ffi_type_uint32202# define ffi_type_slong ffi_type_sint32203#elif LONG_MAX == FFI_64_BIT_MAX204# define ffi_type_ulong ffi_type_uint64205# define ffi_type_slong ffi_type_sint64206#else207 #error "long size not supported"208#endif209 210/* These are defined in types.c. */211FFI_EXTERN ffi_type ffi_type_void;212FFI_EXTERN ffi_type ffi_type_uint8;213FFI_EXTERN ffi_type ffi_type_sint8;214FFI_EXTERN ffi_type ffi_type_uint16;215FFI_EXTERN ffi_type ffi_type_sint16;216FFI_EXTERN ffi_type ffi_type_uint32;217FFI_EXTERN ffi_type ffi_type_sint32;218FFI_EXTERN ffi_type ffi_type_uint64;219FFI_EXTERN ffi_type ffi_type_sint64;220FFI_EXTERN ffi_type ffi_type_float;221FFI_EXTERN ffi_type ffi_type_double;222FFI_EXTERN ffi_type ffi_type_pointer;223FFI_EXTERN ffi_type ffi_type_longdouble;224 225#ifdef FFI_TARGET_HAS_COMPLEX_TYPE226FFI_EXTERN ffi_type ffi_type_complex_float;227FFI_EXTERN ffi_type ffi_type_complex_double;228FFI_EXTERN ffi_type ffi_type_complex_longdouble;229#endif230#endif /* LIBFFI_HIDE_BASIC_TYPES */231 232typedef enum {233 FFI_OK = 0,234 FFI_BAD_TYPEDEF,235 FFI_BAD_ABI,236 FFI_BAD_ARGTYPE237} ffi_status;238 239typedef struct {240 ffi_abi abi;241 unsigned nargs;242 ffi_type **arg_types;243 ffi_type *rtype;244 unsigned bytes;245 unsigned flags;246#ifdef FFI_EXTRA_CIF_FIELDS247 FFI_EXTRA_CIF_FIELDS;248#endif249} ffi_cif;250 251/* ---- Definitions for the raw API -------------------------------------- */252 253#ifndef FFI_SIZEOF_ARG254# if LONG_MAX == 2147483647255# define FFI_SIZEOF_ARG 4256# elif LONG_MAX == FFI_64_BIT_MAX257# define FFI_SIZEOF_ARG 8258# endif259#endif260 261#ifndef FFI_SIZEOF_JAVA_RAW262# define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG263#endif264 265typedef union {266 ffi_sarg sint;267 ffi_arg uint;268 float flt;269 char data[FFI_SIZEOF_ARG];270 void* ptr;271} ffi_raw;272 273#if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8274/* This is a special case for mips64/n32 ABI (and perhaps others) where275 sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */276typedef union {277 signed int sint;278 unsigned int uint;279 float flt;280 char data[FFI_SIZEOF_JAVA_RAW];281 void* ptr;282} ffi_java_raw;283#else284typedef ffi_raw ffi_java_raw;285#endif286 287 288FFI_API289void ffi_raw_call (ffi_cif *cif,290 void (*fn)(void),291 void *rvalue,292 ffi_raw *avalue);293 294FFI_API void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);295FFI_API void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);296FFI_API size_t ffi_raw_size (ffi_cif *cif);297 298/* This is analogous to the raw API, except it uses Java parameter299 packing, even on 64-bit machines. I.e. on 64-bit machines longs300 and doubles are followed by an empty 64-bit word. */301 302#if !FFI_NATIVE_RAW_API303FFI_API304void ffi_java_raw_call (ffi_cif *cif,305 void (*fn)(void),306 void *rvalue,307 ffi_java_raw *avalue) __attribute__((deprecated));308#endif309 310FFI_API311void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw) __attribute__((deprecated));312FFI_API313void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args) __attribute__((deprecated));314FFI_API315size_t ffi_java_raw_size (ffi_cif *cif) __attribute__((deprecated));316 317/* ---- Version API ------------------------------------------------------ */318 319#define FFI_VERSION_STRING "3.5.2"320#define FFI_VERSION_NUMBER 30502321 322#ifndef LIBFFI_ASM323/* Return a version string. */324FFI_API const char *ffi_get_version (void);325 326/* Return the version as an unsigned long value: (x * 10000 + y * 100 + z) */327FFI_API unsigned long ffi_get_version_number (void);328#endif329 330/* ---- Internals API ---------------------------------------------------- */331 332FFI_API unsigned int ffi_get_default_abi (void);333FFI_API size_t ffi_get_closure_size (void);334 335/* ---- Definitions for closures ----------------------------------------- */336 337#if FFI_CLOSURES338 339#ifdef _MSC_VER340__declspec(align(8))341#endif342typedef struct {343#if 0344 void *trampoline_table;345 void *trampoline_table_entry;346#else347 union {348 char tramp[FFI_TRAMPOLINE_SIZE];349 void *ftramp;350 };351#endif352 ffi_cif *cif;353 void (*fun)(ffi_cif*,void*,void**,void*);354 void *user_data;355#if defined(_MSC_VER) && defined(_M_IX86)356 void *padding;357#endif358} ffi_closure359#ifdef __GNUC__360 __attribute__((aligned (8)))361#endif362 ;363 364#ifndef __GNUC__365# ifdef __sgi366# pragma pack 0367# endif368#endif369 370FFI_API void *ffi_closure_alloc (size_t size, void **code);371FFI_API void ffi_closure_free (void *);372 373FFI_API ffi_status374ffi_prep_closure (ffi_closure*,375 ffi_cif *,376 void (*fun)(ffi_cif*,void*,void**,void*),377 void *user_data)378#if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 405)379 __attribute__((deprecated ("use ffi_prep_closure_loc instead")))380#elif defined(__GNUC__) && __GNUC__ >= 3381 __attribute__((deprecated))382#endif383 ;384 385FFI_API ffi_status386ffi_prep_closure_loc (ffi_closure*,387 ffi_cif *,388 void (*fun)(ffi_cif*,void*,void**,void*),389 void *user_data,390 void *codeloc);391 392#if defined(__x86_64__) || defined(__arm64__)393FFI_API ffi_closure *394ffi_find_closure_for_code(void *code);395#ifdef __APPLE__396FFI_API ffi_closure *ffi_find_closure_for_code_np(void *code);397#endif398#endif399 400#ifdef __sgi401# pragma pack 8402#endif403typedef struct {404#if 0405 void *trampoline_table;406 void *trampoline_table_entry;407#else408 char tramp[FFI_TRAMPOLINE_SIZE];409#endif410 ffi_cif *cif;411 412#if !FFI_NATIVE_RAW_API413 414 /* If this is enabled, then a raw closure has the same layout415 as a regular closure. We use this to install an intermediate416 handler to do the translation, void** -> ffi_raw*. */417 418 void (*translate_args)(ffi_cif*,void*,void**,void*);419 void *this_closure;420 421#endif422 423 void (*fun)(ffi_cif*,void*,ffi_raw*,void*);424 void *user_data;425 426} ffi_raw_closure;427 428typedef struct {429#if 0430 void *trampoline_table;431 void *trampoline_table_entry;432#else433 char tramp[FFI_TRAMPOLINE_SIZE];434#endif435 436 ffi_cif *cif;437 438#if !FFI_NATIVE_RAW_API439 440 /* If this is enabled, then a raw closure has the same layout441 as a regular closure. We use this to install an intermediate442 handler to do the translation, void** -> ffi_raw*. */443 444 void (*translate_args)(ffi_cif*,void*,void**,void*);445 void *this_closure;446 447#endif448 449 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*);450 void *user_data;451 452} ffi_java_raw_closure;453 454FFI_API ffi_status455ffi_prep_raw_closure (ffi_raw_closure*,456 ffi_cif *cif,457 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),458 void *user_data);459 460FFI_API ffi_status461ffi_prep_raw_closure_loc (ffi_raw_closure*,462 ffi_cif *cif,463 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),464 void *user_data,465 void *codeloc);466 467#if !FFI_NATIVE_RAW_API468FFI_API ffi_status469ffi_prep_java_raw_closure (ffi_java_raw_closure*,470 ffi_cif *cif,471 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),472 void *user_data) __attribute__((deprecated));473 474FFI_API ffi_status475ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,476 ffi_cif *cif,477 void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),478 void *user_data,479 void *codeloc) __attribute__((deprecated));480#endif481 482#endif /* FFI_CLOSURES */483 484#ifdef FFI_GO_CLOSURES485 486typedef struct {487 void *tramp;488 ffi_cif *cif;489 void (*fun)(ffi_cif*,void*,void**,void*);490} ffi_go_closure;491 492FFI_API ffi_status ffi_prep_go_closure (ffi_go_closure*, ffi_cif *,493 void (*fun)(ffi_cif*,void*,void**,void*));494 495FFI_API void ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue,496 void **avalue, void *closure);497 498#endif /* FFI_GO_CLOSURES */499 500/* ---- Public interface definition -------------------------------------- */501 502FFI_API503ffi_status ffi_prep_cif(ffi_cif *cif,504 ffi_abi abi,505 unsigned int nargs,506 ffi_type *rtype,507 ffi_type **atypes);508 509FFI_API510ffi_status ffi_prep_cif_var(ffi_cif *cif,511 ffi_abi abi,512 unsigned int nfixedargs,513 unsigned int ntotalargs,514 ffi_type *rtype,515 ffi_type **atypes);516 517FFI_API518void ffi_call(ffi_cif *cif,519 void (*fn)(void),520 void *rvalue,521 void **avalue);522 523FFI_API524ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type,525 size_t *offsets);526 527/* Convert between closure and function pointers. */528#if defined(PA_LINUX) || defined(PA_HPUX)529#define FFI_FN(f) ((void (*)(void))((unsigned int)(f) | 2))530#define FFI_CL(f) ((void *)((unsigned int)(f) & ~3))531#else532#define FFI_FN(f) ((void (*)(void))f)533#define FFI_CL(f) ((void *)(f))534#endif535 536/* ---- Definitions shared with assembly code ---------------------------- */537 538#endif539 540#ifdef __cplusplus541}542#endif543 544#endif545 