From dfa475a76947cd1cbe44c5326facb4781a659fde Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 24 Mar 2022 16:21:03 -0700 Subject: [PATCH] util: add pointer utils, use to constrain fs pointers --- .../include/stratosphere/fs/fs_filesystem.hpp | 2 +- .../include/stratosphere/fs/fs_istorage.hpp | 3 + .../stratosphere/fs/fsa/fs_ifilesystem.hpp | 3 + .../fssystem/fssystem_aes_ctr_storage.hpp | 2 +- .../fssystem/fssystem_aes_xts_storage.hpp | 2 +- .../fssystem_alignment_matching_storage.hpp | 6 +- libraries/libvapours/include/vapours/util.hpp | 1 + .../vapours/util/util_pointer_util.hpp | 62 +++++++++++++++++++ 8 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 libraries/libvapours/include/vapours/util/util_pointer_util.hpp diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_filesystem.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_filesystem.hpp index 86e384214..1ca745fd8 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_filesystem.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_filesystem.hpp @@ -20,7 +20,7 @@ namespace ams::fs { namespace fsa { - class IFile; + class IFileSystem; } diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_istorage.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_istorage.hpp index 6894962d1..cd96b9afb 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_istorage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_istorage.hpp @@ -110,4 +110,7 @@ namespace ams::fs { } }; + template + concept PointerToStorage = ::ams::util::RawOrSmartPointerTo; + } diff --git a/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifilesystem.hpp b/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifilesystem.hpp index ce8903aab..d72670e4a 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifilesystem.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fsa/fs_ifilesystem.hpp @@ -181,4 +181,7 @@ namespace ams::fs::fsa { } }; + template + concept PointerToFileSystem = ::ams::util::RawOrSmartPointerTo; + } diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_ctr_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_ctr_storage.hpp index e90fdf736..1c779ff1d 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_ctr_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_ctr_storage.hpp @@ -21,7 +21,7 @@ namespace ams::fssystem { /* ACCURATE_TO_VERSION: Unknown */ - template + template class AesCtrStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable { NON_COPYABLE(AesCtrStorage); NON_MOVEABLE(AesCtrStorage); diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_xts_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_xts_storage.hpp index 299ae4f38..211bd8239 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_xts_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_xts_storage.hpp @@ -22,7 +22,7 @@ namespace ams::fssystem { /* ACCURATE_TO_VERSION: Unknown */ - template + template class AesXtsStorage : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable { NON_COPYABLE(AesXtsStorage); NON_MOVEABLE(AesXtsStorage); diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_alignment_matching_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_alignment_matching_storage.hpp index b6a950403..9e53b3ada 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_alignment_matching_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_alignment_matching_storage.hpp @@ -133,7 +133,7 @@ namespace ams::fssystem { }; /* ACCURATE_TO_VERSION: Unknown */ - template + template class AlignmentMatchingStoragePooledBuffer : public ::ams::fs::IStorage, public ::ams::fs::impl::Newable { NON_COPYABLE(AlignmentMatchingStoragePooledBuffer); NON_MOVEABLE(AlignmentMatchingStoragePooledBuffer); @@ -142,12 +142,12 @@ namespace ams::fssystem { static_assert(util::IsPowerOfTwo(BufferAlign)); private: - BaseStorageType m_base_storage; + BasePointer m_base_storage; s64 m_base_storage_size; size_t m_data_align; bool m_is_base_storage_size_dirty; public: - explicit AlignmentMatchingStoragePooledBuffer(BaseStorageType bs, size_t da) : m_base_storage(std::move(bs)), m_data_align(da), m_is_base_storage_size_dirty(true) { + explicit AlignmentMatchingStoragePooledBuffer(BasePointer bs, size_t da) : m_base_storage(std::move(bs)), m_data_align(da), m_is_base_storage_size_dirty(true) { AMS_ASSERT(util::IsPowerOfTwo(da)); } diff --git a/libraries/libvapours/include/vapours/util.hpp b/libraries/libvapours/include/vapours/util.hpp index 1b9991aa7..0bc4a6bdf 100644 --- a/libraries/libvapours/include/vapours/util.hpp +++ b/libraries/libvapours/include/vapours/util.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libvapours/include/vapours/util/util_pointer_util.hpp b/libraries/libvapours/include/vapours/util/util_pointer_util.hpp new file mode 100644 index 000000000..8ee61e150 --- /dev/null +++ b/libraries/libvapours/include/vapours/util/util_pointer_util.hpp @@ -0,0 +1,62 @@ +/* + * 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 . + */ +#pragma once +#include +#include + +namespace ams::util { + + namespace impl { + + template + struct IsSharedPointerImpl : public std::false_type{}; + + template + struct IsSharedPointerImpl> : public std::true_type{}; + + template + struct IsUniquePointerImpl : public std::false_type{}; + + template + struct IsUniquePointerImpl> : public std::true_type{}; + + template + concept PointerToImpl = std::same_as::element_type, U>; + + } + + template + concept IsRawPointer = std::is_pointer::value; + + template + concept IsSharedPointer = impl::IsSharedPointerImpl::value; + + template + concept IsUniquePointer = impl::IsUniquePointerImpl::value; + + template + concept IsSmartPointer = IsSharedPointer || IsUniquePointer; + + template + concept IsRawOrSmartPointer = IsRawPointer || IsSmartPointer; + + template + concept SmartPointerTo = IsSmartPointer && impl::PointerToImpl; + + template + concept RawOrSmartPointerTo = IsRawOrSmartPointer && impl::PointerToImpl; + +}