new-ipc: implement deferral. sm now works.

This commit is contained in:
Michael Scire 2019-10-11 02:15:14 -07:00 committed by SciresM
parent f4dcd1db9b
commit c8ed190e5c
13 changed files with 193 additions and 157 deletions

View file

@ -33,7 +33,7 @@ extern "C" {
u32 __nx_applet_type = AppletType_None;
#define INNER_HEAP_SIZE 0x20000
#define INNER_HEAP_SIZE 0x4000
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
char nx_inner_heap[INNER_HEAP_SIZE];
@ -68,7 +68,7 @@ void __libnx_initheap(void) {
}
void __appInit(void) {
SetFirmwareVersionForLibnx();
sts::hos::SetVersionForLibnx();
/* We must do no service setup here, because we are sm. */
}
@ -79,29 +79,45 @@ void __appExit(void) {
using namespace sts;
namespace {
/* sm:m, sm:, sm:dmnt. */
constexpr size_t NumServers = 3;
sf::hipc::ServerManager<NumServers> g_server_manager;
}
int main(int argc, char **argv)
{
/* Create service waitable manager. */
static auto s_server_manager = WaitableManager(1);
/* NOTE: These handles are manually managed, but we don't save references to them to close on exit. */
/* This is fine, because if SM crashes we have much bigger issues. */
/* Create sm:, (and thus allow things to register to it). */
s_server_manager.AddWaitable(new ManagedPortServer<sm::UserService>("sm:", 0x40));
{
Handle sm_h;
R_ASSERT(svcManageNamedPort(&sm_h, "sm:", 0x40));
g_server_manager.RegisterServer<sm::UserService>(sm_h);
}
/* Create sm:m manually. */
Handle smm_h;
R_ASSERT(sm::impl::RegisterServiceForSelf(&smm_h, sm::ServiceName::Encode("sm:m"), 1));
s_server_manager.AddWaitable(new ExistingPortServer<sm::ManagerService>(smm_h, 1));
{
Handle smm_h;
R_ASSERT(sm::impl::RegisterServiceForSelf(&smm_h, sm::ServiceName::Encode("sm:m"), 1));
g_server_manager.RegisterServer<sm::ManagerService>(smm_h);
}
/*===== ATMOSPHERE EXTENSION =====*/
/* Create sm:dmnt manually. */
Handle smdmnt_h;
R_ASSERT(sm::impl::RegisterServiceForSelf(&smdmnt_h, sm::ServiceName::Encode("sm:dmnt"), 1));
s_server_manager.AddWaitable(new ExistingPortServer<sm::DmntService>(smm_h, 1));;
{
Handle smdmnt_h;
R_ASSERT(sm::impl::RegisterServiceForSelf(&smdmnt_h, sm::ServiceName::Encode("sm:dmnt"), 1));
g_server_manager.RegisterServer<sm::DmntService>(smdmnt_h);
}
/*================================*/
/* Loop forever, servicing our services. */
s_server_manager.Process();
g_server_manager.LoopProcess();
/* Cleanup. */
return 0;