[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
+97 -99
View File
@@ -19,79 +19,10 @@ class INpnsSystem final : public ServiceFramework<INpnsSystem> {
public:
explicit INpnsSystem(Core::System& system_)
: ServiceFramework{system_, "npns:s"}, service_context{system, "npns:s"},
get_receive_event{service_context}, get_request_change_state_cancel_event{service_context} {
// clang-format off
static const FunctionInfo functions[] = {
{1, nullptr, "ListenAll"},
{2, C<&INpnsSystem::ListenTo>, "ListenTo"},
{3, nullptr, "Receive"},
{4, nullptr, "ReceiveRaw"},
{5, C<&INpnsSystem::GetReceiveEvent>, "GetReceiveEvent"},
{6, nullptr, "ListenUndelivered"},
{7, nullptr, "GetStateChangeEvent"},
{8, C<&INpnsSystem::ListenToByName>, "ListenToByName"},
{11, nullptr, "SubscribeTopic"},
{12, nullptr, "UnsubscribeTopic"},
{13, nullptr, "QueryIsTopicExist"},
{14, nullptr, "SubscribeTopicByAccount"}, // 18.0.0+
{15, nullptr, "UnsubscribeTopicByAccount"}, // 18.0.0+
{16, nullptr, "DownloadSubscriptionList"}, // 18.0.0+
{21, nullptr, "CreateToken"},
{22, nullptr, "CreateTokenWithApplicationId"},
{23, nullptr, "DestroyToken"},
{24, nullptr, "DestroyTokenWithApplicationId"},
{25, nullptr, "QueryIsTokenValid"},
{26, nullptr, "ListenToMyApplicationId"},
{27, nullptr, "DestroyTokenAll"},
{28, nullptr, "CreateTokenWithName"}, // 18.0.0+
{29, nullptr, "DestroyTokenWithName"}, // 18.0.0+
{31, nullptr, "UploadTokenToBaaS"},
{32, nullptr, "DestroyTokenForBaaS"},
{33, nullptr, "CreateTokenForBaaS"},
{34, nullptr, "SetBaaSDeviceAccountIdList"},
{35, nullptr, "LinkNsaId"}, // 17.0.0+
{36, nullptr, "UnlinkNsaId"}, // 17.0.0+
{37, nullptr, "RelinkNsaId"}, // 18.0.0+
{40, nullptr, "GetNetworkServiceAccountIdTokenRequestEvent"}, // 17.0.0+
{41, nullptr, "TryPopNetworkServiceAccountIdTokenRequestUid"}, // 17.0.0+
{42, nullptr, "SetNetworkServiceAccountIdTokenSuccess"}, // 17.0.0+
{43, nullptr, "SetNetworkServiceAccountIdTokenFailure"}, // 17.0.0+
{44, nullptr, "SetUidList"}, // 17.0.0+
{45, nullptr, "PutDigitalTwinKeyValue"}, // 17.0.0+
{51, nullptr, "DeleteDigitalTwinKeyValue"}, // 18.0.0+
{101, nullptr, "Suspend"},
{102, nullptr, "Resume"},
{103, C<&INpnsSystem::GetState>, "GetState"},
{104, nullptr, "GetStatistics"},
{105, nullptr, "GetPlayReportRequestEvent"},
{106, C<&INpnsSystem::GetLastNotifiedTime>, "GetLastNotifiedTime"}, // 18.0.0+
{107, nullptr, "SetLastNotifiedTime"}, // 18.0.0+
{111, nullptr, "GetJid"},
{112, nullptr, "CreateJid"},
{113, nullptr, "DestroyJid"},
{114, nullptr, "AttachJid"},
{115, nullptr, "DetachJid"},
{120, nullptr, "CreateNotificationReceiver"},
{151, nullptr, "GetStateWithHandover"},
{152, nullptr, "GetStateChangeEventWithHandover"},
{153, nullptr, "GetDropEventWithHandover"},
{154, nullptr, "CreateTokenAsync"},
{155, nullptr, "CreateTokenAsyncWithApplicationId"},
{156, nullptr, "CreateTokenWithNameAsync"}, // 18.0.0+
{161, C<&INpnsSystem::GetRequestChangeStateCancelEvent>, "GetRequestChangeStateCancelEvent"}, // 10.0.0+
{162, nullptr, "RequestChangeStateForceTimedWithCancelEvent"},
{201, nullptr, "RequestChangeStateForceTimed"},
{202, nullptr, "RequestChangeStateForceAsync"},
{301, nullptr, "GetPassword"}, // 18.0.0+
{302, nullptr, "GetAllImmigration"}, // 18.0.0+
{303, nullptr, "GetNotificationHistories"}, // 18.0.0+
{304, nullptr, "GetPersistentConnectionSummary"}, // 18.0.0+
{305, nullptr, "GetDigitalTwinSummary"}, // 18.0.0+
{306, nullptr, "GetDigitalTwinValue"}, // 18.0.0+
};
// clang-format on
get_receive_event{service_context}, get_request_change_state_cancel_event{service_context} {}
RegisterHandlers(functions);
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
~INpnsSystem() override = default;
@@ -140,6 +71,74 @@ private:
R_SUCCEED();
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{1, nullptr, "ListenAll"},
FunctionInfo{2, C<&INpnsSystem::ListenTo>, "ListenTo"},
FunctionInfo{3, nullptr, "Receive"},
FunctionInfo{4, nullptr, "ReceiveRaw"},
FunctionInfo{5, C<&INpnsSystem::GetReceiveEvent>, "GetReceiveEvent"},
FunctionInfo{6, nullptr, "ListenUndelivered"},
FunctionInfo{7, nullptr, "GetStateChangeEvent"},
FunctionInfo{8, C<&INpnsSystem::ListenToByName>, "ListenToByName"},
FunctionInfo{11, nullptr, "SubscribeTopic"},
FunctionInfo{12, nullptr, "UnsubscribeTopic"},
FunctionInfo{13, nullptr, "QueryIsTopicExist"},
FunctionInfo{14, nullptr, "SubscribeTopicByAccount", MakeVersionGate({18,0,0})},
FunctionInfo{15, nullptr, "UnsubscribeTopicByAccount", MakeVersionGate({18,0,0})},
FunctionInfo{16, nullptr, "DownloadSubscriptionList", MakeVersionGate({18,0,0})},
FunctionInfo{21, nullptr, "CreateToken"},
FunctionInfo{22, nullptr, "CreateTokenWithApplicationId"},
FunctionInfo{23, nullptr, "DestroyToken"},
FunctionInfo{24, nullptr, "DestroyTokenWithApplicationId"},
FunctionInfo{25, nullptr, "QueryIsTokenValid"},
FunctionInfo{26, nullptr, "ListenToMyApplicationId"},
FunctionInfo{27, nullptr, "DestroyTokenAll"},
FunctionInfo{28, nullptr, "CreateTokenWithName", MakeVersionGate({18,0,0})},
FunctionInfo{29, nullptr, "DestroyTokenWithName", MakeVersionGate({18,0,0})},
FunctionInfo{31, nullptr, "UploadTokenToBaaS"},
FunctionInfo{32, nullptr, "DestroyTokenForBaaS"},
FunctionInfo{33, nullptr, "CreateTokenForBaaS"},
FunctionInfo{34, nullptr, "SetBaaSDeviceAccountIdList"},
FunctionInfo{35, nullptr, "LinkNsaId", MakeVersionGate({17,0,0})},
FunctionInfo{36, nullptr, "UnlinkNsaId", MakeVersionGate({17,0,0})},
FunctionInfo{37, nullptr, "RelinkNsaId", MakeVersionGate({18,0,0})},
FunctionInfo{40, nullptr, "GetNetworkServiceAccountIdTokenRequestEvent", MakeVersionGate({17,0,0})},
FunctionInfo{41, nullptr, "TryPopNetworkServiceAccountIdTokenRequestUid", MakeVersionGate({17,0,0})},
FunctionInfo{42, nullptr, "SetNetworkServiceAccountIdTokenSuccess", MakeVersionGate({17,0,0})},
FunctionInfo{43, nullptr, "SetNetworkServiceAccountIdTokenFailure", MakeVersionGate({17,0,0})},
FunctionInfo{44, nullptr, "SetUidList", MakeVersionGate({17,0,0})},
FunctionInfo{45, nullptr, "PutDigitalTwinKeyValue", MakeVersionGate({17,0,0})},
FunctionInfo{51, nullptr, "DeleteDigitalTwinKeyValue", MakeVersionGate({18,0,0})},
FunctionInfo{101, nullptr, "Suspend"},
FunctionInfo{102, nullptr, "Resume"},
FunctionInfo{103, C<&INpnsSystem::GetState>, "GetState"},
FunctionInfo{104, nullptr, "GetStatistics"},
FunctionInfo{105, nullptr, "GetPlayReportRequestEvent"},
FunctionInfo{106, C<&INpnsSystem::GetLastNotifiedTime>, "GetLastNotifiedTime", MakeVersionGate({18,0,0})},
FunctionInfo{107, nullptr, "SetLastNotifiedTime", MakeVersionGate({18,0,0})},
FunctionInfo{111, nullptr, "GetJid"},
FunctionInfo{112, nullptr, "CreateJid"},
FunctionInfo{113, nullptr, "DestroyJid"},
FunctionInfo{114, nullptr, "AttachJid"},
FunctionInfo{115, nullptr, "DetachJid"},
FunctionInfo{120, nullptr, "CreateNotificationReceiver"},
FunctionInfo{151, nullptr, "GetStateWithHandover"},
FunctionInfo{152, nullptr, "GetStateChangeEventWithHandover"},
FunctionInfo{153, nullptr, "GetDropEventWithHandover"},
FunctionInfo{154, nullptr, "CreateTokenAsync"},
FunctionInfo{155, nullptr, "CreateTokenAsyncWithApplicationId"},
FunctionInfo{156, nullptr, "CreateTokenWithNameAsync", MakeVersionGate({18,0,0})},
FunctionInfo{161, C<&INpnsSystem::GetRequestChangeStateCancelEvent>, "GetRequestChangeStateCancelEvent", MakeVersionGate({10,0,0})},
FunctionInfo{162, nullptr, "RequestChangeStateForceTimedWithCancelEvent"},
FunctionInfo{201, nullptr, "RequestChangeStateForceTimed"},
FunctionInfo{202, nullptr, "RequestChangeStateForceAsync"},
FunctionInfo{301, nullptr, "GetPassword", MakeVersionGate({18,0,0})},
FunctionInfo{302, nullptr, "GetAllImmigration", MakeVersionGate({18,0,0})},
FunctionInfo{303, nullptr, "GetNotificationHistories", MakeVersionGate({18,0,0})},
FunctionInfo{304, nullptr, "GetPersistentConnectionSummary", MakeVersionGate({18,0,0})},
FunctionInfo{305, nullptr, "GetDigitalTwinSummary", MakeVersionGate({18,0,0})},
FunctionInfo{306, nullptr, "GetDigitalTwinValue", MakeVersionGate({18,0,0})}
);
KernelHelpers::ServiceContext service_context;
Event get_receive_event;
Event get_request_change_state_cancel_event;
@@ -148,34 +147,10 @@ private:
class INpnsUser final : public ServiceFramework<INpnsUser> {
public:
explicit INpnsUser(Core::System& system_)
: ServiceFramework{system_, "npns:u"}, service_context{system, "npns:u"}, get_receive_event{service_context} {
// clang-format off
static const FunctionInfo functions[] = {
{1, nullptr, "ListenAll"},
{2, nullptr, "ListenTo"},
{3, nullptr, "Receive"},
{4, nullptr, "ReceiveRaw"},
{5, C<&INpnsUser::GetReceiveEvent>, "GetReceiveEvent"},
{7, nullptr, "GetStateChangeEvent"},
{8, C<&INpnsUser::ListenToByName>, "ListenToByName"}, // 18.0.0+
{21, nullptr, "CreateToken"},
{23, nullptr, "DestroyToken"},
{25, nullptr, "QueryIsTokenValid"},
{26, nullptr, "ListenToMyApplicationId"},
{101, nullptr, "Suspend"},
{102, nullptr, "Resume"},
{103, nullptr, "GetState"},
{104, nullptr, "GetStatistics"},
{111, nullptr, "GetJid"},
{120, nullptr, "CreateNotificationReceiver"},
{151, nullptr, "GetStateWithHandover"},
{152, nullptr, "GetStateChangeEventWithHandover"},
{153, nullptr, "GetDropEventWithHandover"},
{154, nullptr, "CreateTokenAsync"},
};
// clang-format on
: ServiceFramework{system_, "npns:u"}, service_context{system, "npns:u"}, get_receive_event{service_context} {}
RegisterHandlers(functions);
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
private:
@@ -195,6 +170,29 @@ private:
R_SUCCEED();
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{1, nullptr, "ListenAll"},
FunctionInfo{2, nullptr, "ListenTo"},
FunctionInfo{3, nullptr, "Receive"},
FunctionInfo{4, nullptr, "ReceiveRaw"},
FunctionInfo{5, C<&INpnsUser::GetReceiveEvent>, "GetReceiveEvent"},
FunctionInfo{7, nullptr, "GetStateChangeEvent"},
FunctionInfo{8, C<&INpnsUser::ListenToByName>, "ListenToByName", MakeVersionGate({18,0,0})},
FunctionInfo{21, nullptr, "CreateToken"},
FunctionInfo{23, nullptr, "DestroyToken"},
FunctionInfo{25, nullptr, "QueryIsTokenValid"},
FunctionInfo{26, nullptr, "ListenToMyApplicationId"},
FunctionInfo{101, nullptr, "Suspend"},
FunctionInfo{102, nullptr, "Resume"},
FunctionInfo{103, nullptr, "GetState"},
FunctionInfo{104, nullptr, "GetStatistics"},
FunctionInfo{111, nullptr, "GetJid"},
FunctionInfo{120, nullptr, "CreateNotificationReceiver"},
FunctionInfo{151, nullptr, "GetStateWithHandover"},
FunctionInfo{152, nullptr, "GetStateChangeEventWithHandover"},
FunctionInfo{153, nullptr, "GetDropEventWithHandover"},
FunctionInfo{154, nullptr, "CreateTokenAsync"}
);
KernelHelpers::ServiceContext service_context;
Event get_receive_event;
};