sf: Change interface definition methodology (#1074)

* sf: Begin experimenting with new interface declaration format

* sf: convert fs interfaces to new format

* sf: finish conversion of libstrat to new definitions

* sf: convert loader to new format

* sf: convert spl to new format

* sf: update ncm for new format

* sf: convert pm to new format

* sf: convert ro/sm to new format

* sf: update fatal for new format

* sf: support building dmnt under new scheme

* sf: update ams.mitm for new format

* sf: correct invocation def for pointer holder

* fs: correct 10.x+ user bindings for Get*SpaceSize
This commit is contained in:
SciresM 2020-07-07 17:07:23 -07:00 committed by GitHub
parent 94eb2195d3
commit 9fde97cfdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
190 changed files with 3220 additions and 3172 deletions

View file

@ -413,7 +413,7 @@ namespace ams::ro::impl {
}
/* Service implementations. */
Result LoadNrr(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) {
Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ABORT_UNLESS(context != nullptr);
@ -454,7 +454,7 @@ namespace ams::ro::impl {
return ResultSuccess();
}
Result UnloadNrr(size_t context_id, u64 nrr_address) {
Result UnregisterModuleInfo(size_t context_id, u64 nrr_address) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ABORT_UNLESS(context != nullptr);
@ -476,7 +476,7 @@ namespace ams::ro::impl {
return UnmapNrr(context->process_handle, nrr_backup.mapped_header, nrr_backup.nrr_heap_address, nrr_backup.nrr_heap_size, nrr_backup.mapped_code_address);
}
Result LoadNro(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
Result MapManualLoadModuleMemory(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ABORT_UNLESS(context != nullptr);
@ -522,7 +522,7 @@ namespace ams::ro::impl {
return ResultSuccess();
}
Result UnloadNro(size_t context_id, u64 nro_address) {
Result UnmapManualLoadModuleMemory(size_t context_id, u64 nro_address) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ABORT_UNLESS(context != nullptr);

View file

@ -35,10 +35,10 @@ namespace ams::ro::impl {
void UnregisterProcess(size_t context_id);
/* Service implementations. */
Result LoadNrr(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type);
Result UnloadNrr(size_t context_id, u64 nrr_address);
Result LoadNro(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size);
Result UnloadNro(size_t context_id, u64 nro_address);
Result RegisterModuleInfo(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type);
Result UnregisterModuleInfo(size_t context_id, u64 nrr_address);
Result MapManualLoadModuleMemory(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size);
Result UnmapManualLoadModuleMemory(size_t context_id, u64 nro_address);
/* Debug service implementations. */
Result GetProcessModuleInfo(u32 *out_count, LoaderModuleInfo *out_infos, size_t max_out_count, os::ProcessId process_id);

View file

@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "ro_debug_monitor.hpp"
#include "ro_debug_monitor_service.hpp"
#include "impl/ro_service_impl.hpp"
namespace ams::ro {

View file

@ -18,18 +18,10 @@
namespace ams::ro {
class DebugMonitorService final : public sf::IServiceObject {
protected:
enum class CommandId {
GetProcessModuleInfo = 0,
};
private:
/* Actual commands. */
Result GetProcessModuleInfo(sf::Out<u32> out_count, const sf::OutArray<LoaderModuleInfo> &out_infos, os::ProcessId process_id);
class DebugMonitorService final {
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(GetProcessModuleInfo),
};
Result GetProcessModuleInfo(sf::Out<u32> out_count, const sf::OutArray<LoaderModuleInfo> &out_infos, os::ProcessId process_id);
};
static_assert(ro::impl::IsIDebugMonitorInterface<DebugMonitorService>);
}

View file

@ -14,8 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "ro_debug_monitor.hpp"
#include "ro_service.hpp"
#include "ro_debug_monitor_service.hpp"
#include "ro_ro_service.hpp"
extern "C" {
extern u32 __start__;
@ -84,10 +84,6 @@ void __appExit(void) {
setsysExit();
}
/* Helpers to create RO objects. */
static constexpr auto MakeRoServiceForSelf = []() { return std::make_shared<ro::Service>(ro::ModuleType::ForSelf); };
static constexpr auto MakeRoServiceForOthers = []() { return std::make_shared<ro::Service>(ro::ModuleType::ForOthers); };
namespace {
/* ldr:ro, ro:dmnt, ro:1. */
@ -122,11 +118,11 @@ int main(int argc, char **argv)
}
/* Create services. */
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::impl::IDebugMonitorInterface, ro::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForSelf>(ForSelfServiceName, ForSelfMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::impl::IRoInterface, ro::RoServiceForSelf>(ForSelfServiceName, ForSelfMaxSessions)));
if (hos::GetVersion() >= hos::Version_7_0_0) {
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForOthers>(ForOthersServiceName, ForOthersMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::impl::IRoInterface, ro::RoServiceForOthers>(ForOthersServiceName, ForOthersMaxSessions)));
}
/* Loop forever, servicing our services. */

View file

@ -0,0 +1,67 @@
/*
* 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 "ro_ro_service.hpp"
#include "impl/ro_service_impl.hpp"
namespace ams::ro {
void SetDevelopmentHardware(bool is_development_hardware) {
impl::SetDevelopmentHardware(is_development_hardware);
}
void SetDevelopmentFunctionEnabled(bool is_development_function_enabled) {
impl::SetDevelopmentFunctionEnabled(is_development_function_enabled);
}
RoService::RoService(ModuleType t) : context_id(impl::InvalidContextId), type(t) {
/* ... */
}
RoService::~RoService() {
impl::UnregisterProcess(this->context_id);
}
Result RoService::MapManualLoadModuleMemory(sf::Out<u64> load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::MapManualLoadModuleMemory(load_address.GetPointer(), this->context_id, nro_address, nro_size, bss_address, bss_size);
}
Result RoService::UnmapManualLoadModuleMemory(const sf::ClientProcessId &client_pid, u64 nro_address) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::UnmapManualLoadModuleMemory(this->context_id, nro_address);
}
Result RoService::RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::RegisterModuleInfo(this->context_id, svc::InvalidHandle, nrr_address, nrr_size, ModuleType::ForSelf, true);
}
Result RoService::UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::UnregisterModuleInfo(this->context_id, nrr_address);
}
Result RoService::RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h) {
return impl::RegisterProcess(std::addressof(this->context_id), process_h.GetValue(), client_pid.GetValue());
}
Result RoService::RegisterModuleInfoEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::RegisterModuleInfo(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->type, this->type == ModuleType::ForOthers);
}
}

View file

@ -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/>.
*/
#pragma once
#include <stratosphere.hpp>
namespace ams::ro {
/* Access utilities. */
void SetDevelopmentHardware(bool is_development_hardware);
void SetDevelopmentFunctionEnabled(bool is_development_function_enabled);
class RoService {
private:
size_t context_id;
ModuleType type;
protected:
explicit RoService(ModuleType t);
public:
virtual ~RoService();
public:
/* Actual commands. */
Result MapManualLoadModuleMemory(sf::Out<u64> out_load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size);
Result UnmapManualLoadModuleMemory(const sf::ClientProcessId &client_pid, u64 nro_address);
Result RegisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size);
Result UnregisterModuleInfo(const sf::ClientProcessId &client_pid, u64 nrr_address);
Result RegisterProcessHandle(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h);
Result RegisterModuleInfoEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h);
};
static_assert(ro::impl::IsIRoInterface<RoService>);
class RoServiceForSelf final : public RoService {
public:
RoServiceForSelf() : RoService(ro::ModuleType::ForSelf) { /* ... */ }
};
/* TODO: This is really JitPlugin... */
class RoServiceForOthers final : public RoService {
public:
RoServiceForOthers() : RoService(ro::ModuleType::ForOthers) { /* ... */ }
};
}

View file

@ -1,67 +0,0 @@
/*
* 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 "ro_service.hpp"
#include "impl/ro_service_impl.hpp"
namespace ams::ro {
void SetDevelopmentHardware(bool is_development_hardware) {
impl::SetDevelopmentHardware(is_development_hardware);
}
void SetDevelopmentFunctionEnabled(bool is_development_function_enabled) {
impl::SetDevelopmentFunctionEnabled(is_development_function_enabled);
}
Service::Service(ModuleType t) : context_id(impl::InvalidContextId), type(t) {
/* ... */
}
Service::~Service() {
impl::UnregisterProcess(this->context_id);
}
Result Service::LoadNro(sf::Out<u64> load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::LoadNro(load_address.GetPointer(), this->context_id, nro_address, nro_size, bss_address, bss_size);
}
Result Service::UnloadNro(const sf::ClientProcessId &client_pid, u64 nro_address) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::UnloadNro(this->context_id, nro_address);
}
Result Service::LoadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::LoadNrr(this->context_id, INVALID_HANDLE, nrr_address, nrr_size, ModuleType::ForSelf, true);
}
Result Service::UnloadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::UnloadNrr(this->context_id, nrr_address);
}
Result Service::Initialize(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h) {
return impl::RegisterProcess(&this->context_id, process_h.GetValue(), client_pid.GetValue());
}
Result Service::LoadNrrEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h) {
R_TRY(impl::ValidateProcess(this->context_id, client_pid.GetValue()));
return impl::LoadNrr(this->context_id, process_h.GetValue(), nrr_address, nrr_size, this->type, this->type == ModuleType::ForOthers);
}
}

View file

@ -1,62 +0,0 @@
/*
* 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::ro {
/* Access utilities. */
void SetDevelopmentHardware(bool is_development_hardware);
void SetDevelopmentFunctionEnabled(bool is_development_function_enabled);
class Service final : public sf::IServiceObject {
protected:
enum class CommandId {
LoadNro = 0,
UnloadNro = 1,
LoadNrr = 2,
UnloadNrr = 3,
Initialize = 4,
LoadNrrEx = 10,
};
private:
size_t context_id;
ModuleType type;
public:
explicit Service(ModuleType t);
virtual ~Service();
private:
/* Actual commands. */
Result LoadNro(sf::Out<u64> out_load_address, const sf::ClientProcessId &client_pid, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size);
Result UnloadNro(const sf::ClientProcessId &client_pid, u64 nro_address);
Result LoadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size);
Result UnloadNrr(const sf::ClientProcessId &client_pid, u64 nrr_address);
Result Initialize(const sf::ClientProcessId &client_pid, sf::CopyHandle process_h);
Result LoadNrrEx(const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h);
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(LoadNro),
MAKE_SERVICE_COMMAND_META(UnloadNro),
MAKE_SERVICE_COMMAND_META(LoadNrr),
MAKE_SERVICE_COMMAND_META(UnloadNrr),
MAKE_SERVICE_COMMAND_META(Initialize),
MAKE_SERVICE_COMMAND_META(LoadNrrEx, hos::Version_7_0_0),
};
};
}