FEX/ThunkLibs/libX11/X11Common.h
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

26 lines
509 B
C++

#pragma once
#include <array>
#include <string>
extern "C" {
#include <X11/Xlib.h>
}
namespace X11 {
constexpr static std::array<std::string_view, 13> CallbackKeys = {{
XNGeometryCallback,
XNDestroyCallback,
XNPreeditStartCallback,
XNPreeditDoneCallback,
XNPreeditDrawCallback,
XNPreeditCaretCallback,
XNPreeditStateNotifyCallback,
XNStatusStartCallback,
XNStatusDoneCallback,
XNStatusDrawCallback,
XNR6PreeditCallback,
XNStringConversionCallback,
}};
}