summaryrefslogtreecommitdiff
path: root/testsuite
Commit message (Collapse)AuthorAgeFilesLines
* Never link pthread for androidAnthony Green2022-09-261-12/+15
|
* Test idea borrowed from cpythonAnthony Green2022-09-241-0/+90
|
* Add test case transcribed from cpythonAnthony Green2022-09-241-0/+63
|
* Add new files for distributionAnthony Green2022-09-191-0/+1
|
* Add test caseAnthony Green2022-09-181-0/+60
|
* Add missing ABI_ATTRAnthony Green2022-09-181-1/+1
|
* Add MSYS configuration files (#728)Hans2022-09-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | * 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 test case for 64-bit mingwAnthony Green2022-09-151-20/+20
|
* Passes on 64bit mingwAnthony Green2022-09-151-2/+2
|
* Fix test headersAnthony Green2022-09-152-164/+2
|
* msvc requires the printf change, not mingwAnthony Green2022-09-151-2/+2
|
* Fix test caseAnthony Green2022-09-141-4/+5
|
* Improve test caseAnthony Green2022-09-141-2/+2
|
* Add test caseAnthony Green2022-09-141-0/+40
|
* Fix unwindtest on macosAnthony Green2022-09-062-2/+6
|
* Prune warnings from sparc64 linux ldAnthony Green2022-09-041-7/+9
|
* Update testsuite MakefileAnthony Green2022-05-291-118/+124
|
* New test casesAnthony Green2022-05-283-0/+195
|
* Fix check for invalid varargs arguments. (#707)Roland Schatz2022-05-231-0/+154
|
* testsuite/libffi.closures: Fix PowerPC 64 (#709)A. Wilcox2022-05-234-4/+4
| | | | | | -mlong-double-128 is only supported on glibc. This test still passes on glibc targets, and now passes on musl targets as well (which uses 64-bit ldbl).
* Clean up typesAnthony Green2022-05-221-9/+8
|
* testsuite/libffi.call: fix mismatching return types (#679)Andreas Schwab2021-12-234-7/+7
| | | Co-authored-by: Andreas Schwab <schwab@suse.de>
* No more xfail for alphaAnthony Green2021-07-291-1/+1
|
* Test passing structs by valueAnthony Green2021-07-292-0/+154
|
* Fix CHECKAnthony Green2021-07-161-1/+1
|
* Don't check the whole buffer, just what we printed.Anthony Green2021-07-161-2/+2
|
* Fix test caseAnthony Green2021-07-161-1/+1
|
* Fix test checkAnthony Green2021-07-161-1/+1
|
* Fix test checkAnthony Green2021-07-161-1/+1
|
* Use CHECK to assert more things in test suite (#654)Hood Chatham2021-07-1696-57/+1202
| | | | | | | * Use CHECK to assert more things in test suite * Use snprintf instead of sprintf * Fix va_struct1 and va_struct3
* Fix warningsAnthony Green2021-06-282-4/+4
|
* Add missing test cases to distributionAnthony Green2021-06-281-2/+7
|
* Add tests for single entry structs (#653)Hood Chatham2021-06-283-0/+289
|
* Fix the assertions in cls-24byte (#652)Hood Chatham2021-06-281-3/+3
| | | | | * Fix the assertions in cls-24byte * Update print statement too
* Print more information when an assertion fails in test suite (#649)Hood Chatham2021-06-272-2/+14
|
* Fix signature of function pointer in cls_dbls_struct (#648)Hood Chatham2021-06-271-1/+1
|
* Remove test caseAnthony Green2021-06-261-1/+0
|
* This test includes a closure and must live in the closures test directory. ↵Matthew Green2021-06-261-0/+0
| | | | | (#645) Co-authored-by: Matthew Green <squidhacks@users.noreply.github.com>
* Make test methods static (#644)Hood Chatham2021-06-2535-35/+35
|
* Avoid undefined behaviourAnthony Green2021-06-221-1/+5
|
* 2021-06-15 Jakub Jelinek <jakub@redhat.com>Jakub Jelinek2021-06-151-0/+107
| | | | | | | | * src/x86/ffi64.c (classify_argument): For FFI_TYPE_STRUCT set words to number of words needed for type->size + byte_offset bytes rather than just type->size bytes. Compute pos before the loop and check total size of the structure. * testsuite/libffi.call/nested_struct12.c: New test.
* Add struct test to verify a nested float struct (#640)Cheng Jin2021-06-091-0/+86
| | | | | | | The test aims to check a nested float struct [float, [float,float]] to see whether it works good with libffi. Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
* Remove reference to old test caseAnthony Green2021-06-091-1/+1
|
* testsuite: fix compiler vendor detection on dash as /bin/sh (#594)Sergei Trofimovich2021-03-241-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | In https://bugs.gentoo.org/753299 Paolo Pedroni reported a single test failure out of all libffi. Here is the minimal reproducer: ``` $ ./autogen $ CONFIG_SHELL=/bin/dash ./configure --host=x86_64-pc-linux-gnu $ make check RUNTESTFLAGS='complex.exp' ... FAIL: libffi.complex/cls_align_complex_float.c (test for excess errors) ``` This happens because under 'dash' shell autoconf generates slightly different style of string quotation in `config.log`: - on bash: `ax_cv_c_compiler_vendor=gnu` - on dash: `ax_cv_c_compiler_vendor='gnu'` To avoid shell quotation parsing the change just embeds `compiler_vendor` into `local.exp` at configure time. Reported-by: Paolo Pedroni Bug: https://bugs.gentoo.org/753299 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
* Bug #680. Don't accept floats or small ints as var args. (#628)Anthony Green2021-03-234-207/+197
| | | | | | | * 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.
* Static tramp v5 (#624)Madhavan T. Venkataraman2021-03-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* testsuite: Add a missing include of <inttypes.h> to fix build failure in ↵Jeremy Huddleston Sequoia2020-10-271-0/+2
| | | | | test suite (#587) Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
* Add gcc bug tests backAnthony Green2020-06-073-8/+28
|
* Move nested_struct3 test to closures directoryv3.3Anthony Green2019-11-232-1/+1
|
* Add missing closing braceAnthony Green2019-11-231-0/+1
|