mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-03 16:18:51 -04:00
[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:
parent
021d4c88fa
commit
5362ee9450
44 changed files with 1785 additions and 6 deletions
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
23
libraries/libstratosphere/include/stratosphere/cs.hpp
Normal file
23
libraries/libstratosphere/include/stratosphere/cs.hpp
Normal 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>
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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)
|
|
@ -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)
|
|
@ -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>);
|
||||
|
||||
}
|
|
@ -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];
|
||||
};
|
||||
|
||||
}
|
24
libraries/libstratosphere/include/stratosphere/scs.hpp
Normal file
24
libraries/libstratosphere/include/stratosphere/scs.hpp
Normal 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>
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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();
|
||||
};
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -397,6 +397,7 @@ namespace ams::boot2 {
|
|||
/* Device whether to launch tma or htc. */
|
||||
if (svc::IsKernelMesosphere() && IsHtcEnabled()) {
|
||||
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Htc, ncm::StorageId::None), 0);
|
||||
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Cs, ncm::StorageId::None), 0);
|
||||
} else {
|
||||
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Tma, ncm::StorageId::BuiltInSystem), 0);
|
||||
}
|
||||
|
|
24
libraries/libstratosphere/source/cs/cs_audio_server.cpp
Normal file
24
libraries/libstratosphere/source/cs/cs_audio_server.cpp
Normal 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::cs {
|
||||
|
||||
void InitializeAudioServer() {
|
||||
/* TODO: Support audio server. */
|
||||
}
|
||||
|
||||
}
|
31
libraries/libstratosphere/source/cs/cs_command_processor.cpp
Normal file
31
libraries/libstratosphere/source/cs/cs_command_processor.cpp
Normal 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::cs {
|
||||
|
||||
bool CommandProcessor::ProcessCommand(const CommandHeader &header, const u8 *body, s32 socket) {
|
||||
switch (header.command) {
|
||||
/* TODO: Command support. */
|
||||
default:
|
||||
scs::CommandProcessor::ProcessCommand(header, body, socket);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
24
libraries/libstratosphere/source/cs/cs_hid_server.cpp
Normal file
24
libraries/libstratosphere/source/cs/cs_hid_server.cpp
Normal 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::cs {
|
||||
|
||||
void InitializeHidServer() {
|
||||
/* TODO: Support hid redirection server. */
|
||||
}
|
||||
|
||||
}
|
|
@ -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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::cs {
|
||||
|
||||
void InitializeRemoteVideoServer() {
|
||||
/* TODO: Support remote video server. */
|
||||
}
|
||||
|
||||
}
|
26
libraries/libstratosphere/source/cs/cs_target_io_server.cpp
Normal file
26
libraries/libstratosphere/source/cs/cs_target_io_server.cpp
Normal 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::cs {
|
||||
|
||||
void InitializeTargetIoServer() {
|
||||
/* Launch target io server. */
|
||||
os::ProcessId process_id;
|
||||
scs::LaunchProgram(std::addressof(process_id), ncm::SystemProgramId::DevServer, nullptr, 0, 0);
|
||||
}
|
||||
|
||||
}
|
26
libraries/libstratosphere/source/htc/tenv/htc_tenv.cpp
Normal file
26
libraries/libstratosphere/source/htc/tenv/htc_tenv.cpp
Normal 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "impl/htc_tenv_allocator.hpp"
|
||||
|
||||
namespace ams::htc::tenv {
|
||||
|
||||
void Initialize(AllocateFunction allocate, DeallocateFunction deallocate) {
|
||||
/* Initialize the library allocator. */
|
||||
impl::InitializeAllocator(allocate, deallocate);
|
||||
}
|
||||
|
||||
}
|
|
@ -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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htc_tenv_service.hpp"
|
||||
|
||||
namespace ams::htc::tenv {
|
||||
|
||||
Result Service::GetVariable(sf::Out<s64> out_size, const sf::OutBuffer &out_buffer, const htc::tenv::VariableName &name) {
|
||||
/* TODO */
|
||||
AMS_ABORT("Service::GetVariable");
|
||||
}
|
||||
|
||||
Result Service::GetVariableLength(sf::Out<s64> out_size,const htc::tenv::VariableName &name) {
|
||||
/* TODO */
|
||||
AMS_ABORT("Service::GetVariableLength");
|
||||
}
|
||||
|
||||
Result Service::WaitUntilVariableAvailable(s64 timeout_ms) {
|
||||
/* TODO */
|
||||
AMS_ABORT("Service::WaitUntilVariableAvailable");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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.hpp>
|
||||
|
||||
namespace ams::htc::tenv {
|
||||
|
||||
class Service {
|
||||
private:
|
||||
os::ProcessId m_process_id;
|
||||
public:
|
||||
constexpr Service(os::ProcessId pid) : m_process_id(pid) { /* ... */ }
|
||||
public:
|
||||
Result GetVariable(sf::Out<s64> out_size, const sf::OutBuffer &out_buffer, const htc::tenv::VariableName &name);
|
||||
Result GetVariableLength(sf::Out<s64> out_size,const htc::tenv::VariableName &name);
|
||||
Result WaitUntilVariableAvailable(s64 timeout_ms);
|
||||
};
|
||||
static_assert(htc::tenv::IsIService<Service>);
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "impl/htc_tenv_allocator.hpp"
|
||||
#include "htc_tenv_service.hpp"
|
||||
|
||||
namespace ams::htc::tenv {
|
||||
|
||||
Result ServiceManager::GetServiceInterface(sf::Out<sf::SharedPointer<htc::tenv::IService>> out, const sf::ClientProcessId &process_id) {
|
||||
*out = impl::SfObjectFactory::CreateSharedEmplaced<htc::tenv::IService, Service>(process_id.GetValue());
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htc_tenv_allocator.hpp"
|
||||
|
||||
namespace ams::htc::tenv::impl {
|
||||
|
||||
namespace {
|
||||
|
||||
constinit AllocateFunction g_allocate = nullptr;
|
||||
constinit DeallocateFunction g_deallocate = nullptr;
|
||||
|
||||
}
|
||||
|
||||
void InitializeAllocator(AllocateFunction allocate, DeallocateFunction deallocate) {
|
||||
/* Check that we don't already have allocator functions. */
|
||||
AMS_ASSERT(g_allocate == nullptr);
|
||||
AMS_ASSERT(g_deallocate == nullptr);
|
||||
|
||||
/* Set our allocator functions. */
|
||||
g_allocate = allocate;
|
||||
g_deallocate = deallocate;
|
||||
|
||||
/* Check that we have allocator functions. */
|
||||
AMS_ASSERT(g_allocate != nullptr);
|
||||
AMS_ASSERT(g_deallocate != nullptr);
|
||||
}
|
||||
|
||||
void *Allocate(size_t size) {
|
||||
/* Check that we have an allocator. */
|
||||
AMS_ASSERT(g_allocate != nullptr);
|
||||
|
||||
return g_allocate(size);
|
||||
}
|
||||
|
||||
void Deallocate(void *p, size_t size) {
|
||||
/* Check that we have a deallocator. */
|
||||
AMS_ASSERT(g_deallocate != nullptr);
|
||||
|
||||
return g_deallocate(p, size);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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.hpp>
|
||||
|
||||
namespace ams::htc::tenv::impl {
|
||||
|
||||
void InitializeAllocator(AllocateFunction allocate, DeallocateFunction deallocate);
|
||||
|
||||
void *Allocate(size_t size);
|
||||
void Deallocate(void *p, size_t size);
|
||||
|
||||
class SfAllocator {
|
||||
public:
|
||||
constexpr ALWAYS_INLINE SfAllocator() { /* ... */ }
|
||||
|
||||
void *Allocate(size_t size) {
|
||||
return ::ams::htc::tenv::impl::Allocate(size);
|
||||
}
|
||||
|
||||
void Deallocate(void *p, size_t size) {
|
||||
return ::ams::htc::tenv::impl::Deallocate(p, size);
|
||||
}
|
||||
};
|
||||
|
||||
using SfPolicy = sf::StatelessAllocationPolicy<SfAllocator>;
|
||||
using SfObjectFactory = sf::ObjectFactory<SfPolicy>;
|
||||
|
||||
}
|
|
@ -150,13 +150,13 @@ namespace ams::htcs::client {
|
|||
}
|
||||
|
||||
Result RemoteSocket::Connect(sf::Out<s32> out_err, sf::Out<s32> out_res, const htcs::SockAddrHtcs &address) {
|
||||
static_assert(sizeof(htcs::SockAddrHtcs) == sizeof(::SockAddrHtcs));
|
||||
return ::htcsSocketConnect(std::addressof(m_s), out_err.GetPointer(), out_res.GetPointer(), reinterpret_cast<const ::SockAddrHtcs *>(std::addressof(address)));
|
||||
static_assert(sizeof(htcs::SockAddrHtcs) == sizeof(::HtcsSockAddr));
|
||||
return ::htcsSocketConnect(std::addressof(m_s), out_err.GetPointer(), out_res.GetPointer(), reinterpret_cast<const ::HtcsSockAddr *>(std::addressof(address)));
|
||||
}
|
||||
|
||||
Result RemoteSocket::Bind(sf::Out<s32> out_err, sf::Out<s32> out_res, const htcs::SockAddrHtcs &address) {
|
||||
static_assert(sizeof(htcs::SockAddrHtcs) == sizeof(::SockAddrHtcs));
|
||||
return ::htcsSocketBind(std::addressof(m_s), out_err.GetPointer(), out_res.GetPointer(), reinterpret_cast<const ::SockAddrHtcs *>(std::addressof(address)));
|
||||
static_assert(sizeof(htcs::SockAddrHtcs) == sizeof(::HtcsSockAddr));
|
||||
return ::htcsSocketBind(std::addressof(m_s), out_err.GetPointer(), out_res.GetPointer(), reinterpret_cast<const ::HtcsSockAddr *>(std::addressof(address)));
|
||||
}
|
||||
|
||||
Result RemoteSocket::Listen(sf::Out<s32> out_err, sf::Out<s32> out_res, s32 backlog_count) {
|
||||
|
@ -176,9 +176,9 @@ namespace ams::htcs::client {
|
|||
}
|
||||
|
||||
Result RemoteSocket::AcceptResults(sf::Out<s32> out_err, sf::Out<sf::SharedPointer<tma::ISocket>> out, sf::Out<htcs::SockAddrHtcs> out_address, u32 task_id) {
|
||||
static_assert(sizeof(htcs::SockAddrHtcs) == sizeof(::SockAddrHtcs));
|
||||
static_assert(sizeof(htcs::SockAddrHtcs) == sizeof(::HtcsSockAddr));
|
||||
::HtcsSocket libnx_socket;
|
||||
R_TRY(::htcsSocketAcceptResults(std::addressof(m_s), out_err.GetPointer(), std::addressof(libnx_socket), reinterpret_cast<::SockAddrHtcs *>(out_address.GetPointer()), task_id));
|
||||
R_TRY(::htcsSocketAcceptResults(std::addressof(m_s), out_err.GetPointer(), std::addressof(libnx_socket), reinterpret_cast<::HtcsSockAddr *>(out_address.GetPointer()), task_id));
|
||||
|
||||
R_SUCCEED_IF(*out_err != 0);
|
||||
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::scs {
|
||||
|
||||
namespace {
|
||||
|
||||
struct ResponseError {
|
||||
ResponseHeader header;
|
||||
u32 result;
|
||||
};
|
||||
|
||||
constinit os::SdkMutex g_htcs_send_mutex;
|
||||
|
||||
}
|
||||
|
||||
os::SdkMutex &GetHtcsSendMutex() {
|
||||
return g_htcs_send_mutex;
|
||||
}
|
||||
|
||||
void CommandProcessor::SendSuccess(s32 socket, const CommandHeader &header) {
|
||||
/* Build the response. */
|
||||
const ResponseHeader response = {
|
||||
.id = header.id,
|
||||
.response = Response_Success,
|
||||
.body_size = 0,
|
||||
};
|
||||
|
||||
/* Send the response. */
|
||||
std::scoped_lock lk(GetHtcsSendMutex());
|
||||
htcs::Send(socket, std::addressof(response), sizeof(response), 0);
|
||||
}
|
||||
|
||||
void CommandProcessor::SendErrorResult(s32 socket, const CommandHeader &header, Result result) {
|
||||
return SendErrorResult(socket, header.id, result);
|
||||
}
|
||||
|
||||
void CommandProcessor::SendErrorResult(s32 socket, u64 id, Result result) {
|
||||
/* Build the response. */
|
||||
const ResponseError response = {
|
||||
.header = {
|
||||
.id = id,
|
||||
.response = Response_Error,
|
||||
.body_size = sizeof(response) - sizeof(response.header),
|
||||
},
|
||||
.result = result.GetValue(),
|
||||
};
|
||||
|
||||
/* Send the response. */
|
||||
std::scoped_lock lk(GetHtcsSendMutex());
|
||||
htcs::Send(socket, std::addressof(response), sizeof(response), 0);
|
||||
}
|
||||
|
||||
void CommandProcessor::OnProcessStart(u64 id, s32 socket, os::ProcessId process_id) {
|
||||
/* TODO */
|
||||
AMS_ABORT("CommandProcessor::OnProcessStart");
|
||||
}
|
||||
|
||||
void CommandProcessor::OnProcessExit(u64 id, s32 socket, os::ProcessId process_id) {
|
||||
/* TODO */
|
||||
AMS_ABORT("CommandProcessor::OnProcessExit");
|
||||
}
|
||||
|
||||
void CommandProcessor::OnProcessJitDebug(u64 id, s32 socket, os::ProcessId process_id) {
|
||||
/* TODO */
|
||||
AMS_ABORT("CommandProcessor::OnProcessJitDebug");
|
||||
}
|
||||
|
||||
void CommandProcessor::Initialize() {
|
||||
/* Register our process event handlers. */
|
||||
scs::RegisterCommonProcessEventHandler(OnProcessStart, OnProcessExit, OnProcessJitDebug);
|
||||
}
|
||||
|
||||
bool CommandProcessor::ProcessCommand(const CommandHeader &header, const u8 *body, s32 socket) {
|
||||
switch (header.command) {
|
||||
/* TODO: Support commands. */
|
||||
default:
|
||||
SendErrorResult(socket, header, scs::ResultUnknownCommand());
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
38
libraries/libstratosphere/source/scs/scs_server_manager.cpp
Normal file
38
libraries/libstratosphere/source/scs/scs_server_manager.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::scs {
|
||||
|
||||
namespace {
|
||||
|
||||
ServerManager g_server_manager;
|
||||
|
||||
}
|
||||
|
||||
ServerManager *GetServerManager() {
|
||||
return std::addressof(g_server_manager);
|
||||
}
|
||||
|
||||
void StartServer() {
|
||||
/* Start the server. */
|
||||
g_server_manager.ResumeProcessing();
|
||||
|
||||
/* Loop processing the server. */
|
||||
g_server_manager.LoopProcess();
|
||||
}
|
||||
|
||||
}
|
152
libraries/libstratosphere/source/scs/scs_shell.cpp
Normal file
152
libraries/libstratosphere/source/scs/scs_shell.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::scs {
|
||||
|
||||
namespace {
|
||||
|
||||
struct SocketInfo {
|
||||
u64 id;
|
||||
s32 socket;
|
||||
};
|
||||
|
||||
struct ProgramInfo {
|
||||
os::ProcessId process_id;
|
||||
u64 id;
|
||||
s32 socket;
|
||||
s32 info_id;
|
||||
bool _18;
|
||||
bool _19;
|
||||
bool _1A;
|
||||
};
|
||||
|
||||
constexpr inline auto MaxSocketInfo = 2;
|
||||
constexpr inline auto MaxProgramInfo = 64;
|
||||
|
||||
class SocketInfoManager {
|
||||
private:
|
||||
SocketInfo m_infos[MaxProgramInfo];
|
||||
int m_count;
|
||||
public:
|
||||
constexpr SocketInfoManager() = default;
|
||||
|
||||
void Initialize() {
|
||||
/* Clear our count. */
|
||||
m_count = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class ProgramInfoManager {
|
||||
private:
|
||||
s32 m_next_info_id;
|
||||
ProgramInfo m_infos[MaxProgramInfo];
|
||||
int m_count;
|
||||
public:
|
||||
constexpr ProgramInfoManager() = default;
|
||||
|
||||
void Initialize() {
|
||||
/* Reset our next id. */
|
||||
m_next_info_id = 1;
|
||||
|
||||
/* Clear our count. */
|
||||
m_count = 0;
|
||||
}
|
||||
};
|
||||
|
||||
alignas(os::ThreadStackAlignment) constinit u8 g_thread_stack[os::MemoryPageSize];
|
||||
constinit os::ThreadType g_thread;
|
||||
|
||||
constinit ProcessEventHandler g_common_start_handler;
|
||||
constinit ProcessEventHandler g_common_exit_handler;
|
||||
constinit ProcessEventHandler g_common_jit_debug_handler;
|
||||
|
||||
constinit SocketInfoManager g_socket_info_manager;
|
||||
constinit ProgramInfoManager g_program_info_manager;
|
||||
|
||||
void EventHandlerThread(void *) {
|
||||
/* TODO */
|
||||
AMS_ABORT("scs::EventHandlerThread");
|
||||
}
|
||||
|
||||
void StartEventHandlerThread() {
|
||||
/* Create the handler thread. */
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_thread), EventHandlerThread, nullptr, g_thread_stack, sizeof(g_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(scs, ShellEventHandler)));
|
||||
|
||||
/* Set the handler thread's name. */
|
||||
os::SetThreadNamePointer(std::addressof(g_thread), AMS_GET_SYSTEM_THREAD_NAME(scs, ShellEventHandler));
|
||||
|
||||
/* Start the handler thread. */
|
||||
os::StartThread(std::addressof(g_thread));
|
||||
}
|
||||
|
||||
Result PrepareToLaunchProgram(ncm::ProgramId program_id, const void *args, size_t args_size) {
|
||||
/* Set the arguments. */
|
||||
R_TRY_CATCH(ldr::SetProgramArgument(program_id, args, args_size)) {
|
||||
R_CATCH(ldr::ResultTooManyArguments) {
|
||||
/* There are too many arguments already registered. Flush the arguments queue. */
|
||||
R_TRY(ldr::FlushArguments());
|
||||
|
||||
/* Try again. */
|
||||
R_TRY(ldr::SetProgramArgument(program_id, args, args_size));
|
||||
}
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void FlushProgramArgument(ncm::ProgramId program_id) {
|
||||
/* Ensure there are no arguments for the program. */
|
||||
ldr::SetProgramArgument(program_id, "", 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InitializeShell() {
|
||||
/* Initialize our managers. */
|
||||
g_socket_info_manager.Initialize();
|
||||
g_program_info_manager.Initialize();
|
||||
|
||||
/* Start our event handler. */
|
||||
StartEventHandlerThread();
|
||||
}
|
||||
|
||||
void RegisterCommonProcessEventHandler(ProcessEventHandler on_start, ProcessEventHandler on_exit, ProcessEventHandler on_jit_debug) {
|
||||
g_common_start_handler = on_start;
|
||||
g_common_exit_handler = on_exit;
|
||||
g_common_jit_debug_handler = 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) {
|
||||
/* Set up the arguments. */
|
||||
PrepareToLaunchProgram(program_id, args, args_size);
|
||||
|
||||
/* Ensure arguments are managed correctly. */
|
||||
ON_SCOPE_EXIT { FlushProgramArgument(program_id); };
|
||||
|
||||
/* Launch the program. */
|
||||
const ncm::ProgramLocation loc = ncm::ProgramLocation::Make(program_id, ncm::StorageId::BuiltInSystem);
|
||||
R_TRY(pgl::LaunchProgram(out, loc, process_flags | pm::LaunchFlags_SignalOnExit, 0));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result SubscribeProcessEvent(s32 socket, bool is_register, u64 id);
|
||||
|
||||
}
|
41
libraries/libstratosphere/source/scs/scs_shell_server.cpp
Normal file
41
libraries/libstratosphere/source/scs/scs_shell_server.cpp
Normal 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::scs {
|
||||
|
||||
void ShellServer::Initialize(const char *port_name, void *stack, size_t stack_size, CommandProcessor *command_processor) {
|
||||
/* Set our variables. */
|
||||
m_command_processor = command_processor;
|
||||
std::strcpy(m_port_name.name, port_name);
|
||||
|
||||
/* Create our thread. */
|
||||
R_ABORT_UNLESS(os::CreateThread(std::addressof(m_thread), ThreadEntry, this, stack, stack_size, AMS_GET_SYSTEM_THREAD_PRIORITY(scs, ShellServer)));
|
||||
|
||||
/* Set our thread's name. */
|
||||
os::SetThreadNamePointer(std::addressof(m_thread), AMS_GET_SYSTEM_THREAD_NAME(scs, ShellServer));
|
||||
}
|
||||
|
||||
void ShellServer::Start() {
|
||||
os::StartThread(std::addressof(m_thread));
|
||||
}
|
||||
|
||||
void ShellServer::DoShellServer() {
|
||||
/* TODO */
|
||||
AMS_ABORT("ShellServer::DoShellServer");
|
||||
}
|
||||
|
||||
}
|
52
libraries/libstratosphere/source/scs/scs_tenv.cpp
Normal file
52
libraries/libstratosphere/source/scs/scs_tenv.cpp
Normal 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::scs {
|
||||
|
||||
namespace {
|
||||
|
||||
alignas(os::MemoryPageSize) constinit u8 g_tenv_heap_storage[48_KB];
|
||||
constinit lmem::HeapHandle g_tenv_heap_handle = nullptr;
|
||||
constinit os::SdkMutex g_mutex;
|
||||
|
||||
void InitializeExpHeap() {
|
||||
std::scoped_lock lk(g_mutex);
|
||||
g_tenv_heap_handle = lmem::CreateExpHeap(g_tenv_heap_storage, sizeof(g_tenv_heap_storage), lmem::CreateOption_None);
|
||||
}
|
||||
|
||||
void *Allocate(size_t size) {
|
||||
std::scoped_lock lk(g_mutex);
|
||||
void *mem = lmem::AllocateFromExpHeap(g_tenv_heap_handle, size);
|
||||
return mem;
|
||||
}
|
||||
|
||||
void Deallocate(void *p, size_t size) {
|
||||
std::scoped_lock lk(g_mutex);
|
||||
lmem::FreeToExpHeap(g_tenv_heap_handle, p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InitializeTenvServiceManager() {
|
||||
/* Initialize the tenv heap. */
|
||||
InitializeExpHeap();
|
||||
|
||||
/* Initialize the tenv library. */
|
||||
htc::tenv::Initialize(Allocate, Deallocate);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@
|
|||
#include <vapours/results/cal_results.hpp>
|
||||
#include <vapours/results/capsrv_results.hpp>
|
||||
#include <vapours/results/creport_results.hpp>
|
||||
#include <vapours/results/cs_results.hpp>
|
||||
#include <vapours/results/dd_results.hpp>
|
||||
#include <vapours/results/ddsf_results.hpp>
|
||||
#include <vapours/results/debug_results.hpp>
|
||||
|
@ -55,6 +56,7 @@
|
|||
#include <vapours/results/psc_results.hpp>
|
||||
#include <vapours/results/pwm_results.hpp>
|
||||
#include <vapours/results/ro_results.hpp>
|
||||
#include <vapours/results/scs_results.hpp>
|
||||
#include <vapours/results/sdmmc_results.hpp>
|
||||
#include <vapours/results/settings_results.hpp>
|
||||
#include <vapours/results/sf_results.hpp>
|
||||
|
|
28
libraries/libvapours/include/vapours/results/cs_results.hpp
Normal file
28
libraries/libvapours/include/vapours/results/cs_results.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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/results/results_common.hpp>
|
||||
|
||||
namespace ams::cs {
|
||||
|
||||
R_DEFINE_NAMESPACE_RESULT_MODULE(204);
|
||||
|
||||
R_DEFINE_ERROR_RESULT(UnknownCommand, 2);
|
||||
R_DEFINE_ERROR_RESULT(OutOfResource, 4);
|
||||
R_DEFINE_ERROR_RESULT(NoSocket, 7);
|
||||
|
||||
}
|
28
libraries/libvapours/include/vapours/results/scs_results.hpp
Normal file
28
libraries/libvapours/include/vapours/results/scs_results.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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/results/results_common.hpp>
|
||||
|
||||
namespace ams::scs {
|
||||
|
||||
R_DEFINE_NAMESPACE_RESULT_MODULE(204);
|
||||
|
||||
R_DEFINE_ERROR_RESULT(UnknownCommand, 2);
|
||||
R_DEFINE_ERROR_RESULT(OutOfResource, 4);
|
||||
R_DEFINE_ERROR_RESULT(NoSocket, 7);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue