From fb15cf0db4250e11925383cde4d192ed6275da96 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 19 Jan 2024 11:22:37 +0100 Subject: [PATCH] Thunks: Flip order of nullptr check and custom repacking --- ThunkLibs/include/common/Host.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ThunkLibs/include/common/Host.h b/ThunkLibs/include/common/Host.h index 464d72e66..549c20828 100644 --- a/ThunkLibs/include/common/Host.h +++ b/ThunkLibs/include/common/Host.h @@ -275,14 +275,14 @@ struct repack_wrapper { ~repack_wrapper() { // TODO: Properly detect opaque types if constexpr (requires(guest_layout t, decltype(data) h) { t.get_pointer(); (bool)h; *data; }) { - // NOTE: It's assumed that the native host library didn't modify any - // const-pointees, so we skip automatic exit repacking for them. - // However, *custom* repacking must still be applied since it might - // have unrelated side effects (such as deallocation of memory - // reserved on entry) - if (!fex_apply_custom_repacking_exit(*orig_arg.get_pointer(), *data)) { - if constexpr (!std::is_const_v>) { // Skip exit-repacking for const pointees - if (data) { + if (data) { + // NOTE: It's assumed that the native host library didn't modify any + // const-pointees, so we skip automatic exit repacking for them. + // However, *custom* repacking must still be applied since it + // might have unrelated side effects (such as deallocation of + // memory reserved on entry) + if (!fex_apply_custom_repacking_exit(*orig_arg.get_pointer(), *data)) { + if constexpr (!std::is_const_v>) { // Skip exit-repacking for const pointees constexpr bool is_compatible = has_compatible_data_layout && std::is_same_v; if constexpr (!is_compatible && std::is_class_v>) { *orig_arg.get_pointer() = to_guest(*data); // TODO: Only if annotated as out-parameter