260 Commits

Author SHA1 Message Date
Tony Wasserka
7149da387a Thunks: Annotate pointer parameters throughout all thunked libraries 2023-10-25 12:39:57 +02:00
Tony Wasserka
cb215b5f21 FEXLinuxTests/thunks: Add assume_compatible_data_layout tests 2023-10-19 12:49:00 +02:00
Tony Wasserka
0cf2695772 FEXLinuxTests/thunks: Add tests for opaque types 2023-10-19 12:49:00 +02:00
Tony Wasserka
6a6886305e Thunks/gen: Add assume_compatible/is_opaque annotations
These annotations allow for a given type or parameter to be treated as
"compatible" even if data layout analysis can't infer this automatically.

assume_compatible_data_layout is more powerful than is_opaque, since it
allows for structs containing members of a certain type to be automatically
inferred as "compatible".

Conversely however, is_opaque enforces that the underlying data is never
accessed directly, since non-pointer uses of the type would still be
detected as "incompatible".
2023-10-19 12:49:00 +02:00
Tony Wasserka
167fe85cc3 Thunks: Implement ptr_passthrough annotation
This annotation can be used for data types that can't be repacked
automatically even with custom repack annotations. With ptr_passthrough,
the types are wrapped in guest_layout and passed to the host like that.
2023-10-19 12:49:00 +02:00
Tony Wasserka
cf65747667 Thunks: Introduce an intermediate guest_layout wrapper to unpack callback arguments
This will be used later to aid automatic struct repacking.
2023-10-19 12:48:59 +02:00
Tony Wasserka
27bb28b47f Thunks: Carry annotations in callback wrappers of host functions
Previously, two functions with the same signature would always be wrapped
in the same logic. This change allows customizing one function with
annotations while leaving the other one unchanged.
2023-10-19 12:48:59 +02:00
Tony Wasserka
a00da800e7 Thunks: Rename funcptr_types to thunked_funcptrs
This reflects its purpose slightly better, particularly since future patches
will add more information to this object.
2023-10-19 12:48:59 +02:00
Tony Wasserka
bf835e80ac Thunks: Bump compiler requirements to C++20 2023-10-19 12:48:59 +02:00
Tony Wasserka
5bcfaf4b9f Thunks/vulkan: Revert reordering changes from 180d16af7a99fb8e6b7105f06a2c11d9fdb9b4e3
These interfere heavily with ongoing work. Let's reapply the reordering
once the dust has settled instead.
2023-10-19 12:31:33 +02:00
Ryan Houdek
a2b53c8eb0 Thunks: Oops deleted an entry point
Moving some entries around I managed to delete one.
Fixes Vulkan thunks.
2023-10-18 12:21:28 +02:00
Ryan Houdek
180d16af7a Thunks: Fixes missing vulkan definitions
A couple of games were hitting these. Not sure how they were missed in
PR #3159 but adds the missing one.

Small rearrangement to make this easier as well. Hopefully thunk stuff
lands sooner rather than later to automate this for Vulkan.

Maybe `-isystem` instead of `-I` needs to be used unlike what #2076,
might depend on what is installed on the host system.
2023-10-11 01:49:42 -07:00
Ryan Houdek
507cf82dad
Merge pull request #3176 from neobrain/fix_thunks_unused_artifacts
Thunks: Only build guest target for libfex_thunk_test if FEXLinuxTests are enabled
2023-10-04 07:07:18 -07:00
Tony Wasserka
0a09e04e33 Thunks: Only build guest target for libfex_thunk_test if FEXLinuxTests are enabled 2023-10-03 11:43:27 +02:00
Tony Wasserka
fe681ab335 unittests/ThunkLibs: Specify clang resource directory when compiling test code 2023-10-02 22:18:23 +02:00
Tony Wasserka
2b472cb962 Thunks/gen: Enforce type compatibility for function parameters 2023-10-02 22:18:22 +02:00
Tony Wasserka
7f931b5623 Thunks/gen: Add detection logic for data layout differences
This runs the data layout analysis pass added in the previous change twice:
Once for the host architecture and once for the guest architecture. This
allows the new DataLayoutCompareAction to query architecture differences for
each type, which can then be used to instruct code generation accordingly.

Currently, type compatibility is classified into 3 categories:
* Fully compatible (same size/alignment for the type itself and any members)
* Repackable (incompatibility can be resolved with emission of automatable
  repacking code, e.g. when struct members are located at differing offsets
  due to padding bytes)
* Incompatible
2023-10-02 22:18:22 +02:00
Tony Wasserka
070fa9f924 Thunks/gen: Add data layout analysis
This adds a ComputeDataLayout function that maps a set of clang::Types
to an internal representation of their data layout (size, member list, ...).
2023-10-02 22:18:22 +02:00
Tony Wasserka
371bf50c76 Thunks/gen: Track data types passed across architecture boundaries
The set of these types is tracked in AnalysisAction, to which extensive
verification logic is added to detect potential incompatibilities and to
enforce use of annotatations where needed.
2023-10-02 22:18:22 +02:00
Tony Wasserka
d65d29903b Thunks/gen: Rename EmitOutput to OnAnalysisComplete 2023-10-02 22:03:10 +02:00
Tony Wasserka
7791e0090d Thunks: Disable 32-bit host thunks
These are not supported yet.
2023-10-02 22:03:10 +02:00
Tony Wasserka
5a7e3192da Thunks: Fix AddressSanitizer build 2023-09-28 15:13:03 +02:00
Tony Wasserka
04592af609 Thunks: Update Vulkan thunk to v1.3.261.1 2023-09-26 12:14:58 +02:00
Tony Wasserka
adead832a5 Thunks: Avoid recompiling thunk interfaces on FEXLoader changes
The interface files themselves don't use FEXLoader. Only the final library
does.
2023-09-25 23:04:09 +02:00
Tony Wasserka
b00d413961 Thunks/wayland: Add more message signatures required by Super Meat Boy with zink 2023-09-19 17:33:24 +02:00
Tony Wasserka
6b54540756 Thunks/wayland: Add support for message signatures with nullable arguments 2023-09-19 17:33:24 +02:00
Tony Wasserka
356a42d330 Thunks/wayland: Reorder listener signatures alphabetically 2023-09-19 17:33:24 +02:00
Tony Wasserka
8fcf419183 Thunks/wayland: Add more functions required by Super Meat Boy via libdecor and SDL 2023-09-19 17:33:23 +02:00
Ryan Houdek
000fb2efae
Merge pull request #3068 from neobrain/feature_thunk_testlib
unittests: Add test thunk library
2023-09-18 10:31:42 -07:00
Tony Wasserka
bef64c53f8 unittests: Add test thunk library 2023-09-18 16:53:35 +02:00
Tony Wasserka
677b77f1bb Thunks: Simplify PackedArguments invocation code 2023-09-07 13:56:53 +02:00
Tony Wasserka
ab8bc052a0 Thunks/gen: Split interface parsing and code emission into separate files 2023-09-07 13:56:53 +02:00
Tony Wasserka
971821460c Thunks/gen: Move diagnostic marshaling helper to a dedicated header 2023-09-07 13:56:53 +02:00
Ryan Houdek
48121cd585 Thunks: Set bitness flags for 64-bit guests
This will help non-multiarch aware distros
2023-07-31 12:22:33 -07:00
Ryan Houdek
eca80b6046 Remove inline assembly
64 should be enough for anybody.
2023-07-20 16:05:25 -07:00
Ryan Houdek
02fc02964b Thunks/LibX11: Removes variadic multiple argument copying
Just copy one at a time.
2023-07-20 13:52:30 -07:00
Ryan Houdek
e8fcb070b3 Thunks/X11: Fixes variadic packing and callbacks.
Two bugs here that caused thunking X11 thunking in Wine/Proton to not
work.

The easier of the two. The various variadic functions that we thunk
actually take key:value pairs where the first is a string pointer, and
the value can be various things.

We need to handle these as true key:value pairs rather than finding the
first nullptr and dropping the remainder.

Additionally, there are 12 keys that specify a callback that FEX needs
to catch and convert to host callable. Wine is the first application
that I have seen that actually uses this. If these callbacks aren't
wired up then it it can miss events.

The harder of the two problems is the `libX11_Variadic_u64` function was
subtly incorrect. Nothing had previously truly exercised this and my
test program didn't notice anything wrong while writing it.

The first incorrect thing was that it was subtracting the nullptr ender
variable before the stack size calculation, causing the value to
overwrite the stack if the number of remaining elements was event.

Secondly the assembly that was storing two elements per step was
decrementing the counter by 8 instead of two. Didn't pick this up before
since I believe the code was only hitting the non-pair path before.

This gets Proton thunking working under FEX now.
2023-07-20 13:52:30 -07:00
Ryan Houdek
fb34b507a1 Thunks: Remove weak symbol definitions
Fixes #2754

These panicking fallbacks are at times not ending up in as plt calls
for some reason that I haven't been able to reproduce locally.

So far the only way I can reproduce is building with Canonical's PPA
build system, since rebuilding locally didn't resolve the issue.

This will change the failure mode from these panicking asserts happening
at call time, to dlopen failing during relocation when loading the
thunk. Which LD_DEBUG=all can be used for debugging relocation failure
in that case.
2023-07-18 22:33:58 -07:00
Ryan Houdek
f73176d5dc Thunks/xcb: Fixes typo in version check.
Somehow this 14 turned in to a 4.
2023-07-18 04:16:11 -07:00
Ryan Houdek
da0a1710c0 CMake: Fix pkg version extraction
Our regex would only ever capture a single digit, so versions that had
more than one digit per section would lose additional digits.

Fixes and moves the helper to a cmake file to be shared between
GuestLibs and HostLibs.

Uses the fix in xcb because Fedora ships an older version that doesn't
have some of FEX's newer symbols.
2023-07-13 16:01:14 -07:00
Ryan Houdek
f06972c9e2 Thunks: Fixes xcb helper thread creation
Forgot to initialize CBDone to false before the helper thread is
started.
This fixes an issue where an XCB context is created, then stopped, then
another is created but immediately exits because CBDone was still true
from the previous run.

Also adds the handler for `xcb_connect_to_fd` so we don't miss that
usage.
2023-05-05 00:39:07 -07:00
Ryan Houdek
c03ed529e6
Merge pull request #2582 from Sonicadvance1/ccache_thunks
Thunks: Enable ccache if available
2023-04-10 15:57:23 -07:00
Ryan Houdek
f87b00a7e4 Thunks: Make xcb's callback more robust.
Fixes a crash in xcb thunks since more stuff on FEX side has moved over
to jemalloc.

Destructors don't actually get called when a shared library is removed.
It's some weirdo quirk that we can't work around. Instead refcount
Display connections being created and disconnected. Creating the thread
on the first display creation, and tearing down on final display
teardown.

Must be merged before #2564 otherwise that PR will break thunks.
2023-04-03 13:16:50 -07:00
Ryan Houdek
a9f0cb15bf Thunks: Enable ccache if available
More vrooms.
2023-04-03 09:39:42 -07:00
Tony Wasserka
42e2a5421a Thunks: Add wayland-client 2023-04-01 16:58:30 +02:00
Tony Wasserka
557df4f0a7 Thunks/gen: Add support for thunking APIs with pointer-to-function-pointer arguments 2023-04-01 16:52:49 +02:00
Tony Wasserka
fa21944428 Thunks/gen: Print stacktrace on crash
This is useful information e.g. when map lookup from clang::Type pointers
fails during code generation.
2023-03-29 18:39:50 +02:00
Ryan Houdek
abb8de0966 VDSO: Add sigreturn functions to VDSO
These need to be bit-exact following exactly what is shown in the
assembly.

libunwind parses where EIP is to see if it is in a stack frame.
Also needsto live in VDSO otherwise backtrace doesn't work.
2023-02-04 10:35:06 -08:00
Ryan Houdek
cb5573995d Thunks: Fixes host symbol overrides
1) The host library needs to be loaded in the global namespace.

2) We need to use `RTLD_DEFAULT` instead of querying the object
   directly.

We need to load the host library in the global namespace so the symbols
end up in the global symbol table. This follows how all these symbols
/usually/ get loaded. Either by linking directly to the library or how
loaders will end up loading these.

We need to use RTLD_DEFAULT to follow symbol overriding rules that tend
to occur. For example, MangoHUD will LD_PRELOAD a library that provides
GLX and EGL symbols. Which FEX's thunk libraries need to pick up this
override.
If we are querying the host library directly then we fail to pickup
these overrides, thus breaking MangoHUD and other overlays.
2023-02-01 06:47:41 -08:00
Tony Wasserka
0dfe141d70 Thunks: Fix IDE integration 2022-12-28 17:45:05 +01:00