ams: revamp assertion system
This commit is contained in:
@@ -87,7 +87,7 @@ namespace ams::sf::cmif {
|
||||
|
||||
inline DomainObjectId GetId(Entry *e) {
|
||||
const size_t index = e - this->entries;
|
||||
AMS_ASSERT(index < this->num_entries);
|
||||
AMS_ABORT_UNLESS(index < this->num_entries);
|
||||
return DomainObjectId{ u32(index + 1) };
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ namespace ams::sf::cmif {
|
||||
ServerMessageRuntimeMetadata impl_metadata;
|
||||
public:
|
||||
DomainServiceObjectProcessor(ServerDomainBase *d, DomainObjectId *in_obj_ids, size_t num_in_objs) : domain(d), in_object_ids(in_obj_ids), num_in_objects(num_in_objs) {
|
||||
AMS_ASSERT(this->domain != nullptr);
|
||||
AMS_ASSERT(this->in_object_ids != nullptr);
|
||||
AMS_ABORT_UNLESS(this->domain != nullptr);
|
||||
AMS_ABORT_UNLESS(this->in_object_ids != nullptr);
|
||||
this->impl_processor = nullptr;
|
||||
this->out_object_ids = nullptr;
|
||||
this->impl_metadata = {};
|
||||
|
||||
@@ -83,11 +83,11 @@ namespace ams::sf::hipc {
|
||||
virtual ~Server() override {
|
||||
if (this->service_managed) {
|
||||
if constexpr (IsMitmServer) {
|
||||
R_ASSERT(sm::mitm::UninstallMitm(this->service_name));
|
||||
R_ABORT_UNLESS(sm::mitm::UninstallMitm(this->service_name));
|
||||
} else {
|
||||
R_ASSERT(sm::UnregisterService(this->service_name));
|
||||
R_ABORT_UNLESS(sm::UnregisterService(this->service_name));
|
||||
}
|
||||
R_ASSERT(svcCloseHandle(this->port_handle));
|
||||
R_ABORT_UNLESS(svcCloseHandle(this->port_handle));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace ams::sf::hipc {
|
||||
|
||||
/* Get mitm forward session. */
|
||||
sm::MitmProcessInfo client_info;
|
||||
R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_info, this->service_name));
|
||||
R_ABORT_UNLESS(sm::mitm::AcknowledgeSession(forward_service.get(), &client_info, this->service_name));
|
||||
|
||||
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(std::shared_ptr<::Service>(forward_service), client_info))));
|
||||
*out_fsrv = std::move(forward_service);
|
||||
@@ -149,7 +149,7 @@ namespace ams::sf::hipc {
|
||||
void RegisterServerImpl(Handle port_handle, sm::ServiceName service_name, bool managed, cmif::ServiceObjectHolder &&static_holder) {
|
||||
/* Allocate server memory. */
|
||||
auto *server = this->AllocateServer();
|
||||
AMS_ASSERT(server != nullptr);
|
||||
AMS_ABORT_UNLESS(server != nullptr);
|
||||
new (server) Server<ServiceImpl, MakeShared>(port_handle, service_name, managed, std::forward<cmif::ServiceObjectHolder>(static_holder));
|
||||
|
||||
if constexpr (!ServiceObjectTraits<ServiceImpl>::IsMitmServiceObject) {
|
||||
@@ -273,13 +273,13 @@ namespace ams::sf::hipc {
|
||||
private:
|
||||
constexpr inline size_t GetServerIndex(const ServerBase *server) const {
|
||||
const size_t i = server - GetPointer(this->server_storages[0]);
|
||||
AMS_ASSERT(i < MaxServers);
|
||||
AMS_ABORT_UNLESS(i < MaxServers);
|
||||
return i;
|
||||
}
|
||||
|
||||
constexpr inline size_t GetSessionIndex(const ServerSession *session) const {
|
||||
const size_t i = session - GetPointer(this->session_storages[0]);
|
||||
AMS_ASSERT(i < MaxSessions);
|
||||
AMS_ABORT_UNLESS(i < MaxSessions);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ namespace ams::sf::hipc {
|
||||
virtual void FreeSession(ServerSession *session) override final {
|
||||
std::scoped_lock lk(this->resource_mutex);
|
||||
const size_t index = this->GetSessionIndex(session);
|
||||
AMS_ASSERT(this->session_allocated[index]);
|
||||
AMS_ABORT_UNLESS(this->session_allocated[index]);
|
||||
this->session_allocated[index] = false;
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace ams::sf::hipc {
|
||||
virtual void DestroyServer(ServerBase *server) override final {
|
||||
std::scoped_lock lk(this->resource_mutex);
|
||||
const size_t index = this->GetServerIndex(server);
|
||||
AMS_ASSERT(this->server_allocated[index]);
|
||||
AMS_ABORT_UNLESS(this->server_allocated[index]);
|
||||
server->~ServerBase();
|
||||
this->server_allocated[index] = false;
|
||||
}
|
||||
@@ -339,8 +339,8 @@ namespace ams::sf::hipc {
|
||||
std::scoped_lock lk(this->resource_mutex);
|
||||
DomainStorage *ptr = static_cast<DomainStorage *>(domain);
|
||||
const size_t index = ptr - this->domain_storages;
|
||||
AMS_ASSERT(index < ManagerOptions::MaxDomains);
|
||||
AMS_ASSERT(this->domain_allocated[index]);
|
||||
AMS_ABORT_UNLESS(index < ManagerOptions::MaxDomains);
|
||||
AMS_ABORT_UNLESS(this->domain_allocated[index]);
|
||||
this->domain_allocated[index] = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,14 +58,14 @@ namespace ams::sf::hipc {
|
||||
this->is_closed = false;
|
||||
this->has_received = false;
|
||||
this->forward_service = nullptr;
|
||||
AMS_ASSERT(!this->IsMitmSession());
|
||||
AMS_ABORT_UNLESS(!this->IsMitmSession());
|
||||
}
|
||||
|
||||
ServerSession(Handle h, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) : WaitableHolder(h), srv_obj_holder(std::move(obj)), session_handle(h) {
|
||||
this->is_closed = false;
|
||||
this->has_received = false;
|
||||
this->forward_service = std::move(fsrv);
|
||||
AMS_ASSERT(this->IsMitmSession());
|
||||
AMS_ABORT_UNLESS(this->IsMitmSession());
|
||||
}
|
||||
|
||||
bool IsMitmSession() const {
|
||||
|
||||
@@ -797,8 +797,8 @@ namespace ams::sf::impl {
|
||||
return;
|
||||
}
|
||||
Handle server_handle, client_handle;
|
||||
R_ASSERT(sf::hipc::CreateSession(&server_handle, &client_handle));
|
||||
R_ASSERT(manager->RegisterSession(server_handle, std::move(object)));
|
||||
R_ABORT_UNLESS(sf::hipc::CreateSession(&server_handle, &client_handle));
|
||||
R_ABORT_UNLESS(manager->RegisterSession(server_handle, std::move(object)));
|
||||
response.move_handles[Index] = client_handle;
|
||||
}
|
||||
|
||||
@@ -1013,7 +1013,7 @@ namespace ams::sf::impl {
|
||||
/* Fake buffer. This is either InData or OutData, but serializing over buffers. */
|
||||
constexpr auto Attributes = CommandMeta::BufferAttributes[Info.buffer_index];
|
||||
if constexpr (Attributes & SfBufferAttr_In) {
|
||||
/* TODO: AMS_ASSERT()? N does not bother. */
|
||||
/* TODO: AMS_ABORT_UNLESS()? N does not bother. */
|
||||
return *reinterpret_cast<const T *>(buffers[Info.buffer_index].GetAddress());
|
||||
} else if constexpr (Attributes & SfBufferAttr_Out) {
|
||||
return T(buffers[Info.buffer_index]);
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace ams::sf {
|
||||
public:
|
||||
constexpr Out(uintptr_t p) : ptr(reinterpret_cast<T *>(p)) { /* ... */ }
|
||||
constexpr Out(T *p) : ptr(p) { /* ... */ }
|
||||
constexpr Out(const cmif::PointerAndSize &pas) : ptr(reinterpret_cast<T *>(pas.GetAddress())) { /* TODO: Is AMS_ASSERT(pas.GetSize() >= sizeof(T)); necessary? */ }
|
||||
constexpr Out(const cmif::PointerAndSize &pas) : ptr(reinterpret_cast<T *>(pas.GetAddress())) { /* TODO: Is AMS_ABORT_UNLESS(pas.GetSize() >= sizeof(T)); necessary? */ }
|
||||
|
||||
void SetValue(const T& value) const {
|
||||
*this->ptr = value;
|
||||
|
||||
Reference in New Issue
Block a user