libstrat: enable -Wextra, -Werror
This caught an embarrassingly large number of bugs.
This commit is contained in:
@@ -185,7 +185,7 @@ namespace ams::mem::impl::heap {
|
||||
if (cls_from_ptr) {
|
||||
if (cls_from_ptr <= 0) {
|
||||
return EFAULT;
|
||||
} else if (cls_from_size && cls_from_size <= cls_from_ptr) {
|
||||
} else if (cls_from_size && static_cast<s32>(cls_from_size) <= cls_from_ptr) {
|
||||
*p = ptr;
|
||||
return 0;
|
||||
} else {
|
||||
@@ -225,7 +225,7 @@ namespace ams::mem::impl::heap {
|
||||
if (cls_from_ptr) {
|
||||
if (cls_from_ptr <= 0) {
|
||||
return EFAULT;
|
||||
} else if (cls_from_size && cls_from_size <= cls_from_ptr) {
|
||||
} else if (cls_from_size && static_cast<s32>(cls_from_size) <= cls_from_ptr) {
|
||||
return 0;
|
||||
} else {
|
||||
return EINVAL;
|
||||
|
||||
@@ -289,14 +289,14 @@ namespace ams::mem::impl::heap {
|
||||
|
||||
template<>
|
||||
errno_t TlsHeapCache::FreeImpl<false>(TlsHeapCache *_this, void *ptr) {
|
||||
const size_t cls = _this->central->GetClassFromPointer(ptr);
|
||||
const auto cls = _this->central->GetClassFromPointer(ptr);
|
||||
if (cls == 0) {
|
||||
return _this->central->UncacheLargeMemory(ptr);
|
||||
}
|
||||
|
||||
AMS_ASSERT(cls < TlsHeapStatic::NumClassInfo);
|
||||
|
||||
if (static_cast<s32>(cls) >= 0) {
|
||||
if (cls >= 0) {
|
||||
return _this->central->UncacheSmallMemory(ptr);
|
||||
} else if (ptr == nullptr) {
|
||||
return 0;
|
||||
@@ -307,14 +307,14 @@ namespace ams::mem::impl::heap {
|
||||
|
||||
template<>
|
||||
errno_t TlsHeapCache::FreeImpl<true>(TlsHeapCache *_this, void *ptr) {
|
||||
const size_t cls = _this->central->GetClassFromPointer(ptr);
|
||||
const auto cls = _this->central->GetClassFromPointer(ptr);
|
||||
if (cls == 0) {
|
||||
return _this->central->UncacheLargeMemory(ptr);
|
||||
}
|
||||
|
||||
AMS_ASSERT(cls < TlsHeapStatic::NumClassInfo);
|
||||
|
||||
if (static_cast<s32>(cls) >= 0) {
|
||||
if (cls >= 0) {
|
||||
*reinterpret_cast<void **>(ptr) = _this->small_mem_lists[cls];
|
||||
_this->small_mem_lists[cls] = _this->ManglePointer(ptr);
|
||||
|
||||
|
||||
@@ -918,6 +918,8 @@ namespace ams::mem::impl::heap {
|
||||
}
|
||||
|
||||
errno_t TlsHeapCentral::AllocatePhysical(void *start, size_t size) {
|
||||
/* TODO: Implement physical tls heap central logic. */
|
||||
AMS_UNUSED(start, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1419,6 +1421,7 @@ namespace ams::mem::impl::heap {
|
||||
}
|
||||
|
||||
/* TODO: Is this worth supporting? */
|
||||
AMS_UNUSED(out_free_size, out_max_allocatable_size);
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
|
||||
@@ -1494,6 +1497,7 @@ namespace ams::mem::impl::heap {
|
||||
}
|
||||
|
||||
void TlsHeapCentral::DumpImpl(DumpMode dump_mode, int fd, bool json) {
|
||||
AMS_UNUSED(dump_mode, fd, json);
|
||||
AMS_ABORT("Not yet implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -221,6 +221,8 @@ namespace ams::mem::impl::heap {
|
||||
void CalculateHeapHash(HeapHash *out);
|
||||
|
||||
errno_t AddThreadCache(TlsHeapCache *cache) {
|
||||
AMS_UNUSED(cache);
|
||||
|
||||
std::scoped_lock lk(this->lock);
|
||||
|
||||
/* Add thread and recalculate. */
|
||||
@@ -231,6 +233,8 @@ namespace ams::mem::impl::heap {
|
||||
}
|
||||
|
||||
errno_t RemoveThreadCache(TlsHeapCache *cache) {
|
||||
AMS_UNUSED(cache);
|
||||
|
||||
std::scoped_lock lk(this->lock);
|
||||
|
||||
/* Remove thread and recalculate. */
|
||||
@@ -290,7 +294,7 @@ namespace ams::mem::impl::heap {
|
||||
getcpu(std::addressof(cpu_id));
|
||||
}
|
||||
|
||||
return this->CacheSmallMemoryListImpl(cache, cls, count, p, cpu_id, 0);
|
||||
return this->CacheSmallMemoryListImpl(cache, cls, count, p, cpu_id, align);
|
||||
}
|
||||
|
||||
bool CheckCachedSize(s32 size) const {
|
||||
@@ -321,7 +325,7 @@ namespace ams::mem::impl::heap {
|
||||
}
|
||||
}
|
||||
|
||||
size_t GetClassFromPointer(const void *ptr) {
|
||||
s32 GetClassFromPointer(const void *ptr) {
|
||||
std::atomic_thread_fence(std::memory_order_acquire);
|
||||
|
||||
const size_t idx = (reinterpret_cast<uintptr_t>(ptr) - reinterpret_cast<uintptr_t>(this)) / TlsHeapStatic::PageSize;
|
||||
@@ -338,7 +342,7 @@ namespace ams::mem::impl::heap {
|
||||
return this->span_table.pageclass_cache[idx];
|
||||
} else {
|
||||
/* TODO: Handle error? */
|
||||
return 0xFFFFFFFF;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,16 @@ namespace ams::mem::impl {
|
||||
constinit bool g_virt_mem_enabled = false;
|
||||
|
||||
void EnsureVirtualAddressMemoryDetected() {
|
||||
std::scoped_lock lk(g_virt_mem_enabled_lock);
|
||||
if (AMS_LIKELY(g_virt_mem_enabled_detected)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock lk(g_virt_mem_enabled_lock);
|
||||
|
||||
if (AMS_UNLIKELY(g_virt_mem_enabled_detected)) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_virt_mem_enabled = os::IsVirtualAddressMemoryEnabled();
|
||||
}
|
||||
|
||||
@@ -64,6 +70,7 @@ namespace ams::mem::impl {
|
||||
uintptr_t addr;
|
||||
if (IsVirtualAddressMemoryEnabled()) {
|
||||
/* TODO: Support virtual address memory. */
|
||||
AMS_UNUSED(ptr);
|
||||
AMS_ABORT("Virtual address memory not supported yet");
|
||||
} else {
|
||||
if (auto err = ConvertResult(os::AllocateMemoryBlock(std::addressof(addr), util::AlignUp(size, os::MemoryBlockUnitSize))); err != 0) {
|
||||
|
||||
Reference in New Issue
Block a user