ams: prefer construct_at/destroy_at over placement new/explicit destructor

This commit is contained in:
Michael Scire 2021-03-21 20:30:40 -07:00
parent aff0da9427
commit d84dcb653d
49 changed files with 217 additions and 171 deletions

View file

@ -88,8 +88,8 @@ namespace ams::fssystem {
if (this->external_attr_info_buffer == nullptr) {
new_info = new AttrInfo(attr.GetLevel(), 1, size);
} else if (0 <= attr.GetLevel() && attr.GetLevel() < this->external_attr_info_count) {
const auto buffer = this->external_attr_info_buffer + attr.GetLevel() * sizeof(AttrInfo);
new_info = new (buffer) AttrInfo(attr.GetLevel(), 1, size);
void *buffer = this->external_attr_info_buffer + attr.GetLevel() * sizeof(AttrInfo);
new_info = std::construct_at(reinterpret_cast<AttrInfo *>(buffer), attr.GetLevel(), 1, size);
}
/* If we failed to make a new attr info, we can't register. */

View file

@ -102,8 +102,8 @@ namespace ams::fssystem {
InitializeExpHeap();
/* Initialize buffer allocator. */
new (GetPointer(g_buffer_allocator)) mem::StandardAllocator(g_buffer_pool, BufferPoolSize);
new (GetPointer(g_allocator)) fssrv::MemoryResourceFromStandardAllocator(GetPointer(g_buffer_allocator));
util::ConstructAt(g_buffer_allocator, g_buffer_pool, BufferPoolSize);
util::ConstructAt(g_allocator, GetPointer(g_buffer_allocator));
/* Set allocators. */
fs::SetAllocator(AllocateForFileSystemProxy, DeallocateForFileSystemProxy);
@ -111,7 +111,7 @@ namespace ams::fssystem {
/* Initialize the buffer manager. */
/* TODO FS-REIMPL: os::AllocateMemoryBlock(...); */
new (GetPointer(g_buffer_manager)) fssystem::FileSystemBufferManager;
util::ConstructAt(g_buffer_manager);
GetReference(g_buffer_manager).Initialize(MaxCacheCount, reinterpret_cast<uintptr_t>(g_buffer_manager_heap), BufferManagerHeapSize, BlockSize);
/* TODO FS-REIMPL: Memory Report Creators, fssrv::SetMemoryReportCreator */
@ -119,9 +119,9 @@ namespace ams::fssystem {
/* TODO FS-REIMPL: Create Pooled Threads, fssystem::RegisterThreadPool. */
/* Initialize fs creators. */
new (GetPointer(g_rom_fs_creator)) fssrv::fscreator::RomFileSystemCreator(GetPointer(g_allocator));
new (GetPointer(g_partition_fs_creator)) fssrv::fscreator::PartitionFileSystemCreator;
new (GetPointer(g_storage_on_nca_creator)) fssrv::fscreator::StorageOnNcaCreator(GetPointer(g_allocator), *GetNcaCryptoConfiguration(is_prod), is_prod, GetPointer(g_buffer_manager));
util::ConstructAt(g_rom_fs_creator, GetPointer(g_allocator));
util::ConstructAt(g_partition_fs_creator);
util::ConstructAt(g_storage_on_nca_creator, GetPointer(g_allocator), *GetNcaCryptoConfiguration(is_prod), is_prod, GetPointer(g_buffer_manager));
/* TODO FS-REIMPL: Initialize other creators. */