diff --git a/source/processes/ns.cpp b/source/processes/ns.cpp index b9c6cda..f8dc214 100644 --- a/source/processes/ns.cpp +++ b/source/processes/ns.cpp @@ -275,108 +275,6 @@ source.GetLogger()->info("{}: {}", __FUNCTION__, __LINE__); return process; } -// TODO: Replace LaunchTitleInternal with (LaunchTitleFromFile + this) -OS::ResultAnd LaunchTitleInternal3(FakeThread& source, const FileFormat::ExHeader& exheader, HandleTable::Entry& process, uint8_t media_type) { - auto [result, process_id] = source.CallSVC(&OS::SVCGetProcessId, *process.second); - if (result != RESULT_OK) - throw std::runtime_error("LaunchTitle failed to SVCGetProcessId"); - - HandleTable::Entry srv_session = { HANDLE_INVALID, nullptr }; - bool needs_services = true; - if (needs_services) { - std::tie(result,srv_session) = source.CallSVC(&OS::SVCConnectToPort, "srv:"); - if (result != RESULT_OK) - throw std::runtime_error("LaunchTitle failed to SVCConnectToPort"); - - IPC::SendIPCRequest(source, srv_session.first, IPC::EmptyValue{}); - } - - // Register the created process to srv:pm - // TODO: Enable this code... - // TODO: Now that we fixed SM HLE, WE REALLY NEED TO DO THIS PROPERLY INSTEAD. I.e. have loader do this, and have loader register these via pm - auto not_null = [](auto letter) { return letter != 0; }; - auto nonempty_entry = [&](const auto& service) { return boost::algorithm::any_of(service, not_null); }; -// bool needs_services = boost::algorithm::any_of(exheader.service_access_list, nonempty_entry); - if (false && needs_services) { - // Register process through "srv:pm" - // TODO: srv:pm is a service for firmwares higher than 7.0.0 -// Handle srvpm_handle = IPC::SendIPCRequest(source, srv_session.first, -// SM::PortName("srv:pm"), 0); - HandleTable::Entry srvpm_session; - // TODO: On system version 7.0.0 and up, srv:pm is a service! - std::tie(result,srvpm_session) = source.CallSVC(&OS::SVCConnectToPort, "srv:pm"); - if (result != RESULT_OK) { - throw std::runtime_error("LaunchTitle failed to connect to srv:pm"); - } - - auto& parent_process = source.GetParentProcess(); - - // srvpm RegisterProcess - source.WriteTLS(0x80, IPC::CommandHeader::Make(0x403, 2, 2).raw); - source.WriteTLS(0x84, process_id); - auto service_acl_entry_size = sizeof(exheader.aci.service_access_list[0]); - auto service_acl_size = (sizeof(exheader.aci.service_access_list) + service_acl_entry_size - 1) / service_acl_entry_size * service_acl_entry_size; - auto service_acl_addr = parent_process.AllocateStaticBuffer(service_acl_size); - auto service_acl_numentries = service_acl_size / service_acl_entry_size; - - for (auto off = 0; off < sizeof(exheader.aci.service_access_list); ++off) { - auto entry = off / service_acl_entry_size; - auto byte = off % service_acl_entry_size; - source.WriteMemory(service_acl_addr + off, exheader.aci.service_access_list[entry][byte]); - } - source.WriteTLS(0x88, service_acl_numentries); - source.WriteTLS(0x8c, IPC::TranslationDescriptor::MakeStaticBuffer(0, service_acl_size).raw); - source.WriteTLS(0x90, service_acl_addr); - std::tie(result) = source.CallSVC(&OS::SVCSendSyncRequest, srvpm_session.first); - if (result != RESULT_OK && source.ReadTLS(0x84) != RESULT_OK) - throw std::runtime_error("LaunchTitle failed to RegisterProcess to srv:pm"); - - parent_process.FreeStaticBuffer(service_acl_addr); - - source.CallSVC(&OS::SVCCloseHandle, srvpm_session.first); - } - - FS::ProgramInfo program_info{}; - program_info.program_id = exheader.aci.program_id; - program_info.media_type = media_type; - - // Connect to fs:REG and register the new process - // NOTE: Currently, we do this for all non-FIRM processes. There probably - // is an exheader flag that determines when to do this, though! - { - Handle fsreg_handle = IPC::SendIPCRequest(source, srv_session.first, - SM::PortName("fs:REG"), 0); - source.GetLogger()->info("Registering to fs:REG with program id {:#018x}", program_info.program_id); - - // TODO: This program handle is supposed to be retrieved from - // PxiPM::RegisterProgram, which returns the Process9-internal - // handle for the registered application. Since we don't emulate - // PxiPM currently, we just dummy-initialize this program handle - // with an incorrect (but unique) value for now. - Platform::PXI::PM::ProgramHandle program_handle = {process_id}; - - IPC::SendIPCRequest(source, fsreg_handle, - process_id, program_handle, - program_info, FS::StorageInfo{}); - - source.CallSVC(&OS::SVCCloseHandle, fsreg_handle); - } - - source.CallSVC(&OS::SVCCloseHandle, srv_session.first); - source.GetLogger()->info("{} {}EXHEADER STACK SIZE: {:#x}", ThreadPrinter{source}, __LINE__, exheader.stack_size); - - // Run main thread - OS::StartupInfo startup{}; - startup.stack_size = exheader.stack_size; - startup.priority = exheader.aci.flags.priority(); - source.GetLogger()->info("{}about to start title main thread", ThreadPrinter{source}); - std::tie(result) = source.CallSVC(&OS::SVCRun, process.first, startup); - - // Clean up - source.CallSVC(&OS::SVCCloseHandle, std::move(process).first); - - return std::make_tuple(RESULT_OK, process_id); -} OS::ResultAnd LaunchTitleInternal(FakeThread& source, bool from_firm, uint64_t title_id, uint32_t flags /* (currently unused) */) { // TODO: This is fairly ad-hoc currently, i.e. all logic in here is