[hle] constexpr handler dispatch maps, introduce version gating (#4480)

This PR primarily focuses on upbringing constexpr maps for handlers.

Each time an HLE object of a service is construed, it registers it's own handlers, over and over.
Regardless of whetever it needs them at the moment or not.
Additionally we don't require to keep track of different function pointers amongst each object.
This can be done by overriding the given function instead, as opposed to having a separate
hash map for every given object.

In other words: Remove handlers (and handlers_tipc) map for every instance
then read from a static defined per-class.

- [x] Migrate all HLE functions to new `frozen::map` constexpr time finder
- [ ] Measure if this approach actually makes better codegen

Optional:
- [x] Properly gate all functions (that have versions commented next to them)
- [x] Maybe store `HandlerFnP<>` and `const char*` separately, version gating can go in a different map as well

Information such as name can be used on debug builds, but doesn't particularly help on release as one can consult an external reference (or have an annotated IPC map)

Signed-off-by: lizzie <lizzie@eden-emu.dev>

- [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions).
- [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md)
- [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability.

-------------------

Co-authored-by: Maufeat <sahyno1996@gmail.com>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4480
Reviewed-by: Maufeat <sahyno1996@gmail.com>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
This commit is contained in:
lizzie
2026-10-13 04:38:36 +02:00
committed by PavelBARABANOV
parent 989768aa46
commit 1059202c75
392 changed files with 12453 additions and 14117 deletions
+115 -112
View File
@@ -235,15 +235,6 @@ public:
explicit IScanRequest(Core::System& system_)
: ServiceFramework{system_, "IScanRequest"}, svc_ctx{system_, "IScanRequest"} {
static const FunctionInfo functions[] = {
{0, &IScanRequest::Submit, "Submit"},
{1, &IScanRequest::IsProcessing, "IsProcessing"},
{2, &IScanRequest::GetResult, "GetResult"},
{3, &IScanRequest::GetSystemEventReadableHandle, "GetSystemEventReadableHandle"},
{4, &IScanRequest::SetChannels, "SetChannels"},
};
RegisterHandlers(functions);
evt_scan_complete = CreateKEvent(svc_ctx, "IScanRequest:Complete");
evt_processing = CreateKEvent(svc_ctx, "IScanRequest:Processing");
}
@@ -257,8 +248,6 @@ public:
}
private:
std::vector<Network::ScanData> scan_results;
void Submit(HLERequestContext& ctx) {
if (state.load() == State::Finished) {
@@ -329,6 +318,17 @@ private:
evt_scan_complete->Signal(system.Kernel());
}
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, &IScanRequest::Submit, "Submit"},
FunctionInfo{1, &IScanRequest::IsProcessing, "IsProcessing"},
FunctionInfo{2, &IScanRequest::GetResult, "GetResult"},
FunctionInfo{3, &IScanRequest::GetSystemEventReadableHandle, "GetSystemEventReadableHandle"},
FunctionInfo{4, &IScanRequest::SetChannels, "SetChannels"}
);
std::vector<Network::ScanData> scan_results;
KernelHelpers::ServiceContext svc_ctx;
Kernel::KEvent* evt_scan_complete{};
@@ -342,36 +342,6 @@ class IRequest final : public ServiceFramework<IRequest> {
public:
explicit IRequest(Core::System& system_)
: ServiceFramework{system_, "IRequest"}, service_context{system_, "IRequest"} {
static const FunctionInfo functions[] = {
{0, &IRequest::GetRequestState, "GetRequestState"},
{1, &IRequest::GetResult, "GetResult"},
{2, &IRequest::GetSystemEventReadableHandles, "GetSystemEventReadableHandles"},
{3, &IRequest::Cancel, "Cancel"},
{4, &IRequest::Submit, "Submit"},
{5, nullptr, "SetRequirement"},
{6, &IRequest::SetRequirementPreset, "SetRequirementPreset"},
{8, nullptr, "SetPriority"},
{9, &IRequest::SetNetworkProfileId, "SetNetworkProfileId"},
{10, nullptr, "SetRejectable"},
{11, &IRequest::SetConnectionConfirmationOption, "SetConnectionConfirmationOption"},
{12, nullptr, "SetPersistent"},
{13, nullptr, "SetInstant"},
{14, nullptr, "SetSustainable"},
{15, nullptr, "SetRawPriority"},
{16, nullptr, "SetGreedy"},
{17, nullptr, "SetSharable"},
{18, nullptr, "SetRequirementByRevision"},
{19, nullptr, "GetRequirement"},
{20, nullptr, "GetRevision"},
{21, &IRequest::GetAppletInfo, "GetAppletInfo"},
{22, nullptr, "GetAdditionalInfo"},
{23, nullptr, "SetKeptInSleep"},
{24, nullptr, "RegisterSocketDescriptor"},
{25, nullptr, "UnregisterSocketDescriptor"},
{26, nullptr, "GetNetworkAccessStatus"}, //21.0.0+
};
RegisterHandlers(functions);
event1 = CreateKEvent(service_context, "IRequest:Event1");
event2 = CreateKEvent(service_context, "IRequest:Event2");
state = RequestState::NotSubmitted;
@@ -494,6 +464,37 @@ private:
event1->Signal(system.Kernel());
}
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, &IRequest::GetRequestState, "GetRequestState"},
FunctionInfo{1, &IRequest::GetResult, "GetResult"},
FunctionInfo{2, &IRequest::GetSystemEventReadableHandles, "GetSystemEventReadableHandles"},
FunctionInfo{3, &IRequest::Cancel, "Cancel"},
FunctionInfo{4, &IRequest::Submit, "Submit"},
FunctionInfo{5, nullptr, "SetRequirement"},
FunctionInfo{6, &IRequest::SetRequirementPreset, "SetRequirementPreset"},
FunctionInfo{8, nullptr, "SetPriority"},
FunctionInfo{9, &IRequest::SetNetworkProfileId, "SetNetworkProfileId"},
FunctionInfo{10, nullptr, "SetRejectable"},
FunctionInfo{11, &IRequest::SetConnectionConfirmationOption, "SetConnectionConfirmationOption"},
FunctionInfo{12, nullptr, "SetPersistent"},
FunctionInfo{13, nullptr, "SetInstant"},
FunctionInfo{14, nullptr, "SetSustainable"},
FunctionInfo{15, nullptr, "SetRawPriority"},
FunctionInfo{16, nullptr, "SetGreedy"},
FunctionInfo{17, nullptr, "SetSharable"},
FunctionInfo{18, nullptr, "SetRequirementByRevision"},
FunctionInfo{19, nullptr, "GetRequirement"},
FunctionInfo{20, nullptr, "GetRevision"},
FunctionInfo{21, &IRequest::GetAppletInfo, "GetAppletInfo"},
FunctionInfo{22, nullptr, "GetAdditionalInfo"},
FunctionInfo{23, nullptr, "SetKeptInSleep"},
FunctionInfo{24, nullptr, "RegisterSocketDescriptor"},
FunctionInfo{25, nullptr, "UnregisterSocketDescriptor"},
FunctionInfo{26, nullptr, "GetNetworkAccessStatus", MakeVersionGate({21,0,0})}
);
KernelHelpers::ServiceContext service_context;
RequestState state;
@@ -508,14 +509,16 @@ private:
class INetworkProfile final : public ServiceFramework<INetworkProfile> {
public:
explicit INetworkProfile(Core::System& system_) : ServiceFramework{system_, "INetworkProfile"} {
static const FunctionInfo functions[] = {
{0, nullptr, "Update"},
{1, nullptr, "PersistOld"},
{2, nullptr, "Persist"},
};
RegisterHandlers(functions);
explicit INetworkProfile(Core::System& system_) : ServiceFramework{system_, "INetworkProfile"} {}
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, nullptr, "Update"},
FunctionInfo{1, nullptr, "PersistOld"},
FunctionInfo{2, nullptr, "Persist"}
);
};
void IGeneralService::GetClientId(HLERequestContext& ctx) {
@@ -1050,78 +1053,70 @@ void IGeneralService::GetCurrentAccessPoint(HLERequestContext& ctx) {
rb.Push(ResultSuccess);
}
std::optional<ServiceFrameworkBase::FunctionInfoBase> IGeneralService::FindRequest(u32 key) {
static constexpr auto functions = CreateStaticMap(
FunctionInfo{1, &IGeneralService::GetClientId, "GetClientId"},
FunctionInfo{2, &IGeneralService::CreateScanRequest, "CreateScanRequest"},
FunctionInfo{4, &IGeneralService::CreateRequest, "CreateRequest"},
FunctionInfo{5, &IGeneralService::GetCurrentNetworkProfile, "GetCurrentNetworkProfile"},
FunctionInfo{6, &IGeneralService::EnumerateNetworkInterfaces, "EnumerateNetworkInterfaces"},
FunctionInfo{7, &IGeneralService::EnumerateNetworkProfiles, "EnumerateNetworkProfiles"},
FunctionInfo{8, &IGeneralService::GetNetworkProfile, "GetNetworkProfile"},
FunctionInfo{9, &IGeneralService::SetNetworkProfile, "SetNetworkProfile"},
FunctionInfo{10, &IGeneralService::RemoveNetworkProfile, "RemoveNetworkProfile"},
FunctionInfo{11, &IGeneralService::GetScanData, "GetScanDataOld"},
FunctionInfo{12, &IGeneralService::GetCurrentIpAddress, "GetCurrentIpAddress"},
FunctionInfo{13, nullptr, "GetCurrentAccessPointOld"},
FunctionInfo{14, &IGeneralService::CreateTemporaryNetworkProfile, "CreateTemporaryNetworkProfile"},
FunctionInfo{15, &IGeneralService::GetCurrentIpConfigInfo, "GetCurrentIpConfigInfo"},
FunctionInfo{16, &IGeneralService::SetWirelessCommunicationEnabled, "SetWirelessCommunicationEnabled"},
FunctionInfo{17, &IGeneralService::IsWirelessCommunicationEnabled, "IsWirelessCommunicationEnabled"},
FunctionInfo{18, &IGeneralService::GetInternetConnectionStatus, "GetInternetConnectionStatus"},
FunctionInfo{19, &IGeneralService::SetEthernetCommunicationEnabled, "SetEthernetCommunicationEnabled"},
FunctionInfo{20, &IGeneralService::IsEthernetCommunicationEnabled, "IsEthernetCommunicationEnabled"},
FunctionInfo{21, &IGeneralService::IsAnyInternetRequestAccepted, "IsAnyInternetRequestAccepted"},
FunctionInfo{22, &IGeneralService::IsAnyForegroundRequestAccepted, "IsAnyForegroundRequestAccepted"},
FunctionInfo{23, nullptr, "PutToSleep"},
FunctionInfo{24, nullptr, "WakeUp"},
FunctionInfo{25, &IGeneralService::GetSsidListVersion, "GetSsidListVersion"},
FunctionInfo{26, nullptr, "SetExclusiveClient"},
FunctionInfo{27, nullptr, "GetDefaultIpSetting"},
FunctionInfo{28, nullptr, "SetDefaultIpSetting"},
FunctionInfo{29, nullptr, "SetWirelessCommunicationEnabledForTest"},
FunctionInfo{30, nullptr, "SetEthernetCommunicationEnabledForTest"},
FunctionInfo{31, nullptr, "GetTelemetorySystemEventReadableHandle"},
FunctionInfo{32, nullptr, "GetTelemetryInfo"},
FunctionInfo{33, &IGeneralService::ConfirmSystemAvailability, "ConfirmSystemAvailability", MakeVersionGate({2,0,0})},
FunctionInfo{34, &IGeneralService::SetBackgroundRequestEnabled, "SetBackgroundRequestEnabled", MakeVersionGate({4,0,0})},
FunctionInfo{35, &IGeneralService::GetScanDataV2, "GetScanData"},
FunctionInfo{36, &IGeneralService::GetCurrentAccessPoint, "GetCurrentAccessPoint"},
FunctionInfo{37, nullptr, "Shutdown"},
FunctionInfo{38, nullptr, "GetAllowedChannels"},
FunctionInfo{39, nullptr, "NotifyApplicationSuspended"},
FunctionInfo{40, nullptr, "SetAcceptableNetworkTypeFlag"},
FunctionInfo{41, nullptr, "GetAcceptableNetworkTypeFlag"},
FunctionInfo{42, nullptr, "NotifyConnectionStateChanged"},
FunctionInfo{43, nullptr, "SetWowlDelayedWakeTime"},
FunctionInfo{44, nullptr, "IsWiredConnectionAvailable", MakeVersionGate({18,0,0})},
FunctionInfo{45, nullptr, "IsNetworkEmulationFeatureEnabled", MakeVersionGate({18,0,0})},
FunctionInfo{46, nullptr, "SelectActiveNetworkEmulationProfileIdForDebug", MakeVersionGate({18,0,0})},
FunctionInfo{47, &IGeneralService::GetScanDataV3, "GetScanData", MakeVersionGate({19,0,0})},
FunctionInfo{50, nullptr, "IsRewriteFeatureEnabled", MakeVersionGate({18,0,0})},
FunctionInfo{51, nullptr, "CreateRewriteRule", MakeVersionGate({18,0,0})},
FunctionInfo{52, nullptr, "DestroyRewriteRule", MakeVersionGate({18,0,0})}
);
return HandlerTableGenerateWithFind(key, functions);
}
IGeneralService::IGeneralService(Core::System& system_)
: ServiceFramework{system_, "IGeneralService"} {
// clang-format off
static const FunctionInfo functions[] = {
{1, &IGeneralService::GetClientId, "GetClientId"},
{2, &IGeneralService::CreateScanRequest, "CreateScanRequest"},
{4, &IGeneralService::CreateRequest, "CreateRequest"},
{5, &IGeneralService::GetCurrentNetworkProfile, "GetCurrentNetworkProfile"},
{6, &IGeneralService::EnumerateNetworkInterfaces, "EnumerateNetworkInterfaces"},
{7, &IGeneralService::EnumerateNetworkProfiles, "EnumerateNetworkProfiles"},
{8, &IGeneralService::GetNetworkProfile, "GetNetworkProfile"},
{9, &IGeneralService::SetNetworkProfile, "SetNetworkProfile"},
{10, &IGeneralService::RemoveNetworkProfile, "RemoveNetworkProfile"},
{11, &IGeneralService::GetScanData, "GetScanDataOld"},
{12, &IGeneralService::GetCurrentIpAddress, "GetCurrentIpAddress"},
{13, nullptr, "GetCurrentAccessPointOld"},
{14, &IGeneralService::CreateTemporaryNetworkProfile, "CreateTemporaryNetworkProfile"},
{15, &IGeneralService::GetCurrentIpConfigInfo, "GetCurrentIpConfigInfo"},
{16, &IGeneralService::SetWirelessCommunicationEnabled, "SetWirelessCommunicationEnabled"},
{17, &IGeneralService::IsWirelessCommunicationEnabled, "IsWirelessCommunicationEnabled"},
{18, &IGeneralService::GetInternetConnectionStatus, "GetInternetConnectionStatus"},
{19, &IGeneralService::SetEthernetCommunicationEnabled, "SetEthernetCommunicationEnabled"},
{20, &IGeneralService::IsEthernetCommunicationEnabled, "IsEthernetCommunicationEnabled"},
{21, &IGeneralService::IsAnyInternetRequestAccepted, "IsAnyInternetRequestAccepted"},
{22, &IGeneralService::IsAnyForegroundRequestAccepted, "IsAnyForegroundRequestAccepted"},
{23, nullptr, "PutToSleep"},
{24, nullptr, "WakeUp"},
{25, &IGeneralService::GetSsidListVersion, "GetSsidListVersion"},
{26, nullptr, "SetExclusiveClient"},
{27, nullptr, "GetDefaultIpSetting"},
{28, nullptr, "SetDefaultIpSetting"},
{29, nullptr, "SetWirelessCommunicationEnabledForTest"},
{30, nullptr, "SetEthernetCommunicationEnabledForTest"},
{31, nullptr, "GetTelemetorySystemEventReadableHandle"},
{32, nullptr, "GetTelemetryInfo"},
{33, &IGeneralService::ConfirmSystemAvailability, "ConfirmSystemAvailability"}, // 2.0.0+
{34, &IGeneralService::SetBackgroundRequestEnabled, "SetBackgroundRequestEnabled"}, // 4.0.0+
{35, &IGeneralService::GetScanDataV2, "GetScanData"},
{36, &IGeneralService::GetCurrentAccessPoint, "GetCurrentAccessPoint"},
{37, nullptr, "Shutdown"},
{38, nullptr, "GetAllowedChannels"},
{39, nullptr, "NotifyApplicationSuspended"},
{40, nullptr, "SetAcceptableNetworkTypeFlag"},
{41, nullptr, "GetAcceptableNetworkTypeFlag"},
{42, nullptr, "NotifyConnectionStateChanged"},
{43, nullptr, "SetWowlDelayedWakeTime"},
{44, nullptr, "IsWiredConnectionAvailable"}, // 18.0.0+
{45, nullptr, "IsNetworkEmulationFeatureEnabled"}, // 18.0.0+
{46, nullptr, "SelectActiveNetworkEmulationProfileIdForDebug"}, // 18.0.0+
{47, &IGeneralService::GetScanDataV3, "GetScanData"}, // 19.0.0+
{50, nullptr, "IsRewriteFeatureEnabled"}, // 18.0.0+
{51, nullptr, "CreateRewriteRule"}, // 18.0.0+
{52, nullptr, "DestroyRewriteRule"} // 18.0.0+
};
// clang-format on
RegisterHandlers(functions);
}
IGeneralService::~IGeneralService() = default;
class NetworkInterface final : public ServiceFramework<NetworkInterface> {
public:
explicit NetworkInterface(const char* name, Core::System& system_)
: ServiceFramework{system_, name} {
static const FunctionInfo functions[] = {
{4, &NetworkInterface::CreateGeneralServiceOld, "CreateGeneralServiceOld"},
{5, &NetworkInterface::CreateGeneralService, "CreateGeneralService"},
};
RegisterHandlers(functions);
}
explicit NetworkInterface(const char* name, Core::System& system_) : ServiceFramework{system_, name} {}
private:
void CreateGeneralServiceOld(HLERequestContext& ctx) {
@@ -1139,6 +1134,14 @@ private:
rb.Push(ResultSuccess);
rb.PushIpcInterface<IGeneralService>(ctx, system);
}
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{4, &NetworkInterface::CreateGeneralServiceOld, "CreateGeneralServiceOld"},
FunctionInfo{5, &NetworkInterface::CreateGeneralService, "CreateGeneralService"}
);
};
void LoopProcess(Core::System& system) {
+1
View File
@@ -51,6 +51,7 @@ private:
void SetBackgroundRequestEnabled(HLERequestContext& ctx);
void GetCurrentAccessPoint(HLERequestContext& ctx);
void GetScanDataV3(HLERequestContext& ctx);
std::optional<FunctionInfoBase> FindRequest(u32 key) override;
};
} // namespace Service::NIFM