ncm: update to 10.0.0 (#879)
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <stratosphere/ncm/ncm_install_task_base.hpp>
|
||||
#include <stratosphere/ncm/ncm_install_task_data.hpp>
|
||||
#include <stratosphere/ncm/ncm_install_task_occupied_size.hpp>
|
||||
#include <stratosphere/ncm/ncm_memory_report.hpp>
|
||||
#include <stratosphere/ncm/ncm_package_install_task_base.hpp>
|
||||
#include <stratosphere/ncm/ncm_package_install_task.hpp>
|
||||
#include <stratosphere/ncm/ncm_package_system_update_task.hpp>
|
||||
|
||||
@@ -30,14 +30,32 @@
|
||||
|
||||
namespace ams::ncm {
|
||||
|
||||
class ContentMetaMemoryResource {
|
||||
class ContentMetaMemoryResource : public MemoryResource {
|
||||
private:
|
||||
mem::StandardAllocator allocator;
|
||||
sf::StandardAllocatorMemoryResource memory_resource;
|
||||
size_t peak_total_alloc_size;
|
||||
size_t peak_alloc_size;
|
||||
public:
|
||||
ContentMetaMemoryResource(void *heap, size_t heap_size) : allocator(heap, heap_size), memory_resource(std::addressof(allocator)) { /* ... */ }
|
||||
explicit ContentMetaMemoryResource(void *heap, size_t heap_size) : allocator(heap, heap_size) { /* ... */ }
|
||||
|
||||
MemoryResource *Get() { return std::addressof(this->memory_resource); }
|
||||
mem::StandardAllocator *GetAllocator() { return std::addressof(this->allocator); }
|
||||
size_t GetPeakTotalAllocationSize() const { return this->peak_total_alloc_size; }
|
||||
size_t GetPeakAllocationSize() const { return this->peak_alloc_size; }
|
||||
private:
|
||||
virtual void *AllocateImpl(size_t size, size_t alignment) override {
|
||||
void *mem = this->allocator.Allocate(size, alignment);
|
||||
this->peak_total_alloc_size = std::max(this->allocator.Hash().allocated_size, this->peak_total_alloc_size);
|
||||
this->peak_alloc_size = std::max(size, this->peak_alloc_size);
|
||||
return mem;
|
||||
}
|
||||
|
||||
virtual void DeallocateImpl(void *buffer, size_t size, size_t alignment) override {
|
||||
return this->allocator.Free(buffer);
|
||||
}
|
||||
|
||||
virtual bool IsEqualImpl(const MemoryResource &resource) const override {
|
||||
return this == std::addressof(resource);
|
||||
}
|
||||
};
|
||||
|
||||
struct SystemSaveDataInfo {
|
||||
@@ -127,6 +145,7 @@ namespace ams::ncm {
|
||||
virtual Result ActivateContentMetaDatabase(StorageId storage_id) override;
|
||||
virtual Result InactivateContentMetaDatabase(StorageId storage_id) override;
|
||||
virtual Result InvalidateRightsIdCache() override;
|
||||
virtual Result GetMemoryReport(sf::Out<MemoryReport> out) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#pragma once
|
||||
#include <stratosphere/ncm/ncm_i_content_storage.hpp>
|
||||
#include <stratosphere/ncm/ncm_i_content_meta_database.hpp>
|
||||
#include <stratosphere/ncm/ncm_memory_report.hpp>
|
||||
|
||||
namespace ams::ncm {
|
||||
|
||||
@@ -36,6 +37,7 @@ namespace ams::ncm {
|
||||
ActivateContentMetaDatabase = 11,
|
||||
InactivateContentMetaDatabase = 12,
|
||||
InvalidateRightsIdCache = 13,
|
||||
GetMemoryReport = 14,
|
||||
};
|
||||
public:
|
||||
virtual Result CreateContentStorage(StorageId storage_id) = 0;
|
||||
@@ -52,6 +54,7 @@ namespace ams::ncm {
|
||||
virtual Result ActivateContentMetaDatabase(StorageId storage_id) = 0;
|
||||
virtual Result InactivateContentMetaDatabase(StorageId storage_id) = 0;
|
||||
virtual Result InvalidateRightsIdCache() = 0;
|
||||
virtual Result GetMemoryReport(sf::Out<MemoryReport> out) = 0;
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MAKE_SERVICE_COMMAND_META(CreateContentStorage),
|
||||
@@ -68,6 +71,7 @@ namespace ams::ncm {
|
||||
MAKE_SERVICE_COMMAND_META(ActivateContentMetaDatabase, hos::Version_2_0_0),
|
||||
MAKE_SERVICE_COMMAND_META(InactivateContentMetaDatabase, hos::Version_2_0_0),
|
||||
MAKE_SERVICE_COMMAND_META(InvalidateRightsIdCache, hos::Version_9_0_0),
|
||||
MAKE_SERVICE_COMMAND_META(GetMemoryReport, hos::Version_10_0_0),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ namespace ams::ncm {
|
||||
GetAttributes = 18,
|
||||
GetRequiredApplicationVersion = 19,
|
||||
GetContentIdByTypeAndIdOffset = 20,
|
||||
GetCount = 21,
|
||||
GetOwnerApplicationId = 22,
|
||||
};
|
||||
public:
|
||||
/* Actual commands. */
|
||||
@@ -67,6 +69,8 @@ namespace ams::ncm {
|
||||
virtual Result GetAttributes(sf::Out<u8> out_attributes, const ContentMetaKey &key) = 0;
|
||||
virtual Result GetRequiredApplicationVersion(sf::Out<u32> out_version, const ContentMetaKey &key) = 0;
|
||||
virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) = 0;
|
||||
virtual Result GetCount(sf::Out<u32> out_count) = 0;
|
||||
virtual Result GetOwnerApplicationId(sf::Out<ApplicationId> out_id, const ContentMetaKey &key) = 0;
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MAKE_SERVICE_COMMAND_META(Set),
|
||||
@@ -90,6 +94,8 @@ namespace ams::ncm {
|
||||
MAKE_SERVICE_COMMAND_META(GetAttributes),
|
||||
MAKE_SERVICE_COMMAND_META(GetRequiredApplicationVersion, hos::Version_2_0_0),
|
||||
MAKE_SERVICE_COMMAND_META(GetContentIdByTypeAndIdOffset, hos::Version_5_0_0),
|
||||
MAKE_SERVICE_COMMAND_META(GetCount, hos::Version_10_0_0),
|
||||
MAKE_SERVICE_COMMAND_META(GetOwnerApplicationId, hos::Version_10_0_0),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2020 Adubbz, 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/lmem/lmem_common.hpp>
|
||||
|
||||
namespace ams::ncm {
|
||||
|
||||
struct MemoryResourceState {
|
||||
size_t peak_total_alloc_size;
|
||||
size_t peak_alloc_size;
|
||||
size_t allocatable_size;
|
||||
size_t total_free_size;
|
||||
};
|
||||
|
||||
static_assert(sizeof(MemoryResourceState) == 0x20);
|
||||
|
||||
struct MemoryReport {
|
||||
MemoryResourceState system_content_meta_resource_state;
|
||||
MemoryResourceState sd_and_user_content_meta_resource_state;
|
||||
MemoryResourceState gamecard_content_meta_resource_state;
|
||||
MemoryResourceState heap_resource_state;
|
||||
};
|
||||
|
||||
static_assert(sizeof(MemoryReport) == 0x80);
|
||||
|
||||
class HeapState {
|
||||
private:
|
||||
os::Mutex mutex;
|
||||
lmem::HeapHandle heap_handle;
|
||||
size_t total_alloc_size;
|
||||
size_t peak_total_alloc_size;
|
||||
size_t peak_alloc_size;
|
||||
public:
|
||||
constexpr HeapState() : mutex(false), heap_handle(nullptr), total_alloc_size(0), peak_total_alloc_size(0), peak_alloc_size(0) { /* ... */ }
|
||||
|
||||
void Initialize(lmem::HeapHandle heap_handle);
|
||||
void Allocate(size_t size);
|
||||
void Free(size_t size);
|
||||
void GetMemoryResourceState(MemoryResourceState *out);
|
||||
};
|
||||
|
||||
HeapState &GetHeapState();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user