strat: use m_ for member variables

This commit is contained in:
Michael Scire
2021-10-10 00:14:06 -07:00
parent ce28591ab2
commit a595c232b9
425 changed files with 8531 additions and 8484 deletions

View File

@@ -28,20 +28,20 @@ namespace ams::erpt::srv {
return attachment_name;
}
Attachment::Attachment(JournalRecord<AttachmentInfo> *r) : record(r) {
this->record->AddReference();
Attachment::Attachment(JournalRecord<AttachmentInfo> *r) : m_record(r) {
m_record->AddReference();
}
Attachment::~Attachment() {
this->CloseStream();
if (this->record->RemoveReference()) {
if (m_record->RemoveReference()) {
this->DeleteStream(this->FileName().name);
delete this->record;
delete m_record;
}
}
AttachmentFileName Attachment::FileName() const {
return FileName(this->record->info.attachment_id);
return FileName(m_record->m_info.attachment_id);
}
Result Attachment::Open(AttachmentOpenType type) {
@@ -65,13 +65,13 @@ namespace ams::erpt::srv {
}
Result Attachment::GetFlags(AttachmentFlagSet *out) const {
*out = this->record->info.flags;
*out = m_record->m_info.flags;
return ResultSuccess();
}
Result Attachment::SetFlags(AttachmentFlagSet flags) {
if (((~this->record->info.flags) & flags).IsAnySet()) {
this->record->info.flags |= flags;
if (((~m_record->m_info.flags) & flags).IsAnySet()) {
m_record->m_info.flags |= flags;
return Journal::Commit();
}
return ResultSuccess();

View File

@@ -30,7 +30,7 @@ namespace ams::erpt::srv {
class Attachment : public Allocator, public Stream {
private:
JournalRecord<AttachmentInfo> *record;
JournalRecord<AttachmentInfo> *m_record;
private:
AttachmentFileName FileName() const;
public:

View File

@@ -19,7 +19,7 @@
namespace ams::erpt::srv {
AttachmentImpl::AttachmentImpl() : attachment(nullptr) {
AttachmentImpl::AttachmentImpl() : m_attachment(nullptr) {
/* ... */
}
@@ -28,52 +28,52 @@ namespace ams::erpt::srv {
}
Result AttachmentImpl::Open(const AttachmentId &attachment_id) {
R_UNLESS(this->attachment == nullptr, erpt::ResultAlreadyInitialized());
R_UNLESS(m_attachment == nullptr, erpt::ResultAlreadyInitialized());
JournalRecord<AttachmentInfo> *record = Journal::Retrieve(attachment_id);
R_UNLESS(record != nullptr, erpt::ResultNotFound());
this->attachment = new Attachment(record);
R_UNLESS(this->attachment != nullptr, erpt::ResultOutOfMemory());
auto attachment_guard = SCOPE_GUARD { delete this->attachment; this->attachment = nullptr; };
m_attachment = new Attachment(record);
R_UNLESS(m_attachment != nullptr, erpt::ResultOutOfMemory());
auto attachment_guard = SCOPE_GUARD { delete m_attachment; m_attachment = nullptr; };
R_TRY(this->attachment->Open(AttachmentOpenType_Read));
R_TRY(m_attachment->Open(AttachmentOpenType_Read));
attachment_guard.Cancel();
return ResultSuccess();
}
Result AttachmentImpl::Read(ams::sf::Out<u32> out_count, const ams::sf::OutBuffer &out_buffer) {
R_UNLESS(this->attachment != nullptr, erpt::ResultNotInitialized());
R_UNLESS(m_attachment != nullptr, erpt::ResultNotInitialized());
return this->attachment->Read(out_count.GetPointer(), static_cast<u8 *>(out_buffer.GetPointer()), static_cast<u32>(out_buffer.GetSize()));
return m_attachment->Read(out_count.GetPointer(), static_cast<u8 *>(out_buffer.GetPointer()), static_cast<u32>(out_buffer.GetSize()));
}
Result AttachmentImpl::SetFlags(AttachmentFlagSet flags) {
R_UNLESS(this->attachment != nullptr, erpt::ResultNotInitialized());
R_UNLESS(m_attachment != nullptr, erpt::ResultNotInitialized());
return this->attachment->SetFlags(flags);
return m_attachment->SetFlags(flags);
}
Result AttachmentImpl::GetFlags(ams::sf::Out<AttachmentFlagSet> out) {
R_UNLESS(this->attachment != nullptr, erpt::ResultNotInitialized());
R_UNLESS(m_attachment != nullptr, erpt::ResultNotInitialized());
return this->attachment->GetFlags(out.GetPointer());
return m_attachment->GetFlags(out.GetPointer());
}
Result AttachmentImpl::Close() {
if (this->attachment != nullptr) {
this->attachment->Close();
delete this->attachment;
this->attachment = nullptr;
if (m_attachment != nullptr) {
m_attachment->Close();
delete m_attachment;
m_attachment = nullptr;
}
return ResultSuccess();
}
Result AttachmentImpl::GetSize(ams::sf::Out<s64> out) {
R_UNLESS(this->attachment != nullptr, erpt::ResultNotInitialized());
R_UNLESS(m_attachment != nullptr, erpt::ResultNotInitialized());
return this->attachment->GetSize(out.GetPointer());
return m_attachment->GetSize(out.GetPointer());
}
}

View File

@@ -22,7 +22,7 @@ namespace ams::erpt::srv {
class AttachmentImpl {
private:
Attachment *attachment;
Attachment *m_attachment;
public:
AttachmentImpl();
~AttachmentImpl();

View File

@@ -18,7 +18,7 @@
namespace ams::erpt::srv {
u8 Cipher::s_key[crypto::Aes128CtrEncryptor::KeySize + crypto::Aes128CtrEncryptor::IvSize + crypto::Aes128CtrEncryptor::BlockSize];
bool Cipher::s_need_to_store_cipher = false;
constinit u8 Cipher::s_key[crypto::Aes128CtrEncryptor::KeySize + crypto::Aes128CtrEncryptor::IvSize + crypto::Aes128CtrEncryptor::BlockSize];
constinit bool Cipher::s_need_to_store_cipher = false;
}

View File

@@ -25,11 +25,11 @@ namespace ams::erpt::srv {
using ContextList = util::IntrusiveListBaseTraits<Context>::ListType;
ContextList g_category_list;
constinit ContextList g_category_list;
}
Context::Context(CategoryId cat, u32 max_records) : category(cat), max_record_count(max_records), record_count(0) {
Context::Context(CategoryId cat, u32 max_records) : m_category(cat), m_max_record_count(max_records), m_record_count(0) {
g_category_list.push_front(*this);
}
@@ -38,12 +38,12 @@ namespace ams::erpt::srv {
}
Result Context::AddCategoryToReport(Report *report) {
R_SUCCEED_IF(this->record_list.empty());
R_SUCCEED_IF(m_record_list.empty());
for (auto it = this->record_list.begin(); it != this->record_list.end(); it++) {
for (u32 i = 0; i < it->ctx.field_count; i++) {
auto *field = std::addressof(it->ctx.fields[i]);
u8 *arr_buf = it->ctx.array_buffer;
for (auto it = m_record_list.begin(); it != m_record_list.end(); it++) {
for (u32 i = 0; i < it->m_ctx.field_count; i++) {
auto *field = std::addressof(it->m_ctx.fields[i]);
u8 *arr_buf = it->m_ctx.array_buffer;
switch (field->type) {
case FieldType_Bool: R_TRY(Cipher::AddField(report, field->id, field->value_bool)); break;
@@ -81,13 +81,13 @@ namespace ams::erpt::srv {
}
Result Context::AddContextRecordToCategory(std::unique_ptr<ContextRecord> record) {
if (this->record_count < this->max_record_count) {
this->record_list.push_front(*record.release());
this->record_count++;
if (m_record_count < m_max_record_count) {
m_record_list.push_front(*record.release());
m_record_count++;
} else {
ContextRecord *back = std::addressof(this->record_list.back());
this->record_list.pop_back();
this->record_list.push_front(*record.release());
ContextRecord *back = std::addressof(m_record_list.back());
m_record_list.pop_back();
m_record_list.push_front(*record.release());
delete back;
}
@@ -96,7 +96,7 @@ namespace ams::erpt::srv {
Result Context::SubmitContext(const ContextEntry *entry, const u8 *data, u32 data_size) {
auto it = util::range::find_if(g_category_list, [&](const Context &cur) {
return cur.category == entry->category;
return cur.m_category == entry->category;
});
R_UNLESS(it != g_category_list.end(), erpt::ResultCategoryNotFound());
@@ -105,7 +105,7 @@ namespace ams::erpt::srv {
Result Context::SubmitContextRecord(std::unique_ptr<ContextRecord> record) {
auto it = util::range::find_if(g_category_list, [&](const Context &cur) {
return cur.category == record->ctx.category;
return cur.m_category == record->m_ctx.category;
});
R_UNLESS(it != g_category_list.end(), erpt::ResultCategoryNotFound());

View File

@@ -25,10 +25,10 @@ namespace ams::erpt::srv {
class Context : public Allocator, public util::IntrusiveListBaseNode<Context> {
private:
const CategoryId category;
const u32 max_record_count;
u32 record_count;
util::IntrusiveListBaseTraits<ContextRecord>::ListType record_list;
const CategoryId m_category;
const u32 m_max_record_count;
u32 m_record_count;
util::IntrusiveListBaseTraits<ContextRecord>::ListType m_record_list;
public:
Context(CategoryId cat, u32 max_records);
~Context();

View File

@@ -18,7 +18,7 @@
namespace ams::erpt::srv {
u32 ContextRecord::s_record_count = 0;
constinit u32 ContextRecord::s_record_count = 0;
namespace {
@@ -34,56 +34,56 @@ namespace ams::erpt::srv {
}
ContextRecord::ContextRecord() {
this->ctx = {};
m_ctx = {};
}
ContextRecord::ContextRecord(CategoryId category, u32 array_buf_size) {
this->ctx = {
m_ctx = {
.category = category,
.array_buffer = static_cast<u8 *>(Allocate(array_buf_size)),
};
if (this->ctx.array_buffer != nullptr) {
this->ctx.array_buffer_size = array_buf_size;
this->ctx.array_free_count = array_buf_size;
if (m_ctx.array_buffer != nullptr) {
m_ctx.array_buffer_size = array_buf_size;
m_ctx.array_free_count = array_buf_size;
}
}
ContextRecord::~ContextRecord() {
if (this->ctx.array_buffer != nullptr) {
Deallocate(this->ctx.array_buffer);
if (m_ctx.array_buffer != nullptr) {
Deallocate(m_ctx.array_buffer);
}
AMS_ABORT_UNLESS(s_record_count >= this->ctx.field_count);
s_record_count -= this->ctx.field_count;
AMS_ABORT_UNLESS(s_record_count >= m_ctx.field_count);
s_record_count -= m_ctx.field_count;
}
Result ContextRecord::Initialize(const ContextEntry *ctx_ptr, const u8 *data, u32 data_size) {
R_UNLESS(data_size <= ArrayBufferSizeMax, erpt::ResultInvalidArgument());
this->ctx.version = ctx_ptr->version;
this->ctx.field_count = ctx_ptr->field_count;
this->ctx.category = ctx_ptr->category;
this->ctx.array_buffer = nullptr;
this->ctx.array_buffer_size = data_size;
this->ctx.array_free_count = 0;
m_ctx.version = ctx_ptr->version;
m_ctx.field_count = ctx_ptr->field_count;
m_ctx.category = ctx_ptr->category;
m_ctx.array_buffer = nullptr;
m_ctx.array_buffer_size = data_size;
m_ctx.array_free_count = 0;
auto guard = SCOPE_GUARD { this->ctx.field_count = 0; };
auto guard = SCOPE_GUARD { m_ctx.field_count = 0; };
R_UNLESS(this->ctx.field_count <= FieldsPerContext, erpt::ResultInvalidArgument());
R_UNLESS(0 <= this->ctx.category && this->ctx.category < CategoryId_Count, erpt::ResultInvalidArgument());
R_UNLESS(m_ctx.field_count <= FieldsPerContext, erpt::ResultInvalidArgument());
R_UNLESS(0 <= m_ctx.category && m_ctx.category < CategoryId_Count, erpt::ResultInvalidArgument());
for (u32 i = 0; i < this->ctx.field_count; i++) {
this->ctx.fields[i] = ctx_ptr->fields[i];
for (u32 i = 0; i < m_ctx.field_count; i++) {
m_ctx.fields[i] = ctx_ptr->fields[i];
R_UNLESS(0 <= this->ctx.fields[i].id && this->ctx.fields[i].id < FieldId_Count, erpt::ResultInvalidArgument());
R_UNLESS(0 <= this->ctx.fields[i].type && this->ctx.fields[i].type < FieldType_Count, erpt::ResultInvalidArgument());
R_UNLESS(0 <= m_ctx.fields[i].id && m_ctx.fields[i].id < FieldId_Count, erpt::ResultInvalidArgument());
R_UNLESS(0 <= m_ctx.fields[i].type && m_ctx.fields[i].type < FieldType_Count, erpt::ResultInvalidArgument());
R_UNLESS(this->ctx.fields[i].type == FieldToTypeMap[this->ctx.fields[i].id], erpt::ResultFieldTypeMismatch());
R_UNLESS(this->ctx.category == FieldToCategoryMap[this->ctx.fields[i].id], erpt::ResultFieldCategoryMismatch());
R_UNLESS(m_ctx.fields[i].type == FieldToTypeMap[m_ctx.fields[i].id], erpt::ResultFieldTypeMismatch());
R_UNLESS(m_ctx.category == FieldToCategoryMap[m_ctx.fields[i].id], erpt::ResultFieldCategoryMismatch());
if (IsArrayFieldType(this->ctx.fields[i].type)) {
const u32 start_idx = this->ctx.fields[i].value_array.start_idx;
const u32 size = this->ctx.fields[i].value_array.size;
if (IsArrayFieldType(m_ctx.fields[i].type)) {
const u32 start_idx = m_ctx.fields[i].value_array.start_idx;
const u32 size = m_ctx.fields[i].value_array.size;
const u32 end_idx = start_idx + size;
R_UNLESS(start_idx <= data_size, erpt::ResultInvalidArgument());
@@ -95,25 +95,25 @@ namespace ams::erpt::srv {
if (data_size > 0) {
/* If array buffer isn't nullptr, we'll leak memory here, so verify that it is. */
AMS_ABORT_UNLESS(this->ctx.array_buffer == nullptr);
AMS_ABORT_UNLESS(m_ctx.array_buffer == nullptr);
this->ctx.array_buffer = static_cast<u8 *>(AllocateWithAlign(data_size, alignof(u64)));
R_UNLESS(this->ctx.array_buffer != nullptr, erpt::ResultOutOfMemory());
m_ctx.array_buffer = static_cast<u8 *>(AllocateWithAlign(data_size, alignof(u64)));
R_UNLESS(m_ctx.array_buffer != nullptr, erpt::ResultOutOfMemory());
std::memcpy(this->ctx.array_buffer, data, data_size);
std::memcpy(m_ctx.array_buffer, data, data_size);
}
guard.Cancel();
s_record_count += this->ctx.field_count;
s_record_count += m_ctx.field_count;
return ResultSuccess();
}
Result ContextRecord::Add(FieldId field_id, bool value_bool) {
R_UNLESS(this->ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
R_UNLESS(m_ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
s_record_count++;
auto &field = this->ctx.fields[this->ctx.field_count++];
auto &field = m_ctx.fields[m_ctx.field_count++];
field.id = field_id;
field.type = FieldType_Bool;
@@ -124,10 +124,10 @@ namespace ams::erpt::srv {
}
Result ContextRecord::Add(FieldId field_id, u32 value_u32) {
R_UNLESS(this->ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
R_UNLESS(m_ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
s_record_count++;
auto &field = this->ctx.fields[this->ctx.field_count++];
auto &field = m_ctx.fields[m_ctx.field_count++];
field.id = field_id;
field.type = FieldType_NumericU32;
@@ -138,10 +138,10 @@ namespace ams::erpt::srv {
}
Result ContextRecord::Add(FieldId field_id, u64 value_u64) {
R_UNLESS(this->ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
R_UNLESS(m_ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
s_record_count++;
auto &field = this->ctx.fields[this->ctx.field_count++];
auto &field = m_ctx.fields[m_ctx.field_count++];
field.id = field_id;
field.type = FieldType_NumericU64;
@@ -152,10 +152,10 @@ namespace ams::erpt::srv {
}
Result ContextRecord::Add(FieldId field_id, s32 value_i32) {
R_UNLESS(this->ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
R_UNLESS(m_ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
s_record_count++;
auto &field = this->ctx.fields[this->ctx.field_count++];
auto &field = m_ctx.fields[m_ctx.field_count++];
field.id = field_id;
field.type = FieldType_NumericI32;
@@ -166,10 +166,10 @@ namespace ams::erpt::srv {
}
Result ContextRecord::Add(FieldId field_id, s64 value_i64) {
R_UNLESS(this->ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
R_UNLESS(m_ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
s_record_count++;
auto &field = this->ctx.fields[this->ctx.field_count++];
auto &field = m_ctx.fields[m_ctx.field_count++];
field.id = field_id;
field.type = FieldType_NumericI64;
@@ -180,14 +180,14 @@ namespace ams::erpt::srv {
}
Result ContextRecord::Add(FieldId field_id, const void *arr, u32 size, FieldType type) {
R_UNLESS(this->ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
R_UNLESS(size <= this->ctx.array_free_count, erpt::ResultOutOfArraySpace());
R_UNLESS(m_ctx.field_count < FieldsPerContext, erpt::ResultOutOfFieldSpace());
R_UNLESS(size <= m_ctx.array_free_count, erpt::ResultOutOfArraySpace());
const u32 start_idx = this->ctx.array_buffer_size - this->ctx.array_free_count;
this->ctx.array_free_count -= size;
const u32 start_idx = m_ctx.array_buffer_size - m_ctx.array_free_count;
m_ctx.array_free_count -= size;
s_record_count++;
auto &field = this->ctx.fields[this->ctx.field_count++];
auto &field = m_ctx.fields[m_ctx.field_count++];
field.id = field_id;
field.type = type;
@@ -197,7 +197,7 @@ namespace ams::erpt::srv {
.size = size,
};
std::memcpy(this->ctx.array_buffer + start_idx, arr, size);
std::memcpy(m_ctx.array_buffer + start_idx, arr, size);
return ResultSuccess();
}

View File

@@ -30,7 +30,7 @@ namespace ams::erpt::srv {
return s_record_count;
}
private:
ContextEntry ctx;
ContextEntry m_ctx;
private:
Result Add(FieldId field_id, const void *arr, u32 size, FieldType type);
public:
@@ -39,7 +39,7 @@ namespace ams::erpt::srv {
~ContextRecord();
const ContextEntry *GetContextEntryPtr() const {
return std::addressof(this->ctx);
return std::addressof(m_ctx);
}
Result Initialize(const ContextEntry *ctx_ptr, const u8 *data, u32 data_size);

View File

@@ -19,9 +19,9 @@
namespace ams::erpt::srv {
util::IntrusiveListBaseTraits<JournalRecord<AttachmentInfo>>::ListType JournalForAttachments::s_attachment_list;
u32 JournalForAttachments::s_attachment_count = 0;
u32 JournalForAttachments::s_used_storage = 0;
constinit util::IntrusiveListBaseTraits<JournalRecord<AttachmentInfo>>::ListType JournalForAttachments::s_attachment_list;
constinit u32 JournalForAttachments::s_attachment_count = 0;
constinit u32 JournalForAttachments::s_used_storage = 0;
namespace {
@@ -34,7 +34,7 @@ namespace ams::erpt::srv {
auto *record = std::addressof(*it);
it = s_attachment_list.erase(s_attachment_list.iterator_to(*record));
if (record->RemoveReference()) {
Stream::DeleteStream(Attachment::FileName(record->info.attachment_id).name);
Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name);
delete record;
}
}
@@ -48,7 +48,7 @@ namespace ams::erpt::srv {
Result JournalForAttachments::CommitJournal(Stream *stream) {
R_TRY(stream->WriteStream(reinterpret_cast<const u8 *>(std::addressof(s_attachment_count)), sizeof(s_attachment_count)));
for (auto it = s_attachment_list.crbegin(); it != s_attachment_list.crend(); it++) {
R_TRY(stream->WriteStream(reinterpret_cast<const u8 *>(std::addressof(it->info)), sizeof(it->info)));
R_TRY(stream->WriteStream(reinterpret_cast<const u8 *>(std::addressof(it->m_info)), sizeof(it->m_info)));
}
return ResultSuccess();
}
@@ -56,17 +56,17 @@ namespace ams::erpt::srv {
Result JournalForAttachments::DeleteAttachments(ReportId report_id) {
for (auto it = s_attachment_list.begin(); it != s_attachment_list.end(); /* ... */) {
auto *record = std::addressof(*it);
if (record->info.owner_report_id == report_id) {
if (record->m_info.owner_report_id == report_id) {
/* Erase from the list. */
it = s_attachment_list.erase(s_attachment_list.iterator_to(*record));
/* Update storage tracking counts. */
--s_attachment_count;
s_used_storage -= static_cast<u32>(record->info.attachment_size);
s_used_storage -= static_cast<u32>(record->m_info.attachment_size);
/* Delete the object, if we should. */
if (record->RemoveReference()) {
Stream::DeleteStream(Attachment::FileName(record->info.attachment_id).name);
Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name);
delete record;
}
} else {
@@ -80,8 +80,8 @@ namespace ams::erpt::srv {
Result JournalForAttachments::GetAttachmentList(AttachmentList *out, ReportId report_id) {
u32 count = 0;
for (auto it = s_attachment_list.cbegin(); it != s_attachment_list.cend() && count < util::size(out->attachments); it++) {
if (report_id == it->info.owner_report_id) {
out->attachments[count++] = it->info;
if (report_id == it->m_info.owner_report_id) {
out->attachments[count++] = it->m_info;
}
}
out->attachment_count = count;
@@ -118,17 +118,17 @@ namespace ams::erpt::srv {
auto record_guard = SCOPE_GUARD { delete record; };
if (R_FAILED(Stream::GetStreamSize(std::addressof(record->info.attachment_size), Attachment::FileName(record->info.attachment_id).name))) {
if (R_FAILED(Stream::GetStreamSize(std::addressof(record->m_info.attachment_size), Attachment::FileName(record->m_info.attachment_id).name))) {
continue;
}
if (record->info.flags.Test<AttachmentFlag::HasOwner>() && JournalForReports::RetrieveRecord(record->info.owner_report_id) != nullptr) {
if (record->m_info.flags.Test<AttachmentFlag::HasOwner>() && JournalForReports::RetrieveRecord(record->m_info.owner_report_id) != nullptr) {
/* NOTE: Nintendo does not check the result of storing the new record... */
record_guard.Cancel();
StoreRecord(record);
} else {
/* If the attachment has no owner (or we deleted the report), delete the file associated with it. */
Stream::DeleteStream(Attachment::FileName(record->info.attachment_id).name);
Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name);
}
}
@@ -138,7 +138,7 @@ namespace ams::erpt::srv {
JournalRecord<AttachmentInfo> *JournalForAttachments::RetrieveRecord(AttachmentId attachment_id) {
for (auto it = s_attachment_list.begin(); it != s_attachment_list.end(); it++) {
if (auto *record = std::addressof(*it); record->info.attachment_id == attachment_id) {
if (auto *record = std::addressof(*it); record->m_info.attachment_id == attachment_id) {
return record;
}
}
@@ -148,11 +148,11 @@ namespace ams::erpt::srv {
Result JournalForAttachments::SetOwner(AttachmentId attachment_id, ReportId report_id) {
for (auto it = s_attachment_list.begin(); it != s_attachment_list.end(); it++) {
auto *record = std::addressof(*it);
if (record->info.attachment_id == attachment_id) {
R_UNLESS(!record->info.flags.Test<AttachmentFlag::HasOwner>(), erpt::ResultAlreadyOwned());
if (record->m_info.attachment_id == attachment_id) {
R_UNLESS(!record->m_info.flags.Test<AttachmentFlag::HasOwner>(), erpt::ResultAlreadyOwned());
record->info.owner_report_id = report_id;
record->info.flags.Set<AttachmentFlag::HasOwner>();
record->m_info.owner_report_id = report_id;
record->m_info.flags.Set<AttachmentFlag::HasOwner>();
return ResultSuccess();
}
}
@@ -162,7 +162,7 @@ namespace ams::erpt::srv {
Result JournalForAttachments::StoreRecord(JournalRecord<AttachmentInfo> *record) {
/* Check if the record already exists. */
for (auto it = s_attachment_list.begin(); it != s_attachment_list.end(); it++) {
R_UNLESS(it->info.attachment_id != record->info.attachment_id, erpt::ResultAlreadyExists());
R_UNLESS(it->m_info.attachment_id != record->m_info.attachment_id, erpt::ResultAlreadyExists());
}
/* Add a reference to the new record. */
@@ -171,7 +171,7 @@ namespace ams::erpt::srv {
/* Push the record into the list. */
s_attachment_list.push_front(*record);
s_attachment_count++;
s_used_storage += static_cast<u32>(record->info.attachment_size);
s_used_storage += static_cast<u32>(record->m_info.attachment_size);
return ResultSuccess();
}

View File

@@ -18,7 +18,7 @@
namespace ams::erpt::srv {
JournalMeta JournalForMeta::s_journal_meta;
constinit JournalMeta JournalForMeta::s_journal_meta;
void JournalForMeta::InitializeJournal() {
std::memset(std::addressof(s_journal_meta), 0, sizeof(s_journal_meta));

View File

@@ -19,17 +19,17 @@
namespace ams::erpt::srv {
util::IntrusiveListBaseTraits<JournalRecord<ReportInfo>>::ListType JournalForReports::s_record_list;
u32 JournalForReports::s_record_count = 0;
u32 JournalForReports::s_record_count_by_type[ReportType_Count] = {};
u32 JournalForReports::s_used_storage = 0;
constinit util::IntrusiveListBaseTraits<JournalRecord<ReportInfo>>::ListType JournalForReports::s_record_list;
constinit u32 JournalForReports::s_record_count = 0;
constinit u32 JournalForReports::s_record_count_by_type[ReportType_Count] = {};
constinit u32 JournalForReports::s_used_storage = 0;
void JournalForReports::CleanupReports() {
for (auto it = s_record_list.begin(); it != s_record_list.end(); /* ... */) {
auto *record = std::addressof(*it);
it = s_record_list.erase(s_record_list.iterator_to(*record));
if (record->RemoveReference()) {
Stream::DeleteStream(Report::FileName(record->info.id, false).name);
Stream::DeleteStream(Report::FileName(record->m_info.id, false).name);
delete record;
}
}
@@ -44,7 +44,7 @@ namespace ams::erpt::srv {
Result JournalForReports::CommitJournal(Stream *stream) {
R_TRY(stream->WriteStream(reinterpret_cast<const u8 *>(std::addressof(s_record_count)), sizeof(s_record_count)));
for (auto it = s_record_list.crbegin(); it != s_record_list.crend(); it++) {
R_TRY(stream->WriteStream(reinterpret_cast<const u8 *>(std::addressof(it->info)), sizeof(it->info)));
R_TRY(stream->WriteStream(reinterpret_cast<const u8 *>(std::addressof(it->m_info)), sizeof(it->m_info)));
}
return ResultSuccess();
}
@@ -55,22 +55,22 @@ namespace ams::erpt::srv {
/* Update storage tracking counts. */
--s_record_count;
--s_record_count_by_type[record->info.type];
s_used_storage -= static_cast<u32>(record->info.report_size);
--s_record_count_by_type[record->m_info.type];
s_used_storage -= static_cast<u32>(record->m_info.report_size);
/* If we should increment count, do so. */
if (increment_count) {
JournalForMeta::IncrementCount(record->info.flags.Test<ReportFlag::Transmitted>(), record->info.type);
JournalForMeta::IncrementCount(record->m_info.flags.Test<ReportFlag::Transmitted>(), record->m_info.type);
}
/* Delete any attachments. */
if (force_delete_attachments || record->info.flags.Test<ReportFlag::HasAttachment>()) {
JournalForAttachments::DeleteAttachments(record->info.id);
if (force_delete_attachments || record->m_info.flags.Test<ReportFlag::HasAttachment>()) {
JournalForAttachments::DeleteAttachments(record->m_info.id);
}
/* Delete the object, if we should. */
if (record->RemoveReference()) {
Stream::DeleteStream(Report::FileName(record->info.id, false).name);
Stream::DeleteStream(Report::FileName(record->m_info.id, false).name);
delete record;
}
}
@@ -78,7 +78,7 @@ namespace ams::erpt::srv {
Result JournalForReports::DeleteReport(ReportId report_id) {
for (auto it = s_record_list.begin(); it != s_record_list.end(); it++) {
auto *record = std::addressof(*it);
if (record->info.id == report_id) {
if (record->m_info.id == report_id) {
EraseReportImpl(record, false, false);
return ResultSuccess();
}
@@ -89,7 +89,7 @@ namespace ams::erpt::srv {
Result JournalForReports::DeleteReportWithAttachments() {
for (auto it = s_record_list.rbegin(); it != s_record_list.rend(); it++) {
auto *record = std::addressof(*it);
if (record->info.flags.Test<ReportFlag::HasAttachment>()) {
if (record->m_info.flags.Test<ReportFlag::HasAttachment>()) {
EraseReportImpl(record, true, true);
return ResultSuccess();
}
@@ -100,7 +100,7 @@ namespace ams::erpt::srv {
s64 JournalForReports::GetMaxReportSize() {
s64 max_size = 0;
for (auto it = s_record_list.begin(); it != s_record_list.end(); it++) {
max_size = std::max(max_size, it->info.report_size);
max_size = std::max(max_size, it->m_info.report_size);
}
return max_size;
}
@@ -108,8 +108,8 @@ namespace ams::erpt::srv {
Result JournalForReports::GetReportList(ReportList *out, ReportType type_filter) {
u32 count = 0;
for (auto it = s_record_list.cbegin(); it != s_record_list.cend() && count < util::size(out->reports); it++) {
if (type_filter == ReportType_Any || type_filter == it->info.type) {
out->reports[count++] = it->info;
if (type_filter == ReportType_Any || type_filter == it->m_info.type) {
out->reports[count++] = it->m_info;
}
}
out->report_count = count;
@@ -158,8 +158,8 @@ namespace ams::erpt::srv {
/* We will ensure it is freed if we early error. */
auto record_guard = SCOPE_GUARD { delete record; };
if (record->info.report_size == 0) {
R_UNLESS(R_SUCCEEDED(Stream::GetStreamSize(std::addressof(record->info.report_size), Report::FileName(record->info.id, false).name)), erpt::ResultCorruptJournal());
if (record->m_info.report_size == 0) {
R_UNLESS(R_SUCCEEDED(Stream::GetStreamSize(std::addressof(record->m_info.report_size), Report::FileName(record->m_info.id, false).name)), erpt::ResultCorruptJournal());
}
record_guard.Cancel();
@@ -174,7 +174,7 @@ namespace ams::erpt::srv {
JournalRecord<ReportInfo> *JournalForReports::RetrieveRecord(ReportId report_id) {
for (auto it = s_record_list.begin(); it != s_record_list.end(); it++) {
if (auto *record = std::addressof(*it); record->info.id == report_id) {
if (auto *record = std::addressof(*it); record->m_info.id == report_id) {
return record;
}
}
@@ -185,14 +185,14 @@ namespace ams::erpt::srv {
Result JournalForReports::StoreRecord(JournalRecord<ReportInfo> *record) {
/* Check if the record already exists. */
for (auto it = s_record_list.begin(); it != s_record_list.end(); it++) {
R_UNLESS(it->info.id != record->info.id, erpt::ResultAlreadyExists());
R_UNLESS(it->m_info.id != record->m_info.id, erpt::ResultAlreadyExists());
}
/* Delete an older report if we need to. */
if (s_record_count >= ReportCountMax) {
/* Nintendo deletes the oldest report from the type with the most reports. */
/* This is an approximation of FIFO. */
ReportType most_used_type = record->info.type;
ReportType most_used_type = record->m_info.type;
u32 most_used_count = s_record_count_by_type[most_used_type];
for (int i = ReportType_Start; i < ReportType_End; i++) {
@@ -203,7 +203,7 @@ namespace ams::erpt::srv {
}
for (auto it = s_record_list.rbegin(); it != s_record_list.rend(); it++) {
if (it->info.type != most_used_type) {
if (it->m_info.type != most_used_type) {
continue;
}
@@ -219,8 +219,8 @@ namespace ams::erpt::srv {
/* Push the record into the list. */
s_record_list.push_front(*record);
s_record_count++;
s_record_count_by_type[record->info.type]++;
s_used_storage += static_cast<u32>(record->info.report_size);
s_record_count_by_type[record->m_info.type]++;
s_used_storage += static_cast<u32>(record->m_info.report_size);
return ResultSuccess();
}

View File

@@ -23,13 +23,13 @@ namespace ams::erpt::srv {
template<typename Info>
class JournalRecord : public Allocator, public RefCount, public util::IntrusiveListBaseNode<JournalRecord<Info>> {
public:
Info info;
Info m_info;
JournalRecord() {
std::memset(std::addressof(this->info), 0, sizeof(this->info));
std::memset(std::addressof(m_info), 0, sizeof(m_info));
}
explicit JournalRecord(Info info) : info(info) { /* ... */ }
explicit JournalRecord(Info info) : m_info(info) { /* ... */ }
};

View File

@@ -24,8 +24,8 @@
namespace ams::erpt::srv {
lmem::HeapHandle g_heap_handle;
ams::sf::ExpHeapAllocator g_sf_allocator;
constinit lmem::HeapHandle g_heap_handle;
constinit ams::sf::ExpHeapAllocator g_sf_allocator;
namespace {

View File

@@ -23,11 +23,11 @@ namespace ams::erpt::srv {
using ManagerList = util::IntrusiveListBaseTraits<ManagerImpl>::ListType;
ManagerList g_manager_list;
constinit ManagerList g_manager_list;
}
ManagerImpl::ManagerImpl() : system_event(os::EventClearMode_AutoClear, true) {
ManagerImpl::ManagerImpl() : m_system_event(os::EventClearMode_AutoClear, true) {
g_manager_list.push_front(*this);
}
@@ -36,7 +36,7 @@ namespace ams::erpt::srv {
}
void ManagerImpl::NotifyOne() {
this->system_event.Signal();
m_system_event.Signal();
}
Result ManagerImpl::NotifyAll() {
@@ -53,7 +53,7 @@ namespace ams::erpt::srv {
}
Result ManagerImpl::GetEvent(ams::sf::OutCopyHandle out) {
out.SetValue(this->system_event.GetReadableHandle(), false);
out.SetValue(m_system_event.GetReadableHandle(), false);
return ResultSuccess();
}

View File

@@ -20,7 +20,7 @@ namespace ams::erpt::srv {
class ManagerImpl : public util::IntrusiveListBaseNode<ManagerImpl> {
private:
os::SystemEvent system_event;
os::SystemEvent m_system_event;
public:
ManagerImpl();
~ManagerImpl();

View File

@@ -21,17 +21,17 @@ namespace ams::erpt::srv {
class RefCount {
private:
static constexpr u32 MaxReferenceCount = 1000;
std::atomic<u32> ref_count;
std::atomic<u32> m_ref_count;
public:
RefCount() : ref_count(0) { /* ... */ }
RefCount() : m_ref_count(0) { /* ... */ }
void AddReference() {
const auto prev = this->ref_count.fetch_add(1);
const auto prev = m_ref_count.fetch_add(1);
AMS_ABORT_UNLESS(prev <= MaxReferenceCount);
}
bool RemoveReference() {
auto prev = this->ref_count.fetch_sub(1);
auto prev = m_ref_count.fetch_sub(1);
AMS_ABORT_UNLESS(prev != 0);
return prev == 1;
}

View File

@@ -34,20 +34,20 @@ namespace ams::erpt::srv {
return report_name;
}
Report::Report(JournalRecord<ReportInfo> *r, bool redirect_to_sd) : record(r), redirect_to_sd_card(redirect_to_sd) {
this->record->AddReference();
Report::Report(JournalRecord<ReportInfo> *r, bool redirect_to_sd) : m_record(r), m_redirect_to_sd_card(redirect_to_sd) {
m_record->AddReference();
}
Report::~Report() {
this->CloseStream();
if (this->record->RemoveReference()) {
if (m_record->RemoveReference()) {
this->DeleteStream(this->FileName().name);
delete this->record;
delete m_record;
}
}
ReportFileName Report::FileName() const {
return FileName(this->record->info.id, this->redirect_to_sd_card);
return FileName(m_record->m_info.id, m_redirect_to_sd_card);
}
Result Report::Open(ReportOpenType type) {
@@ -71,13 +71,13 @@ namespace ams::erpt::srv {
}
Result Report::GetFlags(ReportFlagSet *out) const {
*out = this->record->info.flags;
*out = m_record->m_info.flags;
return ResultSuccess();
}
Result Report::SetFlags(ReportFlagSet flags) {
if (((~this->record->info.flags) & flags).IsAnySet()) {
this->record->info.flags |= flags;
if (((~m_record->m_info.flags) & flags).IsAnySet()) {
m_record->m_info.flags |= flags;
return Journal::Commit();
}
return ResultSuccess();

View File

@@ -30,8 +30,8 @@ namespace ams::erpt::srv {
class Report : public Allocator, public Stream {
private:
JournalRecord<ReportInfo> *record;
bool redirect_to_sd_card;
JournalRecord<ReportInfo> *m_record;
bool m_redirect_to_sd_card;
private:
ReportFileName FileName() const;
public:

View File

@@ -19,7 +19,7 @@
namespace ams::erpt::srv {
ReportImpl::ReportImpl() : report(nullptr) {
ReportImpl::ReportImpl() : m_report(nullptr) {
/* ... */
}
@@ -28,52 +28,52 @@ namespace ams::erpt::srv {
}
Result ReportImpl::Open(const ReportId &report_id) {
R_UNLESS(this->report == nullptr, erpt::ResultAlreadyInitialized());
R_UNLESS(m_report == nullptr, erpt::ResultAlreadyInitialized());
JournalRecord<ReportInfo> *record = Journal::Retrieve(report_id);
R_UNLESS(record != nullptr, erpt::ResultNotFound());
this->report = new Report(record, false);
R_UNLESS(this->report != nullptr, erpt::ResultOutOfMemory());
auto report_guard = SCOPE_GUARD { delete this->report; this->report = nullptr; };
m_report = new Report(record, false);
R_UNLESS(m_report != nullptr, erpt::ResultOutOfMemory());
auto report_guard = SCOPE_GUARD { delete m_report; m_report = nullptr; };
R_TRY(this->report->Open(ReportOpenType_Read));
R_TRY(m_report->Open(ReportOpenType_Read));
report_guard.Cancel();
return ResultSuccess();
}
Result ReportImpl::Read(ams::sf::Out<u32> out_count, const ams::sf::OutBuffer &out_buffer) {
R_UNLESS(this->report != nullptr, erpt::ResultNotInitialized());
R_UNLESS(m_report != nullptr, erpt::ResultNotInitialized());
return this->report->Read(out_count.GetPointer(), static_cast<u8 *>(out_buffer.GetPointer()), static_cast<u32>(out_buffer.GetSize()));
return m_report->Read(out_count.GetPointer(), static_cast<u8 *>(out_buffer.GetPointer()), static_cast<u32>(out_buffer.GetSize()));
}
Result ReportImpl::SetFlags(ReportFlagSet flags) {
R_UNLESS(this->report != nullptr, erpt::ResultNotInitialized());
R_UNLESS(m_report != nullptr, erpt::ResultNotInitialized());
return this->report->SetFlags(flags);
return m_report->SetFlags(flags);
}
Result ReportImpl::GetFlags(ams::sf::Out<ReportFlagSet> out) {
R_UNLESS(this->report != nullptr, erpt::ResultNotInitialized());
R_UNLESS(m_report != nullptr, erpt::ResultNotInitialized());
return this->report->GetFlags(out.GetPointer());
return m_report->GetFlags(out.GetPointer());
}
Result ReportImpl::Close() {
if (this->report != nullptr) {
this->report->Close();
delete this->report;
this->report = nullptr;
if (m_report != nullptr) {
m_report->Close();
delete m_report;
m_report = nullptr;
}
return ResultSuccess();
}
Result ReportImpl::GetSize(ams::sf::Out<s64> out) {
R_UNLESS(this->report != nullptr, erpt::ResultNotInitialized());
R_UNLESS(m_report != nullptr, erpt::ResultNotInitialized());
return this->report->GetSize(out.GetPointer());
return m_report->GetSize(out.GetPointer());
}
}

View File

@@ -22,7 +22,7 @@ namespace ams::erpt::srv {
class ReportImpl {
private:
Report *report;
Report *m_report;
public:
ReportImpl();
~ReportImpl();

View File

@@ -356,16 +356,16 @@ namespace ams::erpt::srv {
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
record->AddReference();
record->info.type = type;
record->info.id = report_id;
record->info.flags = erpt::srv::MakeNoReportFlags();
record->info.timestamp_user = timestamp_user;
record->info.timestamp_network = timestamp_network;
record->m_info.type = type;
record->m_info.id = report_id;
record->m_info.flags = erpt::srv::MakeNoReportFlags();
record->m_info.timestamp_user = timestamp_user;
record->m_info.timestamp_network = timestamp_network;
if (meta != nullptr) {
record->info.meta_data = *meta;
record->m_info.meta_data = *meta;
}
if (num_attachments > 0) {
record->info.flags.Set<ReportFlag::HasAttachment>();
record->m_info.flags.Set<ReportFlag::HasAttachment>();
}
auto report = std::make_unique<Report>(record.get(), redirect_new_reports);
@@ -373,7 +373,7 @@ namespace ams::erpt::srv {
auto report_guard = SCOPE_GUARD { report->Delete(); };
R_TRY(Context::WriteContextsToReport(report.get()));
R_TRY(report->GetSize(std::addressof(record->info.report_size)));
R_TRY(report->GetSize(std::addressof(record->m_info.report_size)));
if (!redirect_new_reports) {
/* If we're not redirecting new reports, then we want to store the report in the journal. */

View File

@@ -40,7 +40,7 @@ namespace ams::erpt::srv {
constexpr inline sm::ServiceName ErrorReportContextServiceName = sm::ServiceName::Encode("erpt:c");
constexpr inline sm::ServiceName ErrorReportReportServiceName = sm::ServiceName::Encode("erpt:r");
alignas(os::ThreadStackAlignment) u8 g_server_thread_stack[16_KB];
alignas(os::ThreadStackAlignment) constinit u8 g_server_thread_stack[16_KB];
enum PortIndex {
PortIndex_Report,
@@ -49,8 +49,8 @@ namespace ams::erpt::srv {
class ErrorReportServiceManager : public ams::sf::hipc::ServerManager<ErrorReportNumServers, ErrorReportServerOptions, ErrorReportMaxSessions> {
private:
os::ThreadType thread;
ams::sf::UnmanagedServiceObject<erpt::sf::IContext, erpt::srv::ContextImpl> context_session_object;
os::ThreadType m_thread;
ams::sf::UnmanagedServiceObject<erpt::sf::IContext, erpt::srv::ContextImpl> m_context_session_object;
private:
static void ThreadFunction(void *_this) {
reinterpret_cast<ErrorReportServiceManager *>(_this)->SetupAndLoopProcess();
@@ -67,7 +67,7 @@ namespace ams::erpt::srv {
return this->AcceptImpl(server, intf);
}
case PortIndex_Context:
return AcceptImpl(server, this->context_session_object.GetShared());
return AcceptImpl(server, m_context_session_object.GetShared());
default:
return erpt::ResultNotSupported();
}
@@ -79,16 +79,16 @@ namespace ams::erpt::srv {
this->ResumeProcessing();
R_ABORT_UNLESS(os::CreateThread(std::addressof(this->thread), ThreadFunction, this, g_server_thread_stack, sizeof(g_server_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(erpt, IpcServer)));
os::SetThreadNamePointer(std::addressof(this->thread), AMS_GET_SYSTEM_THREAD_NAME(erpt, IpcServer));
R_ABORT_UNLESS(os::CreateThread(std::addressof(m_thread), ThreadFunction, this, g_server_thread_stack, sizeof(g_server_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(erpt, IpcServer)));
os::SetThreadNamePointer(std::addressof(m_thread), AMS_GET_SYSTEM_THREAD_NAME(erpt, IpcServer));
os::StartThread(std::addressof(this->thread));
os::StartThread(std::addressof(m_thread));
return ResultSuccess();
}
void Wait() {
os::WaitThread(std::addressof(this->thread));
os::WaitThread(std::addressof(m_thread));
}
};
@@ -136,16 +136,17 @@ namespace ams::erpt::srv {
}
}
ErrorReportServiceManager g_erpt_server_manager;
constinit util::TypedStorage<ErrorReportServiceManager> g_erpt_server_manager;
}
Result InitializeService() {
return g_erpt_server_manager.Initialize();
util::ConstructAt(g_erpt_server_manager);
return util::GetReference(g_erpt_server_manager).Initialize();
}
void WaitService() {
return g_erpt_server_manager.Wait();
return util::GetReference(g_erpt_server_manager).Wait();
}
}

View File

@@ -50,7 +50,7 @@ namespace ams::erpt::srv {
return fs::GetFileSize(out, file);
}
Stream::Stream() : buffer_size(0), file_position(0), buffer_count(0), buffer(nullptr), stream_mode(StreamMode_Invalid), initialized(false) {
Stream::Stream() : m_buffer_size(0), m_file_position(0), m_buffer_count(0), m_buffer(nullptr), m_stream_mode(StreamMode_Invalid), m_initialized(false) {
/* ... */
}
@@ -60,8 +60,8 @@ namespace ams::erpt::srv {
}
Result Stream::OpenStream(const char *path, StreamMode mode, u32 buffer_size) {
R_UNLESS(s_can_access_fs, erpt::ResultInvalidPowerState());
R_UNLESS(!this->initialized, erpt::ResultAlreadyInitialized());
R_UNLESS(s_can_access_fs, erpt::ResultInvalidPowerState());
R_UNLESS(!m_initialized, erpt::ResultAlreadyInitialized());
auto lock_guard = SCOPE_GUARD {
if (s_fs_commit_mutex.IsLockedByCurrentThread()) {
@@ -73,7 +73,7 @@ namespace ams::erpt::srv {
s_fs_commit_mutex.Lock();
while (true) {
R_TRY_CATCH(fs::OpenFile(std::addressof(this->file_handle), path, fs::OpenMode_Write | fs::OpenMode_AllowAppend)) {
R_TRY_CATCH(fs::OpenFile(std::addressof(m_file_handle), path, fs::OpenMode_Write | fs::OpenMode_AllowAppend)) {
R_CATCH(fs::ResultPathNotFound) {
R_TRY(fs::CreateFile(path, 0));
continue;
@@ -81,31 +81,31 @@ namespace ams::erpt::srv {
} R_END_TRY_CATCH;
break;
}
fs::SetFileSize(this->file_handle, 0);
fs::SetFileSize(m_file_handle, 0);
} else {
R_UNLESS(mode == StreamMode_Read, erpt::ResultInvalidArgument());
R_TRY(fs::OpenFile(std::addressof(this->file_handle), path, fs::OpenMode_Read));
R_TRY(fs::OpenFile(std::addressof(m_file_handle), path, fs::OpenMode_Read));
}
auto file_guard = SCOPE_GUARD { fs::CloseFile(this->file_handle); };
auto file_guard = SCOPE_GUARD { fs::CloseFile(m_file_handle); };
std::strncpy(this->file_name, path, sizeof(this->file_name));
this->file_name[sizeof(this->file_name) - 1] = '\x00';
std::strncpy(m_file_name, path, sizeof(m_file_name));
m_file_name[sizeof(m_file_name) - 1] = '\x00';
if (buffer_size > 0) {
this->buffer = reinterpret_cast<u8 *>(Allocate(buffer_size));
AMS_ASSERT(this->buffer != nullptr);
m_buffer = reinterpret_cast<u8 *>(Allocate(buffer_size));
AMS_ASSERT(m_buffer != nullptr);
} else {
this->buffer = nullptr;
m_buffer = nullptr;
}
this->buffer_size = this->buffer != nullptr ? buffer_size : 0;
this->buffer_count = 0;
this->buffer_position = 0;
this->file_position = 0;
this->stream_mode = mode;
this->initialized = true;
m_buffer_size = m_buffer != nullptr ? buffer_size : 0;
m_buffer_count = 0;
m_buffer_position = 0;
m_file_position = 0;
m_stream_mode = mode;
m_initialized = true;
file_guard.Cancel();
lock_guard.Cancel();
@@ -113,11 +113,11 @@ namespace ams::erpt::srv {
}
Result Stream::ReadStream(u32 *out, u8 *dst, u32 dst_size) {
R_UNLESS(s_can_access_fs, erpt::ResultInvalidPowerState());
R_UNLESS(this->initialized, erpt::ResultNotInitialized());
R_UNLESS(this->stream_mode == StreamMode_Read, erpt::ResultNotInitialized());
R_UNLESS(out != nullptr, erpt::ResultInvalidArgument());
R_UNLESS(dst != nullptr, erpt::ResultInvalidArgument());
R_UNLESS(s_can_access_fs, erpt::ResultInvalidPowerState());
R_UNLESS(m_initialized, erpt::ResultNotInitialized());
R_UNLESS(m_stream_mode == StreamMode_Read, erpt::ResultNotInitialized());
R_UNLESS(out != nullptr, erpt::ResultInvalidArgument());
R_UNLESS(dst != nullptr, erpt::ResultInvalidArgument());
size_t fs_read_size;
u32 read_count = 0;
@@ -126,30 +126,30 @@ namespace ams::erpt::srv {
*out = read_count;
};
if (this->buffer != nullptr) {
if (m_buffer != nullptr) {
while (dst_size > 0) {
if (u32 cur = std::min<u32>(this->buffer_count - this->buffer_position, dst_size); cur > 0) {
std::memcpy(dst, this->buffer + this->buffer_position, cur);
this->buffer_position += cur;
dst += cur;
dst_size -= cur;
read_count += cur;
if (u32 cur = std::min<u32>(m_buffer_count - m_buffer_position, dst_size); cur > 0) {
std::memcpy(dst, m_buffer + m_buffer_position, cur);
m_buffer_position += cur;
dst += cur;
dst_size -= cur;
read_count += cur;
} else {
R_TRY(fs::ReadFile(std::addressof(fs_read_size), this->file_handle, this->file_position, this->buffer, this->buffer_size));
R_TRY(fs::ReadFile(std::addressof(fs_read_size), m_file_handle, m_file_position, m_buffer, m_buffer_size));
this->buffer_position = 0;
this->file_position += static_cast<u32>(fs_read_size);
this->buffer_count = static_cast<u32>(fs_read_size);
m_buffer_position = 0;
m_file_position += static_cast<u32>(fs_read_size);
m_buffer_count = static_cast<u32>(fs_read_size);
if (this->buffer_count == 0) {
if (m_buffer_count == 0) {
break;
}
}
}
} else {
R_TRY(fs::ReadFile(std::addressof(fs_read_size), this->file_handle, this->file_position, dst, dst_size));
R_TRY(fs::ReadFile(std::addressof(fs_read_size), m_file_handle, m_file_position, dst, dst_size));
this->file_position += static_cast<u32>(fs_read_size);
m_file_position += static_cast<u32>(fs_read_size);
read_count = static_cast<u32>(fs_read_size);
}
@@ -157,47 +157,47 @@ namespace ams::erpt::srv {
}
Result Stream::WriteStream(const u8 *src, u32 src_size) {
R_UNLESS(s_can_access_fs, erpt::ResultInvalidPowerState());
R_UNLESS(this->initialized, erpt::ResultNotInitialized());
R_UNLESS(this->stream_mode == StreamMode_Write, erpt::ResultNotInitialized());
R_UNLESS(src != nullptr || src_size == 0, erpt::ResultInvalidArgument());
R_UNLESS(s_can_access_fs, erpt::ResultInvalidPowerState());
R_UNLESS(m_initialized, erpt::ResultNotInitialized());
R_UNLESS(m_stream_mode == StreamMode_Write, erpt::ResultNotInitialized());
R_UNLESS(src != nullptr || src_size == 0, erpt::ResultInvalidArgument());
if (this->buffer != nullptr) {
if (m_buffer != nullptr) {
while (src_size > 0) {
if (u32 cur = std::min<u32>(this->buffer_size - this->buffer_count, src_size); cur > 0) {
std::memcpy(this->buffer + this->buffer_count, src, cur);
this->buffer_count += cur;
src += cur;
src_size -= cur;
if (u32 cur = std::min<u32>(m_buffer_size - m_buffer_count, src_size); cur > 0) {
std::memcpy(m_buffer + m_buffer_count, src, cur);
m_buffer_count += cur;
src += cur;
src_size -= cur;
}
if (this->buffer_count == this->buffer_size) {
if (m_buffer_count == m_buffer_size) {
R_TRY(this->Flush());
}
}
} else {
R_TRY(fs::WriteFile(this->file_handle, this->file_position, src, src_size, fs::WriteOption::None));
this->file_position += src_size;
R_TRY(fs::WriteFile(m_file_handle, m_file_position, src, src_size, fs::WriteOption::None));
m_file_position += src_size;
}
return ResultSuccess();
}
void Stream::CloseStream() {
if (this->initialized) {
if (m_initialized) {
if (s_can_access_fs) {
if (this->stream_mode == StreamMode_Write) {
if (m_stream_mode == StreamMode_Write) {
this->Flush();
fs::FlushFile(this->file_handle);
fs::FlushFile(m_file_handle);
}
fs::CloseFile(this->file_handle);
fs::CloseFile(m_file_handle);
}
if (this->buffer != nullptr) {
Deallocate(this->buffer);
if (m_buffer != nullptr) {
Deallocate(m_buffer);
}
this->initialized = false;
m_initialized = false;
if (s_fs_commit_mutex.IsLockedByCurrentThread()) {
s_fs_commit_mutex.Unlock();
@@ -206,17 +206,17 @@ namespace ams::erpt::srv {
}
Result Stream::GetStreamSize(s64 *out) const {
return GetStreamSize(out, this->file_name);
return GetStreamSize(out, m_file_name);
}
Result Stream::Flush() {
AMS_ASSERT(s_fs_commit_mutex.IsLockedByCurrentThread());
R_SUCCEED_IF(this->buffer_count == 0);
R_TRY(fs::WriteFile(this->file_handle, this->file_position, this->buffer, this->buffer_count, fs::WriteOption::None));
R_SUCCEED_IF(m_buffer_count == 0);
R_TRY(fs::WriteFile(m_file_handle, m_file_position, m_buffer, m_buffer_count, fs::WriteOption::None));
this->file_position += this->buffer_count;
this->buffer_count = 0;
m_file_position += m_buffer_count;
m_buffer_count = 0;
return ResultSuccess();
}

View File

@@ -29,15 +29,15 @@ namespace ams::erpt::srv {
static bool s_can_access_fs;
static os::SdkMutex s_fs_commit_mutex;
private:
u32 buffer_size;
u32 file_position;
u32 buffer_position;
u32 buffer_count;
u8 *buffer;
StreamMode stream_mode;
bool initialized;
fs::FileHandle file_handle;
char file_name[ReportFileNameLength];
u32 m_buffer_size;
u32 m_file_position;
u32 m_buffer_position;
u32 m_buffer_count;
u8 *m_buffer;
StreamMode m_stream_mode;
bool m_initialized;
fs::FileHandle m_file_handle;
char m_file_name[ReportFileNameLength];
public:
Stream();
~Stream();