[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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 1785 additions and 6 deletions

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();
}