ncm: update to 10.0.0 (#879)

This commit is contained in:
Adubbz 2020-04-15 03:11:51 +10:00 committed by GitHub
parent 116e00c21c
commit a25be61e94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 243 additions and 7 deletions

View file

@ -614,7 +614,7 @@ namespace ams::ncm {
if (storage_id == StorageId::GameCard) {
/* Initialize the key value store. */
R_TRY(root->kvs->Initialize(root->max_content_metas, root->memory_resource->Get()));
R_TRY(root->kvs->Initialize(root->max_content_metas, root->memory_resource));
/* Create an on memory content meta database for game cards. */
root->content_meta_database = std::make_shared<OnMemoryContentMetaDatabaseImpl>(std::addressof(*root->kvs));
@ -626,7 +626,7 @@ namespace ams::ncm {
auto mount_guard = SCOPE_GUARD { fs::Unmount(root->mount_name); };
/* Initialize and load the key value store from the filesystem. */
R_TRY(root->kvs->Initialize(root->path, root->max_content_metas, root->memory_resource->Get()));
R_TRY(root->kvs->Initialize(root->path, root->max_content_metas, root->memory_resource));
R_TRY(root->kvs->Load());
/* Create the content meta database. */
@ -665,4 +665,36 @@ namespace ams::ncm {
return ResultSuccess();
}
Result ContentManagerImpl::GetMemoryReport(sf::Out<MemoryReport> out) {
/* Populate content meta resource states. */
MemoryReport report = {
.system_content_meta_resource_state = {
.peak_total_alloc_size = g_system_content_meta_memory_resource.GetPeakTotalAllocationSize(),
.peak_alloc_size = g_system_content_meta_memory_resource.GetPeakAllocationSize(),
.allocatable_size = g_system_content_meta_memory_resource.GetAllocator()->GetAllocatableSize(),
.total_free_size = g_system_content_meta_memory_resource.GetAllocator()->GetTotalFreeSize(),
},
.sd_and_user_content_meta_resource_state {
.peak_total_alloc_size = g_sd_and_user_content_meta_memory_resource.GetPeakTotalAllocationSize(),
.peak_alloc_size = g_sd_and_user_content_meta_memory_resource.GetPeakAllocationSize(),
.allocatable_size = g_sd_and_user_content_meta_memory_resource.GetAllocator()->GetAllocatableSize(),
.total_free_size = g_sd_and_user_content_meta_memory_resource.GetAllocator()->GetTotalFreeSize(),
},
.gamecard_content_meta_resource_state {
.peak_total_alloc_size = g_gamecard_content_meta_memory_resource.GetPeakTotalAllocationSize(),
.peak_alloc_size = g_gamecard_content_meta_memory_resource.GetPeakAllocationSize(),
.allocatable_size = g_gamecard_content_meta_memory_resource.GetAllocator()->GetAllocatableSize(),
.total_free_size = g_gamecard_content_meta_memory_resource.GetAllocator()->GetTotalFreeSize(),
},
.heap_resource_state = {},
};
/* Populate heap memory resource state. */
GetHeapState().GetMemoryResourceState(std::addressof(report.heap_resource_state));
/* Output the report. */
out.SetValue(report);
return ResultSuccess();
}
}

View file

@ -440,4 +440,47 @@ namespace ams::ncm {
return this->GetContentIdImpl(out_content_id.GetPointer(), key, type, std::make_optional(id_offset));
}
Result ContentMetaDatabaseImpl::GetCount(sf::Out<u32> out_count) {
R_TRY(this->EnsureEnabled());
out_count.SetValue(this->kvs->GetCount());
return ResultSuccess();
}
Result ContentMetaDatabaseImpl::GetOwnerApplicationId(sf::Out<ApplicationId> out_id, const ContentMetaKey &key) {
R_TRY(this->EnsureEnabled());
/* Ensure this type of key has an owner. */
R_UNLESS(key.type == ContentMetaType::Application || key.type == ContentMetaType::Patch || key.type == ContentMetaType::AddOnContent, ncm::ResultInvalidContentMetaKey());
/* Applications are their own owner. */
if (key.type == ContentMetaType::Application) {
out_id.SetValue({key.id});
return ResultSuccess();
}
/* Obtain the content meta for the key. */
const void *meta;
size_t meta_size;
R_TRY(this->GetContentMetaPointer(&meta, &meta_size, key));
/* Create a reader. */
ContentMetaReader reader(meta, meta_size);
/* Get the owner application id. */
ApplicationId owner_application_id;
switch (key.type) {
case ContentMetaType::Patch:
owner_application_id = reader.GetExtendedHeader<PatchMetaExtendedHeader>()->application_id;
break;
case ContentMetaType::AddOnContent:
owner_application_id = reader.GetExtendedHeader<AddOnContentMetaExtendedHeader>()->application_id;
break;
AMS_UNREACHABLE_DEFAULT_CASE();
}
/* Set the output value. */
out_id.SetValue(owner_application_id);
return ResultSuccess();
}
}

View file

@ -49,6 +49,8 @@ namespace ams::ncm {
virtual Result GetAttributes(sf::Out<u8> out_attributes, const ContentMetaKey &key) override;
virtual Result GetRequiredApplicationVersion(sf::Out<u32> out_version, const ContentMetaKey &key) override;
virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> out_content_id, const ContentMetaKey &key, ContentType type, u8 id_offset) override;
virtual Result GetCount(sf::Out<u32> out_count) override;
virtual Result GetOwnerApplicationId(sf::Out<ApplicationId> out_id, const ContentMetaKey &key) override;
};
}

View file

@ -0,0 +1,51 @@
/*
* 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/>.
*/
#include <stratosphere.hpp>
namespace ams::ncm {
void HeapState::Initialize(lmem::HeapHandle heap_handle) {
std::scoped_lock lk(this->mutex);
this->heap_handle = heap_handle;
}
void HeapState::Allocate(size_t size) {
std::scoped_lock lk(this->mutex);
this->total_alloc_size += size;
this->peak_total_alloc_size = std::max(this->total_alloc_size, this->peak_total_alloc_size);
this->peak_alloc_size = std::max(size, this->peak_alloc_size);
}
void HeapState::Free(size_t size) {
std::scoped_lock lk(this->mutex);
this->total_alloc_size -= size;
}
void HeapState::GetMemoryResourceState(MemoryResourceState *out) {
*out = {};
std::scoped_lock lk(this->mutex);
out->peak_total_alloc_size = this->peak_total_alloc_size;
out->peak_alloc_size = this->peak_alloc_size;
out->total_free_size = lmem::GetExpHeapTotalFreeSize(this->heap_handle);
out->allocatable_size = lmem::GetExpHeapAllocatableSize(this->heap_handle, alignof(s32));
}
HeapState &GetHeapState() {
static HeapState s_heap_state = {};
return s_heap_state;
}
}

View file

@ -89,6 +89,11 @@ namespace ams::ncm {
virtual Result InvalidateRightsIdCache() override {
return ::ncmInvalidateRightsIdCache();
}
virtual Result GetMemoryReport(sf::Out<MemoryReport> out) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
};
}

View file

@ -156,6 +156,16 @@ namespace ams::ncm {
return ncmContentMetaDatabaseGetContentIdByTypeAndIdOffset(std::addressof(this->srv), Convert(out_content_id.GetPointer()), Convert(key), static_cast<::NcmContentType>(type), id_offset);
}
virtual Result GetCount(sf::Out<u32> out_count) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
virtual Result GetOwnerApplicationId(sf::Out<ApplicationId> out_id, const ContentMetaKey &key) override {
/* TODO: libnx bindings */
AMS_ABORT();
}
};
}