ams-libs: AMS_ASSERT no longer invokes expression

This commit is contained in:
Michael Scire 2021-09-29 21:32:40 -07:00
parent 5dc64bc1f7
commit 9b04ff0f54
38 changed files with 82 additions and 23 deletions

View file

@ -58,6 +58,7 @@ namespace ams::secmon::fatal {
Result ReadSdCard(void *dst, size_t size, size_t sector_index, size_t sector_count) {
/* Validate that our buffer is valid. */
AMS_ASSERT(size >= sector_count * sdmmc::SectorSize);
AMS_UNUSED(size);
/* Repeatedly read sectors. */
u8 *dst_u8 = static_cast<u8 *>(dst);
@ -83,6 +84,7 @@ namespace ams::secmon::fatal {
Result WriteSdCard(size_t sector_index, size_t sector_count, const void *src, size_t size) {
/* Validate that our buffer is valid. */
AMS_ASSERT(size >= sector_count * sdmmc::SectorSize);
AMS_UNUSED(size);
/* Repeatedly read sectors. */
const u8 *src_u8 = static_cast<const u8 *>(src);

View file

@ -34,7 +34,7 @@ namespace ams::crypto::impl {
void AesImpl<KeySize>::Initialize(const void *key, size_t key_size, bool is_encrypt) {
static_assert(IsSupportedKeySize(KeySize));
AMS_ASSERT(key_size == sizeof(int));
AMS_UNUSED(is_encrypt);
AMS_UNUSED(key_size, is_encrypt);
/* Set the security engine keyslot. */
this->slot = *static_cast<const int *>(key);

View file

@ -29,6 +29,7 @@ namespace ams::ddsf {
for (const auto &holder : this->entry_list) {
AMS_ASSERT(holder.IsConstructed());
AMS_ASSERT(holder.Get().GetDeviceCode() != device_code);
AMS_UNUSED(holder);
}
/* Allocate memory for a new device code entry holder. */

View file

@ -21,6 +21,7 @@ namespace ams::err::impl {
void MakeErrorCodeString(char *dst, size_t dst_size, ErrorCode error_code) {
const auto len = util::TSNPrintf(dst, dst_size, "%04d-%04d", error_code.category, error_code.number);
AMS_ASSERT(static_cast<size_t>(len) < dst_size);
AMS_UNUSED(len);
}
}

View file

@ -82,6 +82,7 @@ namespace ams::fs::impl {
const char *IdString::ToValueString(int id) {
const int len = util::SNPrintf(this->buffer, sizeof(this->buffer), "%d", id);
AMS_ASSERT(static_cast<size_t>(len) < sizeof(this->buffer));
AMS_UNUSED(len);
return this->buffer;
}

View file

@ -33,8 +33,9 @@ namespace ams::fs {
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
auto size = util::SNPrintf(dst, dst_size, "%s:", bis_mount_name);
const auto size = util::SNPrintf(dst, dst_size, "%s:", bis_mount_name);
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
AMS_UNUSED(size);
return ResultSuccess();
}

View file

@ -32,8 +32,9 @@ namespace ams::fs {
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
auto size = util::SNPrintf(dst, dst_size, "%s:", GetContentStorageMountName(id));
const auto size = util::SNPrintf(dst, dst_size, "%s:", GetContentStorageMountName(id));
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
AMS_UNUSED(size);
return ResultSuccess();
}

View file

@ -42,8 +42,9 @@ namespace ams::fs {
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
auto size = util::SNPrintf(dst, dst_size, "%s%s%08x:", impl::GameCardFileSystemMountName, GetGameCardMountNameSuffix(this->partition), this->handle);
const auto size = util::SNPrintf(dst, dst_size, "%s%s%08x:", impl::GameCardFileSystemMountName, GetGameCardMountNameSuffix(this->partition), this->handle);
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
AMS_UNUSED(size);
return ResultSuccess();
}

View file

@ -426,8 +426,9 @@ namespace ams::fs {
{
bool normalized = false;
const auto is_norm_result = IsNormalized(std::addressof(normalized), out, unc_preserved, has_mount_name);
AMS_ASSERT(R_SUCCEEDED(is_norm_result));
R_ASSERT(is_norm_result);
AMS_ASSERT(normalized);
AMS_UNUSED(is_norm_result, normalized);
}
return ResultSuccess();

View file

@ -29,8 +29,11 @@ namespace ams::fs {
u32 *dst_invalid = this->invalid_chars;
for (const char *cur = ":*?<>|"; *cur != '\x00'; ++cur) {
AMS_ASSERT(dst_invalid < std::end(this->invalid_chars));
const auto result = util::ConvertCharacterUtf8ToUtf32(dst_invalid, cur);
AMS_ASSERT(result == util::CharacterEncodingResult_Success);
AMS_UNUSED(result);
++dst_invalid;
}
AMS_ASSERT(dst_invalid == std::end(this->invalid_chars));
@ -39,8 +42,11 @@ namespace ams::fs {
u32 *dst_sep = this->separators;
for (const char *cur = "/\\"; *cur != '\x00'; ++cur) {
AMS_ASSERT(dst_sep < std::end(this->separators));
const auto result = util::ConvertCharacterUtf8ToUtf32(dst_sep, cur);
AMS_ASSERT(result == util::CharacterEncodingResult_Success);
AMS_UNUSED(result);
++dst_sep;
}
AMS_ASSERT(dst_sep == std::end(this->separators));

View file

@ -35,8 +35,9 @@ namespace ams::fs {
AMS_ABORT_UNLESS(dst_size >= needed_size);
/* Generate the name. */
auto size = util::SNPrintf(dst, dst_size, "%s:", impl::SdCardFileSystemMountName);
const auto size = util::SNPrintf(dst, dst_size, "%s:", impl::SdCardFileSystemMountName);
AMS_ASSERT(static_cast<size_t>(size) == needed_size - 1);
AMS_UNUSED(size);
return ResultSuccess();
}

View file

@ -215,9 +215,12 @@ namespace ams::fssystem {
AMS_ASSERT(entry != nullptr);
/* Ensure the entry is valid. */
const auto entry_buffer = this->external_entry_buffer != nullptr ? this->external_entry_buffer : this->internal_entry_buffer.get();
AMS_ASSERT(static_cast<void *>(entry_buffer) <= static_cast<void *>(entry));
AMS_ASSERT(static_cast<void *>(entry) < static_cast<void *>(entry_buffer + this->entry_buffer_size));
{
const auto entry_buffer = this->external_entry_buffer != nullptr ? this->external_entry_buffer : this->internal_entry_buffer.get();
AMS_ASSERT(static_cast<void *>(entry_buffer) <= static_cast<void *>(entry));
AMS_ASSERT(static_cast<void *>(entry) < static_cast<void *>(entry_buffer + this->entry_buffer_size));
AMS_UNUSED(entry_buffer);
}
/* Copy the entries back by one. */
std::memmove(entry, entry + 1, sizeof(Entry) * (this->entry_count - ((entry + 1) - this->entries)));

View file

@ -786,6 +786,7 @@ namespace ams::fssystem::save {
/* Get the entry to invalidate. */
const CacheEntry *entry_to_invalidate = std::addressof(this->entries[this->invalidate_index]);
AMS_UNUSED(entry_to_invalidate);
/* Ensure that the entry can be invalidated. */
AMS_ASSERT(entry_to_invalidate->is_valid);

View file

@ -192,6 +192,7 @@ namespace ams::fssystem::save {
const auto cache_buffer = reinterpret_cast<u8 *>(this->memory_range.first) + read_offset;
AMS_ASSERT(read_offset >= 0);
AMS_ASSERT(static_cast<size_t>(read_offset) <= readable_offset_max);
AMS_UNUSED(readable_offset_max);
std::memcpy(buffer, cache_buffer, size);
}
@ -209,6 +210,7 @@ namespace ams::fssystem::save {
const auto cache_buffer = reinterpret_cast<u8 *>(this->memory_range.first) + write_offset;
AMS_ASSERT(write_offset >= 0);
AMS_ASSERT(static_cast<size_t>(write_offset) <= writable_offset_max);
AMS_UNUSED(writable_offset_max);
std::memcpy(cache_buffer, buffer, size);
this->is_dirty = true;

View file

@ -44,9 +44,10 @@ namespace ams::fssystem::save {
{
s64 hash_size = 0;
s64 data_size = 0;
AMS_ASSERT(R_SUCCEEDED(hash_storage.GetSize(std::addressof(hash_size))));
AMS_ASSERT(R_SUCCEEDED(data_storage.GetSize(std::addressof(hash_size))));
R_ASSERT(hash_storage.GetSize(std::addressof(hash_size)));
R_ASSERT(data_storage.GetSize(std::addressof(hash_size)));
AMS_ASSERT(((hash_size / HashSize) * this->verification_block_size) >= data_size);
AMS_UNUSED(hash_size, data_size);
}
/* Set salt. */

View file

@ -141,6 +141,7 @@ namespace ams::gpio::driver::impl {
auto &pad = this->GetDevice().SafeCastTo<Pad>();
auto &driver = pad.GetDriver().SafeCastTo<IGpioDriver>();
AMS_ASSERT(driver.GetInterruptControlMutex(pad).IsLockedByCurrentThread());
AMS_UNUSED(pad, driver);
if (auto *event = this->event_holder.GetSystemEvent(); event != nullptr) {
os::SignalSystemEvent(event);

View file

@ -21,7 +21,7 @@ namespace ams::htcfs {
namespace {
constinit util::TypedStorage<Client> g_client_storage;
constinit bool g_initialized;
[[maybe_unused]] constinit bool g_initialized;
}

View file

@ -49,6 +49,7 @@ namespace ams::htcs::impl::rpc {
AMS_ASSERT(0 <= write_handle_count && write_handle_count < SocketCountMax);
AMS_ASSERT(0 <= exception_handle_count && exception_handle_count < SocketCountMax);
AMS_ASSERT(handle_count * static_cast<s64>(sizeof(s32)) == body_size);
AMS_UNUSED(handle_count);
/* Set our results. */
m_err = err;

View file

@ -63,8 +63,11 @@ namespace ams::mem::impl::heap {
bool CachedHeap::CheckCache() {
bool cache = false;
auto err = this->Query(AllocQuery_CheckCache, std::addressof(cache));
AMS_ASSERT(err != 0);
const auto err = this->Query(AllocQuery_CheckCache, std::addressof(cache));
AMS_ASSERT(err == 0);
AMS_UNUSED(err);
return cache;
}

View file

@ -1151,8 +1151,9 @@ namespace ams::mem::impl::heap {
}
if (start_alignup < end_aligndown) {
auto err = this->FreePhysical(reinterpret_cast<void *>(start_alignup), end_aligndown - start_alignup);
const auto err = this->FreePhysical(reinterpret_cast<void *>(start_alignup), end_aligndown - start_alignup);
AMS_ASSERT(err == 0);
AMS_UNUSED(err);
}
} else {
this->MergeIntoFreeList(span);

View file

@ -167,8 +167,9 @@ namespace ams::mem {
}
}
auto err = GetCentral(this->central_heap_storage)->Free(ptr);
const auto err = GetCentral(this->central_heap_storage)->Free(ptr);
AMS_ASSERT(err == 0);
AMS_UNUSED(err);
}
void *StandardAllocator::Reallocate(void *ptr, size_t new_size) {
@ -248,8 +249,9 @@ namespace ams::mem {
void StandardAllocator::CleanUpManagementArea() const {
AMS_ASSERT(this->initialized);
auto err = GetCentral(this->central_heap_storage)->Query(impl::AllocQuery_UnifyFreeList);
const auto err = GetCentral(this->central_heap_storage)->Query(impl::AllocQuery_UnifyFreeList);
AMS_ASSERT(err == 0);
AMS_UNUSED(err);
}
size_t StandardAllocator::GetSizeOf(const void *ptr) const {

View file

@ -23,7 +23,8 @@ namespace ams::os::impl {
svc::MemoryInfo memory_info;
svc::PageInfo page_info;
const auto result = svc::QueryMemory(std::addressof(memory_info), std::addressof(page_info), address);
AMS_ASSERT(R_SUCCEEDED(result));
R_ASSERT(result);
AMS_UNUSED(result);
return memory_info.state == svc::MemoryState_Free && address + size <= memory_info.addr + memory_info.size;
}

View file

@ -109,6 +109,7 @@ namespace ams::os::impl {
const auto count = mq->count;
const auto offset = mq->offset;
AMS_ASSERT(count > 0);
AMS_UNUSED(count);
return mq->buffer[offset];
}

View file

@ -38,8 +38,9 @@ namespace ams::os::impl {
const s64 frac = tick_val % tick_freq;
const TimeSpan ts = TimeSpan::FromSeconds(seconds) + TimeSpan::FromNanoSeconds(frac * NanoSecondsPerSecond / tick_freq);
constexpr TimeSpan ZeroTS = TimeSpan::FromNanoSeconds(0);
constexpr TimeSpan ZeroTS = TimeSpan::FromNanoSeconds(0);
AMS_ASSERT(!((tick_val > 0 && ts < ZeroTS) || (tick_val < 0 && ts > ZeroTS)));
AMS_UNUSED(ZeroTS);
return ts;
}

View file

@ -49,8 +49,11 @@ namespace ams::os::impl {
WaitableHolderBase *WaitAnyImpl(bool infinite, TimeSpan timeout) {
WaitableHolderBase *holder = nullptr;
const Result wait_result = this->WaitAnyImpl(std::addressof(holder), infinite, timeout, false, svc::InvalidHandle);
AMS_ASSERT(R_SUCCEEDED(wait_result));
R_ASSERT(wait_result);
AMS_UNUSED(wait_result);
return holder;
}
public:

View file

@ -123,8 +123,9 @@ namespace ams::os {
const s32 prev_prio = thread->base_priority;
bool success = impl::GetThreadManager().ChangePriority(thread, priority);
const bool success = impl::GetThreadManager().ChangePriority(thread, priority);
AMS_ASSERT(success);
AMS_UNUSED(success);
thread->base_priority = priority;

View file

@ -45,6 +45,7 @@ namespace ams::os {
AMS_ASSERT(manager->state == WaitableManagerType::State_Initialized);
AMS_ASSERT(impl.IsEmpty());
AMS_UNUSED(impl);
/* Mark not initialized. */
manager->state = WaitableManagerType::State_NotInitialized;

View file

@ -42,8 +42,10 @@ namespace ams::diag {
AMS_CALL_ASSERT_FAIL_IMPL(#expr, ## __VA_ARGS__); \
} \
})
#else
#elif defined(AMS_PRESERVE_ASSERTION_EXPRESSIONS)
#define AMS_ASSERT_IMPL(expr, ...) AMS_UNUSED(expr, ## __VA_ARGS__)
#else
#define AMS_ASSERT_IMPL(expr, ...) static_cast<void>(0)
#endif
#define AMS_ASSERT(expr, ...) AMS_ASSERT_IMPL(expr, ## __VA_ARGS__)
@ -52,8 +54,10 @@ namespace ams::diag {
#ifdef AMS_BUILD_FOR_AUDITING
#define AMS_AUDIT(expr, ...) AMS_ASSERT(expr, ## __VA_ARGS__)
#else
#elif defined(AMS_PRESERVE_AUDIT_EXPRESSIONS)
#define AMS_AUDIT(expr, ...) AMS_UNUSED(expr, ## __VA_ARGS__)
#else
#define AMS_AUDIT(expr, ...) static_cast<void>(0)
#endif
#define AMS_ABORT(...) AMS_CALL_ABORT_IMPL("", ## __VA_ARGS__)

View file

@ -65,6 +65,7 @@ namespace ams::crypto {
bool Verify(const void *signature, size_t size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { this->state = State::Done; };
impl::RsaPssImpl<Hash> impl;
@ -85,6 +86,7 @@ namespace ams::crypto {
bool Verify(const void *signature, size_t size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { this->state = State::Done; };
impl::RsaPssImpl<Hash> impl;
@ -105,6 +107,7 @@ namespace ams::crypto {
bool VerifyWithHash(const void *signature, size_t size, const void *hash, size_t hash_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { this->state = State::Done; };
impl::RsaPssImpl<Hash> impl;
@ -121,6 +124,7 @@ namespace ams::crypto {
bool VerifyWithHash(const void *signature, size_t size, const void *hash, size_t hash_size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { this->state = State::Done; };
impl::RsaPssImpl<Hash> impl;

View file

@ -71,6 +71,7 @@ namespace ams::crypto::impl {
this->count += num;
AMS_ASSERT(words == this->buffer);
AMS_UNUSED(words);
}
public:
constexpr ALWAYS_INLINE WordAllocator(Word *buf, size_t c) : buffer(buf), count(c), max_count(c), min_count(c) { /* ... */ }

View file

@ -96,6 +96,7 @@ namespace ams::crypto::impl {
size_t Update(void *_dst, size_t dst_size, const void *_src, size_t src_size) {
AMS_ASSERT(this->state == State_Initialized);
AMS_ASSERT(dst_size >= src_size);
AMS_UNUSED(dst_size);
u8 *dst = static_cast<u8 *>(_dst);
const u8 *src = static_cast<const u8 *>(_src);

View file

@ -99,6 +99,7 @@ namespace ams::crypto::impl {
inline void HmacImpl<Hash>::GetMac(void *dst, size_t dst_size) {
AMS_ASSERT(this->state == State_Initialized || this->state == State_Done);
AMS_ASSERT(dst_size >= MacSize);
AMS_UNUSED(dst_size);
/* If we're not already finalized, get the final mac. */
if (this->state == State_Initialized) {

View file

@ -85,6 +85,7 @@ namespace ams::crypto::impl {
AMS_ASSERT(salt_size > 0);
AMS_ASSERT(salt_size == HashSize);
AMS_ASSERT(label_digest_size == HashSize);
AMS_UNUSED(salt_size, label_digest_size);
u8 *buf = static_cast<u8 *>(dst);
buf[0] = HeadMagic;
@ -109,6 +110,7 @@ namespace ams::crypto::impl {
AMS_ABORT_UNLESS(dst_size > 0);
AMS_ABORT_UNLESS(buf_size >= 2 * HashSize + 3);
AMS_ABORT_UNLESS(label_digest_size == HashSize);
AMS_UNUSED(label_digest_size);
/* Validate sanity byte. */
bool is_valid = buf[0] == HeadMagic;

View file

@ -33,6 +33,7 @@ namespace ams::crypto::impl {
private:
static void ComputeHashWithPadding(void *dst, const u8 *user_hash, size_t user_hash_size, const void *salt, size_t salt_size) {
AMS_ASSERT(user_hash_size == HashSize);
AMS_UNUSED(user_hash_size);
/* Initialize our buffer. */
u8 buf[8 + HashSize];

View file

@ -61,6 +61,7 @@ namespace ams::crypto::impl {
void GetBufferedData(void *dst, size_t dst_size) const {
AMS_ASSERT(dst_size >= this->GetBufferedDataSize());
AMS_UNUSED(dst_size);
std::memcpy(dst, this->state.buffer, this->GetBufferedDataSize());
}

View file

@ -65,6 +65,7 @@ namespace ams::crypto::impl {
template<typename BlockCipher>
void Initialize(const BlockCipher *cipher, const void *tweak, size_t tweak_size) {
AMS_ASSERT(tweak_size == IvSize);
AMS_UNUSED(tweak_size);
cipher->EncryptBlock(this->tweak, IvSize, tweak, IvSize);

View file

@ -239,6 +239,7 @@ namespace ams::crypto::impl {
AMS_ASSERT(dst_size >= MacSize);
AMS_ASSERT(this->aad_remaining == 0);
AMS_ASSERT(this->msg_remaining == 0);
AMS_UNUSED(dst_size);
/* If we haven't already done so, compute the final mac. */
if (this->state != State_Done) {

View file

@ -173,6 +173,7 @@ int main(int argc, char **argv)
char os_private[0x60];
const auto os_priv_len = util::SNPrintf(os_private, sizeof(os_private), "%s (%.8s)", firmware_version.display_name, firmware_version.revision);
AMS_ASSERT(static_cast<size_t>(os_priv_len) < sizeof(os_private));
AMS_UNUSED(os_priv_len);
R_ABORT_UNLESS(erpt::srv::SetSerialNumberAndOsVersion(serial_number.str,
strnlen(serial_number.str, sizeof(serial_number.str) - 1) + 1,
@ -187,6 +188,8 @@ int main(int argc, char **argv)
char product_model[0x10];
const auto pm_len = erpt::MakeProductModelString(product_model, sizeof(product_model), settings::system::GetProductModel());
AMS_ASSERT(static_cast<size_t>(pm_len) < sizeof(product_model));
AMS_UNUSED(pm_len);
R_ABORT_UNLESS(erpt::srv::SetProductModel(product_model, static_cast<u32>(std::strlen(product_model))));
}