Commit Graph

309 Commits

Author SHA1 Message Date
Tony Wasserka
2359a9899c Library Forwarding: Fix accidental data copying when converting from host to guest layout 2024-03-07 10:52:13 +01:00
Tony Wasserka
31e976a5bc Library Forwarding: Update Vulkan definitions to v1.3.278 2024-02-29 19:08:38 +01:00
Tony Wasserka
67530171e6 Library Forwarding/wayland: Clean up wl_interface exchange 2024-02-21 11:44:55 +01:00
Tony Wasserka
6f00611892 Library Forwarding/wayland: Add functions required by zink + Super Meat Boy on 32-bit 2024-02-21 11:44:55 +01:00
Tony Wasserka
67941f04eb Library Forwarding/wayland: Write arguments for callbacks to guest stack 2024-02-21 11:44:55 +01:00
Tony Wasserka
42531108b7 Library Forwarding/wayland: Enable 32-bit build 2024-02-21 11:44:55 +01:00
Tony Wasserka
7edab7ee3b Library Forwarding/wayland: For 32-bit guests, support repacking wl_interface/wl_message/wl_argument 2024-02-21 11:44:55 +01:00
Tony Wasserka
b9f2389d74 Library Forwarding/wayland: Avoid using global state to substitute callback tables
The pointer tracked internally by Wayland can be queried via
wl_proxy_get_listener, so we don't need our own bookkeeping.

This also changes the callback table's element type to a fixed-size uint64_t,
which makes it work for 32-bit guests.
2024-02-21 11:44:55 +01:00
Tony Wasserka
3c0b041c44 Library Forwarding/wayland: Support reading message signatures on 32-bit guests 2024-02-21 11:44:54 +01:00
Tony Wasserka
0908968e87 Library Forwarding/gen: Don't register types used exclusively with ptr_passthrough annotations
This allows forwarding APIs that sparsely use non-repackable types.
2024-02-21 11:44:54 +01:00
Ryan Houdek
9cab746aa7
Merge pull request #3407 from neobrain/feature_libfwd_arguments_on_guest_stack
Library Forwarding: Allocate packed arguments on the guest stack if needed
2024-02-12 16:31:34 -08:00
Tony Wasserka
df3e51fc8c Library Forwarding: Allocate packed arguments on the guest stack if needed
This is required for host-side calls to guest functions on 32-bit guests.
Since the host stack is allocated before FEX blocks memory inaccessible to
the guest, the guest would otherwise fail to read the packed argument data.
2024-02-05 18:10:34 +01:00
Tony Wasserka
06c29eab88 Library Forwarding: Disable struct padding for packed arguments
ARM64, x86 (64-bit), and x86 (32-bit) each have different alignment
requirements, so this change ensures that consistent data layout is
used for packing and unpacking.
2024-02-05 17:39:34 +01:00
Ryan Houdek
9c37c0f1c3
Merge pull request #3392 from neobrain/feature_libfwd_fixed_size_ints
Library Forwarding: Handle cross-architecture differences of integer types
2024-02-02 08:42:41 -08:00
Tony Wasserka
8e1aaa0559 Library Forwarding: Avoid de-sugaring pointee types
Doing so would accidentally resolve typedefs before. This code isn't needed
now that integers are mapped to fixed-size equivalents anyway.
2024-01-31 19:16:19 +01:00
Tony Wasserka
a4c1aaa6bc Library Forwarding: Fix build for clang < 16 2024-01-31 19:14:57 +01:00
Tony Wasserka
3ff3dc8769 Library Forwarding: Add unit test for diverging parameter type sizes 2024-01-30 17:22:23 +01:00
Tony Wasserka
d04c94fe80 Library Forwarding/gen: Map integers to fixed-size equivalents on guest 2024-01-30 17:22:23 +01:00
Tony Wasserka
0ebf260ed0 Library Forwarding: Consider struct metadata equal if it only differs in integer member type names 2024-01-30 17:22:23 +01:00
Tony Wasserka
28ae84cf60 Library Forwarding: Allow implicit conversions between various integer types
Generally, implicit integer conversions are prohibited for data wrapped in
guest_layout/host_layout, but a few types are exceptional:
* char vs signed char vs unsigned char vs other 8-bit ints
* wchar_t vs other 32-bit ints
* size_t vs uint32_t (32-bit only)
* long long vs other 64-bit ints
* long vs long long (64-bit only)

These combinations have the same data size, so conversions between them are
explicitly allowed now.
2024-01-30 17:22:23 +01:00
Tony Wasserka
26007168b0 Library Forwarding: Extend function pointer interface to take separate guest parameter lists
Some types (notably size_t on 32-bit) have different sizes on the guest than on
the host. This template function must be aware of these differences, so a
second parameter list with fixed-size types must be provided to describe the
guest types.

Note that this information can't be queried through type traits: To a C++
compiler, size_t is indistuingishable from uint64_t. For this reason, the
correct guest type must indeed be provided externally.
2024-01-30 17:22:23 +01:00
Tony Wasserka
a48237e218 Library Forwarding: Don't attempt custom repacking for non-struct types 2024-01-30 17:18:54 +01:00
Ryan Houdek
d04f3a288e
Merge pull request #3377 from neobrain/feature_thunk_flip_nullcheck_order
Library Forwarding: Flip order of nullptr check and custom repacking
2024-01-20 06:47:53 -08:00
Tony Wasserka
fb15cf0db4 Thunks: Flip order of nullptr check and custom repacking 2024-01-19 11:25:07 +01:00
Tony Wasserka
b08d372c78 Thunks: Fix definition of GUEST_THUNK_LIBRARY
The -deps target is the wrong target to add this to, since its compile flags
are propagated to both Guest.cpp and Host.cpp. Instead, define the flag only
when processing files within a guest context.
2024-01-19 11:17:44 +01:00
Tony Wasserka
acf48e29b2 FEXLinuxTests/Thunks: Test interaction of struct repacking and assume_compatible_data_layout 2024-01-19 11:17:44 +01:00
Tony Wasserka
190d8020ff FEXLinuxTests/Thunks: Add tests for assisted struct repacking 2024-01-15 20:40:13 +01:00
Tony Wasserka
6eaeb48fac Thunks/gen: Implement assisted struct repacking
This can be used to allow automatically handling structures that require
special behavior for one member but are automatically repackable otherwise.
The feature is enabled using the new custom_repack annotation and requires
additional repacking functions to be defined in the host file for each
customized member.
2024-01-15 20:40:13 +01:00
Tony Wasserka
cd4578de27 FEXLinuxTests/thunks: Add tests for automatic repacking 2024-01-12 14:47:10 +01:00
Tony Wasserka
4cbaad298a Thunks/gen: Repack out-parameters on exit
To avoid performance traps, several conditions must hold for exit repacking
to apply:
* Argument must be a pointer
* The pointee type must have differing data layout between guest and host
* The pointee type must be non-const

Arguments that don't meet the first two conditions are safe *not* to repack
on exit, since they're either passed by copy or have consistent data layout.
The third condition is a heuristic: In principle, an API function could modify
data through nested pointers even if the argument pointer is const. However,
automatic repacking is not supported for such types anyway, so this is a safe
heuristic to use.
2024-01-12 14:47:10 +01:00
Tony Wasserka
dc477c3bd7 Thunks/gen: Implement automatic struct (entry-)repacking 2024-01-12 14:47:10 +01:00
Tony Wasserka
52419d9911 Thunks/gen: Emit metadata to check if a type has consistent data layout 2024-01-12 14:47:10 +01:00
Tony Wasserka
bcd0efa724 Thunks: Build fix for clang versions older than 15
Returning incomplete types from deleted functions is valid C++, but clang
did not support it until version 15:
https://github.com/llvm/llvm-project/issues/52802
2023-12-26 16:02:08 +01:00
Tony Wasserka
48c2e0689a Thunks/gen: Specialize layout wrappers for pointer types
Pointer types inherently cause data layout compatibility issues, so they're
worth special-casing here. The wrappers will type-pun pointers to 32-bit or
64-bit integers (matching the guest architecture) to avoid direct host-side
use of guest pointers without consideration.
2023-12-26 16:02:08 +01:00
Tony Wasserka
4b09a6bee1 Thunks/gen: Implement host_layout->guest_layout conversion
This enables use of guest_layout for return values.
2023-12-26 16:02:08 +01:00
Tony Wasserka
af645cb750 Thunks/gen: Fill guest_layout stub and implement conversion to host_layout
The guest_layout wrapper provides an architecture-agnostic representation of
the guest data layout of each struct used in a thunked library. A constructor
is added to host_layout to allow conversion of the data to the host layout.

For types that are already fully compatible, both layout wrappers are simple
type aliases to minimize overhead.
2023-12-26 16:02:07 +01:00
Tony Wasserka
c6f8901c16 Thunks/gen: For repackable/compatible structs, use a richer host_layout/guest_layout interface 2023-12-22 20:55:15 +01:00
Tony Wasserka
a797699d62 Thunks/gen: Sort types by dependency before emitting data
This allows future changes to emit interdependent helper structures in the
same order.

The sort algorithm was chosen for simplicity rather than performance. It's
fast enough in practice even for APIs as large as Vulkan.
2023-12-22 20:55:15 +01:00
Tony Wasserka
36c524a021 Thunks: Remove callback_guest and fex_guest_function_ptr
These are superseeded by ptr_passthrough and the guest_layout wrapper.
2023-12-22 20:55:15 +01:00
Tony Wasserka
d4e9ed8e61 Thunks/vulkan: Use string_view literals to express string comparisons
This reduces syntax noise as more functions will be added to this list.
2023-12-04 11:09:25 +01:00
Tony Wasserka
c10402f4f9 Thunks/vulkan: Move custom impl matching to common function 2023-12-04 11:09:25 +01:00
Ryan Houdek
0aa41908a2 Thunks/libX11: Change lock functions to nullptr by default
These are setup to be nullptr by default. Instead of providing no-op
lock instructions just have them be nullptr.

It's already part of the API that they need to be nullptr checked before
calling and this matches behaviour of the real libX11 library. Removes
some spam that is unnecessary.
2023-11-12 16:03:43 -08:00
Tony Wasserka
3a240e3b61 Thunks/xcb: Drop unused and incomplete support for asynchronous callbacks 2023-10-29 11:05:24 +01:00
Tony Wasserka
dd9ed89a7a Thunks/X11: Drop unneeded type annotation 2023-10-25 20:38:57 +02:00
Tony Wasserka
a4e1e0a1fb Thunks/gen: Skip data layout analysis for types that are always assumed compatible 2023-10-25 19:35:02 +02:00
Tony Wasserka
5e9f69001d Thunks/gen: Clarify pointer parameter handling
One of the subconditions was always true, so it can safely be removed.
2023-10-25 19:35:02 +02:00
Ryan Houdek
39c5ab1c81
Merge pull request #3225 from neobrain/fix_32bit_funcptrs
Thunks: Fix function pointer support on 32-bit
2023-10-25 07:07:18 -07:00
Tony Wasserka
adcdb32d49 Thunks: Fix function pointer support on 32-bit 2023-10-25 14:37:22 +02:00
Tony Wasserka
f264578f12 Thunks: Unconditionally enable strict processing mode 2023-10-25 12:39:57 +02:00
Tony Wasserka
7149da387a Thunks: Annotate pointer parameters throughout all thunked libraries 2023-10-25 12:39:57 +02:00