From 15e8e324095859400392bcca8c0baa2a683b7b1f Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 9 Aug 2019 15:30:25 +1000 Subject: [PATCH] Fixed ContentId/PlaceHolderId alignment --- .../source/impl/ncm_placeholder_accessor.cpp | 12 ++--- .../source/impl/ncm_placeholder_accessor.hpp | 2 +- .../ncm/source/ncm_contentstorage.cpp | 4 +- stratosphere/ncm/source/ncm_types.hpp | 45 +++++++++++++++++-- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/stratosphere/ncm/source/impl/ncm_placeholder_accessor.cpp b/stratosphere/ncm/source/impl/ncm_placeholder_accessor.cpp index 79f562e15..ee48fe63e 100644 --- a/stratosphere/ncm/source/impl/ncm_placeholder_accessor.cpp +++ b/stratosphere/ncm/source/impl/ncm_placeholder_accessor.cpp @@ -45,7 +45,7 @@ namespace sts::ncm::impl { return false; } *out_handle = entry->handle; - entry->id = InvalidUuid; + entry->id = InvalidPlaceHolderId; entry->handle = nullptr; return true; } @@ -61,7 +61,7 @@ namespace sts::ncm::impl { PlaceHolderAccessor::CacheEntry *PlaceHolderAccessor::GetFreeEntry() { /* Try to find an already free entry. */ - CacheEntry* entry = this->FindInCache(InvalidUuid); + CacheEntry* entry = this->FindInCache(InvalidPlaceHolderId); if (entry) { return entry; @@ -95,7 +95,7 @@ namespace sts::ncm::impl { fclose(entry->handle); entry->handle = nullptr; } - entry->id = InvalidUuid; + entry->id = InvalidPlaceHolderId; } } @@ -194,7 +194,7 @@ namespace sts::ncm::impl { { std::scoped_lock lock(this->cache_mutex); - if (placeholder_id == InvalidUuid) { + if (placeholder_id == InvalidPlaceHolderId) { *found_in_cache = false; return ResultSuccess; } @@ -206,7 +206,7 @@ namespace sts::ncm::impl { return ResultSuccess; } - cache_entry->id = InvalidUuid; + cache_entry->id = InvalidPlaceHolderId; f = cache_entry->handle; } @@ -234,7 +234,7 @@ namespace sts::ncm::impl { void PlaceHolderAccessor::InvalidateAll() { for (auto &entry : this->caches) { - if (entry.id != InvalidUuid) { + if (entry.id != InvalidPlaceHolderId) { this->Invalidate(&entry); } } diff --git a/stratosphere/ncm/source/impl/ncm_placeholder_accessor.hpp b/stratosphere/ncm/source/impl/ncm_placeholder_accessor.hpp index acaed14ce..73debc2da 100644 --- a/stratosphere/ncm/source/impl/ncm_placeholder_accessor.hpp +++ b/stratosphere/ncm/source/impl/ncm_placeholder_accessor.hpp @@ -50,7 +50,7 @@ namespace sts::ncm::impl { public: PlaceHolderAccessor() : cur_counter(0), delay_flush(false) { for (size_t i = 0; i < MaxCaches; i++) { - caches[i].id = InvalidUuid; + caches[i].id = InvalidPlaceHolderId; } } diff --git a/stratosphere/ncm/source/ncm_contentstorage.cpp b/stratosphere/ncm/source/ncm_contentstorage.cpp index c33e78835..55889a79b 100644 --- a/stratosphere/ncm/source/ncm_contentstorage.cpp +++ b/stratosphere/ncm/source/ncm_contentstorage.cpp @@ -49,9 +49,9 @@ namespace sts::ncm { } void ContentStorageInterface::ClearContentCache() { - if (this->cached_content_id != InvalidUuid) { + if (this->cached_content_id != InvalidContentId) { fclose(this->content_cache_file_handle); - this->cached_content_id = InvalidUuid; + this->cached_content_id = InvalidContentId; } } diff --git a/stratosphere/ncm/source/ncm_types.hpp b/stratosphere/ncm/source/ncm_types.hpp index 17c0b5d00..01a80091b 100644 --- a/stratosphere/ncm/source/ncm_types.hpp +++ b/stratosphere/ncm/source/ncm_types.hpp @@ -34,14 +34,53 @@ namespace sts::ncm { bool operator!=(const Uuid& other) const { return !(*this == other); } + + u8& operator[](size_t i) { + return uuid[i]; + } }; static_assert(sizeof(Uuid) == 0x10, "Uuid definition!"); - static constexpr Uuid InvalidUuid = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; + struct PlaceHolderId { + Uuid uuid; - typedef Uuid ContentId; - typedef Uuid PlaceHolderId; + inline operator Uuid() const { + return this->uuid; + } + + bool operator==(const Uuid& other) const { + return this->uuid == other; + } + + bool operator!=(const Uuid& other) const { + return this->uuid != other; + } + } __attribute__((aligned(8))); + + static_assert(__alignof__(PlaceHolderId) == 8, "PlaceHolderId definition!"); + + struct ContentId { + Uuid uuid; + + inline operator Uuid() const { + return this->uuid; + } + + bool operator==(const Uuid& other) const { + return this->uuid == other; + } + + bool operator!=(const Uuid& other) const { + return this->uuid != other; + } + } __attribute__((aligned(4))); + + static_assert(__alignof__(ContentId) == 4, "ContentId definition!"); + + static constexpr Uuid InvalidUuid = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; + static constexpr PlaceHolderId InvalidPlaceHolderId = { InvalidUuid }; + static constexpr ContentId InvalidContentId = { InvalidUuid }; enum class ContentMetaType : u8 { Unknown = 0x0,