mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-28 09:30:58 +01:00
Stratosphere: Create sm:m internally for sm, instead of using IPC.
This commit is contained in:
parent
080816f2b6
commit
c8ef305880
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "sm_manager_service.hpp"
|
#include "sm_manager_service.hpp"
|
||||||
#include "sm_user_service.hpp"
|
#include "sm_user_service.hpp"
|
||||||
|
#include "sm_registration.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern u32 __start__;
|
extern u32 __start__;
|
||||||
@ -41,8 +42,7 @@ void __appInit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __appExit(void) {
|
void __appExit(void) {
|
||||||
/* Disconnect from ourselves. */
|
/* Nothing to clean up, because we're sm. */
|
||||||
smExit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
@ -55,11 +55,13 @@ int main(int argc, char **argv)
|
|||||||
/* Create sm:, (and thus allow things to register to it). */
|
/* Create sm:, (and thus allow things to register to it). */
|
||||||
server_manager->add_waitable(new ManagedPortServer<UserService>("sm:", 0x40));
|
server_manager->add_waitable(new ManagedPortServer<UserService>("sm:", 0x40));
|
||||||
|
|
||||||
/* Initialize, connecting to ourself. */
|
/* Create sm:m manually. */
|
||||||
smInitialize();
|
Handle smm_h;
|
||||||
|
if (R_FAILED(Registration::RegisterServiceForSelf(smEncodeName("sm:m"), 1, false, &smm_h))) {
|
||||||
|
/* TODO: Panic. */
|
||||||
|
}
|
||||||
|
|
||||||
/* Create sm:m, using libnx to talk to ourself. */
|
server_manager->add_waitable(new ExistingPortServer<ManagerService>(smm_h, 1));
|
||||||
server_manager->add_waitable(new ServiceServer<ManagerService>("sm:m", 1));
|
|
||||||
|
|
||||||
/* Loop forever, servicing our services. */
|
/* Loop forever, servicing our services. */
|
||||||
server_manager->process();
|
server_manager->process();
|
||||||
|
@ -221,6 +221,44 @@ Result Registration::RegisterServiceForPid(u64 pid, u64 service, u64 max_session
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result Registration::RegisterServiceForSelf(u64 service, u64 max_sessions, bool is_light, Handle *out) {
|
||||||
|
u64 pid;
|
||||||
|
Result rc = svcGetProcessId(&pid, CUR_PROCESS_HANDLE);
|
||||||
|
if (R_FAILED(rc)) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 service_name_len = 0;
|
||||||
|
while ((service >> (8 * service_name_len)) & 0xFF) {
|
||||||
|
service_name_len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the service has bytes after a null terminator, that's no good. */
|
||||||
|
if ((service >> (8 * service_name_len))) {
|
||||||
|
return 0xC15;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HasService(service)) {
|
||||||
|
return 0x815;
|
||||||
|
}
|
||||||
|
|
||||||
|
Registration::Service *free_service = GetFreeService();
|
||||||
|
if (free_service == NULL) {
|
||||||
|
return 0xA15;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = 0;
|
||||||
|
*free_service = (const Registration::Service){0};
|
||||||
|
rc = svcCreatePort(out, &free_service->port_h, max_sessions, is_light, (char *)&free_service->service_name);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
free_service->service_name = service;
|
||||||
|
free_service->owner_pid = pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
Result Registration::UnregisterServiceForPid(u64 pid, u64 service) {
|
Result Registration::UnregisterServiceForPid(u64 pid, u64 service) {
|
||||||
if (!service) {
|
if (!service) {
|
||||||
return 0xC15;
|
return 0xC15;
|
||||||
|
@ -36,5 +36,6 @@ class Registration {
|
|||||||
static bool HasService(u64 service);
|
static bool HasService(u64 service);
|
||||||
static Result GetServiceForPid(u64 pid, u64 service, Handle *out);
|
static Result GetServiceForPid(u64 pid, u64 service, Handle *out);
|
||||||
static Result RegisterServiceForPid(u64 pid, u64 service, u64 max_sessions, bool is_light, Handle *out);
|
static Result RegisterServiceForPid(u64 pid, u64 service, u64 max_sessions, bool is_light, Handle *out);
|
||||||
|
static Result RegisterServiceForSelf(u64 service, u64 max_sessions, bool is_light, Handle *out);
|
||||||
static Result UnregisterServiceForPid(u64 pid, u64 service);
|
static Result UnregisterServiceForPid(u64 pid, u64 service);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user