ams: revamp assertion system

This commit is contained in:
Michael Scire 2020-02-22 23:05:14 -08:00
parent 9572fb2ce3
commit 40400aee1f
168 changed files with 1014 additions and 696 deletions

View file

@ -22,7 +22,7 @@ namespace ams::sf::cmif {
Entry *entry = &this->entries.front();
{
std::scoped_lock lk(this->manager->entry_owner_lock);
AMS_ASSERT(entry->owner == this);
AMS_ABORT_UNLESS(entry->owner == this);
entry->owner = nullptr;
}
entry->object.Reset();
@ -41,7 +41,7 @@ namespace ams::sf::cmif {
for (size_t i = 0; i < count; i++) {
Entry *entry = this->manager->entry_manager.AllocateEntry();
R_UNLESS(entry != nullptr, sf::cmif::ResultOutOfDomainEntries());
AMS_ASSERT(entry->owner == nullptr);
AMS_ABORT_UNLESS(entry->owner == nullptr);
out_ids[i] = this->manager->entry_manager.GetId(entry);
}
return ResultSuccess();
@ -54,18 +54,18 @@ namespace ams::sf::cmif {
void ServerDomainManager::Domain::UnreserveIds(const DomainObjectId *ids, size_t count) {
for (size_t i = 0; i < count; i++) {
Entry *entry = this->manager->entry_manager.GetEntry(ids[i]);
AMS_ASSERT(entry != nullptr);
AMS_ASSERT(entry->owner == nullptr);
AMS_ABORT_UNLESS(entry != nullptr);
AMS_ABORT_UNLESS(entry->owner == nullptr);
this->manager->entry_manager.FreeEntry(entry);
}
}
void ServerDomainManager::Domain::RegisterObject(DomainObjectId id, ServiceObjectHolder &&obj) {
Entry *entry = this->manager->entry_manager.GetEntry(id);
AMS_ASSERT(entry != nullptr);
AMS_ABORT_UNLESS(entry != nullptr);
{
std::scoped_lock lk(this->manager->entry_owner_lock);
AMS_ASSERT(entry->owner == nullptr);
AMS_ABORT_UNLESS(entry->owner == nullptr);
entry->owner = this;
this->entries.push_back(*entry);
}
@ -135,8 +135,8 @@ namespace ams::sf::cmif {
void ServerDomainManager::EntryManager::FreeEntry(Entry *entry) {
std::scoped_lock lk(this->lock);
AMS_ASSERT(entry->owner == nullptr);
AMS_ASSERT(!entry->object);
AMS_ABORT_UNLESS(entry->owner == nullptr);
AMS_ABORT_UNLESS(!entry->object);
this->free_list.push_front(*entry);
}
@ -148,8 +148,8 @@ namespace ams::sf::cmif {
const auto id = ids[i];
Entry *entry = this->GetEntry(id);
if (id != InvalidDomainObjectId) {
AMS_ASSERT(entry != nullptr);
AMS_ASSERT(entry->owner == nullptr);
AMS_ABORT_UNLESS(entry != nullptr);
AMS_ABORT_UNLESS(entry->owner == nullptr);
this->free_list.erase(this->free_list.iterator_to(*entry));
}
}

View file

@ -132,7 +132,7 @@ namespace ams::sf::cmif {
/* Write out header. */
constexpr size_t out_header_size = sizeof(CmifDomainOutHeader);
const size_t impl_out_data_total_size = this->GetImplOutDataTotalSize();
AMS_ASSERT(out_header_size + impl_out_data_total_size + sizeof(DomainObjectId) * this->GetOutObjectCount() <= raw_data.GetSize());
AMS_ABORT_UNLESS(out_header_size + impl_out_data_total_size + sizeof(DomainObjectId) * this->GetOutObjectCount() <= raw_data.GetSize());
*reinterpret_cast<CmifDomainOutHeader *>(raw_data.GetPointer()) = CmifDomainOutHeader{ .num_out_objects = static_cast<u32>(this->GetOutObjectCount()), };
/* Set output raw data. */
@ -150,7 +150,7 @@ namespace ams::sf::cmif {
/* Write out header. */
constexpr size_t out_header_size = sizeof(CmifDomainOutHeader);
const size_t impl_out_headers_size = this->GetImplOutHeadersSize();
AMS_ASSERT(out_header_size + impl_out_headers_size <= raw_data.GetSize());
AMS_ABORT_UNLESS(out_header_size + impl_out_headers_size <= raw_data.GetSize());
*reinterpret_cast<CmifDomainOutHeader *>(raw_data.GetPointer()) = CmifDomainOutHeader{ .num_out_objects = 0, };
/* Set output raw data. */
@ -186,7 +186,7 @@ namespace ams::sf::cmif {
}
}
/* TODO: Can we make this error non-fatal? It isn't for N, since they can reserve IDs earlier due to not having to worry about mitm. */
R_ASSERT(this->domain->ReserveIds(reservations, num_unreserved_ids));
R_ABORT_UNLESS(this->domain->ReserveIds(reservations, num_unreserved_ids));
this->domain->ReserveSpecificIds(specific_ids, num_specific_ids);
}

View file

@ -46,7 +46,7 @@ namespace ams::sf::cmif {
/* Forward forwardable results, otherwise ensure we can send result to user. */
R_TRY_CATCH(command_result) {
R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged)
R_CATCH_ALL() { AMS_ASSERT(out_header != nullptr); }
R_CATCH_ALL() { AMS_ABORT_UNLESS(out_header != nullptr); }
} R_END_TRY_CATCH;
/* Write output header to raw data. */
@ -93,7 +93,7 @@ namespace ams::sf::cmif {
return ctx.session->ForwardRequest(ctx);
}
R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged)
R_CATCH_ALL() { AMS_ASSERT(out_header != nullptr); }
R_CATCH_ALL() { AMS_ABORT_UNLESS(out_header != nullptr); }
} R_END_TRY_CATCH;
/* Write output header to raw data. */