Revert "hoc-clk: add live vdd2, live boost clock and basic pwm dimming"
This reverts commit 15b7df8ef1.
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/sf/sf_common.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_service_object_holder.hpp>
|
||||
|
||||
namespace ams::sf::cmif {
|
||||
|
||||
struct DomainObjectId {
|
||||
u32 value;
|
||||
|
||||
constexpr void SetValue(u32 new_value) { this->value = new_value; }
|
||||
};
|
||||
|
||||
static_assert(std::is_trivial<DomainObjectId>::value && sizeof(DomainObjectId) == sizeof(u32), "DomainObjectId");
|
||||
|
||||
inline constexpr bool operator==(const DomainObjectId &lhs, const DomainObjectId &rhs) {
|
||||
return lhs.value == rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator!=(const DomainObjectId &lhs, const DomainObjectId &rhs) {
|
||||
return lhs.value != rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator<(const DomainObjectId &lhs, const DomainObjectId &rhs) {
|
||||
return lhs.value < rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator<=(const DomainObjectId &lhs, const DomainObjectId &rhs) {
|
||||
return lhs.value <= rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator>(const DomainObjectId &lhs, const DomainObjectId &rhs) {
|
||||
return lhs.value > rhs.value;
|
||||
}
|
||||
|
||||
inline constexpr bool operator>=(const DomainObjectId &lhs, const DomainObjectId &rhs) {
|
||||
return lhs.value >= rhs.value;
|
||||
}
|
||||
|
||||
constexpr inline const DomainObjectId InvalidDomainObjectId = { .value = 0 };
|
||||
|
||||
class ServerDomainBase {
|
||||
public:
|
||||
virtual Result ReserveIds(DomainObjectId *out_ids, size_t count) = 0;
|
||||
virtual void ReserveSpecificIds(const DomainObjectId *ids, size_t count) = 0;
|
||||
virtual void UnreserveIds(const DomainObjectId *ids, size_t count) = 0;
|
||||
virtual void RegisterObject(DomainObjectId id, ServiceObjectHolder &&obj) = 0;
|
||||
|
||||
virtual ServiceObjectHolder UnregisterObject(DomainObjectId id) = 0;
|
||||
virtual ServiceObjectHolder GetObject(DomainObjectId id) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/sf/sf_common.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_domain_api.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp>
|
||||
#include <stratosphere/sf/impl/sf_service_object_impl.hpp>
|
||||
|
||||
namespace ams::sf::cmif {
|
||||
|
||||
class ServerDomainManager {
|
||||
NON_COPYABLE(ServerDomainManager);
|
||||
NON_MOVEABLE(ServerDomainManager);
|
||||
private:
|
||||
class Domain;
|
||||
|
||||
struct Entry {
|
||||
NON_COPYABLE(Entry);
|
||||
NON_MOVEABLE(Entry);
|
||||
|
||||
util::IntrusiveListNode free_list_node;
|
||||
util::IntrusiveListNode domain_list_node;
|
||||
Domain *owner;
|
||||
ServiceObjectHolder object;
|
||||
|
||||
explicit Entry() : owner(nullptr) { /* ... */ }
|
||||
};
|
||||
|
||||
class Domain final : public DomainServiceObject, private sf::impl::ServiceObjectImplBase2 {
|
||||
NON_COPYABLE(Domain);
|
||||
NON_MOVEABLE(Domain);
|
||||
private:
|
||||
using EntryList = typename util::IntrusiveListMemberTraits<&Entry::domain_list_node>::ListType;
|
||||
private:
|
||||
ServerDomainManager *m_manager;
|
||||
EntryList m_entries;
|
||||
public:
|
||||
explicit Domain(ServerDomainManager *m) : m_manager(m) { /* ... */ }
|
||||
~Domain();
|
||||
|
||||
void DisposeImpl();
|
||||
|
||||
virtual void AddReference() override {
|
||||
ServiceObjectImplBase2::AddReferenceImpl();
|
||||
}
|
||||
|
||||
virtual void Release() override {
|
||||
if (ServiceObjectImplBase2::ReleaseImpl()) {
|
||||
this->DisposeImpl();
|
||||
}
|
||||
}
|
||||
|
||||
virtual ServerDomainBase *GetServerDomain() override final {
|
||||
return static_cast<ServerDomainBase *>(this);
|
||||
}
|
||||
|
||||
virtual Result ReserveIds(DomainObjectId *out_ids, size_t count) override final;
|
||||
virtual void ReserveSpecificIds(const DomainObjectId *ids, size_t count) override final;
|
||||
virtual void UnreserveIds(const DomainObjectId *ids, size_t count) override final;
|
||||
virtual void RegisterObject(DomainObjectId id, ServiceObjectHolder &&obj) override final;
|
||||
|
||||
virtual ServiceObjectHolder UnregisterObject(DomainObjectId id) override final;
|
||||
virtual ServiceObjectHolder GetObject(DomainObjectId id) override final;
|
||||
};
|
||||
public:
|
||||
using DomainEntryStorage = util::TypedStorage<Entry>;
|
||||
using DomainStorage = util::TypedStorage<Domain>;
|
||||
private:
|
||||
class EntryManager {
|
||||
private:
|
||||
using EntryList = typename util::IntrusiveListMemberTraits<&Entry::free_list_node>::ListType;
|
||||
private:
|
||||
os::SdkMutex m_lock;
|
||||
EntryList m_free_list;
|
||||
Entry *m_entries;
|
||||
size_t m_num_entries;
|
||||
public:
|
||||
EntryManager(DomainEntryStorage *entry_storage, size_t entry_count);
|
||||
~EntryManager();
|
||||
Entry *AllocateEntry();
|
||||
void FreeEntry(Entry *);
|
||||
|
||||
void AllocateSpecificEntries(const DomainObjectId *ids, size_t count);
|
||||
|
||||
inline DomainObjectId GetId(Entry *e) {
|
||||
const size_t index = e - m_entries;
|
||||
AMS_ABORT_UNLESS(index < m_num_entries);
|
||||
return DomainObjectId{ u32(index + 1) };
|
||||
}
|
||||
|
||||
inline Entry *GetEntry(DomainObjectId id) {
|
||||
if (id == InvalidDomainObjectId) {
|
||||
return nullptr;
|
||||
}
|
||||
const size_t index = id.value - 1;
|
||||
if (!(index < m_num_entries)) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_entries + index;
|
||||
}
|
||||
};
|
||||
private:
|
||||
os::SdkMutex m_entry_owner_lock;
|
||||
EntryManager m_entry_manager;
|
||||
private:
|
||||
virtual void *AllocateDomain() = 0;
|
||||
virtual void FreeDomain(void *) = 0;
|
||||
protected:
|
||||
ServerDomainManager(DomainEntryStorage *entry_storage, size_t entry_count) : m_entry_owner_lock(), m_entry_manager(entry_storage, entry_count) { /* ... */ }
|
||||
|
||||
inline DomainServiceObject *AllocateDomainServiceObject() {
|
||||
void *storage = this->AllocateDomain();
|
||||
if (storage == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::construct_at(static_cast<Domain *>(storage), this);
|
||||
}
|
||||
public:
|
||||
static void DestroyDomainServiceObject(DomainServiceObject *obj) {
|
||||
static_cast<Domain *>(obj)->DisposeImpl();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/sf/sf_mitm_config.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_domain_api.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp>
|
||||
|
||||
namespace ams::sf::cmif {
|
||||
|
||||
class DomainServiceObjectDispatchTable : public impl::ServiceDispatchTableBase {
|
||||
private:
|
||||
Result ProcessMessageImpl(ServiceDispatchContext &ctx, ServerDomainBase *domain, const cmif::PointerAndSize &in_raw_data) const;
|
||||
Result ProcessMessageForMitmImpl(ServiceDispatchContext &ctx, ServerDomainBase *domain, const cmif::PointerAndSize &in_raw_data) const;
|
||||
public:
|
||||
Result ProcessMessage(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const;
|
||||
Result ProcessMessageForMitm(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const;
|
||||
};
|
||||
|
||||
|
||||
class DomainServiceObjectProcessor : public ServerMessageProcessor {
|
||||
private:
|
||||
ServerMessageProcessor *m_impl_processor;
|
||||
ServerDomainBase *m_domain;
|
||||
DomainObjectId *m_in_object_ids;
|
||||
DomainObjectId *m_out_object_ids;
|
||||
size_t m_num_in_objects;
|
||||
ServerMessageRuntimeMetadata m_impl_metadata;
|
||||
public:
|
||||
DomainServiceObjectProcessor(ServerDomainBase *d, DomainObjectId *in_obj_ids, size_t num_in_objs) : m_domain(d), m_in_object_ids(in_obj_ids), m_num_in_objects(num_in_objs) {
|
||||
AMS_ABORT_UNLESS(m_domain != nullptr);
|
||||
AMS_ABORT_UNLESS(m_in_object_ids != nullptr);
|
||||
m_impl_processor = nullptr;
|
||||
m_out_object_ids = nullptr;
|
||||
m_impl_metadata = {};
|
||||
}
|
||||
|
||||
constexpr size_t GetInObjectCount() const {
|
||||
return m_num_in_objects;
|
||||
}
|
||||
|
||||
constexpr size_t GetOutObjectCount() const {
|
||||
return m_impl_metadata.GetOutObjectCount();
|
||||
}
|
||||
|
||||
constexpr size_t GetImplOutHeadersSize() const {
|
||||
return m_impl_metadata.GetOutHeadersSize();
|
||||
}
|
||||
|
||||
constexpr size_t GetImplOutDataTotalSize() const {
|
||||
return m_impl_metadata.GetUnalignedOutDataSize() + m_impl_metadata.GetOutHeadersSize();
|
||||
}
|
||||
public:
|
||||
/* Used to enabled templated message processors. */
|
||||
virtual void SetImplementationProcessor(ServerMessageProcessor *impl) override final {
|
||||
if (m_impl_processor == nullptr) {
|
||||
m_impl_processor = impl;
|
||||
} else {
|
||||
m_impl_processor->SetImplementationProcessor(impl);
|
||||
}
|
||||
|
||||
m_impl_metadata = m_impl_processor->GetRuntimeMetadata();
|
||||
}
|
||||
|
||||
virtual const ServerMessageRuntimeMetadata GetRuntimeMetadata() const override final {
|
||||
const auto runtime_metadata = m_impl_processor->GetRuntimeMetadata();
|
||||
|
||||
return ServerMessageRuntimeMetadata {
|
||||
.in_data_size = static_cast<u16>(runtime_metadata.GetInDataSize() + runtime_metadata.GetInObjectCount() * sizeof(DomainObjectId)),
|
||||
.unaligned_out_data_size = static_cast<u16>(runtime_metadata.GetOutDataSize() + runtime_metadata.GetOutObjectCount() * sizeof(DomainObjectId)),
|
||||
.in_headers_size = static_cast<u8>(runtime_metadata.GetInHeadersSize() + sizeof(CmifDomainInHeader)),
|
||||
.out_headers_size = static_cast<u8>(runtime_metadata.GetOutHeadersSize() + sizeof(CmifDomainOutHeader)),
|
||||
.in_object_count = 0,
|
||||
.out_object_count = 0,
|
||||
};
|
||||
}
|
||||
|
||||
virtual Result PrepareForProcess(const ServiceDispatchContext &ctx, const ServerMessageRuntimeMetadata runtime_metadata) const override final;
|
||||
virtual Result GetInObjects(ServiceObjectHolder *in_objects) const override final;
|
||||
virtual HipcRequest PrepareForReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const ServerMessageRuntimeMetadata runtime_metadata) override final;
|
||||
virtual void PrepareForErrorReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const ServerMessageRuntimeMetadata runtime_metadata) override final;
|
||||
virtual void SetOutObjects(const cmif::ServiceDispatchContext &ctx, const HipcRequest &response, ServiceObjectHolder *out_objects, DomainObjectId *ids) override final;
|
||||
};
|
||||
|
||||
class DomainServiceObject : public IServiceObject, public ServerDomainBase {
|
||||
friend class DomainServiceObjectDispatchTable;
|
||||
public:
|
||||
static constexpr inline DomainServiceObjectDispatchTable s_CmifServiceDispatchTable{};
|
||||
private:
|
||||
virtual ServerDomainBase *GetServerDomain() = 0;
|
||||
};
|
||||
|
||||
class MitmDomainServiceObject : public DomainServiceObject{};
|
||||
|
||||
static_assert(sizeof(DomainServiceObject) == sizeof(MitmDomainServiceObject));
|
||||
|
||||
template<>
|
||||
struct ServiceDispatchTraits<DomainServiceObject> {
|
||||
static_assert(std::is_base_of<sf::IServiceObject, DomainServiceObject>::value, "DomainServiceObject must derive from sf::IServiceObject");
|
||||
#if AMS_SF_MITM_SUPPORTED
|
||||
static_assert(!std::is_base_of<sf::IMitmServiceObject, DomainServiceObject>::value, "DomainServiceObject must not derive from sf::IMitmServiceObject");
|
||||
#endif
|
||||
using ProcessHandlerType = decltype(ServiceDispatchMeta::ProcessHandler);
|
||||
|
||||
using DispatchTableType = DomainServiceObjectDispatchTable;
|
||||
static constexpr ProcessHandlerType ProcessHandlerImpl = &impl::ServiceDispatchTableBase::ProcessMessage<DispatchTableType>;
|
||||
|
||||
static constexpr inline ServiceDispatchMeta Meta{std::addressof(DomainServiceObject::s_CmifServiceDispatchTable), ProcessHandlerImpl};
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ServiceDispatchTraits<MitmDomainServiceObject> {
|
||||
static_assert(std::is_base_of<DomainServiceObject, MitmDomainServiceObject>::value, "MitmDomainServiceObject must derive from DomainServiceObject");
|
||||
using ProcessHandlerType = decltype(ServiceDispatchMeta::ProcessHandler);
|
||||
|
||||
using DispatchTableType = DomainServiceObjectDispatchTable;
|
||||
static constexpr ProcessHandlerType ProcessHandlerImpl = &impl::ServiceDispatchTableBase::ProcessMessageForMitm<DispatchTableType>;
|
||||
|
||||
static constexpr inline ServiceDispatchMeta Meta{std::addressof(DomainServiceObject::s_CmifServiceDispatchTable), ProcessHandlerImpl};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/sf/sf_common.hpp>
|
||||
|
||||
namespace ams::sf::cmif {
|
||||
|
||||
using InlineContext = u32;
|
||||
|
||||
InlineContext GetInlineContext();
|
||||
InlineContext SetInlineContext(InlineContext ctx);
|
||||
|
||||
class ScopedInlineContextChanger {
|
||||
private:
|
||||
InlineContext m_prev_ctx;
|
||||
public:
|
||||
ALWAYS_INLINE explicit ScopedInlineContextChanger(InlineContext new_ctx) : m_prev_ctx(SetInlineContext(new_ctx)) { /* ... */ }
|
||||
~ScopedInlineContextChanger() { SetInlineContext(m_prev_ctx); }
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/sf/sf_common.hpp>
|
||||
|
||||
namespace ams::sf::cmif {
|
||||
|
||||
class PointerAndSize {
|
||||
private:
|
||||
uintptr_t m_pointer;
|
||||
size_t m_size;
|
||||
public:
|
||||
constexpr PointerAndSize() : m_pointer(0), m_size(0) { /* ... */ }
|
||||
constexpr PointerAndSize(uintptr_t ptr, size_t sz) : m_pointer(ptr), m_size(sz) { /* ... */ }
|
||||
PointerAndSize(void *ptr, size_t sz) : PointerAndSize(reinterpret_cast<uintptr_t>(ptr), sz) { /* ... */ }
|
||||
|
||||
void *GetPointer() const {
|
||||
return reinterpret_cast<void *>(m_pointer);
|
||||
}
|
||||
|
||||
constexpr uintptr_t GetAddress() const {
|
||||
return m_pointer;
|
||||
}
|
||||
|
||||
constexpr size_t GetSize() const {
|
||||
return m_size;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/sf/sf_service_object.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_pointer_and_size.hpp>
|
||||
|
||||
namespace ams::sf::cmif {
|
||||
|
||||
/* Forward declare ServiceDispatchContext, ServiceObjectHolder. */
|
||||
struct ServiceDispatchContext;
|
||||
class ServiceObjectHolder;
|
||||
struct DomainObjectId;
|
||||
|
||||
/* This is needed for non-templated domain message processing. */
|
||||
struct ServerMessageRuntimeMetadata {
|
||||
u16 in_data_size;
|
||||
u16 unaligned_out_data_size;
|
||||
u8 in_headers_size;
|
||||
u8 out_headers_size;
|
||||
u8 in_object_count;
|
||||
u8 out_object_count;
|
||||
|
||||
constexpr size_t GetInDataSize() const {
|
||||
return static_cast<size_t>(this->in_data_size);
|
||||
}
|
||||
|
||||
constexpr size_t GetOutDataSize() const {
|
||||
return static_cast<size_t>(util::AlignUp(this->unaligned_out_data_size, sizeof(u32)));
|
||||
}
|
||||
|
||||
constexpr size_t GetUnalignedOutDataSize() const {
|
||||
return static_cast<size_t>(this->unaligned_out_data_size);
|
||||
}
|
||||
|
||||
constexpr size_t GetInHeadersSize() const {
|
||||
return static_cast<size_t>(this->in_headers_size);
|
||||
}
|
||||
|
||||
constexpr size_t GetOutHeadersSize() const {
|
||||
return static_cast<size_t>(this->out_headers_size);
|
||||
}
|
||||
|
||||
constexpr size_t GetInObjectCount() const {
|
||||
return static_cast<size_t>(this->in_object_count);
|
||||
}
|
||||
|
||||
constexpr size_t GetOutObjectCount() const {
|
||||
return static_cast<size_t>(this->out_object_count);
|
||||
}
|
||||
|
||||
constexpr size_t GetUnfixedOutPointerSizeOffset() const {
|
||||
return this->GetInDataSize() + this->GetInHeadersSize() + 0x10 /* padding. */;
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(util::is_pod<ServerMessageRuntimeMetadata>::value, "util::is_pod<ServerMessageRuntimeMetadata>::value");
|
||||
static_assert(sizeof(ServerMessageRuntimeMetadata) == sizeof(u64), "sizeof(ServerMessageRuntimeMetadata)");
|
||||
|
||||
class ServerMessageProcessor {
|
||||
public:
|
||||
/* Used to enabled templated message processors. */
|
||||
virtual void SetImplementationProcessor(ServerMessageProcessor *impl) = 0;
|
||||
virtual const ServerMessageRuntimeMetadata GetRuntimeMetadata() const = 0;
|
||||
|
||||
virtual Result PrepareForProcess(const ServiceDispatchContext &ctx, const ServerMessageRuntimeMetadata runtime_metadata) const = 0;
|
||||
virtual Result GetInObjects(ServiceObjectHolder *in_objects) const = 0;
|
||||
virtual HipcRequest PrepareForReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const ServerMessageRuntimeMetadata runtime_metadata) = 0;
|
||||
virtual void PrepareForErrorReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const ServerMessageRuntimeMetadata runtime_metadata) = 0;
|
||||
virtual void SetOutObjects(const cmif::ServiceDispatchContext &ctx, const HipcRequest &response, ServiceObjectHolder *out_objects, DomainObjectId *ids) = 0;
|
||||
};
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/sf/sf_mitm_config.hpp>
|
||||
#include <stratosphere/sf/sf_service_object.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_pointer_and_size.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp>
|
||||
|
||||
namespace ams::sf::hipc {
|
||||
|
||||
class ServerSessionManager;
|
||||
class ServerSession;
|
||||
|
||||
}
|
||||
|
||||
namespace ams::sf::cmif {
|
||||
|
||||
class ServerMessageProcessor;
|
||||
|
||||
struct HandlesToClose {
|
||||
os::NativeHandle handles[8];
|
||||
size_t num_handles;
|
||||
};
|
||||
|
||||
struct ServiceDispatchContext {
|
||||
sf::IServiceObject *srv_obj;
|
||||
hipc::ServerSessionManager *manager;
|
||||
hipc::ServerSession *session;
|
||||
ServerMessageProcessor *processor;
|
||||
HandlesToClose *handles_to_close;
|
||||
const PointerAndSize pointer_buffer;
|
||||
const PointerAndSize in_message_buffer;
|
||||
const PointerAndSize out_message_buffer;
|
||||
const HipcParsedRequest request;
|
||||
};
|
||||
|
||||
struct ServiceCommandMeta {
|
||||
hos::Version hosver_low;
|
||||
hos::Version hosver_high;
|
||||
u32 cmd_id;
|
||||
Result (*handler)(CmifOutHeader **out_header_ptr, ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data);
|
||||
|
||||
constexpr inline bool MatchesVersion(hos::Version hosver) const {
|
||||
const bool min_valid = this->hosver_low == hos::Version_Min;
|
||||
const bool max_valid = this->hosver_high == hos::Version_Max;
|
||||
|
||||
return (min_valid || this->hosver_low <= hosver) && (max_valid || hosver <= this->hosver_high);
|
||||
}
|
||||
|
||||
constexpr inline bool Matches(u32 cmd_id, hos::Version hosver) const {
|
||||
return this->cmd_id == cmd_id && this->MatchesVersion(hosver);
|
||||
}
|
||||
|
||||
constexpr inline decltype(handler) GetHandler() const {
|
||||
return this->handler;
|
||||
}
|
||||
|
||||
constexpr inline bool operator>(const ServiceCommandMeta &rhs) const {
|
||||
if (this->cmd_id > rhs.cmd_id) {
|
||||
return true;
|
||||
} else if (this->cmd_id == rhs.cmd_id && this->hosver_low > rhs.hosver_low) {
|
||||
return true;
|
||||
} else if (this->cmd_id == rhs.cmd_id && this->hosver_low == rhs.hosver_low && this->hosver_high == rhs.hosver_high){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
static_assert(util::is_pod<ServiceCommandMeta>::value && sizeof(ServiceCommandMeta) == 0x18, "sizeof(ServiceCommandMeta)");
|
||||
|
||||
namespace impl {
|
||||
|
||||
|
||||
class ServiceDispatchTableBase {
|
||||
protected:
|
||||
Result ProcessMessageImpl(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data, const ServiceCommandMeta *entries, const size_t entry_count, u32 interface_id_for_debug) const;
|
||||
Result ProcessMessageForMitmImpl(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data, const ServiceCommandMeta *entries, const size_t entry_count, u32 interface_id_for_debug) const;
|
||||
public:
|
||||
/* CRTP. */
|
||||
template<typename T>
|
||||
Result ProcessMessage(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const {
|
||||
static_assert(std::is_base_of<ServiceDispatchTableBase, T>::value, "ServiceDispatchTableBase::Process<T>");
|
||||
R_RETURN(static_cast<const T *>(this)->ProcessMessage(ctx, in_raw_data));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Result ProcessMessageForMitm(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const {
|
||||
static_assert(std::is_base_of<ServiceDispatchTableBase, T>::value, "ServiceDispatchTableBase::ProcessForMitm<T>");
|
||||
R_RETURN(static_cast<const T *>(this)->ProcessMessageForMitm(ctx, in_raw_data));
|
||||
}
|
||||
};
|
||||
|
||||
template<u32 InterfaceIdForDebug, size_t N>
|
||||
class ServiceDispatchTableImpl : public ServiceDispatchTableBase {
|
||||
public:
|
||||
static constexpr size_t NumEntries = N;
|
||||
private:
|
||||
const std::array<ServiceCommandMeta, N> m_entries;
|
||||
public:
|
||||
explicit constexpr ServiceDispatchTableImpl(const std::array<ServiceCommandMeta, N> &e) : m_entries{e} { /* ... */ }
|
||||
|
||||
Result ProcessMessage(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const {
|
||||
R_RETURN(this->ProcessMessageImpl(ctx, in_raw_data, m_entries.data(), m_entries.size(), InterfaceIdForDebug));
|
||||
}
|
||||
|
||||
Result ProcessMessageForMitm(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const {
|
||||
R_RETURN(this->ProcessMessageForMitmImpl(ctx, in_raw_data, m_entries.data(), m_entries.size(), InterfaceIdForDebug));
|
||||
}
|
||||
|
||||
constexpr const std::array<ServiceCommandMeta, N> &GetEntries() const {
|
||||
return m_entries;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<u32 InterfaceIdForDebug, size_t N>
|
||||
class ServiceDispatchTable : public impl::ServiceDispatchTableImpl<InterfaceIdForDebug, N> {
|
||||
public:
|
||||
explicit constexpr ServiceDispatchTable(const std::array<ServiceCommandMeta, N> &e) : impl::ServiceDispatchTableImpl<InterfaceIdForDebug, N>(e) { /* ... */ }
|
||||
};
|
||||
|
||||
struct ServiceDispatchMeta {
|
||||
const impl::ServiceDispatchTableBase *DispatchTable;
|
||||
Result (impl::ServiceDispatchTableBase::*ProcessHandler)(ServiceDispatchContext &, const cmif::PointerAndSize &) const;
|
||||
|
||||
uintptr_t GetServiceId() const {
|
||||
return reinterpret_cast<uintptr_t>(this->DispatchTable);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> requires sf::IsServiceObject<T>
|
||||
struct ServiceDispatchTraits {
|
||||
using ProcessHandlerType = decltype(ServiceDispatchMeta::ProcessHandler);
|
||||
|
||||
static constexpr inline auto DispatchTable = T::template s_CmifServiceDispatchTable<T>;
|
||||
using DispatchTableType = decltype(DispatchTable);
|
||||
|
||||
static constexpr ProcessHandlerType ProcessHandlerImpl = sf::IsMitmServiceObject<T> ? (&impl::ServiceDispatchTableBase::ProcessMessageForMitm<DispatchTableType>)
|
||||
: (&impl::ServiceDispatchTableBase::ProcessMessage<DispatchTableType>);
|
||||
|
||||
static constexpr inline ServiceDispatchMeta Meta{std::addressof(DispatchTable), ProcessHandlerImpl};
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ServiceDispatchTraits<sf::IServiceObject> {
|
||||
static constexpr inline auto DispatchTable = ServiceDispatchTable<0, 0>(std::array<ServiceCommandMeta, 0>{});
|
||||
};
|
||||
|
||||
#if AMS_SF_MITM_SUPPORTED
|
||||
template<>
|
||||
struct ServiceDispatchTraits<sf::IMitmServiceObject> {
|
||||
static constexpr inline auto DispatchTable = ServiceDispatchTable<0, 0>(std::array<ServiceCommandMeta, 0>{});
|
||||
};
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
constexpr ALWAYS_INLINE const ServiceDispatchMeta *GetServiceDispatchMeta() {
|
||||
return std::addressof(ServiceDispatchTraits<T>::Meta);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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/sf/sf_service_object.hpp>
|
||||
#include <stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp>
|
||||
|
||||
namespace ams::sf::cmif {
|
||||
|
||||
class ServiceObjectHolder {
|
||||
private:
|
||||
SharedPointer<IServiceObject> m_srv;
|
||||
const ServiceDispatchMeta *m_dispatch_meta;
|
||||
private:
|
||||
/* Copy constructor. */
|
||||
ServiceObjectHolder(const ServiceObjectHolder &o) : m_srv(o.m_srv), m_dispatch_meta(o.m_dispatch_meta) { /* ... */ }
|
||||
ServiceObjectHolder &operator=(const ServiceObjectHolder &o) = delete;
|
||||
public:
|
||||
/* Default constructor, null all members. */
|
||||
ServiceObjectHolder() : m_srv(nullptr, false), m_dispatch_meta(nullptr) { /* ... */ }
|
||||
|
||||
~ServiceObjectHolder() {
|
||||
m_dispatch_meta = nullptr;
|
||||
}
|
||||
|
||||
/* Ensure correct type id at runtime through template constructor. */
|
||||
template<typename ServiceImpl>
|
||||
constexpr explicit ServiceObjectHolder(SharedPointer<ServiceImpl> &&s) : m_srv(std::move(s)), m_dispatch_meta(GetServiceDispatchMeta<ServiceImpl>()) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* Move constructor, assignment operator. */
|
||||
ServiceObjectHolder(ServiceObjectHolder &&o) : m_srv(std::move(o.m_srv)), m_dispatch_meta(std::move(o.m_dispatch_meta)) {
|
||||
o.m_dispatch_meta = nullptr;
|
||||
}
|
||||
|
||||
ServiceObjectHolder &operator=(ServiceObjectHolder &&o) {
|
||||
ServiceObjectHolder tmp(std::move(o));
|
||||
tmp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* State management. */
|
||||
void swap(ServiceObjectHolder &o) {
|
||||
m_srv.swap(o.m_srv);
|
||||
std::swap(m_dispatch_meta, o.m_dispatch_meta);
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
m_srv = nullptr;
|
||||
m_dispatch_meta = nullptr;
|
||||
}
|
||||
|
||||
ServiceObjectHolder Clone() const {
|
||||
return ServiceObjectHolder(*this);
|
||||
}
|
||||
|
||||
/* Boolean operators. */
|
||||
explicit constexpr operator bool() const {
|
||||
return m_srv != nullptr;
|
||||
}
|
||||
|
||||
constexpr bool operator!() const {
|
||||
return m_srv == nullptr;
|
||||
}
|
||||
|
||||
/* Getters. */
|
||||
constexpr uintptr_t GetServiceId() const {
|
||||
if (m_dispatch_meta) {
|
||||
return m_dispatch_meta->GetServiceId();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Interface>
|
||||
constexpr inline bool IsServiceObjectValid() const {
|
||||
return this->GetServiceId() == GetServiceDispatchMeta<Interface>()->GetServiceId();
|
||||
}
|
||||
|
||||
template<typename Interface>
|
||||
inline Interface *GetServiceObject() const {
|
||||
if (this->GetServiceId() == GetServiceDispatchMeta<Interface>()->GetServiceId()) {
|
||||
return static_cast<Interface *>(m_srv.Get());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline sf::IServiceObject *GetServiceObjectUnsafe() const {
|
||||
return static_cast<sf::IServiceObject *>(m_srv.Get());
|
||||
}
|
||||
|
||||
/* Processing. */
|
||||
Result ProcessMessage(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user