Stratosphere: Fix IServer constructors. SM is fully functional on hardware now.

This commit is contained in:
Michael Scire 2018-04-22 05:13:33 -06:00
parent 674528b246
commit ecf2517bd5
7 changed files with 26 additions and 31 deletions

View file

@ -4,10 +4,6 @@
template <typename T>
class ExistingPortServer : public IServer<T> {
private:
virtual Result register_self(const char *service_name) {
return 0;
}
public:
ExistingPortServer(Handle port_h, unsigned int max_s) : IServer<T>(NULL, max_s) {
this->port_handle = port_h;

View file

@ -17,15 +17,9 @@ class IServer : public IWaitable {
unsigned int max_sessions;
unsigned int num_sessions;
ServiceSession<T> **sessions;
virtual Result register_self(const char *service_name) {
return smRegisterService(&this->port_handle, service_name, false, this->max_sessions);
}
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<T> *[this->max_sessions];
for (unsigned int i = 0; i < this->max_sessions; i++) {
this->sessions[i] = NULL;

View file

@ -4,10 +4,10 @@
template <typename T>
class ManagedPortServer : public IServer<T> {
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<T>(service_name, max_s) { }
ManagedPortServer(const char *service_name, unsigned int max_s) : IServer<T>(service_name, max_s) {
if (R_FAILED(svcManageNamedPort(&this->port_handle, service_name, this->max_sessions))) {
/* TODO: panic */
}
}
};

View file

@ -4,10 +4,10 @@
template <typename T>
class ServiceServer : public IServer<T> {
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<T>(service_name, max_s) { }
ServiceServer(const char *service_name, unsigned int max_s) : IServer<T>(service_name, max_s) {
if (R_FAILED(smRegisterService(&this->port_handle, service_name, false, this->max_sessions))) {
/* TODO: Panic. */
}
}
};

View file

@ -1,7 +1,6 @@
#include <switch.h>
#include <algorithm>
#include <cstdio>
#include <stratosphere/waitablemanager.hpp>

View file

@ -53,11 +53,11 @@ int main(int argc, char **argv)
WaitableManager *server_manager = new WaitableManager(U64_MAX);
/* Create sm:, (and thus allow things to register to it). */
server_manager->add_waitable(new ManagedPortServer<UserService>("dbg:", 0x40));
server_manager->add_waitable(new ManagedPortServer<UserService>("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. */
}

View file

@ -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] == '*') {
/* 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));
u64 mask = U64_MAX;
for (unsigned int i = 0; i < 8 - (cur_size - 1); i++) {
mask >>= 8;
}
if (cur_service == service && (!is_host || cur_is_host)) {
/* Mask cur_service, service with 0xFF.. up until the wildcard. */
cur_service &= mask;
service_for_compare &= mask;
}
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;