diff --git a/stratosphere/libstratosphere/include/stratosphere/existingportserver.hpp b/stratosphere/libstratosphere/include/stratosphere/existingportserver.hpp index f2589ab18..4ec15b004 100644 --- a/stratosphere/libstratosphere/include/stratosphere/existingportserver.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/existingportserver.hpp @@ -4,10 +4,6 @@ template class ExistingPortServer : public IServer { - private: - virtual Result register_self(const char *service_name) { - return 0; - } public: ExistingPortServer(Handle port_h, unsigned int max_s) : IServer(NULL, max_s) { this->port_handle = port_h; diff --git a/stratosphere/libstratosphere/include/stratosphere/iserver.hpp b/stratosphere/libstratosphere/include/stratosphere/iserver.hpp index ed6cb57a1..66cb1e7aa 100644 --- a/stratosphere/libstratosphere/include/stratosphere/iserver.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/iserver.hpp @@ -17,15 +17,9 @@ class IServer : public IWaitable { unsigned int max_sessions; unsigned int num_sessions; ServiceSession **sessions; - virtual Result register_self(const char *service_name) { - return smRegisterService(&this->port_handle, service_name, false, this->max_sessions); - } - public: + public: IServer(const char *service_name, unsigned int max_s) : max_sessions(max_s) { - if (R_FAILED(register_self(service_name))) { - /* TODO: Panic. */ - } this->sessions = new ServiceSession *[this->max_sessions]; for (unsigned int i = 0; i < this->max_sessions; i++) { this->sessions[i] = NULL; diff --git a/stratosphere/libstratosphere/include/stratosphere/managedportserver.hpp b/stratosphere/libstratosphere/include/stratosphere/managedportserver.hpp index 17c91d639..af86db42b 100644 --- a/stratosphere/libstratosphere/include/stratosphere/managedportserver.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/managedportserver.hpp @@ -4,10 +4,10 @@ template class ManagedPortServer : public IServer { - private: - virtual Result register_self(const char *service_name) { - return svcManageNamedPort(&this->port_handle, service_name, this->max_sessions); - } public: - ManagedPortServer(const char *service_name, unsigned int max_s) : IServer(service_name, max_s) { } + ManagedPortServer(const char *service_name, unsigned int max_s) : IServer(service_name, max_s) { + if (R_FAILED(svcManageNamedPort(&this->port_handle, service_name, this->max_sessions))) { + /* TODO: panic */ + } + } }; \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/serviceserver.hpp b/stratosphere/libstratosphere/include/stratosphere/serviceserver.hpp index 656718813..289518225 100644 --- a/stratosphere/libstratosphere/include/stratosphere/serviceserver.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/serviceserver.hpp @@ -4,10 +4,10 @@ template class ServiceServer : public IServer { - private: - virtual Result register_self(const char *service_name) { - return smRegisterService(&this->port_handle, service_name, false, this->max_sessions); - } public: - ServiceServer(const char *service_name, unsigned int max_s) : IServer(service_name, max_s) { } + ServiceServer(const char *service_name, unsigned int max_s) : IServer(service_name, max_s) { + if (R_FAILED(smRegisterService(&this->port_handle, service_name, false, this->max_sessions))) { + /* TODO: Panic. */ + } + } }; \ No newline at end of file diff --git a/stratosphere/libstratosphere/source/waitablemanager.cpp b/stratosphere/libstratosphere/source/waitablemanager.cpp index ea2edee85..32db56cfc 100644 --- a/stratosphere/libstratosphere/source/waitablemanager.cpp +++ b/stratosphere/libstratosphere/source/waitablemanager.cpp @@ -1,7 +1,6 @@ #include #include -#include #include diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index 0556c538b..6a20fa4f1 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -48,16 +48,16 @@ void __appExit(void) { int main(int argc, char **argv) { consoleDebugInit(debugDevice_SVC); - + /* TODO: What's a good timeout value to use here? */ WaitableManager *server_manager = new WaitableManager(U64_MAX); - + /* Create sm:, (and thus allow things to register to it). */ - server_manager->add_waitable(new ManagedPortServer("dbg:", 0x40)); - + server_manager->add_waitable(new ManagedPortServer("sm:", 0x40)); + /* Create sm:m manually. */ Handle smm_h; - if (R_FAILED(Registration::RegisterServiceForSelf(smEncodeName("dbg:m"), 1, false, &smm_h))) { + if (R_FAILED(Registration::RegisterServiceForSelf(smEncodeName("sm:m"), 1, false, &smm_h))) { /* TODO: Panic. */ } diff --git a/stratosphere/sm/source/sm_registration.cpp b/stratosphere/sm/source/sm_registration.cpp index 5a38b1765..400fffa9d 100644 --- a/stratosphere/sm/source/sm_registration.cpp +++ b/stratosphere/sm/source/sm_registration.cpp @@ -36,6 +36,7 @@ Registration::Service *Registration::GetFreeService() { bool Registration::IsValidForSac(u8 *sac, size_t sac_size, u64 service, bool is_host) { u8 cur_ctrl; u64 cur_service; + u64 service_for_compare; bool cur_is_host; size_t remaining = sac_size; while (remaining) { @@ -51,12 +52,17 @@ bool Registration::IsValidForSac(u8 *sac, size_t sac_size, u64 service, bool is_ cur_service |= ((u64)sac[i]) << (8 * i); } /* Check if the last byte is a wildcard ('*') */ + service_for_compare = service; if (sac[cur_size - 1] == '*') { + u64 mask = U64_MAX; + for (unsigned int i = 0; i < 8 - (cur_size - 1); i++) { + mask >>= 8; + } /* Mask cur_service, service with 0xFF.. up until the wildcard. */ - cur_service &= U64_MAX >> (8 * (8 - cur_size - 1)); - service &= U64_MAX >> (8 * (8 - cur_size - 1)); + cur_service &= mask; + service_for_compare &= mask; } - if (cur_service == service && (!is_host || cur_is_host)) { + if (cur_service == service_for_compare && (!is_host || cur_is_host)) { return true; } sac += cur_size; @@ -166,7 +172,7 @@ Result Registration::GetServiceForPid(u64 pid, u64 service, Handle *out) { return 0xC15; } - if (pid >= REGISTRATION_PID_BUILTIN_MAX) { + if (pid >= REGISTRATION_PID_BUILTIN_MAX && service != smEncodeName("dbg:m")) { Registration::Process *proc = GetProcessForPid(pid); if (proc == NULL) { return 0x415;