110 Commits

Author SHA1 Message Date
Anthony Green
074c423f86 feat: Add ffi_get_default_abi and ffi_get_closure_size functions 2025-06-08 07:30:54 -04:00
Anthony Green
bac99f2f3f
Release candidate 1 for 3.5.0. Windows build fixes. (#916)
* refactor(ci): improve wget retry logic in .ci/install.sh

* build(github-actions): use static runtime library in build

* refactor(ffi.h.in): export version API

* chore: update libffi version to 3.5.0-rc1
2025-06-05 06:12:10 -04:00
Anthony Green
c9a3a06f9b feat(libffi): upgrade to version 3.5.0 and add version API 2025-05-26 08:18:13 -04:00
KJ Tsanaktsidis
01db744b4a
Disable ASAN in ffi_call_int functions (#858)
The pattern for several of the architectures is for ffi_call_int to
stack-allocate some arguments + the registers, and then
ffi_call_$ARCH will pop the top of that structure into registers, and
then adjust the stack pointer such that the alloca'd buffer _becomes_
the stack-passed arguments for the function being called.

If libffi is compiled with ASAN, then there will be a redzone inserted
after the alloca'd buffer which is marked as poisoned. This redzone
appears beyond the end of $sp upon entry to the called function.

If the called function does anything to use this stack memory, ASAN will
notice that it's poisoned and report an error.

This commit fixes the situation (on the architectures that I have access
to) disabling instrumentation for ffi_call_int; that means there will be
no alloca redzone left on the shadow-stack.
2024-09-20 06:00:49 -04:00
Bill Roberts
45d284f2d0
aarch64: support pointer authentication (#834)
* aarch64: fix callstack in ffi_call_SYSV

The debug stack gets corrupted between the frame and stack pivots, update
the CFI directives so the call stack stays correct in the debugger.

str     x9, [x1, #32] // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> main() (good)
mov     x29, x1       // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> ffi_call() -> main() (bad)
mov     sp, x0        // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> main() (good)

The CFA data needs to be updated around the pivots, after this patch the
callstack stays correct.

Signed-off-by: Bill Roberts <bill.roberts@arm.com>

* aarch64: remove uneeded CFI directive

This directive doesn't actually set the CFA to anything valid, and
during unwinding this isn't even used. Note that the PAC/Darwin usage
is quite suspect as well, as the CFA is either x1 or x29 after the frame
pivot, and the CFA address is what's used as the modifier when verifying
the PAC. At least this is the behavior on Linux with PAC, I need to
verify ARME ABI unwinding. So for now leave Darwin as is.

Signed-off-by: Bill Roberts <bill.roberts@arm.com>

* ptrauth: rename define for clarity

Rename the HAVE_PTRAUTH define for clarity that its associated with the
ARM64E ABI and not the ARM64 ABI that can be supported on Linux and
enabled with -mbranch-protection=standard.

Signed-off-by: Bill Roberts <bill.roberts@arm.com>

* aarch64: add PAC support to ffi_call_SYSV

Support AARCH64 Pointer Authentication Codes (PAC) within ffi_call_SYSV
and support exception unwinding.

The Linux ABI for PAC is to use paciasp/autiasp instructions which also
have hint space equivelent instructions. They sign the LR (x30) with the
A key and the current stack pointer as the salt. Note that this can also be
configured to use the B key and will use pacibsp/autibsp hint instructions.

The Linux ABI for exception frame data when PAC is enabled assumes that the
Connonical Frame Address, or CFA is equal to the stack pointer. I.E sp is
equal to x29 (fp). When the unwinder is invoked the cfa will point to
the frame which will include the *signed* return address from the LR.
This will then be passed to __builtin_aarch64_autia1716 where the CFA
will be used as the salt and stored to register x16 and register x17
will contain the signed address to demangle. This can be noted in:
  - d6d7afcdbc/libgcc/config/aarch64/aarch64-unwind.h (L56)

The other required portion of this is to indicate to the unwinder that
this is a signed address that needs to go the special demangle route in
the unwinder. This is accomplished by using CFI directive "cfi_window_save"
which marks that frame as being signed.

Putting all of this together is a bit tricky, as the internals of
ffi_call_SYSV the callee allocates its stack and frame and passes it in
arg1 (x0) and arg2 (x1) to the called function, where that function
pivots its stack, so care must be taken to get the sp == fp before
paciasp is called and also restore that state before autiasp is called.

Signed-off-by: Bill Roberts <bill.roberts@arm.com>

---------

Signed-off-by: Bill Roberts <bill.roberts@arm.com>
2024-06-01 13:34:53 -04:00
Anthony Green
cd78b53912 Always define long double types. 2024-02-18 07:48:51 -05:00
Виктор Чернякин
a1c391bd8e
Fix a variety of warnings (#811) 2023-12-22 05:30:50 -05:00
Nobuyoshi Nakada
c23e9a1c81
Check if FFI_GO_CLOSURES is defined (#796)
This macro is always defined to 1 if defined, or undefined.
With `-Wundef` option, checking the value without checking if it is defined causes warnings:

```
/opt/local/include/ffi.h:477:5: warning: 'FFI_GO_CLOSURES' is not defined, evaluates to 0 [-Wundef]
#if FFI_GO_CLOSURES
    ^
```
2023-10-21 07:44:24 -04:00
serge-sans-paille
ce077e5565
Forward declare open_temp_exec_file (#764)
It's defined in closures.c and used in tramp.c.
Also declare it as an hidden symbol, as it should be.

Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
2023-02-02 09:46:29 -05:00
Anthony Green
e58e22b223 From Dave Anglin:
A couple of years ago the 32-bit hppa targets were converted from using a trampoline executed on the stack to the function descriptor technique used by ia64. This is more efficient and avoids having to have an executable stack. However, function pointers on 32-bit need the PLABEL bit set in the pointer. It distinguishes between pointers that point directly to the executable code and pointer that point to a function descriptor. We need the later for libffi. But as a result, it is not possible to convert using casts data pointers to function pointers.

The solution at the time was to set the PLABEL bit in hppa closure pointers using FFI_CLOSURE_PTR. However, I realized recently that this was a bad choice. Packages like python-cffi allocate their own closure pointers, so this isn't going to work well there.

A better solution is to leave closure pointers unchanged and only set the PLABEL bit in pointers used to point to executable code.

The attached patch drops the FFI_CLOSURE_PTR and FFI_RESTORE_PTR defines. This allows some cleanup in the hppa closure routines. The FFI_FN define is now used to set the PLABEL bit on hppa. ffi_closure_alloc is modified to set the PLABEL bit in the value set in *code.

I also added a FFI_CL define to convert a function pointer to a closure pointer. It is only used in one test case.
2023-02-02 07:02:53 -05:00
Xavier Claessens
2b2f61f6e6
Small build cleanup (#743)
* configure.ac: Remove some unused checks

* Fix FFI_API definition

When doing a static build dllimport/dllexport should be disabled. It was
also using 2 different macros FFI_BUILDING_DLL and FFI_BUILDING for no
reason.
2022-10-24 14:39:04 -04:00
musvaage
f7233db2a7
typos (#742) 2022-10-17 18:26:17 -04:00
Anthony Green
598ea692b8 Clean ups, preparing for new release 2022-09-19 06:43:41 -04:00
Ole André Vadla Ravnås
e6d05bea0b
Fix struct padding warning reported by MSVC (#613)
When building on 32-bit x86.
2022-09-01 08:51:15 -04:00
matoro
5264a7c5cd
Move FFI_TYPE definitions above <ffitarget.h> include (#722)
For powerpc at least, these definitions are referenced in the
target-specific ffitarget.h.  Discovered in the jffi project.  Should
close https://github.com/libffi/libffi/issues/637.  Downstream jffi bug
https://github.com/jnr/jffi/issues/107.  Downstream distro bug
https://bugs.gentoo.org/827215.

Testing - both libffi and jffi test suites pass with this patch applied,
at least on ppc64le linux.  I did not see any warnings about
redefinitions.

Tested versions - libffi 3.4.2, jffi 1.3.6 and 1.3.9.
2022-07-21 17:54:19 -04:00
Jeremy Huddleston Sequoia
cd4428911d
Add missing FFI_HIDDEN to ffi_tramp_is_present declaration (#651)
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2021-06-28 07:56:30 -04:00
Anthony Green
1e5dc8de82 Add missing file from make dist. Add missing license info. 2021-06-26 12:08:35 -04:00
Anthony Green
205cf01b57
Bug #680. Don't accept floats or small ints as var args. (#628)
* Bug #680.  Don't accept floats or small ints as var args.

* Bug #680.  Don't accept floats or small ints as var args.

* Bug #680.  Don't accept floats or small ints as var args.
2021-03-23 11:31:08 -04:00
Madhavan T. Venkataraman
9ba559217b
Static tramp v5 (#624)
* Static Trampolines

Closure Trampoline Security Issue
=================================

Currently, the trampoline code used in libffi is not statically defined in
a source file (except for MACH). The trampoline is either pre-defined
machine code in a data buffer. Or, it is generated at runtime. In order to
execute a trampoline, it needs to be placed in a page with executable
permissions.

Executable data pages are attack surfaces for attackers who may try to
inject their own code into the page and contrive to have it executed. The
security settings in a system may prevent various tricks used in user land
to write code into a page and to have it executed somehow. On such systems,
libffi trampolines would not be able to run.

Static Trampoline
=================

To solve this problem, the trampoline code needs to be defined statically
in a source file, compiled and placed in the text segment so it can be
mapped and executed naturally without any tricks. However, the trampoline
needs to be able to access the closure pointer at runtime.

PC-relative data referencing
============================

The solution implemented in this patch set uses PC-relative data references.
The trampoline is mapped in a code page. Adjacent to the code page, a data
page is mapped that contains the parameters of the trampoline:

	- the closure pointer
	- pointer to the ABI handler to jump to

The trampoline code uses an offset relative to its current PC to access its
data.

Some architectures support PC-relative data references in the ISA itself.
E.g., X64 supports RIP-relative references. For others, the PC has to
somehow be loaded into a general purpose register to do PC-relative data
referencing. To do this, we need to define a get_pc() kind of function and
call it to load the PC in a desired register.

There are two cases:

1. The call instruction pushes the return address on the stack.

   In this case, get_pc() will extract the return address from the stack
   and load it in the desired register and return.

2. The call instruction stores the return address in a designated register.

   In this case, get_pc() will copy the return address to the desired
   register and return.

Either way, the PC next to the call instruction is obtained.

Scratch register
================

In order to do its job, the trampoline code would need to use a scratch
register. Depending on the ABI, there may not be a register available for
scratch. This problem needs to be solved so that all ABIs will work.

The trampoline will save two values on the stack:

	- the closure pointer
	- the original value of the scratch register

This is what the stack will look like:

	sp before trampoline ------>	--------------------
					| closure pointer  |
					--------------------
					| scratch register |
	sp after trampoline ------->	--------------------

The ABI handler can do the following as needed by the ABI:

	- the closure pointer can be loaded in a desired register

	- the scratch register can be restored to its original value

	- the stack pointer can be restored to its original value
	  (the value when the trampoline was invoked)

To do this, I have defined prolog code for each ABI handler. The legacy
trampoline jumps to the ABI handler directly. But the static trampoline
defined in this patch jumps tp the prolog code which performs the above
actions before jumping to the ABI handler.

Trampoline Table
================

In order to reduce the trampoline memory footprint, the trampoline code
would be defined as a code array in the text segment. This array would be
mapped into the address space of the caller. The mapping would, therefore,
contain a trampoline table.

Adjacent to the trampoline table mapping, there will be a data mapping that
contains a parameter table, one parameter block for each trampoline. The
parameter block will contain:

	- a pointer to the closure
	- a pointer to the ABI handler

The static trampoline code would finally look like this:

	- Make space on the stack for the closure and the scratch register
	  by moving the stack pointer down
	- Store the original value of the scratch register on the stack
	- Using PC-relative reference, get the closure pointer
	- Store the closure pointer on the stack
	- Using PC-relative reference, get the ABI handler pointer
	- Jump to the ABI handler

Mapping size
============

The size of the code mapping that contains the trampoline table needs to be
determined on a per architecture basis. If a particular architecture
supports multiple base page sizes, then the largest supported base page size
needs to be chosen. E.g., we choose 16K for ARM64.

Trampoline allocation and free
==============================

Static trampolines are allocated in ffi_closure_alloc() and freed in
ffi_closure_free().

Normally, applications use these functions. But there are some cases out
there where the user of libffi allocates and manages its own closure
memory. In such cases, static trampolines cannot be used. These will
fall back to using legacy trampolines. The user has to make sure that
the memory is executable.

ffi_closure structure
=====================

I did not want to make any changes to the size of the closure structure for
this feature to guarantee compatibility. But the opaque static trampoline
handle needs to be stored in the closure. I have defined it as follows:

-  char tramp[FFI_TRAMPOLINE_SIZE];
+  union {
+    char tramp[FFI_TRAMPOLINE_SIZE];
+    void *ftramp;
+  };

If static trampolines are used, then tramp[] is not needed to store a
dynamic trampoline. That space can be reused to store the handle. Hence,
the union.

Architecture Support
====================

Support has been added for x64, i386, aarch64 and arm. Support for other
architectures can be added very easily in the future.

OS Support
==========

Support has been added for Linux. Support for other OSes can be added very
easily.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>

* x86: Support for Static Trampolines

	- Define the arch-specific initialization function ffi_tramp_arch ()
	  that returns trampoline size information to common code.

	- Define the trampoline code mapping and data mapping sizes.

	- Define the trampoline code table statically. Define two tables,
	  actually, one with CET and one without.

	- Introduce a tiny prolog for each ABI handling function. The ABI
	  handlers addressed are:

	  	- ffi_closure_unix64
		- ffi_closure_unix64_sse
		- ffi_closure_win64

	  The prolog functions are called:

		- ffi_closure_unix64_alt
		- ffi_closure_unix64_sse_alt
		- ffi_closure_win64_alt

	  The legacy trampoline jumps to the ABI handler. The static
	  trampoline jumps to the prolog function. The prolog function uses
	  the information provided by the static trampoline, sets things up
	  for the ABI handler and then jumps to the ABI handler.

	- Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to
	  initialize static trampoline parameters.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>

* i386: Support for Static Trampolines

	- Define the arch-specific initialization function ffi_tramp_arch ()
	  that returns trampoline size information to common code.

	- Define the trampoline code table statically. Define two tables,
	  actually, one with CET and one without.

	- Define the trampoline code table statically.

	- Introduce a tiny prolog for each ABI handling function. The ABI
	  handlers addressed are:

	  	- ffi_closure_i386
		- ffi_closure_STDCALL
		- ffi_closure_REGISTER

	  The prolog functions are called:

	  	- ffi_closure_i386_alt
		- ffi_closure_STDCALL_alt
		- ffi_closure_REGISTER_alt

	  The legacy trampoline jumps to the ABI handler. The static
	  trampoline jumps to the prolog function. The prolog function uses
	  the information provided by the static trampoline, sets things up
	  for the ABI handler and then jumps to the ABI handler.

	- Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to
	  initialize static trampoline parameters.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>

* arm64: Support for Static Trampolines

	- Define the arch-specific initialization function ffi_tramp_arch ()
	  that returns trampoline size information to common code.

	- Define the trampoline code mapping and data mapping sizes.

	- Define the trampoline code table statically.

	- Introduce a tiny prolog for each ABI handling function. The ABI
	  handlers addressed are:

	  	- ffi_closure_SYSV
		- ffi_closure_SYSV_V

	  The prolog functions are called:

	  	- ffi_closure_SYSV_alt
		- ffi_closure_SYSV_V_alt

	  The legacy trampoline jumps to the ABI handler. The static
	  trampoline jumps to the prolog function. The prolog function uses
	  the information provided by the static trampoline, sets things up
	  for the ABI handler and then jumps to the ABI handler.

	- Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to
	  initialize static trampoline parameters.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>

* arm: Support for Static Trampolines

	- Define the arch-specific initialization function ffi_tramp_arch ()
	  that returns trampoline size information to common code.

	- Define the trampoline code mapping and data mapping sizes.

	- Define the trampoline code table statically.

	- Introduce a tiny prolog for each ABI handling function. The ABI
	  handlers addressed are:

	  	- ffi_closure_SYSV
		- ffi_closure_VFP

	  The prolog functions are called:

	  	- ffi_closure_SYSV_alt
		- ffi_closure_VFP_alt

	  The legacy trampoline jumps to the ABI handler. The static
	  trampoline jumps to the prolog function. The prolog function uses
	  the information provided by the static trampoline, sets things up
	  for the ABI handler and then jumps to the ABI handler.

	- Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to
	  initialize static trampoline parameters.

Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
2021-03-05 11:07:30 -05:00
Moxie Bot
8eb2d2b056 Revamp PA_LINUX and PA_HPUX target closures to use function descriptors.
2020-02-23  John David Anglin  <danglin@gcc.gnu.org>

	* include/ffi.h.in (FFI_CLOSURE_PTR, FFI_RESTORE_PTR): Define.
	* src/closures.c (ffi_closure_alloc): Convert closure pointer
	return by malloc to function pointer.
	(ffi_closure_free): Convert function pointer back to malloc pointer.
	* src/pa/ffi.c (ffi_closure_inner_pa32): Use union to double word
	align return address on stack.  Adjust statements referencing return
	address.  Convert closure argument from function pointer to standard
	closure pointer.
	(ffi_prep_closure_loc): Likewise convert closure argument back to
	closure pointer.  Remove assembler trampolines.  Setup simulated
	function descriptor as on ia64.
	src/pa/ffitarget.h (FFI_TRAMPOLINE_SIZE): Reduce to 12.
	src/pa/hpux32.S (ffi_closure_pa32): Retrieve closure pointer and real
	gp from fake gp value in register %r19.
	src/pa/linux.S (ffi_closure_pa32): Likewise.
2020-02-24 10:29:20 -05:00
Anthony Green
3a7580da73 Mark java raw APIs as deprecated. 2019-11-13 07:59:18 -05:00
Jeremy Huddleston Sequoia
05a1796419 Cleanup symbol exports on darwin and add architecture preprocessor checks to assist in building fat binaries (eg: i386+x86_64 on macOS or arm+aarch64 on iOS) (#450)
* x86: Ensure _efi64 suffixed symbols are not exported

* x86: Ensure we do not export ffi_prep_cif_machdep

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

* x86: Ensure we don't export ffi_call_win64, ffi_closure_win64, or ffi_go_closure_win64

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

* closures: Silence a semantic warning

libffi/src/closures.c:175:23: This function declaration is not a prototype

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

* aarch64: Ensure we don't export ffi_prep_cif_machdep

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

* arm: Ensure we don't export ffi_prep_cif_machdep

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

* aarch64, arm, x86: Add architecture preprocessor checks to support easier fat builds (eg: iOS)

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

* x86: Silence some static analysis warnings

libffi/src/x86/ffi64.c:286:21: The left operand of '!=' is a garbage value due to array index out of bounds
libffi/src/x86/ffi64.c:297:22: The left operand of '!=' is a garbage value due to array index out of bounds

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

* aarch: Use FFI_HIDDEN rather than .hidden

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>

* ffi.h: Don't advertise ffi_java_rvalue_to_raw, ffi_prep_java_raw_closure, and ffi_prep_java_raw_closure_loc when FFI_NATIVE_RAW_API is 0

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2019-02-19 07:11:28 -05:00
Florian Weimer
44a6c28545 aarch64: Flush code mapping in addition to data mapping (#471)
This needs a new function, ffi_data_to_code_pointer, to translate
from data pointers to code pointers.

Fixes issue #470.
2019-02-19 06:55:11 -05:00
Gregory Pakosz
e6eac7863e Prefix ALIGN_DOWN macro with FFI_ 2018-09-18 15:19:53 +02:00
fwg
af6773d6ab Fix appveyor windows build (#420)
* Fix msvcc dll build by adding dllexport decorations to all API declarations

* Fix appveyor build for VS 2013

Use the new -DFFI_BUILDING_DLL for producing a working DLL. Update the
msvcc.sh wrapper script to successfully compile the testsuite files.

* MSVC build: suppress warnings in testsuite

* fix testsuite on appveyor
2018-04-02 06:55:31 -05:00
Stef O'Rear
3840d49aaa New RISC-V port (#281)
* Add RISC-V support

This patch adds support for the RISC-V architecture (https://riscv.org).

This patch has been tested using QEMU user-mode emulation and GCC 7.2.0
in the following configurations:

* -march=rv32imac -mabi=ilp32
* -march=rv32g -mabi=ilp32d
* -march=rv64imac -mabi=lp64
* -march=rv64g -mabi=lp64d

The ABI currently can be found at
https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md .

* Add RISC-V to README

* RISC-V: fix configure.host
2018-03-11 08:55:15 -04:00
Reini Urban
9c6cb58812 __attribute__ deprecated (msg) only since gcc 4.5
make it work with older compilers
2017-07-04 17:12:23 +02:00
Gregory Pakosz
bd72848c7a Prefix ALIGN macros with FFI_ 2017-04-27 13:22:28 +02:00
Yen Chi Hsuan
982b89c01a Install public headers in the standard path 2016-11-13 19:20:53 +08:00
Tom Tromey
b50eabf489 minor comment cleanup
This patch minor cleans up ffi.h.in comments in a minor way.  It fixes
some typos and capitalizations, adds some periods, and reformats some
comments to a more GNU-ish style.  It also fixes up some stale
documentation.
2016-05-04 06:39:21 -10:00
Tom Tromey
6c07077a61 Change ffi.h.in so that braces match
This is a tiny refactoring to make it so brace-matching works in
Emacs.
2016-05-04 06:38:34 -10:00
Tom Tromey
2fbc0369b8 move ffi_prep_cif_core to ffi_common.h 2016-05-04 06:38:34 -10:00
Tom Tromey
38a4d72c95 add ffi_get_struct_offsets 2016-02-22 16:07:55 -07:00
Anthony Green
0bb71b52f5 Merge pull request #211 from tromey/move-prep-types-out-of-ffi.h
ffi_prep_types is internal-only
2016-02-20 06:41:10 -05:00
Tom Tromey
4805bf9ccd remove FFI_TYPE typedef 2015-11-19 14:17:42 -07:00
Tom Tromey
8bec5ca26a ffi_prep_types is internal-only 2015-11-15 10:51:14 -07:00
Tom Tromey
ff33ddd1ab mark ffi_prep_closure as deprecated 2015-11-07 12:04:24 -07:00
Richard Henderson
5d69d57a05 configure: Move target source selection into configure.host
This eliminates the AM_CONDITIONAL ugliness, which eliminates
just a bit of extra boilerplate for a new target.

At the same time, properly categorize the EXTRA_DIST files
into SOURCES and HEADERS, for the generation of ctags.
2014-11-14 13:06:12 +01:00
Richard Henderson
89bbde8b4e Add ffi_cfi.h
Have one copy of the HAVE_AS_CFI_PSEUDO_OP code
to share between all backends.
2014-11-12 09:15:35 +01:00
Richard Henderson
e951d64c08 Add entry points for interacting with Go
A "ffi_go_closure" is intended to be compatible with the
function descriptors used by Go, and ffi_call_go sets up
the static chain parameter for calling a Go function.

The entry points are disabled when a backend has not been
updated, much like we do for "normal" closures.
2014-11-12 09:15:35 +01:00
Dominik Vogt
6e8a446083 2014-07-22 Dominik Vogt <vogt@linux.vnet.ibm.com>
* src/types.c (FFI_TYPEDEF, FFI_NONCONST_TYPEDEF): Merge the macros by
	adding another argument that controls whether the result is const or not
	(FFI_LDBL_CONST): Temporary macro to reduce ifdef confusion
	* src/prep_cif.c (ffi_prep_cif_core): Replace list of systems with new
	macro FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
	* src/pa/ffitarget.h (FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION):
	Define.
	* src/s390/ffitarget.h (FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION):
	Define.
	* src/x86/ffitarget.h (FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION):
	Define.

2014-07-22  Dominik Vogt  <vogt@linux.vnet.ibm.com>

	* doc/libffi.texi (Primitive Types): Document ffi_type_complex_float,
	ffi_type_complex_double and ffi_type_complex_longdouble
	(Complex Types): New subsection.
	(Complex Type Example): Ditto.
	* testsuite/libffi.call/cls_align_complex_double.c: New
	FFI_TYPE_COMPLEX test.
	* testsuite/libffi.call/cls_align_complex_float.c: Ditto.
	* testsuite/libffi.call/cls_align_complex_longdouble.c: Ditto.
	* testsuite/libffi.call/cls_complex_double.c: Ditto.
	* testsuite/libffi.call/cls_complex_float.c: Ditto.
	* testsuite/libffi.call/cls_complex_longdouble.c: Ditto.
	* testsuite/libffi.call/cls_complex_struct_double.c: Ditto.
	* testsuite/libffi.call/cls_complex_struct_float.c: Ditto.
	* testsuite/libffi.call/cls_complex_struct_longdouble.c: Ditto.
	* testsuite/libffi.call/cls_complex_va_double.c: Ditto.
	* testsuite/libffi.call/cls_complex_va_float.c: Ditto.
	* testsuite/libffi.call/cls_complex_va_longdouble.c: Ditto.
	* testsuite/libffi.call/complex_double.c: Ditto.
	* testsuite/libffi.call/complex_defs_double.c: Ditto.
	* testsuite/libffi.call/complex_float.c: Ditto.
	* testsuite/libffi.call/complex_defs_float.c: Ditto.
	* testsuite/libffi.call/complex_longdouble.c: Ditto.
	* testsuite/libffi.call/complex_defs_longdouble.c: Ditto.
	* testsuite/libffi.call/complex_int.c: Ditto.
	* testsuite/libffi.call/many_complex_double.c: Ditto.
	* testsuite/libffi.call/many_complex_float.c: Ditto.
	* testsuite/libffi.call/many_complex_longdouble.c: Ditto.
	* testsuite/libffi.call/return_complex1_double.c: Ditto.
	* testsuite/libffi.call/return_complex1_float.c: Ditto.
	* testsuite/libffi.call/return_complex1_longdouble.c: Ditto.
	* testsuite/libffi.call/return_complex2_double.c: Ditto.
	* testsuite/libffi.call/return_complex2_float.c: Ditto.
	* testsuite/libffi.call/return_complex2_longdouble.c: Ditto.
	* testsuite/libffi.call/return_complex_double.c: Ditto.
	* testsuite/libffi.call/return_complex_float.c: Ditto.
	* testsuite/libffi.call/return_complex_longdouble.c: Ditto.
	* src/raw_api.c (ffi_raw_to_ptrarray): Handle FFI_TYPE_COMPLEX
	(ffi_ptrarray_to_raw): Ditto.
	* src/prep_cif.c (ffi_prep_cif_core): Abort if FFI_TYPE_COMPLEX is not
	implemented in libffi for the target.
	* src/java_raw_api.c (ffi_java_raw_size): FFI_TYPE_COMPLEX not supported
	yet (abort).
	(ffi_java_raw_to_ptrarray): Ditto.
	(ffi_java_rvalue_to_raw): Ditto.
	(ffi_java_raw_to_rvalue):  Ditto.
	* src/debug.c (ffi_type_test): Add debug tests for complex types.
	* include/ffi.h.in (FFI_TYPE_COMPLEX): Add new FFI_TYPE_COMPLEX.
	(FFI_TYPE_LAST): Bump.
	(ffi_type_complex_float): Add new ffi_type_....
	(ffi_type_complex_double): Ditto.
	(ffi_type_complex_longdouble): Ditto.

2014-07-22  Dominik Vogt  <vogt@linux.vnet.ibm.com>

	* src/s390/ffitarget.h (FFI_TARGET_HAS_COMPLEX_TYPE): Define to provide
	FFI_TYPE_COMPLEX support.
	* src/s390/ffi.c (ffi_check_struct_type): Implement FFI_TYPE_COMPLEX
	(ffi_prep_args): Ditto.
	(ffi_prep_cif_machdep): Ditto.
	(ffi_closure_helper_SYSV): Ditto.
2014-09-20 06:24:41 -04:00
Ehsan Akhgari
fb25cd08ed Add support for building with clang-cl 2014-06-12 20:42:18 -04:00
Ryan Hill
cbc5a3c020 Fix typo 2014-05-31 08:26:34 -04:00
Josh Triplett
35634dbcea Remove autogenerated files from the repository
Add an autogen.sh to regenerate them.
2014-03-16 04:24:12 -07:00
Anthony Green
3dc3f32c35 Undo iOS ARM64 changes. 2013-12-05 16:23:25 -05:00
Zachary Waldowski
cb719a5c1c Darwin/iOS: Fix LLVM 3.3 warning re: memcpy. 2013-11-30 04:09:18 -05:00
Alan Modra
ac75368893 This separates the 32-bit sysv/linux/bsd code from the 64-bit linux
code, and makes it possible to link code compiled with different
options to those used to compile libffi.  For example, a
-mlong-double-128 libffi can be used with -mlong-double-64 code.

Using the return value area as a place to pass parameters wasn't such
a good idea, causing a failure of cls_ulonglong.c.  I didn't see this
when running the mainline gcc libffi testsuite because that version of
the test is inferior to the upstreamm libffi test.

Using NUM_FPR_ARG_REGISTERS rather than NUM_FPR_ARG_REGISTERS64 meant
that a parameter save area could be allocated before it was strictly
necessary.  Wrong but harmless.  Found when splitting apart ffi.c
into 32-bit and 64-bit support.
2013-11-21 06:12:35 -05:00
Anthony Green
8af42f9944 Respect HAVE_ALLOCA_H 2013-11-13 16:40:28 -05:00
Anthony Green
d2fcbcdfbe Add m88k and VAX support. Update some configury bits. 2013-10-08 06:27:46 -04:00
Anthony Green
6a028caec1 Don't use GCCisms to define types when
+       building with the SUNPRO compiler.
2013-01-10 01:19:43 -05:00