abi check fixes and Linux/x32 support
This commit is contained in:
@@ -43,3 +43,5 @@ alpha
|
|||||||
autoconf-archive-update
|
autoconf-archive-update
|
||||||
ffitarget-include-fix
|
ffitarget-include-fix
|
||||||
no-undefined-fix
|
no-undefined-fix
|
||||||
|
x86_abi_check_fix
|
||||||
|
x32-abi
|
||||||
|
|||||||
0
.pc/x32-abi/.timestamp
Normal file
0
.pc/x32-abi/.timestamp
Normal file
4768
.pc/x32-abi/ChangeLog
Normal file
4768
.pc/x32-abi/ChangeLog
Normal file
File diff suppressed because it is too large
Load Diff
349
.pc/x32-abi/README
Normal file
349
.pc/x32-abi/README
Normal file
@@ -0,0 +1,349 @@
|
|||||||
|
Status
|
||||||
|
======
|
||||||
|
|
||||||
|
libffi-3.0.11 was released on *****************. Check the libffi web
|
||||||
|
page for updates: <URL:http://sourceware.org/libffi/>.
|
||||||
|
|
||||||
|
|
||||||
|
What is libffi?
|
||||||
|
===============
|
||||||
|
|
||||||
|
Compilers for high level languages generate code that follow certain
|
||||||
|
conventions. These conventions are necessary, in part, for separate
|
||||||
|
compilation to work. One such convention is the "calling
|
||||||
|
convention". The "calling convention" is essentially a set of
|
||||||
|
assumptions made by the compiler about where function arguments will
|
||||||
|
be found on entry to a function. A "calling convention" also specifies
|
||||||
|
where the return value for a function is found.
|
||||||
|
|
||||||
|
Some programs may not know at the time of compilation what arguments
|
||||||
|
are to be passed to a function. For instance, an interpreter may be
|
||||||
|
told at run-time about the number and types of arguments used to call
|
||||||
|
a given function. Libffi can be used in such programs to provide a
|
||||||
|
bridge from the interpreter program to compiled code.
|
||||||
|
|
||||||
|
The libffi library provides a portable, high level programming
|
||||||
|
interface to various calling conventions. This allows a programmer to
|
||||||
|
call any function specified by a call interface description at run
|
||||||
|
time.
|
||||||
|
|
||||||
|
FFI stands for Foreign Function Interface. A foreign function
|
||||||
|
interface is the popular name for the interface that allows code
|
||||||
|
written in one language to call code written in another language. The
|
||||||
|
libffi library really only provides the lowest, machine dependent
|
||||||
|
layer of a fully featured foreign function interface. A layer must
|
||||||
|
exist above libffi that handles type conversions for values passed
|
||||||
|
between the two languages.
|
||||||
|
|
||||||
|
|
||||||
|
Supported Platforms
|
||||||
|
===================
|
||||||
|
|
||||||
|
Libffi has been ported to many different platforms.
|
||||||
|
For specific configuration details and testing status, please
|
||||||
|
refer to the wiki page here:
|
||||||
|
|
||||||
|
http://www.moxielogic.org/wiki/index.php?title=Libffi_3.0.11
|
||||||
|
|
||||||
|
At the time of release, the following basic configurations have been
|
||||||
|
tested:
|
||||||
|
|
||||||
|
|--------------+------------------|
|
||||||
|
| Architecture | Operating System |
|
||||||
|
|--------------+------------------|
|
||||||
|
| Alpha | Linux |
|
||||||
|
| Alpha | Tru64 |
|
||||||
|
| ARM | Linux |
|
||||||
|
| ARM | iOS |
|
||||||
|
| AVR32 | Linux |
|
||||||
|
| HPPA | HPUX |
|
||||||
|
| IA-64 | Linux |
|
||||||
|
| M68K | RTEMS |
|
||||||
|
| MIPS | IRIX |
|
||||||
|
| MIPS | Linux |
|
||||||
|
| MIPS | RTEMS |
|
||||||
|
| MIPS64 | Linux |
|
||||||
|
| PowerPC | AMIGA |
|
||||||
|
| PowerPC | Linux |
|
||||||
|
| PowerPC | Mac OSX |
|
||||||
|
| PowerPC | FreeBSD |
|
||||||
|
| PowerPC64 | Linux |
|
||||||
|
| S390 | Linux |
|
||||||
|
| S390X | Linux |
|
||||||
|
| SPARC | Linux |
|
||||||
|
| SPARC | Solaris |
|
||||||
|
| SPARC64 | Linux |
|
||||||
|
| SPARC64 | FreeBSD |
|
||||||
|
| X86 | FreeBSD |
|
||||||
|
| X86 | Interix |
|
||||||
|
| X86 | kFreeBSD |
|
||||||
|
| X86 | Linux |
|
||||||
|
| X86 | Mac OSX |
|
||||||
|
| X86 | OpenBSD |
|
||||||
|
| X86 | OS/2 |
|
||||||
|
| X86 | Solaris |
|
||||||
|
| X86 | Windows/Cygwin |
|
||||||
|
| X86 | Windows/MingW |
|
||||||
|
| X86-64 | FreeBSD |
|
||||||
|
| X86-64 | Linux |
|
||||||
|
| X86-64 | OpenBSD |
|
||||||
|
| X86-64 | Windows/MingW |
|
||||||
|
|--------------+------------------|
|
||||||
|
|
||||||
|
Please send additional platform test results to
|
||||||
|
libffi-discuss@sourceware.org and feel free to update the wiki page
|
||||||
|
above.
|
||||||
|
|
||||||
|
Installing libffi
|
||||||
|
=================
|
||||||
|
|
||||||
|
First you must configure the distribution for your particular
|
||||||
|
system. Go to the directory you wish to build libffi in and run the
|
||||||
|
"configure" program found in the root directory of the libffi source
|
||||||
|
distribution.
|
||||||
|
|
||||||
|
You may want to tell configure where to install the libffi library and
|
||||||
|
header files. To do that, use the --prefix configure switch. Libffi
|
||||||
|
will install under /usr/local by default.
|
||||||
|
|
||||||
|
If you want to enable extra run-time debugging checks use the the
|
||||||
|
--enable-debug configure switch. This is useful when your program dies
|
||||||
|
mysteriously while using libffi.
|
||||||
|
|
||||||
|
Another useful configure switch is --enable-purify-safety. Using this
|
||||||
|
will add some extra code which will suppress certain warnings when you
|
||||||
|
are using Purify with libffi. Only use this switch when using
|
||||||
|
Purify, as it will slow down the library.
|
||||||
|
|
||||||
|
It's also possible to build libffi on Windows platforms with
|
||||||
|
Microsoft's Visual C++ compiler. In this case, use the msvcc.sh
|
||||||
|
wrapper script during configuration like so:
|
||||||
|
|
||||||
|
path/to/configure CC=path/to/msvcc.sh LD=link CPP=\"cl -nologo -EP\"
|
||||||
|
|
||||||
|
For 64-bit Windows builds, use CC="path/to/msvcc.sh -m64".
|
||||||
|
You may also need to specify --build appropriately. When building with MSVC
|
||||||
|
under a MingW environment, you may need to remove the line in configure
|
||||||
|
that sets 'fix_srcfile_path' to a 'cygpath' command. ('cygpath' is not
|
||||||
|
present in MingW, and is not required when using MingW-style paths.)
|
||||||
|
|
||||||
|
For iOS builds, refer to the build-ios.sh script for guidance.
|
||||||
|
|
||||||
|
Configure has many other options. Use "configure --help" to see them all.
|
||||||
|
|
||||||
|
Once configure has finished, type "make". Note that you must be using
|
||||||
|
GNU make. You can ftp GNU make from prep.ai.mit.edu:/pub/gnu.
|
||||||
|
|
||||||
|
To ensure that libffi is working as advertised, type "make check".
|
||||||
|
This will require that you have DejaGNU installed.
|
||||||
|
|
||||||
|
To install the library and header files, type "make install".
|
||||||
|
|
||||||
|
|
||||||
|
History
|
||||||
|
=======
|
||||||
|
|
||||||
|
See the ChangeLog files for details.
|
||||||
|
|
||||||
|
3.0.11 MMM-DD-YY
|
||||||
|
Lots of build fixes.
|
||||||
|
Add Amiga newer MacOS support.
|
||||||
|
Fix Octeon and MC68881 support.
|
||||||
|
Fix code pessimizations.
|
||||||
|
|
||||||
|
3.0.10 Aug-23-11
|
||||||
|
Add support for Apple's iOS.
|
||||||
|
Add support for ARM VFP ABI.
|
||||||
|
Add RTEMS support for MIPS and M68K.
|
||||||
|
Fix instruction cache clearing problems on
|
||||||
|
ARM and SPARC.
|
||||||
|
Fix the N64 build on mips-sgi-irix6.5.
|
||||||
|
Enable builds with Microsoft's compiler.
|
||||||
|
Enable x86 builds with Oracle's Solaris compiler.
|
||||||
|
Fix support for calling code compiled with Oracle's Sparc
|
||||||
|
Solaris compiler.
|
||||||
|
Testsuite fixes for Tru64 Unix.
|
||||||
|
Additional platform support.
|
||||||
|
|
||||||
|
3.0.9 Dec-31-09
|
||||||
|
Add AVR32 and win64 ports. Add ARM softfp support.
|
||||||
|
Many fixes for AIX, Solaris, HP-UX, *BSD.
|
||||||
|
Several PowerPC and x86-64 bug fixes.
|
||||||
|
Build DLL for windows.
|
||||||
|
|
||||||
|
3.0.8 Dec-19-08
|
||||||
|
Add *BSD, BeOS, and PA-Linux support.
|
||||||
|
|
||||||
|
3.0.7 Nov-11-08
|
||||||
|
Fix for ppc FreeBSD.
|
||||||
|
(thanks to Andreas Tobler)
|
||||||
|
|
||||||
|
3.0.6 Jul-17-08
|
||||||
|
Fix for closures on sh.
|
||||||
|
Mark the sh/sh64 stack as non-executable.
|
||||||
|
(both thanks to Kaz Kojima)
|
||||||
|
|
||||||
|
3.0.5 Apr-3-08
|
||||||
|
Fix libffi.pc file.
|
||||||
|
Fix #define ARM for IcedTea users.
|
||||||
|
Fix x86 closure bug.
|
||||||
|
|
||||||
|
3.0.4 Feb-24-08
|
||||||
|
Fix x86 OpenBSD configury.
|
||||||
|
|
||||||
|
3.0.3 Feb-22-08
|
||||||
|
Enable x86 OpenBSD thanks to Thomas Heller, and
|
||||||
|
x86-64 FreeBSD thanks to Björn König and Andreas Tobler.
|
||||||
|
Clean up test instruction in README.
|
||||||
|
|
||||||
|
3.0.2 Feb-21-08
|
||||||
|
Improved x86 FreeBSD support.
|
||||||
|
Thanks to Björn König.
|
||||||
|
|
||||||
|
3.0.1 Feb-15-08
|
||||||
|
Fix instruction cache flushing bug on MIPS.
|
||||||
|
Thanks to David Daney.
|
||||||
|
|
||||||
|
3.0.0 Feb-15-08
|
||||||
|
Many changes, mostly thanks to the GCC project.
|
||||||
|
Cygnus Solutions is now Red Hat.
|
||||||
|
|
||||||
|
[10 years go by...]
|
||||||
|
|
||||||
|
1.20 Oct-5-98
|
||||||
|
Raffaele Sena produces ARM port.
|
||||||
|
|
||||||
|
1.19 Oct-5-98
|
||||||
|
Fixed x86 long double and long long return support.
|
||||||
|
m68k bug fixes from Andreas Schwab.
|
||||||
|
Patch for DU assembler compatibility for the Alpha from Richard
|
||||||
|
Henderson.
|
||||||
|
|
||||||
|
1.18 Apr-17-98
|
||||||
|
Bug fixes and MIPS configuration changes.
|
||||||
|
|
||||||
|
1.17 Feb-24-98
|
||||||
|
Bug fixes and m68k port from Andreas Schwab. PowerPC port from
|
||||||
|
Geoffrey Keating. Various bug x86, Sparc and MIPS bug fixes.
|
||||||
|
|
||||||
|
1.16 Feb-11-98
|
||||||
|
Richard Henderson produces Alpha port.
|
||||||
|
|
||||||
|
1.15 Dec-4-97
|
||||||
|
Fixed an n32 ABI bug. New libtool, auto* support.
|
||||||
|
|
||||||
|
1.14 May-13-97
|
||||||
|
libtool is now used to generate shared and static libraries.
|
||||||
|
Fixed a minor portability problem reported by Russ McManus
|
||||||
|
<mcmanr@eq.gs.com>.
|
||||||
|
|
||||||
|
1.13 Dec-2-96
|
||||||
|
Added --enable-purify-safety to keep Purify from complaining
|
||||||
|
about certain low level code.
|
||||||
|
Sparc fix for calling functions with < 6 args.
|
||||||
|
Linux x86 a.out fix.
|
||||||
|
|
||||||
|
1.12 Nov-22-96
|
||||||
|
Added missing ffi_type_void, needed for supporting void return
|
||||||
|
types. Fixed test case for non MIPS machines. Cygnus Support
|
||||||
|
is now Cygnus Solutions.
|
||||||
|
|
||||||
|
1.11 Oct-30-96
|
||||||
|
Added notes about GNU make.
|
||||||
|
|
||||||
|
1.10 Oct-29-96
|
||||||
|
Added configuration fix for non GNU compilers.
|
||||||
|
|
||||||
|
1.09 Oct-29-96
|
||||||
|
Added --enable-debug configure switch. Clean-ups based on LCLint
|
||||||
|
feedback. ffi_mips.h is always installed. Many configuration
|
||||||
|
fixes. Fixed ffitest.c for sparc builds.
|
||||||
|
|
||||||
|
1.08 Oct-15-96
|
||||||
|
Fixed n32 problem. Many clean-ups.
|
||||||
|
|
||||||
|
1.07 Oct-14-96
|
||||||
|
Gordon Irlam rewrites v8.S again. Bug fixes.
|
||||||
|
|
||||||
|
1.06 Oct-14-96
|
||||||
|
Gordon Irlam improved the sparc port.
|
||||||
|
|
||||||
|
1.05 Oct-14-96
|
||||||
|
Interface changes based on feedback.
|
||||||
|
|
||||||
|
1.04 Oct-11-96
|
||||||
|
Sparc port complete (modulo struct passing bug).
|
||||||
|
|
||||||
|
1.03 Oct-10-96
|
||||||
|
Passing struct args, and returning struct values works for
|
||||||
|
all architectures/calling conventions. Expanded tests.
|
||||||
|
|
||||||
|
1.02 Oct-9-96
|
||||||
|
Added SGI n32 support. Fixed bugs in both o32 and Linux support.
|
||||||
|
Added "make test".
|
||||||
|
|
||||||
|
1.01 Oct-8-96
|
||||||
|
Fixed float passing bug in mips version. Restructured some
|
||||||
|
of the code. Builds cleanly with SGI tools.
|
||||||
|
|
||||||
|
1.00 Oct-7-96
|
||||||
|
First release. No public announcement.
|
||||||
|
|
||||||
|
|
||||||
|
Authors & Credits
|
||||||
|
=================
|
||||||
|
|
||||||
|
libffi was originally written by Anthony Green <green@redhat.com>.
|
||||||
|
|
||||||
|
The developers of the GNU Compiler Collection project have made
|
||||||
|
innumerable valuable contributions. See the ChangeLog file for
|
||||||
|
details.
|
||||||
|
|
||||||
|
Some of the ideas behind libffi were inspired by Gianni Mariani's free
|
||||||
|
gencall library for Silicon Graphics machines.
|
||||||
|
|
||||||
|
The closure mechanism was designed and implemented by Kresten Krab
|
||||||
|
Thorup.
|
||||||
|
|
||||||
|
Major processor architecture ports were contributed by the following
|
||||||
|
developers:
|
||||||
|
|
||||||
|
alpha Richard Henderson
|
||||||
|
arm Raffaele Sena
|
||||||
|
cris Simon Posnjak, Hans-Peter Nilsson
|
||||||
|
frv Anthony Green
|
||||||
|
ia64 Hans Boehm
|
||||||
|
m32r Kazuhiro Inaoka
|
||||||
|
m68k Andreas Schwab
|
||||||
|
mips Anthony Green, Casey Marshall
|
||||||
|
mips64 David Daney
|
||||||
|
pa Randolph Chung, Dave Anglin, Andreas Tobler
|
||||||
|
powerpc Geoffrey Keating, Andreas Tobler,
|
||||||
|
David Edelsohn, John Hornkvist
|
||||||
|
powerpc64 Jakub Jelinek
|
||||||
|
s390 Gerhard Tonn, Ulrich Weigand
|
||||||
|
sh Kaz Kojima
|
||||||
|
sh64 Kaz Kojima
|
||||||
|
sparc Anthony Green, Gordon Irlam
|
||||||
|
x86 Anthony Green, Jon Beniston
|
||||||
|
x86-64 Bo Thorsen
|
||||||
|
|
||||||
|
Jesper Skov and Andrew Haley both did more than their fair share of
|
||||||
|
stepping through the code and tracking down bugs.
|
||||||
|
|
||||||
|
Thanks also to Tom Tromey for bug fixes, documentation and
|
||||||
|
configuration help.
|
||||||
|
|
||||||
|
Thanks to Jim Blandy, who provided some useful feedback on the libffi
|
||||||
|
interface.
|
||||||
|
|
||||||
|
Andreas Tobler has done a tremendous amount of work on the testsuite.
|
||||||
|
|
||||||
|
Alex Oliva solved the executable page problem for SElinux.
|
||||||
|
|
||||||
|
The list above is almost certainly incomplete and inaccurate. I'm
|
||||||
|
happy to make corrections or additions upon request.
|
||||||
|
|
||||||
|
If you have a problem, or have found a bug, please send a note to the
|
||||||
|
author at green@moxielogic.com, or the project mailing list at
|
||||||
|
libffi-discuss@sourceware.org.
|
||||||
635
.pc/x32-abi/src/x86/ffi64.c
Normal file
635
.pc/x32-abi/src/x86/ffi64.c
Normal file
@@ -0,0 +1,635 @@
|
|||||||
|
/* -----------------------------------------------------------------------
|
||||||
|
ffi64.c - Copyright (c) 20011 Anthony Green
|
||||||
|
Copyright (c) 2008, 2010 Red Hat, Inc.
|
||||||
|
Copyright (c) 2002, 2007 Bo Thorsen <bo@suse.de>
|
||||||
|
|
||||||
|
x86-64 Foreign Function Interface
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
``Software''), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
----------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include <ffi.h>
|
||||||
|
#include <ffi_common.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
|
#define MAX_GPR_REGS 6
|
||||||
|
#define MAX_SSE_REGS 8
|
||||||
|
|
||||||
|
struct register_args
|
||||||
|
{
|
||||||
|
/* Registers for argument passing. */
|
||||||
|
UINT64 gpr[MAX_GPR_REGS];
|
||||||
|
__int128_t sse[MAX_SSE_REGS];
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
|
||||||
|
void *raddr, void (*fnaddr)(void), unsigned ssecount);
|
||||||
|
|
||||||
|
/* All reference to register classes here is identical to the code in
|
||||||
|
gcc/config/i386/i386.c. Do *not* change one without the other. */
|
||||||
|
|
||||||
|
/* Register class used for passing given 64bit part of the argument.
|
||||||
|
These represent classes as documented by the PS ABI, with the
|
||||||
|
exception of SSESF, SSEDF classes, that are basically SSE class,
|
||||||
|
just gcc will use SF or DFmode move instead of DImode to avoid
|
||||||
|
reformatting penalties.
|
||||||
|
|
||||||
|
Similary we play games with INTEGERSI_CLASS to use cheaper SImode moves
|
||||||
|
whenever possible (upper half does contain padding). */
|
||||||
|
enum x86_64_reg_class
|
||||||
|
{
|
||||||
|
X86_64_NO_CLASS,
|
||||||
|
X86_64_INTEGER_CLASS,
|
||||||
|
X86_64_INTEGERSI_CLASS,
|
||||||
|
X86_64_SSE_CLASS,
|
||||||
|
X86_64_SSESF_CLASS,
|
||||||
|
X86_64_SSEDF_CLASS,
|
||||||
|
X86_64_SSEUP_CLASS,
|
||||||
|
X86_64_X87_CLASS,
|
||||||
|
X86_64_X87UP_CLASS,
|
||||||
|
X86_64_COMPLEX_X87_CLASS,
|
||||||
|
X86_64_MEMORY_CLASS
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_CLASSES 4
|
||||||
|
|
||||||
|
#define SSE_CLASS_P(X) ((X) >= X86_64_SSE_CLASS && X <= X86_64_SSEUP_CLASS)
|
||||||
|
|
||||||
|
/* x86-64 register passing implementation. See x86-64 ABI for details. Goal
|
||||||
|
of this code is to classify each 8bytes of incoming argument by the register
|
||||||
|
class and assign registers accordingly. */
|
||||||
|
|
||||||
|
/* Return the union class of CLASS1 and CLASS2.
|
||||||
|
See the x86-64 PS ABI for details. */
|
||||||
|
|
||||||
|
static enum x86_64_reg_class
|
||||||
|
merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
|
||||||
|
{
|
||||||
|
/* Rule #1: If both classes are equal, this is the resulting class. */
|
||||||
|
if (class1 == class2)
|
||||||
|
return class1;
|
||||||
|
|
||||||
|
/* Rule #2: If one of the classes is NO_CLASS, the resulting class is
|
||||||
|
the other class. */
|
||||||
|
if (class1 == X86_64_NO_CLASS)
|
||||||
|
return class2;
|
||||||
|
if (class2 == X86_64_NO_CLASS)
|
||||||
|
return class1;
|
||||||
|
|
||||||
|
/* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
|
||||||
|
if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
|
||||||
|
return X86_64_MEMORY_CLASS;
|
||||||
|
|
||||||
|
/* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
|
||||||
|
if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
|
||||||
|
|| (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
|
||||||
|
return X86_64_INTEGERSI_CLASS;
|
||||||
|
if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
|
||||||
|
|| class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
|
||||||
|
return X86_64_INTEGER_CLASS;
|
||||||
|
|
||||||
|
/* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
|
||||||
|
MEMORY is used. */
|
||||||
|
if (class1 == X86_64_X87_CLASS
|
||||||
|
|| class1 == X86_64_X87UP_CLASS
|
||||||
|
|| class1 == X86_64_COMPLEX_X87_CLASS
|
||||||
|
|| class2 == X86_64_X87_CLASS
|
||||||
|
|| class2 == X86_64_X87UP_CLASS
|
||||||
|
|| class2 == X86_64_COMPLEX_X87_CLASS)
|
||||||
|
return X86_64_MEMORY_CLASS;
|
||||||
|
|
||||||
|
/* Rule #6: Otherwise class SSE is used. */
|
||||||
|
return X86_64_SSE_CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Classify the argument of type TYPE and mode MODE.
|
||||||
|
CLASSES will be filled by the register class used to pass each word
|
||||||
|
of the operand. The number of words is returned. In case the parameter
|
||||||
|
should be passed in memory, 0 is returned. As a special case for zero
|
||||||
|
sized containers, classes[0] will be NO_CLASS and 1 is returned.
|
||||||
|
|
||||||
|
See the x86-64 PS ABI for details.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
|
||||||
|
size_t byte_offset)
|
||||||
|
{
|
||||||
|
switch (type->type)
|
||||||
|
{
|
||||||
|
case FFI_TYPE_UINT8:
|
||||||
|
case FFI_TYPE_SINT8:
|
||||||
|
case FFI_TYPE_UINT16:
|
||||||
|
case FFI_TYPE_SINT16:
|
||||||
|
case FFI_TYPE_UINT32:
|
||||||
|
case FFI_TYPE_SINT32:
|
||||||
|
case FFI_TYPE_UINT64:
|
||||||
|
case FFI_TYPE_SINT64:
|
||||||
|
case FFI_TYPE_POINTER:
|
||||||
|
{
|
||||||
|
int size = byte_offset + type->size;
|
||||||
|
|
||||||
|
if (size <= 4)
|
||||||
|
{
|
||||||
|
classes[0] = X86_64_INTEGERSI_CLASS;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (size <= 8)
|
||||||
|
{
|
||||||
|
classes[0] = X86_64_INTEGER_CLASS;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (size <= 12)
|
||||||
|
{
|
||||||
|
classes[0] = X86_64_INTEGER_CLASS;
|
||||||
|
classes[1] = X86_64_INTEGERSI_CLASS;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
else if (size <= 16)
|
||||||
|
{
|
||||||
|
classes[0] = classes[1] = X86_64_INTEGERSI_CLASS;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
FFI_ASSERT (0);
|
||||||
|
}
|
||||||
|
case FFI_TYPE_FLOAT:
|
||||||
|
if (!(byte_offset % 8))
|
||||||
|
classes[0] = X86_64_SSESF_CLASS;
|
||||||
|
else
|
||||||
|
classes[0] = X86_64_SSE_CLASS;
|
||||||
|
return 1;
|
||||||
|
case FFI_TYPE_DOUBLE:
|
||||||
|
classes[0] = X86_64_SSEDF_CLASS;
|
||||||
|
return 1;
|
||||||
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
|
classes[0] = X86_64_X87_CLASS;
|
||||||
|
classes[1] = X86_64_X87UP_CLASS;
|
||||||
|
return 2;
|
||||||
|
case FFI_TYPE_STRUCT:
|
||||||
|
{
|
||||||
|
const int UNITS_PER_WORD = 8;
|
||||||
|
int words = (type->size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
|
||||||
|
ffi_type **ptr;
|
||||||
|
int i;
|
||||||
|
enum x86_64_reg_class subclasses[MAX_CLASSES];
|
||||||
|
|
||||||
|
/* If the struct is larger than 32 bytes, pass it on the stack. */
|
||||||
|
if (type->size > 32)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < words; i++)
|
||||||
|
classes[i] = X86_64_NO_CLASS;
|
||||||
|
|
||||||
|
/* Zero sized arrays or structures are NO_CLASS. We return 0 to
|
||||||
|
signalize memory class, so handle it as special case. */
|
||||||
|
if (!words)
|
||||||
|
{
|
||||||
|
classes[0] = X86_64_NO_CLASS;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Merge the fields of structure. */
|
||||||
|
for (ptr = type->elements; *ptr != NULL; ptr++)
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
|
||||||
|
byte_offset = ALIGN (byte_offset, (*ptr)->alignment);
|
||||||
|
|
||||||
|
num = classify_argument (*ptr, subclasses, byte_offset % 8);
|
||||||
|
if (num == 0)
|
||||||
|
return 0;
|
||||||
|
for (i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
int pos = byte_offset / 8;
|
||||||
|
classes[i + pos] =
|
||||||
|
merge_classes (subclasses[i], classes[i + pos]);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte_offset += (*ptr)->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (words > 2)
|
||||||
|
{
|
||||||
|
/* When size > 16 bytes, if the first one isn't
|
||||||
|
X86_64_SSE_CLASS or any other ones aren't
|
||||||
|
X86_64_SSEUP_CLASS, everything should be passed in
|
||||||
|
memory. */
|
||||||
|
if (classes[0] != X86_64_SSE_CLASS)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (i = 1; i < words; i++)
|
||||||
|
if (classes[i] != X86_64_SSEUP_CLASS)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Final merger cleanup. */
|
||||||
|
for (i = 0; i < words; i++)
|
||||||
|
{
|
||||||
|
/* If one class is MEMORY, everything should be passed in
|
||||||
|
memory. */
|
||||||
|
if (classes[i] == X86_64_MEMORY_CLASS)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* The X86_64_SSEUP_CLASS should be always preceded by
|
||||||
|
X86_64_SSE_CLASS or X86_64_SSEUP_CLASS. */
|
||||||
|
if (classes[i] == X86_64_SSEUP_CLASS
|
||||||
|
&& classes[i - 1] != X86_64_SSE_CLASS
|
||||||
|
&& classes[i - 1] != X86_64_SSEUP_CLASS)
|
||||||
|
{
|
||||||
|
/* The first one should never be X86_64_SSEUP_CLASS. */
|
||||||
|
FFI_ASSERT (i != 0);
|
||||||
|
classes[i] = X86_64_SSE_CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
|
||||||
|
everything should be passed in memory. */
|
||||||
|
if (classes[i] == X86_64_X87UP_CLASS
|
||||||
|
&& (classes[i - 1] != X86_64_X87_CLASS))
|
||||||
|
{
|
||||||
|
/* The first one should never be X86_64_X87UP_CLASS. */
|
||||||
|
FFI_ASSERT (i != 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
FFI_ASSERT(0);
|
||||||
|
}
|
||||||
|
return 0; /* Never reached. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Examine the argument and return set number of register required in each
|
||||||
|
class. Return zero iff parameter should be passed in memory, otherwise
|
||||||
|
the number of registers. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
examine_argument (ffi_type *type, enum x86_64_reg_class classes[MAX_CLASSES],
|
||||||
|
_Bool in_return, int *pngpr, int *pnsse)
|
||||||
|
{
|
||||||
|
int i, n, ngpr, nsse;
|
||||||
|
|
||||||
|
n = classify_argument (type, classes, 0);
|
||||||
|
if (n == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ngpr = nsse = 0;
|
||||||
|
for (i = 0; i < n; ++i)
|
||||||
|
switch (classes[i])
|
||||||
|
{
|
||||||
|
case X86_64_INTEGER_CLASS:
|
||||||
|
case X86_64_INTEGERSI_CLASS:
|
||||||
|
ngpr++;
|
||||||
|
break;
|
||||||
|
case X86_64_SSE_CLASS:
|
||||||
|
case X86_64_SSESF_CLASS:
|
||||||
|
case X86_64_SSEDF_CLASS:
|
||||||
|
nsse++;
|
||||||
|
break;
|
||||||
|
case X86_64_NO_CLASS:
|
||||||
|
case X86_64_SSEUP_CLASS:
|
||||||
|
break;
|
||||||
|
case X86_64_X87_CLASS:
|
||||||
|
case X86_64_X87UP_CLASS:
|
||||||
|
case X86_64_COMPLEX_X87_CLASS:
|
||||||
|
return in_return != 0;
|
||||||
|
default:
|
||||||
|
abort ();
|
||||||
|
}
|
||||||
|
|
||||||
|
*pngpr = ngpr;
|
||||||
|
*pnsse = nsse;
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Perform machine dependent cif processing. */
|
||||||
|
|
||||||
|
ffi_status
|
||||||
|
ffi_prep_cif_machdep (ffi_cif *cif)
|
||||||
|
{
|
||||||
|
int gprcount, ssecount, i, avn, n, ngpr, nsse, flags;
|
||||||
|
enum x86_64_reg_class classes[MAX_CLASSES];
|
||||||
|
size_t bytes;
|
||||||
|
|
||||||
|
gprcount = ssecount = 0;
|
||||||
|
|
||||||
|
flags = cif->rtype->type;
|
||||||
|
if (flags != FFI_TYPE_VOID)
|
||||||
|
{
|
||||||
|
n = examine_argument (cif->rtype, classes, 1, &ngpr, &nsse);
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
/* The return value is passed in memory. A pointer to that
|
||||||
|
memory is the first argument. Allocate a register for it. */
|
||||||
|
gprcount++;
|
||||||
|
/* We don't have to do anything in asm for the return. */
|
||||||
|
flags = FFI_TYPE_VOID;
|
||||||
|
}
|
||||||
|
else if (flags == FFI_TYPE_STRUCT)
|
||||||
|
{
|
||||||
|
/* Mark which registers the result appears in. */
|
||||||
|
_Bool sse0 = SSE_CLASS_P (classes[0]);
|
||||||
|
_Bool sse1 = n == 2 && SSE_CLASS_P (classes[1]);
|
||||||
|
if (sse0 && !sse1)
|
||||||
|
flags |= 1 << 8;
|
||||||
|
else if (!sse0 && sse1)
|
||||||
|
flags |= 1 << 9;
|
||||||
|
else if (sse0 && sse1)
|
||||||
|
flags |= 1 << 10;
|
||||||
|
/* Mark the true size of the structure. */
|
||||||
|
flags |= cif->rtype->size << 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Go over all arguments and determine the way they should be passed.
|
||||||
|
If it's in a register and there is space for it, let that be so. If
|
||||||
|
not, add it's size to the stack byte count. */
|
||||||
|
for (bytes = 0, i = 0, avn = cif->nargs; i < avn; i++)
|
||||||
|
{
|
||||||
|
if (examine_argument (cif->arg_types[i], classes, 0, &ngpr, &nsse) == 0
|
||||||
|
|| gprcount + ngpr > MAX_GPR_REGS
|
||||||
|
|| ssecount + nsse > MAX_SSE_REGS)
|
||||||
|
{
|
||||||
|
long align = cif->arg_types[i]->alignment;
|
||||||
|
|
||||||
|
if (align < 8)
|
||||||
|
align = 8;
|
||||||
|
|
||||||
|
bytes = ALIGN (bytes, align);
|
||||||
|
bytes += cif->arg_types[i]->size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gprcount += ngpr;
|
||||||
|
ssecount += nsse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ssecount)
|
||||||
|
flags |= 1 << 11;
|
||||||
|
cif->flags = flags;
|
||||||
|
cif->bytes = ALIGN (bytes, 8);
|
||||||
|
|
||||||
|
return FFI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
||||||
|
{
|
||||||
|
enum x86_64_reg_class classes[MAX_CLASSES];
|
||||||
|
char *stack, *argp;
|
||||||
|
ffi_type **arg_types;
|
||||||
|
int gprcount, ssecount, ngpr, nsse, i, avn;
|
||||||
|
_Bool ret_in_memory;
|
||||||
|
struct register_args *reg_args;
|
||||||
|
|
||||||
|
/* Can't call 32-bit mode from 64-bit mode. */
|
||||||
|
FFI_ASSERT (cif->abi == FFI_UNIX64);
|
||||||
|
|
||||||
|
/* If the return value is a struct and we don't have a return value
|
||||||
|
address then we need to make one. Note the setting of flags to
|
||||||
|
VOID above in ffi_prep_cif_machdep. */
|
||||||
|
ret_in_memory = (cif->rtype->type == FFI_TYPE_STRUCT
|
||||||
|
&& (cif->flags & 0xff) == FFI_TYPE_VOID);
|
||||||
|
if (rvalue == NULL && ret_in_memory)
|
||||||
|
rvalue = alloca (cif->rtype->size);
|
||||||
|
|
||||||
|
/* Allocate the space for the arguments, plus 4 words of temp space. */
|
||||||
|
stack = alloca (sizeof (struct register_args) + cif->bytes + 4*8);
|
||||||
|
reg_args = (struct register_args *) stack;
|
||||||
|
argp = stack + sizeof (struct register_args);
|
||||||
|
|
||||||
|
gprcount = ssecount = 0;
|
||||||
|
|
||||||
|
/* If the return value is passed in memory, add the pointer as the
|
||||||
|
first integer argument. */
|
||||||
|
if (ret_in_memory)
|
||||||
|
reg_args->gpr[gprcount++] = (long) rvalue;
|
||||||
|
|
||||||
|
avn = cif->nargs;
|
||||||
|
arg_types = cif->arg_types;
|
||||||
|
|
||||||
|
for (i = 0; i < avn; ++i)
|
||||||
|
{
|
||||||
|
size_t size = arg_types[i]->size;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = examine_argument (arg_types[i], classes, 0, &ngpr, &nsse);
|
||||||
|
if (n == 0
|
||||||
|
|| gprcount + ngpr > MAX_GPR_REGS
|
||||||
|
|| ssecount + nsse > MAX_SSE_REGS)
|
||||||
|
{
|
||||||
|
long align = arg_types[i]->alignment;
|
||||||
|
|
||||||
|
/* Stack arguments are *always* at least 8 byte aligned. */
|
||||||
|
if (align < 8)
|
||||||
|
align = 8;
|
||||||
|
|
||||||
|
/* Pass this argument in memory. */
|
||||||
|
argp = (void *) ALIGN (argp, align);
|
||||||
|
memcpy (argp, avalue[i], size);
|
||||||
|
argp += size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* The argument is passed entirely in registers. */
|
||||||
|
char *a = (char *) avalue[i];
|
||||||
|
int j;
|
||||||
|
|
||||||
|
for (j = 0; j < n; j++, a += 8, size -= 8)
|
||||||
|
{
|
||||||
|
switch (classes[j])
|
||||||
|
{
|
||||||
|
case X86_64_INTEGER_CLASS:
|
||||||
|
case X86_64_INTEGERSI_CLASS:
|
||||||
|
reg_args->gpr[gprcount] = 0;
|
||||||
|
memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8);
|
||||||
|
gprcount++;
|
||||||
|
break;
|
||||||
|
case X86_64_SSE_CLASS:
|
||||||
|
case X86_64_SSEDF_CLASS:
|
||||||
|
reg_args->sse[ssecount++] = *(UINT64 *) a;
|
||||||
|
break;
|
||||||
|
case X86_64_SSESF_CLASS:
|
||||||
|
reg_args->sse[ssecount++] = *(UINT32 *) a;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ffi_call_unix64 (stack, cif->bytes + sizeof (struct register_args),
|
||||||
|
cif->flags, rvalue, fn, ssecount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern void ffi_closure_unix64(void);
|
||||||
|
|
||||||
|
ffi_status
|
||||||
|
ffi_prep_closure_loc (ffi_closure* closure,
|
||||||
|
ffi_cif* cif,
|
||||||
|
void (*fun)(ffi_cif*, void*, void**, void*),
|
||||||
|
void *user_data,
|
||||||
|
void *codeloc)
|
||||||
|
{
|
||||||
|
volatile unsigned short *tramp;
|
||||||
|
|
||||||
|
/* Sanity check on the cif ABI. */
|
||||||
|
{
|
||||||
|
int abi = cif->abi;
|
||||||
|
if (UNLIKELY (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI)))
|
||||||
|
return FFI_BAD_ABI;
|
||||||
|
}
|
||||||
|
|
||||||
|
tramp = (volatile unsigned short *) &closure->tramp[0];
|
||||||
|
|
||||||
|
tramp[0] = 0xbb49; /* mov <code>, %r11 */
|
||||||
|
*(void * volatile *) &tramp[1] = ffi_closure_unix64;
|
||||||
|
tramp[5] = 0xba49; /* mov <data>, %r10 */
|
||||||
|
*(void * volatile *) &tramp[6] = codeloc;
|
||||||
|
|
||||||
|
/* Set the carry bit iff the function uses any sse registers.
|
||||||
|
This is clc or stc, together with the first byte of the jmp. */
|
||||||
|
tramp[10] = cif->flags & (1 << 11) ? 0x49f9 : 0x49f8;
|
||||||
|
|
||||||
|
tramp[11] = 0xe3ff; /* jmp *%r11 */
|
||||||
|
|
||||||
|
closure->cif = cif;
|
||||||
|
closure->fun = fun;
|
||||||
|
closure->user_data = user_data;
|
||||||
|
|
||||||
|
return FFI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ffi_closure_unix64_inner(ffi_closure *closure, void *rvalue,
|
||||||
|
struct register_args *reg_args, char *argp)
|
||||||
|
{
|
||||||
|
ffi_cif *cif;
|
||||||
|
void **avalue;
|
||||||
|
ffi_type **arg_types;
|
||||||
|
long i, avn;
|
||||||
|
int gprcount, ssecount, ngpr, nsse;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
cif = closure->cif;
|
||||||
|
avalue = alloca(cif->nargs * sizeof(void *));
|
||||||
|
gprcount = ssecount = 0;
|
||||||
|
|
||||||
|
ret = cif->rtype->type;
|
||||||
|
if (ret != FFI_TYPE_VOID)
|
||||||
|
{
|
||||||
|
enum x86_64_reg_class classes[MAX_CLASSES];
|
||||||
|
int n = examine_argument (cif->rtype, classes, 1, &ngpr, &nsse);
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
/* The return value goes in memory. Arrange for the closure
|
||||||
|
return value to go directly back to the original caller. */
|
||||||
|
rvalue = (void *) reg_args->gpr[gprcount++];
|
||||||
|
/* We don't have to do anything in asm for the return. */
|
||||||
|
ret = FFI_TYPE_VOID;
|
||||||
|
}
|
||||||
|
else if (ret == FFI_TYPE_STRUCT && n == 2)
|
||||||
|
{
|
||||||
|
/* Mark which register the second word of the structure goes in. */
|
||||||
|
_Bool sse0 = SSE_CLASS_P (classes[0]);
|
||||||
|
_Bool sse1 = SSE_CLASS_P (classes[1]);
|
||||||
|
if (!sse0 && sse1)
|
||||||
|
ret |= 1 << 8;
|
||||||
|
else if (sse0 && !sse1)
|
||||||
|
ret |= 1 << 9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
avn = cif->nargs;
|
||||||
|
arg_types = cif->arg_types;
|
||||||
|
|
||||||
|
for (i = 0; i < avn; ++i)
|
||||||
|
{
|
||||||
|
enum x86_64_reg_class classes[MAX_CLASSES];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = examine_argument (arg_types[i], classes, 0, &ngpr, &nsse);
|
||||||
|
if (n == 0
|
||||||
|
|| gprcount + ngpr > MAX_GPR_REGS
|
||||||
|
|| ssecount + nsse > MAX_SSE_REGS)
|
||||||
|
{
|
||||||
|
long align = arg_types[i]->alignment;
|
||||||
|
|
||||||
|
/* Stack arguments are *always* at least 8 byte aligned. */
|
||||||
|
if (align < 8)
|
||||||
|
align = 8;
|
||||||
|
|
||||||
|
/* Pass this argument in memory. */
|
||||||
|
argp = (void *) ALIGN (argp, align);
|
||||||
|
avalue[i] = argp;
|
||||||
|
argp += arg_types[i]->size;
|
||||||
|
}
|
||||||
|
/* If the argument is in a single register, or two consecutive
|
||||||
|
integer registers, then we can use that address directly. */
|
||||||
|
else if (n == 1
|
||||||
|
|| (n == 2 && !(SSE_CLASS_P (classes[0])
|
||||||
|
|| SSE_CLASS_P (classes[1]))))
|
||||||
|
{
|
||||||
|
/* The argument is in a single register. */
|
||||||
|
if (SSE_CLASS_P (classes[0]))
|
||||||
|
{
|
||||||
|
avalue[i] = ®_args->sse[ssecount];
|
||||||
|
ssecount += n;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
avalue[i] = ®_args->gpr[gprcount];
|
||||||
|
gprcount += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Otherwise, allocate space to make them consecutive. */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *a = alloca (16);
|
||||||
|
int j;
|
||||||
|
|
||||||
|
avalue[i] = a;
|
||||||
|
for (j = 0; j < n; j++, a += 8)
|
||||||
|
{
|
||||||
|
if (SSE_CLASS_P (classes[j]))
|
||||||
|
memcpy (a, ®_args->sse[ssecount++], 8);
|
||||||
|
else
|
||||||
|
memcpy (a, ®_args->gpr[gprcount++], 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Invoke the closure. */
|
||||||
|
closure->fun (cif, rvalue, avalue, closure->user_data);
|
||||||
|
|
||||||
|
/* Tell assembly how to perform return type promotions. */
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
128
.pc/x32-abi/src/x86/ffitarget.h
Normal file
128
.pc/x32-abi/src/x86/ffitarget.h
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/* -----------------------------------------------------------------*-C-*-
|
||||||
|
ffitarget.h - Copyright (c) 2012 Anthony Green
|
||||||
|
Copyright (c) 1996-2003, 2010 Red Hat, Inc.
|
||||||
|
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Target configuration macros for x86 and x86-64.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
``Software''), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#ifndef LIBFFI_TARGET_H
|
||||||
|
#define LIBFFI_TARGET_H
|
||||||
|
|
||||||
|
#ifndef LIBFFI_H
|
||||||
|
#error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ---- System specific configurations ----------------------------------- */
|
||||||
|
|
||||||
|
/* For code common to all platforms on x86 and x86_64. */
|
||||||
|
#define X86_ANY
|
||||||
|
|
||||||
|
#if defined (X86_64) && defined (__i386__)
|
||||||
|
#undef X86_64
|
||||||
|
#define X86
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef X86_WIN64
|
||||||
|
#define FFI_SIZEOF_ARG 8
|
||||||
|
#define USE_BUILTIN_FFS 0 /* not yet implemented in mingw-64 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ---- Generic type definitions ----------------------------------------- */
|
||||||
|
|
||||||
|
#ifndef LIBFFI_ASM
|
||||||
|
#ifdef X86_WIN64
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
typedef unsigned __int64 ffi_arg;
|
||||||
|
typedef __int64 ffi_sarg;
|
||||||
|
#else
|
||||||
|
typedef unsigned long long ffi_arg;
|
||||||
|
typedef long long ffi_sarg;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
typedef unsigned long ffi_arg;
|
||||||
|
typedef signed long ffi_sarg;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum ffi_abi {
|
||||||
|
FFI_FIRST_ABI = 0,
|
||||||
|
|
||||||
|
/* ---- Intel x86 Win32 ---------- */
|
||||||
|
#ifdef X86_WIN32
|
||||||
|
FFI_SYSV,
|
||||||
|
FFI_STDCALL,
|
||||||
|
FFI_THISCALL,
|
||||||
|
FFI_FASTCALL,
|
||||||
|
FFI_LAST_ABI,
|
||||||
|
/* TODO: Add fastcall support for the sake of completeness */
|
||||||
|
FFI_DEFAULT_ABI = FFI_SYSV
|
||||||
|
|
||||||
|
#elif defined(X86_WIN64)
|
||||||
|
FFI_WIN64,
|
||||||
|
FFI_LAST_ABI,
|
||||||
|
FFI_DEFAULT_ABI = FFI_WIN64
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* ---- Intel x86 and AMD x86-64 - */
|
||||||
|
FFI_SYSV,
|
||||||
|
FFI_UNIX64, /* Unix variants all use the same ABI for x86-64 */
|
||||||
|
FFI_LAST_ABI,
|
||||||
|
#if defined(__i386__) || defined(__i386)
|
||||||
|
FFI_DEFAULT_ABI = FFI_SYSV
|
||||||
|
#else
|
||||||
|
FFI_DEFAULT_ABI = FFI_UNIX64
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
} ffi_abi;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ---- Definitions for closures ----------------------------------------- */
|
||||||
|
|
||||||
|
#define FFI_CLOSURES 1
|
||||||
|
#define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
|
||||||
|
#define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
|
||||||
|
#define FFI_TYPE_SMALL_STRUCT_4B (FFI_TYPE_LAST + 3)
|
||||||
|
|
||||||
|
#if defined (X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
|
||||||
|
#define FFI_TRAMPOLINE_SIZE 24
|
||||||
|
#define FFI_NATIVE_RAW_API 0
|
||||||
|
#else
|
||||||
|
#ifdef X86_WIN32
|
||||||
|
#define FFI_TRAMPOLINE_SIZE 52
|
||||||
|
#else
|
||||||
|
#ifdef X86_WIN64
|
||||||
|
#define FFI_TRAMPOLINE_SIZE 29
|
||||||
|
#define FFI_NATIVE_RAW_API 0
|
||||||
|
#define FFI_NO_RAW_API 1
|
||||||
|
#else
|
||||||
|
#define FFI_TRAMPOLINE_SIZE 10
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifndef X86_WIN64
|
||||||
|
#define FFI_NATIVE_RAW_API 1 /* x86 has native raw api support */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
0
.pc/x86_abi_check_fix/.timestamp
Normal file
0
.pc/x86_abi_check_fix/.timestamp
Normal file
4764
.pc/x86_abi_check_fix/ChangeLog
Normal file
4764
.pc/x86_abi_check_fix/ChangeLog
Normal file
File diff suppressed because it is too large
Load Diff
216
.pc/x86_abi_check_fix/src/prep_cif.c
Normal file
216
.pc/x86_abi_check_fix/src/prep_cif.c
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
/* -----------------------------------------------------------------------
|
||||||
|
prep_cif.c - Copyright (c) 2011, 2012 Anthony Green
|
||||||
|
Copyright (c) 1996, 1998, 2007 Red Hat, Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
``Software''), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
----------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include <ffi.h>
|
||||||
|
#include <ffi_common.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/* Round up to FFI_SIZEOF_ARG. */
|
||||||
|
|
||||||
|
#define STACK_ARG_SIZE(x) ALIGN(x, FFI_SIZEOF_ARG)
|
||||||
|
|
||||||
|
/* Perform machine independent initialization of aggregate type
|
||||||
|
specifications. */
|
||||||
|
|
||||||
|
static ffi_status initialize_aggregate(ffi_type *arg)
|
||||||
|
{
|
||||||
|
ffi_type **ptr;
|
||||||
|
|
||||||
|
if (UNLIKELY(arg == NULL || arg->elements == NULL))
|
||||||
|
return FFI_BAD_TYPEDEF;
|
||||||
|
|
||||||
|
arg->size = 0;
|
||||||
|
arg->alignment = 0;
|
||||||
|
|
||||||
|
ptr = &(arg->elements[0]);
|
||||||
|
|
||||||
|
if (UNLIKELY(ptr == 0))
|
||||||
|
return FFI_BAD_TYPEDEF;
|
||||||
|
|
||||||
|
while ((*ptr) != NULL)
|
||||||
|
{
|
||||||
|
if (UNLIKELY(((*ptr)->size == 0)
|
||||||
|
&& (initialize_aggregate((*ptr)) != FFI_OK)))
|
||||||
|
return FFI_BAD_TYPEDEF;
|
||||||
|
|
||||||
|
/* Perform a sanity check on the argument type */
|
||||||
|
FFI_ASSERT_VALID_TYPE(*ptr);
|
||||||
|
|
||||||
|
arg->size = ALIGN(arg->size, (*ptr)->alignment);
|
||||||
|
arg->size += (*ptr)->size;
|
||||||
|
|
||||||
|
arg->alignment = (arg->alignment > (*ptr)->alignment) ?
|
||||||
|
arg->alignment : (*ptr)->alignment;
|
||||||
|
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Structure size includes tail padding. This is important for
|
||||||
|
structures that fit in one register on ABIs like the PowerPC64
|
||||||
|
Linux ABI that right justify small structs in a register.
|
||||||
|
It's also needed for nested structure layout, for example
|
||||||
|
struct A { long a; char b; }; struct B { struct A x; char y; };
|
||||||
|
should find y at an offset of 2*sizeof(long) and result in a
|
||||||
|
total size of 3*sizeof(long). */
|
||||||
|
arg->size = ALIGN (arg->size, arg->alignment);
|
||||||
|
|
||||||
|
if (arg->size == 0)
|
||||||
|
return FFI_BAD_TYPEDEF;
|
||||||
|
else
|
||||||
|
return FFI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef __CRIS__
|
||||||
|
/* The CRIS ABI specifies structure elements to have byte
|
||||||
|
alignment only, so it completely overrides this functions,
|
||||||
|
which assumes "natural" alignment and padding. */
|
||||||
|
|
||||||
|
/* Perform machine independent ffi_cif preparation, then call
|
||||||
|
machine dependent routine. */
|
||||||
|
|
||||||
|
/* For non variadic functions isvariadic should be 0 and
|
||||||
|
nfixedargs==ntotalargs.
|
||||||
|
|
||||||
|
For variadic calls, isvariadic should be 1 and nfixedargs
|
||||||
|
and ntotalargs set as appropriate. nfixedargs must always be >=1 */
|
||||||
|
|
||||||
|
|
||||||
|
ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
|
||||||
|
unsigned int isvariadic,
|
||||||
|
unsigned int nfixedargs,
|
||||||
|
unsigned int ntotalargs,
|
||||||
|
ffi_type *rtype, ffi_type **atypes)
|
||||||
|
{
|
||||||
|
unsigned bytes = 0;
|
||||||
|
unsigned int i;
|
||||||
|
ffi_type **ptr;
|
||||||
|
|
||||||
|
FFI_ASSERT(cif != NULL);
|
||||||
|
FFI_ASSERT((!isvariadic) || (nfixedargs >= 1));
|
||||||
|
FFI_ASSERT(nfixedargs <= ntotalargs);
|
||||||
|
|
||||||
|
#ifndef X86_WIN32
|
||||||
|
if (! (abi > FFI_FIRST_ABI) && (abi <= FFI_LAST_ABI))
|
||||||
|
return FFI_BAD_ABI;
|
||||||
|
#else
|
||||||
|
if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI || abi == FFI_THISCALL))
|
||||||
|
return FFI_BAD_ABI;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cif->abi = abi;
|
||||||
|
cif->arg_types = atypes;
|
||||||
|
cif->nargs = ntotalargs;
|
||||||
|
cif->rtype = rtype;
|
||||||
|
|
||||||
|
cif->flags = 0;
|
||||||
|
|
||||||
|
/* Initialize the return type if necessary */
|
||||||
|
if ((cif->rtype->size == 0) && (initialize_aggregate(cif->rtype) != FFI_OK))
|
||||||
|
return FFI_BAD_TYPEDEF;
|
||||||
|
|
||||||
|
/* Perform a sanity check on the return type */
|
||||||
|
FFI_ASSERT_VALID_TYPE(cif->rtype);
|
||||||
|
|
||||||
|
/* x86, x86-64 and s390 stack space allocation is handled in prep_machdep. */
|
||||||
|
#if !defined M68K && !defined X86_ANY && !defined S390 && !defined PA
|
||||||
|
/* Make space for the return structure pointer */
|
||||||
|
if (cif->rtype->type == FFI_TYPE_STRUCT
|
||||||
|
#ifdef SPARC
|
||||||
|
&& (cif->abi != FFI_V9 || cif->rtype->size > 32)
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
bytes = STACK_ARG_SIZE(sizeof(void*));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Initialize any uninitialized aggregate type definitions */
|
||||||
|
if (((*ptr)->size == 0) && (initialize_aggregate((*ptr)) != FFI_OK))
|
||||||
|
return FFI_BAD_TYPEDEF;
|
||||||
|
|
||||||
|
/* Perform a sanity check on the argument type, do this
|
||||||
|
check after the initialization. */
|
||||||
|
FFI_ASSERT_VALID_TYPE(*ptr);
|
||||||
|
|
||||||
|
#if !defined X86_ANY && !defined S390 && !defined PA
|
||||||
|
#ifdef SPARC
|
||||||
|
if (((*ptr)->type == FFI_TYPE_STRUCT
|
||||||
|
&& ((*ptr)->size > 16 || cif->abi != FFI_V9))
|
||||||
|
|| ((*ptr)->type == FFI_TYPE_LONGDOUBLE
|
||||||
|
&& cif->abi != FFI_V9))
|
||||||
|
bytes += sizeof(void*);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
/* Add any padding if necessary */
|
||||||
|
if (((*ptr)->alignment - 1) & bytes)
|
||||||
|
bytes = ALIGN(bytes, (*ptr)->alignment);
|
||||||
|
|
||||||
|
bytes += STACK_ARG_SIZE((*ptr)->size);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
cif->bytes = bytes;
|
||||||
|
|
||||||
|
/* Perform machine dependent cif processing */
|
||||||
|
#ifdef FFI_TARGET_SPECIFIC_VARIADIC
|
||||||
|
if (isvariadic)
|
||||||
|
return ffi_prep_cif_machdep_var(cif, nfixedargs, ntotalargs);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ffi_prep_cif_machdep(cif);
|
||||||
|
}
|
||||||
|
#endif /* not __CRIS__ */
|
||||||
|
|
||||||
|
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
|
||||||
|
ffi_type *rtype, ffi_type **atypes)
|
||||||
|
{
|
||||||
|
return ffi_prep_cif_core(cif, abi, 0, nargs, nargs, rtype, atypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
ffi_status ffi_prep_cif_var(ffi_cif *cif,
|
||||||
|
ffi_abi abi,
|
||||||
|
unsigned int nfixedargs,
|
||||||
|
unsigned int ntotalargs,
|
||||||
|
ffi_type *rtype,
|
||||||
|
ffi_type **atypes)
|
||||||
|
{
|
||||||
|
return ffi_prep_cif_core(cif, abi, 1, nfixedargs, ntotalargs, rtype, atypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if FFI_CLOSURES
|
||||||
|
|
||||||
|
ffi_status
|
||||||
|
ffi_prep_closure (ffi_closure* closure,
|
||||||
|
ffi_cif* cif,
|
||||||
|
void (*fun)(ffi_cif*,void*,void**,void*),
|
||||||
|
void *user_data)
|
||||||
|
{
|
||||||
|
return ffi_prep_closure_loc (closure, cif, fun, user_data, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
16
ChangeLog
16
ChangeLog
@@ -1,3 +1,19 @@
|
|||||||
|
2012-03-03 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
* src/x86/ffi64.c (ffi_call): Cast the return value to unsigned
|
||||||
|
long.
|
||||||
|
(ffi_prep_closure_loc): Cast to 64bit address in trampoline.
|
||||||
|
(ffi_closure_unix64_inner): Cast return pointer to unsigned long
|
||||||
|
first.
|
||||||
|
|
||||||
|
* src/x86/ffitarget.h (FFI_SIZEOF_ARG): Defined to 8 for x32.
|
||||||
|
(ffi_arg): Set to unsigned long long for x32.
|
||||||
|
(ffi_sarg): Set to long long for x32.
|
||||||
|
|
||||||
|
2012-03-03 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
* src/prep_cif.c (ffi_prep_cif_core): Properly check bad ABI.
|
||||||
|
|
||||||
2012-03-03 Andoni Morales Alastruey <ylatuya@gmail.com>
|
2012-03-03 Andoni Morales Alastruey <ylatuya@gmail.com>
|
||||||
|
|
||||||
* configure.ac: Add -no-undefined for both 32- and 64-bit x86
|
* configure.ac: Add -no-undefined for both 32- and 64-bit x86
|
||||||
|
|||||||
3
README
3
README
@@ -78,6 +78,7 @@ tested:
|
|||||||
| X86 | Interix |
|
| X86 | Interix |
|
||||||
| X86 | kFreeBSD |
|
| X86 | kFreeBSD |
|
||||||
| X86 | Linux |
|
| X86 | Linux |
|
||||||
|
| X86 | Linux/x32 |
|
||||||
| X86 | Mac OSX |
|
| X86 | Mac OSX |
|
||||||
| X86 | OpenBSD |
|
| X86 | OpenBSD |
|
||||||
| X86 | OS/2 |
|
| X86 | OS/2 |
|
||||||
@@ -148,6 +149,8 @@ See the ChangeLog files for details.
|
|||||||
3.0.11 MMM-DD-YY
|
3.0.11 MMM-DD-YY
|
||||||
Lots of build fixes.
|
Lots of build fixes.
|
||||||
Add Amiga newer MacOS support.
|
Add Amiga newer MacOS support.
|
||||||
|
Add Linux/x32 support.
|
||||||
|
Add thiscall and fastcall support on Windows.
|
||||||
Fix Octeon and MC68881 support.
|
Fix Octeon and MC68881 support.
|
||||||
Fix code pessimizations.
|
Fix code pessimizations.
|
||||||
|
|
||||||
|
|||||||
@@ -44,3 +44,5 @@ alpha
|
|||||||
autoconf-archive-update
|
autoconf-archive-update
|
||||||
ffitarget-include-fix
|
ffitarget-include-fix
|
||||||
no-undefined-fix
|
no-undefined-fix
|
||||||
|
x86_abi_check_fix
|
||||||
|
x32-abi
|
||||||
|
|||||||
99
patches/x32-abi
Normal file
99
patches/x32-abi
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
Index: libffi/ChangeLog
|
||||||
|
===================================================================
|
||||||
|
--- libffi.orig/ChangeLog
|
||||||
|
+++ libffi/ChangeLog
|
||||||
|
@@ -1,5 +1,17 @@
|
||||||
|
2012-03-03 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
+ * src/x86/ffi64.c (ffi_call): Cast the return value to unsigned
|
||||||
|
+ long.
|
||||||
|
+ (ffi_prep_closure_loc): Cast to 64bit address in trampoline.
|
||||||
|
+ (ffi_closure_unix64_inner): Cast return pointer to unsigned long
|
||||||
|
+ first.
|
||||||
|
+
|
||||||
|
+ * src/x86/ffitarget.h (FFI_SIZEOF_ARG): Defined to 8 for x32.
|
||||||
|
+ (ffi_arg): Set to unsigned long long for x32.
|
||||||
|
+ (ffi_sarg): Set to long long for x32.
|
||||||
|
+
|
||||||
|
+2012-03-03 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
+
|
||||||
|
* src/prep_cif.c (ffi_prep_cif_core): Properly check bad ABI.
|
||||||
|
|
||||||
|
2012-03-03 Andoni Morales Alastruey <ylatuya@gmail.com>
|
||||||
|
Index: libffi/src/x86/ffi64.c
|
||||||
|
===================================================================
|
||||||
|
--- libffi.orig/src/x86/ffi64.c
|
||||||
|
+++ libffi/src/x86/ffi64.c
|
||||||
|
@@ -427,7 +427,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void)
|
||||||
|
/* If the return value is passed in memory, add the pointer as the
|
||||||
|
first integer argument. */
|
||||||
|
if (ret_in_memory)
|
||||||
|
- reg_args->gpr[gprcount++] = (long) rvalue;
|
||||||
|
+ reg_args->gpr[gprcount++] = (unsigned long) rvalue;
|
||||||
|
|
||||||
|
avn = cif->nargs;
|
||||||
|
arg_types = cif->arg_types;
|
||||||
|
@@ -509,9 +509,11 @@ ffi_prep_closure_loc (ffi_closure* closu
|
||||||
|
tramp = (volatile unsigned short *) &closure->tramp[0];
|
||||||
|
|
||||||
|
tramp[0] = 0xbb49; /* mov <code>, %r11 */
|
||||||
|
- *(void * volatile *) &tramp[1] = ffi_closure_unix64;
|
||||||
|
+ *((unsigned long long * volatile) &tramp[1])
|
||||||
|
+ = (unsigned long) ffi_closure_unix64;
|
||||||
|
tramp[5] = 0xba49; /* mov <data>, %r10 */
|
||||||
|
- *(void * volatile *) &tramp[6] = codeloc;
|
||||||
|
+ *((unsigned long long * volatile) &tramp[6])
|
||||||
|
+ = (unsigned long) codeloc;
|
||||||
|
|
||||||
|
/* Set the carry bit iff the function uses any sse registers.
|
||||||
|
This is clc or stc, together with the first byte of the jmp. */
|
||||||
|
@@ -550,7 +552,7 @@ ffi_closure_unix64_inner(ffi_closure *cl
|
||||||
|
{
|
||||||
|
/* The return value goes in memory. Arrange for the closure
|
||||||
|
return value to go directly back to the original caller. */
|
||||||
|
- rvalue = (void *) reg_args->gpr[gprcount++];
|
||||||
|
+ rvalue = (void *) (unsigned long) reg_args->gpr[gprcount++];
|
||||||
|
/* We don't have to do anything in asm for the return. */
|
||||||
|
ret = FFI_TYPE_VOID;
|
||||||
|
}
|
||||||
|
Index: libffi/src/x86/ffitarget.h
|
||||||
|
===================================================================
|
||||||
|
--- libffi.orig/src/x86/ffitarget.h
|
||||||
|
+++ libffi/src/x86/ffitarget.h
|
||||||
|
@@ -61,9 +61,15 @@ typedef unsigned long long ffi_arg;
|
||||||
|
typedef long long ffi_sarg;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
+#if defined __x86_64__ && !defined __LP64__
|
||||||
|
+#define FFI_SIZEOF_ARG 8
|
||||||
|
+typedef unsigned long long ffi_arg;
|
||||||
|
+typedef long long ffi_sarg;
|
||||||
|
+#else
|
||||||
|
typedef unsigned long ffi_arg;
|
||||||
|
typedef signed long ffi_sarg;
|
||||||
|
#endif
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
typedef enum ffi_abi {
|
||||||
|
FFI_FIRST_ABI = 0,
|
||||||
|
Index: libffi/README
|
||||||
|
===================================================================
|
||||||
|
--- libffi.orig/README
|
||||||
|
+++ libffi/README
|
||||||
|
@@ -78,6 +78,7 @@ tested:
|
||||||
|
| X86 | Interix |
|
||||||
|
| X86 | kFreeBSD |
|
||||||
|
| X86 | Linux |
|
||||||
|
+| X86 | Linux/x32 |
|
||||||
|
| X86 | Mac OSX |
|
||||||
|
| X86 | OpenBSD |
|
||||||
|
| X86 | OS/2 |
|
||||||
|
@@ -148,6 +149,8 @@ See the ChangeLog files for details.
|
||||||
|
3.0.11 MMM-DD-YY
|
||||||
|
Lots of build fixes.
|
||||||
|
Add Amiga newer MacOS support.
|
||||||
|
+ Add Linux/x32 support.
|
||||||
|
+ Add thiscall and fastcall support on Windows.
|
||||||
|
Fix Octeon and MC68881 support.
|
||||||
|
Fix code pessimizations.
|
||||||
|
|
||||||
25
patches/x86_abi_check_fix
Normal file
25
patches/x86_abi_check_fix
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
Index: libffi/ChangeLog
|
||||||
|
===================================================================
|
||||||
|
--- libffi.orig/ChangeLog
|
||||||
|
+++ libffi/ChangeLog
|
||||||
|
@@ -1,3 +1,7 @@
|
||||||
|
+2012-03-03 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
+
|
||||||
|
+ * src/prep_cif.c (ffi_prep_cif_core): Properly check bad ABI.
|
||||||
|
+
|
||||||
|
2012-03-03 Andoni Morales Alastruey <ylatuya@gmail.com>
|
||||||
|
|
||||||
|
* configure.ac: Add -no-undefined for both 32- and 64-bit x86
|
||||||
|
Index: libffi/src/prep_cif.c
|
||||||
|
===================================================================
|
||||||
|
--- libffi.orig/src/prep_cif.c
|
||||||
|
+++ libffi/src/prep_cif.c
|
||||||
|
@@ -112,7 +112,7 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(
|
||||||
|
FFI_ASSERT(nfixedargs <= ntotalargs);
|
||||||
|
|
||||||
|
#ifndef X86_WIN32
|
||||||
|
- if (! (abi > FFI_FIRST_ABI) && (abi <= FFI_LAST_ABI))
|
||||||
|
+ if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI))
|
||||||
|
return FFI_BAD_ABI;
|
||||||
|
#else
|
||||||
|
if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI || abi == FFI_THISCALL))
|
||||||
@@ -112,7 +112,7 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
|
|||||||
FFI_ASSERT(nfixedargs <= ntotalargs);
|
FFI_ASSERT(nfixedargs <= ntotalargs);
|
||||||
|
|
||||||
#ifndef X86_WIN32
|
#ifndef X86_WIN32
|
||||||
if (! (abi > FFI_FIRST_ABI) && (abi <= FFI_LAST_ABI))
|
if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI))
|
||||||
return FFI_BAD_ABI;
|
return FFI_BAD_ABI;
|
||||||
#else
|
#else
|
||||||
if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI || abi == FFI_THISCALL))
|
if (! (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI || abi == FFI_THISCALL))
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
|||||||
/* If the return value is passed in memory, add the pointer as the
|
/* If the return value is passed in memory, add the pointer as the
|
||||||
first integer argument. */
|
first integer argument. */
|
||||||
if (ret_in_memory)
|
if (ret_in_memory)
|
||||||
reg_args->gpr[gprcount++] = (long) rvalue;
|
reg_args->gpr[gprcount++] = (unsigned long) rvalue;
|
||||||
|
|
||||||
avn = cif->nargs;
|
avn = cif->nargs;
|
||||||
arg_types = cif->arg_types;
|
arg_types = cif->arg_types;
|
||||||
@@ -509,9 +509,11 @@ ffi_prep_closure_loc (ffi_closure* closure,
|
|||||||
tramp = (volatile unsigned short *) &closure->tramp[0];
|
tramp = (volatile unsigned short *) &closure->tramp[0];
|
||||||
|
|
||||||
tramp[0] = 0xbb49; /* mov <code>, %r11 */
|
tramp[0] = 0xbb49; /* mov <code>, %r11 */
|
||||||
*(void * volatile *) &tramp[1] = ffi_closure_unix64;
|
*((unsigned long long * volatile) &tramp[1])
|
||||||
|
= (unsigned long) ffi_closure_unix64;
|
||||||
tramp[5] = 0xba49; /* mov <data>, %r10 */
|
tramp[5] = 0xba49; /* mov <data>, %r10 */
|
||||||
*(void * volatile *) &tramp[6] = codeloc;
|
*((unsigned long long * volatile) &tramp[6])
|
||||||
|
= (unsigned long) codeloc;
|
||||||
|
|
||||||
/* Set the carry bit iff the function uses any sse registers.
|
/* Set the carry bit iff the function uses any sse registers.
|
||||||
This is clc or stc, together with the first byte of the jmp. */
|
This is clc or stc, together with the first byte of the jmp. */
|
||||||
@@ -550,7 +552,7 @@ ffi_closure_unix64_inner(ffi_closure *closure, void *rvalue,
|
|||||||
{
|
{
|
||||||
/* The return value goes in memory. Arrange for the closure
|
/* The return value goes in memory. Arrange for the closure
|
||||||
return value to go directly back to the original caller. */
|
return value to go directly back to the original caller. */
|
||||||
rvalue = (void *) reg_args->gpr[gprcount++];
|
rvalue = (void *) (unsigned long) reg_args->gpr[gprcount++];
|
||||||
/* We don't have to do anything in asm for the return. */
|
/* We don't have to do anything in asm for the return. */
|
||||||
ret = FFI_TYPE_VOID;
|
ret = FFI_TYPE_VOID;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,9 +61,15 @@ typedef unsigned long long ffi_arg;
|
|||||||
typedef long long ffi_sarg;
|
typedef long long ffi_sarg;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#if defined __x86_64__ && !defined __LP64__
|
||||||
|
#define FFI_SIZEOF_ARG 8
|
||||||
|
typedef unsigned long long ffi_arg;
|
||||||
|
typedef long long ffi_sarg;
|
||||||
|
#else
|
||||||
typedef unsigned long ffi_arg;
|
typedef unsigned long ffi_arg;
|
||||||
typedef signed long ffi_sarg;
|
typedef signed long ffi_sarg;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum ffi_abi {
|
typedef enum ffi_abi {
|
||||||
FFI_FIRST_ABI = 0,
|
FFI_FIRST_ABI = 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user