├── libs └── libffi │ ├── testsuite │ ├── config │ │ └── default.exp │ ├── libffi.call │ │ ├── err_bad_typedef.c │ │ ├── return_fl.c │ │ ├── return_sc.c │ │ ├── return_ldl.c │ │ ├── return_sl.c │ │ ├── return_dbl.c │ │ ├── return_fl1.c │ │ ├── return_uc.c │ │ ├── err_bad_abi.c │ │ ├── call.exp │ │ ├── return_ul.c │ │ ├── return_ll.c │ │ ├── strlen.c │ │ ├── return_fl3.c │ │ ├── negint.c │ │ ├── return_dbl2.c │ │ ├── return_dbl1.c │ │ ├── strlen2.c │ │ ├── strlen3.c │ │ ├── cls_float.c │ │ ├── cls_sint.c │ │ ├── return_ll1.c │ │ ├── cls_schar.c │ │ ├── cls_uchar.c │ │ ├── cls_sshort.c │ │ ├── cls_double.c │ │ ├── cls_ulong_va.c │ │ ├── cls_uint_va.c │ │ ├── cls_uchar_va.c │ │ ├── cls_uint.c │ │ ├── cls_ushort.c │ │ ├── cls_ushort_va.c │ │ ├── unwindtest_ffi_call.cc │ │ ├── return_fl2.c │ │ ├── many2.c │ │ ├── strlen4.c │ │ ├── float.c │ │ ├── float1.c │ │ ├── struct3.c │ │ ├── uninitialized.c │ │ ├── float4.c │ │ ├── many.c │ │ ├── promotion.c │ │ ├── struct4.c │ │ ├── struct6.c │ │ ├── cls_dbls_struct.c │ │ ├── closure_simple.c │ │ ├── struct1.c │ │ ├── struct5.c │ │ ├── struct9.c │ │ ├── cls_ulonglong.c │ │ ├── struct2.c │ │ ├── float2.c │ │ ├── float3.c │ │ ├── cls_double_va.c │ │ ├── cls_longdouble_va.c │ │ ├── struct7.c │ │ ├── testclosure.c │ │ ├── cls_multi_schar.c │ │ ├── cls_multi_sshort.c │ │ ├── cls_multi_ushort.c │ │ ├── struct8.c │ │ ├── cls_pointer.c │ │ ├── cls_multi_sshortchar.c │ │ ├── cls_multi_ushortchar.c │ │ ├── cls_multi_uchar.c │ │ ├── cls_1_1byte.c │ │ ├── problem1.c │ │ ├── cls_8byte.c │ │ ├── cls_4byte.c │ │ ├── cls_2byte.c │ │ ├── cls_9byte1.c │ │ ├── cls_9byte2.c │ │ ├── cls_3byte1.c │ │ ├── cls_3byte2.c │ │ ├── va_struct1.c │ │ ├── cls_align_sint32.c │ │ ├── cls_align_uint32.c │ │ ├── cls_align_sint16.c │ │ ├── cls_align_uint16.c │ │ └── cls_align_double.c │ └── lib │ │ └── wrapper.exp │ ├── .gitignore │ ├── doc │ ├── stamp-vti │ └── version.texi │ ├── man │ ├── Makefile.am │ ├── ffi.3 │ ├── ffi_prep_cif.3 │ ├── ffi_prep_cif_var.3 │ └── ffi_call.3 │ ├── include │ └── Makefile.am │ ├── libffi.pc.in │ ├── m4 │ ├── asmcfi.m4 │ └── ltversion.m4 │ ├── LICENSE │ ├── libtool-version │ ├── ChangeLog.libgcj │ └── src │ ├── bfin │ └── ffitarget.h │ ├── m88k │ └── ffitarget.h │ ├── vax │ └── ffitarget.h │ ├── nios2 │ └── ffitarget.h │ ├── microblaze │ └── ffitarget.h │ ├── ia64 │ ├── ia64_flags.h │ └── ffitarget.h │ ├── xtensa │ └── ffitarget.h │ ├── metag │ └── ffitarget.h │ ├── arc │ └── ffitarget.h │ ├── alpha │ └── ffitarget.h │ ├── m32r │ └── ffitarget.h │ ├── moxie │ └── ffitarget.h │ ├── sh │ └── ffitarget.h │ ├── m68k │ └── ffitarget.h │ ├── avr32 │ └── ffitarget.h │ ├── aarch64 │ └── ffitarget.h │ ├── sh64 │ └── ffitarget.h │ ├── cris │ └── ffitarget.h │ ├── s390 │ └── ffitarget.h │ ├── frv │ └── ffitarget.h │ ├── tile │ └── ffitarget.h │ ├── debug.c │ ├── sparc │ └── ffitarget.h │ ├── arm │ └── ffitarget.h │ └── pa │ └── ffitarget.h ├── tests └── ulysses.txt ├── .gitignore ├── storage.h ├── storage.c ├── LICENSE └── Makefile /libs/libffi/testsuite/config/default.exp: -------------------------------------------------------------------------------- 1 | load_lib "standard.exp" 2 | -------------------------------------------------------------------------------- /tests/ulysses.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intersystems-community/cna/master/tests/ulysses.txt -------------------------------------------------------------------------------- /libs/libffi/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | config.log 3 | confdefs.h 4 | *~ 5 | x86_64-w64-mingw32 6 | i686-pc-mingw32 -------------------------------------------------------------------------------- /libs/libffi/doc/stamp-vti: -------------------------------------------------------------------------------- 1 | @set UPDATED 25 April 2014 2 | @set UPDATED-MONTH April 2014 3 | @set EDITION 3.1 4 | @set VERSION 3.1 5 | -------------------------------------------------------------------------------- /libs/libffi/doc/version.texi: -------------------------------------------------------------------------------- 1 | @set UPDATED 25 April 2014 2 | @set UPDATED-MONTH April 2014 3 | @set EDITION 3.1 4 | @set VERSION 3.1 5 | -------------------------------------------------------------------------------- /libs/libffi/man/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this with automake to create Makefile.in 2 | 3 | AUTOMAKE_OPTIONS=foreign 4 | 5 | EXTRA_DIST = ffi.3 ffi_call.3 ffi_prep_cif.3 ffi_prep_cif_var.3 6 | 7 | man_MANS = ffi.3 ffi_call.3 ffi_prep_cif.3 ffi_prep_cif_var.3 8 | 9 | -------------------------------------------------------------------------------- /libs/libffi/include/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this with automake to create Makefile.in 2 | 3 | AUTOMAKE_OPTIONS=foreign 4 | 5 | DISTCLEANFILES=ffitarget.h 6 | EXTRA_DIST=ffi.h.in ffi_common.h 7 | 8 | includesdir = $(libdir)/@PACKAGE_NAME@-@PACKAGE_VERSION@/include 9 | nodist_includes_HEADERS = ffi.h ffitarget.h 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Libraries 8 | *.lib 9 | *.la 10 | *.lo 11 | *.a 12 | 13 | # Shared objects (inc. Windows DLLs) 14 | *.dll 15 | *.so 16 | *.so.* 17 | *.dylib 18 | 19 | # Executables 20 | *.exe 21 | *.out 22 | *.app 23 | *.i*86 24 | *.x86_64 25 | *.hex 26 | test 27 | 28 | log.txt 29 | .DS_Store 30 | -------------------------------------------------------------------------------- /storage.h: -------------------------------------------------------------------------------- 1 | #ifndef STORAGE_H 2 | #define STORAGE_H 3 | 4 | #include 5 | 6 | typedef struct _storage { 7 | void **data; 8 | size_t n; 9 | size_t allocated; 10 | } storage; 11 | 12 | void 13 | init_storage(storage *x); 14 | 15 | void * 16 | alloc(storage *x, size_t size); 17 | 18 | void 19 | free_storage(storage *x); 20 | 21 | #endif -------------------------------------------------------------------------------- /libs/libffi/libffi.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | toolexeclibdir=@toolexeclibdir@ 5 | includedir=${libdir}/@PACKAGE_NAME@-@PACKAGE_VERSION@/include 6 | 7 | Name: @PACKAGE_NAME@ 8 | Description: Library supporting Foreign Function Interfaces 9 | Version: @PACKAGE_VERSION@ 10 | Libs: -L${toolexeclibdir} -lffi 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /libs/libffi/m4/asmcfi.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([GCC_AS_CFI_PSEUDO_OP], 2 | [AC_CACHE_CHECK([assembler .cfi pseudo-op support], 3 | gcc_cv_as_cfi_pseudo_op, [ 4 | gcc_cv_as_cfi_pseudo_op=unknown 5 | AC_TRY_COMPILE([asm (".cfi_startproc\n\t.cfi_endproc");],, 6 | [gcc_cv_as_cfi_pseudo_op=yes], 7 | [gcc_cv_as_cfi_pseudo_op=no]) 8 | ]) 9 | if test "x$gcc_cv_as_cfi_pseudo_op" = xyes; then 10 | AC_DEFINE(HAVE_AS_CFI_PSEUDO_OP, 1, 11 | [Define if your assembler supports .cfi_* directives.]) 12 | fi 13 | ]) 14 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/err_bad_typedef.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_prep_cif 2 | Purpose: Test error return for bad typedefs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Blake Chaffin 6/6/2007 */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | int main (void) 12 | { 13 | ffi_cif cif; 14 | ffi_type* arg_types[1]; 15 | 16 | ffi_type badType = ffi_type_void; 17 | 18 | arg_types[0] = NULL; 19 | 20 | badType.size = 0; 21 | 22 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &badType, 23 | arg_types) == FFI_BAD_TYPEDEF); 24 | 25 | exit(0); 26 | } 27 | -------------------------------------------------------------------------------- /storage.c: -------------------------------------------------------------------------------- 1 | #include "storage.h" 2 | 3 | #include 4 | #include 5 | 6 | void 7 | init_storage(storage *x) 8 | { 9 | x->n = 0; 10 | x->allocated = 10; 11 | x->data = malloc(sizeof(void *) * x->allocated); 12 | } 13 | 14 | void * 15 | alloc(storage *x, size_t size) 16 | { 17 | if (x->n == x->allocated) { 18 | x->allocated *= 2; 19 | x->data = realloc(x->data, sizeof(void *) * x->allocated); 20 | } 21 | 22 | return x->data[x->n++] = malloc(size); 23 | } 24 | 25 | void 26 | free_storage(storage *x) 27 | { 28 | size_t i; 29 | for (i = 0; i < x->n; ++i) { 30 | free(x->data[i]); 31 | } 32 | free(x->data); 33 | x->n = 0; 34 | x->allocated = 0; 35 | } -------------------------------------------------------------------------------- /libs/libffi/m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2013 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 4038 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2.418]) 16 | m4_define([LT_PACKAGE_REVISION], [2.4.2.418]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2.418' 20 | macro_revision='2.4.2.418' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_fl.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static float return_fl(float fl) 11 | { 12 | return 2 * fl; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | float fl, rfl; 20 | 21 | args[0] = &ffi_type_float; 22 | values[0] = &fl; 23 | 24 | /* Initialize the cif */ 25 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 26 | &ffi_type_float, args) == FFI_OK); 27 | 28 | for (fl = -127.0; fl < 127; fl++) 29 | { 30 | ffi_call(&cif, FFI_FN(return_fl), &rfl, values); 31 | printf ("%f vs %f\n", rfl, return_fl(fl)); 32 | CHECK(rfl == 2 * fl); 33 | } 34 | exit(0); 35 | } 36 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_sc.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value signed char. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static signed char return_sc(signed char sc) 11 | { 12 | return sc; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | ffi_arg rint; 20 | signed char sc; 21 | 22 | args[0] = &ffi_type_schar; 23 | values[0] = ≻ 24 | 25 | /* Initialize the cif */ 26 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 27 | &ffi_type_schar, args) == FFI_OK); 28 | 29 | for (sc = (signed char) -127; 30 | sc < (signed char) 127; sc++) 31 | { 32 | ffi_call(&cif, FFI_FN(return_sc), &rint, values); 33 | CHECK((signed char)rint == sc); 34 | } 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_ldl.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value long double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20071113 */ 6 | 7 | /* { dg-do run { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */ 8 | #include "ffitest.h" 9 | 10 | static long double return_ldl(long double ldl) 11 | { 12 | return 2*ldl; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | long double ldl, rldl; 20 | 21 | args[0] = &ffi_type_longdouble; 22 | values[0] = &ldl; 23 | 24 | /* Initialize the cif */ 25 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 26 | &ffi_type_longdouble, args) == FFI_OK); 27 | 28 | for (ldl = -127.0; ldl < 127.0; ldl++) 29 | { 30 | ffi_call(&cif, FFI_FN(return_ldl), &rldl, values); 31 | CHECK(rldl == 2 * ldl); 32 | } 33 | exit(0); 34 | } 35 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_sl.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check if long as return type is handled correctly. 3 | Limitations: none. 4 | PR: none. 5 | */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | static long return_sl(long l1, long l2) 10 | { 11 | return l1 - l2; 12 | } 13 | 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | ffi_arg res; 20 | unsigned long l1, l2; 21 | 22 | args[0] = &ffi_type_slong; 23 | args[1] = &ffi_type_slong; 24 | values[0] = &l1; 25 | values[1] = &l2; 26 | 27 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 28 | &ffi_type_slong, args) == FFI_OK); 29 | 30 | l1 = 1073741823L; 31 | l2 = 1073741824L; 32 | 33 | ffi_call(&cif, FFI_FN(return_sl), &res, values); 34 | printf("res: %ld, %ld\n", (long)res, l1 - l2); 35 | /* { dg-output "res: -1, -1" } */ 36 | 37 | exit(0); 38 | } 39 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_dbl.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static double return_dbl(double dbl) 11 | { 12 | printf ("%f\n", dbl); 13 | return 2 * dbl; 14 | } 15 | int main (void) 16 | { 17 | ffi_cif cif; 18 | ffi_type *args[MAX_ARGS]; 19 | void *values[MAX_ARGS]; 20 | double dbl, rdbl; 21 | 22 | args[0] = &ffi_type_double; 23 | values[0] = &dbl; 24 | 25 | /* Initialize the cif */ 26 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 27 | &ffi_type_double, args) == FFI_OK); 28 | 29 | for (dbl = -127.3; dbl < 127; dbl++) 30 | { 31 | ffi_call(&cif, FFI_FN(return_dbl), &rdbl, values); 32 | printf ("%f vs %f\n", rdbl, return_dbl(dbl)); 33 | CHECK(rdbl == 2 * dbl); 34 | } 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_fl1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static float return_fl(float fl1, float fl2) 11 | { 12 | return fl1 + fl2; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | float fl1, fl2, rfl; 20 | 21 | args[0] = &ffi_type_float; 22 | args[1] = &ffi_type_float; 23 | values[0] = &fl1; 24 | values[1] = &fl2; 25 | 26 | /* Initialize the cif */ 27 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 28 | &ffi_type_float, args) == FFI_OK); 29 | fl1 = 127.0; 30 | fl2 = 128.0; 31 | 32 | ffi_call(&cif, FFI_FN(return_fl), &rfl, values); 33 | printf ("%f vs %f\n", rfl, return_fl(fl1, fl2)); 34 | CHECK(rfl == fl1 + fl2); 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_uc.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value unsigned char. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static unsigned char return_uc(unsigned char uc) 11 | { 12 | return uc; 13 | } 14 | 15 | int main (void) 16 | { 17 | ffi_cif cif; 18 | ffi_type *args[MAX_ARGS]; 19 | void *values[MAX_ARGS]; 20 | ffi_arg rint; 21 | 22 | unsigned char uc; 23 | 24 | args[0] = &ffi_type_uchar; 25 | values[0] = &uc; 26 | 27 | /* Initialize the cif */ 28 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 29 | &ffi_type_uchar, args) == FFI_OK); 30 | 31 | for (uc = (unsigned char) '\x00'; 32 | uc < (unsigned char) '\xff'; uc++) 33 | { 34 | ffi_call(&cif, FFI_FN(return_uc), &rint, values); 35 | CHECK((unsigned char)rint == uc); 36 | } 37 | exit(0); 38 | } 39 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/err_bad_abi.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_prep_cif, ffi_prep_closure 2 | Purpose: Test error return for bad ABIs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Blake Chaffin 6/6/2007 */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static void 12 | dummy_fn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__, 13 | void** args __UNUSED__, void* userdata __UNUSED__) 14 | {} 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | void *code; 20 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 21 | ffi_type* arg_types[1]; 22 | 23 | arg_types[0] = NULL; 24 | 25 | CHECK(ffi_prep_cif(&cif, 255, 0, &ffi_type_void, 26 | arg_types) == FFI_BAD_ABI); 27 | 28 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &ffi_type_void, 29 | arg_types) == FFI_OK); 30 | 31 | cif.abi= 255; 32 | 33 | CHECK(ffi_prep_closure_loc(pcl, &cif, dummy_fn, NULL, code) == FFI_BAD_ABI); 34 | 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /libs/libffi/man/ffi.3: -------------------------------------------------------------------------------- 1 | .Dd February 15, 2008 2 | .Dt FFI 3 3 | .Sh NAME 4 | .Nm FFI 5 | .Nd Foreign Function Interface 6 | .Sh LIBRARY 7 | libffi, -lffi 8 | .Sh SYNOPSIS 9 | .In ffi.h 10 | .Ft ffi_status 11 | .Fo ffi_prep_cif 12 | .Fa "ffi_cif *cif" 13 | .Fa "ffi_abi abi" 14 | .Fa "unsigned int nargs" 15 | .Fa "ffi_type *rtype" 16 | .Fa "ffi_type **atypes" 17 | .Fc 18 | .Ft void 19 | .Fo ffi_prep_cif_var 20 | .Fa "ffi_cif *cif" 21 | .Fa "ffi_abi abi" 22 | .Fa "unsigned int nfixedargs" 23 | .Fa "unsigned int ntotalargs" 24 | .Fa "ffi_type *rtype" 25 | .Fa "ffi_type **atypes" 26 | .Fc 27 | .Ft void 28 | .Fo ffi_call 29 | .Fa "ffi_cif *cif" 30 | .Fa "void (*fn)(void)" 31 | .Fa "void *rvalue" 32 | .Fa "void **avalue" 33 | .Fc 34 | .Sh DESCRIPTION 35 | The foreign function interface provides a mechanism by which a function can 36 | generate a call to another function at runtime without requiring knowledge of 37 | the called function's interface at compile time. 38 | .Sh SEE ALSO 39 | .Xr ffi_prep_cif 3 , 40 | .Xr ffi_prep_cif_var 3 , 41 | .Xr ffi_call 3 42 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/call.exp: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2003, 2006, 2009, 2010 Free Software Foundation, Inc. 2 | 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; see the file COPYING3. If not see 15 | # . 16 | 17 | dg-init 18 | libffi-init 19 | 20 | global srcdir subdir 21 | 22 | run-many-tests [lsort [glob -nocomplain -- $srcdir/$subdir/*.{c,cc}]] "" 23 | 24 | dg-finish 25 | 26 | # Local Variables: 27 | # tcl-indent-level:4 28 | # End: 29 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_ul.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check if unsigned long as return type is handled correctly. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20060724 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | static unsigned long return_ul(unsigned long ul1, unsigned long ul2) 10 | { 11 | return ul1 + ul2; 12 | } 13 | 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | ffi_arg res; 20 | unsigned long ul1, ul2; 21 | 22 | args[0] = &ffi_type_ulong; 23 | args[1] = &ffi_type_ulong; 24 | values[0] = &ul1; 25 | values[1] = &ul2; 26 | 27 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 28 | &ffi_type_ulong, args) == FFI_OK); 29 | 30 | ul1 = 1073741823L; 31 | ul2 = 1073741824L; 32 | 33 | ffi_call(&cif, FFI_FN(return_ul), &res, values); 34 | printf("res: %lu, %lu\n", (unsigned long)res, ul1 + ul2); 35 | /* { dg-output "res: 2147483647, 2147483647" } */ 36 | 37 | exit(0); 38 | } 39 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_ll.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value long long. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | static long long return_ll(long long ll) 10 | { 11 | return ll; 12 | } 13 | 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | long long rlonglong; 20 | long long ll; 21 | 22 | args[0] = &ffi_type_sint64; 23 | values[0] = ≪ 24 | 25 | /* Initialize the cif */ 26 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 27 | &ffi_type_sint64, args) == FFI_OK); 28 | 29 | for (ll = 0LL; ll < 100LL; ll++) 30 | { 31 | ffi_call(&cif, FFI_FN(return_ll), &rlonglong, values); 32 | CHECK(rlonglong == ll); 33 | } 34 | 35 | for (ll = 55555555555000LL; ll < 55555555555100LL; ll++) 36 | { 37 | ffi_call(&cif, FFI_FN(return_ll), &rlonglong, values); 38 | CHECK(rlonglong == ll); 39 | } 40 | exit(0); 41 | } 42 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/strlen.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check strlen function call. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static size_t ABI_ATTR my_strlen(char *s) 11 | { 12 | return (strlen(s)); 13 | } 14 | 15 | int main (void) 16 | { 17 | ffi_cif cif; 18 | ffi_type *args[MAX_ARGS]; 19 | void *values[MAX_ARGS]; 20 | ffi_arg rint; 21 | char *s; 22 | 23 | args[0] = &ffi_type_pointer; 24 | values[0] = (void*) &s; 25 | 26 | /* Initialize the cif */ 27 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, 28 | &ffi_type_sint, args) == FFI_OK); 29 | 30 | s = "a"; 31 | ffi_call(&cif, FFI_FN(my_strlen), &rint, values); 32 | CHECK(rint == 1); 33 | 34 | s = "1234567"; 35 | ffi_call(&cif, FFI_FN(my_strlen), &rint, values); 36 | CHECK(rint == 7); 37 | 38 | s = "1234567890123456789012345"; 39 | ffi_call(&cif, FFI_FN(my_strlen), &rint, values); 40 | CHECK(rint == 25); 41 | 42 | exit (0); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Artem Daugel-Dauge, InterSystems-Ru 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_fl3.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static float return_fl(float fl1, float fl2, unsigned int in3, float fl4) 11 | { 12 | return fl1 + fl2 + in3 + fl4; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | float fl1, fl2, fl4, rfl; 20 | unsigned int in3; 21 | args[0] = &ffi_type_float; 22 | args[1] = &ffi_type_float; 23 | args[2] = &ffi_type_uint; 24 | args[3] = &ffi_type_float; 25 | values[0] = &fl1; 26 | values[1] = &fl2; 27 | values[2] = &in3; 28 | values[3] = &fl4; 29 | 30 | /* Initialize the cif */ 31 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 32 | &ffi_type_float, args) == FFI_OK); 33 | fl1 = 127.0; 34 | fl2 = 128.0; 35 | in3 = 255; 36 | fl4 = 512.7; 37 | 38 | ffi_call(&cif, FFI_FN(return_fl), &rfl, values); 39 | printf ("%f vs %f\n", rfl, return_fl(fl1, fl2, in3, fl4)); 40 | CHECK(rfl == fl1 + fl2 + in3 + fl4); 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/negint.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check that negative integers are passed correctly. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static int checking(int a, short b, signed char c) 12 | { 13 | 14 | return (a < 0 && b < 0 && c < 0); 15 | } 16 | 17 | int main (void) 18 | { 19 | ffi_cif cif; 20 | ffi_type *args[MAX_ARGS]; 21 | void *values[MAX_ARGS]; 22 | ffi_arg rint; 23 | 24 | signed int si; 25 | signed short ss; 26 | signed char sc; 27 | 28 | args[0] = &ffi_type_sint; 29 | values[0] = &si; 30 | args[1] = &ffi_type_sshort; 31 | values[1] = &ss; 32 | args[2] = &ffi_type_schar; 33 | values[2] = ≻ 34 | 35 | /* Initialize the cif */ 36 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 37 | &ffi_type_sint, args) == FFI_OK); 38 | 39 | si = -6; 40 | ss = -12; 41 | sc = -1; 42 | 43 | checking (si, ss, sc); 44 | 45 | ffi_call(&cif, FFI_FN(checking), &rint, values); 46 | 47 | printf ("%d vs %d\n", (int)rint, checking (si, ss, sc)); 48 | 49 | CHECK(rint != 0); 50 | 51 | exit (0); 52 | } 53 | -------------------------------------------------------------------------------- /libs/libffi/LICENSE: -------------------------------------------------------------------------------- 1 | libffi - Copyright (c) 1996-2014 Anthony Green, Red Hat, Inc and others. 2 | See source files for details. 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 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_dbl2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static double return_dbl(double dbl1, double dbl2, unsigned int in3, double dbl4) 11 | { 12 | return dbl1 + dbl2 + in3 + dbl4; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | double dbl1, dbl2, dbl4, rdbl; 20 | unsigned int in3; 21 | args[0] = &ffi_type_double; 22 | args[1] = &ffi_type_double; 23 | args[2] = &ffi_type_uint; 24 | args[3] = &ffi_type_double; 25 | values[0] = &dbl1; 26 | values[1] = &dbl2; 27 | values[2] = &in3; 28 | values[3] = &dbl4; 29 | 30 | /* Initialize the cif */ 31 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 32 | &ffi_type_double, args) == FFI_OK); 33 | dbl1 = 127.0; 34 | dbl2 = 128.0; 35 | in3 = 255; 36 | dbl4 = 512.7; 37 | 38 | ffi_call(&cif, FFI_FN(return_dbl), &rdbl, values); 39 | printf ("%f vs %f\n", rdbl, return_dbl(dbl1, dbl2, in3, dbl4)); 40 | CHECK(rdbl == dbl1 + dbl2 + in3 + dbl4); 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libs/libffi/libtool-version: -------------------------------------------------------------------------------- 1 | # This file is used to maintain libtool version info for libffi. See 2 | # the libtool manual to understand the meaning of the fields. This is 3 | # a separate file so that version updates don't involve re-running 4 | # automake. 5 | # 6 | # Here are a set of rules to help you update your library version 7 | # information: 8 | # 9 | # 1. Start with version information of `0:0:0' for each libtool library. 10 | # 11 | # 2. Update the version information only immediately before a public 12 | # release of your software. More frequent updates are unnecessary, 13 | # and only guarantee that the current interface number gets larger 14 | # faster. 15 | # 16 | # 3. If the library source code has changed at all since the last 17 | # update, then increment revision (`c:r:a' becomes `c:r+1:a'). 18 | # 19 | # 4. If any interfaces have been added, removed, or changed since the 20 | # last update, increment current, and set revision to 0. 21 | # 22 | # 5. If any interfaces have been added since the last public release, 23 | # then increment age. 24 | # 25 | # 6. If any interfaces have been removed since the last public 26 | # release, then set age to 0. 27 | # 28 | # CURRENT:REVISION:AGE 29 | 6:2:0 30 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_dbl1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static double return_dbl(double dbl1, float fl2, unsigned int in3, double dbl4) 11 | { 12 | return dbl1 + fl2 + in3 + dbl4; 13 | } 14 | int main (void) 15 | { 16 | ffi_cif cif; 17 | ffi_type *args[MAX_ARGS]; 18 | void *values[MAX_ARGS]; 19 | double dbl1, dbl4, rdbl; 20 | float fl2; 21 | unsigned int in3; 22 | args[0] = &ffi_type_double; 23 | args[1] = &ffi_type_float; 24 | args[2] = &ffi_type_uint; 25 | args[3] = &ffi_type_double; 26 | values[0] = &dbl1; 27 | values[1] = &fl2; 28 | values[2] = &in3; 29 | values[3] = &dbl4; 30 | 31 | /* Initialize the cif */ 32 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 33 | &ffi_type_double, args) == FFI_OK); 34 | dbl1 = 127.0; 35 | fl2 = 128.0; 36 | in3 = 255; 37 | dbl4 = 512.7; 38 | 39 | ffi_call(&cif, FFI_FN(return_dbl), &rdbl, values); 40 | printf ("%f vs %f\n", rdbl, return_dbl(dbl1, fl2, in3, dbl4)); 41 | CHECK(rdbl == dbl1 + fl2 + in3 + dbl4); 42 | exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/strlen2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check strlen function call with additional arguments. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static size_t ABI_ATTR my_f(char *s, float a) 12 | { 13 | return (size_t) ((int) strlen(s) + (int) a); 14 | } 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[MAX_ARGS]; 20 | void *values[MAX_ARGS]; 21 | ffi_arg rint; 22 | char *s; 23 | float v2; 24 | args[0] = &ffi_type_pointer; 25 | args[1] = &ffi_type_float; 26 | values[0] = (void*) &s; 27 | values[1] = (void*) &v2; 28 | 29 | /* Initialize the cif */ 30 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, 31 | &ffi_type_sint, args) == FFI_OK); 32 | 33 | s = "a"; 34 | v2 = 0.0; 35 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 36 | CHECK(rint == 1); 37 | 38 | s = "1234567"; 39 | v2 = -1.0; 40 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 41 | CHECK(rint == 6); 42 | 43 | s = "1234567890123456789012345"; 44 | v2 = 1.0; 45 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 46 | CHECK(rint == 26); 47 | 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/strlen3.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check strlen function call with additional arguments. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static size_t ABI_ATTR my_f(float a, char *s) 12 | { 13 | return (size_t) ((int) strlen(s) + (int) a); 14 | } 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[MAX_ARGS]; 20 | void *values[MAX_ARGS]; 21 | ffi_arg rint; 22 | char *s; 23 | float v2; 24 | args[1] = &ffi_type_pointer; 25 | args[0] = &ffi_type_float; 26 | values[1] = (void*) &s; 27 | values[0] = (void*) &v2; 28 | 29 | /* Initialize the cif */ 30 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, 31 | &ffi_type_sint, args) == FFI_OK); 32 | 33 | s = "a"; 34 | v2 = 0.0; 35 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 36 | CHECK(rint == 1); 37 | 38 | s = "1234567"; 39 | v2 = -1.0; 40 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 41 | CHECK(rint == 6); 42 | 43 | s = "1234567890123456789012345"; 44 | v2 = 1.0; 45 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 46 | CHECK(rint == 26); 47 | 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_float.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20030828 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void cls_ret_float_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 11 | void* userdata __UNUSED__) 12 | { 13 | *(float *)resp = *(float *)args[0]; 14 | 15 | printf("%g: %g\n",*(float *)args[0], 16 | *(float *)resp); 17 | } 18 | 19 | typedef float (*cls_ret_float)(float); 20 | 21 | int main (void) 22 | { 23 | ffi_cif cif; 24 | void *code; 25 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 26 | ffi_type * cl_arg_types[2]; 27 | float res; 28 | 29 | cl_arg_types[0] = &ffi_type_float; 30 | cl_arg_types[1] = NULL; 31 | 32 | /* Initialize the cif */ 33 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 34 | &ffi_type_float, cl_arg_types) == FFI_OK); 35 | 36 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_float_fn, NULL, code) == FFI_OK); 37 | res = ((((cls_ret_float)code)(-2122.12))); 38 | /* { dg-output "\\-2122.12: \\-2122.12" } */ 39 | printf("res: %.6f\n", res); 40 | /* { dg-output "\nres: \-2122.120117" } */ 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_sint.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value sint32. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20031108 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void cls_ret_sint_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 11 | void* userdata __UNUSED__) 12 | { 13 | *(ffi_arg*)resp = *(signed int *)args[0]; 14 | printf("%d: %d\n",*(signed int *)args[0], 15 | (int)*(ffi_arg *)(resp)); 16 | } 17 | typedef signed int (*cls_ret_sint)(signed int); 18 | 19 | int main (void) 20 | { 21 | ffi_cif cif; 22 | void *code; 23 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 24 | ffi_type * cl_arg_types[2]; 25 | signed int res; 26 | 27 | cl_arg_types[0] = &ffi_type_sint; 28 | cl_arg_types[1] = NULL; 29 | 30 | /* Initialize the cif */ 31 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 32 | &ffi_type_sint, cl_arg_types) == FFI_OK); 33 | 34 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_sint_fn, NULL, code) == FFI_OK); 35 | 36 | res = (*((cls_ret_sint)code))(65534); 37 | /* { dg-output "65534: 65534" } */ 38 | printf("res: %d\n",res); 39 | /* { dg-output "\nres: 65534" } */ 40 | 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_ll1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check if long long are passed in the corresponding regs on ppc. 3 | Limitations: none. 4 | PR: 20104. 5 | Originator: 20050222 */ 6 | 7 | /* { dg-do run } */ 8 | /* { dg-options "-Wno-format" { target alpha*-dec-osf* } } */ 9 | #include "ffitest.h" 10 | static long long return_ll(int ll0, long long ll1, int ll2) 11 | { 12 | return ll0 + ll1 + ll2; 13 | } 14 | 15 | int main (void) 16 | { 17 | ffi_cif cif; 18 | ffi_type *args[MAX_ARGS]; 19 | void *values[MAX_ARGS]; 20 | long long rlonglong; 21 | long long ll1; 22 | unsigned ll0, ll2; 23 | 24 | args[0] = &ffi_type_sint; 25 | args[1] = &ffi_type_sint64; 26 | args[2] = &ffi_type_sint; 27 | values[0] = &ll0; 28 | values[1] = &ll1; 29 | values[2] = &ll2; 30 | 31 | /* Initialize the cif */ 32 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 33 | &ffi_type_sint64, args) == FFI_OK); 34 | 35 | ll0 = 11111111; 36 | ll1 = 11111111111000LL; 37 | ll2 = 11111111; 38 | 39 | ffi_call(&cif, FFI_FN(return_ll), &rlonglong, values); 40 | printf("res: %" PRIdLL ", %" PRIdLL "\n", rlonglong, ll0 + ll1 + ll2); 41 | /* { dg-output "res: 11111133333222, 11111133333222" } */ 42 | exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /libs/libffi/ChangeLog.libgcj: -------------------------------------------------------------------------------- 1 | 2004-01-14 Kelley Cook 2 | 3 | * configure.in: Add in AC_PREREQ(2.13) 4 | 5 | 2003-02-20 Alexandre Oliva 6 | 7 | * configure.in: Propagate ORIGINAL_LD_FOR_MULTILIBS to 8 | config.status. 9 | * configure: Rebuilt. 10 | 11 | 2002-01-27 Alexandre Oliva 12 | 13 | * configure.in (toolexecdir, toolexeclibdir): Set and AC_SUBST. 14 | Remove USE_LIBDIR conditional. 15 | * Makefile.am (toolexecdir, toolexeclibdir): Don't override. 16 | * Makefile.in, configure: Rebuilt. 17 | 18 | Mon Aug 9 18:33:38 1999 Rainer Orth 19 | 20 | * include/Makefile.in: Rebuilt. 21 | * Makefile.in: Rebuilt 22 | * Makefile.am (toolexeclibdir): Add $(MULTISUBDIR) even for native 23 | builds. 24 | Use USE_LIBDIR. 25 | 26 | * configure: Rebuilt. 27 | * configure.in (USE_LIBDIR): Define for native builds. 28 | Use lowercase in configure --help explanations. 29 | 30 | 1999-08-08 Anthony Green 31 | 32 | * include/ffi.h.in (FFI_FN): Remove `...'. 33 | 34 | 1999-08-08 Anthony Green 35 | 36 | * Makefile.in: Rebuilt. 37 | * Makefile.am (AM_CFLAGS): Compile with -fexceptions. 38 | 39 | * src/x86/sysv.S: Add exception handling metadata. 40 | 41 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_schar.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value schar. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20031108 */ 6 | 7 | 8 | 9 | /* { dg-do run } */ 10 | #include "ffitest.h" 11 | 12 | static void cls_ret_schar_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 13 | void* userdata __UNUSED__) 14 | { 15 | *(ffi_arg*)resp = *(signed char *)args[0]; 16 | printf("%d: %d\n",*(signed char *)args[0], 17 | (int)*(ffi_arg *)(resp)); 18 | } 19 | typedef signed char (*cls_ret_schar)(signed char); 20 | 21 | int main (void) 22 | { 23 | ffi_cif cif; 24 | void *code; 25 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 26 | ffi_type * cl_arg_types[2]; 27 | signed char res; 28 | 29 | cl_arg_types[0] = &ffi_type_schar; 30 | cl_arg_types[1] = NULL; 31 | 32 | /* Initialize the cif */ 33 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 34 | &ffi_type_schar, cl_arg_types) == FFI_OK); 35 | 36 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_schar_fn, NULL, code) == FFI_OK); 37 | 38 | res = (*((cls_ret_schar)code))(127); 39 | /* { dg-output "127: 127" } */ 40 | printf("res: %d\n", res); 41 | /* { dg-output "\nres: 127" } */ 42 | 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_uchar.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value uchar. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20030828 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void cls_ret_uchar_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 11 | void* userdata __UNUSED__) 12 | { 13 | *(ffi_arg*)resp = *(unsigned char *)args[0]; 14 | printf("%d: %d\n",*(unsigned char *)args[0], 15 | (int)*(ffi_arg *)(resp)); 16 | } 17 | typedef unsigned char (*cls_ret_uchar)(unsigned char); 18 | 19 | int main (void) 20 | { 21 | ffi_cif cif; 22 | void *code; 23 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 24 | ffi_type * cl_arg_types[2]; 25 | unsigned char res; 26 | 27 | cl_arg_types[0] = &ffi_type_uchar; 28 | cl_arg_types[1] = NULL; 29 | 30 | /* Initialize the cif */ 31 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 32 | &ffi_type_uchar, cl_arg_types) == FFI_OK); 33 | 34 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_uchar_fn, NULL, code) == FFI_OK); 35 | 36 | res = (*((cls_ret_uchar)code))(127); 37 | /* { dg-output "127: 127" } */ 38 | printf("res: %d\n",res); 39 | /* { dg-output "\nres: 127" } */ 40 | 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_sshort.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value sshort. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20031108 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void cls_ret_sshort_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 11 | void* userdata __UNUSED__) 12 | { 13 | *(ffi_arg*)resp = *(signed short *)args[0]; 14 | printf("%d: %d\n",*(signed short *)args[0], 15 | (int)*(ffi_arg *)(resp)); 16 | } 17 | typedef signed short (*cls_ret_sshort)(signed short); 18 | 19 | int main (void) 20 | { 21 | ffi_cif cif; 22 | void *code; 23 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 24 | ffi_type * cl_arg_types[2]; 25 | signed short res; 26 | 27 | cl_arg_types[0] = &ffi_type_sshort; 28 | cl_arg_types[1] = NULL; 29 | 30 | /* Initialize the cif */ 31 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 32 | &ffi_type_sshort, cl_arg_types) == FFI_OK); 33 | 34 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_sshort_fn, NULL, code) == FFI_OK); 35 | 36 | res = (*((cls_ret_sshort)code))(255); 37 | /* { dg-output "255: 255" } */ 38 | printf("res: %d\n",res); 39 | /* { dg-output "\nres: 255" } */ 40 | 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_double.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20030828 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void cls_ret_double_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 11 | void* userdata __UNUSED__) 12 | { 13 | *(double *)resp = *(double *)args[0]; 14 | 15 | printf("%f: %f\n",*(double *)args[0], 16 | *(double *)resp); 17 | } 18 | typedef double (*cls_ret_double)(double); 19 | 20 | int main (void) 21 | { 22 | ffi_cif cif; 23 | void *code; 24 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 25 | ffi_type * cl_arg_types[2]; 26 | double res; 27 | 28 | cl_arg_types[0] = &ffi_type_double; 29 | cl_arg_types[1] = NULL; 30 | 31 | /* Initialize the cif */ 32 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 33 | &ffi_type_double, cl_arg_types) == FFI_OK); 34 | 35 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_double_fn, NULL, code) == FFI_OK); 36 | 37 | res = (*((cls_ret_double)code))(21474.789); 38 | /* { dg-output "21474.789000: 21474.789000" } */ 39 | printf("res: %.6f\n", res); 40 | /* { dg-output "\nres: 21474.789000" } */ 41 | 42 | exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_ulong_va.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Test anonymous unsigned long argument. 3 | Limitations: none. 4 | PR: none. 5 | Originator: ARM Ltd. */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | typedef unsigned long T; 12 | 13 | static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 14 | void* userdata __UNUSED__) 15 | { 16 | *(T *)resp = *(T *)args[0]; 17 | 18 | printf("%ld: %ld %ld\n", *(T *)resp, *(T *)args[0], *(T *)args[1]); 19 | } 20 | 21 | typedef T (*cls_ret_T)(T, ...); 22 | 23 | int main (void) 24 | { 25 | ffi_cif cif; 26 | void *code; 27 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 28 | ffi_type * cl_arg_types[3]; 29 | T res; 30 | 31 | cl_arg_types[0] = &ffi_type_ulong; 32 | cl_arg_types[1] = &ffi_type_ulong; 33 | cl_arg_types[2] = NULL; 34 | 35 | /* Initialize the cif */ 36 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, 37 | &ffi_type_ulong, cl_arg_types) == FFI_OK); 38 | 39 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); 40 | res = ((((cls_ret_T)code)(67, 4))); 41 | /* { dg-output "67: 67 4" } */ 42 | printf("res: %ld\n", res); 43 | /* { dg-output "\nres: 67" } */ 44 | exit(0); 45 | } 46 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_uint_va.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Test anonymous unsigned int argument. 3 | Limitations: none. 4 | PR: none. 5 | Originator: ARM Ltd. */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | typedef unsigned int T; 12 | 13 | static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 14 | void* userdata __UNUSED__) 15 | { 16 | *(ffi_arg *)resp = *(T *)args[0]; 17 | 18 | printf("%d: %d %d\n", (int)*(ffi_arg *)resp, *(T *)args[0], *(T *)args[1]); 19 | } 20 | 21 | typedef T (*cls_ret_T)(T, ...); 22 | 23 | int main (void) 24 | { 25 | ffi_cif cif; 26 | void *code; 27 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 28 | ffi_type * cl_arg_types[3]; 29 | T res; 30 | 31 | cl_arg_types[0] = &ffi_type_uint; 32 | cl_arg_types[1] = &ffi_type_uint; 33 | cl_arg_types[2] = NULL; 34 | 35 | /* Initialize the cif */ 36 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, 37 | &ffi_type_uint, cl_arg_types) == FFI_OK); 38 | 39 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); 40 | res = ((((cls_ret_T)code)(67, 4))); 41 | /* { dg-output "67: 67 4" } */ 42 | printf("res: %d\n", res); 43 | /* { dg-output "\nres: 67" } */ 44 | exit(0); 45 | } 46 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_uchar_va.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Test anonymous unsigned char argument. 3 | Limitations: none. 4 | PR: none. 5 | Originator: ARM Ltd. */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef unsigned char T; 11 | 12 | static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 13 | void* userdata __UNUSED__) 14 | { 15 | *(ffi_arg *)resp = *(T *)args[0]; 16 | 17 | printf("%d: %d %d\n", (int)(*(ffi_arg *)resp), *(T *)args[0], *(T *)args[1]); 18 | } 19 | 20 | typedef T (*cls_ret_T)(T, ...); 21 | 22 | int main (void) 23 | { 24 | ffi_cif cif; 25 | void *code; 26 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 27 | ffi_type * cl_arg_types[3]; 28 | T res; 29 | 30 | cl_arg_types[0] = &ffi_type_uchar; 31 | cl_arg_types[1] = &ffi_type_uchar; 32 | cl_arg_types[2] = NULL; 33 | 34 | /* Initialize the cif */ 35 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, 36 | &ffi_type_uchar, cl_arg_types) == FFI_OK); 37 | 38 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); 39 | res = ((((cls_ret_T)code)(67, 4))); 40 | /* { dg-output "67: 67 4" } */ 41 | printf("res: %d\n", res); 42 | /* { dg-output "\nres: 67" } */ 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_uint.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value uint. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20030828 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void cls_ret_uint_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 11 | void* userdata __UNUSED__) 12 | { 13 | *(ffi_arg *)resp = *(unsigned int *)args[0]; 14 | 15 | printf("%d: %d\n",*(unsigned int *)args[0], 16 | (int)*(ffi_arg *)(resp)); 17 | } 18 | typedef unsigned int (*cls_ret_uint)(unsigned int); 19 | 20 | int main (void) 21 | { 22 | ffi_cif cif; 23 | void *code; 24 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 25 | ffi_type * cl_arg_types[2]; 26 | unsigned int res; 27 | 28 | cl_arg_types[0] = &ffi_type_uint; 29 | cl_arg_types[1] = NULL; 30 | 31 | /* Initialize the cif */ 32 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 33 | &ffi_type_uint, cl_arg_types) == FFI_OK); 34 | 35 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_uint_fn, NULL, code) == FFI_OK); 36 | 37 | res = (*((cls_ret_uint)code))(2147483647); 38 | /* { dg-output "2147483647: 2147483647" } */ 39 | printf("res: %d\n",res); 40 | /* { dg-output "\nres: 2147483647" } */ 41 | 42 | exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_ushort.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value ushort. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20030828 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void cls_ret_ushort_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 11 | void* userdata __UNUSED__) 12 | { 13 | *(ffi_arg*)resp = *(unsigned short *)args[0]; 14 | 15 | printf("%d: %d\n",*(unsigned short *)args[0], 16 | (int)*(ffi_arg *)(resp)); 17 | } 18 | typedef unsigned short (*cls_ret_ushort)(unsigned short); 19 | 20 | int main (void) 21 | { 22 | ffi_cif cif; 23 | void *code; 24 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 25 | ffi_type * cl_arg_types[2]; 26 | unsigned short res; 27 | 28 | cl_arg_types[0] = &ffi_type_ushort; 29 | cl_arg_types[1] = NULL; 30 | 31 | /* Initialize the cif */ 32 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 33 | &ffi_type_ushort, cl_arg_types) == FFI_OK); 34 | 35 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_ushort_fn, NULL, code) == FFI_OK); 36 | 37 | res = (*((cls_ret_ushort)code))(65535); 38 | /* { dg-output "65535: 65535" } */ 39 | printf("res: %d\n",res); 40 | /* { dg-output "\nres: 65535" } */ 41 | 42 | exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_ushort_va.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Test anonymous unsigned short argument. 3 | Limitations: none. 4 | PR: none. 5 | Originator: ARM Ltd. */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef unsigned short T; 11 | 12 | static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 13 | void* userdata __UNUSED__) 14 | { 15 | *(ffi_arg *)resp = *(T *)args[0]; 16 | 17 | printf("%d: %d %d\n", (int)(*(ffi_arg *)resp), *(T *)args[0], *(T *)args[1]); 18 | } 19 | 20 | typedef T (*cls_ret_T)(T, ...); 21 | 22 | int main (void) 23 | { 24 | ffi_cif cif; 25 | void *code; 26 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 27 | ffi_type * cl_arg_types[3]; 28 | T res; 29 | 30 | cl_arg_types[0] = &ffi_type_ushort; 31 | cl_arg_types[1] = &ffi_type_ushort; 32 | cl_arg_types[2] = NULL; 33 | 34 | /* Initialize the cif */ 35 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, 36 | &ffi_type_ushort, cl_arg_types) == FFI_OK); 37 | 38 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); 39 | res = ((((cls_ret_T)code)(67, 4))); 40 | /* { dg-output "67: 67 4" } */ 41 | printf("res: %d\n", res); 42 | /* { dg-output "\nres: 67" } */ 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/unwindtest_ffi_call.cc: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, unwind info 2 | Purpose: Check if the unwind information is passed correctly. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Andreas Tobler 20061213 */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static int checking(int a __UNUSED__, short b __UNUSED__, 12 | signed char c __UNUSED__) 13 | { 14 | throw 9; 15 | } 16 | 17 | int main (void) 18 | { 19 | ffi_cif cif; 20 | ffi_type *args[MAX_ARGS]; 21 | void *values[MAX_ARGS]; 22 | ffi_arg rint; 23 | 24 | signed int si; 25 | signed short ss; 26 | signed char sc; 27 | 28 | args[0] = &ffi_type_sint; 29 | values[0] = &si; 30 | args[1] = &ffi_type_sshort; 31 | values[1] = &ss; 32 | args[2] = &ffi_type_schar; 33 | values[2] = ≻ 34 | 35 | /* Initialize the cif */ 36 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 37 | &ffi_type_sint, args) == FFI_OK); 38 | 39 | si = -6; 40 | ss = -12; 41 | sc = -1; 42 | { 43 | try 44 | { 45 | ffi_call(&cif, FFI_FN(checking), &rint, values); 46 | } catch (int exception_code) 47 | { 48 | CHECK(exception_code == 9); 49 | } 50 | printf("part one OK\n"); 51 | /* { dg-output "part one OK" } */ 52 | } 53 | exit(0); 54 | } 55 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/return_fl2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20050212 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | /* Use volatile float to avoid false negative on ix86. See PR target/323. */ 11 | static float return_fl(float fl1, float fl2, float fl3, float fl4) 12 | { 13 | volatile float sum; 14 | 15 | sum = fl1 + fl2 + fl3 + fl4; 16 | return sum; 17 | } 18 | int main (void) 19 | { 20 | ffi_cif cif; 21 | ffi_type *args[MAX_ARGS]; 22 | void *values[MAX_ARGS]; 23 | float fl1, fl2, fl3, fl4, rfl; 24 | volatile float sum; 25 | 26 | args[0] = &ffi_type_float; 27 | args[1] = &ffi_type_float; 28 | args[2] = &ffi_type_float; 29 | args[3] = &ffi_type_float; 30 | values[0] = &fl1; 31 | values[1] = &fl2; 32 | values[2] = &fl3; 33 | values[3] = &fl4; 34 | 35 | /* Initialize the cif */ 36 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 37 | &ffi_type_float, args) == FFI_OK); 38 | fl1 = 127.0; 39 | fl2 = 128.0; 40 | fl3 = 255.1; 41 | fl4 = 512.7; 42 | 43 | ffi_call(&cif, FFI_FN(return_fl), &rfl, values); 44 | printf ("%f vs %f\n", rfl, return_fl(fl1, fl2, fl3, fl4)); 45 | 46 | sum = fl1 + fl2 + fl3 + fl4; 47 | CHECK(rfl == sum); 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/many2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check uint8_t arguments. 3 | Limitations: none. 4 | PR: PR45677. 5 | Originator: Dan Witte 20100916 */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | #define NARGS 7 12 | 13 | typedef unsigned char u8; 14 | 15 | #ifdef __GNUC__ 16 | __attribute__((noinline)) 17 | #endif 18 | uint8_t 19 | foo (uint8_t a, uint8_t b, uint8_t c, uint8_t d, 20 | uint8_t e, uint8_t f, uint8_t g) 21 | { 22 | return a + b + c + d + e + f + g; 23 | } 24 | 25 | uint8_t ABI_ATTR 26 | bar (uint8_t a, uint8_t b, uint8_t c, uint8_t d, 27 | uint8_t e, uint8_t f, uint8_t g) 28 | { 29 | return foo (a, b, c, d, e, f, g); 30 | } 31 | 32 | int 33 | main (void) 34 | { 35 | ffi_type *ffitypes[NARGS]; 36 | int i; 37 | ffi_cif cif; 38 | ffi_arg result = 0; 39 | uint8_t args[NARGS]; 40 | void *argptrs[NARGS]; 41 | 42 | for (i = 0; i < NARGS; ++i) 43 | ffitypes[i] = &ffi_type_uint8; 44 | 45 | CHECK (ffi_prep_cif (&cif, ABI_NUM, NARGS, 46 | &ffi_type_uint8, ffitypes) == FFI_OK); 47 | 48 | for (i = 0; i < NARGS; ++i) 49 | { 50 | args[i] = i; 51 | argptrs[i] = &args[i]; 52 | } 53 | ffi_call (&cif, FFI_FN (bar), &result, argptrs); 54 | 55 | CHECK (result == 21); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/strlen4.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check strlen function call with additional arguments. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static size_t ABI_ATTR my_f(float a, char *s, int i) 12 | { 13 | return (size_t) ((int) strlen(s) + (int) a + i); 14 | } 15 | 16 | int main (void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[MAX_ARGS]; 20 | void *values[MAX_ARGS]; 21 | ffi_arg rint; 22 | char *s; 23 | int v1; 24 | float v2; 25 | args[2] = &ffi_type_sint; 26 | args[1] = &ffi_type_pointer; 27 | args[0] = &ffi_type_float; 28 | values[2] = (void*) &v1; 29 | values[1] = (void*) &s; 30 | values[0] = (void*) &v2; 31 | 32 | /* Initialize the cif */ 33 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 3, 34 | &ffi_type_sint, args) == FFI_OK); 35 | 36 | s = "a"; 37 | v1 = 1; 38 | v2 = 0.0; 39 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 40 | CHECK(rint == 2); 41 | 42 | s = "1234567"; 43 | v2 = -1.0; 44 | v1 = -2; 45 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 46 | CHECK(rint == 4); 47 | 48 | s = "1234567890123456789012345"; 49 | v2 = 1.0; 50 | v1 = 2; 51 | ffi_call(&cif, FFI_FN(my_f), &rint, values); 52 | CHECK(rint == 28); 53 | 54 | exit(0); 55 | } 56 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static int floating(int a, float b, double c, long double d) 12 | { 13 | int i; 14 | 15 | i = (int) ((float)a/b + ((float)c/(float)d)); 16 | 17 | return i; 18 | } 19 | 20 | int main (void) 21 | { 22 | ffi_cif cif; 23 | ffi_type *args[MAX_ARGS]; 24 | void *values[MAX_ARGS]; 25 | ffi_arg rint; 26 | 27 | float f; 28 | signed int si1; 29 | double d; 30 | long double ld; 31 | 32 | args[0] = &ffi_type_sint; 33 | values[0] = &si1; 34 | args[1] = &ffi_type_float; 35 | values[1] = &f; 36 | args[2] = &ffi_type_double; 37 | values[2] = &d; 38 | args[3] = &ffi_type_longdouble; 39 | values[3] = &ld; 40 | 41 | /* Initialize the cif */ 42 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 43 | &ffi_type_sint, args) == FFI_OK); 44 | 45 | si1 = 6; 46 | f = 3.14159; 47 | d = (double)1.0/(double)3.0; 48 | ld = 2.71828182846L; 49 | 50 | floating (si1, f, d, ld); 51 | 52 | ffi_call(&cif, FFI_FN(floating), &rint, values); 53 | 54 | printf ("%d vs %d\n", (int)rint, floating (si1, f, d, ld)); 55 | 56 | CHECK((int)rint == floating(si1, f, d, ld)); 57 | 58 | exit (0); 59 | } 60 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/float1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | #include "float.h" 10 | 11 | typedef union 12 | { 13 | double d; 14 | unsigned char c[sizeof (double)]; 15 | } value_type; 16 | 17 | #define CANARY 0xba 18 | 19 | static double dblit(float f) 20 | { 21 | return f/3.0; 22 | } 23 | 24 | int main (void) 25 | { 26 | ffi_cif cif; 27 | ffi_type *args[MAX_ARGS]; 28 | void *values[MAX_ARGS]; 29 | float f; 30 | value_type result[2]; 31 | unsigned int i; 32 | 33 | args[0] = &ffi_type_float; 34 | values[0] = &f; 35 | 36 | /* Initialize the cif */ 37 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 38 | &ffi_type_double, args) == FFI_OK); 39 | 40 | f = 3.14159; 41 | 42 | /* Put a canary in the return array. This is a regression test for 43 | a buffer overrun. */ 44 | memset(result[1].c, CANARY, sizeof (double)); 45 | 46 | ffi_call(&cif, FFI_FN(dblit), &result[0].d, values); 47 | 48 | /* These are not always the same!! Check for a reasonable delta */ 49 | 50 | CHECK(result[0].d - dblit(f) < DBL_EPSILON); 51 | 52 | /* Check the canary. */ 53 | for (i = 0; i < sizeof (double); ++i) 54 | CHECK(result[1].c[i] == CANARY); 55 | 56 | exit(0); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /libs/libffi/man/ffi_prep_cif.3: -------------------------------------------------------------------------------- 1 | .Dd February 15, 2008 2 | .Dt ffi_prep_cif 3 3 | .Sh NAME 4 | .Nm ffi_prep_cif 5 | .Nd Prepare a 6 | .Nm ffi_cif 7 | structure for use with 8 | .Nm ffi_call 9 | . 10 | .Sh SYNOPSIS 11 | .In ffi.h 12 | .Ft ffi_status 13 | .Fo ffi_prep_cif 14 | .Fa "ffi_cif *cif" 15 | .Fa "ffi_abi abi" 16 | .Fa "unsigned int nargs" 17 | .Fa "ffi_type *rtype" 18 | .Fa "ffi_type **atypes" 19 | .Fc 20 | .Sh DESCRIPTION 21 | The 22 | .Nm ffi_prep_cif 23 | function prepares a 24 | .Nm ffi_cif 25 | structure for use with 26 | .Nm ffi_call 27 | . 28 | .Fa abi 29 | specifies a set of calling conventions to use. 30 | .Fa atypes 31 | is an array of 32 | .Fa nargs 33 | pointers to 34 | .Nm ffi_type 35 | structs that describe the data type, size and alignment of each argument. 36 | .Fa rtype 37 | points to an 38 | .Nm ffi_type 39 | that describes the data type, size and alignment of the 40 | return value. Note that to call a variadic function 41 | .Nm ffi_prep_cif_var 42 | must be used instead. 43 | .Sh RETURN VALUES 44 | Upon successful completion, 45 | .Nm ffi_prep_cif 46 | returns 47 | .Nm FFI_OK . 48 | It will return 49 | .Nm FFI_BAD_TYPEDEF 50 | if 51 | .Fa cif 52 | is 53 | .Nm NULL 54 | or 55 | .Fa atypes 56 | or 57 | .Fa rtype 58 | is malformed. If 59 | .Fa abi 60 | does not refer to a valid ABI, 61 | .Nm FFI_BAD_ABI 62 | will be returned. Available ABIs are 63 | defined in 64 | .Nm . 65 | .Sh SEE ALSO 66 | .Xr ffi 3 , 67 | .Xr ffi_call 3 , 68 | .Xr ffi_prep_cif_var 3 69 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct3.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct 11 | { 12 | int si; 13 | } test_structure_3; 14 | 15 | static test_structure_3 ABI_ATTR struct3(test_structure_3 ts) 16 | { 17 | ts.si = -(ts.si*2); 18 | 19 | return ts; 20 | } 21 | 22 | int main (void) 23 | { 24 | ffi_cif cif; 25 | ffi_type *args[MAX_ARGS]; 26 | void *values[MAX_ARGS]; 27 | int compare_value; 28 | ffi_type ts3_type; 29 | ffi_type *ts3_type_elements[2]; 30 | 31 | test_structure_3 ts3_arg; 32 | test_structure_3 *ts3_result = 33 | (test_structure_3 *) malloc (sizeof(test_structure_3)); 34 | 35 | ts3_type.size = 0; 36 | ts3_type.alignment = 0; 37 | ts3_type.type = FFI_TYPE_STRUCT; 38 | ts3_type.elements = ts3_type_elements; 39 | ts3_type_elements[0] = &ffi_type_sint; 40 | ts3_type_elements[1] = NULL; 41 | 42 | args[0] = &ts3_type; 43 | values[0] = &ts3_arg; 44 | 45 | /* Initialize the cif */ 46 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, 47 | &ts3_type, args) == FFI_OK); 48 | 49 | ts3_arg.si = -123; 50 | compare_value = ts3_arg.si; 51 | 52 | ffi_call(&cif, FFI_FN(struct3), ts3_result, values); 53 | 54 | printf ("%d %d\n", ts3_result->si, -(compare_value*2)); 55 | 56 | CHECK(ts3_result->si == -(compare_value*2)); 57 | 58 | free (ts3_result); 59 | exit(0); 60 | } 61 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/uninitialized.c: -------------------------------------------------------------------------------- 1 | /* { dg-do run } */ 2 | #include "ffitest.h" 3 | 4 | typedef struct 5 | { 6 | unsigned char uc; 7 | double d; 8 | unsigned int ui; 9 | } test_structure_1; 10 | 11 | static test_structure_1 struct1(test_structure_1 ts) 12 | { 13 | ts.uc++; 14 | ts.d--; 15 | ts.ui++; 16 | 17 | return ts; 18 | } 19 | 20 | int main (void) 21 | { 22 | ffi_cif cif; 23 | ffi_type *args[MAX_ARGS]; 24 | void *values[MAX_ARGS]; 25 | ffi_type ts1_type; 26 | ffi_type *ts1_type_elements[4]; 27 | 28 | memset(&cif, 1, sizeof(cif)); 29 | ts1_type.size = 0; 30 | ts1_type.alignment = 0; 31 | ts1_type.type = FFI_TYPE_STRUCT; 32 | ts1_type.elements = ts1_type_elements; 33 | ts1_type_elements[0] = &ffi_type_uchar; 34 | ts1_type_elements[1] = &ffi_type_double; 35 | ts1_type_elements[2] = &ffi_type_uint; 36 | ts1_type_elements[3] = NULL; 37 | 38 | test_structure_1 ts1_arg; 39 | /* This is a hack to get a properly aligned result buffer */ 40 | test_structure_1 *ts1_result = 41 | (test_structure_1 *) malloc (sizeof(test_structure_1)); 42 | 43 | args[0] = &ts1_type; 44 | values[0] = &ts1_arg; 45 | 46 | /* Initialize the cif */ 47 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 48 | &ts1_type, args) == FFI_OK); 49 | 50 | ts1_arg.uc = '\x01'; 51 | ts1_arg.d = 3.14159; 52 | ts1_arg.ui = 555; 53 | 54 | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); 55 | 56 | CHECK(ts1_result->ui == 556); 57 | CHECK(ts1_result->d == 3.14159 - 1); 58 | 59 | free (ts1_result); 60 | exit(0); 61 | } 62 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/float4.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check denorm double value. 3 | Limitations: none. 4 | PR: PR26483. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | /* { dg-options "-mieee" { target alpha*-*-* } } */ 9 | 10 | #include "ffitest.h" 11 | #include "float.h" 12 | 13 | typedef union 14 | { 15 | double d; 16 | unsigned char c[sizeof (double)]; 17 | } value_type; 18 | 19 | #define CANARY 0xba 20 | 21 | static double dblit(double d) 22 | { 23 | return d; 24 | } 25 | 26 | int main (void) 27 | { 28 | ffi_cif cif; 29 | ffi_type *args[MAX_ARGS]; 30 | void *values[MAX_ARGS]; 31 | double d; 32 | value_type result[2]; 33 | unsigned int i; 34 | 35 | args[0] = &ffi_type_double; 36 | values[0] = &d; 37 | 38 | /* Initialize the cif */ 39 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 40 | &ffi_type_double, args) == FFI_OK); 41 | 42 | d = DBL_MIN / 2; 43 | 44 | /* Put a canary in the return array. This is a regression test for 45 | a buffer overrun. */ 46 | memset(result[1].c, CANARY, sizeof (double)); 47 | 48 | ffi_call(&cif, FFI_FN(dblit), &result[0].d, values); 49 | 50 | /* The standard delta check doesn't work for denorms. Since we didn't do 51 | any arithmetic, we should get the original result back, and hence an 52 | exact check should be OK here. */ 53 | 54 | CHECK(result[0].d == dblit(d)); 55 | 56 | /* Check the canary. */ 57 | for (i = 0; i < sizeof (double); ++i) 58 | CHECK(result[1].c[i] == CANARY); 59 | 60 | exit(0); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | RM := rm 3 | CD := cd 4 | MAKE := make 5 | 6 | CFLAGS += -Wall -Wextra -fpic -O2 -fno-strict-aliasing -Wno-unused-parameter 7 | 8 | SYS := $(shell gcc -dumpmachine) 9 | LIBFFI_PATH := ./libs/libffi 10 | 11 | ifeq ($(SYS), x86_64-w64-mingw32) 12 | BUILDSYS := $(SYS) 13 | else 14 | BUILDSYS := $(shell bash $(LIBFFI_PATH)/config.guess) 15 | endif 16 | 17 | LIBFFI_PATH := $(LIBFFI_PATH)/$(BUILDSYS) 18 | INCLUDES :=-I$(LIBFFI_PATH)/include 19 | LIBS := -L$(LIBFFI_PATH)/.libs -lffi 20 | 21 | ifneq (, $(findstring linux, $(SYS))) 22 | SUFFIX := so 23 | LDFLAGS := -shared 24 | LIBS += -ldl 25 | else ifneq (, $(findstring mingw, $(SYS))) 26 | SUFFIX := dll 27 | LDFLAGS := -mdll 28 | else 29 | $(error Unsupported build platform) 30 | endif 31 | 32 | 33 | ifndef GLOBALS_HOME 34 | $(error Couldn't find GLOBALS_HOME) 35 | endif 36 | 37 | 38 | INCLUDES += -I${GLOBALS_HOME}/dev/cpp/include 39 | CFLAGS += $(INCLUDES) 40 | TESTSDIR := tests 41 | 42 | .PHONY: all clean libffi libffi-clean 43 | 44 | all: libcna.$(SUFFIX) $(TESTSDIR)/libtest.$(SUFFIX) 45 | 46 | libffi: 47 | cd libs/libffi && ./configure --build=$(BUILDSYS) --enable-shared=no && $(MAKE) 48 | 49 | cna.o: cna.c storage.h 50 | 51 | storage.o: storage.c storage.h 52 | 53 | libcna.$(SUFFIX): cna.o storage.o 54 | $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) 55 | 56 | $(TESTSDIR)/teslib.o: $(TESTSDIR)/testlib.c 57 | 58 | $(TESTSDIR)/libtest.$(SUFFIX): $(TESTSDIR)/testlib.o 59 | $(CC) $(LDFLAGS) -o $@ $^ 60 | 61 | libffi-clean: 62 | $(CD) libs/libffi && $(MAKE) clean 63 | 64 | clean: 65 | $(RM) *.$(SUFFIX) *.o $(TESTSDIR)/*.$(SUFFIX) $(TESTSDIR)/*.o -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/many.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value float, with many arguments 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static float ABI_ATTR many(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13) 15 | { 16 | #if 0 17 | printf("%f %f %f %f %f %f %f %f %f %f %f %f %f\n", 18 | (double) f1, (double) f2, (double) f3, (double) f4, (double) f5, 19 | (double) f6, (double) f7, (double) f8, (double) f9, (double) f10, 20 | (double) f11, (double) f12, (double) f13); 21 | #endif 22 | 23 | return f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13; 24 | } 25 | 26 | int main (void) 27 | { 28 | ffi_cif cif; 29 | ffi_type *args[13]; 30 | void *values[13]; 31 | float fa[13]; 32 | float f, ff; 33 | int i; 34 | 35 | for (i = 0; i < 13; i++) 36 | { 37 | args[i] = &ffi_type_float; 38 | values[i] = &fa[i]; 39 | fa[i] = (float) i; 40 | } 41 | 42 | /* Initialize the cif */ 43 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 13, 44 | &ffi_type_float, args) == FFI_OK); 45 | 46 | ffi_call(&cif, FFI_FN(many), &f, values); 47 | 48 | ff = many(fa[0], fa[1], 49 | fa[2], fa[3], 50 | fa[4], fa[5], 51 | fa[6], fa[7], 52 | fa[8], fa[9], 53 | fa[10],fa[11],fa[12]); 54 | 55 | if (fabs(f - ff) < FLT_EPSILON) 56 | exit(0); 57 | else 58 | abort(); 59 | } 60 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/promotion.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Promotion test. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | static int promotion(signed char sc, signed short ss, 10 | unsigned char uc, unsigned short us) 11 | { 12 | int r = (int) sc + (int) ss + (int) uc + (int) us; 13 | 14 | return r; 15 | } 16 | 17 | int main (void) 18 | { 19 | ffi_cif cif; 20 | ffi_type *args[MAX_ARGS]; 21 | void *values[MAX_ARGS]; 22 | ffi_arg rint; 23 | signed char sc; 24 | unsigned char uc; 25 | signed short ss; 26 | unsigned short us; 27 | unsigned long ul; 28 | 29 | args[0] = &ffi_type_schar; 30 | args[1] = &ffi_type_sshort; 31 | args[2] = &ffi_type_uchar; 32 | args[3] = &ffi_type_ushort; 33 | values[0] = ≻ 34 | values[1] = &ss; 35 | values[2] = &uc; 36 | values[3] = &us; 37 | 38 | /* Initialize the cif */ 39 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 40 | &ffi_type_sint, args) == FFI_OK); 41 | 42 | us = 0; 43 | ul = 0; 44 | 45 | for (sc = (signed char) -127; 46 | sc <= (signed char) 120; sc += 1) 47 | for (ss = -30000; ss <= 30000; ss += 10000) 48 | for (uc = (unsigned char) 0; 49 | uc <= (unsigned char) 200; uc += 20) 50 | for (us = 0; us <= 60000; us += 10000) 51 | { 52 | ul++; 53 | ffi_call(&cif, FFI_FN(promotion), &rint, values); 54 | CHECK((int)rint == (signed char) sc + (signed short) ss + 55 | (unsigned char) uc + (unsigned short) us); 56 | } 57 | printf("%lu promotion tests run\n", ul); 58 | exit(0); 59 | } 60 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct4.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct 11 | { 12 | unsigned ui1; 13 | unsigned ui2; 14 | unsigned ui3; 15 | } test_structure_4; 16 | 17 | static test_structure_4 ABI_ATTR struct4(test_structure_4 ts) 18 | { 19 | ts.ui3 = ts.ui1 * ts.ui2 * ts.ui3; 20 | 21 | return ts; 22 | } 23 | 24 | int main (void) 25 | { 26 | ffi_cif cif; 27 | ffi_type *args[MAX_ARGS]; 28 | void *values[MAX_ARGS]; 29 | ffi_type ts4_type; 30 | ffi_type *ts4_type_elements[4]; 31 | 32 | test_structure_4 ts4_arg; 33 | 34 | /* This is a hack to get a properly aligned result buffer */ 35 | test_structure_4 *ts4_result = 36 | (test_structure_4 *) malloc (sizeof(test_structure_4)); 37 | 38 | ts4_type.size = 0; 39 | ts4_type.alignment = 0; 40 | ts4_type.type = FFI_TYPE_STRUCT; 41 | ts4_type.elements = ts4_type_elements; 42 | ts4_type_elements[0] = &ffi_type_uint; 43 | ts4_type_elements[1] = &ffi_type_uint; 44 | ts4_type_elements[2] = &ffi_type_uint; 45 | ts4_type_elements[3] = NULL; 46 | 47 | args[0] = &ts4_type; 48 | values[0] = &ts4_arg; 49 | 50 | /* Initialize the cif */ 51 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts4_type, args) == FFI_OK); 52 | 53 | ts4_arg.ui1 = 2; 54 | ts4_arg.ui2 = 3; 55 | ts4_arg.ui3 = 4; 56 | 57 | ffi_call (&cif, FFI_FN(struct4), ts4_result, values); 58 | 59 | CHECK(ts4_result->ui3 == 2U * 3U * 4U); 60 | 61 | 62 | free (ts4_result); 63 | exit(0); 64 | } 65 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct6.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | typedef struct 10 | { 11 | float f; 12 | double d; 13 | } test_structure_6; 14 | 15 | static test_structure_6 ABI_ATTR struct6 (test_structure_6 ts) 16 | { 17 | ts.f += 1; 18 | ts.d += 1; 19 | 20 | return ts; 21 | } 22 | 23 | int main (void) 24 | { 25 | ffi_cif cif; 26 | ffi_type *args[MAX_ARGS]; 27 | void *values[MAX_ARGS]; 28 | ffi_type ts6_type; 29 | ffi_type *ts6_type_elements[3]; 30 | 31 | test_structure_6 ts6_arg; 32 | 33 | /* This is a hack to get a properly aligned result buffer */ 34 | test_structure_6 *ts6_result = 35 | (test_structure_6 *) malloc (sizeof(test_structure_6)); 36 | 37 | ts6_type.size = 0; 38 | ts6_type.alignment = 0; 39 | ts6_type.type = FFI_TYPE_STRUCT; 40 | ts6_type.elements = ts6_type_elements; 41 | ts6_type_elements[0] = &ffi_type_float; 42 | ts6_type_elements[1] = &ffi_type_double; 43 | ts6_type_elements[2] = NULL; 44 | 45 | args[0] = &ts6_type; 46 | values[0] = &ts6_arg; 47 | 48 | /* Initialize the cif */ 49 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts6_type, args) == FFI_OK); 50 | 51 | ts6_arg.f = 5.55f; 52 | ts6_arg.d = 6.66; 53 | 54 | printf ("%g\n", ts6_arg.f); 55 | printf ("%g\n", ts6_arg.d); 56 | 57 | ffi_call(&cif, FFI_FN(struct6), ts6_result, values); 58 | 59 | CHECK(ts6_result->f == 5.55f + 1); 60 | CHECK(ts6_result->d == 6.66 + 1); 61 | 62 | free (ts6_result); 63 | exit(0); 64 | } 65 | -------------------------------------------------------------------------------- /libs/libffi/man/ffi_prep_cif_var.3: -------------------------------------------------------------------------------- 1 | .Dd January 25, 2011 2 | .Dt ffi_prep_cif_var 3 3 | .Sh NAME 4 | .Nm ffi_prep_cif_var 5 | .Nd Prepare a 6 | .Nm ffi_cif 7 | structure for use with 8 | .Nm ffi_call 9 | for variadic functions. 10 | .Sh SYNOPSIS 11 | .In ffi.h 12 | .Ft ffi_status 13 | .Fo ffi_prep_cif_var 14 | .Fa "ffi_cif *cif" 15 | .Fa "ffi_abi abi" 16 | .Fa "unsigned int nfixedargs" 17 | .Fa "unsigned int ntotalargs" 18 | .Fa "ffi_type *rtype" 19 | .Fa "ffi_type **atypes" 20 | .Fc 21 | .Sh DESCRIPTION 22 | The 23 | .Nm ffi_prep_cif_var 24 | function prepares a 25 | .Nm ffi_cif 26 | structure for use with 27 | .Nm ffi_call 28 | for variadic functions. 29 | .Fa abi 30 | specifies a set of calling conventions to use. 31 | .Fa atypes 32 | is an array of 33 | .Fa ntotalargs 34 | pointers to 35 | .Nm ffi_type 36 | structs that describe the data type, size and alignment of each argument. 37 | .Fa rtype 38 | points to an 39 | .Nm ffi_type 40 | that describes the data type, size and alignment of the 41 | return value. 42 | .Fa nfixedargs 43 | must contain the number of fixed (non-variadic) arguments. 44 | Note that to call a non-variadic function 45 | .Nm ffi_prep_cif 46 | must be used. 47 | .Sh RETURN VALUES 48 | Upon successful completion, 49 | .Nm ffi_prep_cif_var 50 | returns 51 | .Nm FFI_OK . 52 | It will return 53 | .Nm FFI_BAD_TYPEDEF 54 | if 55 | .Fa cif 56 | is 57 | .Nm NULL 58 | or 59 | .Fa atypes 60 | or 61 | .Fa rtype 62 | is malformed. If 63 | .Fa abi 64 | does not refer to a valid ABI, 65 | .Nm FFI_BAD_ABI 66 | will be returned. Available ABIs are 67 | defined in 68 | .Nm 69 | . 70 | .Sh SEE ALSO 71 | .Xr ffi 3 , 72 | .Xr ffi_call 3 , 73 | .Xr ffi_prep_cif 3 74 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_dbls_struct.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check double arguments in structs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Blake Chaffin 6/23/2007 */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | typedef struct Dbls { 12 | double x; 13 | double y; 14 | } Dbls; 15 | 16 | void 17 | closure_test_fn(Dbls p) 18 | { 19 | printf("%.1f %.1f\n", p.x, p.y); 20 | } 21 | 22 | void 23 | closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__, 24 | void** args, void* userdata __UNUSED__) 25 | { 26 | closure_test_fn(*(Dbls*)args[0]); 27 | } 28 | 29 | int main(int argc __UNUSED__, char** argv __UNUSED__) 30 | { 31 | ffi_cif cif; 32 | 33 | void *code; 34 | ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 35 | ffi_type* cl_arg_types[1]; 36 | 37 | ffi_type ts1_type; 38 | ffi_type* ts1_type_elements[4]; 39 | 40 | Dbls arg = { 1.0, 2.0 }; 41 | 42 | ts1_type.size = 0; 43 | ts1_type.alignment = 0; 44 | ts1_type.type = FFI_TYPE_STRUCT; 45 | ts1_type.elements = ts1_type_elements; 46 | 47 | ts1_type_elements[0] = &ffi_type_double; 48 | ts1_type_elements[1] = &ffi_type_double; 49 | ts1_type_elements[2] = NULL; 50 | 51 | cl_arg_types[0] = &ts1_type; 52 | 53 | /* Initialize the cif */ 54 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 55 | &ffi_type_void, cl_arg_types) == FFI_OK); 56 | 57 | CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK); 58 | 59 | ((void*(*)(Dbls))(code))(arg); 60 | /* { dg-output "1.0 2.0\n" } */ 61 | 62 | closure_test_fn(arg); 63 | /* { dg-output "1.0 2.0\n" } */ 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/closure_simple.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check simple closure handling with all ABIs 3 | Limitations: none. 4 | PR: none. 5 | Originator: */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | static void 11 | closure_test(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata) 12 | { 13 | *(ffi_arg*)resp = 14 | (int)*(int *)args[0] + (int)(*(int *)args[1]) 15 | + (int)(*(int *)args[2]) + (int)(*(int *)args[3]) 16 | + (int)(intptr_t)userdata; 17 | 18 | printf("%d %d %d %d: %d\n", 19 | (int)*(int *)args[0], (int)(*(int *)args[1]), 20 | (int)(*(int *)args[2]), (int)(*(int *)args[3]), 21 | (int)*(ffi_arg *)resp); 22 | 23 | } 24 | 25 | typedef int (ABI_ATTR *closure_test_type0)(int, int, int, int); 26 | 27 | int main (void) 28 | { 29 | ffi_cif cif; 30 | void *code; 31 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 32 | ffi_type * cl_arg_types[17]; 33 | int res; 34 | 35 | cl_arg_types[0] = &ffi_type_uint; 36 | cl_arg_types[1] = &ffi_type_uint; 37 | cl_arg_types[2] = &ffi_type_uint; 38 | cl_arg_types[3] = &ffi_type_uint; 39 | cl_arg_types[4] = NULL; 40 | 41 | /* Initialize the cif */ 42 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 4, 43 | &ffi_type_sint, cl_arg_types) == FFI_OK); 44 | 45 | CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test, 46 | (void *) 3 /* userdata */, code) == FFI_OK); 47 | 48 | res = (*(closure_test_type0)code)(0, 1, 2, 3); 49 | /* { dg-output "0 1 2 3: 9" } */ 50 | 51 | printf("res: %d\n",res); 52 | /* { dg-output "\nres: 9" } */ 53 | 54 | exit(0); 55 | } 56 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct 11 | { 12 | unsigned char uc; 13 | double d; 14 | unsigned int ui; 15 | } test_structure_1; 16 | 17 | static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) 18 | { 19 | ts.uc++; 20 | ts.d--; 21 | ts.ui++; 22 | 23 | return ts; 24 | } 25 | 26 | int main (void) 27 | { 28 | ffi_cif cif; 29 | ffi_type *args[MAX_ARGS]; 30 | void *values[MAX_ARGS]; 31 | ffi_type ts1_type; 32 | ffi_type *ts1_type_elements[4]; 33 | 34 | test_structure_1 ts1_arg; 35 | 36 | /* This is a hack to get a properly aligned result buffer */ 37 | test_structure_1 *ts1_result = 38 | (test_structure_1 *) malloc (sizeof(test_structure_1)); 39 | 40 | ts1_type.size = 0; 41 | ts1_type.alignment = 0; 42 | ts1_type.type = FFI_TYPE_STRUCT; 43 | ts1_type.elements = ts1_type_elements; 44 | ts1_type_elements[0] = &ffi_type_uchar; 45 | ts1_type_elements[1] = &ffi_type_double; 46 | ts1_type_elements[2] = &ffi_type_uint; 47 | ts1_type_elements[3] = NULL; 48 | 49 | args[0] = &ts1_type; 50 | values[0] = &ts1_arg; 51 | 52 | /* Initialize the cif */ 53 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, 54 | &ts1_type, args) == FFI_OK); 55 | 56 | ts1_arg.uc = '\x01'; 57 | ts1_arg.d = 3.14159; 58 | ts1_arg.ui = 555; 59 | 60 | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); 61 | 62 | CHECK(ts1_result->ui == 556); 63 | CHECK(ts1_result->d == 3.14159 - 1); 64 | 65 | free (ts1_result); 66 | exit(0); 67 | } 68 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct5.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | typedef struct 10 | { 11 | char c1; 12 | char c2; 13 | } test_structure_5; 14 | 15 | static test_structure_5 ABI_ATTR struct5(test_structure_5 ts1, test_structure_5 ts2) 16 | { 17 | ts1.c1 += ts2.c1; 18 | ts1.c2 -= ts2.c2; 19 | 20 | return ts1; 21 | } 22 | 23 | int main (void) 24 | { 25 | ffi_cif cif; 26 | ffi_type *args[MAX_ARGS]; 27 | void *values[MAX_ARGS]; 28 | ffi_type ts5_type; 29 | ffi_type *ts5_type_elements[3]; 30 | 31 | test_structure_5 ts5_arg1, ts5_arg2; 32 | 33 | /* This is a hack to get a properly aligned result buffer */ 34 | test_structure_5 *ts5_result = 35 | (test_structure_5 *) malloc (sizeof(test_structure_5)); 36 | 37 | ts5_type.size = 0; 38 | ts5_type.alignment = 0; 39 | ts5_type.type = FFI_TYPE_STRUCT; 40 | ts5_type.elements = ts5_type_elements; 41 | ts5_type_elements[0] = &ffi_type_schar; 42 | ts5_type_elements[1] = &ffi_type_schar; 43 | ts5_type_elements[2] = NULL; 44 | 45 | args[0] = &ts5_type; 46 | args[1] = &ts5_type; 47 | values[0] = &ts5_arg1; 48 | values[1] = &ts5_arg2; 49 | 50 | /* Initialize the cif */ 51 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &ts5_type, args) == FFI_OK); 52 | 53 | ts5_arg1.c1 = 2; 54 | ts5_arg1.c2 = 6; 55 | ts5_arg2.c1 = 5; 56 | ts5_arg2.c2 = 3; 57 | 58 | ffi_call (&cif, FFI_FN(struct5), ts5_result, values); 59 | 60 | CHECK(ts5_result->c1 == 7); 61 | CHECK(ts5_result->c2 == 3); 62 | 63 | 64 | free (ts5_result); 65 | exit(0); 66 | } 67 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct9.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct 11 | { 12 | float f; 13 | int i; 14 | } test_structure_9; 15 | 16 | static test_structure_9 ABI_ATTR struct9 (test_structure_9 ts) 17 | { 18 | ts.f += 1; 19 | ts.i += 1; 20 | 21 | return ts; 22 | } 23 | 24 | int main (void) 25 | { 26 | ffi_cif cif; 27 | ffi_type *args[MAX_ARGS]; 28 | void *values[MAX_ARGS]; 29 | ffi_type ts9_type; 30 | ffi_type *ts9_type_elements[3]; 31 | 32 | test_structure_9 ts9_arg; 33 | 34 | /* This is a hack to get a properly aligned result buffer */ 35 | test_structure_9 *ts9_result = 36 | (test_structure_9 *) malloc (sizeof(test_structure_9)); 37 | 38 | ts9_type.size = 0; 39 | ts9_type.alignment = 0; 40 | ts9_type.type = FFI_TYPE_STRUCT; 41 | ts9_type.elements = ts9_type_elements; 42 | ts9_type_elements[0] = &ffi_type_float; 43 | ts9_type_elements[1] = &ffi_type_sint; 44 | ts9_type_elements[2] = NULL; 45 | 46 | args[0] = &ts9_type; 47 | values[0] = &ts9_arg; 48 | 49 | /* Initialize the cif */ 50 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts9_type, args) == FFI_OK); 51 | 52 | ts9_arg.f = 5.55f; 53 | ts9_arg.i = 5; 54 | 55 | printf ("%g\n", ts9_arg.f); 56 | printf ("%d\n", ts9_arg.i); 57 | 58 | ffi_call(&cif, FFI_FN(struct9), ts9_result, values); 59 | 60 | printf ("%g\n", ts9_result->f); 61 | printf ("%d\n", ts9_result->i); 62 | 63 | CHECK(ts9_result->f == 5.55f + 1); 64 | CHECK(ts9_result->i == 5 + 1); 65 | 66 | free (ts9_result); 67 | exit(0); 68 | } 69 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_ulonglong.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value long long. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20030828 */ 6 | 7 | /* { dg-do run } */ 8 | /* { dg-options "-Wno-format" { target alpha*-dec-osf* } } */ 9 | #include "ffitest.h" 10 | 11 | static void cls_ret_ulonglong_fn(ffi_cif* cif __UNUSED__, void* resp, 12 | void** args, void* userdata __UNUSED__) 13 | { 14 | *(unsigned long long *)resp= 0xfffffffffffffffLL ^ *(unsigned long long *)args[0]; 15 | 16 | printf("%" PRIuLL ": %" PRIuLL "\n",*(unsigned long long *)args[0], 17 | *(unsigned long long *)(resp)); 18 | } 19 | typedef unsigned long long (*cls_ret_ulonglong)(unsigned long long); 20 | 21 | int main (void) 22 | { 23 | ffi_cif cif; 24 | void *code; 25 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 26 | ffi_type * cl_arg_types[2]; 27 | unsigned long long res; 28 | 29 | cl_arg_types[0] = &ffi_type_uint64; 30 | cl_arg_types[1] = NULL; 31 | 32 | /* Initialize the cif */ 33 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 34 | &ffi_type_uint64, cl_arg_types) == FFI_OK); 35 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_ulonglong_fn, NULL, code) == FFI_OK); 36 | res = (*((cls_ret_ulonglong)code))(214LL); 37 | /* { dg-output "214: 1152921504606846761" } */ 38 | printf("res: %" PRIdLL "\n", res); 39 | /* { dg-output "\nres: 1152921504606846761" } */ 40 | 41 | res = (*((cls_ret_ulonglong)code))(9223372035854775808LL); 42 | /* { dg-output "\n9223372035854775808: 8070450533247928831" } */ 43 | printf("res: %" PRIdLL "\n", res); 44 | /* { dg-output "\nres: 8070450533247928831" } */ 45 | 46 | exit(0); 47 | } 48 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct 11 | { 12 | double d1; 13 | double d2; 14 | } test_structure_2; 15 | 16 | static test_structure_2 ABI_ATTR struct2(test_structure_2 ts) 17 | { 18 | ts.d1--; 19 | ts.d2--; 20 | 21 | return ts; 22 | } 23 | 24 | int main (void) 25 | { 26 | ffi_cif cif; 27 | ffi_type *args[MAX_ARGS]; 28 | void *values[MAX_ARGS]; 29 | test_structure_2 ts2_arg; 30 | ffi_type ts2_type; 31 | ffi_type *ts2_type_elements[3]; 32 | 33 | /* This is a hack to get a properly aligned result buffer */ 34 | test_structure_2 *ts2_result = 35 | (test_structure_2 *) malloc (sizeof(test_structure_2)); 36 | 37 | ts2_type.size = 0; 38 | ts2_type.alignment = 0; 39 | ts2_type.type = FFI_TYPE_STRUCT; 40 | ts2_type.elements = ts2_type_elements; 41 | ts2_type_elements[0] = &ffi_type_double; 42 | ts2_type_elements[1] = &ffi_type_double; 43 | ts2_type_elements[2] = NULL; 44 | 45 | args[0] = &ts2_type; 46 | values[0] = &ts2_arg; 47 | 48 | /* Initialize the cif */ 49 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts2_type, args) == FFI_OK); 50 | 51 | ts2_arg.d1 = 5.55; 52 | ts2_arg.d2 = 6.66; 53 | 54 | printf ("%g\n", ts2_arg.d1); 55 | printf ("%g\n", ts2_arg.d2); 56 | 57 | ffi_call(&cif, FFI_FN(struct2), ts2_result, values); 58 | 59 | printf ("%g\n", ts2_result->d1); 60 | printf ("%g\n", ts2_result->d2); 61 | 62 | CHECK(ts2_result->d1 == 5.55 - 1); 63 | CHECK(ts2_result->d2 == 6.66 - 1); 64 | 65 | free (ts2_result); 66 | exit(0); 67 | } 68 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/float2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value long double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-excess-errors "fails" { target x86_64-*-mingw* x86_64-*-cygwin* } } */ 8 | /* { dg-do run { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */ 9 | 10 | #include "ffitest.h" 11 | #include "float.h" 12 | 13 | static long double ldblit(float f) 14 | { 15 | return (long double) (((long double) f)/ (long double) 3.0); 16 | } 17 | 18 | int main (void) 19 | { 20 | ffi_cif cif; 21 | ffi_type *args[MAX_ARGS]; 22 | void *values[MAX_ARGS]; 23 | float f; 24 | long double ld; 25 | 26 | args[0] = &ffi_type_float; 27 | values[0] = &f; 28 | 29 | /* Initialize the cif */ 30 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 31 | &ffi_type_longdouble, args) == FFI_OK); 32 | 33 | f = 3.14159; 34 | 35 | #if 1 36 | /* This is ifdef'd out for now. long double support under SunOS/gcc 37 | is pretty much non-existent. You'll get the odd bus error in library 38 | routines like printf(). */ 39 | printf ("%Lf\n", ldblit(f)); 40 | #endif 41 | ld = 666; 42 | ffi_call(&cif, FFI_FN(ldblit), &ld, values); 43 | 44 | #if 1 45 | /* This is ifdef'd out for now. long double support under SunOS/gcc 46 | is pretty much non-existent. You'll get the odd bus error in library 47 | routines like printf(). */ 48 | printf ("%Lf, %Lf, %Lf, %Lf\n", ld, ldblit(f), ld - ldblit(f), LDBL_EPSILON); 49 | #endif 50 | 51 | /* These are not always the same!! Check for a reasonable delta */ 52 | if (ld - ldblit(f) < LDBL_EPSILON) 53 | puts("long double return value tests ok!"); 54 | else 55 | CHECK(0); 56 | 57 | exit(0); 58 | } 59 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/float3.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check float arguments with different orders. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | #include "float.h" 11 | 12 | static double floating_1(float a, double b, long double c) 13 | { 14 | return (double) a + b + (double) c; 15 | } 16 | 17 | static double floating_2(long double a, double b, float c) 18 | { 19 | return (double) a + b + (double) c; 20 | } 21 | 22 | int main (void) 23 | { 24 | ffi_cif cif; 25 | ffi_type *args[MAX_ARGS]; 26 | void *values[MAX_ARGS]; 27 | double rd; 28 | 29 | float f; 30 | double d; 31 | long double ld; 32 | 33 | args[0] = &ffi_type_float; 34 | values[0] = &f; 35 | args[1] = &ffi_type_double; 36 | values[1] = &d; 37 | args[2] = &ffi_type_longdouble; 38 | values[2] = &ld; 39 | 40 | /* Initialize the cif */ 41 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 42 | &ffi_type_double, args) == FFI_OK); 43 | 44 | f = 3.14159; 45 | d = (double)1.0/(double)3.0; 46 | ld = 2.71828182846L; 47 | 48 | floating_1 (f, d, ld); 49 | 50 | ffi_call(&cif, FFI_FN(floating_1), &rd, values); 51 | 52 | CHECK(rd - floating_1(f, d, ld) < DBL_EPSILON); 53 | 54 | args[0] = &ffi_type_longdouble; 55 | values[0] = &ld; 56 | args[1] = &ffi_type_double; 57 | values[1] = &d; 58 | args[2] = &ffi_type_float; 59 | values[2] = &f; 60 | 61 | /* Initialize the cif */ 62 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 63 | &ffi_type_double, args) == FFI_OK); 64 | 65 | floating_2 (ld, d, f); 66 | 67 | ffi_call(&cif, FFI_FN(floating_2), &rd, values); 68 | 69 | CHECK(rd - floating_2(ld, d, f) < DBL_EPSILON); 70 | 71 | exit (0); 72 | } 73 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_double_va.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Test doubles passed in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Blake Chaffin 6/6/2007 */ 6 | 7 | /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ 8 | /* { dg-output "" { xfail avr32*-*-* } } */ 9 | /* { dg-output "" { xfail mips-sgi-irix6* } } PR libffi/46660 */ 10 | 11 | #include "ffitest.h" 12 | 13 | static void 14 | cls_double_va_fn(ffi_cif* cif __UNUSED__, void* resp, 15 | void** args, void* userdata __UNUSED__) 16 | { 17 | char* format = *(char**)args[0]; 18 | double doubleValue = *(double*)args[1]; 19 | 20 | *(ffi_arg*)resp = printf(format, doubleValue); 21 | } 22 | 23 | int main (void) 24 | { 25 | ffi_cif cif; 26 | void *code; 27 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 28 | void* args[3]; 29 | ffi_type* arg_types[3]; 30 | 31 | char* format = "%.1f\n"; 32 | double doubleArg = 7; 33 | ffi_arg res = 0; 34 | 35 | arg_types[0] = &ffi_type_pointer; 36 | arg_types[1] = &ffi_type_double; 37 | arg_types[2] = NULL; 38 | 39 | /* This printf call is variadic */ 40 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, &ffi_type_sint, 41 | arg_types) == FFI_OK); 42 | 43 | args[0] = &format; 44 | args[1] = &doubleArg; 45 | args[2] = NULL; 46 | 47 | ffi_call(&cif, FFI_FN(printf), &res, args); 48 | /* { dg-output "7.0" } */ 49 | printf("res: %d\n", (int) res); 50 | /* { dg-output "\nres: 4" } */ 51 | 52 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, 53 | code) == FFI_OK); 54 | 55 | res = ((int(*)(char*, ...))(code))(format, doubleArg); 56 | /* { dg-output "\n7.0" } */ 57 | printf("res: %d\n", (int) res); 58 | /* { dg-output "\nres: 4" } */ 59 | 60 | exit(0); 61 | } 62 | -------------------------------------------------------------------------------- /libs/libffi/src/bfin/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | ffitarget.h - Copyright (c) 2012 Alexandre K. I. de Mendonca 3 | 4 | Blackfin Foreign Function Interface 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | ----------------------------------------------------------------------- */ 26 | 27 | #ifndef LIBFFI_TARGET_H 28 | #define LIBFFI_TARGET_H 29 | 30 | #ifndef LIBFFI_ASM 31 | typedef unsigned long ffi_arg; 32 | typedef signed long ffi_sarg; 33 | 34 | typedef enum ffi_abi { 35 | FFI_FIRST_ABI = 0, 36 | FFI_SYSV, 37 | FFI_LAST_ABI, 38 | FFI_DEFAULT_ABI = FFI_SYSV 39 | } ffi_abi; 40 | #endif 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_longdouble_va.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Test long doubles passed in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Blake Chaffin 6/6/2007 */ 6 | 7 | /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ 8 | /* { dg-output "" { xfail avr32*-*-* x86_64-*-mingw* } } */ 9 | /* { dg-output "" { xfail mips-sgi-irix6* } } PR libffi/46660 */ 10 | 11 | #include "ffitest.h" 12 | 13 | static void 14 | cls_longdouble_va_fn(ffi_cif* cif __UNUSED__, void* resp, 15 | void** args, void* userdata __UNUSED__) 16 | { 17 | char* format = *(char**)args[0]; 18 | long double ldValue = *(long double*)args[1]; 19 | 20 | *(ffi_arg*)resp = printf(format, ldValue); 21 | } 22 | 23 | int main (void) 24 | { 25 | ffi_cif cif; 26 | void *code; 27 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 28 | void* args[3]; 29 | ffi_type* arg_types[3]; 30 | 31 | char* format = "%.1Lf\n"; 32 | long double ldArg = 7; 33 | ffi_arg res = 0; 34 | 35 | arg_types[0] = &ffi_type_pointer; 36 | arg_types[1] = &ffi_type_longdouble; 37 | arg_types[2] = NULL; 38 | 39 | /* This printf call is variadic */ 40 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, &ffi_type_sint, 41 | arg_types) == FFI_OK); 42 | 43 | args[0] = &format; 44 | args[1] = &ldArg; 45 | args[2] = NULL; 46 | 47 | ffi_call(&cif, FFI_FN(printf), &res, args); 48 | /* { dg-output "7.0" } */ 49 | printf("res: %d\n", (int) res); 50 | /* { dg-output "\nres: 4" } */ 51 | 52 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_longdouble_va_fn, NULL, 53 | code) == FFI_OK); 54 | 55 | res = ((int(*)(char*, ...))(code))(format, ldArg); 56 | /* { dg-output "\n7.0" } */ 57 | printf("res: %d\n", (int) res); 58 | /* { dg-output "\nres: 4" } */ 59 | 60 | exit(0); 61 | } 62 | -------------------------------------------------------------------------------- /libs/libffi/src/m88k/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Miodrag Vallat. 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, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /* 25 | * m88k Foreign Function Interface 26 | */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_ASM 32 | typedef unsigned long ffi_arg; 33 | typedef signed long ffi_sarg; 34 | 35 | typedef enum ffi_abi { 36 | FFI_FIRST_ABI = 0, 37 | FFI_OBSD, 38 | FFI_DEFAULT_ABI = FFI_OBSD, 39 | FFI_LAST_ABI = FFI_DEFAULT_ABI + 1 40 | } ffi_abi; 41 | #endif 42 | 43 | /* ---- Definitions for closures ----------------------------------------- */ 44 | 45 | #define FFI_CLOSURES 1 46 | #define FFI_TRAMPOLINE_SIZE 0x14 47 | #define FFI_NATIVE_RAW_API 0 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /libs/libffi/src/vax/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Miodrag Vallat. 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, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /* 25 | * vax Foreign Function Interface 26 | */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_ASM 32 | typedef unsigned long ffi_arg; 33 | typedef signed long ffi_sarg; 34 | 35 | typedef enum ffi_abi { 36 | FFI_FIRST_ABI = 0, 37 | FFI_ELFBSD, 38 | FFI_DEFAULT_ABI = FFI_ELFBSD, 39 | FFI_LAST_ABI = FFI_DEFAULT_ABI + 1 40 | } ffi_abi; 41 | #endif 42 | 43 | /* ---- Definitions for closures ----------------------------------------- */ 44 | 45 | #define FFI_CLOSURES 1 46 | #define FFI_TRAMPOLINE_SIZE 15 47 | #define FFI_NATIVE_RAW_API 0 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct7.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | typedef struct 10 | { 11 | float f1; 12 | float f2; 13 | double d; 14 | } test_structure_7; 15 | 16 | static test_structure_7 ABI_ATTR struct7 (test_structure_7 ts) 17 | { 18 | ts.f1 += 1; 19 | ts.f2 += 1; 20 | ts.d += 1; 21 | 22 | return ts; 23 | } 24 | 25 | int main (void) 26 | { 27 | ffi_cif cif; 28 | ffi_type *args[MAX_ARGS]; 29 | void *values[MAX_ARGS]; 30 | ffi_type ts7_type; 31 | ffi_type *ts7_type_elements[4]; 32 | 33 | test_structure_7 ts7_arg; 34 | 35 | /* This is a hack to get a properly aligned result buffer */ 36 | test_structure_7 *ts7_result = 37 | (test_structure_7 *) malloc (sizeof(test_structure_7)); 38 | 39 | ts7_type.size = 0; 40 | ts7_type.alignment = 0; 41 | ts7_type.type = FFI_TYPE_STRUCT; 42 | ts7_type.elements = ts7_type_elements; 43 | ts7_type_elements[0] = &ffi_type_float; 44 | ts7_type_elements[1] = &ffi_type_float; 45 | ts7_type_elements[2] = &ffi_type_double; 46 | ts7_type_elements[3] = NULL; 47 | 48 | args[0] = &ts7_type; 49 | values[0] = &ts7_arg; 50 | 51 | /* Initialize the cif */ 52 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts7_type, args) == FFI_OK); 53 | 54 | ts7_arg.f1 = 5.55f; 55 | ts7_arg.f2 = 55.5f; 56 | ts7_arg.d = 6.66; 57 | 58 | printf ("%g\n", ts7_arg.f1); 59 | printf ("%g\n", ts7_arg.f2); 60 | printf ("%g\n", ts7_arg.d); 61 | 62 | ffi_call(&cif, FFI_FN(struct7), ts7_result, values); 63 | 64 | printf ("%g\n", ts7_result->f1); 65 | printf ("%g\n", ts7_result->f2); 66 | printf ("%g\n", ts7_result->d); 67 | 68 | CHECK(ts7_result->f1 == 5.55f + 1); 69 | CHECK(ts7_result->f2 == 55.5f + 1); 70 | CHECK(ts7_result->d == 6.66 + 1); 71 | 72 | free (ts7_result); 73 | exit(0); 74 | } 75 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/testclosure.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value float. 3 | Limitations: none. 4 | PR: 41908. 5 | Originator: 20091102 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct cls_struct_combined { 11 | float a; 12 | float b; 13 | float c; 14 | float d; 15 | } cls_struct_combined; 16 | 17 | void cls_struct_combined_fn(struct cls_struct_combined arg) 18 | { 19 | printf("%g %g %g %g\n", 20 | arg.a, arg.b, 21 | arg.c, arg.d); 22 | fflush(stdout); 23 | } 24 | 25 | static void 26 | cls_struct_combined_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__, 27 | void** args, void* userdata __UNUSED__) 28 | { 29 | struct cls_struct_combined a0; 30 | 31 | a0 = *(struct cls_struct_combined*)(args[0]); 32 | 33 | cls_struct_combined_fn(a0); 34 | } 35 | 36 | 37 | int main (void) 38 | { 39 | ffi_cif cif; 40 | void *code; 41 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 42 | ffi_type* cls_struct_fields0[5]; 43 | ffi_type cls_struct_type0; 44 | ffi_type* dbl_arg_types[5]; 45 | 46 | struct cls_struct_combined g_dbl = {4.0, 5.0, 1.0, 8.0}; 47 | 48 | cls_struct_type0.size = 0; 49 | cls_struct_type0.alignment = 0; 50 | cls_struct_type0.type = FFI_TYPE_STRUCT; 51 | cls_struct_type0.elements = cls_struct_fields0; 52 | 53 | cls_struct_fields0[0] = &ffi_type_float; 54 | cls_struct_fields0[1] = &ffi_type_float; 55 | cls_struct_fields0[2] = &ffi_type_float; 56 | cls_struct_fields0[3] = &ffi_type_float; 57 | cls_struct_fields0[4] = NULL; 58 | 59 | dbl_arg_types[0] = &cls_struct_type0; 60 | dbl_arg_types[1] = NULL; 61 | 62 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_void, 63 | dbl_arg_types) == FFI_OK); 64 | 65 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_combined_gn, NULL, code) == FFI_OK); 66 | 67 | ((void(*)(cls_struct_combined)) (code))(g_dbl); 68 | /* { dg-output "4 5 1 8" } */ 69 | exit(0); 70 | } 71 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_multi_schar.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check passing of multiple signed char values. 3 | Limitations: none. 4 | PR: PR13221. 5 | Originator: 20031129 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | signed char test_func_fn(signed char a1, signed char a2) 11 | { 12 | signed char result; 13 | 14 | result = a1 + a2; 15 | 16 | printf("%d %d: %d\n", a1, a2, result); 17 | 18 | return result; 19 | 20 | } 21 | 22 | static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, 23 | void *data __UNUSED__) 24 | { 25 | signed char a1, a2; 26 | 27 | a1 = *(signed char *)avals[0]; 28 | a2 = *(signed char *)avals[1]; 29 | 30 | *(ffi_arg *)rval = test_func_fn(a1, a2); 31 | 32 | } 33 | 34 | typedef signed char (*test_type)(signed char, signed char); 35 | 36 | int main (void) 37 | { 38 | ffi_cif cif; 39 | void *code; 40 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 41 | void * args_dbl[3]; 42 | ffi_type * cl_arg_types[3]; 43 | ffi_arg res_call; 44 | signed char a, b, res_closure; 45 | 46 | a = 2; 47 | b = 125; 48 | 49 | args_dbl[0] = &a; 50 | args_dbl[1] = &b; 51 | args_dbl[2] = NULL; 52 | 53 | cl_arg_types[0] = &ffi_type_schar; 54 | cl_arg_types[1] = &ffi_type_schar; 55 | cl_arg_types[2] = NULL; 56 | 57 | /* Initialize the cif */ 58 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 59 | &ffi_type_schar, cl_arg_types) == FFI_OK); 60 | 61 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 62 | /* { dg-output "2 125: 127" } */ 63 | printf("res: %d\n", (signed char)res_call); 64 | /* { dg-output "\nres: 127" } */ 65 | 66 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 67 | 68 | res_closure = (*((test_type)code))(2, 125); 69 | /* { dg-output "\n2 125: 127" } */ 70 | printf("res: %d\n", res_closure); 71 | /* { dg-output "\nres: 127" } */ 72 | 73 | exit(0); 74 | } 75 | -------------------------------------------------------------------------------- /libs/libffi/src/nios2/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* libffi target includes for Altera Nios II. 2 | 3 | Copyright (c) 2013 Mentor Graphics. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23 | 24 | 25 | #ifndef LIBFFI_TARGET_H 26 | #define LIBFFI_TARGET_H 27 | 28 | #ifndef LIBFFI_H 29 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 30 | #endif 31 | 32 | #ifndef LIBFFI_ASM 33 | typedef unsigned long ffi_arg; 34 | typedef signed long ffi_sarg; 35 | 36 | typedef enum ffi_abi { 37 | FFI_FIRST_ABI = 0, 38 | FFI_SYSV, 39 | FFI_LAST_ABI, 40 | FFI_DEFAULT_ABI = FFI_SYSV 41 | } ffi_abi; 42 | #endif 43 | 44 | /* Structures have a 4-byte alignment even if all the fields have lesser 45 | alignment requirements. */ 46 | #define FFI_AGGREGATE_ALIGNMENT 4 47 | 48 | #define FFI_CLOSURES 1 49 | #define FFI_TRAMPOLINE_SIZE 28 /* 7 instructions */ 50 | #define FFI_NATIVE_RAW_API 0 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_multi_sshort.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check passing of multiple signed short values. 3 | Limitations: none. 4 | PR: PR13221. 5 | Originator: 20031129 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | signed short test_func_fn(signed short a1, signed short a2) 11 | { 12 | signed short result; 13 | 14 | result = a1 + a2; 15 | 16 | printf("%d %d: %d\n", a1, a2, result); 17 | 18 | return result; 19 | 20 | } 21 | 22 | static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, 23 | void *data __UNUSED__) 24 | { 25 | signed short a1, a2; 26 | 27 | a1 = *(signed short *)avals[0]; 28 | a2 = *(signed short *)avals[1]; 29 | 30 | *(ffi_arg *)rval = test_func_fn(a1, a2); 31 | 32 | } 33 | 34 | typedef signed short (*test_type)(signed short, signed short); 35 | 36 | int main (void) 37 | { 38 | ffi_cif cif; 39 | void *code; 40 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 41 | void * args_dbl[3]; 42 | ffi_type * cl_arg_types[3]; 43 | ffi_arg res_call; 44 | unsigned short a, b, res_closure; 45 | 46 | a = 2; 47 | b = 32765; 48 | 49 | args_dbl[0] = &a; 50 | args_dbl[1] = &b; 51 | args_dbl[2] = NULL; 52 | 53 | cl_arg_types[0] = &ffi_type_sshort; 54 | cl_arg_types[1] = &ffi_type_sshort; 55 | cl_arg_types[2] = NULL; 56 | 57 | /* Initialize the cif */ 58 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 59 | &ffi_type_sshort, cl_arg_types) == FFI_OK); 60 | 61 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 62 | /* { dg-output "2 32765: 32767" } */ 63 | printf("res: %d\n", (unsigned short)res_call); 64 | /* { dg-output "\nres: 32767" } */ 65 | 66 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 67 | 68 | res_closure = (*((test_type)code))(2, 32765); 69 | /* { dg-output "\n2 32765: 32767" } */ 70 | printf("res: %d\n", res_closure); 71 | /* { dg-output "\nres: 32767" } */ 72 | 73 | exit(0); 74 | } 75 | -------------------------------------------------------------------------------- /libs/libffi/src/microblaze/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | ffitarget.h - Copyright (c) 2012, 2013 Xilinx, Inc 3 | 4 | Target configuration macros for MicroBlaze. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | ----------------------------------------------------------------------- */ 26 | 27 | #ifndef LIBFFI_TARGET_H 28 | #define LIBFFI_TARGET_H 29 | 30 | #ifndef LIBFFI_H 31 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 32 | #endif 33 | 34 | #ifndef LIBFFI_ASM 35 | typedef unsigned long ffi_arg; 36 | typedef signed long ffi_sarg; 37 | 38 | typedef enum ffi_abi { 39 | FFI_FIRST_ABI = 0, 40 | FFI_SYSV, 41 | FFI_LAST_ABI, 42 | FFI_DEFAULT_ABI = FFI_SYSV 43 | } ffi_abi; 44 | #endif 45 | 46 | /* Definitions for closures */ 47 | 48 | #define FFI_CLOSURES 1 49 | #define FFI_NATIVE_RAW_API 0 50 | 51 | #define FFI_TRAMPOLINE_SIZE (4*8) 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_multi_ushort.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check passing of multiple unsigned short values. 3 | Limitations: none. 4 | PR: PR13221. 5 | Originator: 20031129 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | unsigned short test_func_fn(unsigned short a1, unsigned short a2) 11 | { 12 | unsigned short result; 13 | 14 | result = a1 + a2; 15 | 16 | printf("%d %d: %d\n", a1, a2, result); 17 | 18 | return result; 19 | 20 | } 21 | 22 | static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, 23 | void *data __UNUSED__) 24 | { 25 | unsigned short a1, a2; 26 | 27 | a1 = *(unsigned short *)avals[0]; 28 | a2 = *(unsigned short *)avals[1]; 29 | 30 | *(ffi_arg *)rval = test_func_fn(a1, a2); 31 | 32 | } 33 | 34 | typedef unsigned short (*test_type)(unsigned short, unsigned short); 35 | 36 | int main (void) 37 | { 38 | ffi_cif cif; 39 | void *code; 40 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 41 | void * args_dbl[3]; 42 | ffi_type * cl_arg_types[3]; 43 | ffi_arg res_call; 44 | unsigned short a, b, res_closure; 45 | 46 | a = 2; 47 | b = 32765; 48 | 49 | args_dbl[0] = &a; 50 | args_dbl[1] = &b; 51 | args_dbl[2] = NULL; 52 | 53 | cl_arg_types[0] = &ffi_type_ushort; 54 | cl_arg_types[1] = &ffi_type_ushort; 55 | cl_arg_types[2] = NULL; 56 | 57 | /* Initialize the cif */ 58 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 59 | &ffi_type_ushort, cl_arg_types) == FFI_OK); 60 | 61 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 62 | /* { dg-output "2 32765: 32767" } */ 63 | printf("res: %d\n", (unsigned short)res_call); 64 | /* { dg-output "\nres: 32767" } */ 65 | 66 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 67 | 68 | res_closure = (*((test_type)code))(2, 32765); 69 | /* { dg-output "\n2 32765: 32767" } */ 70 | printf("res: %d\n", res_closure); 71 | /* { dg-output "\nres: 32767" } */ 72 | 73 | exit(0); 74 | } 75 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/lib/wrapper.exp: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2004, 2007 Free Software Foundation, Inc. 2 | 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with GCC; see the file COPYING3. If not see 15 | # . 16 | 17 | # This file contains GCC-specifics for status wrappers for test programs. 18 | 19 | # ${tool}_maybe_build_wrapper -- Build wrapper object if the target 20 | # needs it. FILENAME is the path to the wrapper file. If there are 21 | # additional arguments, they are command-line options to provide to 22 | # the compiler when compiling FILENAME. 23 | 24 | proc ${tool}_maybe_build_wrapper { filename args } { 25 | global gluefile wrap_flags 26 | 27 | if { [target_info needs_status_wrapper] != "" \ 28 | && [target_info needs_status_wrapper] != "0" \ 29 | && ![info exists gluefile] } { 30 | set saved_wrap_compile_flags [target_info wrap_compile_flags] 31 | set flags [join $args " "] 32 | # The wrapper code may contain code that gcc objects on. This 33 | # became true for dejagnu-1.4.4. The set of warnings and code 34 | # that gcc objects on may change, so just make sure -w is always 35 | # passed to turn off all warnings. 36 | set_currtarget_info wrap_compile_flags \ 37 | "$saved_wrap_compile_flags -w $flags" 38 | set result [build_wrapper $filename] 39 | set_currtarget_info wrap_compile_flags "$saved_wrap_compile_flags" 40 | if { $result != "" } { 41 | set gluefile [lindex $result 0] 42 | set wrap_flags [lindex $result 1] 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /libs/libffi/src/ia64/ia64_flags.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | ia64_flags.h - Copyright (c) 2000 Hewlett Packard Company 3 | 4 | IA64/unix Foreign Function Interface 5 | 6 | Original author: Hans Boehm, HP Labs 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the 10 | ``Software''), to deal in the Software without restriction, including 11 | without limitation the rights to use, copy, modify, merge, publish, 12 | distribute, sublicense, and/or sell copies of the Software, and to 13 | permit persons to whom the Software is furnished to do so, subject to 14 | the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included 17 | in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | ----------------------------------------------------------------------- */ 28 | 29 | /* "Type" codes used between assembly and C. When used as a part of 30 | a cfi->flags value, the low byte will be these extra type codes, 31 | and bits 8-31 will be the actual size of the type. */ 32 | 33 | /* Small structures containing N words in integer registers. */ 34 | #define FFI_IA64_TYPE_SMALL_STRUCT (FFI_TYPE_LAST + 1) 35 | 36 | /* Homogeneous Floating Point Aggregates (HFAs) which are returned 37 | in FP registers. */ 38 | #define FFI_IA64_TYPE_HFA_FLOAT (FFI_TYPE_LAST + 2) 39 | #define FFI_IA64_TYPE_HFA_DOUBLE (FFI_TYPE_LAST + 3) 40 | #define FFI_IA64_TYPE_HFA_LDOUBLE (FFI_TYPE_LAST + 4) 41 | -------------------------------------------------------------------------------- /libs/libffi/src/xtensa/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2013 Tensilica, Inc. 3 | Target configuration macros for XTENSA. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | ----------------------------------------------------------------------- */ 25 | 26 | #ifndef LIBFFI_TARGET_H 27 | #define LIBFFI_TARGET_H 28 | 29 | #ifndef LIBFFI_H 30 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 31 | #endif 32 | 33 | #ifndef LIBFFI_ASM 34 | typedef unsigned long ffi_arg; 35 | typedef signed long ffi_sarg; 36 | 37 | typedef enum ffi_abi { 38 | FFI_FIRST_ABI = 0, 39 | FFI_SYSV, 40 | FFI_LAST_ABI, 41 | FFI_DEFAULT_ABI = FFI_SYSV 42 | } ffi_abi; 43 | #endif 44 | 45 | #define FFI_REGISTER_NARGS 6 46 | 47 | /* ---- Definitions for closures ----------------------------------------- */ 48 | 49 | #define FFI_CLOSURES 1 50 | #define FFI_NATIVE_RAW_API 0 51 | #define FFI_TRAMPOLINE_SIZE 24 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libs/libffi/src/metag/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2013 Imagination Technologies Ltd. 3 | Target configuration macros for Meta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | 25 | ----------------------------------------------------------------------- */ 26 | 27 | #ifndef LIBFFI_TARGET_H 28 | #define LIBFFI_TARGET_H 29 | 30 | #ifndef LIBFFI_H 31 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 32 | #endif 33 | 34 | #ifndef LIBFFI_ASM 35 | typedef unsigned long ffi_arg; 36 | typedef signed long ffi_sarg; 37 | 38 | typedef enum ffi_abi { 39 | FFI_FIRST_ABI = 0, 40 | FFI_SYSV, 41 | FFI_DEFAULT_ABI = FFI_SYSV, 42 | FFI_LAST_ABI = FFI_DEFAULT_ABI + 1, 43 | } ffi_abi; 44 | #endif 45 | 46 | /* ---- Definitions for closures ----------------------------------------- */ 47 | 48 | #define FFI_CLOSURES 1 49 | #define FFI_TRAMPOLINE_SIZE 48 50 | #define FFI_NATIVE_RAW_API 0 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /libs/libffi/src/arc/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 2013 Synopsys, Inc. (www.synopsys.com) 4 | Target configuration macros for ARC. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 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 RENESAS TECHNOLOGY 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. 24 | 25 | ----------------------------------------------------------------------- */ 26 | 27 | #ifndef LIBFFI_TARGET_H 28 | #define LIBFFI_TARGET_H 29 | 30 | #ifndef LIBFFI_H 31 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 32 | #endif 33 | 34 | /* ---- Generic type definitions ----------------------------------------- */ 35 | 36 | #ifndef LIBFFI_ASM 37 | typedef unsigned long ffi_arg; 38 | typedef signed long ffi_sarg; 39 | 40 | typedef enum ffi_abi 41 | { 42 | FFI_FIRST_ABI = 0, 43 | FFI_ARCOMPACT, 44 | FFI_LAST_ABI, 45 | FFI_DEFAULT_ABI = FFI_ARCOMPACT 46 | } ffi_abi; 47 | #endif 48 | 49 | #define FFI_CLOSURES 1 50 | #define FFI_TRAMPOLINE_SIZE 12 51 | #define FFI_NATIVE_RAW_API 0 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libs/libffi/src/alpha/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for Alpha. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | #ifndef LIBFFI_ASM 36 | typedef unsigned long ffi_arg; 37 | typedef signed long ffi_sarg; 38 | 39 | typedef enum ffi_abi { 40 | FFI_FIRST_ABI = 0, 41 | FFI_OSF, 42 | FFI_LAST_ABI, 43 | FFI_DEFAULT_ABI = FFI_OSF 44 | } ffi_abi; 45 | #endif 46 | 47 | /* ---- Definitions for closures ----------------------------------------- */ 48 | 49 | #define FFI_CLOSURES 1 50 | #define FFI_TRAMPOLINE_SIZE 24 51 | #define FFI_NATIVE_RAW_API 0 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libs/libffi/src/m32r/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 2004 Renesas Technology. 4 | Target configuration macros for M32R. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 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 RENESAS TECHNOLOGY 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. 24 | 25 | ----------------------------------------------------------------------- */ 26 | 27 | #ifndef LIBFFI_TARGET_H 28 | #define LIBFFI_TARGET_H 29 | 30 | #ifndef LIBFFI_H 31 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 32 | #endif 33 | 34 | /* ---- Generic type definitions ----------------------------------------- */ 35 | 36 | #ifndef LIBFFI_ASM 37 | typedef unsigned long ffi_arg; 38 | typedef signed long ffi_sarg; 39 | 40 | typedef enum ffi_abi 41 | { 42 | FFI_FIRST_ABI = 0, 43 | FFI_SYSV, 44 | FFI_LAST_ABI, 45 | FFI_DEFAULT_ABI = FFI_SYSV 46 | } ffi_abi; 47 | #endif 48 | 49 | #define FFI_CLOSURES 0 50 | #define FFI_TRAMPOLINE_SIZE 24 51 | #define FFI_NATIVE_RAW_API 0 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libs/libffi/src/moxie/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012, 2013 Anthony Green 3 | Target configuration macros for Moxie 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | 25 | ----------------------------------------------------------------------- */ 26 | 27 | #ifndef LIBFFI_TARGET_H 28 | #define LIBFFI_TARGET_H 29 | 30 | /* ---- System specific configurations ----------------------------------- */ 31 | 32 | #ifndef LIBFFI_ASM 33 | typedef unsigned long ffi_arg; 34 | typedef signed long ffi_sarg; 35 | 36 | typedef enum ffi_abi { 37 | FFI_FIRST_ABI = 0, 38 | FFI_EABI, 39 | FFI_DEFAULT_ABI = FFI_EABI, 40 | FFI_LAST_ABI = FFI_DEFAULT_ABI + 1 41 | } ffi_abi; 42 | #endif 43 | 44 | /* ---- Definitions for closures ----------------------------------------- */ 45 | 46 | #define FFI_CLOSURES 1 47 | #define FFI_NATIVE_RAW_API 0 48 | 49 | /* Trampolines are 12-bytes long. See ffi_prep_closure_loc. */ 50 | #define FFI_TRAMPOLINE_SIZE (12) 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /libs/libffi/src/sh/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for SuperH. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | /* ---- Generic type definitions ----------------------------------------- */ 36 | 37 | #ifndef LIBFFI_ASM 38 | typedef unsigned long ffi_arg; 39 | typedef signed long ffi_sarg; 40 | 41 | typedef enum ffi_abi { 42 | FFI_FIRST_ABI = 0, 43 | FFI_SYSV, 44 | FFI_LAST_ABI, 45 | FFI_DEFAULT_ABI = FFI_SYSV 46 | } ffi_abi; 47 | #endif 48 | 49 | #define FFI_CLOSURES 1 50 | #define FFI_TRAMPOLINE_SIZE 16 51 | #define FFI_NATIVE_RAW_API 0 52 | 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /libs/libffi/src/m68k/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for Motorola 68K. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | #ifndef LIBFFI_ASM 36 | typedef unsigned long ffi_arg; 37 | typedef signed long ffi_sarg; 38 | 39 | typedef enum ffi_abi { 40 | FFI_FIRST_ABI = 0, 41 | FFI_SYSV, 42 | FFI_LAST_ABI, 43 | FFI_DEFAULT_ABI = FFI_SYSV 44 | } ffi_abi; 45 | #endif 46 | 47 | /* ---- Definitions for closures ----------------------------------------- */ 48 | 49 | #define FFI_CLOSURES 1 50 | #define FFI_TRAMPOLINE_SIZE 16 51 | #define FFI_NATIVE_RAW_API 0 52 | 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/struct8.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: From the original ffitest.c */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | typedef struct 10 | { 11 | float f1; 12 | float f2; 13 | float f3; 14 | float f4; 15 | } test_structure_8; 16 | 17 | static test_structure_8 ABI_ATTR struct8 (test_structure_8 ts) 18 | { 19 | ts.f1 += 1; 20 | ts.f2 += 1; 21 | ts.f3 += 1; 22 | ts.f4 += 1; 23 | 24 | return ts; 25 | } 26 | 27 | int main (void) 28 | { 29 | ffi_cif cif; 30 | ffi_type *args[MAX_ARGS]; 31 | void *values[MAX_ARGS]; 32 | ffi_type ts8_type; 33 | ffi_type *ts8_type_elements[5]; 34 | 35 | test_structure_8 ts8_arg; 36 | 37 | /* This is a hack to get a properly aligned result buffer */ 38 | test_structure_8 *ts8_result = 39 | (test_structure_8 *) malloc (sizeof(test_structure_8)); 40 | 41 | ts8_type.size = 0; 42 | ts8_type.alignment = 0; 43 | ts8_type.type = FFI_TYPE_STRUCT; 44 | ts8_type.elements = ts8_type_elements; 45 | ts8_type_elements[0] = &ffi_type_float; 46 | ts8_type_elements[1] = &ffi_type_float; 47 | ts8_type_elements[2] = &ffi_type_float; 48 | ts8_type_elements[3] = &ffi_type_float; 49 | ts8_type_elements[4] = NULL; 50 | 51 | args[0] = &ts8_type; 52 | values[0] = &ts8_arg; 53 | 54 | /* Initialize the cif */ 55 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts8_type, args) == FFI_OK); 56 | 57 | ts8_arg.f1 = 5.55f; 58 | ts8_arg.f2 = 55.5f; 59 | ts8_arg.f3 = -5.55f; 60 | ts8_arg.f4 = -55.5f; 61 | 62 | printf ("%g\n", ts8_arg.f1); 63 | printf ("%g\n", ts8_arg.f2); 64 | printf ("%g\n", ts8_arg.f3); 65 | printf ("%g\n", ts8_arg.f4); 66 | 67 | ffi_call(&cif, FFI_FN(struct8), ts8_result, values); 68 | 69 | printf ("%g\n", ts8_result->f1); 70 | printf ("%g\n", ts8_result->f2); 71 | printf ("%g\n", ts8_result->f3); 72 | printf ("%g\n", ts8_result->f4); 73 | 74 | CHECK(ts8_result->f1 == 5.55f + 1); 75 | CHECK(ts8_result->f2 == 55.5f + 1); 76 | CHECK(ts8_result->f3 == -5.55f + 1); 77 | CHECK(ts8_result->f4 == -55.5f + 1); 78 | 79 | free (ts8_result); 80 | exit(0); 81 | } 82 | -------------------------------------------------------------------------------- /libs/libffi/src/avr32/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 2009 Bradley Smith 4 | Target configuration macros for AVR32. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | #ifndef LIBFFI_ASM 36 | typedef unsigned long ffi_arg; 37 | typedef signed long ffi_sarg; 38 | 39 | typedef enum ffi_abi { 40 | FFI_FIRST_ABI = 0, 41 | FFI_SYSV, 42 | FFI_LAST_ABI, 43 | FFI_DEFAULT_ABI = FFI_SYSV 44 | } ffi_abi; 45 | #endif 46 | 47 | #define FFI_EXTRA_CIF_FIELDS unsigned int rstruct_flag 48 | 49 | /* Definitions for closures */ 50 | 51 | #define FFI_CLOSURES 1 52 | #define FFI_TRAMPOLINE_SIZE 36 53 | #define FFI_NATIVE_RAW_API 0 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_pointer.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check pointer arguments. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Blake Chaffin 6/6/2007 */ 6 | 7 | /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ 8 | #include "ffitest.h" 9 | 10 | void* cls_pointer_fn(void* a1, void* a2) 11 | { 12 | void* result = (void*)((intptr_t)a1 + (intptr_t)a2); 13 | 14 | printf("0x%08x 0x%08x: 0x%08x\n", 15 | (unsigned int)(uintptr_t) a1, 16 | (unsigned int)(uintptr_t) a2, 17 | (unsigned int)(uintptr_t) result); 18 | 19 | return result; 20 | } 21 | 22 | static void 23 | cls_pointer_gn(ffi_cif* cif __UNUSED__, void* resp, 24 | void** args, void* userdata __UNUSED__) 25 | { 26 | void* a1 = *(void**)(args[0]); 27 | void* a2 = *(void**)(args[1]); 28 | 29 | *(void**)resp = cls_pointer_fn(a1, a2); 30 | } 31 | 32 | int main (void) 33 | { 34 | ffi_cif cif; 35 | void *code; 36 | ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 37 | void* args[3]; 38 | /* ffi_type cls_pointer_type; */ 39 | ffi_type* arg_types[3]; 40 | 41 | /* cls_pointer_type.size = sizeof(void*); 42 | cls_pointer_type.alignment = 0; 43 | cls_pointer_type.type = FFI_TYPE_POINTER; 44 | cls_pointer_type.elements = NULL;*/ 45 | 46 | void* arg1 = (void*)0x12345678; 47 | void* arg2 = (void*)0x89abcdef; 48 | ffi_arg res = 0; 49 | 50 | arg_types[0] = &ffi_type_pointer; 51 | arg_types[1] = &ffi_type_pointer; 52 | arg_types[2] = NULL; 53 | 54 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer, 55 | arg_types) == FFI_OK); 56 | 57 | args[0] = &arg1; 58 | args[1] = &arg2; 59 | args[2] = NULL; 60 | 61 | ffi_call(&cif, FFI_FN(cls_pointer_fn), &res, args); 62 | /* { dg-output "0x12345678 0x89abcdef: 0x9be02467" } */ 63 | printf("res: 0x%08x\n", (unsigned int) res); 64 | /* { dg-output "\nres: 0x9be02467" } */ 65 | 66 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK); 67 | 68 | res = (ffi_arg)(uintptr_t)((void*(*)(void*, void*))(code))(arg1, arg2); 69 | /* { dg-output "\n0x12345678 0x89abcdef: 0x9be02467" } */ 70 | printf("res: 0x%08x\n", (unsigned int) res); 71 | /* { dg-output "\nres: 0x9be02467" } */ 72 | 73 | exit(0); 74 | } 75 | -------------------------------------------------------------------------------- /libs/libffi/src/aarch64/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | ``Software''), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 21 | 22 | #ifndef LIBFFI_TARGET_H 23 | #define LIBFFI_TARGET_H 24 | 25 | #ifndef LIBFFI_H 26 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 27 | #endif 28 | 29 | #ifndef LIBFFI_ASM 30 | typedef unsigned long ffi_arg; 31 | typedef signed long ffi_sarg; 32 | 33 | typedef enum ffi_abi 34 | { 35 | FFI_FIRST_ABI = 0, 36 | FFI_SYSV, 37 | FFI_LAST_ABI, 38 | FFI_DEFAULT_ABI = FFI_SYSV 39 | } ffi_abi; 40 | #endif 41 | 42 | /* ---- Definitions for closures ----------------------------------------- */ 43 | 44 | #define FFI_CLOSURES 1 45 | #define FFI_TRAMPOLINE_SIZE 36 46 | #define FFI_NATIVE_RAW_API 0 47 | 48 | /* ---- Internal ---- */ 49 | 50 | #if defined (__APPLE__) 51 | #define FFI_TARGET_SPECIFIC_VARIADIC 52 | #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_flags; unsigned aarch64_nfixedargs 53 | #else 54 | #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_flags 55 | #endif 56 | 57 | #define AARCH64_FFI_WITH_V_BIT 0 58 | 59 | #define AARCH64_N_XREG 32 60 | #define AARCH64_N_VREG 32 61 | #define AARCH64_CALL_CONTEXT_SIZE (AARCH64_N_XREG * 8 + AARCH64_N_VREG * 16) 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /libs/libffi/src/sh64/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for SuperH - SHmedia. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | /* ---- Generic type definitions ----------------------------------------- */ 36 | 37 | #ifndef LIBFFI_ASM 38 | typedef unsigned long ffi_arg; 39 | typedef signed long ffi_sarg; 40 | 41 | typedef enum ffi_abi { 42 | FFI_FIRST_ABI = 0, 43 | FFI_SYSV, 44 | FFI_LAST_ABI, 45 | FFI_DEFAULT_ABI = FFI_SYSV 46 | } ffi_abi; 47 | 48 | #define FFI_EXTRA_CIF_FIELDS long long flags2 49 | #endif 50 | 51 | /* ---- Definitions for closures ----------------------------------------- */ 52 | 53 | #define FFI_CLOSURES 1 54 | #define FFI_TRAMPOLINE_SIZE 32 55 | #define FFI_NATIVE_RAW_API 0 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /libs/libffi/src/ia64/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for IA-64. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | #ifndef LIBFFI_ASM 36 | typedef unsigned long long ffi_arg; 37 | typedef signed long long ffi_sarg; 38 | 39 | typedef enum ffi_abi { 40 | FFI_FIRST_ABI = 0, 41 | FFI_UNIX, /* Linux and all Unix variants use the same conventions */ 42 | FFI_LAST_ABI, 43 | FFI_DEFAULT_ABI = FFI_UNIX 44 | } ffi_abi; 45 | #endif 46 | 47 | /* ---- Definitions for closures ----------------------------------------- */ 48 | 49 | #define FFI_CLOSURES 1 50 | #define FFI_TRAMPOLINE_SIZE 24 /* Really the following struct, which */ 51 | /* can be interpreted as a C function */ 52 | /* descriptor: */ 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /libs/libffi/src/cris/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for CRIS. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | #ifndef LIBFFI_ASM 36 | typedef unsigned long ffi_arg; 37 | typedef signed long ffi_sarg; 38 | 39 | typedef enum ffi_abi { 40 | FFI_FIRST_ABI = 0, 41 | FFI_SYSV, 42 | FFI_LAST_ABI, 43 | FFI_DEFAULT_ABI = FFI_SYSV 44 | } ffi_abi; 45 | #endif 46 | 47 | /* ---- Definitions for closures ----------------------------------------- */ 48 | 49 | #define FFI_CLOSURES 1 50 | #define FFI_CRIS_TRAMPOLINE_CODE_PART_SIZE 36 51 | #define FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE (7*4) 52 | #define FFI_TRAMPOLINE_SIZE \ 53 | (FFI_CRIS_TRAMPOLINE_CODE_PART_SIZE + FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE) 54 | #define FFI_NATIVE_RAW_API 0 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /libs/libffi/src/s390/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for S390. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | #if defined (__s390x__) 36 | #ifndef S390X 37 | #define S390X 38 | #endif 39 | #endif 40 | 41 | /* ---- System specific configurations ----------------------------------- */ 42 | 43 | #ifndef LIBFFI_ASM 44 | typedef unsigned long ffi_arg; 45 | typedef signed long ffi_sarg; 46 | 47 | typedef enum ffi_abi { 48 | FFI_FIRST_ABI = 0, 49 | FFI_SYSV, 50 | FFI_LAST_ABI, 51 | FFI_DEFAULT_ABI = FFI_SYSV 52 | } ffi_abi; 53 | #endif 54 | 55 | 56 | /* ---- Definitions for closures ----------------------------------------- */ 57 | 58 | #define FFI_CLOSURES 1 59 | #ifdef S390X 60 | #define FFI_TRAMPOLINE_SIZE 32 61 | #else 62 | #define FFI_TRAMPOLINE_SIZE 16 63 | #endif 64 | #define FFI_NATIVE_RAW_API 0 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /libs/libffi/src/frv/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2004 Red Hat, Inc. 4 | Target configuration macros for FR-V 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | /* ---- System specific configurations ----------------------------------- */ 36 | 37 | #ifndef LIBFFI_ASM 38 | typedef unsigned long ffi_arg; 39 | typedef signed long ffi_sarg; 40 | 41 | typedef enum ffi_abi { 42 | FFI_FIRST_ABI = 0, 43 | FFI_EABI, 44 | FFI_LAST_ABI, 45 | FFI_DEFAULT_ABI = FFI_EABI 46 | } ffi_abi; 47 | #endif 48 | 49 | /* ---- Definitions for closures ----------------------------------------- */ 50 | 51 | #define FFI_CLOSURES 1 52 | #define FFI_NATIVE_RAW_API 0 53 | 54 | #ifdef __FRV_FDPIC__ 55 | /* Trampolines are 8 4-byte instructions long. */ 56 | #define FFI_TRAMPOLINE_SIZE (8*4) 57 | #else 58 | /* Trampolines are 5 4-byte instructions long. */ 59 | #define FFI_TRAMPOLINE_SIZE (5*4) 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /libs/libffi/src/tile/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Tilera Corp. 3 | Target configuration macros for TILE. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | ``Software''), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | ----------------------------------------------------------------------- */ 25 | 26 | #ifndef LIBFFI_TARGET_H 27 | #define LIBFFI_TARGET_H 28 | 29 | #ifndef LIBFFI_H 30 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 31 | #endif 32 | 33 | #ifndef LIBFFI_ASM 34 | 35 | #include 36 | 37 | typedef uint_reg_t ffi_arg; 38 | typedef int_reg_t ffi_sarg; 39 | 40 | typedef enum ffi_abi { 41 | FFI_FIRST_ABI = 0, 42 | FFI_UNIX, 43 | FFI_LAST_ABI, 44 | FFI_DEFAULT_ABI = FFI_UNIX 45 | } ffi_abi; 46 | #endif 47 | 48 | /* ---- Definitions for closures ----------------------------------------- */ 49 | #define FFI_CLOSURES 1 50 | 51 | #ifdef __tilegx__ 52 | /* We always pass 8-byte values, even in -m32 mode. */ 53 | # define FFI_SIZEOF_ARG 8 54 | # ifdef __LP64__ 55 | # define FFI_TRAMPOLINE_SIZE (8 * 5) /* 5 bundles */ 56 | # else 57 | # define FFI_TRAMPOLINE_SIZE (8 * 3) /* 3 bundles */ 58 | # endif 59 | #else 60 | # define FFI_SIZEOF_ARG 4 61 | # define FFI_TRAMPOLINE_SIZE 8 /* 1 bundle */ 62 | #endif 63 | #define FFI_NATIVE_RAW_API 0 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_multi_sshortchar.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check passing of multiple signed short/char values. 3 | Limitations: none. 4 | PR: PR13221. 5 | Originator: 20031129 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | signed short test_func_fn(signed char a1, signed short a2, 11 | signed char a3, signed short a4) 12 | { 13 | signed short result; 14 | 15 | result = a1 + a2 + a3 + a4; 16 | 17 | printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result); 18 | 19 | return result; 20 | 21 | } 22 | 23 | static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, 24 | void *data __UNUSED__) 25 | { 26 | signed char a1, a3; 27 | signed short a2, a4; 28 | 29 | a1 = *(signed char *)avals[0]; 30 | a2 = *(signed short *)avals[1]; 31 | a3 = *(signed char *)avals[2]; 32 | a4 = *(signed short *)avals[3]; 33 | 34 | *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4); 35 | 36 | } 37 | 38 | typedef signed short (*test_type)(signed char, signed short, 39 | signed char, signed short); 40 | 41 | int main (void) 42 | { 43 | ffi_cif cif; 44 | void *code; 45 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 46 | void * args_dbl[5]; 47 | ffi_type * cl_arg_types[5]; 48 | ffi_arg res_call; 49 | signed char a, c; 50 | signed short b, d, res_closure; 51 | 52 | a = 1; 53 | b = 32765; 54 | c = 127; 55 | d = -128; 56 | 57 | args_dbl[0] = &a; 58 | args_dbl[1] = &b; 59 | args_dbl[2] = &c; 60 | args_dbl[3] = &d; 61 | args_dbl[4] = NULL; 62 | 63 | cl_arg_types[0] = &ffi_type_schar; 64 | cl_arg_types[1] = &ffi_type_sshort; 65 | cl_arg_types[2] = &ffi_type_schar; 66 | cl_arg_types[3] = &ffi_type_sshort; 67 | cl_arg_types[4] = NULL; 68 | 69 | /* Initialize the cif */ 70 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 71 | &ffi_type_sshort, cl_arg_types) == FFI_OK); 72 | 73 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 74 | /* { dg-output "1 32765 127 -128: 32765" } */ 75 | printf("res: %d\n", (signed short)res_call); 76 | /* { dg-output "\nres: 32765" } */ 77 | 78 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 79 | 80 | res_closure = (*((test_type)code))(1, 32765, 127, -128); 81 | /* { dg-output "\n1 32765 127 -128: 32765" } */ 82 | printf("res: %d\n", res_closure); 83 | /* { dg-output "\nres: 32765" } */ 84 | 85 | exit(0); 86 | } 87 | -------------------------------------------------------------------------------- /libs/libffi/src/debug.c: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | debug.c - Copyright (c) 1996 Red Hat, Inc. 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, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | ----------------------------------------------------------------------- */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /* General debugging routines */ 31 | 32 | void ffi_stop_here(void) 33 | { 34 | /* This function is only useful for debugging purposes. 35 | Place a breakpoint on ffi_stop_here to be notified of 36 | significant events. */ 37 | } 38 | 39 | /* This function should only be called via the FFI_ASSERT() macro */ 40 | 41 | void ffi_assert(char *expr, char *file, int line) 42 | { 43 | fprintf(stderr, "ASSERTION FAILURE: %s at %s:%d\n", expr, file, line); 44 | ffi_stop_here(); 45 | abort(); 46 | } 47 | 48 | /* Perform a sanity check on an ffi_type structure */ 49 | 50 | void ffi_type_test(ffi_type *a, char *file, int line) 51 | { 52 | FFI_ASSERT_AT(a != NULL, file, line); 53 | 54 | FFI_ASSERT_AT(a->type <= FFI_TYPE_LAST, file, line); 55 | FFI_ASSERT_AT(a->type == FFI_TYPE_VOID || a->size > 0, file, line); 56 | FFI_ASSERT_AT(a->type == FFI_TYPE_VOID || a->alignment > 0, file, line); 57 | FFI_ASSERT_AT(a->type != FFI_TYPE_STRUCT || a->elements != NULL, file, line); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_multi_ushortchar.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check passing of multiple unsigned short/char values. 3 | Limitations: none. 4 | PR: PR13221. 5 | Originator: 20031129 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | unsigned short test_func_fn(unsigned char a1, unsigned short a2, 11 | unsigned char a3, unsigned short a4) 12 | { 13 | unsigned short result; 14 | 15 | result = a1 + a2 + a3 + a4; 16 | 17 | printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result); 18 | 19 | return result; 20 | 21 | } 22 | 23 | static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, 24 | void *data __UNUSED__) 25 | { 26 | unsigned char a1, a3; 27 | unsigned short a2, a4; 28 | 29 | a1 = *(unsigned char *)avals[0]; 30 | a2 = *(unsigned short *)avals[1]; 31 | a3 = *(unsigned char *)avals[2]; 32 | a4 = *(unsigned short *)avals[3]; 33 | 34 | *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4); 35 | 36 | } 37 | 38 | typedef unsigned short (*test_type)(unsigned char, unsigned short, 39 | unsigned char, unsigned short); 40 | 41 | int main (void) 42 | { 43 | ffi_cif cif; 44 | void *code; 45 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 46 | void * args_dbl[5]; 47 | ffi_type * cl_arg_types[5]; 48 | ffi_arg res_call; 49 | unsigned char a, c; 50 | unsigned short b, d, res_closure; 51 | 52 | a = 1; 53 | b = 2; 54 | c = 127; 55 | d = 128; 56 | 57 | args_dbl[0] = &a; 58 | args_dbl[1] = &b; 59 | args_dbl[2] = &c; 60 | args_dbl[3] = &d; 61 | args_dbl[4] = NULL; 62 | 63 | cl_arg_types[0] = &ffi_type_uchar; 64 | cl_arg_types[1] = &ffi_type_ushort; 65 | cl_arg_types[2] = &ffi_type_uchar; 66 | cl_arg_types[3] = &ffi_type_ushort; 67 | cl_arg_types[4] = NULL; 68 | 69 | /* Initialize the cif */ 70 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 71 | &ffi_type_ushort, cl_arg_types) == FFI_OK); 72 | 73 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 74 | /* { dg-output "1 2 127 128: 258" } */ 75 | printf("res: %d\n", (unsigned short)res_call); 76 | /* { dg-output "\nres: 258" } */ 77 | 78 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 79 | 80 | res_closure = (*((test_type)code))(1, 2, 127, 128); 81 | /* { dg-output "\n1 2 127 128: 258" } */ 82 | printf("res: %d\n", res_closure); 83 | /* { dg-output "\nres: 258" } */ 84 | 85 | exit(0); 86 | } 87 | -------------------------------------------------------------------------------- /libs/libffi/src/sparc/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for SPARC. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | /* ---- System specific configurations ----------------------------------- */ 36 | 37 | #if defined(__arch64__) || defined(__sparcv9) 38 | #ifndef SPARC64 39 | #define SPARC64 40 | #endif 41 | #endif 42 | 43 | #ifndef LIBFFI_ASM 44 | typedef unsigned long ffi_arg; 45 | typedef signed long ffi_sarg; 46 | 47 | typedef enum ffi_abi { 48 | FFI_FIRST_ABI = 0, 49 | FFI_V8, 50 | FFI_V8PLUS, 51 | FFI_V9, 52 | FFI_LAST_ABI, 53 | #ifdef SPARC64 54 | FFI_DEFAULT_ABI = FFI_V9 55 | #else 56 | FFI_DEFAULT_ABI = FFI_V8 57 | #endif 58 | } ffi_abi; 59 | #endif 60 | 61 | /* ---- Definitions for closures ----------------------------------------- */ 62 | 63 | #define FFI_CLOSURES 1 64 | #define FFI_NATIVE_RAW_API 0 65 | 66 | #ifdef SPARC64 67 | #define FFI_TRAMPOLINE_SIZE 24 68 | #else 69 | #define FFI_TRAMPOLINE_SIZE 16 70 | #endif 71 | 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /libs/libffi/src/arm/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 2010 CodeSourcery 4 | Copyright (c) 1996-2003 Red Hat, Inc. 5 | 6 | Target configuration macros for ARM. 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the 10 | ``Software''), to deal in the Software without restriction, including 11 | without limitation the rights to use, copy, modify, merge, publish, 12 | distribute, sublicense, and/or sell copies of the Software, and to 13 | permit persons to whom the Software is furnished to do so, subject to 14 | the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included 17 | in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | 28 | ----------------------------------------------------------------------- */ 29 | 30 | #ifndef LIBFFI_TARGET_H 31 | #define LIBFFI_TARGET_H 32 | 33 | #ifndef LIBFFI_H 34 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 35 | #endif 36 | 37 | #ifndef LIBFFI_ASM 38 | typedef unsigned long ffi_arg; 39 | typedef signed long ffi_sarg; 40 | 41 | typedef enum ffi_abi { 42 | FFI_FIRST_ABI = 0, 43 | FFI_SYSV, 44 | FFI_VFP, 45 | FFI_LAST_ABI, 46 | #ifdef __ARM_PCS_VFP 47 | FFI_DEFAULT_ABI = FFI_VFP, 48 | #else 49 | FFI_DEFAULT_ABI = FFI_SYSV, 50 | #endif 51 | } ffi_abi; 52 | #endif 53 | 54 | #define FFI_EXTRA_CIF_FIELDS \ 55 | int vfp_used; \ 56 | short vfp_reg_free, vfp_nargs; \ 57 | signed char vfp_args[16] \ 58 | 59 | /* Internally used. */ 60 | #define FFI_TYPE_STRUCT_VFP_FLOAT (FFI_TYPE_LAST + 1) 61 | #define FFI_TYPE_STRUCT_VFP_DOUBLE (FFI_TYPE_LAST + 2) 62 | 63 | #define FFI_TARGET_SPECIFIC_VARIADIC 64 | 65 | /* ---- Definitions for closures ----------------------------------------- */ 66 | 67 | #define FFI_CLOSURES 1 68 | #define FFI_TRAMPOLINE_SIZE 20 69 | #define FFI_NATIVE_RAW_API 0 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_multi_uchar.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check passing of multiple unsigned char values. 3 | Limitations: none. 4 | PR: PR13221. 5 | Originator: 20031129 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | unsigned char test_func_fn(unsigned char a1, unsigned char a2, 11 | unsigned char a3, unsigned char a4) 12 | { 13 | unsigned char result; 14 | 15 | result = a1 + a2 + a3 + a4; 16 | 17 | printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result); 18 | 19 | return result; 20 | 21 | } 22 | 23 | static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, 24 | void *data __UNUSED__) 25 | { 26 | unsigned char a1, a2, a3, a4; 27 | 28 | a1 = *(unsigned char *)avals[0]; 29 | a2 = *(unsigned char *)avals[1]; 30 | a3 = *(unsigned char *)avals[2]; 31 | a4 = *(unsigned char *)avals[3]; 32 | 33 | *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4); 34 | 35 | } 36 | 37 | typedef unsigned char (*test_type)(unsigned char, unsigned char, 38 | unsigned char, unsigned char); 39 | 40 | void test_func(ffi_cif *cif __UNUSED__, void *rval __UNUSED__, void **avals, 41 | void *data __UNUSED__) 42 | { 43 | printf("%d %d %d %d\n", *(unsigned char *)avals[0], 44 | *(unsigned char *)avals[1], *(unsigned char *)avals[2], 45 | *(unsigned char *)avals[3]); 46 | } 47 | int main (void) 48 | { 49 | ffi_cif cif; 50 | void *code; 51 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 52 | void * args_dbl[5]; 53 | ffi_type * cl_arg_types[5]; 54 | ffi_arg res_call; 55 | unsigned char a, b, c, d, res_closure; 56 | 57 | a = 1; 58 | b = 2; 59 | c = 127; 60 | d = 125; 61 | 62 | args_dbl[0] = &a; 63 | args_dbl[1] = &b; 64 | args_dbl[2] = &c; 65 | args_dbl[3] = &d; 66 | args_dbl[4] = NULL; 67 | 68 | cl_arg_types[0] = &ffi_type_uchar; 69 | cl_arg_types[1] = &ffi_type_uchar; 70 | cl_arg_types[2] = &ffi_type_uchar; 71 | cl_arg_types[3] = &ffi_type_uchar; 72 | cl_arg_types[4] = NULL; 73 | 74 | /* Initialize the cif */ 75 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 76 | &ffi_type_uchar, cl_arg_types) == FFI_OK); 77 | 78 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 79 | /* { dg-output "1 2 127 125: 255" } */ 80 | printf("res: %d\n", (unsigned char)res_call); 81 | /* { dg-output "\nres: 255" } */ 82 | 83 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 84 | 85 | res_closure = (*((test_type)code))(1, 2, 127, 125); 86 | /* { dg-output "\n1 2 127 125: 255" } */ 87 | printf("res: %d\n", res_closure); 88 | /* { dg-output "\nres: 255" } */ 89 | 90 | exit(0); 91 | } 92 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_1_1byte.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Especially with small structures which may fit in one 4 | register. Depending on the ABI. 5 | Limitations: none. 6 | PR: none. 7 | Originator: 20030902 */ 8 | 9 | 10 | 11 | /* { dg-do run } */ 12 | #include "ffitest.h" 13 | 14 | typedef struct cls_struct_1_1byte { 15 | unsigned char a; 16 | } cls_struct_1_1byte; 17 | 18 | cls_struct_1_1byte cls_struct_1_1byte_fn(struct cls_struct_1_1byte a1, 19 | struct cls_struct_1_1byte a2) 20 | { 21 | struct cls_struct_1_1byte result; 22 | 23 | result.a = a1.a + a2.a; 24 | 25 | printf("%d %d: %d\n", a1.a, a2.a, result.a); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_1_1byte_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_1_1byte a1, a2; 36 | 37 | a1 = *(struct cls_struct_1_1byte*)(args[0]); 38 | a2 = *(struct cls_struct_1_1byte*)(args[1]); 39 | 40 | *(cls_struct_1_1byte*)resp = cls_struct_1_1byte_fn(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[2]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_1_1byte g_dbl = { 12 }; 54 | struct cls_struct_1_1byte f_dbl = { 178 }; 55 | struct cls_struct_1_1byte res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_uchar; 63 | cls_struct_fields[1] = NULL; 64 | 65 | dbl_arg_types[0] = &cls_struct_type; 66 | dbl_arg_types[1] = &cls_struct_type; 67 | dbl_arg_types[2] = NULL; 68 | 69 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 70 | dbl_arg_types) == FFI_OK); 71 | 72 | args_dbl[0] = &g_dbl; 73 | args_dbl[1] = &f_dbl; 74 | args_dbl[2] = NULL; 75 | 76 | ffi_call(&cif, FFI_FN(cls_struct_1_1byte_fn), &res_dbl, args_dbl); 77 | /* { dg-output "12 178: 190" } */ 78 | printf("res: %d\n", res_dbl.a); 79 | /* { dg-output "\nres: 190" } */ 80 | 81 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_1_1byte_gn, NULL, code) == FFI_OK); 82 | 83 | res_dbl = ((cls_struct_1_1byte(*)(cls_struct_1_1byte, cls_struct_1_1byte))(code))(g_dbl, f_dbl); 84 | /* { dg-output "\n12 178: 190" } */ 85 | printf("res: %d\n", res_dbl.a); 86 | /* { dg-output "\nres: 190" } */ 87 | 88 | exit(0); 89 | } 90 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/problem1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20030828 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct my_ffi_struct { 11 | double a; 12 | double b; 13 | double c; 14 | } my_ffi_struct; 15 | 16 | my_ffi_struct callee(struct my_ffi_struct a1, struct my_ffi_struct a2) 17 | { 18 | struct my_ffi_struct result; 19 | result.a = a1.a + a2.a; 20 | result.b = a1.b + a2.b; 21 | result.c = a1.c + a2.c; 22 | 23 | 24 | printf("%g %g %g %g %g %g: %g %g %g\n", a1.a, a1.b, a1.c, 25 | a2.a, a2.b, a2.c, result.a, result.b, result.c); 26 | 27 | return result; 28 | } 29 | 30 | void stub(ffi_cif* cif __UNUSED__, void* resp, void** args, 31 | void* userdata __UNUSED__) 32 | { 33 | struct my_ffi_struct a1; 34 | struct my_ffi_struct a2; 35 | 36 | a1 = *(struct my_ffi_struct*)(args[0]); 37 | a2 = *(struct my_ffi_struct*)(args[1]); 38 | 39 | *(my_ffi_struct *)resp = callee(a1, a2); 40 | } 41 | 42 | 43 | int main(void) 44 | { 45 | ffi_type* my_ffi_struct_fields[4]; 46 | ffi_type my_ffi_struct_type; 47 | ffi_cif cif; 48 | void *code; 49 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 50 | void* args[4]; 51 | ffi_type* arg_types[3]; 52 | 53 | struct my_ffi_struct g = { 1.0, 2.0, 3.0 }; 54 | struct my_ffi_struct f = { 1.0, 2.0, 3.0 }; 55 | struct my_ffi_struct res; 56 | 57 | my_ffi_struct_type.size = 0; 58 | my_ffi_struct_type.alignment = 0; 59 | my_ffi_struct_type.type = FFI_TYPE_STRUCT; 60 | my_ffi_struct_type.elements = my_ffi_struct_fields; 61 | 62 | my_ffi_struct_fields[0] = &ffi_type_double; 63 | my_ffi_struct_fields[1] = &ffi_type_double; 64 | my_ffi_struct_fields[2] = &ffi_type_double; 65 | my_ffi_struct_fields[3] = NULL; 66 | 67 | arg_types[0] = &my_ffi_struct_type; 68 | arg_types[1] = &my_ffi_struct_type; 69 | arg_types[2] = NULL; 70 | 71 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &my_ffi_struct_type, 72 | arg_types) == FFI_OK); 73 | 74 | args[0] = &g; 75 | args[1] = &f; 76 | args[2] = NULL; 77 | ffi_call(&cif, FFI_FN(callee), &res, args); 78 | /* { dg-output "1 2 3 1 2 3: 2 4 6" } */ 79 | printf("res: %g %g %g\n", res.a, res.b, res.c); 80 | /* { dg-output "\nres: 2 4 6" } */ 81 | 82 | CHECK(ffi_prep_closure_loc(pcl, &cif, stub, NULL, code) == FFI_OK); 83 | 84 | res = ((my_ffi_struct(*)(struct my_ffi_struct, struct my_ffi_struct))(code))(g, f); 85 | /* { dg-output "\n1 2 3 1 2 3: 2 4 6" } */ 86 | printf("res: %g %g %g\n", res.a, res.b, res.c); 87 | /* { dg-output "\nres: 2 4 6" } */ 88 | 89 | exit(0);; 90 | } 91 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_8byte.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Depending on the ABI. Check overlapping. 4 | Limitations: none. 5 | PR: none. 6 | Originator: 20030828 */ 7 | 8 | /* { dg-do run } */ 9 | #include "ffitest.h" 10 | 11 | typedef struct cls_struct_8byte { 12 | int a; 13 | float b; 14 | } cls_struct_8byte; 15 | 16 | cls_struct_8byte cls_struct_8byte_fn(struct cls_struct_8byte a1, 17 | struct cls_struct_8byte a2) 18 | { 19 | struct cls_struct_8byte result; 20 | 21 | result.a = a1.a + a2.a; 22 | result.b = a1.b + a2.b; 23 | 24 | printf("%d %g %d %g: %d %g\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); 25 | 26 | return result; 27 | } 28 | 29 | static void 30 | cls_struct_8byte_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 31 | void* userdata __UNUSED__) 32 | { 33 | 34 | struct cls_struct_8byte a1, a2; 35 | 36 | a1 = *(struct cls_struct_8byte*)(args[0]); 37 | a2 = *(struct cls_struct_8byte*)(args[1]); 38 | 39 | *(cls_struct_8byte*)resp = cls_struct_8byte_fn(a1, a2); 40 | } 41 | 42 | int main (void) 43 | { 44 | ffi_cif cif; 45 | void *code; 46 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 47 | void* args_dbl[5]; 48 | ffi_type* cls_struct_fields[4]; 49 | ffi_type cls_struct_type; 50 | ffi_type* dbl_arg_types[5]; 51 | 52 | struct cls_struct_8byte g_dbl = { 1, 2.0 }; 53 | struct cls_struct_8byte f_dbl = { 4, 5.0 }; 54 | struct cls_struct_8byte res_dbl; 55 | 56 | cls_struct_type.size = 0; 57 | cls_struct_type.alignment = 0; 58 | cls_struct_type.type = FFI_TYPE_STRUCT; 59 | cls_struct_type.elements = cls_struct_fields; 60 | 61 | cls_struct_fields[0] = &ffi_type_sint; 62 | cls_struct_fields[1] = &ffi_type_float; 63 | cls_struct_fields[2] = NULL; 64 | 65 | dbl_arg_types[0] = &cls_struct_type; 66 | dbl_arg_types[1] = &cls_struct_type; 67 | dbl_arg_types[2] = NULL; 68 | 69 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 70 | dbl_arg_types) == FFI_OK); 71 | 72 | args_dbl[0] = &g_dbl; 73 | args_dbl[1] = &f_dbl; 74 | args_dbl[2] = NULL; 75 | 76 | ffi_call(&cif, FFI_FN(cls_struct_8byte_fn), &res_dbl, args_dbl); 77 | /* { dg-output "1 2 4 5: 5 7" } */ 78 | printf("res: %d %g\n", res_dbl.a, res_dbl.b); 79 | /* { dg-output "\nres: 5 7" } */ 80 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_8byte_gn, NULL, code) == FFI_OK); 81 | 82 | res_dbl = ((cls_struct_8byte(*)(cls_struct_8byte, cls_struct_8byte))(code))(g_dbl, f_dbl); 83 | /* { dg-output "\n1 2 4 5: 5 7" } */ 84 | printf("res: %d %g\n", res_dbl.a, res_dbl.b); 85 | /* { dg-output "\nres: 5 7" } */ 86 | 87 | exit(0); 88 | } 89 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_4byte.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Depending on the ABI. Check overlapping. 4 | Limitations: none. 5 | PR: none. 6 | Originator: 20030828 */ 7 | 8 | /* { dg-do run } */ 9 | 10 | #include "ffitest.h" 11 | 12 | typedef struct cls_struct_4byte { 13 | unsigned short a; 14 | unsigned short b; 15 | } cls_struct_4byte; 16 | 17 | cls_struct_4byte cls_struct_4byte_fn(struct cls_struct_4byte a1, 18 | struct cls_struct_4byte a2) 19 | { 20 | struct cls_struct_4byte result; 21 | 22 | result.a = a1.a + a2.a; 23 | result.b = a1.b + a2.b; 24 | 25 | printf("%d %d %d %d: %d %d\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_4byte_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_4byte a1, a2; 36 | 37 | a1 = *(struct cls_struct_4byte*)(args[0]); 38 | a2 = *(struct cls_struct_4byte*)(args[1]); 39 | 40 | *(cls_struct_4byte*)resp = cls_struct_4byte_fn(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[4]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_4byte g_dbl = { 127, 120 }; 54 | struct cls_struct_4byte f_dbl = { 12, 128 }; 55 | struct cls_struct_4byte res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_ushort; 63 | cls_struct_fields[1] = &ffi_type_ushort; 64 | cls_struct_fields[2] = NULL; 65 | 66 | dbl_arg_types[0] = &cls_struct_type; 67 | dbl_arg_types[1] = &cls_struct_type; 68 | dbl_arg_types[2] = NULL; 69 | 70 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 71 | dbl_arg_types) == FFI_OK); 72 | 73 | args_dbl[0] = &g_dbl; 74 | args_dbl[1] = &f_dbl; 75 | args_dbl[2] = NULL; 76 | 77 | ffi_call(&cif, FFI_FN(cls_struct_4byte_fn), &res_dbl, args_dbl); 78 | /* { dg-output "127 120 12 128: 139 248" } */ 79 | printf("res: %d %d\n", res_dbl.a, res_dbl.b); 80 | /* { dg-output "\nres: 139 248" } */ 81 | 82 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_4byte_gn, NULL, code) == FFI_OK); 83 | 84 | res_dbl = ((cls_struct_4byte(*)(cls_struct_4byte, cls_struct_4byte))(code))(g_dbl, f_dbl); 85 | /* { dg-output "\n127 120 12 128: 139 248" } */ 86 | printf("res: %d %d\n", res_dbl.a, res_dbl.b); 87 | /* { dg-output "\nres: 139 248" } */ 88 | 89 | exit(0); 90 | } 91 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_2byte.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Especially with small structures which may fit in one 4 | register. Depending on the ABI. 5 | Limitations: none. 6 | PR: none. 7 | Originator: 20030828 */ 8 | 9 | /* { dg-do run } */ 10 | #include "ffitest.h" 11 | 12 | typedef struct cls_struct_2byte { 13 | unsigned char a; 14 | unsigned char b; 15 | } cls_struct_2byte; 16 | 17 | cls_struct_2byte cls_struct_2byte_fn(struct cls_struct_2byte a1, 18 | struct cls_struct_2byte a2) 19 | { 20 | struct cls_struct_2byte result; 21 | 22 | result.a = a1.a + a2.a; 23 | result.b = a1.b + a2.b; 24 | 25 | printf("%d %d %d %d: %d %d\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_2byte_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_2byte a1, a2; 36 | 37 | a1 = *(struct cls_struct_2byte*)(args[0]); 38 | a2 = *(struct cls_struct_2byte*)(args[1]); 39 | 40 | *(cls_struct_2byte*)resp = cls_struct_2byte_fn(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[4]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_2byte g_dbl = { 12, 127 }; 54 | struct cls_struct_2byte f_dbl = { 1, 13 }; 55 | struct cls_struct_2byte res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_uchar; 63 | cls_struct_fields[1] = &ffi_type_uchar; 64 | cls_struct_fields[2] = NULL; 65 | 66 | dbl_arg_types[0] = &cls_struct_type; 67 | dbl_arg_types[1] = &cls_struct_type; 68 | dbl_arg_types[2] = NULL; 69 | 70 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 71 | dbl_arg_types) == FFI_OK); 72 | 73 | args_dbl[0] = &g_dbl; 74 | args_dbl[1] = &f_dbl; 75 | args_dbl[2] = NULL; 76 | 77 | ffi_call(&cif, FFI_FN(cls_struct_2byte_fn), &res_dbl, args_dbl); 78 | /* { dg-output "12 127 1 13: 13 140" } */ 79 | printf("res: %d %d\n", res_dbl.a, res_dbl.b); 80 | /* { dg-output "\nres: 13 140" } */ 81 | 82 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_2byte_gn, NULL, code) == FFI_OK); 83 | 84 | res_dbl = ((cls_struct_2byte(*)(cls_struct_2byte, cls_struct_2byte))(code))(g_dbl, f_dbl); 85 | /* { dg-output "\n12 127 1 13: 13 140" } */ 86 | printf("res: %d %d\n", res_dbl.a, res_dbl.b); 87 | /* { dg-output "\nres: 13 140" } */ 88 | 89 | exit(0); 90 | } 91 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_9byte1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Depending on the ABI. Darwin/AIX do double-word 4 | alignment of the struct if the first element is a double. 5 | Check that it does not here. 6 | Limitations: none. 7 | PR: none. 8 | Originator: 20030914 */ 9 | 10 | /* { dg-do run } */ 11 | #include "ffitest.h" 12 | 13 | typedef struct cls_struct_9byte { 14 | int a; 15 | double b; 16 | } cls_struct_9byte; 17 | 18 | cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1, 19 | struct cls_struct_9byte b2) 20 | { 21 | struct cls_struct_9byte result; 22 | 23 | result.a = b1.a + b2.a; 24 | result.b = b1.b + b2.b; 25 | 26 | printf("%d %g %d %g: %d %g\n", b1.a, b1.b, b2.a, b2.b, 27 | result.a, result.b); 28 | 29 | return result; 30 | } 31 | 32 | static void cls_struct_9byte_gn(ffi_cif* cif __UNUSED__, void* resp, 33 | void** args, void* userdata __UNUSED__) 34 | { 35 | struct cls_struct_9byte b1, b2; 36 | 37 | b1 = *(struct cls_struct_9byte*)(args[0]); 38 | b2 = *(struct cls_struct_9byte*)(args[1]); 39 | 40 | *(cls_struct_9byte*)resp = cls_struct_9byte_fn(b1, b2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[3]; 49 | ffi_type* cls_struct_fields[3]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[3]; 52 | 53 | struct cls_struct_9byte h_dbl = { 7, 8.0}; 54 | struct cls_struct_9byte j_dbl = { 1, 9.0}; 55 | struct cls_struct_9byte res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_sint; 63 | cls_struct_fields[1] = &ffi_type_double; 64 | cls_struct_fields[2] = NULL; 65 | 66 | dbl_arg_types[0] = &cls_struct_type; 67 | dbl_arg_types[1] = &cls_struct_type; 68 | dbl_arg_types[2] = NULL; 69 | 70 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 71 | dbl_arg_types) == FFI_OK); 72 | 73 | args_dbl[0] = &h_dbl; 74 | args_dbl[1] = &j_dbl; 75 | args_dbl[2] = NULL; 76 | 77 | ffi_call(&cif, FFI_FN(cls_struct_9byte_fn), &res_dbl, args_dbl); 78 | /* { dg-output "7 8 1 9: 8 17" } */ 79 | printf("res: %d %g\n", res_dbl.a, res_dbl.b); 80 | /* { dg-output "\nres: 8 17" } */ 81 | 82 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_9byte_gn, NULL, code) == FFI_OK); 83 | 84 | res_dbl = ((cls_struct_9byte(*)(cls_struct_9byte, cls_struct_9byte))(code))(h_dbl, j_dbl); 85 | /* { dg-output "\n7 8 1 9: 8 17" } */ 86 | printf("res: %d %g\n", res_dbl.a, res_dbl.b); 87 | /* { dg-output "\nres: 8 17" } */ 88 | 89 | exit(0); 90 | } 91 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_9byte2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Depending on the ABI. Darwin/AIX do double-word 4 | alignment of the struct if the first element is a double. 5 | Check that it does here. 6 | Limitations: none. 7 | PR: none. 8 | Originator: 20030914 */ 9 | 10 | /* { dg-do run } */ 11 | #include "ffitest.h" 12 | 13 | typedef struct cls_struct_9byte { 14 | double a; 15 | int b; 16 | } cls_struct_9byte; 17 | 18 | cls_struct_9byte cls_struct_9byte_fn(struct cls_struct_9byte b1, 19 | struct cls_struct_9byte b2) 20 | { 21 | struct cls_struct_9byte result; 22 | 23 | result.a = b1.a + b2.a; 24 | result.b = b1.b + b2.b; 25 | 26 | printf("%g %d %g %d: %g %d\n", b1.a, b1.b, b2.a, b2.b, 27 | result.a, result.b); 28 | 29 | return result; 30 | } 31 | 32 | static void cls_struct_9byte_gn(ffi_cif* cif __UNUSED__, void* resp, 33 | void** args, void* userdata __UNUSED__) 34 | { 35 | struct cls_struct_9byte b1, b2; 36 | 37 | b1 = *(struct cls_struct_9byte*)(args[0]); 38 | b2 = *(struct cls_struct_9byte*)(args[1]); 39 | 40 | *(cls_struct_9byte*)resp = cls_struct_9byte_fn(b1, b2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[3]; 49 | ffi_type* cls_struct_fields[3]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[3]; 52 | 53 | struct cls_struct_9byte h_dbl = { 7.0, 8}; 54 | struct cls_struct_9byte j_dbl = { 1.0, 9}; 55 | struct cls_struct_9byte res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_double; 63 | cls_struct_fields[1] = &ffi_type_sint; 64 | cls_struct_fields[2] = NULL; 65 | 66 | dbl_arg_types[0] = &cls_struct_type; 67 | dbl_arg_types[1] = &cls_struct_type; 68 | dbl_arg_types[2] = NULL; 69 | 70 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 71 | dbl_arg_types) == FFI_OK); 72 | 73 | args_dbl[0] = &h_dbl; 74 | args_dbl[1] = &j_dbl; 75 | args_dbl[2] = NULL; 76 | 77 | ffi_call(&cif, FFI_FN(cls_struct_9byte_fn), &res_dbl, args_dbl); 78 | /* { dg-output "7 8 1 9: 8 17" } */ 79 | printf("res: %g %d\n", res_dbl.a, res_dbl.b); 80 | /* { dg-output "\nres: 8 17" } */ 81 | 82 | 83 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_9byte_gn, NULL, code) == FFI_OK); 84 | 85 | res_dbl = ((cls_struct_9byte(*)(cls_struct_9byte, cls_struct_9byte))(code))(h_dbl, j_dbl); 86 | /* { dg-output "\n7 8 1 9: 8 17" } */ 87 | printf("res: %g %d\n", res_dbl.a, res_dbl.b); 88 | /* { dg-output "\nres: 8 17" } */ 89 | 90 | exit(0); 91 | } 92 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_3byte1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Especially with small structures which may fit in one 4 | register. Depending on the ABI. Check overlapping. 5 | Limitations: none. 6 | PR: none. 7 | Originator: 20030828 */ 8 | 9 | /* { dg-do run } */ 10 | #include "ffitest.h" 11 | 12 | typedef struct cls_struct_3byte { 13 | unsigned short a; 14 | unsigned char b; 15 | } cls_struct_3byte; 16 | 17 | cls_struct_3byte cls_struct_3byte_fn(struct cls_struct_3byte a1, 18 | struct cls_struct_3byte a2) 19 | { 20 | struct cls_struct_3byte result; 21 | 22 | result.a = a1.a + a2.a; 23 | result.b = a1.b + a2.b; 24 | 25 | printf("%d %d %d %d: %d %d\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_3byte_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_3byte a1, a2; 36 | 37 | a1 = *(struct cls_struct_3byte*)(args[0]); 38 | a2 = *(struct cls_struct_3byte*)(args[1]); 39 | 40 | *(cls_struct_3byte*)resp = cls_struct_3byte_fn(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[4]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_3byte g_dbl = { 12, 119 }; 54 | struct cls_struct_3byte f_dbl = { 1, 15 }; 55 | struct cls_struct_3byte res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_ushort; 63 | cls_struct_fields[1] = &ffi_type_uchar; 64 | cls_struct_fields[2] = NULL; 65 | 66 | dbl_arg_types[0] = &cls_struct_type; 67 | dbl_arg_types[1] = &cls_struct_type; 68 | dbl_arg_types[2] = NULL; 69 | 70 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 71 | dbl_arg_types) == FFI_OK); 72 | 73 | args_dbl[0] = &g_dbl; 74 | args_dbl[1] = &f_dbl; 75 | args_dbl[2] = NULL; 76 | 77 | ffi_call(&cif, FFI_FN(cls_struct_3byte_fn), &res_dbl, args_dbl); 78 | /* { dg-output "12 119 1 15: 13 134" } */ 79 | printf("res: %d %d\n", res_dbl.a, res_dbl.b); 80 | /* { dg-output "\nres: 13 134" } */ 81 | 82 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_3byte_gn, NULL, code) == FFI_OK); 83 | 84 | res_dbl = ((cls_struct_3byte(*)(cls_struct_3byte, cls_struct_3byte))(code))(g_dbl, f_dbl); 85 | /* { dg-output "\n12 119 1 15: 13 134" } */ 86 | printf("res: %d %d\n", res_dbl.a, res_dbl.b); 87 | /* { dg-output "\nres: 13 134" } */ 88 | 89 | exit(0); 90 | } 91 | -------------------------------------------------------------------------------- /libs/libffi/man/ffi_call.3: -------------------------------------------------------------------------------- 1 | .Dd February 15, 2008 2 | .Dt ffi_call 3 3 | .Sh NAME 4 | .Nm ffi_call 5 | .Nd Invoke a foreign function. 6 | .Sh SYNOPSIS 7 | .In ffi.h 8 | .Ft void 9 | .Fo ffi_call 10 | .Fa "ffi_cif *cif" 11 | .Fa "void (*fn)(void)" 12 | .Fa "void *rvalue" 13 | .Fa "void **avalue" 14 | .Fc 15 | .Sh DESCRIPTION 16 | The 17 | .Nm ffi_call 18 | function provides a simple mechanism for invoking a function without 19 | requiring knowledge of the function's interface at compile time. 20 | .Fa fn 21 | is called with the values retrieved from the pointers in the 22 | .Fa avalue 23 | array. The return value from 24 | .Fa fn 25 | is placed in storage pointed to by 26 | .Fa rvalue . 27 | .Fa cif 28 | contains information describing the data types, sizes and alignments of the 29 | arguments to and return value from 30 | .Fa fn , 31 | and must be initialized with 32 | .Nm ffi_prep_cif 33 | before it is used with 34 | .Nm ffi_call . 35 | .Pp 36 | .Fa rvalue 37 | must point to storage that is sizeof(ffi_arg) or larger for non-floating point 38 | types. For smaller-sized return value types, the 39 | .Nm ffi_arg 40 | or 41 | .Nm ffi_sarg 42 | integral type must be used to hold 43 | the return value. 44 | .Sh EXAMPLES 45 | .Bd -literal 46 | #include 47 | #include 48 | 49 | unsigned char 50 | foo(unsigned int, float); 51 | 52 | int 53 | main(int argc, const char **argv) 54 | { 55 | ffi_cif cif; 56 | ffi_type *arg_types[2]; 57 | void *arg_values[2]; 58 | ffi_status status; 59 | 60 | // Because the return value from foo() is smaller than sizeof(long), it 61 | // must be passed as ffi_arg or ffi_sarg. 62 | ffi_arg result; 63 | 64 | // Specify the data type of each argument. Available types are defined 65 | // in . 66 | arg_types[0] = &ffi_type_uint; 67 | arg_types[1] = &ffi_type_float; 68 | 69 | // Prepare the ffi_cif structure. 70 | if ((status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 71 | 2, &ffi_type_uint8, arg_types)) != FFI_OK) 72 | { 73 | // Handle the ffi_status error. 74 | } 75 | 76 | // Specify the values of each argument. 77 | unsigned int arg1 = 42; 78 | float arg2 = 5.1; 79 | 80 | arg_values[0] = &arg1; 81 | arg_values[1] = &arg2; 82 | 83 | // Invoke the function. 84 | ffi_call(&cif, FFI_FN(foo), &result, arg_values); 85 | 86 | // The ffi_arg 'result' now contains the unsigned char returned from foo(), 87 | // which can be accessed by a typecast. 88 | printf("result is %hhu", (unsigned char)result); 89 | 90 | return 0; 91 | } 92 | 93 | // The target function. 94 | unsigned char 95 | foo(unsigned int x, float y) 96 | { 97 | unsigned char result = x - y; 98 | return result; 99 | } 100 | .Ed 101 | .Sh SEE ALSO 102 | .Xr ffi 3 , 103 | .Xr ffi_prep_cif 3 104 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_3byte2.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure passing with different structure size. 3 | Especially with small structures which may fit in one 4 | register. Depending on the ABI. Check overlapping. 5 | Limitations: none. 6 | PR: none. 7 | Originator: 20030828 */ 8 | 9 | /* { dg-do run } */ 10 | #include "ffitest.h" 11 | 12 | typedef struct cls_struct_3byte_1 { 13 | unsigned char a; 14 | unsigned short b; 15 | } cls_struct_3byte_1; 16 | 17 | cls_struct_3byte_1 cls_struct_3byte_fn1(struct cls_struct_3byte_1 a1, 18 | struct cls_struct_3byte_1 a2) 19 | { 20 | struct cls_struct_3byte_1 result; 21 | 22 | result.a = a1.a + a2.a; 23 | result.b = a1.b + a2.b; 24 | 25 | printf("%d %d %d %d: %d %d\n", a1.a, a1.b, a2.a, a2.b, result.a, result.b); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_3byte_gn1(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_3byte_1 a1, a2; 36 | 37 | a1 = *(struct cls_struct_3byte_1*)(args[0]); 38 | a2 = *(struct cls_struct_3byte_1*)(args[1]); 39 | 40 | *(cls_struct_3byte_1*)resp = cls_struct_3byte_fn1(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[4]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_3byte_1 g_dbl = { 15, 125 }; 54 | struct cls_struct_3byte_1 f_dbl = { 9, 19 }; 55 | struct cls_struct_3byte_1 res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_uchar; 63 | cls_struct_fields[1] = &ffi_type_ushort; 64 | cls_struct_fields[2] = NULL; 65 | 66 | dbl_arg_types[0] = &cls_struct_type; 67 | dbl_arg_types[1] = &cls_struct_type; 68 | dbl_arg_types[2] = NULL; 69 | 70 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 71 | dbl_arg_types) == FFI_OK); 72 | 73 | args_dbl[0] = &g_dbl; 74 | args_dbl[1] = &f_dbl; 75 | args_dbl[2] = NULL; 76 | 77 | ffi_call(&cif, FFI_FN(cls_struct_3byte_fn1), &res_dbl, args_dbl); 78 | /* { dg-output "15 125 9 19: 24 144" } */ 79 | printf("res: %d %d\n", res_dbl.a, res_dbl.b); 80 | /* { dg-output "\nres: 24 144" } */ 81 | 82 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_3byte_gn1, NULL, code) == FFI_OK); 83 | 84 | res_dbl = ((cls_struct_3byte_1(*)(cls_struct_3byte_1, cls_struct_3byte_1))(code))(g_dbl, f_dbl); 85 | /* { dg-output "\n15 125 9 19: 24 144" } */ 86 | printf("res: %d %d\n", res_dbl.a, res_dbl.b); 87 | /* { dg-output "\nres: 24 144" } */ 88 | 89 | exit(0); 90 | } 91 | -------------------------------------------------------------------------------- /libs/libffi/src/pa/ffitarget.h: -------------------------------------------------------------------------------- 1 | /* -----------------------------------------------------------------*-C-*- 2 | ffitarget.h - Copyright (c) 2012 Anthony Green 3 | Copyright (c) 1996-2003 Red Hat, Inc. 4 | Target configuration macros for hppa. 5 | 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: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | 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 OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | 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 OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | ----------------------------------------------------------------------- */ 27 | 28 | #ifndef LIBFFI_TARGET_H 29 | #define LIBFFI_TARGET_H 30 | 31 | #ifndef LIBFFI_H 32 | #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead." 33 | #endif 34 | 35 | /* ---- System specific configurations ----------------------------------- */ 36 | 37 | #ifndef LIBFFI_ASM 38 | typedef unsigned long ffi_arg; 39 | typedef signed long ffi_sarg; 40 | 41 | typedef enum ffi_abi { 42 | FFI_FIRST_ABI = 0, 43 | 44 | #ifdef PA_LINUX 45 | FFI_PA32, 46 | FFI_LAST_ABI, 47 | FFI_DEFAULT_ABI = FFI_PA32 48 | #endif 49 | 50 | #ifdef PA_HPUX 51 | FFI_PA32, 52 | FFI_LAST_ABI, 53 | FFI_DEFAULT_ABI = FFI_PA32 54 | #endif 55 | 56 | #ifdef PA64_HPUX 57 | #error "PA64_HPUX FFI is not yet implemented" 58 | FFI_PA64, 59 | FFI_LAST_ABI, 60 | FFI_DEFAULT_ABI = FFI_PA64 61 | #endif 62 | } ffi_abi; 63 | #endif 64 | 65 | /* ---- Definitions for closures ----------------------------------------- */ 66 | 67 | #define FFI_CLOSURES 1 68 | #define FFI_NATIVE_RAW_API 0 69 | 70 | #ifdef PA_LINUX 71 | #define FFI_TRAMPOLINE_SIZE 32 72 | #else 73 | #define FFI_TRAMPOLINE_SIZE 40 74 | #endif 75 | 76 | #define FFI_TYPE_SMALL_STRUCT2 -1 77 | #define FFI_TYPE_SMALL_STRUCT3 -2 78 | #define FFI_TYPE_SMALL_STRUCT4 -3 79 | #define FFI_TYPE_SMALL_STRUCT5 -4 80 | #define FFI_TYPE_SMALL_STRUCT6 -5 81 | #define FFI_TYPE_SMALL_STRUCT7 -6 82 | #define FFI_TYPE_SMALL_STRUCT8 -7 83 | #endif 84 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/va_struct1.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Test passing struct in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: ARM Ltd. */ 6 | 7 | /* { dg-do run } */ 8 | /* { dg-output "" { xfail avr32*-*-* } } */ 9 | 10 | #include "ffitest.h" 11 | #include 12 | 13 | struct small_tag 14 | { 15 | unsigned char a; 16 | unsigned char b; 17 | }; 18 | 19 | struct large_tag 20 | { 21 | unsigned a; 22 | unsigned b; 23 | unsigned c; 24 | unsigned d; 25 | unsigned e; 26 | }; 27 | 28 | static int 29 | test_fn (int n, ...) 30 | { 31 | va_list ap; 32 | struct small_tag s1; 33 | struct small_tag s2; 34 | struct large_tag l; 35 | 36 | va_start (ap, n); 37 | s1 = va_arg (ap, struct small_tag); 38 | l = va_arg (ap, struct large_tag); 39 | s2 = va_arg (ap, struct small_tag); 40 | printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, 41 | s2.a, s2.b); 42 | va_end (ap); 43 | return n + 1; 44 | } 45 | 46 | int 47 | main (void) 48 | { 49 | ffi_cif cif; 50 | void* args[5]; 51 | ffi_type* arg_types[5]; 52 | 53 | ffi_type s_type; 54 | ffi_type *s_type_elements[3]; 55 | 56 | ffi_type l_type; 57 | ffi_type *l_type_elements[6]; 58 | 59 | struct small_tag s1; 60 | struct small_tag s2; 61 | struct large_tag l1; 62 | 63 | int n; 64 | ffi_arg res; 65 | 66 | s_type.size = 0; 67 | s_type.alignment = 0; 68 | s_type.type = FFI_TYPE_STRUCT; 69 | s_type.elements = s_type_elements; 70 | 71 | s_type_elements[0] = &ffi_type_uchar; 72 | s_type_elements[1] = &ffi_type_uchar; 73 | s_type_elements[2] = NULL; 74 | 75 | l_type.size = 0; 76 | l_type.alignment = 0; 77 | l_type.type = FFI_TYPE_STRUCT; 78 | l_type.elements = l_type_elements; 79 | 80 | l_type_elements[0] = &ffi_type_uint; 81 | l_type_elements[1] = &ffi_type_uint; 82 | l_type_elements[2] = &ffi_type_uint; 83 | l_type_elements[3] = &ffi_type_uint; 84 | l_type_elements[4] = &ffi_type_uint; 85 | l_type_elements[5] = NULL; 86 | 87 | arg_types[0] = &ffi_type_sint; 88 | arg_types[1] = &s_type; 89 | arg_types[2] = &l_type; 90 | arg_types[3] = &s_type; 91 | arg_types[4] = NULL; 92 | 93 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &ffi_type_sint, arg_types) == FFI_OK); 94 | 95 | s1.a = 5; 96 | s1.b = 6; 97 | 98 | l1.a = 10; 99 | l1.b = 11; 100 | l1.c = 12; 101 | l1.d = 13; 102 | l1.e = 14; 103 | 104 | s2.a = 7; 105 | s2.b = 8; 106 | 107 | n = 41; 108 | 109 | args[0] = &n; 110 | args[1] = &s1; 111 | args[2] = &l1; 112 | args[3] = &s2; 113 | args[4] = NULL; 114 | 115 | ffi_call(&cif, FFI_FN(test_fn), &res, args); 116 | /* { dg-output "5 6 10 11 12 13 14 7 8" } */ 117 | printf("res: %d\n", (int) res); 118 | /* { dg-output "\nres: 42" } */ 119 | 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_align_sint32.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of sint32. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20031203 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct cls_struct_align { 11 | unsigned char a; 12 | signed int b; 13 | unsigned char c; 14 | } cls_struct_align; 15 | 16 | cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, 17 | struct cls_struct_align a2) 18 | { 19 | struct cls_struct_align result; 20 | 21 | result.a = a1.a + a2.a; 22 | result.b = a1.b + a2.b; 23 | result.c = a1.c + a2.c; 24 | 25 | printf("%d %d %d %d %d %d: %d %d %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_align a1, a2; 36 | 37 | a1 = *(struct cls_struct_align*)(args[0]); 38 | a2 = *(struct cls_struct_align*)(args[1]); 39 | 40 | *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[4]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_align g_dbl = { 12, 4951, 127 }; 54 | struct cls_struct_align f_dbl = { 1, 9320, 13 }; 55 | struct cls_struct_align res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_uchar; 63 | cls_struct_fields[1] = &ffi_type_sint; 64 | cls_struct_fields[2] = &ffi_type_uchar; 65 | cls_struct_fields[3] = NULL; 66 | 67 | dbl_arg_types[0] = &cls_struct_type; 68 | dbl_arg_types[1] = &cls_struct_type; 69 | dbl_arg_types[2] = NULL; 70 | 71 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 72 | dbl_arg_types) == FFI_OK); 73 | 74 | args_dbl[0] = &g_dbl; 75 | args_dbl[1] = &f_dbl; 76 | args_dbl[2] = NULL; 77 | 78 | ffi_call(&cif, FFI_FN(cls_struct_align_fn), &res_dbl, args_dbl); 79 | /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ 80 | printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 81 | /* { dg-output "\nres: 13 14271 140" } */ 82 | 83 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); 84 | 85 | res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl); 86 | /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ 87 | printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 88 | /* { dg-output "\nres: 13 14271 140" } */ 89 | 90 | exit(0); 91 | } 92 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_align_uint32.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of uint32. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20031203 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct cls_struct_align { 11 | unsigned char a; 12 | unsigned int b; 13 | unsigned char c; 14 | } cls_struct_align; 15 | 16 | cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, 17 | struct cls_struct_align a2) 18 | { 19 | struct cls_struct_align result; 20 | 21 | result.a = a1.a + a2.a; 22 | result.b = a1.b + a2.b; 23 | result.c = a1.c + a2.c; 24 | 25 | printf("%d %d %d %d %d %d: %d %d %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_align a1, a2; 36 | 37 | a1 = *(struct cls_struct_align*)(args[0]); 38 | a2 = *(struct cls_struct_align*)(args[1]); 39 | 40 | *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[4]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_align g_dbl = { 12, 4951, 127 }; 54 | struct cls_struct_align f_dbl = { 1, 9320, 13 }; 55 | struct cls_struct_align res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_uchar; 63 | cls_struct_fields[1] = &ffi_type_uint; 64 | cls_struct_fields[2] = &ffi_type_uchar; 65 | cls_struct_fields[3] = NULL; 66 | 67 | dbl_arg_types[0] = &cls_struct_type; 68 | dbl_arg_types[1] = &cls_struct_type; 69 | dbl_arg_types[2] = NULL; 70 | 71 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 72 | dbl_arg_types) == FFI_OK); 73 | 74 | args_dbl[0] = &g_dbl; 75 | args_dbl[1] = &f_dbl; 76 | args_dbl[2] = NULL; 77 | 78 | ffi_call(&cif, FFI_FN(cls_struct_align_fn), &res_dbl, args_dbl); 79 | /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ 80 | printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 81 | /* { dg-output "\nres: 13 14271 140" } */ 82 | 83 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); 84 | 85 | res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl); 86 | /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ 87 | printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 88 | /* { dg-output "\nres: 13 14271 140" } */ 89 | 90 | exit(0); 91 | } 92 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_align_sint16.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of sint16. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20031203 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct cls_struct_align { 11 | unsigned char a; 12 | signed short b; 13 | unsigned char c; 14 | } cls_struct_align; 15 | 16 | cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, 17 | struct cls_struct_align a2) 18 | { 19 | struct cls_struct_align result; 20 | 21 | result.a = a1.a + a2.a; 22 | result.b = a1.b + a2.b; 23 | result.c = a1.c + a2.c; 24 | 25 | printf("%d %d %d %d %d %d: %d %d %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_align a1, a2; 36 | 37 | a1 = *(struct cls_struct_align*)(args[0]); 38 | a2 = *(struct cls_struct_align*)(args[1]); 39 | 40 | *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[4]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_align g_dbl = { 12, 4951, 127 }; 54 | struct cls_struct_align f_dbl = { 1, 9320, 13 }; 55 | struct cls_struct_align res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_uchar; 63 | cls_struct_fields[1] = &ffi_type_sshort; 64 | cls_struct_fields[2] = &ffi_type_uchar; 65 | cls_struct_fields[3] = NULL; 66 | 67 | dbl_arg_types[0] = &cls_struct_type; 68 | dbl_arg_types[1] = &cls_struct_type; 69 | dbl_arg_types[2] = NULL; 70 | 71 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 72 | dbl_arg_types) == FFI_OK); 73 | 74 | args_dbl[0] = &g_dbl; 75 | args_dbl[1] = &f_dbl; 76 | args_dbl[2] = NULL; 77 | 78 | ffi_call(&cif, FFI_FN(cls_struct_align_fn), &res_dbl, args_dbl); 79 | /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ 80 | printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 81 | /* { dg-output "\nres: 13 14271 140" } */ 82 | 83 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); 84 | 85 | res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl); 86 | /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ 87 | printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 88 | /* { dg-output "\nres: 13 14271 140" } */ 89 | 90 | exit(0); 91 | } 92 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_align_uint16.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of uint16. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20031203 */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | 10 | typedef struct cls_struct_align { 11 | unsigned char a; 12 | unsigned short b; 13 | unsigned char c; 14 | } cls_struct_align; 15 | 16 | cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, 17 | struct cls_struct_align a2) 18 | { 19 | struct cls_struct_align result; 20 | 21 | result.a = a1.a + a2.a; 22 | result.b = a1.b + a2.b; 23 | result.c = a1.c + a2.c; 24 | 25 | printf("%d %d %d %d %d %d: %d %d %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); 26 | 27 | return result; 28 | } 29 | 30 | static void 31 | cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 32 | void* userdata __UNUSED__) 33 | { 34 | 35 | struct cls_struct_align a1, a2; 36 | 37 | a1 = *(struct cls_struct_align*)(args[0]); 38 | a2 = *(struct cls_struct_align*)(args[1]); 39 | 40 | *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2); 41 | } 42 | 43 | int main (void) 44 | { 45 | ffi_cif cif; 46 | void *code; 47 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 48 | void* args_dbl[5]; 49 | ffi_type* cls_struct_fields[4]; 50 | ffi_type cls_struct_type; 51 | ffi_type* dbl_arg_types[5]; 52 | 53 | struct cls_struct_align g_dbl = { 12, 4951, 127 }; 54 | struct cls_struct_align f_dbl = { 1, 9320, 13 }; 55 | struct cls_struct_align res_dbl; 56 | 57 | cls_struct_type.size = 0; 58 | cls_struct_type.alignment = 0; 59 | cls_struct_type.type = FFI_TYPE_STRUCT; 60 | cls_struct_type.elements = cls_struct_fields; 61 | 62 | cls_struct_fields[0] = &ffi_type_uchar; 63 | cls_struct_fields[1] = &ffi_type_ushort; 64 | cls_struct_fields[2] = &ffi_type_uchar; 65 | cls_struct_fields[3] = NULL; 66 | 67 | dbl_arg_types[0] = &cls_struct_type; 68 | dbl_arg_types[1] = &cls_struct_type; 69 | dbl_arg_types[2] = NULL; 70 | 71 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 72 | dbl_arg_types) == FFI_OK); 73 | 74 | args_dbl[0] = &g_dbl; 75 | args_dbl[1] = &f_dbl; 76 | args_dbl[2] = NULL; 77 | 78 | ffi_call(&cif, FFI_FN(cls_struct_align_fn), &res_dbl, args_dbl); 79 | /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ 80 | printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 81 | /* { dg-output "\nres: 13 14271 140" } */ 82 | 83 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); 84 | 85 | res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl); 86 | /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ 87 | printf("res: %d %d %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 88 | /* { dg-output "\nres: 13 14271 140" } */ 89 | 90 | exit(0); 91 | } 92 | -------------------------------------------------------------------------------- /libs/libffi/testsuite/libffi.call/cls_align_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of double. 3 | Limitations: none. 4 | PR: none. 5 | Originator: 20031203 */ 6 | 7 | 8 | 9 | /* { dg-do run } */ 10 | #include "ffitest.h" 11 | 12 | typedef struct cls_struct_align { 13 | unsigned char a; 14 | double b; 15 | unsigned char c; 16 | } cls_struct_align; 17 | 18 | cls_struct_align cls_struct_align_fn(struct cls_struct_align a1, 19 | struct cls_struct_align a2) 20 | { 21 | struct cls_struct_align result; 22 | 23 | result.a = a1.a + a2.a; 24 | result.b = a1.b + a2.b; 25 | result.c = a1.c + a2.c; 26 | 27 | printf("%d %g %d %d %g %d: %d %g %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c); 28 | 29 | return result; 30 | } 31 | 32 | static void 33 | cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, 34 | void* userdata __UNUSED__) 35 | { 36 | 37 | struct cls_struct_align a1, a2; 38 | 39 | a1 = *(struct cls_struct_align*)(args[0]); 40 | a2 = *(struct cls_struct_align*)(args[1]); 41 | 42 | *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2); 43 | } 44 | 45 | int main (void) 46 | { 47 | ffi_cif cif; 48 | void *code; 49 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 50 | void* args_dbl[5]; 51 | ffi_type* cls_struct_fields[4]; 52 | ffi_type cls_struct_type; 53 | ffi_type* dbl_arg_types[5]; 54 | 55 | struct cls_struct_align g_dbl = { 12, 4951, 127 }; 56 | struct cls_struct_align f_dbl = { 1, 9320, 13 }; 57 | struct cls_struct_align res_dbl; 58 | 59 | cls_struct_type.size = 0; 60 | cls_struct_type.alignment = 0; 61 | cls_struct_type.type = FFI_TYPE_STRUCT; 62 | cls_struct_type.elements = cls_struct_fields; 63 | 64 | cls_struct_fields[0] = &ffi_type_uchar; 65 | cls_struct_fields[1] = &ffi_type_double; 66 | cls_struct_fields[2] = &ffi_type_uchar; 67 | cls_struct_fields[3] = NULL; 68 | 69 | dbl_arg_types[0] = &cls_struct_type; 70 | dbl_arg_types[1] = &cls_struct_type; 71 | dbl_arg_types[2] = NULL; 72 | 73 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, 74 | dbl_arg_types) == FFI_OK); 75 | 76 | args_dbl[0] = &g_dbl; 77 | args_dbl[1] = &f_dbl; 78 | args_dbl[2] = NULL; 79 | 80 | ffi_call(&cif, FFI_FN(cls_struct_align_fn), &res_dbl, args_dbl); 81 | /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */ 82 | printf("res: %d %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 83 | /* { dg-output "\nres: 13 14271 140" } */ 84 | 85 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); 86 | 87 | res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl); 88 | /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */ 89 | printf("res: %d %g %d\n", res_dbl.a, res_dbl.b, res_dbl.c); 90 | /* { dg-output "\nres: 13 14271 140" } */ 91 | 92 | exit(0); 93 | } 94 | --------------------------------------------------------------------------------