[tma2] [Ongoing] Continue implementing modules for tma2. (#1388)

* cs: add stub sysmodule to host command shell server

* cs: implement logic for main (linker error paradise, for now)

* cs: implement more of the system module's skeleton

* htcs: update client type names for libnx pr merge
This commit is contained in:
SciresM
2021-03-16 17:13:30 -07:00
committed by GitHub
parent 021d4c88fa
commit 5362ee9450
44 changed files with 1785 additions and 6 deletions

View File

@@ -45,6 +45,7 @@
#include <stratosphere/capsrv.hpp>
#include <stratosphere/cfg.hpp>
#include <stratosphere/clkrst.hpp>
#include <stratosphere/cs.hpp>
#include <stratosphere/ddsf.hpp>
#include <stratosphere/dmnt.hpp>
#include <stratosphere/erpt.hpp>
@@ -77,6 +78,7 @@
#include <stratosphere/regulator.hpp>
#include <stratosphere/ro.hpp>
#include <stratosphere/settings.hpp>
#include <stratosphere/scs.hpp>
#include <stratosphere/sf.hpp>
#include <stratosphere/sm.hpp>
#include <stratosphere/socket.hpp>

View File

@@ -144,6 +144,19 @@ namespace ams::impl {
AMS_DEFINE_SYSTEM_THREAD(10, tma, BridgePcieDriver);
/* cs/scs. */
AMS_DEFINE_SYSTEM_THREAD(20, cs, Main);
AMS_DEFINE_SYSTEM_THREAD(20, cs, HidctlService);
AMS_DEFINE_SYSTEM_THREAD(20, cs, HidctlLegacyServer);
AMS_DEFINE_SYSTEM_THREAD(20, cs, AudioServer);
AMS_DEFINE_SYSTEM_THREAD(10, cs, GrcVideoSender);
AMS_DEFINE_SYSTEM_THREAD(10, cs, GrcVideoReader);
AMS_DEFINE_SYSTEM_THREAD(10, cs, GrcAudioSender);
AMS_DEFINE_SYSTEM_THREAD(10, cs, GrcAudioReader);
AMS_DEFINE_SYSTEM_THREAD(21, scs, ShellServer);
AMS_DEFINE_SYSTEM_THREAD(21, scs, ShellEventHandler);
/* DevServer/TioServer. */
AMS_DEFINE_SYSTEM_THREAD(21, TioServer, Main);
AMS_DEFINE_SYSTEM_THREAD(21, TioServer, FileServerHtcsServer);

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/cs/cs_audio_server.hpp>
#include <stratosphere/cs/cs_hid_server.hpp>
#include <stratosphere/cs/cs_remote_video_server.hpp>
#include <stratosphere/cs/cs_target_io_server.hpp>
#include <stratosphere/cs/cs_command_processor.hpp>

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::cs {
void InitializeAudioServer();
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/scs/scs_command_processor.hpp>
namespace ams::cs {
using CommandHeader = scs::CommandHeader;
using ResponseHeader = scs::ResponseHeader;
class CommandProcessor : public scs::CommandProcessor {
public:
virtual bool ProcessCommand(const CommandHeader &header, const u8 *body, s32 socket) override;
};
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::cs {
void InitializeHidServer();
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::cs {
void InitializeRemoteVideoServer();
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::cs {
void InitializeTargetIoServer();
}

View File

@@ -17,3 +17,7 @@
#include <stratosphere/htc/server/htc_htcmisc_hipc_server.hpp>
#include <stratosphere/htc/server/htc_htcmisc_channel_ids.hpp>
#include <stratosphere/htc/tenv/htc_tenv_types.hpp>
#include <stratosphere/htc/tenv/htc_tenv.hpp>
#include <stratosphere/htc/tenv/htc_tenv_service_manager.hpp>

View File

@@ -0,0 +1,25 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::htc::tenv {
void Initialize(AllocateFunction allocate, DeallocateFunction deallocate);
Result RegisterDefinitionFilePath(os::ProcessId process_id, const char *path, size_t size);
void UnregisterDefinitionFilePath(os::ProcessId process_id);
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/sf.hpp>
#include <stratosphere/htc/tenv/htc_tenv_types.hpp>
#define AMS_HTC_TENV_I_SERVICE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, GetVariable, (sf::Out<s64> out_size, const sf::OutBuffer &out_buffer, const htc::tenv::VariableName &name), (out_size, out_buffer, name)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, GetVariableLength, (sf::Out<s64> out_size,const htc::tenv::VariableName &name), (out_size, name)) \
AMS_SF_METHOD_INFO(C, H, 2, Result, WaitUntilVariableAvailable, (s64 timeout_ms), (timeout_ms))
AMS_SF_DEFINE_INTERFACE(ams::htc::tenv, IService, AMS_HTC_TENV_I_SERVICE_INTERFACE_INFO)

View File

@@ -0,0 +1,25 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/sf.hpp>
#include <stratosphere/os/os_common_types.hpp>
#include <stratosphere/htc/tenv/htc_tenv_i_service.hpp>
#define AMS_HTC_TENV_I_SERVICE_MANAGER_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, GetServiceInterface, (sf::Out<sf::SharedPointer<htc::tenv::IService>> out, const sf::ClientProcessId &process_id), (out, process_id))
AMS_SF_DEFINE_INTERFACE(ams::htc::tenv, IServiceManager, AMS_HTC_TENV_I_SERVICE_MANAGER_INTERFACE_INFO)

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/sm/sm_types.hpp>
#include <stratosphere/htc/tenv/htc_tenv_i_service_manager.hpp>
namespace ams::htc::tenv {
constexpr inline sm::ServiceName ServiceName = sm::ServiceName::Encode("htc:tenv");
class ServiceManager {
public:
Result GetServiceInterface(sf::Out<sf::SharedPointer<htc::tenv::IService>> out, const sf::ClientProcessId &process_id);
};
static_assert(htc::tenv::IsIServiceManager<ServiceManager>);
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::htc::tenv {
struct VariableName {
char str[0x40];
};
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/scs/scs_command_processor.hpp>
#include <stratosphere/scs/scs_shell_server.hpp>
#include <stratosphere/scs/scs_shell.hpp>
#include <stratosphere/scs/scs_tenv.hpp>
#include <stratosphere/scs/scs_server_manager.hpp>

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::scs {
struct CommandHeader {
u64 id;
u32 command;
u32 body_size;
};
struct ResponseHeader {
u64 id;
u32 response;
u32 body_size;
};
class CommandProcessor {
protected:
enum Command {
Command_None = 0,
Command_LaunchProgramFromHost = 1,
Command_TerminateProcesses = 2,
Command_GetFirmwareVersion = 3,
Command_Reboot = 4,
Command_SetSafeMode = 5,
Command_RegisterTenvDefinitionFilePath = 6,
Command_TerminateApplication = 7,
Command_Shutdown = 8,
Command_SubscribeProcessEvent = 9,
Command_GetTitleName = 10,
Command_ControlVirtualTemperature = 11,
Command_LaunchInstalledApplication = 12,
Command_LaunchGameCardApplication = 13,
Command_LaunchInstalledSystemProcess = 14,
Command_TakeScreenShot = 15,
Command_TakeForegroundScreenShot = 16,
Command_SimulateGameCardDetection = 17,
Command_SimulateSdCardDetection = 18,
Command_DumpRunningApplication = 19,
};
enum Response {
Response_None = 0,
Response_Success = 1,
Response_Error = 2,
/* ... */
};
public:
constexpr CommandProcessor() = default;
void Initialize();
public:
virtual bool ProcessCommand(const CommandHeader &header, const u8 *body, s32 socket);
protected:
static void SendSuccess(s32 socket, const CommandHeader &header);
static void SendErrorResult(s32 socket, const CommandHeader &header, Result result);
private:
static void SendErrorResult(s32 socket, u64 id, Result result);
static void OnProcessStart(u64 id, s32 socket, os::ProcessId process_id);
static void OnProcessExit(u64 id, s32 socket, os::ProcessId process_id);
static void OnProcessJitDebug(u64 id, s32 socket, os::ProcessId process_id);
};
os::SdkMutex &GetHtcsSendMutex();
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/sf.hpp>
namespace ams::scs {
enum Port {
Port_HtcTenv,
Port_Count,
};
constexpr inline int SessionCount[Port_Count] = {
6,
};
constexpr inline auto MaxSessions = [] {
auto total = 0;
for (const auto sessions : SessionCount) {
total += sessions;
}
return total;
}();
struct ServerOptions {
static constexpr size_t PointerBufferSize = 0;
static constexpr size_t MaxDomains = 6;
static constexpr size_t MaxDomainObjects = 16;
};
class ServerManager final : public sf::hipc::ServerManager<Port_Count, ServerOptions, MaxSessions> {
/* ... */
};
ServerManager *GetServerManager();
void StartServer();
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os.hpp>
#include <stratosphere/ncm/ncm_ids.hpp>
namespace ams::scs {
using ProcessEventHandler = void(*)(u64 id, s32 socket, os::ProcessId process_id);
void InitializeShell();
void RegisterCommonProcessEventHandler(ProcessEventHandler on_start, ProcessEventHandler on_exit, ProcessEventHandler on_jit_debug);
bool RegisterSocket(s32 socket);
void UnregisterSocket(s32 socket);
Result LaunchProgram(os::ProcessId *out, ncm::ProgramId program_id, const void *args, size_t args_size, u32 process_flags);
Result SubscribeProcessEvent(s32 socket, bool is_register, u64 id);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os.hpp>
#include <stratosphere/htcs.hpp>
#include <stratosphere/scs/scs_command_processor.hpp>
namespace ams::scs {
class ShellServer {
private:
htcs::HtcsPortName m_port_name;
os::ThreadType m_thread;
u8 m_buffer[64_KB];
CommandProcessor *m_command_processor;
private:
static void ThreadEntry(void *arg) { reinterpret_cast<ShellServer *>(arg)->DoShellServer(); }
void DoShellServer();
public:
constexpr ShellServer() = default;
public:
void Initialize(const char *port_name, void *stack, size_t stack_size, CommandProcessor *command_processor);
void Start();
};
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::scs {
void InitializeTenvServiceManager();
}