Ioctl32: Removes static fextl::vector in ioctlemulation

Removes a global static initializer for the vector and its atexit
handler.

This handler array can be consteval similar to the x86 tables so it can
be generated entirely at compile time.
This commit is contained in:
Ryan Houdek 2024-07-11 23:50:21 -07:00
parent 870e395ac4
commit 6cdaea680d
No known key found for this signature in database
3 changed files with 14 additions and 48 deletions

View File

@ -20,7 +20,6 @@
#include <FEXCore/fextl/vector.h>
#include <cstdint>
#include <functional>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <unistd.h>
@ -37,7 +36,7 @@ static void UnhandledIoctl(const char* Type, int fd, uint32_t cmd, uint32_t args
}
namespace BasicHandler {
uint64_t BasicHandler(int fd, uint32_t cmd, uint32_t args) {
uint32_t BasicHandler(int fd, uint32_t cmd, uint32_t args) {
uint64_t Result = ::ioctl(fd, cmd, args);
SYSCALL_ERRNO();
}
@ -702,47 +701,22 @@ namespace DRM {
}
} // namespace DRM
struct IoctlHandler {
uint32_t Command;
std::function<uint32_t(int fd, uint32_t cmd, uint32_t args)> Handler;
};
using HandlerType = uint32_t (*)(int fd, uint32_t cmd, uint32_t args);
static fextl::vector<std::function<uint32_t(int fd, uint32_t cmd, uint32_t args)>> Handlers;
void InitializeStaticIoctlHandlers() {
std::array<HandlerType, 1U << _IOC_TYPEBITS> Handlers = []() consteval {
using namespace DRM;
using namespace sockios;
std::array<HandlerType, 1U << _IOC_TYPEBITS> Handlers {};
const fextl::vector<IoctlHandler> LocalHandlers = {{
#define _BASIC_META(x) IoctlHandler {_IOC_TYPE(x), FEX::HLE::x32::BasicHandler::BasicHandler},
#define _BASIC_META_VAR(x, args...) IoctlHandler {_IOC_TYPE(x(args)), FEX::HLE::x32::BasicHandler::BasicHandler},
#define _CUSTOM_META(name, ioctl_num) IoctlHandler {_IOC_TYPE(FEX_##name), FEX::HLE::x32::BasicHandler::BasicHandler},
#define _CUSTOM_META_OFFSET(name, ioctl_num, offset) IoctlHandler {_IOC_TYPE(FEX_##name), FEX::HLE::x32::BasicHandler::BasicHandler},
///< Default fill handlers with BasicHandler.
for (auto& Handler : Handlers) {
Handler = FEX::HLE::x32::BasicHandler::BasicHandler;
}
// Asound
#include "LinuxSyscalls/x32/Ioctl/asound.inl"
// Streams
#include "LinuxSyscalls/x32/Ioctl/streams.inl"
// USB Dev
#include "LinuxSyscalls/x32/Ioctl/usbdev.inl"
// Input
#include "LinuxSyscalls/x32/Ioctl/input.inl"
// SOCKIOS
#include "LinuxSyscalls/x32/Ioctl/sockios.inl"
// Joystick
#include "LinuxSyscalls/x32/Ioctl/joystick.inl"
// Wireless
#include "LinuxSyscalls/x32/Ioctl/wireless.inl"
#undef _BASIC_META
#undef _BASIC_META_VAR
#undef _CUSTOM_META
#undef _CUSTOM_META_OFFSET
#define _BASIC_META(x) IoctlHandler {_IOC_TYPE(x), FEX::HLE::x32::DRM::Handler},
#define _BASIC_META_VAR(x, args...) IoctlHandler {_IOC_TYPE(x(args)), FEX::HLE::x32::DRM::Handler},
#define _CUSTOM_META(name, ioctl_num) IoctlHandler {_IOC_TYPE(FEX_##name), FEX::HLE::x32::DRM::Handler},
#define _CUSTOM_META_OFFSET(name, ioctl_num, offset) IoctlHandler {_IOC_TYPE(FEX_##name), FEX::HLE::x32::DRM::Handler},
#define _BASIC_META(x) Handlers[_IOC_TYPE(x)] = FEX::HLE::x32::DRM::Handler;
#define _BASIC_META_VAR(x, args...) Handlers[_IOC_TYPE(x(args))] = FEX::HLE::x32::DRM::Handler;
#define _CUSTOM_META(name, ioctl_num) Handlers[_IOC_TYPE(FEX_##name)] = FEX::HLE::x32::DRM::Handler;
#define _CUSTOM_META_OFFSET(name, ioctl_num, offset) Handlers[_IOC_TYPE(FEX_##name)] = FEX::HLE::x32::DRM::Handler;
// DRM
#include "LinuxSyscalls/x32/Ioctl/drm.inl"
@ -763,14 +737,9 @@ void InitializeStaticIoctlHandlers() {
#undef _BASIC_META_VAR
#undef _CUSTOM_META
#undef _CUSTOM_META_OFFSET
}};
Handlers.assign(1U << _IOC_TYPEBITS, FEX::HLE::x32::BasicHandler::BasicHandler);
for (auto& Arg : LocalHandlers) {
Handlers[Arg.Command] = Arg.Handler;
}
}
return Handlers;
}();
uint32_t ioctl32(FEXCore::Core::CpuStateFrame* Frame, int fd, uint32_t request, uint32_t args) {
return Handlers[_IOC_TYPE(request)](fd, request, args);

View File

@ -7,7 +7,6 @@ struct CpuStateFrame;
}
namespace FEX::HLE::x32 {
void InitializeStaticIoctlHandlers();
uint32_t ioctl32(FEXCore::Core::CpuStateFrame* Frame, int fd, uint32_t request, uint32_t args);
void CheckAndAddFDDuplication(int fd, int NewFD);
} // namespace FEX::HLE::x32

View File

@ -96,8 +96,6 @@ void x32SyscallHandler::RegisterSyscallHandlers() {
FEX::HLE::x32::RegisterTimer(this);
FEX::HLE::x32::RegisterPassthrough(this);
FEX::HLE::x32::InitializeStaticIoctlHandlers();
#if PRINT_MISSING_SYSCALLS
for (auto& Syscall : SyscallNames) {
if (Definitions[Syscall.first].Ptr == cvt(&UnimplementedSyscall)) {