summaryrefslogtreecommitdiff
path: root/src/aarch64
Commit message (Collapse)AuthorAgeFilesLines
* Add MSYS configuration files (#728)Hans2022-09-171-9/+11
| | | | | | | | | | | | | | | | | | | | | | | | | * Add MSYS configuration files MSYS behaves very similiar to Cygwin, e.g. also __CYGWIN__ is defined. Now 'make check' passes on MSYS without extra patches. * Fix warning extra tokens at end of #endif in closures.c Extra tokens converted into a comment. Also nearby indentations corrected. * Fix missing prototype warning mkostemp() on Cygwin Cygwin requires also _GNU_SOURCE to be defined to enable mkostemp() prototype. * Fix warning label ‘out’ defined but not used in ffi functions Define same preprocessor conditions for goto and label visibility. * Fix warning label ‘out’ defined but not used and related indentations. Define same preprocessor conditions for goto and label visibility. Correct also related indentations. Co-authored-by: Hannes Müller <>
* Fix ILP32 for aarch64Anthony Green2022-06-251-0/+9
|
* Fix building on aarch64 after e409225b41b60c490a094bb068e639a2364202fd (#716)Martin Storsjö2022-05-291-1/+1
| | | | The ALIGN_DOWN macro was renamed in 2018 in e6eac7863e2bf1a009ea863041b354bdb4af6b67.
* Pass large structs by value for Linux x86_64 and Aarch64.Anthony Green2022-05-281-8/+31
| | | | Aarch patch by Andreas Schwab. https://github.com/libffi/libffi/commit/482b37f00467325e3389bab322525099860dd9aa
* arm64e: Pull in pointer authentication code from Apple's arm64e libffi port ↵Jeremy Huddleston Sequoia2021-03-243-44/+78
| | | | | | | | (#565) NOTES: This changes the ptrauth support from #548 to match what Apple is shipping in its libffi-27 tag. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
* aarch64: Fix closures for win64 (#606)AndreRH2021-03-231-9/+11
|
* Add some missing #if conditionals from Apple's code drop (#620)Jeremy Huddleston Sequoia2021-03-202-0/+9
| | | | | | | | | * arm/aarch64: Add FFI_CLOSURES conditionals where appropriate Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * aarch64: Don't emit the do_closure label when building without FFI_GO_CLOSURES Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
* Static tramp v5 (#624)Madhavan T. Venkataraman2021-03-053-1/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* aarch64: Allow FFI_WIN64 for winelib (#593)AndreRH2020-11-103-31/+47
|
* aarch64: Fix typoJakub Wilk2020-06-301-1/+1
|
* win64_armasm: Fix the spelling of ALIGN (#553)Martin Storsjö2020-04-251-1/+1
|
* Fix building for aarch64 windows with mingw toolchains (#555)Martin Storsjö2020-04-252-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | * aarch64: Check _WIN32 instead of _M_ARM64 for detecting windows This fixes building for aarch64 with mingw toolchains. _M_ARM64 is predefined by MSVC, while mingw compilers predefine __aarch64__. In aarch64 specific code, change checks for _M_ARM64 into checks for _WIN32. In arch independent code, check for (defined(_M_ARM64) || defined(__aarch64__)) && defined(_WIN32) instead of just _M_ARM64. In src/closures.c, coalesce checks like defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) into plain defined(_WIN32). Technically, this enables code for ARM32 windows where it wasn't, but as far as I can see it, those codepaths should be fine for that architecture variant as well. * aarch64: Only use armasm source when building with MSVC When building for windows/arm64 with clang, the normal gas style .S source works fine. sysv.S and win64_armasm.S seem to be functionally equivalent, with only differences being due to assembler syntax.
* Port to iOS/arm64e (#548)Ole André Vadla Ravnås2020-03-092-2/+19
|
* Clean up line endings (#509)John Ericson2019-10-081-505/+505
| | | | The CLRF visual studio files can be kept that way, but recognized as text. The assembly file can be converted to LF.
* fix mingw build and crashing bugs for Python Windows ARM64 (#496)Paul Monson2019-08-073-11/+23
| | | | | | * fix mingw build and crashing bugs for Python Windows ARM64 * Fix issues found in PR review
* libffi: added ARM64 support for Windows (#486)ossdev072019-06-253-56/+622
| | | | | | | | | | | | | | | | | | * libffi: added ARM64 support for Windows 1. ported sysv.S to win64_armasm.S for armasm64 assembler 2. added msvc_build folder for visual studio solution 3. updated README.md for the same 4. MSVC solution created with the changes, and below test suites are tested with test script written in python. libffi.bhaible libffi.call 5. Basic functionality of above test suites are getting passed Signed-off-by: ossdev07 <ossdev@puresoftware.com> * Update README.md
* fix check for Linux/aarch64Dan Horák2019-03-292-2/+2
| | | | fixes #473
* Cleanup symbol exports on darwin and add architecture preprocessor checks to ↵Jeremy Huddleston Sequoia2019-02-192-10/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* aarch64: Flush code mapping in addition to data mapping (#471)Florian Weimer2019-02-191-0/+4
| | | | | | This needs a new function, ffi_data_to_code_pointer, to translate from data pointers to code pointers. Fixes issue #470.
* Fix Q registers parameter passing on ARM64Martin Bektchiev2018-10-311-2/+2
| | | | The second two quads are located at offset 32 not 16
* Revert "Remove some symbol exports and cleanup newline warnings (#433)"Anthony Green2018-05-051-6/+0
| | | | This reverts commit a5a0f3cf36dfb4d64316414a872288c3170e6c1d.
* Remove some symbol exports and cleanup newline warnings (#433)Jeremy Huddleston Sequoia2018-05-051-0/+6
| | | | | | | | | | * build: Ensure darwin generated sources end with a new line Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org> * build: Use .private_extern where missing to prevent exporting symbols that are not API Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org>
* Revert "Fix passing struct by value on aarch64"Andreas Schwab2018-02-201-31/+8
| | | | | | This reverts commit 482b37f00467325e3389bab322525099860dd9aa. That was actually a bug in python, see <https://bugs.python.org/issue30353>.
* Fix passing struct by value on aarch64Andreas Schwab2018-02-071-8/+31
| | | | This fixes the ctypes test in the python testsuite.
* aarch64: fix index base register for AArch64Saleem Abdulrasool2017-10-261-1/+1
| | | | | The base is passed in `x3`, not in `x2`. This fixes the indexing base so that the right value is used.
* Merge branch 'master' based on ksjogo/libffiJean-Luc Jumpertz2017-10-231-2/+2
|\ | | | | | | | | | | | | | | | | Added a tvOS target in Xcode project. Misc Xcode project cleanup. Fix macOS build target in Xcode project. # Conflicts: # src/aarch64/ffi.c # src/x86/ffi64.c
| * Fix macOS build target in Xcode project.Jean-Luc Jumpertz2017-09-041-2/+2
| | | | | | | | | | | | - Add missing files for desktop platforms in generate-darwin-source-and-headers.py, and in the Xcode project. - Add a static library target for macOS. - Fix "implicit conversion loses integer precision" warnings for iOS mad macOS targets.
* | Merge pull request #263 from ksjogo/masterAnthony Green2017-09-271-1/+1
|\ \ | |/ | | fix ios builds
| * Update XcodeprojJohannes Goslar2017-03-301-1/+1
| | | | | | | | | | | | | | Include all currently relevent files. Call autogen is build script. Fix compiler settings. Fix mach include.
* | Prefix ALIGN macros with FFI_Gregory Pakosz2017-04-271-2/+2
|/
* Merge pull request #269 from frida/fix/aarch64-variadic-closures-on-iosTom Tromey2016-08-101-0/+9
|\ | | | | aarch64: Fix handling of variadic closures on iOS
| * aarch64: Fix handling of variadic closures on iOSOle André Vadla Ravnås2016-08-101-0/+9
| |
* | Merge pull request #268 from frida/fix/aarch64-large-aggregatesTom Tromey2016-08-101-0/+1
|\ \ | | | | | | aarch64: Fix handling of aggregates larger than 16 bytes
| * | aarch64: Fix handling of aggregates larger than 16 bytesOle André Vadla Ravnås2016-08-101-0/+1
| |/ | | | | | | | | Instead of allocating stack space for a pointer we would allocate stack space for the actual aggregate size.
* | aarch64: Fix warning about unused function on iOSOle André Vadla Ravnås2016-08-101-6/+8
| |
* | aarch64: Fix operand size warning reported by ClangOle André Vadla Ravnås2016-08-101-1/+1
|/
* Define FFI_SIZEOF_JAVA_RAW for aarch64 ILP32Andreas Schwab2016-03-161-0/+1
| | | | | Like x32, aarch64 ILP32 needs to define FFI_SIZEOF_JAVA_RAW. This fixes the java interpreter.
* Fixed #181 -- Corrected problems with ARMv7 build under iOS.Russell Keith-Magee2015-12-213-246/+34
| | | | | Based on a patch from @fealebenpae, with input from @SolaWing and @rth7680, and testing from @superdump.
* aarch64: Handle ILP32 ABIAndrew Pinski2015-02-112-3/+21
|
* aarch64: implement the trampoline table workaround for ffi closures on Apple ↵Yavor Georgiev2015-01-163-15/+282
| | | | | | systems This is a direct copy/paste port of the ARM code, with changes because of Aarch64 pc-relative addressing restrictions.
* aarch64: rewrite range syntax into list to appease ClangYavor Georgiev2015-01-161-4/+4
| | | | Clang's assembler in Xcode 6 appears to choke when the operand of st4 is a range, but is happy with a list.
* Fix for https://github.com/atgreen/libffi/issues/141James Greenhalgh2014-12-061-0/+5
|
* aarch64: Add support for Go closuresRichard Henderson2014-11-123-6/+112
|
* aarch64: Move x8 out of call_contextRichard Henderson2014-11-123-5/+4
| | | | | Reduces stack size. It was only used by the closure, and there are available argument registers.
* aarch64: Add support for complex typesRichard Henderson2014-11-122-9/+27
|
* aarch64: Remove aarch64_flagsRichard Henderson2014-11-122-7/+2
| | | | | This field was useless from the start, since the normal flags field is available for backend use.
* aarch64: Unify scalar fp and hfa handlingRichard Henderson2014-11-121-134/+91
| | | | | Since an HFA of a single element is exactly the same as scalar, this tidies things up a bit.
* aarch64: Move return value handling into ffi_closure_SYSVRichard Henderson2014-11-123-271/+176
| | | | | As with the change to ffi_call_SYSV, this avoids copying data into a temporary buffer.
* aarch64: Move return value handling into ffi_call_SYSVRichard Henderson2014-11-123-114/+258
| | | | | This lets us pass return data directly to the caller of ffi_call in most cases, rather than storing it into temporary storage first.
* aarch64: Merge prep_args with ffi_callRichard Henderson2014-11-122-241/+144
| | | | | Use the trick to allocate the stack frame for ffi_call_SYSV within ffi_call itself.