sf: convert loader to new format

This commit is contained in:
Michael Scire 2020-07-06 20:00:07 -07:00
parent dd432f33e8
commit fb3b29516c
6 changed files with 124 additions and 95 deletions

View file

@ -19,3 +19,6 @@
#include <stratosphere/ldr/ldr_types.hpp>
#include <stratosphere/ldr/ldr_shell_api.hpp>
#include <stratosphere/ldr/ldr_pm_api.hpp>
#include <stratosphere/ldr/impl/ldr_process_manager_interface.hpp>
#include <stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp>
#include <stratosphere/ldr/impl/ldr_shell_interface.hpp>

View file

@ -0,0 +1,32 @@
/*
* 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/ldr/ldr_types.hpp>
#include <stratosphere/sf.hpp>
namespace ams::ldr::impl {
#define AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, FlushArguments, ()) \
AMS_SF_METHOD_INFO(C, H, 2, Result, GetProcessModuleInfo, (sf::Out<u32> count, const sf::OutPointerArray<ModuleInfo> &out, os::ProcessId process_id)) \
AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out<bool> out, ncm::ProgramId program_id))
AMS_SF_DEFINE_INTERFACE(IDebugMonitorInterface, AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO)
}

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/ldr/ldr_types.hpp>
#include <stratosphere/sf.hpp>
namespace ams::ldr::impl {
#define AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, CreateProcess, (sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, GetProgramInfo, (sf::Out<ProgramInfo> out_program_info, const ncm::ProgramLocation &loc)) \
AMS_SF_METHOD_INFO(C, H, 2, Result, PinProgram, (sf::Out<PinId> out_id, const ncm::ProgramLocation &loc)) \
AMS_SF_METHOD_INFO(C, H, 3, Result, UnpinProgram, (PinId id)) \
AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabledProgramVerification, (bool enabled), hos::Version_10_0_0) \
AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out<bool> out, ncm::ProgramId program_id)) \
AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetProgramInfo, (sf::Out<ProgramInfo> out_program_info, sf::Out<cfg::OverrideStatus> out_status, const ncm::ProgramLocation &loc)) \
AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmospherePinProgram, (sf::Out<PinId> out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status))
AMS_SF_DEFINE_INTERFACE(IProcessManagerInterface, AMS_LDR_I_PROCESS_MANAGER_INTERFACE_INTERFACE_INFO)
}

View file

@ -0,0 +1,32 @@
/*
* 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/ldr/ldr_types.hpp>
#include <stratosphere/sf.hpp>
namespace ams::ldr::impl {
#define AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, FlushArguments, ()) \
AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereRegisterExternalCode, (sf::OutMoveHandle out, ncm::ProgramId program_id)) \
AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereUnregisterExternalCode, (ncm::ProgramId program_id))
AMS_SF_DEFINE_INTERFACE(IShellInterface, AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO)
}

View file

@ -18,101 +18,27 @@
namespace ams::ldr {
class LoaderService : public sf::IServiceObject {
protected:
class LoaderService final {
public:
/* Official commands. */
virtual Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h);
virtual Result GetProgramInfo(sf::Out<ProgramInfo> out_program_info, const ncm::ProgramLocation &loc);
virtual Result PinProgram(sf::Out<PinId> out_id, const ncm::ProgramLocation &loc);
virtual Result UnpinProgram(PinId id);
virtual Result SetProgramArguments(ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size);
virtual Result FlushArguments();
virtual Result GetProcessModuleInfo(sf::Out<u32> count, const sf::OutPointerArray<ModuleInfo> &out, os::ProcessId process_id);
virtual Result SetEnabledProgramVerification(bool enabled);
Result CreateProcess(sf::OutMoveHandle proc_h, PinId id, u32 flags, sf::CopyHandle reslimit_h);
Result GetProgramInfo(sf::Out<ProgramInfo> out_program_info, const ncm::ProgramLocation &loc);
Result PinProgram(sf::Out<PinId> out_id, const ncm::ProgramLocation &loc);
Result UnpinProgram(PinId id);
Result SetProgramArguments(ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size);
Result FlushArguments();
Result GetProcessModuleInfo(sf::Out<u32> count, const sf::OutPointerArray<ModuleInfo> &out, os::ProcessId process_id);
Result SetEnabledProgramVerification(bool enabled);
/* Atmosphere commands. */
virtual Result AtmosphereRegisterExternalCode(sf::OutMoveHandle out, ncm::ProgramId program_id);
virtual void AtmosphereUnregisterExternalCode(ncm::ProgramId program_id);
virtual void AtmosphereHasLaunchedProgram(sf::Out<bool> out, ncm::ProgramId program_id);
virtual Result AtmosphereGetProgramInfo(sf::Out<ProgramInfo> out_program_info, sf::Out<cfg::OverrideStatus> out_status, const ncm::ProgramLocation &loc);
virtual Result AtmospherePinProgram(sf::Out<PinId> out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status);
Result AtmosphereRegisterExternalCode(sf::OutMoveHandle out, ncm::ProgramId program_id);
void AtmosphereUnregisterExternalCode(ncm::ProgramId program_id);
void AtmosphereHasLaunchedProgram(sf::Out<bool> out, ncm::ProgramId program_id);
Result AtmosphereGetProgramInfo(sf::Out<ProgramInfo> out_program_info, sf::Out<cfg::OverrideStatus> out_status, const ncm::ProgramLocation &loc);
Result AtmospherePinProgram(sf::Out<PinId> out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status);
};
namespace pm {
class ProcessManagerInterface final : public LoaderService {
protected:
enum class CommandId {
CreateProcess = 0,
GetProgramInfo = 1,
PinProgram = 2,
UnpinProgram = 3,
SetEnabledProgramVerification = 4,
AtmosphereHasLaunchedProgram = 65000,
AtmosphereGetProgramInfo = 65001,
AtmospherePinProgram = 65002,
};
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(CreateProcess),
MAKE_SERVICE_COMMAND_META(GetProgramInfo),
MAKE_SERVICE_COMMAND_META(PinProgram),
MAKE_SERVICE_COMMAND_META(UnpinProgram),
MAKE_SERVICE_COMMAND_META(SetEnabledProgramVerification, hos::Version_10_0_0),
MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram),
MAKE_SERVICE_COMMAND_META(AtmosphereGetProgramInfo),
MAKE_SERVICE_COMMAND_META(AtmospherePinProgram),
};
};
}
namespace dmnt {
class DebugMonitorInterface final : public LoaderService {
protected:
enum class CommandId {
SetProgramArguments = 0,
FlushArguments = 1,
GetProcessModuleInfo = 2,
AtmosphereHasLaunchedProgram = 65000,
};
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(SetProgramArguments),
MAKE_SERVICE_COMMAND_META(FlushArguments),
MAKE_SERVICE_COMMAND_META(GetProcessModuleInfo),
MAKE_SERVICE_COMMAND_META(AtmosphereHasLaunchedProgram),
};
};
}
namespace shell {
class ShellInterface final : public LoaderService {
protected:
enum class CommandId {
SetProgramArguments = 0,
FlushArguments = 1,
AtmosphereRegisterExternalCode = 65000,
AtmosphereUnregisterExternalCode = 65001,
};
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(SetProgramArguments),
MAKE_SERVICE_COMMAND_META(FlushArguments),
MAKE_SERVICE_COMMAND_META(AtmosphereRegisterExternalCode),
MAKE_SERVICE_COMMAND_META(AtmosphereUnregisterExternalCode),
};
};
}
static_assert(ams::ldr::impl::IsIProcessManagerInterface<LoaderService>);
static_assert(ams::ldr::impl::IsIDebugMonitorInterface<LoaderService>);
static_assert(ams::ldr::impl::IsIShellInterface<LoaderService>);
}

View file

@ -129,9 +129,9 @@ int main(int argc, char **argv)
ldr::SetDevelopmentForAcidSignatureCheck(spl::IsDevelopment());
/* Add services to manager. */
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::pm::ProcessManagerInterface>(ProcessManagerServiceName, ProcessManagerMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::shell::ShellInterface>(ShellServiceName, ShellMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::dmnt::DebugMonitorInterface>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::impl::IProcessManagerInterface, ldr::LoaderService>(ProcessManagerServiceName, ProcessManagerMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::impl::IShellInterface, ldr::LoaderService>(ShellServiceName, ShellMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::impl::IDebugMonitorInterface, ldr::LoaderService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
/* Loop forever, servicing our services. */
g_server_manager.LoopProcess();