mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-14 01:00:43 +02:00
FEXCore: adds support for compat input prctl
The size of the input_event struct differs between 32 bits applications and 64 bits applications. To deal with this, the kernel implements a compat variant for the input syscalls, but it's only enabled for 32 bit processes. In libkrunfw we're introducing a prctl that enables a 64 bit process to request the kernel to enable the compat variant for the input syscalls. This commit makes use of that interface for enabling/disabling the compat input variant as required. The visible effect is that input devices such as gamepads work properly on emulated 32 bit applications. Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
1 parent
cac3767c20
commit
5c51c54ccc
1 file changed
+40
@@ -287,6 +287,36 @@ void SetupTSOEmulation(FEXCore::Context::Context* CTX) {
|
||||
}
|
||||
} // namespace FEX::TSO
|
||||
|
||||
namespace FEX::CompatInput {
|
||||
void SetupCompatInput(bool enable) {
|
||||
// We need to check if these are defined or not. This is a very fresh feature.
|
||||
#ifndef PR_GET_COMPAT_INPUT
|
||||
#define PR_GET_COMPAT_INPUT 0x63494e50
|
||||
#endif
|
||||
#ifndef PR_SET_COMPAT_INPUT
|
||||
#define PR_SET_COMPAT_INPUT 0x43494e50
|
||||
#endif
|
||||
#ifndef PR_SET_COMPAT_INPUT_DISABLE
|
||||
#define PR_SET_COMPAT_INPUT_DISABLE 0
|
||||
#endif
|
||||
#ifndef PR_SET_COMPAT_INPUT_ENABLE
|
||||
#define PR_SET_COMPAT_INPUT_ENABLE 1
|
||||
#endif
|
||||
// Check to see if this is supported.
|
||||
auto Result = prctl(PR_GET_COMPAT_INPUT, 0, 0, 0, 0);
|
||||
if (Result == -1) {
|
||||
// Unsupported, early exit.
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
prctl(PR_SET_COMPAT_INPUT, PR_SET_COMPAT_INPUT_ENABLE, 0, 0, 0);
|
||||
} else {
|
||||
prctl(PR_SET_COMPAT_INPUT, PR_SET_COMPAT_INPUT_DISABLE, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
} // namespace FEX::CompatInput
|
||||
|
||||
/**
|
||||
* @brief Get an FD from an environment variable and then unset the environment variable.
|
||||
*
|
||||
@@ -510,6 +540,16 @@ int main(int argc, char** argv, char** const envp) {
|
||||
// Setup TSO hardware emulation immediately after initializing the context.
|
||||
FEX::TSO::SetupTSOEmulation(CTX.get());
|
||||
|
||||
if (!Loader.Is64BitMode()) {
|
||||
// Tell the kernel we want to use the compat input syscalls even though we're
|
||||
// a 64 bit process.
|
||||
FEX::CompatInput::SetupCompatInput(true);
|
||||
} else {
|
||||
// Our parent could be an instance running a 32 bit application, so we need
|
||||
// to disable compat input if we're running a 64 bit one ourselves.
|
||||
FEX::CompatInput::SetupCompatInput(false);
|
||||
}
|
||||
|
||||
auto SignalDelegation = FEX::HLE::CreateSignalDelegator(CTX.get(), Program.ProgramName, SupportsAVX);
|
||||
auto ThunkHandler = FEX::HLE::CreateThunkHandler();
|
||||
|
||||
|
||||
Reference in new issue
Block a user