├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── .gitignore ├── .gitmodules ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── libffi-rs ├── CHANGELOG.md ├── CMakeLists.txt ├── Cargo.toml ├── README.md ├── TODO.md ├── examples │ ├── c │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── support.c │ │ ├── support.h │ │ └── test.c │ ├── sort.rs │ └── types.rs ├── release.toml └── src │ ├── high │ ├── call.rs │ ├── mod.rs │ └── types.rs │ ├── lib.rs │ ├── low.rs │ └── middle │ ├── builder.rs │ ├── mod.rs │ ├── types.rs │ └── util.rs ├── libffi-sys-rs ├── CHANGELOG.md ├── Cargo.toml ├── README.md ├── build │ ├── build.rs │ ├── common.rs │ ├── msvc.rs │ └── not_msvc.rs ├── include │ └── msvc │ │ ├── ffi.h │ │ └── fficonfig.h ├── libffi │ ├── ChangeLog │ ├── ChangeLog.old │ ├── LICENSE │ ├── LICENSE-BUILDTOOLS │ ├── Makefile.am │ ├── Makefile.in │ ├── README.md │ ├── acinclude.m4 │ ├── aclocal.m4 │ ├── compile │ ├── config.guess │ ├── config.sub │ ├── configure │ ├── configure.ac │ ├── configure.host │ ├── depcomp │ ├── doc │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── libffi.info │ │ ├── libffi.pdf │ │ ├── libffi.texi │ │ ├── mdate-sh │ │ ├── stamp-vti │ │ ├── texinfo.tex │ │ └── version.texi │ ├── fficonfig.h.in │ ├── generate-darwin-source-and-headers.py │ ├── include │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── ffi.h.in │ │ ├── ffi_cfi.h │ │ ├── ffi_common.h │ │ └── tramp.h │ ├── install-sh │ ├── libffi.map.in │ ├── libffi.pc.in │ ├── libffi.xcodeproj │ │ └── project.pbxproj │ ├── libtool-ldflags │ ├── libtool-version │ ├── ltmain.sh │ ├── m4 │ │ ├── asmcfi.m4 │ │ ├── ax_cc_maxopt.m4 │ │ ├── ax_cflags_warn_all.m4 │ │ ├── ax_check_compile_flag.m4 │ │ ├── ax_compiler_vendor.m4 │ │ ├── ax_configure_args.m4 │ │ ├── ax_enable_builddir.m4 │ │ ├── ax_gcc_archflag.m4 │ │ ├── ax_gcc_x86_cpuid.m4 │ │ ├── ax_prepend_flag.m4 │ │ ├── ax_require_defined.m4 │ │ ├── libtool.m4 │ │ ├── ltoptions.m4 │ │ ├── ltsugar.m4 │ │ ├── ltversion.m4 │ │ └── lt~obsolete.m4 │ ├── make_sunver.pl │ ├── man │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── ffi.3 │ │ ├── ffi_call.3 │ │ ├── ffi_prep_cif.3 │ │ └── ffi_prep_cif_var.3 │ ├── missing │ ├── msvc_build │ │ └── aarch64 │ │ │ ├── Ffi_staticLib.sln │ │ │ ├── Ffi_staticLib.vcxproj │ │ │ ├── Ffi_staticLib.vcxproj.filters │ │ │ ├── Ffi_staticLib.vcxproj.user │ │ │ └── aarch64_include │ │ │ ├── ffi.h │ │ │ └── fficonfig.h │ ├── msvcc.sh │ ├── src │ │ ├── aarch64 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ ├── sysv.S │ │ │ └── win64_armasm.S │ │ ├── alpha │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ └── osf.S │ │ ├── arc │ │ │ ├── arcompact.S │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── arm │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ ├── sysv.S │ │ │ └── sysv_msvc_arm32.S │ │ ├── avr32 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── bfin │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── closures.c │ │ ├── cris │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── csky │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── debug.c │ │ ├── dlmalloc.c │ │ ├── frv │ │ │ ├── eabi.S │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── ia64 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── ia64_flags.h │ │ │ └── unix.S │ │ ├── java_raw_api.c │ │ ├── kvx │ │ │ ├── asm.h │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── loongarch64 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── m32r │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── m68k │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── m88k │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── obsd.S │ │ ├── metag │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── microblaze │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── mips │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── n32.S │ │ │ └── o32.S │ │ ├── moxie │ │ │ ├── eabi.S │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── or1k │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── pa │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── hpux32.S │ │ │ ├── hpux64.S │ │ │ └── linux.S │ │ ├── powerpc │ │ │ ├── aix.S │ │ │ ├── aix_closure.S │ │ │ ├── asm.h │ │ │ ├── darwin.S │ │ │ ├── darwin_closure.S │ │ │ ├── ffi.c │ │ │ ├── ffi_darwin.c │ │ │ ├── ffi_linux64.c │ │ │ ├── ffi_powerpc.h │ │ │ ├── ffi_sysv.c │ │ │ ├── ffitarget.h │ │ │ ├── linux64.S │ │ │ ├── linux64_closure.S │ │ │ ├── ppc_closure.S │ │ │ ├── sysv.S │ │ │ └── t-aix │ │ ├── prep_cif.c │ │ ├── raw_api.c │ │ ├── riscv │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── s390 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ └── sysv.S │ │ ├── sh │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── sh64 │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ │ ├── sparc │ │ │ ├── ffi.c │ │ │ ├── ffi64.c │ │ │ ├── ffitarget.h │ │ │ ├── internal.h │ │ │ ├── v8.S │ │ │ └── v9.S │ │ ├── tile │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── tile.S │ │ ├── tramp.c │ │ ├── types.c │ │ ├── vax │ │ │ ├── elfbsd.S │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── wasm32 │ │ │ ├── ffi.c │ │ │ └── ffitarget.h │ │ ├── x86 │ │ │ ├── asmnames.h │ │ │ ├── ffi.c │ │ │ ├── ffi64.c │ │ │ ├── ffitarget.h │ │ │ ├── ffiw64.c │ │ │ ├── internal.h │ │ │ ├── internal64.h │ │ │ ├── sysv.S │ │ │ ├── sysv_intel.S │ │ │ ├── unix64.S │ │ │ ├── win64.S │ │ │ └── win64_intel.S │ │ └── xtensa │ │ │ ├── ffi.c │ │ │ ├── ffitarget.h │ │ │ └── sysv.S │ └── testsuite │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── config │ │ └── default.exp │ │ ├── emscripten │ │ ├── build-tests.sh │ │ ├── build.sh │ │ ├── conftest.py │ │ ├── node-tests.sh │ │ ├── test.html │ │ └── test_libffi.py │ │ ├── lib │ │ ├── libffi.exp │ │ ├── target-libpath.exp │ │ └── wrapper.exp │ │ ├── libffi.bhaible │ │ ├── Makefile │ │ ├── README │ │ ├── alignof.h │ │ ├── bhaible.exp │ │ ├── test-call.c │ │ ├── test-callback.c │ │ └── testcases.c │ │ ├── libffi.call │ │ ├── align_mixed.c │ │ ├── align_stdcall.c │ │ ├── bpo_38748.c │ │ ├── call.exp │ │ ├── callback.c │ │ ├── callback2.c │ │ ├── callback3.c │ │ ├── callback4.c │ │ ├── err_bad_typedef.c │ │ ├── ffitest.h │ │ ├── float.c │ │ ├── float1.c │ │ ├── float2.c │ │ ├── float3.c │ │ ├── float4.c │ │ ├── float_va.c │ │ ├── many.c │ │ ├── many2.c │ │ ├── many_double.c │ │ ├── many_mixed.c │ │ ├── negint.c │ │ ├── offsets.c │ │ ├── pr1172638.c │ │ ├── promotion.c │ │ ├── pyobjc_tc.c │ │ ├── return_dbl.c │ │ ├── return_dbl1.c │ │ ├── return_dbl2.c │ │ ├── return_fl.c │ │ ├── return_fl1.c │ │ ├── return_fl2.c │ │ ├── return_fl3.c │ │ ├── return_ldl.c │ │ ├── return_ll.c │ │ ├── return_ll1.c │ │ ├── return_sc.c │ │ ├── return_sl.c │ │ ├── return_uc.c │ │ ├── return_ul.c │ │ ├── s55.c │ │ ├── strlen.c │ │ ├── strlen2.c │ │ ├── strlen3.c │ │ ├── strlen4.c │ │ ├── struct1.c │ │ ├── struct10.c │ │ ├── struct2.c │ │ ├── struct3.c │ │ ├── struct4.c │ │ ├── struct5.c │ │ ├── struct6.c │ │ ├── struct7.c │ │ ├── struct8.c │ │ ├── struct9.c │ │ ├── struct_by_value_2.c │ │ ├── struct_by_value_3.c │ │ ├── struct_by_value_3f.c │ │ ├── struct_by_value_4.c │ │ ├── struct_by_value_4f.c │ │ ├── struct_by_value_big.c │ │ ├── struct_by_value_small.c │ │ ├── struct_int_float.c │ │ ├── struct_return_2H.c │ │ ├── struct_return_8H.c │ │ ├── uninitialized.c │ │ ├── va_1.c │ │ ├── va_2.c │ │ ├── va_3.c │ │ ├── va_struct1.c │ │ ├── va_struct2.c │ │ └── va_struct3.c │ │ ├── libffi.closures │ │ ├── closure.exp │ │ ├── closure_fn0.c │ │ ├── closure_fn1.c │ │ ├── closure_fn2.c │ │ ├── closure_fn3.c │ │ ├── closure_fn4.c │ │ ├── closure_fn5.c │ │ ├── closure_fn6.c │ │ ├── closure_loc_fn0.c │ │ ├── closure_simple.c │ │ ├── cls_12byte.c │ │ ├── cls_16byte.c │ │ ├── cls_18byte.c │ │ ├── cls_19byte.c │ │ ├── cls_1_1byte.c │ │ ├── cls_20byte.c │ │ ├── cls_20byte1.c │ │ ├── cls_24byte.c │ │ ├── cls_2byte.c │ │ ├── cls_3_1byte.c │ │ ├── cls_3byte1.c │ │ ├── cls_3byte2.c │ │ ├── cls_3float.c │ │ ├── cls_4_1byte.c │ │ ├── cls_4byte.c │ │ ├── cls_5_1_byte.c │ │ ├── cls_5byte.c │ │ ├── cls_64byte.c │ │ ├── cls_6_1_byte.c │ │ ├── cls_6byte.c │ │ ├── cls_7_1_byte.c │ │ ├── cls_7byte.c │ │ ├── cls_8byte.c │ │ ├── cls_9byte1.c │ │ ├── cls_9byte2.c │ │ ├── cls_align_double.c │ │ ├── cls_align_float.c │ │ ├── cls_align_longdouble.c │ │ ├── cls_align_longdouble_split.c │ │ ├── cls_align_longdouble_split2.c │ │ ├── cls_align_pointer.c │ │ ├── cls_align_sint16.c │ │ ├── cls_align_sint32.c │ │ ├── cls_align_sint64.c │ │ ├── cls_align_uint16.c │ │ ├── cls_align_uint32.c │ │ ├── cls_align_uint64.c │ │ ├── cls_dbls_struct.c │ │ ├── cls_double.c │ │ ├── cls_double_va.c │ │ ├── cls_float.c │ │ ├── cls_longdouble.c │ │ ├── cls_longdouble_va.c │ │ ├── cls_many_mixed_args.c │ │ ├── cls_many_mixed_float_double.c │ │ ├── cls_multi_schar.c │ │ ├── cls_multi_sshort.c │ │ ├── cls_multi_sshortchar.c │ │ ├── cls_multi_uchar.c │ │ ├── cls_multi_ushort.c │ │ ├── cls_multi_ushortchar.c │ │ ├── cls_pointer.c │ │ ├── cls_pointer_stack.c │ │ ├── cls_schar.c │ │ ├── cls_sint.c │ │ ├── cls_sshort.c │ │ ├── cls_struct_va1.c │ │ ├── cls_uchar.c │ │ ├── cls_uint.c │ │ ├── cls_uint_va.c │ │ ├── cls_ulong_va.c │ │ ├── cls_ulonglong.c │ │ ├── cls_ushort.c │ │ ├── err_bad_abi.c │ │ ├── ffitest.h │ │ ├── huge_struct.c │ │ ├── nested_struct.c │ │ ├── nested_struct1.c │ │ ├── nested_struct10.c │ │ ├── nested_struct11.c │ │ ├── nested_struct12.c │ │ ├── nested_struct13.c │ │ ├── nested_struct2.c │ │ ├── nested_struct3.c │ │ ├── nested_struct4.c │ │ ├── nested_struct5.c │ │ ├── nested_struct6.c │ │ ├── nested_struct7.c │ │ ├── nested_struct8.c │ │ ├── nested_struct9.c │ │ ├── problem1.c │ │ ├── single_entry_structs1.c │ │ ├── single_entry_structs2.c │ │ ├── single_entry_structs3.c │ │ ├── stret_large.c │ │ ├── stret_large2.c │ │ ├── stret_medium.c │ │ ├── stret_medium2.c │ │ ├── testclosure.c │ │ ├── unwindtest.cc │ │ └── unwindtest_ffi_call.cc │ │ ├── libffi.complex │ │ ├── cls_align_complex.inc │ │ ├── cls_align_complex_double.c │ │ ├── cls_align_complex_float.c │ │ ├── cls_align_complex_longdouble.c │ │ ├── cls_complex.inc │ │ ├── cls_complex_double.c │ │ ├── cls_complex_float.c │ │ ├── cls_complex_longdouble.c │ │ ├── cls_complex_struct.inc │ │ ├── cls_complex_struct_double.c │ │ ├── cls_complex_struct_float.c │ │ ├── cls_complex_struct_longdouble.c │ │ ├── cls_complex_va.inc │ │ ├── cls_complex_va_double.c │ │ ├── cls_complex_va_float.c │ │ ├── cls_complex_va_longdouble.c │ │ ├── complex.exp │ │ ├── complex.inc │ │ ├── complex_defs_double.inc │ │ ├── complex_defs_float.inc │ │ ├── complex_defs_longdouble.inc │ │ ├── complex_double.c │ │ ├── complex_float.c │ │ ├── complex_int.c │ │ ├── complex_longdouble.c │ │ ├── ffitest.h │ │ ├── many_complex.inc │ │ ├── many_complex_double.c │ │ ├── many_complex_float.c │ │ ├── many_complex_longdouble.c │ │ ├── return_complex.inc │ │ ├── return_complex1.inc │ │ ├── return_complex1_double.c │ │ ├── return_complex1_float.c │ │ ├── return_complex1_longdouble.c │ │ ├── return_complex2.inc │ │ ├── return_complex2_double.c │ │ ├── return_complex2_float.c │ │ ├── return_complex2_longdouble.c │ │ ├── return_complex_double.c │ │ ├── return_complex_float.c │ │ └── return_complex_longdouble.c │ │ └── libffi.go │ │ ├── aa-direct.c │ │ ├── closure1.c │ │ ├── ffitest.h │ │ ├── go.exp │ │ └── static-chain.h ├── release.toml └── src │ ├── arch.rs │ └── lib.rs └── scripts ├── README.md └── qemutests.sh /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: cargo 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "11:00" 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | src/raw.rs 4 | .idea 5 | *.iml 6 | cmake-build-*/ 7 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tov/libffi-rs/1c915790b7240291a6855d98dc4d3d1535ea74d5/.gitmodules -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | members = [ 4 | "libffi-rs", 5 | "libffi-sys-rs", 6 | ] 7 | 8 | [workspace.package] 9 | repository = "https://github.com/tov/libffi-rs" 10 | license = "MIT/Apache-2.0" 11 | keywords = ["ffi", "libffi", "closure", "c"] 12 | edition = "2021" 13 | rust-version = "1.78" 14 | 15 | [workspace.lints.clippy] 16 | complexity = "warn" 17 | correctness = "warn" 18 | module_inception = { level = "allow", priority = 1 } 19 | must_use_candidate = { level = "allow", priority = 1 } 20 | perf = "warn" 21 | style = "warn" 22 | suspicious = "warn" 23 | unreadable_literal = "warn" 24 | wildcard_imports = { level = "allow", priority = 1 } 25 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Jesse A. Tov 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /libffi-rs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is here to make CLion happy. 2 | -------------------------------------------------------------------------------- /libffi-rs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libffi" 3 | version = "4.1.0" 4 | authors = ["Jesse A. Tov "] 5 | description = "Rust bindings for libffi" 6 | repository.workspace = true 7 | readme = "README.md" 8 | license.workspace = true 9 | keywords.workspace = true 10 | categories = ["development-tools::ffi"] 11 | edition.workspace = true 12 | rust-version.workspace = true 13 | 14 | [dependencies] 15 | libffi-sys = { path = "../libffi-sys-rs", version = "^3.3" } 16 | libc = "0.2.65" 17 | 18 | [features] 19 | complex = [] 20 | system = ["libffi-sys/system"] 21 | 22 | [package.metadata.docs.rs] 23 | features = ["system"] 24 | 25 | [lints] 26 | workspace = true 27 | -------------------------------------------------------------------------------- /libffi-rs/TODO.md: -------------------------------------------------------------------------------- 1 | # To do 2 | 3 | - Many more tests and examples. 4 | 5 | - high::BuilderN? 6 | - Custom complex number types? But Rust doesn’t support complex numbers 7 | anyway... 8 | - CIF inspection? 9 | -------------------------------------------------------------------------------- /libffi-rs/examples/c/.gitignore: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /libffi-rs/examples/c/Makefile: -------------------------------------------------------------------------------- 1 | default: test 2 | 3 | CFLAGS = `pkg-config --cflags libffi` 4 | LDFLAGS = `pkg-config --libs libffi` 5 | 6 | -------------------------------------------------------------------------------- /libffi-rs/examples/c/support.c: -------------------------------------------------------------------------------- 1 | #include "include_ffi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | // ffi_type** ffi_type_alloc_array(size_t size, ffi_type** types) 8 | // { 9 | // ffi_type** copy = malloc((size + 1) 10 | 11 | void ffi_type_destroy(ffi_type* type) 12 | { 13 | if (type == NULL) return; 14 | 15 | if (type->type == FFI_TYPE_STRUCT || type->type == FFI_TYPE_COMPLEX) { 16 | ffi_type_destroy_array(type->elements); 17 | free(type); 18 | } 19 | } 20 | 21 | void ffi_type_destroy_array(ffi_type** types) 22 | { 23 | for (ffi_type** curr = types; *curr != NULL; ++curr) 24 | ffi_type_destroy(*curr); 25 | 26 | free(types); 27 | } 28 | 29 | ffi_type* ffi_type_clone(ffi_type* type) 30 | { 31 | if (type == NULL) return NULL; 32 | 33 | if (type->type == FFI_TYPE_STRUCT || type->type == FFI_TYPE_COMPLEX) { 34 | ffi_type* copy = malloc(sizeof(ffi_type)); 35 | assert(copy != NULL); 36 | 37 | memcpy(copy, type, sizeof(ffi_type)); 38 | copy->elements = ffi_type_clone_array(type->elements); 39 | 40 | return copy; 41 | } else 42 | return type; 43 | } 44 | 45 | ffi_type** ffi_type_clone_array(ffi_type** types) 46 | { 47 | size_t size = 1; 48 | for (ffi_type** curr = types; *curr != NULL; ++curr) 49 | ++size; 50 | 51 | ffi_type** copy = malloc(size * sizeof(ffi_type*)); 52 | assert(copy != NULL); 53 | 54 | for (size_t i = 0; i < size; ++i) 55 | copy[i] = ffi_type_clone(types[i]); 56 | 57 | return copy; 58 | } 59 | -------------------------------------------------------------------------------- /libffi-rs/examples/c/support.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ffi_type_destroy(ffi_type*); 4 | void ffi_type_destroy_array(ffi_type**); 5 | 6 | ffi_type* ffi_type_clone(ffi_type*); 7 | ffi_type** ffi_type_clone_array(ffi_type**); 8 | -------------------------------------------------------------------------------- /libffi-rs/examples/c/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void callback(ffi_cif* cif, void* result, void** args, void* userdata) 6 | { 7 | *(int*)result = *(int*)userdata + **(int**)args; 8 | } 9 | 10 | int main() 11 | { 12 | ffi_cif cif; 13 | ffi_type* args[1] = { &ffi_type_sint }; 14 | ffi_closure* closure; 15 | int (*fn)(int); 16 | int env = 5; 17 | 18 | assert(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 19 | &ffi_type_sint, args) 20 | == FFI_OK); 21 | closure = ffi_closure_alloc(sizeof(ffi_closure), (void**)&fn); 22 | assert(ffi_prep_closure_loc(closure, &cif, callback, &env, fn) 23 | == FFI_OK); 24 | 25 | printf("%d\n", fn(6)); 26 | printf("%d\n", fn(7)); 27 | } 28 | -------------------------------------------------------------------------------- /libffi-rs/examples/sort.rs: -------------------------------------------------------------------------------- 1 | // Example calling out to libc qsort. 2 | 3 | use libffi::high::Closure2; 4 | 5 | mod c { 6 | use core::ffi::{c_int, c_void}; 7 | use libffi::high::FnPtr2; 8 | 9 | pub type Callback<'a> = FnPtr2<'a, *const c_void, *const c_void, c_int>; 10 | 11 | extern "C" { 12 | pub fn qsort(base: *const c_void, nel: usize, width: usize, compar: Callback); 13 | } 14 | } 15 | 16 | fn qsort(array: &mut [T]) { 17 | use core::cmp::Ordering::*; 18 | use core::ffi::c_void; 19 | use core::mem; 20 | 21 | let lambda = |x: *const c_void, y: *const c_void| { 22 | let x = unsafe { &*(x as *const T) }; 23 | let y = unsafe { &*(y as *const T) }; 24 | match x.cmp(y) { 25 | Less => -1, 26 | Equal => 0, 27 | Greater => 1, 28 | } 29 | }; 30 | let compare = Closure2::new(&lambda); 31 | 32 | unsafe { 33 | c::qsort( 34 | array.as_ptr() as *const _, 35 | array.len(), 36 | mem::size_of::(), 37 | *compare.code_ptr(), 38 | ) 39 | } 40 | } 41 | 42 | fn main() { 43 | let mut v = vec![3, 4, 8, 1, 2, 0, 9]; 44 | qsort(&mut v); 45 | 46 | assert_eq!(vec![0, 1, 2, 3, 4, 8, 9], v); 47 | } 48 | -------------------------------------------------------------------------------- /libffi-rs/examples/types.rs: -------------------------------------------------------------------------------- 1 | use libffi::middle::Type; 2 | 3 | fn main() { 4 | Type::structure(vec![Type::u16(), Type::u16()]); 5 | } 6 | -------------------------------------------------------------------------------- /libffi-rs/release.toml: -------------------------------------------------------------------------------- 1 | pre-release-replacements = [ 2 | { file="README.md", search="libffi = \"[0-9.]*\"", replace="libffi = \"{{version}}\"" }, 3 | { file="README.md", search="version = \"[0-9.]*\"", replace="version = \"{{version}}\"" }, 4 | { file="src/lib.rs", search="libffi = \"[0-9.]*\"", replace="libffi = \"{{version}}\"" }, 5 | { file="src/lib.rs", search="version = \"[0-9.]*\"", replace="version = \"{{version}}\"" }, 6 | { file="src/lib.rs", search="https://docs[.]rs/libffi/[0-9.]*", replace="https://docs.rs/libffi/{{version}}" }, 7 | { file="CHANGELOG.md", search="\\[Unreleased\\]", replace="[{{version}}] - {{date}}" } 8 | ] 9 | -------------------------------------------------------------------------------- /libffi-rs/src/middle/util.rs: -------------------------------------------------------------------------------- 1 | use core::marker::PhantomData; 2 | use core::ops::Deref; 3 | 4 | pub struct Unique { 5 | contents: *mut T, 6 | _marker: PhantomData, 7 | } 8 | 9 | impl Deref for Unique { 10 | type Target = *mut T; 11 | fn deref(&self) -> &Self::Target { 12 | &self.contents 13 | } 14 | } 15 | 16 | impl Unique { 17 | pub unsafe fn new(ptr: *mut T) -> Self { 18 | Unique { 19 | contents: ptr, 20 | _marker: PhantomData, 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libffi-sys-rs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libffi-sys" 3 | version = "3.3.1" 4 | authors = ["Jesse A. Tov "] 5 | links = "ffi" 6 | build = "build/build.rs" 7 | description = "Raw Rust bindings for libffi" 8 | repository.workspace = true 9 | readme = "README.md" 10 | license.workspace = true 11 | keywords.workspace = true 12 | edition.workspace = true 13 | rust-version.workspace = true 14 | 15 | [features] 16 | system = [] 17 | complex = [] 18 | 19 | [package.metadata.docs.rs] 20 | features = ["system"] 21 | 22 | [build-dependencies] 23 | cc = "1.0" 24 | 25 | [lints] 26 | workspace = true 27 | -------------------------------------------------------------------------------- /libffi-sys-rs/build/build.rs: -------------------------------------------------------------------------------- 1 | mod common; 2 | #[cfg(target_env = "msvc")] 3 | mod msvc; 4 | #[cfg(not(target_env = "msvc"))] 5 | mod not_msvc; 6 | 7 | #[cfg(target_env = "msvc")] 8 | use msvc::*; 9 | #[cfg(not(target_env = "msvc"))] 10 | use not_msvc::*; 11 | 12 | fn main() { 13 | if cfg!(feature = "system") { 14 | probe_and_link(); 15 | } else { 16 | build_and_link(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /libffi-sys-rs/build/common.rs: -------------------------------------------------------------------------------- 1 | pub use std::{ 2 | env, fs, 3 | path::{Path, PathBuf}, 4 | process::Command, 5 | }; 6 | 7 | #[track_caller] 8 | pub fn run_command(which: &'static str, cmd: &mut Command) { 9 | match cmd.status() { 10 | Ok(status) if status.success() => (), 11 | Ok(status) => { 12 | println!("cargo:warning={which} failed with {status}"); 13 | panic!("{which}: {status} ({cmd:?})"); 14 | } 15 | Err(err) => { 16 | println!("cargo:warning={which} failed with error {err}"); 17 | panic!("{which}: {err} ({cmd:?})"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/LICENSE: -------------------------------------------------------------------------------- 1 | libffi - Copyright (c) 1996-2024 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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/doc/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this with automake to create Makefile.in 2 | 3 | info_TEXINFOS = libffi.texi 4 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/doc/libffi.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tov/libffi-rs/1c915790b7240291a6855d98dc4d3d1535ea74d5/libffi-sys-rs/libffi/doc/libffi.pdf -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/doc/stamp-vti: -------------------------------------------------------------------------------- 1 | @set UPDATED 1 June 2024 2 | @set UPDATED-MONTH June 2024 3 | @set EDITION 3.4.7 4 | @set VERSION 3.4.7 5 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/doc/version.texi: -------------------------------------------------------------------------------- 1 | @set UPDATED 1 June 2024 2 | @set UPDATED-MONTH June 2024 3 | @set EDITION 3.4.7 4 | @set VERSION 3.4.7 5 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/include/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this with automake to create Makefile.in 2 | 3 | AUTOMAKE_OPTIONS=foreign 4 | 5 | DISTCLEANFILES=ffitarget.h 6 | noinst_HEADERS=ffi_common.h ffi_cfi.h tramp.h 7 | EXTRA_DIST=ffi.h.in 8 | 9 | nodist_include_HEADERS = ffi.h ffitarget.h 10 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/include/tramp.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------- 2 | ffi_tramp.h - Copyright (C) 2021 Microsoft, Inc. 3 | 4 | Static trampoline definitions. 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the ``Software''), to deal in the Software without 9 | restriction, including without limitation the rights to use, copy, 10 | modify, merge, publish, distribute, sublicense, and/or sell copies 11 | of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 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 FFI_TRAMP_H 29 | #define FFI_TRAMP_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | int ffi_tramp_is_supported(void); 36 | void *ffi_tramp_alloc (int flags); 37 | void ffi_tramp_set_parms (void *tramp, void *data, void *code); 38 | void *ffi_tramp_get_addr (void *tramp); 39 | void ffi_tramp_free (void *tramp); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* FFI_TRAMP_H */ 46 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/libffi.map.in: -------------------------------------------------------------------------------- 1 | #define LIBFFI_ASM 2 | #define LIBFFI_H 3 | #include 4 | #include 5 | 6 | /* These version numbers correspond to the libtool-version abi numbers, 7 | not to the libffi release numbers. */ 8 | 9 | LIBFFI_BASE_8.0 { 10 | global: 11 | /* Exported data variables. */ 12 | ffi_type_void; 13 | ffi_type_uint8; 14 | ffi_type_sint8; 15 | ffi_type_uint16; 16 | ffi_type_sint16; 17 | ffi_type_uint32; 18 | ffi_type_sint32; 19 | ffi_type_uint64; 20 | ffi_type_sint64; 21 | ffi_type_float; 22 | ffi_type_double; 23 | ffi_type_longdouble; 24 | ffi_type_pointer; 25 | 26 | /* Exported functions. */ 27 | ffi_call; 28 | ffi_prep_cif; 29 | ffi_prep_cif_var; 30 | 31 | ffi_raw_call; 32 | ffi_ptrarray_to_raw; 33 | ffi_raw_to_ptrarray; 34 | ffi_raw_size; 35 | 36 | #if !FFI_NATIVE_RAW_API 37 | ffi_java_raw_call; 38 | #endif 39 | 40 | ffi_java_ptrarray_to_raw; 41 | ffi_java_raw_to_ptrarray; 42 | ffi_java_raw_size; 43 | 44 | ffi_get_struct_offsets; 45 | local: 46 | *; 47 | }; 48 | 49 | #ifdef FFI_TARGET_HAS_COMPLEX_TYPE 50 | LIBFFI_COMPLEX_8.0 { 51 | global: 52 | /* Exported data variables. */ 53 | ffi_type_complex_float; 54 | ffi_type_complex_double; 55 | ffi_type_complex_longdouble; 56 | } LIBFFI_BASE_8.0; 57 | #endif 58 | 59 | #if FFI_CLOSURES 60 | LIBFFI_CLOSURE_8.0 { 61 | global: 62 | ffi_closure_alloc; 63 | ffi_closure_free; 64 | ffi_prep_closure; 65 | ffi_prep_closure_loc; 66 | ffi_prep_raw_closure; 67 | ffi_prep_raw_closure_loc; 68 | #if !FFI_NATIVE_RAW_API 69 | ffi_prep_java_raw_closure; 70 | ffi_prep_java_raw_closure_loc; 71 | #endif 72 | } LIBFFI_BASE_8.0; 73 | #endif 74 | 75 | #if FFI_GO_CLOSURES 76 | LIBFFI_GO_CLOSURE_8.0 { 77 | global: 78 | ffi_call_go; 79 | ffi_prep_go_closure; 80 | } LIBFFI_CLOSURE_8.0; 81 | #endif 82 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/libffi.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | toolexeclibdir=@toolexeclibdir@ 5 | includedir=@includedir@ 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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | 9:4:1 30 | -------------------------------------------------------------------------------- /libffi-sys-rs/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_sections\n\t.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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/m4/ax_configure_args.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_configure_args.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CONFIGURE_ARGS 8 | # 9 | # DESCRIPTION 10 | # 11 | # Helper macro for AX_ENABLE_BUILDDIR. 12 | # 13 | # The traditional way of starting a subdir-configure is running the script 14 | # with ${1+"$@"} but since autoconf 2.60 this is broken. Instead we have 15 | # to rely on eval'ing $ac_configure_args however some old autoconf 16 | # versions do not provide that. To ensure maximum portability of autoconf 17 | # extension macros this helper can be AC_REQUIRE'd so that 18 | # $ac_configure_args will always be present. 19 | # 20 | # Sadly, the traditional "exec $SHELL" of the enable_builddir macros is 21 | # spoiled now and must be replaced by "eval + exit $?". 22 | # 23 | # Example: 24 | # 25 | # AC_DEFUN([AX_ENABLE_SUBDIR],[dnl 26 | # AC_REQUIRE([AX_CONFIGURE_ARGS])dnl 27 | # eval $SHELL $ac_configure_args || exit $? 28 | # ...]) 29 | # 30 | # LICENSE 31 | # 32 | # Copyright (c) 2008 Guido U. Draheim 33 | # 34 | # Copying and distribution of this file, with or without modification, are 35 | # permitted in any medium without royalty provided the copyright notice 36 | # and this notice are preserved. This file is offered as-is, without any 37 | # warranty. 38 | 39 | #serial 14 40 | 41 | AC_DEFUN([AX_CONFIGURE_ARGS],[ 42 | # [$]@ is unusable in 2.60+ but earlier autoconf had no ac_configure_args 43 | if test "${ac_configure_args+set}" != "set" ; then 44 | ac_configure_args= 45 | for ac_arg in ${1+"[$]@"}; do 46 | ac_configure_args="$ac_configure_args '$ac_arg'" 47 | done 48 | fi 49 | ]) 50 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/m4/ax_prepend_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_prepend_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_PREPEND_FLAG(FLAG, [FLAGS-VARIABLE]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # FLAG is added to the front of the FLAGS-VARIABLE shell variable, with a 12 | # space added in between. 13 | # 14 | # If FLAGS-VARIABLE is not specified, the current language's flags (e.g. 15 | # CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains 16 | # FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly 17 | # FLAG. 18 | # 19 | # NOTE: Implementation based on AX_APPEND_FLAG. 20 | # 21 | # LICENSE 22 | # 23 | # Copyright (c) 2008 Guido U. Draheim 24 | # Copyright (c) 2011 Maarten Bosmans 25 | # Copyright (c) 2018 John Zaitseff 26 | # 27 | # Copying and distribution of this file, with or without modification, are 28 | # permitted in any medium without royalty provided the copyright notice 29 | # and this notice are preserved. This file is offered as-is, without any 30 | # warranty. 31 | 32 | #serial 2 33 | 34 | AC_DEFUN([AX_PREPEND_FLAG], 35 | [dnl 36 | AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF 37 | AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])]) 38 | AS_VAR_SET_IF(FLAGS,[ 39 | AS_CASE([" AS_VAR_GET(FLAGS) "], 40 | [*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])], 41 | [ 42 | FLAGS="$1 $FLAGS" 43 | AC_RUN_LOG([: FLAGS="$FLAGS"]) 44 | ]) 45 | ], 46 | [ 47 | AS_VAR_SET(FLAGS,[$1]) 48 | AC_RUN_LOG([: FLAGS="$FLAGS"]) 49 | ]) 50 | AS_VAR_POPDEF([FLAGS])dnl 51 | ])dnl AX_PREPEND_FLAG 52 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/m4/ax_require_defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 2 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2019, 2021-2022 Free Software Foundation, 4 | # Inc. 5 | # Written by Scott James Remnant, 2004 6 | # 7 | # This file is free software; the Free Software Foundation gives 8 | # unlimited permission to copy and/or distribute it, with or without 9 | # modifications, as long as this notice is preserved. 10 | 11 | # @configure_input@ 12 | 13 | # serial 4245 ltversion.m4 14 | # This file is part of GNU Libtool 15 | 16 | m4_define([LT_PACKAGE_VERSION], [2.4.7]) 17 | m4_define([LT_PACKAGE_REVISION], [2.4.7]) 18 | 19 | AC_DEFUN([LTVERSION_VERSION], 20 | [macro_version='2.4.7' 21 | macro_revision='2.4.7' 22 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 23 | _LT_DECL(, macro_revision, 0) 24 | ]) 25 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/msvc_build/aarch64/Ffi_staticLib.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28302.56 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ffi_staticLib_arm64", "Ffi_staticLib.vcxproj", "{115502C0-BE05-4767-BF19-5C87D805FAD6}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|ARM64 = Debug|ARM64 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | Release|ARM64 = Release|ARM64 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {115502C0-BE05-4767-BF19-5C87D805FAD6}.Debug|ARM64.ActiveCfg = Debug|ARM64 19 | {115502C0-BE05-4767-BF19-5C87D805FAD6}.Debug|ARM64.Build.0 = Debug|ARM64 20 | {115502C0-BE05-4767-BF19-5C87D805FAD6}.Debug|x64.ActiveCfg = Debug|ARM64 21 | {115502C0-BE05-4767-BF19-5C87D805FAD6}.Debug|x86.ActiveCfg = Debug|ARM64 22 | {115502C0-BE05-4767-BF19-5C87D805FAD6}.Release|ARM64.ActiveCfg = Release|ARM64 23 | {115502C0-BE05-4767-BF19-5C87D805FAD6}.Release|ARM64.Build.0 = Release|ARM64 24 | {115502C0-BE05-4767-BF19-5C87D805FAD6}.Release|x64.ActiveCfg = Release|ARM64 25 | {115502C0-BE05-4767-BF19-5C87D805FAD6}.Release|x86.ActiveCfg = Release|ARM64 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(ExtensibilityGlobals) = postSolution 31 | SolutionGuid = {241C54C7-20DD-4897-9376-E6B6D1B43BD5} 32 | EndGlobalSection 33 | EndGlobal 34 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/msvc_build/aarch64/Ffi_staticLib.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/alpha/internal.h: -------------------------------------------------------------------------------- 1 | #define ALPHA_ST_VOID 0 2 | #define ALPHA_ST_INT 1 3 | #define ALPHA_ST_FLOAT 2 4 | #define ALPHA_ST_DOUBLE 3 5 | #define ALPHA_ST_CPLXF 4 6 | #define ALPHA_ST_CPLXD 5 7 | 8 | #define ALPHA_LD_VOID 0 9 | #define ALPHA_LD_INT64 1 10 | #define ALPHA_LD_INT32 2 11 | #define ALPHA_LD_UINT16 3 12 | #define ALPHA_LD_SINT16 4 13 | #define ALPHA_LD_UINT8 5 14 | #define ALPHA_LD_SINT8 6 15 | #define ALPHA_LD_FLOAT 7 16 | #define ALPHA_LD_DOUBLE 8 17 | #define ALPHA_LD_CPLXF 9 18 | #define ALPHA_LD_CPLXD 10 19 | 20 | #define ALPHA_ST_SHIFT 0 21 | #define ALPHA_LD_SHIFT 8 22 | #define ALPHA_RET_IN_MEM 0x10000 23 | #define ALPHA_FLAGS(S, L) (((L) << ALPHA_LD_SHIFT) | (S)) 24 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/arm/internal.h: -------------------------------------------------------------------------------- 1 | #define ARM_TYPE_VFP_S 0 2 | #define ARM_TYPE_VFP_D 1 3 | #define ARM_TYPE_VFP_N 2 4 | #define ARM_TYPE_INT64 3 5 | #define ARM_TYPE_INT 4 6 | #define ARM_TYPE_VOID 5 7 | #define ARM_TYPE_STRUCT 6 8 | 9 | #if defined(FFI_EXEC_STATIC_TRAMP) 10 | /* 11 | * For the trampoline table mapping, a mapping size of 4K (base page size) 12 | * is chosen. 13 | */ 14 | #define ARM_TRAMP_MAP_SHIFT 12 15 | #define ARM_TRAMP_MAP_SIZE (1 << ARM_TRAMP_MAP_SHIFT) 16 | #define ARM_TRAMP_SIZE 20 17 | #endif 18 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/kvx/asm.h: -------------------------------------------------------------------------------- 1 | /* args are passed on registers from r0 up to r11 => 12*8 bytes */ 2 | #define REG_ARGS_SIZE (12*8) 3 | #define KVX_REGISTER_SIZE (8) 4 | #define KVX_ABI_SLOT_SIZE (KVX_REGISTER_SIZE) 5 | #define KVX_ABI_MAX_AGGREGATE_IN_REG_SIZE (4*KVX_ABI_SLOT_SIZE) 6 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/powerpc/t-aix: -------------------------------------------------------------------------------- 1 | # This file is needed by GCC in order to correctly build AIX FAT 2 | # library for libffi. 3 | # However, it has no sense to include this code here, as it depends 4 | # on GCC multilib architecture. 5 | # Thus, this file is a simple stub replaced in GCC repository. 6 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/s390/internal.h: -------------------------------------------------------------------------------- 1 | /* If these values change, sysv.S must be adapted! */ 2 | #define FFI390_RET_DOUBLE 0 3 | #define FFI390_RET_FLOAT 1 4 | #define FFI390_RET_INT64 2 5 | #define FFI390_RET_INT32 3 6 | #define FFI390_RET_VOID 4 7 | 8 | #define FFI360_RET_MASK 7 9 | #define FFI390_RET_IN_MEM 8 10 | 11 | #define FFI390_RET_STRUCT (FFI390_RET_VOID | FFI390_RET_IN_MEM) 12 | 13 | 14 | #if defined(FFI_EXEC_STATIC_TRAMP) 15 | /* 16 | * For the trampoline code table mapping, a mapping size of 4K is chosen. 17 | */ 18 | #define FFI390_TRAMP_MAP_SHIFT 12 19 | #define FFI390_TRAMP_MAP_SIZE (1 << FFI390_TRAMP_MAP_SHIFT) 20 | #define FFI390_TRAMP_SIZE 16 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/sparc/internal.h: -------------------------------------------------------------------------------- 1 | #define SPARC_RET_VOID 0 2 | #define SPARC_RET_STRUCT 1 3 | #define SPARC_RET_UINT8 2 4 | #define SPARC_RET_SINT8 3 5 | #define SPARC_RET_UINT16 4 6 | #define SPARC_RET_SINT16 5 7 | #define SPARC_RET_UINT32 6 8 | #define SP_V9_RET_SINT32 7 /* v9 only */ 9 | #define SP_V8_RET_CPLX16 7 /* v8 only */ 10 | #define SPARC_RET_INT64 8 11 | #define SPARC_RET_INT128 9 12 | 13 | /* Note that F_7 is missing, and is handled by SPARC_RET_STRUCT. */ 14 | #define SPARC_RET_F_8 10 15 | #define SPARC_RET_F_6 11 16 | #define SPARC_RET_F_4 12 17 | #define SPARC_RET_F_2 13 18 | #define SP_V9_RET_F_3 14 /* v9 only */ 19 | #define SP_V8_RET_CPLX8 14 /* v8 only */ 20 | #define SPARC_RET_F_1 15 21 | 22 | #define SPARC_FLAG_RET_MASK 15 23 | #define SPARC_FLAG_RET_IN_MEM 32 24 | #define SPARC_FLAG_FP_ARGS 64 25 | 26 | #define SPARC_SIZEMASK_SHIFT 8 27 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/x86/asmnames.h: -------------------------------------------------------------------------------- 1 | #ifndef ASMNAMES_H 2 | #define ASMNAMES_H 3 | 4 | #define C2(X, Y) X ## Y 5 | #define C1(X, Y) C2(X, Y) 6 | #ifdef __USER_LABEL_PREFIX__ 7 | # define C(X) C1(__USER_LABEL_PREFIX__, X) 8 | #else 9 | # define C(X) X 10 | #endif 11 | 12 | #ifdef __APPLE__ 13 | # define L(X) C1(L, X) 14 | #else 15 | # define L(X) C1(.L, X) 16 | #endif 17 | 18 | #if defined(__ELF__) && defined(__PIC__) 19 | # define PLT(X) X@PLT 20 | #else 21 | # define PLT(X) X 22 | #endif 23 | 24 | #ifdef __ELF__ 25 | # define ENDF(X) .type X,@function; .size X, . - X 26 | #else 27 | # define ENDF(X) 28 | #endif 29 | 30 | #endif /* ASMNAMES_H */ 31 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/x86/internal.h: -------------------------------------------------------------------------------- 1 | #define X86_RET_FLOAT 0 2 | #define X86_RET_DOUBLE 1 3 | #define X86_RET_LDOUBLE 2 4 | #define X86_RET_SINT8 3 5 | #define X86_RET_SINT16 4 6 | #define X86_RET_UINT8 5 7 | #define X86_RET_UINT16 6 8 | #define X86_RET_INT64 7 9 | #define X86_RET_INT32 8 10 | #define X86_RET_VOID 9 11 | #define X86_RET_STRUCTPOP 10 12 | #define X86_RET_STRUCTARG 11 13 | #define X86_RET_STRUCT_1B 12 14 | #define X86_RET_STRUCT_2B 13 15 | #define X86_RET_UNUSED14 14 16 | #define X86_RET_UNUSED15 15 17 | 18 | #define X86_RET_TYPE_MASK 15 19 | #define X86_RET_POP_SHIFT 4 20 | 21 | #define R_EAX 0 22 | #define R_EDX 1 23 | #define R_ECX 2 24 | 25 | #ifdef __PCC__ 26 | # define HAVE_FASTCALL 0 27 | #else 28 | # define HAVE_FASTCALL 1 29 | #endif 30 | 31 | #if defined(FFI_EXEC_STATIC_TRAMP) 32 | /* 33 | * For the trampoline code table mapping, a mapping size of 4K (base page size) 34 | * is chosen. 35 | */ 36 | #define X86_TRAMP_MAP_SHIFT 12 37 | #define X86_TRAMP_MAP_SIZE (1 << X86_TRAMP_MAP_SHIFT) 38 | #ifdef ENDBR_PRESENT 39 | #define X86_TRAMP_SIZE 44 40 | #else 41 | #define X86_TRAMP_SIZE 40 42 | #endif 43 | #endif 44 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/src/x86/internal64.h: -------------------------------------------------------------------------------- 1 | #define UNIX64_RET_VOID 0 2 | #define UNIX64_RET_UINT8 1 3 | #define UNIX64_RET_UINT16 2 4 | #define UNIX64_RET_UINT32 3 5 | #define UNIX64_RET_SINT8 4 6 | #define UNIX64_RET_SINT16 5 7 | #define UNIX64_RET_SINT32 6 8 | #define UNIX64_RET_INT64 7 9 | #define UNIX64_RET_XMM32 8 10 | #define UNIX64_RET_XMM64 9 11 | #define UNIX64_RET_X87 10 12 | #define UNIX64_RET_X87_2 11 13 | #define UNIX64_RET_ST_XMM0_RAX 12 14 | #define UNIX64_RET_ST_RAX_XMM0 13 15 | #define UNIX64_RET_ST_XMM0_XMM1 14 16 | #define UNIX64_RET_ST_RAX_RDX 15 17 | 18 | #define UNIX64_RET_LAST 15 19 | 20 | #define UNIX64_FLAG_RET_IN_MEM (1 << 10) 21 | #define UNIX64_FLAG_XMM_ARGS (1 << 11) 22 | #define UNIX64_SIZE_SHIFT 12 23 | 24 | #if defined(FFI_EXEC_STATIC_TRAMP) 25 | /* 26 | * For the trampoline code table mapping, a mapping size of 4K (base page size) 27 | * is chosen. 28 | */ 29 | #define UNIX64_TRAMP_MAP_SHIFT 12 30 | #define UNIX64_TRAMP_MAP_SIZE (1 << UNIX64_TRAMP_MAP_SHIFT) 31 | #ifdef ENDBR_PRESENT 32 | #define UNIX64_TRAMP_SIZE 40 33 | #else 34 | #define UNIX64_TRAMP_SIZE 32 35 | #endif 36 | #endif 37 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/config/default.exp: -------------------------------------------------------------------------------- 1 | load_lib "standard.exp" 2 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/emscripten/build-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if ! [ -x "$(command -v emcc)" ]; then 4 | echo "Error: emcc could not be found." >&2 5 | exit 1 6 | fi 7 | 8 | set -e 9 | 10 | cd "$1" 11 | shift 12 | 13 | export CFLAGS="-fPIC -O2 -I../../target/include $EXTRA_CFLAGS" 14 | export CXXFLAGS="$CFLAGS -sNO_DISABLE_EXCEPTION_CATCHING $EXTRA_CXXFLAGS" 15 | export LDFLAGS=" \ 16 | -L../../target/lib/ -lffi \ 17 | -sEXPORT_ALL \ 18 | -sMODULARIZE \ 19 | -sMAIN_MODULE \ 20 | -sNO_DISABLE_EXCEPTION_CATCHING \ 21 | -sWASM_BIGINT \ 22 | $EXTRA_LD_FLAGS \ 23 | " 24 | 25 | # Rename main functions to test__filename so we can link them together 26 | ls *c | sed 's!\(.*\)\.c!sed -i "s/main/test__\1/g" \0!g' | bash 27 | 28 | # Compile 29 | ls *.c | sed 's/\(.*\)\.c/emcc $CFLAGS -c \1.c -o \1.o /g' | bash 30 | ls *.cc | sed 's/\(.*\)\.cc/em++ $CXXFLAGS -c \1.cc -o \1.o /g' | bash 31 | 32 | # Link 33 | em++ $LDFLAGS *.o -o test.js 34 | cp ../emscripten/test.html . 35 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/emscripten/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if ! [ -x "$(command -v emcc)" ]; then 4 | echo "Error: emcc could not be found." >&2 5 | exit 1 6 | fi 7 | 8 | set -e 9 | 10 | SOURCE_DIR=$PWD 11 | 12 | # Working directories 13 | TARGET=$SOURCE_DIR/target 14 | mkdir -p "$TARGET" 15 | 16 | # Define default arguments 17 | DEBUG=false 18 | 19 | # Parse arguments 20 | while [ $# -gt 0 ]; do 21 | case $1 in 22 | --debug) DEBUG=true ;; 23 | *) echo "ERROR: Unknown parameter: $1" >&2; exit 1 ;; 24 | esac 25 | shift 26 | done 27 | 28 | # Common compiler flags 29 | export CFLAGS="-O3 -fPIC" 30 | if [ "$DEBUG" = "true" ]; then export CFLAGS+=" -DDEBUG_F"; fi 31 | export CXXFLAGS="$CFLAGS" 32 | 33 | # Build paths 34 | export CPATH="$TARGET/include" 35 | export PKG_CONFIG_PATH="$TARGET/lib/pkgconfig" 36 | export EM_PKG_CONFIG_PATH="$PKG_CONFIG_PATH" 37 | 38 | # Specific variables for cross-compilation 39 | export CHOST="wasm32-unknown-linux" # wasm32-unknown-emscripten 40 | 41 | autoreconf -fiv 42 | emconfigure ./configure --host=$CHOST --prefix="$TARGET" --enable-static --disable-shared --disable-dependency-tracking \ 43 | --disable-builddir --disable-multi-os-directory --disable-raw-api --disable-docs 44 | make install 45 | cp fficonfig.h target/include/ 46 | cp include/ffi_common.h target/include/ 47 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/emscripten/node-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! [ -x "$(command -v emcc)" ]; then 4 | echo "Error: emcc could not be found." >&2 5 | exit 1 6 | fi 7 | 8 | # Common compiler flags 9 | export CFLAGS="-fPIC $EXTRA_CFLAGS" 10 | export CXXFLAGS="$CFLAGS -sNO_DISABLE_EXCEPTION_CATCHING $EXTRA_CXXFLAGS" 11 | export LDFLAGS="-sEXPORTED_FUNCTIONS=_main,_malloc,_free -sALLOW_TABLE_GROWTH -sASSERTIONS -sNO_DISABLE_EXCEPTION_CATCHING -sWASM_BIGINT" 12 | 13 | # Specific variables for cross-compilation 14 | export CHOST="wasm32-unknown-linux" # wasm32-unknown-emscripten 15 | 16 | autoreconf -fiv 17 | emconfigure ./configure --prefix="$(pwd)/target" --host=$CHOST --enable-static --disable-shared \ 18 | --disable-builddir --disable-multi-os-directory --disable-raw-api --disable-docs || 19 | (cat config.log && exit 1) 20 | make 21 | 22 | EMMAKEN_JUST_CONFIGURE=1 emmake make check \ 23 | RUNTESTFLAGS="LDFLAGS_FOR_TARGET='$LDFLAGS'" || (cat testsuite/libffi.log && exit 1) 24 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/emscripten/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/emscripten/test_libffi.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import pathlib 3 | import pytest 4 | 5 | TEST_PATH = pathlib.Path(__file__).parents[1].resolve() 6 | 7 | xfails = {} 8 | 9 | 10 | def libffi_tests(self, selenium, libffi_test): 11 | if libffi_test in xfails: 12 | pytest.xfail(f'known failure with code "{xfails[libffi_test]}"') 13 | res = selenium.run_js( 14 | """ 15 | window.TestModule = await Module(); 16 | """ 17 | ) 18 | selenium.run_js( 19 | f""" 20 | try {{ 21 | TestModule._test__{libffi_test}(); 22 | }} catch(e){{ 23 | if(e.name !== "ExitStatus"){{ 24 | throw e; 25 | }} 26 | if(e.status !== 0){{ 27 | throw new Error(`Terminated with nonzero status code ${{e.status}}: ` + e.message); 28 | }} 29 | }} 30 | """ 31 | ) 32 | 33 | 34 | class TestCall: 35 | TEST_BUILD_DIR = "libffi.call.test" 36 | test_call = libffi_tests 37 | 38 | 39 | class TestClosures: 40 | TEST_BUILD_DIR = "libffi.closures.test" 41 | test_closures = libffi_tests 42 | 43 | 44 | def pytest_generate_tests(metafunc): 45 | test_build_dir = metafunc.cls.TEST_BUILD_DIR 46 | test_names = [x.stem for x in (TEST_PATH / test_build_dir).glob("*.o")] 47 | metafunc.parametrize("libffi_test", test_names) 48 | 49 | 50 | if __name__ == "__main__": 51 | subprocess.call(["build-tests.sh", "libffi.call"]) 52 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.bhaible/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -O2 -Wall 3 | prefix = 4 | includedir = $(prefix)/include 5 | libdir = $(prefix)/lib 6 | CPPFLAGS = -I$(includedir) 7 | LDFLAGS = -L$(libdir) -Wl,-rpath,$(libdir) 8 | 9 | all: check-call check-callback 10 | 11 | test-call: test-call.c testcases.c 12 | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o test-call test-call.c -lffi 13 | 14 | test-callback: test-callback.c testcases.c 15 | $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o test-callback test-callback.c -lffi 16 | 17 | check-call: test-call 18 | ./test-call > test-call.out 19 | LC_ALL=C uniq -u < test-call.out > failed-call 20 | test '!' -s failed-call 21 | 22 | check-callback: test-callback 23 | ./test-callback > test-callback.out 24 | LC_ALL=C uniq -u < test-callback.out > failed-callback 25 | test '!' -s failed-callback 26 | 27 | clean: 28 | rm -f test-call test-callback test-call.out test-callback.out failed-call failed-callback 29 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/align_mixed.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check for proper argument alignment. 3 | Limitations: none. 4 | PR: none. 5 | Originator: (from many_win32.c) */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static float ABI_ATTR align_arguments(int i1, 12 | double f2, 13 | int i3, 14 | double f4) 15 | { 16 | return i1+f2+i3+f4; 17 | } 18 | 19 | int main(void) 20 | { 21 | ffi_cif cif; 22 | ffi_type *args[4] = { 23 | &ffi_type_sint, 24 | &ffi_type_double, 25 | &ffi_type_sint, 26 | &ffi_type_double 27 | }; 28 | double fa[2] = {1,2}; 29 | int ia[2] = {1,2}; 30 | void *values[4] = {&ia[0], &fa[0], &ia[1], &fa[1]}; 31 | float f, ff; 32 | 33 | /* Initialize the cif */ 34 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 4, 35 | &ffi_type_float, args) == FFI_OK); 36 | 37 | ff = align_arguments(ia[0], fa[0], ia[1], fa[1]); 38 | 39 | ffi_call(&cif, FFI_FN(align_arguments), &f, values); 40 | 41 | if (f == ff) 42 | printf("align arguments tests ok!\n"); 43 | else 44 | CHECK(0); 45 | exit(0); 46 | } 47 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/align_stdcall.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check for proper argument alignment. 3 | Limitations: none. 4 | PR: none. 5 | Originator: (from many_win32.c) */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "ffitest.h" 10 | 11 | static float ABI_ATTR align_arguments(int i1, 12 | double f2, 13 | int i3, 14 | double f4) 15 | { 16 | return i1+f2+i3+f4; 17 | } 18 | 19 | int main(void) 20 | { 21 | ffi_cif cif; 22 | ffi_type *args[4] = { 23 | &ffi_type_sint, 24 | &ffi_type_double, 25 | &ffi_type_sint, 26 | &ffi_type_double 27 | }; 28 | double fa[2] = {1,2}; 29 | int ia[2] = {1,2}; 30 | void *values[4] = {&ia[0], &fa[0], &ia[1], &fa[1]}; 31 | float f, ff; 32 | 33 | /* Initialize the cif */ 34 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 4, 35 | &ffi_type_float, args) == FFI_OK); 36 | 37 | ff = align_arguments(ia[0], fa[0], ia[1], fa[1]);; 38 | 39 | ffi_call(&cif, FFI_FN(align_arguments), &f, values); 40 | 41 | if (f == ff) 42 | printf("align arguments tests ok!\n"); 43 | else 44 | CHECK(0); 45 | exit(0); 46 | } 47 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/bpo_38748.c: -------------------------------------------------------------------------------- 1 | /* Area: bpo-38748 2 | Purpose: test for stdcall alignment problem 3 | Source: github.com/python/cpython/pull/26204 */ 4 | 5 | /* { dg-do run } */ 6 | 7 | #include "ffitest.h" 8 | #include "ffi_common.h" 9 | 10 | static UINT32 ABI_ATTR align_arguments(UINT32 l1, 11 | UINT64 l2) 12 | { 13 | return l1 + (UINT32) l2; 14 | } 15 | 16 | int main(void) 17 | { 18 | ffi_cif cif; 19 | ffi_type *args[4] = { 20 | &ffi_type_uint32, 21 | &ffi_type_uint64 22 | }; 23 | ffi_arg lr1, lr2; 24 | UINT32 l1 = 1; 25 | UINT64 l2 = 2; 26 | void *values[2] = {&l1, &l2}; 27 | 28 | /* Initialize the cif */ 29 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, 30 | &ffi_type_uint32, args) == FFI_OK); 31 | 32 | lr1 = align_arguments(l1, l2); 33 | 34 | ffi_call(&cif, FFI_FN(align_arguments), &lr2, values); 35 | 36 | if (lr1 == lr2) 37 | printf("bpo-38748 arguments tests ok!\n"); 38 | else 39 | CHECK(0); 40 | exit(0); 41 | } 42 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/call.exp: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2003, 2006, 2009, 2010, 2014 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 | if { [string match $compiler_vendor "microsoft"] } { 23 | # -wd4005 macro redefinition 24 | # -wd4244 implicit conversion to type of smaller size 25 | # -wd4305 truncation to smaller type 26 | # -wd4477 printf %lu of uintptr_t 27 | # -wd4312 implicit conversion to type of greater size 28 | # -wd4311 pointer truncation to unsigned long 29 | # -EHsc C++ Exception Handling (no SEH exceptions) 30 | set additional_options "-wd4005 -wd4244 -wd4305 -wd4477 -wd4312 -wd4311 -EHsc"; 31 | } else { 32 | set additional_options ""; 33 | } 34 | 35 | set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.c]] 36 | 37 | run-many-tests $tlist $additional_options 38 | 39 | set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.cc]] 40 | 41 | # No C++ for or1k 42 | if { [istarget "or1k-*-*"] } { 43 | foreach test $tlist { 44 | unsupported "$test" 45 | } 46 | } else { 47 | run-many-tests $tlist $additional_options 48 | } 49 | 50 | dg-finish 51 | 52 | # Local Variables: 53 | # tcl-indent-level:4 54 | # End: 55 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | #include 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(float f) 22 | { 23 | return f/3.0; 24 | } 25 | 26 | int main (void) 27 | { 28 | ffi_cif cif; 29 | ffi_type *args[MAX_ARGS]; 30 | void *values[MAX_ARGS]; 31 | float f; 32 | value_type result[2]; 33 | unsigned int i; 34 | 35 | args[0] = &ffi_type_float; 36 | values[0] = &f; 37 | 38 | /* Initialize the cif */ 39 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 40 | &ffi_type_double, args) == FFI_OK); 41 | 42 | f = 3.14159; 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 | /* These are not always the same!! Check for a reasonable delta */ 51 | 52 | CHECK(fabs(result[0].d - dblit(f)) < DBL_EPSILON); 53 | 54 | /* Check the canary. */ 55 | for (i = 0; i < sizeof (double); ++i) 56 | CHECK(result[1].c[i] == CANARY); 57 | 58 | exit(0); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | /* { dg-do run } */ 7 | 8 | #include "ffitest.h" 9 | #include "float.h" 10 | 11 | #include 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 | long double original; 26 | 27 | args[0] = &ffi_type_float; 28 | values[0] = &f; 29 | 30 | /* Initialize the cif */ 31 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 32 | &ffi_type_longdouble, args) == FFI_OK); 33 | 34 | f = 3.14159; 35 | 36 | #if defined(__sun) && defined(__GNUC__) 37 | /* long double support under SunOS/gcc is pretty much non-existent. 38 | You'll get the odd bus error in library routines like printf() */ 39 | #else 40 | printf ("%Lf\n", ldblit(f)); 41 | #endif 42 | 43 | ld = 666; 44 | ffi_call(&cif, FFI_FN(ldblit), &ld, values); 45 | 46 | #if defined(__sun) && defined(__GNUC__) 47 | /* long double support under SunOS/gcc is pretty much non-existent. 48 | You'll get the odd bus error in library routines like printf() */ 49 | #else 50 | printf ("%Lf, %Lf, %Lf, %Lf\n", ld, ldblit(f), ld - ldblit(f), LDBL_EPSILON); 51 | #endif 52 | 53 | /* These are not always the same!! Check for a reasonable delta */ 54 | original = ldblit(f); 55 | if (((ld > original) ? (ld - original) : (original - ld)) < LDBL_EPSILON) 56 | puts("long double return value tests ok!"); 57 | else 58 | CHECK(0); 59 | 60 | exit(0); 61 | } 62 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | #include 13 | 14 | static double floating_1(float a, double b, long double c) 15 | { 16 | return (double) a + b + (double) c; 17 | } 18 | 19 | static double floating_2(long double a, double b, float c) 20 | { 21 | return (double) a + b + (double) c; 22 | } 23 | 24 | int main (void) 25 | { 26 | ffi_cif cif; 27 | ffi_type *args[MAX_ARGS]; 28 | void *values[MAX_ARGS]; 29 | double rd; 30 | 31 | float f; 32 | double d; 33 | long double ld; 34 | 35 | args[0] = &ffi_type_float; 36 | values[0] = &f; 37 | args[1] = &ffi_type_double; 38 | values[1] = &d; 39 | args[2] = &ffi_type_longdouble; 40 | values[2] = &ld; 41 | 42 | /* Initialize the cif */ 43 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 44 | &ffi_type_double, args) == FFI_OK); 45 | 46 | f = 3.14159; 47 | d = (double)1.0/(double)3.0; 48 | ld = 2.71828182846L; 49 | 50 | floating_1 (f, d, ld); 51 | 52 | ffi_call(&cif, FFI_FN(floating_1), &rd, values); 53 | 54 | CHECK(fabs(rd - floating_1(f, d, ld)) < DBL_EPSILON); 55 | 56 | args[0] = &ffi_type_longdouble; 57 | values[0] = &ld; 58 | args[1] = &ffi_type_double; 59 | values[1] = &d; 60 | args[2] = &ffi_type_float; 61 | values[2] = &f; 62 | 63 | /* Initialize the cif */ 64 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 65 | &ffi_type_double, args) == FFI_OK); 66 | 67 | floating_2 (ld, d, f); 68 | 69 | ffi_call(&cif, FFI_FN(floating_2), &rd, values); 70 | 71 | CHECK(fabs(rd - floating_2(ld, d, f)) < DBL_EPSILON); 72 | 73 | exit (0); 74 | } 75 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/many_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double, 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 double many(double f1, 15 | double f2, 16 | double f3, 17 | double f4, 18 | double f5, 19 | double f6, 20 | double f7, 21 | double f8, 22 | double f9, 23 | double f10, 24 | double f11, 25 | double f12, 26 | double f13) 27 | { 28 | #if 0 29 | printf("%f %f %f %f %f %f %f %f %f %f %f %f %f\n", 30 | (double) f1, (double) f2, (double) f3, (double) f4, (double) f5, 31 | (double) f6, (double) f7, (double) f8, (double) f9, (double) f10, 32 | (double) f11, (double) f12, (double) f13); 33 | #endif 34 | 35 | return ((f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12) * f13); 36 | } 37 | 38 | int main (void) 39 | { 40 | ffi_cif cif; 41 | ffi_type *args[13]; 42 | void *values[13]; 43 | double fa[13]; 44 | double f, ff; 45 | int i; 46 | 47 | for (i = 0; i < 13; i++) 48 | { 49 | args[i] = &ffi_type_double; 50 | values[i] = &fa[i]; 51 | fa[i] = (double) i; 52 | } 53 | 54 | /* Initialize the cif */ 55 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 13, 56 | &ffi_type_double, args) == FFI_OK); 57 | 58 | ffi_call(&cif, FFI_FN(many), &f, values); 59 | 60 | ff = many(fa[0], fa[1], 61 | fa[2], fa[3], 62 | fa[4], fa[5], 63 | fa[6], fa[7], 64 | fa[8], fa[9], 65 | fa[10],fa[11],fa[12]); 66 | if (fabs(f - ff) < FLT_EPSILON) 67 | exit(0); 68 | else 69 | abort(); 70 | } 71 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/many_mixed.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value double, 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 double many(double f1, 15 | double f2, 16 | long int i1, 17 | double f3, 18 | double f4, 19 | long int i2, 20 | double f5, 21 | double f6, 22 | long int i3, 23 | double f7, 24 | double f8, 25 | long int i4, 26 | double f9, 27 | double f10, 28 | long int i5, 29 | double f11, 30 | double f12, 31 | long int i6, 32 | double f13) 33 | { 34 | return ((double) (i1 + i2 + i3 + i4 + i5 + i6) + (f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12) * f13); 35 | } 36 | 37 | int main (void) 38 | { 39 | ffi_cif cif; 40 | ffi_type *args[19]; 41 | void *values[19]; 42 | double fa[19]; 43 | long int la[19]; 44 | double f, ff; 45 | int i; 46 | 47 | for (i = 0; i < 19; i++) 48 | { 49 | if( (i - 2) % 3 == 0) { 50 | args[i] = &ffi_type_slong; 51 | la[i] = (long int) i; 52 | values[i] = &la[i]; 53 | } 54 | else { 55 | args[i] = &ffi_type_double; 56 | fa[i] = (double) i; 57 | values[i] = &fa[i]; 58 | } 59 | } 60 | 61 | /* Initialize the cif */ 62 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 19, 63 | &ffi_type_double, args) == FFI_OK); 64 | 65 | ffi_call(&cif, FFI_FN(many), &f, values); 66 | 67 | ff = many(fa[0], fa[1], la[2], 68 | fa[3], fa[4], la[5], 69 | fa[6], fa[7], la[8], 70 | fa[9], fa[10], la[11], 71 | fa[12], fa[13], la[14], 72 | fa[15], fa[16], la[17], 73 | fa[18]); 74 | if (fabs(f - ff) < FLT_EPSILON) 75 | exit(0); 76 | else 77 | abort(); 78 | } 79 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/offsets.c: -------------------------------------------------------------------------------- 1 | /* Area: Struct layout 2 | Purpose: Test ffi_get_struct_offsets 3 | Limitations: none. 4 | PR: none. 5 | Originator: Tom Tromey. */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | #include 10 | 11 | struct test_1 12 | { 13 | char c; 14 | float f; 15 | char c2; 16 | int i; 17 | }; 18 | 19 | int 20 | main (void) 21 | { 22 | ffi_type test_1_type; 23 | ffi_type *test_1_elements[5]; 24 | size_t test_1_offsets[4]; 25 | 26 | test_1_elements[0] = &ffi_type_schar; 27 | test_1_elements[1] = &ffi_type_float; 28 | test_1_elements[2] = &ffi_type_schar; 29 | test_1_elements[3] = &ffi_type_sint; 30 | test_1_elements[4] = NULL; 31 | 32 | test_1_type.size = 0; 33 | test_1_type.alignment = 0; 34 | test_1_type.type = FFI_TYPE_STRUCT; 35 | test_1_type.elements = test_1_elements; 36 | 37 | CHECK (ffi_get_struct_offsets (FFI_DEFAULT_ABI, &test_1_type, test_1_offsets) 38 | == FFI_OK); 39 | CHECK (test_1_type.size == sizeof (struct test_1)); 40 | CHECK (offsetof (struct test_1, c) == test_1_offsets[0]); 41 | CHECK (offsetof (struct test_1, f) == test_1_offsets[1]); 42 | CHECK (offsetof (struct test_1, c2) == test_1_offsets[2]); 43 | CHECK (offsetof (struct test_1, i) == test_1_offsets[3]); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | /* { dg-do run } */ 7 | 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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | CHECK(ll0 == 11111111); 13 | CHECK(ll1 == 11111111111000LL); 14 | CHECK(ll2 == 11111111); 15 | return ll0 + ll1 + ll2; 16 | } 17 | 18 | int main (void) 19 | { 20 | ffi_cif cif; 21 | ffi_type *args[MAX_ARGS]; 22 | void *values[MAX_ARGS]; 23 | long long rlonglong; 24 | long long ll1; 25 | unsigned ll0, ll2; 26 | 27 | args[0] = &ffi_type_sint; 28 | args[1] = &ffi_type_sint64; 29 | args[2] = &ffi_type_sint; 30 | values[0] = &ll0; 31 | values[1] = &ll1; 32 | values[2] = &ll2; 33 | 34 | /* Initialize the cif */ 35 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 36 | &ffi_type_sint64, args) == FFI_OK); 37 | 38 | ll0 = 11111111; 39 | ll1 = 11111111111000LL; 40 | ll2 = 11111111; 41 | 42 | ffi_call(&cif, FFI_FN(return_ll), &rlonglong, values); 43 | printf("res: %" PRIdLL ", %" PRIdLL "\n", rlonglong, ll0 + ll1 + ll2); 44 | /* { dg-output "res: 11111133333222, 11111133333222" } */ 45 | CHECK(rlonglong == 11111133333222); 46 | CHECK(ll0 + ll1 + ll2 == 11111133333222); 47 | exit(0); 48 | } 49 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | CHECK(l1 == 1073741823L); 12 | CHECK(l2 == 1073741824L); 13 | return l1 - l2; 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 res; 22 | unsigned long l1, l2; 23 | 24 | args[0] = &ffi_type_slong; 25 | args[1] = &ffi_type_slong; 26 | values[0] = &l1; 27 | values[1] = &l2; 28 | 29 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 30 | &ffi_type_slong, args) == FFI_OK); 31 | 32 | l1 = 1073741823L; 33 | l2 = 1073741824L; 34 | 35 | ffi_call(&cif, FFI_FN(return_sl), &res, values); 36 | printf("res: %ld, %ld\n", (long)res, l1 - l2); 37 | /* { dg-output "res: -1, -1" } */ 38 | CHECK((long)res == -1); 39 | CHECK(l1 + 1 == l2); 40 | 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | CHECK(ul1 == 1073741823L); 12 | CHECK(ul2 == 1073741824L); 13 | return ul1 + ul2; 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 res; 22 | unsigned long ul1, ul2; 23 | 24 | args[0] = &ffi_type_ulong; 25 | args[1] = &ffi_type_ulong; 26 | values[0] = &ul1; 27 | values[1] = &ul2; 28 | 29 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 30 | &ffi_type_ulong, args) == FFI_OK); 31 | 32 | ul1 = 1073741823L; 33 | ul2 = 1073741824L; 34 | 35 | ffi_call(&cif, FFI_FN(return_ul), &res, values); 36 | printf("res: %lu, %lu\n", (unsigned long)res, ul1 + ul2); 37 | /* { dg-output "res: 2147483647, 2147483647" } */ 38 | CHECK(res == 2147483647L); 39 | CHECK(ul1 + ul2 == 2147483647L); 40 | 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/s55.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 | } s55; 14 | 15 | static s55 ABI_ATTR f55(s55 ts, float f) 16 | { 17 | s55 r; 18 | r.f = ts.f + f; 19 | printf ("f55>> %g + %g = %g\n", ts.f, f, r.f); 20 | return r; 21 | } 22 | 23 | int main (void) 24 | { 25 | ffi_cif cif; 26 | s55 F, Fr; 27 | float f; 28 | void *values[] = { &F, &f }; 29 | ffi_type s55_type; 30 | ffi_type *args[] = { &s55_type, &ffi_type_float }; 31 | ffi_type *s55_type_elements[] = { &ffi_type_float, NULL }; 32 | 33 | /* This is a hack to get a properly aligned result buffer */ 34 | s55 *s55_result = 35 | (s55 *) malloc (sizeof(s55)); 36 | 37 | s55_type.size = 0; 38 | s55_type.alignment = 0; 39 | s55_type.type = FFI_TYPE_STRUCT; 40 | s55_type.elements = s55_type_elements; 41 | 42 | /* Initialize the cif */ 43 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &s55_type, args) == FFI_OK); 44 | 45 | F.f = 1; 46 | Fr = f55(F, 2.14); 47 | printf ("%g\n", Fr.f); 48 | 49 | F.f = 1; 50 | f = 2.14; 51 | ffi_call(&cif, FFI_FN(f55), s55_result, values); 52 | printf ("%g\n", s55_result->f); 53 | 54 | fflush(0); 55 | 56 | CHECK(fabs(Fr.f - s55_result->f) < FLT_EPSILON); 57 | 58 | free (s55_result); 59 | exit(0); 60 | } 61 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 unsigned int ABI_ATTR my_strlen(char *s) 11 | { 12 | return (unsigned int) (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_uint, 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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 int ABI_ATTR my_f(char *s, float a) 12 | { 13 | return (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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 int ABI_ATTR my_f(float a, char *s) 12 | { 13 | return (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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 int ABI_ATTR my_f(float a, char *s, int i) 12 | { 13 | return (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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/struct10.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check structures. 3 | Limitations: none. 4 | PR: none. 5 | Originator: Sergei Trofimovich 6 | 7 | The test originally discovered in ruby's bindings 8 | for ffi in https://bugs.gentoo.org/634190 */ 9 | 10 | /* { dg-do run } */ 11 | #include "ffitest.h" 12 | 13 | struct s { 14 | int s32; 15 | float f32; 16 | signed char s8; 17 | }; 18 | 19 | struct s ABI_ATTR make_s(void) { 20 | struct s r; 21 | r.s32 = 0x1234; 22 | r.f32 = 7.0; 23 | r.s8 = 0x78; 24 | return r; 25 | } 26 | 27 | int main() { 28 | ffi_cif cif; 29 | struct s r; 30 | ffi_type rtype; 31 | ffi_type* s_fields[] = { 32 | &ffi_type_sint, 33 | &ffi_type_float, 34 | &ffi_type_schar, 35 | NULL, 36 | }; 37 | 38 | rtype.size = 0; 39 | rtype.alignment = 0, 40 | rtype.type = FFI_TYPE_STRUCT, 41 | rtype.elements = s_fields, 42 | 43 | r.s32 = 0xbad; 44 | r.f32 = 999.999; 45 | r.s8 = 0x51; 46 | 47 | // Here we emulate the following call: 48 | //r = make_s(); 49 | 50 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &rtype, NULL) == FFI_OK); 51 | ffi_call(&cif, FFI_FN(make_s), &r, NULL); 52 | 53 | CHECK(r.s32 == 0x1234); 54 | CHECK(r.f32 == 7.0); 55 | CHECK(r.s8 == 0x78); 56 | exit(0); 57 | } 58 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/struct_by_value_2.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 int ui01; 13 | unsigned int ui02; 14 | } test_structure_1; 15 | 16 | static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) 17 | { 18 | ts.ui02++; 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 ts1_type; 29 | ffi_type *ts1_type_elements[3]; 30 | 31 | test_structure_1 ts1_arg; 32 | 33 | /* This is a hack to get a properly aligned result buffer */ 34 | test_structure_1 *ts1_result = 35 | (test_structure_1 *) malloc (sizeof(test_structure_1)); 36 | 37 | ts1_type.size = 0; 38 | ts1_type.alignment = 0; 39 | ts1_type.type = FFI_TYPE_STRUCT; 40 | ts1_type.elements = ts1_type_elements; 41 | ts1_type_elements[0] = &ffi_type_uint; 42 | ts1_type_elements[1] = &ffi_type_uint; 43 | ts1_type_elements[2] = NULL; 44 | 45 | args[0] = &ts1_type; 46 | values[0] = &ts1_arg; 47 | 48 | /* Initialize the cif */ 49 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, 50 | &ts1_type, args) == FFI_OK); 51 | 52 | ts1_arg.ui02 = 555; 53 | 54 | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); 55 | 56 | CHECK(ts1_result->ui02 == 556); 57 | 58 | /* This will fail if ffi_call isn't passing the struct by value. */ 59 | CHECK(ts1_arg.ui02 == 555); 60 | 61 | free (ts1_result); 62 | exit(0); 63 | } 64 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/struct_by_value_3.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 int ui01; 13 | unsigned int ui02; 14 | unsigned int ui03; 15 | } test_structure_1; 16 | 17 | static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) 18 | { 19 | ts.ui03++; 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 ts1_type; 30 | ffi_type *ts1_type_elements[4]; 31 | 32 | test_structure_1 ts1_arg; 33 | 34 | /* This is a hack to get a properly aligned result buffer */ 35 | test_structure_1 *ts1_result = 36 | (test_structure_1 *) malloc (sizeof(test_structure_1)); 37 | 38 | ts1_type.size = 0; 39 | ts1_type.alignment = 0; 40 | ts1_type.type = FFI_TYPE_STRUCT; 41 | ts1_type.elements = ts1_type_elements; 42 | ts1_type_elements[0] = &ffi_type_uint; 43 | ts1_type_elements[1] = &ffi_type_uint; 44 | ts1_type_elements[2] = &ffi_type_uint; 45 | ts1_type_elements[3] = NULL; 46 | 47 | args[0] = &ts1_type; 48 | values[0] = &ts1_arg; 49 | 50 | /* Initialize the cif */ 51 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, 52 | &ts1_type, args) == FFI_OK); 53 | 54 | ts1_arg.ui03 = 555; 55 | 56 | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); 57 | 58 | CHECK(ts1_result->ui03 == 556); 59 | 60 | /* This will fail if ffi_call isn't passing the struct by value. */ 61 | CHECK(ts1_arg.ui03 == 555); 62 | 63 | free (ts1_result); 64 | exit(0); 65 | } 66 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/struct_by_value_3f.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 f01; 13 | float f02; 14 | float f03; 15 | } test_structure_1; 16 | 17 | static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) 18 | { 19 | ts.f03++; 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 ts1_type; 30 | ffi_type *ts1_type_elements[5]; 31 | 32 | test_structure_1 ts1_arg; 33 | 34 | /* This is a hack to get a properly aligned result buffer */ 35 | test_structure_1 *ts1_result = 36 | (test_structure_1 *) malloc (sizeof(test_structure_1)); 37 | 38 | ts1_type.size = 0; 39 | ts1_type.alignment = 0; 40 | ts1_type.type = FFI_TYPE_STRUCT; 41 | ts1_type.elements = ts1_type_elements; 42 | ts1_type_elements[0] = &ffi_type_float; 43 | ts1_type_elements[1] = &ffi_type_float; 44 | ts1_type_elements[2] = &ffi_type_float; 45 | ts1_type_elements[3] = NULL; 46 | 47 | args[0] = &ts1_type; 48 | values[0] = &ts1_arg; 49 | 50 | /* Initialize the cif */ 51 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, 52 | &ts1_type, args) == FFI_OK); 53 | 54 | ts1_arg.f03 = 555.5; 55 | 56 | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); 57 | 58 | CHECK(fabs(ts1_result->f03 - 556.5) < FLT_EPSILON); 59 | 60 | /* This will fail if ffi_call isn't passing the struct by value. */ 61 | CHECK(fabs(ts1_arg.f03 - 555.5) < FLT_EPSILON); 62 | 63 | free (ts1_result); 64 | exit(0); 65 | } 66 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/struct_by_value_4.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 int ui01; 13 | unsigned int ui02; 14 | unsigned int ui03; 15 | unsigned int ui04; 16 | } test_structure_1; 17 | 18 | static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) 19 | { 20 | ts.ui04++; 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 ts1_type; 31 | ffi_type *ts1_type_elements[5]; 32 | 33 | test_structure_1 ts1_arg; 34 | 35 | /* This is a hack to get a properly aligned result buffer */ 36 | test_structure_1 *ts1_result = 37 | (test_structure_1 *) malloc (sizeof(test_structure_1)); 38 | 39 | ts1_type.size = 0; 40 | ts1_type.alignment = 0; 41 | ts1_type.type = FFI_TYPE_STRUCT; 42 | ts1_type.elements = ts1_type_elements; 43 | ts1_type_elements[0] = &ffi_type_uint; 44 | ts1_type_elements[1] = &ffi_type_uint; 45 | ts1_type_elements[2] = &ffi_type_uint; 46 | ts1_type_elements[3] = &ffi_type_uint; 47 | ts1_type_elements[4] = 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.ui04 = 555; 57 | 58 | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); 59 | 60 | CHECK(ts1_result->ui04 == 556); 61 | 62 | /* This will fail if ffi_call isn't passing the struct by value. */ 63 | CHECK(ts1_arg.ui04 == 555); 64 | 65 | free (ts1_result); 66 | exit(0); 67 | } 68 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/struct_by_value_4f.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 f01; 13 | float f02; 14 | float f03; 15 | float f04; 16 | } test_structure_1; 17 | 18 | static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) 19 | { 20 | ts.f04++; 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 ts1_type; 31 | ffi_type *ts1_type_elements[5]; 32 | 33 | test_structure_1 ts1_arg; 34 | 35 | /* This is a hack to get a properly aligned result buffer */ 36 | test_structure_1 *ts1_result = 37 | (test_structure_1 *) malloc (sizeof(test_structure_1)); 38 | 39 | ts1_type.size = 0; 40 | ts1_type.alignment = 0; 41 | ts1_type.type = FFI_TYPE_STRUCT; 42 | ts1_type.elements = ts1_type_elements; 43 | ts1_type_elements[0] = &ffi_type_float; 44 | ts1_type_elements[1] = &ffi_type_float; 45 | ts1_type_elements[2] = &ffi_type_float; 46 | ts1_type_elements[3] = &ffi_type_float; 47 | ts1_type_elements[4] = 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.f04 = 555.5; 57 | 58 | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); 59 | 60 | CHECK(fabs(ts1_result->f04 - 556.5) < FLT_EPSILON); 61 | 62 | /* This will fail if ffi_call isn't passing the struct by value. */ 63 | CHECK(fabs(ts1_arg.f04 - 555.5) < FLT_EPSILON); 64 | 65 | free (ts1_result); 66 | exit(0); 67 | } 68 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/struct_by_value_small.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 int ui17; 13 | } test_structure_1; 14 | 15 | static test_structure_1 ABI_ATTR struct1(test_structure_1 ts) 16 | { 17 | ts.ui17++; 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 | ffi_type ts1_type; 28 | ffi_type *ts1_type_elements[2]; 29 | 30 | test_structure_1 ts1_arg; 31 | 32 | /* This is a hack to get a properly aligned result buffer */ 33 | test_structure_1 *ts1_result = 34 | (test_structure_1 *) malloc (sizeof(test_structure_1)); 35 | 36 | ts1_type.size = 0; 37 | ts1_type.alignment = 0; 38 | ts1_type.type = FFI_TYPE_STRUCT; 39 | ts1_type.elements = ts1_type_elements; 40 | ts1_type_elements[0] = &ffi_type_uint; 41 | ts1_type_elements[1] = NULL; 42 | 43 | args[0] = &ts1_type; 44 | values[0] = &ts1_arg; 45 | 46 | /* Initialize the cif */ 47 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, 48 | &ts1_type, args) == FFI_OK); 49 | 50 | ts1_arg.ui17 = 555; 51 | 52 | ffi_call(&cif, FFI_FN(struct1), ts1_result, values); 53 | 54 | CHECK(ts1_result->ui17 == 556); 55 | 56 | /* This will fail if ffi_call isn't passing the struct by value. */ 57 | CHECK(ts1_arg.ui17 == 555); 58 | 59 | free (ts1_result); 60 | exit(0); 61 | } 62 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/struct_return_2H.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 | short x; 12 | short y; 13 | } test_structure_5; 14 | 15 | static test_structure_5 ABI_ATTR struct5(test_structure_5 inp) 16 | { 17 | inp.x *= 2; 18 | inp.y *= 3; 19 | 20 | return inp; 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; 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_sshort; 42 | ts5_type_elements[1] = &ffi_type_sshort; 43 | ts5_type_elements[2] = NULL; 44 | 45 | args[0] = &ts5_type; 46 | values[0] = &ts5_arg1; 47 | 48 | /* Initialize the cif */ 49 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts5_type, args) == FFI_OK); 50 | 51 | ts5_arg1.x = 99; 52 | ts5_arg1.y = 88; 53 | 54 | ffi_call (&cif, FFI_FN(struct5), ts5_result, values); 55 | 56 | CHECK(ts5_result->x == 99*2); 57 | CHECK(ts5_result->y == 88*3); 58 | CHECK(ts5_arg1.x == 99); 59 | CHECK(ts5_arg1.y == 88); 60 | 61 | free (ts5_result); 62 | exit(0); 63 | } 64 | -------------------------------------------------------------------------------- /libffi-sys-rs/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.call/va_1.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 | 9 | #include "ffitest.h" 10 | #include 11 | 12 | struct small_tag 13 | { 14 | unsigned char a; 15 | unsigned char b; 16 | }; 17 | 18 | struct large_tag 19 | { 20 | unsigned a; 21 | unsigned b; 22 | unsigned c; 23 | unsigned d; 24 | unsigned e; 25 | }; 26 | 27 | int 28 | main (void) 29 | { 30 | ffi_cif cif; 31 | ffi_type* arg_types[15]; 32 | 33 | ffi_type s_type; 34 | ffi_type *s_type_elements[3]; 35 | 36 | ffi_type l_type; 37 | ffi_type *l_type_elements[6]; 38 | 39 | s_type.size = 0; 40 | s_type.alignment = 0; 41 | s_type.type = FFI_TYPE_STRUCT; 42 | s_type.elements = s_type_elements; 43 | 44 | s_type_elements[0] = &ffi_type_uchar; 45 | s_type_elements[1] = &ffi_type_uchar; 46 | s_type_elements[2] = NULL; 47 | 48 | l_type.size = 0; 49 | l_type.alignment = 0; 50 | l_type.type = FFI_TYPE_STRUCT; 51 | l_type.elements = l_type_elements; 52 | 53 | l_type_elements[0] = &ffi_type_uint; 54 | l_type_elements[1] = &ffi_type_uint; 55 | l_type_elements[2] = &ffi_type_uint; 56 | l_type_elements[3] = &ffi_type_uint; 57 | l_type_elements[4] = &ffi_type_uint; 58 | l_type_elements[5] = NULL; 59 | 60 | arg_types[0] = &ffi_type_sint; 61 | arg_types[1] = &s_type; 62 | arg_types[2] = &l_type; 63 | arg_types[3] = &s_type; 64 | arg_types[4] = &ffi_type_uchar; 65 | arg_types[5] = &ffi_type_schar; 66 | arg_types[6] = &ffi_type_ushort; 67 | arg_types[7] = &ffi_type_sshort; 68 | arg_types[8] = &ffi_type_uint; 69 | arg_types[9] = &ffi_type_sint; 70 | arg_types[10] = &ffi_type_ulong; 71 | arg_types[11] = &ffi_type_slong; 72 | arg_types[12] = &ffi_type_double; 73 | arg_types[13] = &ffi_type_double; 74 | arg_types[14] = NULL; 75 | 76 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 14, &ffi_type_sint, arg_types) == FFI_BAD_ARGTYPE); 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK((int)*(int *)args[0] == 0); 24 | CHECK((int)*(int *)args[1] == 1); 25 | CHECK((int)*(int *)args[2] == 2); 26 | CHECK((int)*(int *)args[3] == 3); 27 | CHECK((int)*(ffi_arg *)resp == 9); 28 | } 29 | 30 | typedef int (ABI_ATTR *closure_test_type0)(int, int, int, int); 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 | ffi_type * cl_arg_types[17]; 38 | int res; 39 | 40 | cl_arg_types[0] = &ffi_type_uint; 41 | cl_arg_types[1] = &ffi_type_uint; 42 | cl_arg_types[2] = &ffi_type_uint; 43 | cl_arg_types[3] = &ffi_type_uint; 44 | cl_arg_types[4] = NULL; 45 | 46 | /* Initialize the cif */ 47 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 4, 48 | &ffi_type_sint, cl_arg_types) == FFI_OK); 49 | 50 | CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test, 51 | (void *) 3 /* userdata */, code) == FFI_OK); 52 | 53 | res = (*(closure_test_type0)code)(0, 1, 2, 3); 54 | /* { dg-output "0 1 2 3: 9" } */ 55 | 56 | printf("res: %d\n",res); 57 | /* { dg-output "\nres: 9" } */ 58 | CHECK(res == 9); 59 | 60 | exit(0); 61 | } 62 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(p.x == 1); 21 | CHECK(p.y == 2); 22 | } 23 | 24 | void 25 | closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__, 26 | void** args, void* userdata __UNUSED__) 27 | { 28 | closure_test_fn(*(Dbls*)args[0]); 29 | } 30 | 31 | int main(int argc __UNUSED__, char** argv __UNUSED__) 32 | { 33 | ffi_cif cif; 34 | 35 | void *code; 36 | ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 37 | ffi_type* cl_arg_types[1]; 38 | 39 | ffi_type ts1_type; 40 | ffi_type* ts1_type_elements[4]; 41 | 42 | Dbls arg = { 1.0, 2.0 }; 43 | 44 | ts1_type.size = 0; 45 | ts1_type.alignment = 0; 46 | ts1_type.type = FFI_TYPE_STRUCT; 47 | ts1_type.elements = ts1_type_elements; 48 | 49 | ts1_type_elements[0] = &ffi_type_double; 50 | ts1_type_elements[1] = &ffi_type_double; 51 | ts1_type_elements[2] = NULL; 52 | 53 | cl_arg_types[0] = &ts1_type; 54 | 55 | /* Initialize the cif */ 56 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 57 | &ffi_type_void, cl_arg_types) == FFI_OK); 58 | 59 | CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK); 60 | 61 | ((void (*)(Dbls))(code))(arg); 62 | /* { dg-output "1.0 2.0" } */ 63 | 64 | closure_test_fn(arg); 65 | /* { dg-output "\n1.0 2.0" } */ 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | #define BUF_SIZE 50 14 | static char buffer[BUF_SIZE]; 15 | 16 | static void 17 | cls_double_va_fn(ffi_cif* cif __UNUSED__, void* resp, 18 | void** args, void* userdata __UNUSED__) 19 | { 20 | char* format = *(char**)args[0]; 21 | double doubleValue = *(double*)args[1]; 22 | 23 | *(ffi_arg*)resp = printf(format, doubleValue); 24 | CHECK(*(ffi_arg*)resp == 4); 25 | snprintf(buffer, BUF_SIZE, format, doubleValue); 26 | CHECK(strncmp(buffer, "7.0\n", 4) == 0); 27 | } 28 | 29 | int main (void) 30 | { 31 | ffi_cif cif; 32 | void *code; 33 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 34 | void* args[3]; 35 | ffi_type* arg_types[3]; 36 | 37 | char* format = "%.1f\n"; 38 | double doubleArg = 7; 39 | ffi_arg res = 0; 40 | 41 | arg_types[0] = &ffi_type_pointer; 42 | arg_types[1] = &ffi_type_double; 43 | arg_types[2] = NULL; 44 | 45 | /* This printf call is variadic */ 46 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, &ffi_type_sint, 47 | arg_types) == FFI_OK); 48 | 49 | args[0] = &format; 50 | args[1] = &doubleArg; 51 | args[2] = NULL; 52 | 53 | ffi_call(&cif, FFI_FN(printf), &res, args); 54 | /* { dg-output "7.0" } */ 55 | printf("res: %d\n", (int) res); 56 | /* { dg-output "\nres: 4" } */ 57 | CHECK(res == 4); 58 | 59 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, 60 | code) == FFI_OK); 61 | 62 | res = ((int(*)(char*, ...))(code))(format, doubleArg); 63 | /* { dg-output "\n7.0" } */ 64 | printf("res: %d\n", (int) res); 65 | /* { dg-output "\nres: 4" } */ 66 | CHECK(res == 4); 67 | 68 | exit(0); 69 | } 70 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK((int)(*(float *)args[0]) == -2122); 19 | CHECK((int)(*(float *)resp) == -2122); 20 | } 21 | 22 | typedef float (*cls_ret_float)(float); 23 | 24 | int main (void) 25 | { 26 | ffi_cif cif; 27 | void *code; 28 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 29 | ffi_type * cl_arg_types[2]; 30 | float res; 31 | 32 | cl_arg_types[0] = &ffi_type_float; 33 | cl_arg_types[1] = NULL; 34 | 35 | /* Initialize the cif */ 36 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 37 | &ffi_type_float, cl_arg_types) == FFI_OK); 38 | 39 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_float_fn, NULL, code) == FFI_OK); 40 | res = ((((cls_ret_float)code)(-2122.12))); 41 | /* { dg-output "\\-2122.12: \\-2122.12" } */ 42 | printf("res: %.6f\n", res); 43 | /* { dg-output "\nres: \-2122.120117" } */ 44 | CHECK((int)res == -2122); 45 | exit(0); 46 | } 47 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/cls_many_mixed_args.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check closures called with many args of mixed types 3 | Limitations: none. 4 | PR: none. 5 | Originator: */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | #include 10 | #include 11 | 12 | #define NARGS 16 13 | 14 | static void cls_ret_double_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 15 | void* userdata __UNUSED__) 16 | { 17 | int i; 18 | double r = 0; 19 | double t; 20 | for(i = 0; i < NARGS; i++) 21 | { 22 | if(i == 4 || i == 9 || i == 11 || i == 13 || i == 15) 23 | { 24 | t = *(long int *)args[i]; 25 | CHECK(t == i+1); 26 | } 27 | else 28 | { 29 | t = *(double *)args[i]; 30 | CHECK(fabs(t - ((i+1) * 0.1)) < FLT_EPSILON); 31 | } 32 | r += t; 33 | } 34 | *(double *)resp = r; 35 | } 36 | typedef double (*cls_ret_double)(double, double, double, double, long int, 37 | double, double, double, double, long int, double, long int, double, long int, 38 | double, long int); 39 | 40 | int main (void) 41 | { 42 | ffi_cif cif; 43 | void *code; 44 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 45 | ffi_type * cl_arg_types[NARGS]; 46 | double res; 47 | int i; 48 | double expected = 64.9; 49 | 50 | for(i = 0; i < NARGS; i++) 51 | { 52 | if(i == 4 || i == 9 || i == 11 || i == 13 || i == 15) 53 | cl_arg_types[i] = &ffi_type_slong; 54 | else 55 | cl_arg_types[i] = &ffi_type_double; 56 | } 57 | 58 | /* Initialize the cif */ 59 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NARGS, 60 | &ffi_type_double, cl_arg_types) == FFI_OK); 61 | 62 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_double_fn, NULL, code) == FFI_OK); 63 | 64 | res = (((cls_ret_double)code))(0.1, 0.2, 0.3, 0.4, 5, 0.6, 0.7, 0.8, 0.9, 10, 65 | 1.1, 12, 1.3, 14, 1.5, 16); 66 | if (fabs(res - expected) < FLT_EPSILON) 67 | exit(0); 68 | else 69 | abort(); 70 | } 71 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/cls_many_mixed_float_double.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check register allocation for closure calls with many float and double arguments 3 | Limitations: none. 4 | PR: none. 5 | Originator: */ 6 | 7 | /* { dg-do run } */ 8 | #include "ffitest.h" 9 | #include 10 | #include 11 | 12 | #define NARGS 16 13 | 14 | static void cls_mixed_float_double_fn(ffi_cif* cif , void* ret, void** args, 15 | void* userdata __UNUSED__) 16 | { 17 | double r = 0; 18 | unsigned int i; 19 | double t; 20 | for(i=0; i < cif->nargs; i++) 21 | { 22 | if(cif->arg_types[i] == &ffi_type_double) { 23 | t = *(((double**)(args))[i]); 24 | } else { 25 | t = *(((float**)(args))[i]); 26 | } 27 | r += t; 28 | } 29 | *((double*)ret) = r; 30 | } 31 | typedef double (*cls_mixed)(double, float, double, double, double, double, double, float, float, double, float, float); 32 | 33 | int main (void) 34 | { 35 | ffi_cif cif; 36 | ffi_closure *closure; 37 | void* code; 38 | ffi_type *argtypes[12] = {&ffi_type_double, &ffi_type_float, &ffi_type_double, 39 | &ffi_type_double, &ffi_type_double, &ffi_type_double, 40 | &ffi_type_double, &ffi_type_float, &ffi_type_float, 41 | &ffi_type_double, &ffi_type_float, &ffi_type_float}; 42 | 43 | 44 | closure = ffi_closure_alloc(sizeof(ffi_closure), (void**)&code); 45 | if(closure ==NULL) 46 | abort(); 47 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 12, &ffi_type_double, argtypes) == FFI_OK); 48 | CHECK(ffi_prep_closure_loc(closure, &cif, cls_mixed_float_double_fn, NULL, code) == FFI_OK); 49 | double ret = ((cls_mixed)code)(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2); 50 | ffi_closure_free(closure); 51 | if(fabs(ret - 7.8) < FLT_EPSILON) 52 | exit(0); 53 | else 54 | abort(); 55 | } 56 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | static 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 | CHECK(a1 == 2); 30 | CHECK(a2 == 125); 31 | 32 | *(ffi_arg *)rval = test_func_fn(a1, a2); 33 | 34 | } 35 | 36 | typedef signed char (*test_type)(signed char, signed char); 37 | 38 | int main (void) 39 | { 40 | ffi_cif cif; 41 | void *code; 42 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 43 | void * args_dbl[3]; 44 | ffi_type * cl_arg_types[3]; 45 | ffi_arg res_call; 46 | signed char a, b, res_closure; 47 | 48 | a = 2; 49 | b = 125; 50 | 51 | args_dbl[0] = &a; 52 | args_dbl[1] = &b; 53 | args_dbl[2] = NULL; 54 | 55 | cl_arg_types[0] = &ffi_type_schar; 56 | cl_arg_types[1] = &ffi_type_schar; 57 | cl_arg_types[2] = NULL; 58 | 59 | /* Initialize the cif */ 60 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 61 | &ffi_type_schar, cl_arg_types) == FFI_OK); 62 | 63 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 64 | /* { dg-output "2 125: 127" } */ 65 | printf("res: %d\n", (signed char)res_call); 66 | /* { dg-output "\nres: 127" } */ 67 | CHECK((signed char)res_call == 127); 68 | 69 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 70 | 71 | res_closure = (*((test_type)code))(2, 125); 72 | /* { dg-output "\n2 125: 127" } */ 73 | printf("res: %d\n", res_closure); 74 | /* { dg-output "\nres: 127" } */ 75 | CHECK(res_closure == 127); 76 | 77 | exit(0); 78 | } 79 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | static 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 | CHECK(a1 == 2); 18 | CHECK(a2 == 32765); 19 | CHECK(result == 32767); 20 | 21 | return result; 22 | 23 | } 24 | 25 | static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, 26 | void *data __UNUSED__) 27 | { 28 | signed short a1, a2; 29 | 30 | a1 = *(signed short *)avals[0]; 31 | a2 = *(signed short *)avals[1]; 32 | 33 | *(ffi_arg *)rval = test_func_fn(a1, a2); 34 | 35 | } 36 | 37 | typedef signed short (*test_type)(signed short, signed short); 38 | 39 | int main (void) 40 | { 41 | ffi_cif cif; 42 | void *code; 43 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 44 | void * args_dbl[3]; 45 | ffi_type * cl_arg_types[3]; 46 | ffi_arg res_call; 47 | unsigned short a, b, res_closure; 48 | 49 | a = 2; 50 | b = 32765; 51 | 52 | args_dbl[0] = &a; 53 | args_dbl[1] = &b; 54 | args_dbl[2] = NULL; 55 | 56 | cl_arg_types[0] = &ffi_type_sshort; 57 | cl_arg_types[1] = &ffi_type_sshort; 58 | cl_arg_types[2] = NULL; 59 | 60 | /* Initialize the cif */ 61 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 62 | &ffi_type_sshort, cl_arg_types) == FFI_OK); 63 | 64 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 65 | /* { dg-output "2 32765: 32767" } */ 66 | printf("res: %d\n", (unsigned short)res_call); 67 | /* { dg-output "\nres: 32767" } */ 68 | CHECK((unsigned short)res_call == 32767); 69 | 70 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 71 | 72 | res_closure = (*((test_type)code))(2, 32765); 73 | /* { dg-output "\n2 32765: 32767" } */ 74 | printf("res: %d\n", res_closure); 75 | /* { dg-output "\nres: 32767" } */ 76 | CHECK(res_closure == 32767); 77 | 78 | exit(0); 79 | } 80 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | static 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 | CHECK(a1 == 2); 19 | CHECK(a2 == 32765); 20 | CHECK(result == 32767); 21 | 22 | return result; 23 | } 24 | 25 | static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals, 26 | void *data __UNUSED__) 27 | { 28 | unsigned short a1, a2; 29 | 30 | a1 = *(unsigned short *)avals[0]; 31 | a2 = *(unsigned short *)avals[1]; 32 | 33 | *(ffi_arg *)rval = test_func_fn(a1, a2); 34 | 35 | } 36 | 37 | typedef unsigned short (*test_type)(unsigned short, unsigned short); 38 | 39 | int main (void) 40 | { 41 | ffi_cif cif; 42 | void *code; 43 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 44 | void * args_dbl[3]; 45 | ffi_type * cl_arg_types[3]; 46 | ffi_arg res_call; 47 | unsigned short a, b, res_closure; 48 | 49 | a = 2; 50 | b = 32765; 51 | 52 | args_dbl[0] = &a; 53 | args_dbl[1] = &b; 54 | args_dbl[2] = NULL; 55 | 56 | cl_arg_types[0] = &ffi_type_ushort; 57 | cl_arg_types[1] = &ffi_type_ushort; 58 | cl_arg_types[2] = NULL; 59 | 60 | /* Initialize the cif */ 61 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, 62 | &ffi_type_ushort, cl_arg_types) == FFI_OK); 63 | 64 | ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl); 65 | /* { dg-output "2 32765: 32767" } */ 66 | printf("res: %d\n", (unsigned short)res_call); 67 | /* { dg-output "\nres: 32767" } */ 68 | 69 | CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK); 70 | 71 | res_closure = (*((test_type)code))(2, 32765); 72 | /* { dg-output "\n2 32765: 32767" } */ 73 | printf("res: %d\n", res_closure); 74 | /* { dg-output "\nres: 32767" } */ 75 | CHECK(res_closure == 32767); 76 | 77 | exit(0); 78 | } 79 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(*(signed char *)args[0] == 127); 19 | CHECK((int)*(ffi_arg *)(resp) == 127); 20 | } 21 | typedef signed char (*cls_ret_schar)(signed char); 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[2]; 29 | signed char res; 30 | 31 | cl_arg_types[0] = &ffi_type_schar; 32 | cl_arg_types[1] = NULL; 33 | 34 | /* Initialize the cif */ 35 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 36 | &ffi_type_schar, cl_arg_types) == FFI_OK); 37 | 38 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_schar_fn, NULL, code) == FFI_OK); 39 | 40 | res = (*((cls_ret_schar)code))(127); 41 | /* { dg-output "127: 127" } */ 42 | printf("res: %d\n", res); 43 | /* { dg-output "\nres: 127" } */ 44 | CHECK(res == 127); 45 | 46 | exit(0); 47 | } 48 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(*(signed int *)args[0] == 65534); 17 | CHECK((int)*(ffi_arg *)(resp) == 65534); 18 | } 19 | typedef signed int (*cls_ret_sint)(signed int); 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 int res; 28 | 29 | cl_arg_types[0] = &ffi_type_sint; 30 | cl_arg_types[1] = NULL; 31 | 32 | /* Initialize the cif */ 33 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 34 | &ffi_type_sint, cl_arg_types) == FFI_OK); 35 | 36 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_sint_fn, NULL, code) == FFI_OK); 37 | 38 | res = (*((cls_ret_sint)code))(65534); 39 | /* { dg-output "65534: 65534" } */ 40 | printf("res: %d\n",res); 41 | /* { dg-output "\nres: 65534" } */ 42 | 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(*(signed short *)args[0] == 255); 17 | CHECK((int)*(ffi_arg *)(resp) == 255); 18 | } 19 | typedef signed short (*cls_ret_sshort)(signed short); 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 short res; 28 | 29 | cl_arg_types[0] = &ffi_type_sshort; 30 | cl_arg_types[1] = NULL; 31 | 32 | /* Initialize the cif */ 33 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 34 | &ffi_type_sshort, cl_arg_types) == FFI_OK); 35 | 36 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_sshort_fn, NULL, code) == FFI_OK); 37 | 38 | res = (*((cls_ret_sshort)code))(255); 39 | /* { dg-output "255: 255" } */ 40 | printf("res: %d\n",res); 41 | /* { dg-output "\nres: 255" } */ 42 | CHECK(res == 255); 43 | 44 | exit(0); 45 | } 46 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(*(unsigned char *)args[0] == 127); 17 | CHECK((int)*(ffi_arg *)(resp) == 127); 18 | } 19 | typedef unsigned char (*cls_ret_uchar)(unsigned 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 | unsigned char res; 28 | 29 | cl_arg_types[0] = &ffi_type_uchar; 30 | cl_arg_types[1] = NULL; 31 | 32 | /* Initialize the cif */ 33 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 34 | &ffi_type_uchar, cl_arg_types) == FFI_OK); 35 | 36 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_uchar_fn, NULL, code) == FFI_OK); 37 | 38 | res = (*((cls_ret_uchar)code))(127); 39 | /* { dg-output "127: 127" } */ 40 | printf("res: %d\n",res); 41 | /* { dg-output "\nres: 127" } */ 42 | CHECK(res == 127); 43 | 44 | exit(0); 45 | } 46 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(*(unsigned int *)args[0] == 2147483647); 19 | CHECK((int)*(ffi_arg *)(resp) == 2147483647); 20 | } 21 | typedef unsigned int (*cls_ret_uint)(unsigned int); 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[2]; 29 | unsigned int res; 30 | 31 | cl_arg_types[0] = &ffi_type_uint; 32 | cl_arg_types[1] = NULL; 33 | 34 | /* Initialize the cif */ 35 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 36 | &ffi_type_uint, cl_arg_types) == FFI_OK); 37 | 38 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_uint_fn, NULL, code) == FFI_OK); 39 | 40 | res = (*((cls_ret_uint)code))(2147483647); 41 | /* { dg-output "2147483647: 2147483647" } */ 42 | printf("res: %d\n",res); 43 | /* { dg-output "\nres: 2147483647" } */ 44 | CHECK(res == 2147483647); 45 | 46 | exit(0); 47 | } 48 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(*(T *)args[0] == 67); 20 | CHECK(*(T *)args[1] == 4); 21 | CHECK((int)*(ffi_arg *)resp == 67); 22 | } 23 | 24 | typedef T (*cls_ret_T)(T, ...); 25 | 26 | int main (void) 27 | { 28 | ffi_cif cif; 29 | void *code; 30 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 31 | ffi_type * cl_arg_types[3]; 32 | T res; 33 | 34 | cl_arg_types[0] = &ffi_type_uint; 35 | cl_arg_types[1] = &ffi_type_uint; 36 | cl_arg_types[2] = NULL; 37 | 38 | /* Initialize the cif */ 39 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, 40 | &ffi_type_uint, cl_arg_types) == FFI_OK); 41 | 42 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); 43 | res = ((((cls_ret_T)code)(67, 4))); 44 | /* { dg-output "67: 67 4" } */ 45 | printf("res: %d\n", res); 46 | /* { dg-output "\nres: 67" } */ 47 | CHECK(res == 67); 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(*(T *)args[0] == 67); 20 | CHECK(*(T *)args[1] == 4); 21 | CHECK(*(T *)resp == 67); 22 | } 23 | 24 | typedef T (*cls_ret_T)(T, ...); 25 | 26 | int main (void) 27 | { 28 | ffi_cif cif; 29 | void *code; 30 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 31 | ffi_type * cl_arg_types[3]; 32 | T res; 33 | 34 | cl_arg_types[0] = &ffi_type_ulong; 35 | cl_arg_types[1] = &ffi_type_ulong; 36 | cl_arg_types[2] = NULL; 37 | 38 | /* Initialize the cif */ 39 | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, 40 | &ffi_type_ulong, cl_arg_types) == FFI_OK); 41 | 42 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK); 43 | res = ((((cls_ret_T)code)(67, 4))); 44 | /* { dg-output "67: 67 4" } */ 45 | printf("res: %ld\n", res); 46 | /* { dg-output "\nres: 67" } */ 47 | CHECK(res == 67); 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(res == 1152921504606846761LL); 41 | 42 | res = (*((cls_ret_ulonglong)code))(9223372035854775808LL); 43 | /* { dg-output "\n9223372035854775808: 8070450533247928831" } */ 44 | printf("res: %" PRIdLL "\n", res); 45 | /* { dg-output "\nres: 8070450533247928831" } */ 46 | CHECK(res == 8070450533247928831LL); 47 | 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | CHECK(*(unsigned short *)args[0] == 65535); 18 | CHECK((int)*(ffi_arg *)(resp) == 65535); 19 | } 20 | typedef unsigned short (*cls_ret_ushort)(unsigned short); 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[2]; 28 | unsigned short res; 29 | 30 | cl_arg_types[0] = &ffi_type_ushort; 31 | cl_arg_types[1] = NULL; 32 | 33 | /* Initialize the cif */ 34 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 35 | &ffi_type_ushort, cl_arg_types) == FFI_OK); 36 | 37 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_ushort_fn, NULL, code) == FFI_OK); 38 | 39 | res = (*((cls_ret_ushort)code))(65535); 40 | /* { dg-output "65535: 65535" } */ 41 | printf("res: %d\n",res); 42 | /* { dg-output "\nres: 65535" } */ 43 | CHECK(res == 65535); 44 | 45 | exit(0); 46 | } 47 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/ffitest.h: -------------------------------------------------------------------------------- 1 | #include "../libffi.call/ffitest.h" 2 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 | static 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 | CHECK_FLOAT_EQ(arg.a, 4); 25 | CHECK_FLOAT_EQ(arg.b, 5); 26 | CHECK_FLOAT_EQ(arg.c, 1); 27 | CHECK_FLOAT_EQ(arg.d, 8); 28 | } 29 | 30 | static void 31 | cls_struct_combined_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__, 32 | void** args, void* userdata __UNUSED__) 33 | { 34 | struct cls_struct_combined a0; 35 | 36 | a0 = *(struct cls_struct_combined*)(args[0]); 37 | 38 | cls_struct_combined_fn(a0); 39 | } 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 | ffi_type* cls_struct_fields0[5]; 48 | ffi_type cls_struct_type0; 49 | ffi_type* dbl_arg_types[5]; 50 | 51 | struct cls_struct_combined g_dbl = {4.0, 5.0, 1.0, 8.0}; 52 | 53 | cls_struct_type0.size = 0; 54 | cls_struct_type0.alignment = 0; 55 | cls_struct_type0.type = FFI_TYPE_STRUCT; 56 | cls_struct_type0.elements = cls_struct_fields0; 57 | 58 | cls_struct_fields0[0] = &ffi_type_float; 59 | cls_struct_fields0[1] = &ffi_type_float; 60 | cls_struct_fields0[2] = &ffi_type_float; 61 | cls_struct_fields0[3] = &ffi_type_float; 62 | cls_struct_fields0[4] = NULL; 63 | 64 | dbl_arg_types[0] = &cls_struct_type0; 65 | dbl_arg_types[1] = NULL; 66 | 67 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_void, 68 | dbl_arg_types) == FFI_OK); 69 | 70 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_combined_gn, NULL, code) == FFI_OK); 71 | 72 | ((void(*)(cls_struct_combined)) (code))(g_dbl); 73 | /* { dg-output "4 5 1 8" } */ 74 | exit(0); 75 | } 76 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.closures/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 { xfail moxie*-*-* } } */ 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 | extern "C" 18 | int main (void) 19 | { 20 | ffi_cif cif; 21 | ffi_type *args[MAX_ARGS]; 22 | void *values[MAX_ARGS]; 23 | ffi_arg rint; 24 | 25 | signed int si; 26 | signed short ss; 27 | signed char sc; 28 | 29 | args[0] = &ffi_type_sint; 30 | values[0] = &si; 31 | args[1] = &ffi_type_sshort; 32 | values[1] = &ss; 33 | args[2] = &ffi_type_schar; 34 | values[2] = ≻ 35 | 36 | /* Initialize the cif */ 37 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 38 | &ffi_type_sint, args) == FFI_OK); 39 | 40 | si = -6; 41 | ss = -12; 42 | sc = -1; 43 | { 44 | try 45 | { 46 | ffi_call(&cif, FFI_FN(checking), &rint, values); 47 | } catch (int exception_code) 48 | { 49 | CHECK(exception_code == 9); 50 | } 51 | printf("part one OK\n"); 52 | /* { dg-output "part one OK" } */ 53 | } 54 | exit(0); 55 | } 56 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_align_complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "cls_align_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_align_complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "cls_align_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_align_complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check structure alignment of complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "cls_align_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | #include "ffitest.h" 3 | #include 4 | 5 | static void cls_ret_complex_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, 6 | void* userdata __UNUSED__) 7 | { 8 | _Complex T_C_TYPE *pa; 9 | _Complex T_C_TYPE *pr; 10 | pa = (_Complex T_C_TYPE *)args[0]; 11 | pr = (_Complex T_C_TYPE *)resp; 12 | *pr = *pa; 13 | 14 | printf("%.6f,%.6fi: %.6f,%.6fi\n", 15 | T_CONV creal (*pa), T_CONV cimag (*pa), 16 | T_CONV creal (*pr), T_CONV cimag (*pr)); 17 | } 18 | typedef _Complex T_C_TYPE (*cls_ret_complex)(_Complex T_C_TYPE); 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 | _Complex T_C_TYPE res; 27 | 28 | cl_arg_types[0] = &T_FFI_TYPE; 29 | cl_arg_types[1] = NULL; 30 | 31 | /* Initialize the cif */ 32 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 33 | &T_FFI_TYPE, cl_arg_types) == FFI_OK); 34 | 35 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_complex_fn, NULL, code) == FFI_OK); 36 | 37 | res = (*((cls_ret_complex)code))(0.125 + 128.0 * I); 38 | printf("res: %.6f,%.6fi\n", T_CONV creal (res), T_CONV cimag (res)); 39 | CHECK (res == (0.125 + 128.0 * I)); 40 | 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "cls_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "cls_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: closure_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "cls_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_struct.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | #include "ffitest.h" 3 | #include 4 | 5 | typedef struct Cs { 6 | _Complex T_C_TYPE x; 7 | _Complex T_C_TYPE y; 8 | } Cs; 9 | 10 | Cs gc; 11 | 12 | void 13 | closure_test_fn(Cs p) 14 | { 15 | printf("%.1f,%.1fi %.1f,%.1fi\n", 16 | T_CONV creal (p.x), T_CONV cimag (p.x), 17 | T_CONV creal (p.y), T_CONV cimag (p.y)); 18 | gc = p; 19 | } 20 | 21 | void 22 | closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__, 23 | void** args, void* userdata __UNUSED__) 24 | { 25 | closure_test_fn(*(Cs*)args[0]); 26 | } 27 | 28 | int main(int argc __UNUSED__, char** argv __UNUSED__) 29 | { 30 | ffi_cif cif; 31 | 32 | void *code; 33 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); 34 | ffi_type *cl_arg_types[1]; 35 | 36 | ffi_type ts1_type; 37 | ffi_type* ts1_type_elements[4]; 38 | 39 | Cs arg = { 1.0 + 11.0 * I, 2.0 + 22.0 * I}; 40 | 41 | ts1_type.size = 0; 42 | ts1_type.alignment = 0; 43 | ts1_type.type = FFI_TYPE_STRUCT; 44 | ts1_type.elements = ts1_type_elements; 45 | 46 | ts1_type_elements[0] = &T_FFI_TYPE; 47 | ts1_type_elements[1] = &T_FFI_TYPE; 48 | ts1_type_elements[2] = NULL; 49 | 50 | cl_arg_types[0] = &ts1_type; 51 | 52 | /* Initialize the cif */ 53 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 54 | &ffi_type_void, cl_arg_types) == FFI_OK); 55 | 56 | CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK); 57 | 58 | gc.x = 0.0 + 0.0 * I; 59 | gc.y = 0.0 + 0.0 * I; 60 | ((void*(*)(Cs))(code))(arg); 61 | /* { dg-output "1.0,11.0i 2.0,22.0i\n" } */ 62 | CHECK (gc.x == arg.x && gc.y == arg.y); 63 | 64 | gc.x = 0.0 + 0.0 * I; 65 | gc.y = 0.0 + 0.0 * I; 66 | closure_test_fn(arg); 67 | /* { dg-output "1.0,11.0i 2.0,22.0i\n" } */ 68 | CHECK (gc.x == arg.x && gc.y == arg.y); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_struct_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check complex arguments in structs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "cls_complex_struct.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_struct_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check complex arguments in structs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "cls_complex_struct.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_struct_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Check complex arguments in structs. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "cls_complex_struct.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_va_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Test complex' passed in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "cls_complex_va.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_va_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Test complex' passed in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | /* Alpha splits _Complex into two arguments. It's illegal to pass 10 | float through varargs, so _Complex float goes badly. In sort of 11 | gets passed as _Complex double, but the compiler doesn't agree 12 | with itself on this issue. */ 13 | /* { dg-do run { xfail alpha*-*-* } } */ 14 | 15 | #include "complex_defs_float.inc" 16 | #include "cls_complex_va.inc" 17 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/cls_complex_va_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call, closure_call 2 | Purpose: Test complex' passed in variable argument lists. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "cls_complex_va.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/complex.exp: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2003, 2006, 2009, 2010, 2014 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 | set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.{c,cc}]] 23 | 24 | if { [libffi_feature_test "#ifdef FFI_TARGET_HAS_COMPLEX_TYPE"] } { 25 | run-many-tests $tlist "" 26 | } else { 27 | foreach test $tlist { 28 | unsupported "$test" 29 | } 30 | } 31 | 32 | dg-finish 33 | 34 | # Local Variables: 35 | # tcl-indent-level:4 36 | # End: 37 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/complex.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*-*/ 2 | #include "ffitest.h" 3 | #include 4 | 5 | static _Complex T_C_TYPE f_complex(_Complex T_C_TYPE c, int x, int *py) 6 | { 7 | c = -(2 * creal (c)) + (cimag (c) + 1)* I; 8 | *py += x; 9 | 10 | return c; 11 | } 12 | 13 | int main (void) 14 | { 15 | ffi_cif cif; 16 | ffi_type *args[MAX_ARGS]; 17 | void *values[MAX_ARGS]; 18 | 19 | _Complex T_C_TYPE tc_arg; 20 | _Complex T_C_TYPE tc_result; 21 | int tc_int_arg_x; 22 | int tc_y; 23 | int *tc_ptr_arg_y = &tc_y; 24 | 25 | args[0] = &T_FFI_TYPE; 26 | args[1] = &ffi_type_sint; 27 | args[2] = &ffi_type_pointer; 28 | values[0] = &tc_arg; 29 | values[1] = &tc_int_arg_x; 30 | values[2] = &tc_ptr_arg_y; 31 | 32 | /* Initialize the cif */ 33 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3, 34 | &T_FFI_TYPE, args) == FFI_OK); 35 | 36 | tc_arg = 1 + 7 * I; 37 | tc_int_arg_x = 1234; 38 | tc_y = 9876; 39 | ffi_call(&cif, FFI_FN(f_complex), &tc_result, values); 40 | 41 | printf ("%f,%fi %f,%fi, x %d 1234, y %d 11110\n", 42 | T_CONV creal (tc_result), T_CONV cimag (tc_result), 43 | T_CONV creal (2.0), T_CONV creal (8.0), tc_int_arg_x, tc_y); 44 | 45 | CHECK (creal (tc_result) == -2); 46 | CHECK (cimag (tc_result) == 8); 47 | CHECK (tc_int_arg_x == 1234); 48 | CHECK (*tc_ptr_arg_y == 11110); 49 | 50 | exit(0); 51 | } 52 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/complex_defs_double.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | /* Complex base type. */ 3 | #define T_FFI_TYPE ffi_type_complex_double 4 | /* C type corresponding to the base type. */ 5 | #define T_C_TYPE double 6 | /* C cast for a value of type T_C_TYPE that is passed to printf. */ 7 | #define T_CONV 8 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/complex_defs_float.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | /* Complex base type. */ 3 | #define T_FFI_TYPE ffi_type_complex_float 4 | /* C type corresponding to the base type. */ 5 | #define T_C_TYPE float 6 | /* C cast for a value of type T_C_TYPE that is passed to printf. */ 7 | #define T_CONV (double) 8 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/complex_defs_longdouble.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | /* Complex base type. */ 3 | #define T_FFI_TYPE ffi_type_complex_longdouble 4 | /* C type corresponding to the base type. */ 5 | #define T_C_TYPE long double 6 | /* C cast for a value of type T_C_TYPE that is passed to printf. */ 7 | #define T_CONV 8 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check complex types. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check complex types. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check complex types. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/ffitest.h: -------------------------------------------------------------------------------- 1 | #include "../libffi.call/ffitest.h" 2 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/many_complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex, with many arguments 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "many_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/many_complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex, with many arguments 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "many_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/many_complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex, with many arguments 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "many_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | #include "ffitest.h" 3 | #include 4 | 5 | static _Complex T_C_TYPE return_c(_Complex T_C_TYPE c) 6 | { 7 | printf ("%f,%fi\n", T_CONV creal (c), T_CONV cimag (c)); 8 | return 2 * c; 9 | } 10 | int main (void) 11 | { 12 | ffi_cif cif; 13 | ffi_type *args[MAX_ARGS]; 14 | void *values[MAX_ARGS]; 15 | _Complex T_C_TYPE c, rc, rc2; 16 | T_C_TYPE cr, ci; 17 | 18 | args[0] = &T_FFI_TYPE; 19 | values[0] = &c; 20 | 21 | /* Initialize the cif */ 22 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 23 | &T_FFI_TYPE, args) == FFI_OK); 24 | 25 | for (cr = -127.0; cr < 127; cr++) 26 | { 27 | ci = 1000.0 - cr; 28 | c = cr + ci * I; 29 | ffi_call(&cif, FFI_FN(return_c), &rc, values); 30 | rc2 = return_c(c); 31 | printf ("%f,%fi vs %f,%fi\n", 32 | T_CONV creal (rc), T_CONV cimag (rc), 33 | T_CONV creal (rc2), T_CONV cimag (rc2)); 34 | CHECK(rc == 2 * c); 35 | } 36 | exit(0); 37 | } 38 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex1.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | #include "ffitest.h" 3 | #include 4 | 5 | static _Complex T_C_TYPE return_c(_Complex T_C_TYPE c1, float fl2, unsigned int in3, _Complex T_C_TYPE c4) 6 | { 7 | return c1 + fl2 + in3 + c4; 8 | } 9 | int main (void) 10 | { 11 | ffi_cif cif; 12 | ffi_type *args[MAX_ARGS]; 13 | void *values[MAX_ARGS]; 14 | _Complex T_C_TYPE c1, c4, rc, rc2; 15 | float fl2; 16 | unsigned int in3; 17 | args[0] = &T_FFI_TYPE; 18 | args[1] = &ffi_type_float; 19 | args[2] = &ffi_type_uint; 20 | args[3] = &T_FFI_TYPE; 21 | values[0] = &c1; 22 | values[1] = &fl2; 23 | values[2] = &in3; 24 | values[3] = &c4; 25 | 26 | /* Initialize the cif */ 27 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 28 | &T_FFI_TYPE, args) == FFI_OK); 29 | c1 = 127.0 + 255.0 * I; 30 | fl2 = 128.0; 31 | in3 = 255; 32 | c4 = 512.7 + 1024.1 * I; 33 | 34 | ffi_call(&cif, FFI_FN(return_c), &rc, values); 35 | rc2 = return_c(c1, fl2, in3, c4); 36 | printf ("%f,%fi vs %f,%fi\n", 37 | T_CONV creal (rc), T_CONV cimag (rc), 38 | T_CONV creal (rc2), T_CONV cimag (rc2)); 39 | CHECK(rc == rc2); 40 | exit(0); 41 | } 42 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex1_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "return_complex1.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex1_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "return_complex1.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex1_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "return_complex1.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex2.inc: -------------------------------------------------------------------------------- 1 | /* -*-c-*- */ 2 | #include "ffitest.h" 3 | #include 4 | 5 | _Complex T_C_TYPE 6 | return_c(_Complex T_C_TYPE c1, _Complex T_C_TYPE c2, 7 | unsigned int in3, _Complex T_C_TYPE c4) 8 | { 9 | volatile _Complex T_C_TYPE r = c1 + c2 + in3 + c4; 10 | return r; 11 | } 12 | 13 | int main (void) 14 | { 15 | ffi_cif cif; 16 | ffi_type *args[MAX_ARGS]; 17 | void *values[MAX_ARGS]; 18 | _Complex T_C_TYPE c1, c2, c4, rc, rc2; 19 | unsigned int in3; 20 | args[0] = &T_FFI_TYPE; 21 | args[1] = &T_FFI_TYPE; 22 | args[2] = &ffi_type_uint; 23 | args[3] = &T_FFI_TYPE; 24 | values[0] = &c1; 25 | values[1] = &c2; 26 | values[2] = &in3; 27 | values[3] = &c4; 28 | 29 | /* Initialize the cif */ 30 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 31 | &T_FFI_TYPE, args) == FFI_OK); 32 | c1 = 127.0 + 255.0 * I; 33 | c2 = 128.0 + 256.0; 34 | in3 = 255; 35 | c4 = 512.7 + 1024.1 * I; 36 | 37 | ffi_call(&cif, FFI_FN(return_c), &rc, values); 38 | rc2 = return_c(c1, c2, in3, c4); 39 | printf ("%f,%fi vs %f,%fi\n", 40 | T_CONV creal (rc), T_CONV cimag (rc), 41 | T_CONV creal (rc2), T_CONV cimag (rc2)); 42 | CHECK(rc == rc2); 43 | exit(0); 44 | } 45 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex2_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "return_complex2.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex2_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "return_complex2.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex2_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "return_complex2.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex_double.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_double.inc" 10 | #include "return_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex_float.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_float.inc" 10 | #include "return_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.complex/return_complex_longdouble.c: -------------------------------------------------------------------------------- 1 | /* Area: ffi_call 2 | Purpose: Check return value complex. 3 | Limitations: none. 4 | PR: none. 5 | Originator: . */ 6 | 7 | /* { dg-do run } */ 8 | 9 | #include "complex_defs_longdouble.inc" 10 | #include "return_complex.inc" 11 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.go/aa-direct.c: -------------------------------------------------------------------------------- 1 | /* { dg-do run } */ 2 | 3 | #include "static-chain.h" 4 | 5 | #if defined(__GNUC__) && !defined(__clang__) && defined(STATIC_CHAIN_REG) 6 | 7 | #include "ffitest.h" 8 | 9 | /* Blatent assumption here that the prologue doesn't clobber the 10 | static chain for trivial functions. If this is not true, don't 11 | define STATIC_CHAIN_REG, and we'll test what we can via other tests. */ 12 | void *doit(void) 13 | { 14 | register void *chain __asm__(STATIC_CHAIN_REG); 15 | return chain; 16 | } 17 | 18 | int main() 19 | { 20 | ffi_cif cif; 21 | void *result; 22 | 23 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 0, &ffi_type_pointer, NULL) == FFI_OK); 24 | 25 | ffi_call_go(&cif, FFI_FN(doit), &result, NULL, &result); 26 | 27 | CHECK(result == &result); 28 | 29 | return 0; 30 | } 31 | 32 | #else /* UNSUPPORTED */ 33 | int main() { return 0; } 34 | #endif 35 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.go/closure1.c: -------------------------------------------------------------------------------- 1 | /* { dg-do run } */ 2 | 3 | #include "ffitest.h" 4 | 5 | void doit(ffi_cif *cif, void *rvalue, void **avalue, void *closure) 6 | { 7 | (void)cif; 8 | (void)avalue; 9 | *(void **)rvalue = closure; 10 | } 11 | 12 | typedef void * (*FN)(void); 13 | 14 | int main() 15 | { 16 | ffi_cif cif; 17 | ffi_go_closure cl; 18 | void *result; 19 | 20 | CHECK(ffi_prep_cif(&cif, ABI_NUM, 0, &ffi_type_pointer, NULL) == FFI_OK); 21 | CHECK(ffi_prep_go_closure(&cl, &cif, doit) == FFI_OK); 22 | 23 | ffi_call_go(&cif, FFI_FN(*(FN *)&cl), &result, NULL, &cl); 24 | 25 | CHECK(result == &cl); 26 | 27 | exit(0); 28 | } 29 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.go/ffitest.h: -------------------------------------------------------------------------------- 1 | #include "../libffi.call/ffitest.h" 2 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.go/go.exp: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2003, 2006, 2009, 2010, 2014 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 | set tlist [lsort [glob -nocomplain -- $srcdir/$subdir/*.{c,cc}]] 23 | 24 | if { [libffi_feature_test "#ifdef FFI_GO_CLOSURES"] } { 25 | run-many-tests $tlist "" 26 | } else { 27 | foreach test $tlist { 28 | unsupported "$test" 29 | } 30 | } 31 | 32 | dg-finish 33 | 34 | # Local Variables: 35 | # tcl-indent-level:4 36 | # End: 37 | -------------------------------------------------------------------------------- /libffi-sys-rs/libffi/testsuite/libffi.go/static-chain.h: -------------------------------------------------------------------------------- 1 | #ifdef __aarch64__ 2 | # define STATIC_CHAIN_REG "x18" 3 | #elif defined(__alpha__) 4 | # define STATIC_CHAIN_REG "$1" 5 | #elif defined(__arm__) 6 | # define STATIC_CHAIN_REG "ip" 7 | #elif defined(__sparc__) 8 | # if defined(__arch64__) || defined(__sparcv9) 9 | # define STATIC_CHAIN_REG "g5" 10 | # else 11 | # define STATIC_CHAIN_REG "g2" 12 | # endif 13 | #elif defined(__x86_64__) 14 | # define STATIC_CHAIN_REG "r10" 15 | #elif defined(__i386__) 16 | # ifndef ABI_NUM 17 | # define STATIC_CHAIN_REG "ecx" /* FFI_DEFAULT_ABI only */ 18 | # endif 19 | #endif 20 | -------------------------------------------------------------------------------- /libffi-sys-rs/release.toml: -------------------------------------------------------------------------------- 1 | pre-release-replacements = [ 2 | { file="README.md", search="libffi-sys = \"[0-9.]*\"", replace="libffi-sys = \"{{version}}\"" }, 3 | { file="README.md", search="version = \"[0-9.]*\"", replace="version = \"{{version}}\"" }, 4 | { file="src/lib.rs", search="libffi-sys = \"[0-9.]*\"", replace="libffi-sys = \"{{version}}\"" }, 5 | { file="src/lib.rs", search="version = \"[0-9.]*\"", replace="version = \"{{version}}\"" }, 6 | { file="src/lib.rs", search="https://docs[.]rs/libffi-sys/[0-9.]*", replace="https://docs.rs/libffi-sys/{{version}}" }, 7 | { file="CHANGELOG.md", search="\\[Unreleased\\]", replace="[{{version}}] - {{date}}" } 8 | ] 9 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | # qemutests.sh 2 | 3 | This script uses QEMU to run tests on the following CPU architectures: 4 | 5 | * ARMv7 6 | * PowerPC64 7 | * PowerPC64 little-endian 8 | * Riscv64 9 | * S390X 10 | * Sparc64 11 | 12 | The script has been tested on Debian and Ubuntu, and requires `gcc` and `rustup` 13 | to be installed. 14 | 15 | ## Usage 16 | 17 | Run `scripts/qemutests.sh SETUP` to set up everything needed to run tests and 18 | run the tests. 19 | 20 | If everything is already set up, this script can be executed with 21 | `scripts/qemutests.sh`. --------------------------------------------------------------------------------