Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Not for review] Thunks: Implement data layout analysis and struct repacking. Add 32-bit support to Wayland and Vulkan #3135

Closed
wants to merge 48 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
aecea05
TODODROP. DISABLE TESTS
neobrain Aug 22, 2023
34fce64
Thunks/gen: Track data types passed across architecture boundaries
neobrain Aug 24, 2023
89cf474
Thunks/gen: Add data layout analysis
neobrain Aug 24, 2023
c0ba993
Thunks/gen: Add detection logic for data layout differences
neobrain Aug 24, 2023
561fa3f
TODOFINISH. Add new annotations everywhere
neobrain Aug 3, 2023
dc3588d
unittests/ThunkLibs: Add data layout tests
neobrain Aug 10, 2023
fa53e2a
TODO APPLY TO OTHER TESTS TOO. TODOSQUASH: Also check host layout in …
neobrain Aug 22, 2023
1dcdc53
unittests/Thunks: Bump libclang requirement to C++20
neobrain Aug 22, 2023
cd798a5
TODOSPLIT test cases. unittests/ThunkLibs: Add struct repacking tests…
neobrain Sep 6, 2023
307deed
Thunks: Carry annotations in callback wrappers of host functions
neobrain Aug 8, 2023
0c5e4f7
Thunks: Introduce an intermediate guest_layout wrapper to unpack call…
neobrain Aug 8, 2023
1639db5
Thunks: Implement ptr_passthrough annotation
neobrain Sep 19, 2023
5b3c977
unittests/thunks: Add ptr_passthrough tests
neobrain Sep 6, 2023
5d7da30
TODOFINISH. Disable this test for now
neobrain Aug 22, 2023
bee6537
Thunks/gen: Add assume_compatible/is_opaque annotations
neobrain Aug 24, 2023
42cc086
unittests/thunks: Add tests for assume_compatible/is_opaque annotations
neobrain Sep 6, 2023
ba0aec0
TODO FIX BUILD. Thunks/gen: Enforce type compatibility for function p…
neobrain Aug 8, 2023
a80c60c
TODOMOVE. Various 32-bit fixes
neobrain Aug 24, 2023
7425f7e
TODOMOVE. Add support for asynchronous callbacks
neobrain Aug 7, 2023
cd70f04
TODODROP. Partially revert "Add support for asynchronous callbacks"
neobrain Aug 7, 2023
d5f5f43
Thunks/xcb: Drop unused and incomplete support for asynchous callbacks
neobrain Aug 15, 2023
a108aeb
Thunks/gen: Emit layout information for types passed across thunk bou…
neobrain Aug 14, 2023
cf41a02
TODO CONSIDER SQUASHING, or avoid introducing guest_layout placeholde…
neobrain Aug 15, 2023
b3695eb
TODOMOVE. Thunks: Avoid recompiling thunk interfaces on FEXLoader cha…
neobrain Sep 22, 2023
59f0de0
Thunks/gen: Also use guest_layout for return values
neobrain Aug 24, 2023
f204124
Thunks/gen: Implement automatic struct repacking
neobrain Aug 15, 2023
f6796a4
Thunks: Handle type differences for Guest->Host calls through functio…
neobrain Aug 15, 2023
af5d765
Thunks/gen: Implement assisted struct repacking
neobrain Aug 22, 2023
c4900fd
TODOSQUASH. Add unwrap_host helper
neobrain Aug 22, 2023
cea56eb
TODOSQUASH. Fix things that turned up during testing
neobrain Aug 22, 2023
1b3cea4
TODOSQUASH: unittests: Clean up automatic struct repacking tests
neobrain Aug 23, 2023
f8778df
unittests/Thunks: Add tests for assisted struct repacking
neobrain Aug 23, 2023
239c010
Add more assisted repacking tests
neobrain Sep 6, 2023
23cc9bb
unittests/thunks: Add tests for opaque types
neobrain Aug 23, 2023
fe624b8
TODOSQUASH. For struct repacking, const must be stripped off from poi…
neobrain Aug 23, 2023
6db1efd
unittests/Thunks: Add assume_compatible_data_layout test
neobrain Aug 23, 2023
a14b70b
unittests/thunks: Add assume_compatible_data_layout tests
neobrain Aug 23, 2023
657ca8f
unittests/Thunks: Add test for divergent function parameters
neobrain Aug 24, 2023
08c8b38
TODO ENSURE THERE'S A REPLACEMENT. Deprecate callback_guest annotation
neobrain Aug 31, 2023
715bd3a
TODOFINISH. Thunks/gen: Map guest integer types to fixed-size equival…
neobrain Aug 31, 2023
43fe4a1
TODOFINISH. Disable struct padding for packed arguments
neobrain Aug 31, 2023
44df42d
TODOSQUASH. Simplify this code. Not sure if correct
neobrain Aug 31, 2023
68266de
TODOFINISH. Fix 32-bit jemalloc symbols
neobrain Sep 4, 2023
77d84ac
TODO SPLIT host.h changes. Thunks/libwayland: Add 32-bit specific bits
neobrain Sep 4, 2023
dbdb8a6
TODOFINISH. Thunks/vulkan: Add 32-bit support
neobrain Sep 4, 2023
17426aa
Revert "TODOSPLIT test cases. unittests/ThunkLibs: Add struct repacki…
neobrain Sep 6, 2023
02518f2
TODOSQUASH. Thunks: Add more tests
neobrain Sep 6, 2023
ca023e7
TODOFINISH. Thunks/gen: Avoid generating layout conversion code for n…
neobrain Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TODOSQUASH: unittests: Clean up automatic struct repacking tests
  • Loading branch information
neobrain committed Sep 22, 2023
commit 1b3cea416b587d14b024a6064fd3b5476a6688fc
21 changes: 21 additions & 0 deletions ThunkLibs/libfex_thunk_test/api.h
Original file line number Diff line number Diff line change
@@ -10,4 +10,25 @@ extern "C" {

uint32_t GetDoubledValue(uint32_t);


/// Interfaces used to test automatic struct repacking

// A simple struct with data layout that differs between guest and host.
// The thunk generator should emit code that swaps the member data into
// correct position.
struct ReorderingType {
#if defined(__aarch64__) || defined(_M_ARM64) // TODO: Use proper host check
uint32_t a;
uint32_t b;
#else
uint32_t b;
uint32_t a;
#endif
};

ReorderingType MakeReorderingType(uint32_t a, uint32_t b);
uint32_t GetReorderingTypeMember(ReorderingType*, int index);
void ModifyReorderingTypeMembers(ReorderingType* data);
uint32_t QueryOffsetOf(ReorderingType*, int index);

}
17 changes: 17 additions & 0 deletions ThunkLibs/libfex_thunk_test/lib.cpp
Original file line number Diff line number Diff line change
@@ -6,4 +6,21 @@ uint32_t GetDoubledValue(uint32_t input) {
return 2 * input;
}

ReorderingType MakeReorderingType(uint32_t a, uint32_t b) {
return ReorderingType { .a = a, .b = b };
}

uint32_t GetReorderingTypeMember(ReorderingType* data, int index) {
if (index == 0) {
return data->a;
} else {
return data->b;
}
}

void ModifyReorderingTypeMembers(ReorderingType* data) {
data->a += 1;
data->b += 2;
}

} // extern "C"
7 changes: 7 additions & 0 deletions ThunkLibs/libfex_thunk_test/libfex_thunk_test_interface.cpp
Original file line number Diff line number Diff line change
@@ -12,3 +12,10 @@ template<auto, int, typename>
struct fex_gen_param {};

template<> struct fex_gen_config<GetDoubledValue> {};

template<> struct fex_gen_config<MakeReorderingType> {};
template<> struct fex_gen_config<GetReorderingTypeMember> {};
template<> struct fex_gen_config<ModifyReorderingTypeMembers> {};

template<> struct fex_gen_config<QueryOffsetOf> : fexgen::custom_host_impl {};
template<> struct fex_gen_param<QueryOffsetOf, 0, ReorderingType*> : fexgen::ptr_passthrough {};
26 changes: 26 additions & 0 deletions unittests/FEXLinuxTests/tests/thunks/thunk_testlib.cpp
Original file line number Diff line number Diff line change
@@ -17,8 +17,34 @@ struct Fixture {

#define GET_SYMBOL(name) decltype(&::name) name = (decltype(name))dlsym(lib, #name)
GET_SYMBOL(GetDoubledValue);
GET_SYMBOL(MakeReorderingType);
GET_SYMBOL(GetReorderingTypeMember);
GET_SYMBOL(ModifyReorderingTypeMembers);
GET_SYMBOL(QueryOffsetOf);
};

TEST_CASE_METHOD(Fixture, "Trivial") {
CHECK(GetDoubledValue(10) == 20);
}

TEST_CASE_METHOD(Fixture, "Automatic struct repacking") {
{
// Test repacking of return values
ReorderingType test_struct = MakeReorderingType(0x1234, 0x5678);
REQUIRE(test_struct.a == 0x1234);
REQUIRE(test_struct.b == 0x5678);

// Test offsets of the host-side guest_layout wrapper match the guest-side ones
CHECK(QueryOffsetOf(&test_struct, 0) == offsetof(ReorderingType, a));
CHECK(QueryOffsetOf(&test_struct, 1) == offsetof(ReorderingType, b));

// Test repacking of input pointers
CHECK(GetReorderingTypeMember(&test_struct, 0) == 0x1234);
CHECK(GetReorderingTypeMember(&test_struct, 1) == 0x5678);

// Test repacking of output pointers
ModifyReorderingTypeMembers(&test_struct);
CHECK(GetReorderingTypeMember(&test_struct, 0) == 0x1235);
CHECK(GetReorderingTypeMember(&test_struct, 1) == 0x567a);
};
}