Skip to content

Commit

Permalink
erpt: remove deprecated fields, they didn't actually change IDs, just…
Browse files Browse the repository at this point in the history
… the mapping between id and name table index
  • Loading branch information
SciresM committed Oct 12, 2023
1 parent 05259b7 commit 71d0274
Show file tree
Hide file tree
Showing 10 changed files with 719 additions and 1,406 deletions.
1,303 changes: 681 additions & 622 deletions libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp

Large diffs are not rendered by default.

This file was deleted.

12 changes: 0 additions & 12 deletions libraries/libstratosphere/include/stratosphere/erpt/erpt_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <stratosphere/os.hpp>
#include <stratosphere/time/time_posix_time.hpp>
#include <stratosphere/erpt/erpt_ids.autogen.hpp>
#include <stratosphere/erpt/erpt_ids_deprecated.autogen.hpp>

namespace ams::erpt {

Expand Down Expand Up @@ -49,17 +48,6 @@ namespace ams::erpt {

#undef GENERATE_ENUM

#define GENERATE_ENUM(NAME, ID, ...) DeprecatedFieldId_##NAME = ID,

enum DeprecatedFieldId {
AMS_ERPT_FOREACH_DEPRECATED_FIELD(GENERATE_ENUM)
DeprecatedFieldId_Count,
};

#undef GENERATE_ENUM

#define ERPT_FIELD_ID(NAME) (::ams::hos::GetVersion() >= ::ams::hos::Version_17_0_0 ? ::ams::erpt::FieldId_##NAME : static_cast<::ams::erpt::FieldId>(::ams::util::ToUnderlying(::ams::erpt::DeprecatedFieldId_##NAME)))

constexpr inline u32 ArrayBufferSizeDefault = 0x100;
constexpr inline u32 ArrayBufferSizeMax = 96_KB;
constexpr inline u32 ArrayFieldSizeMax = 16_KB - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ namespace ams::erpt::srv {
AMS_ERPT_FOREACH_FIELD(STRINGIZE_HANDLER)
};

constexpr inline const char * const DeprecatedFieldString[] = {
AMS_ERPT_FOREACH_DEPRECATED_FIELD(STRINGIZE_HANDLER)
};

constexpr inline const char * const CategoryString[] = {
AMS_ERPT_FOREACH_CATEGORY(STRINGIZE_HANDLER)
};
Expand Down Expand Up @@ -80,49 +76,16 @@ namespace ams::erpt::srv {
};
#undef GET_FIELD_FLAG

#define GET_FIELD_CATEGORY(FIELD, ID, CATEGORY, TYPE, FLAG) [DeprecatedFieldId_##FIELD] = CategoryId_##CATEGORY,
constexpr inline const CategoryId DeprecatedFieldToCategoryMap[] = {
AMS_ERPT_FOREACH_DEPRECATED_FIELD(GET_FIELD_CATEGORY)
};
#undef GET_FIELD_CATEGORY

#define GET_FIELD_TYPE(FIELD, ID, CATEGORY, TYPE, FLAG) [DeprecatedFieldId_##FIELD] = TYPE,
constexpr inline const FieldType DeprecatedFieldToTypeMap[] = {
AMS_ERPT_FOREACH_DEPRECATED_FIELD(GET_FIELD_TYPE)
};
#undef GET_FIELD_TYPE

#define GET_FIELD_FLAG(FIELD, ID, CATEGORY, TYPE, FLAG) [DeprecatedFieldId_##FIELD] = FLAG,
constexpr inline const FieldFlag DeprecatedFieldToFlagMap[] = {
AMS_ERPT_FOREACH_DEPRECATED_FIELD(GET_FIELD_FLAG)
};
#undef GET_FIELD_FLAG

inline CategoryId ConvertFieldToCategory(FieldId id) {
if (hos::GetVersion() >= hos::Version_17_0_0) {
return FieldToCategoryMap[id];
} else {
AMS_ABORT_UNLESS(util::ToUnderlying(id) < util::ToUnderlying(DeprecatedFieldId_Count));
return DeprecatedFieldToCategoryMap[id];
}
return FieldToCategoryMap[id];
}

inline FieldType ConvertFieldToType(FieldId id) {
if (hos::GetVersion() >= hos::Version_17_0_0) {
return FieldToTypeMap[id];
} else {
AMS_ABORT_UNLESS(util::ToUnderlying(id) < util::ToUnderlying(DeprecatedFieldId_Count));
return DeprecatedFieldToTypeMap[id];
}
return FieldToTypeMap[id];
}

inline FieldFlag ConvertFieldToFlag(FieldId id) {
if (hos::GetVersion() >= hos::Version_17_0_0) {
return FieldToFlagMap[id];
} else {
AMS_ABORT_UNLESS(util::ToUnderlying(id) < util::ToUnderlying(DeprecatedFieldId_Count));
return DeprecatedFieldToFlagMap[id];
}
return FieldToFlagMap[id];
}

constexpr inline ReportFlagSet MakeNoReportFlags() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace ams::erpt::srv {
oaep.Encrypt(cipher, sizeof(cipher), s_key, sizeof(s_key), salt, sizeof(salt));
}

Formatter::AddField(report, ERPT_FIELD_ID(CipherKey), cipher, sizeof(cipher));
Formatter::AddField(report, FieldId_CipherKey, cipher, sizeof(cipher));
std::memset(s_key, 0, sizeof(s_key));

R_RETURN(Formatter::End(report));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ namespace ams::erpt::srv {
for (u32 i = 0; i < m_ctx.field_count; i++) {
m_ctx.fields[i] = ctx_ptr->fields[i];

R_UNLESS(0 <= m_ctx.fields[i].id && m_ctx.fields[i].id < ERPT_FIELD_ID(Count), erpt::ResultInvalidArgument());
R_UNLESS(0 <= m_ctx.fields[i].type && m_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(m_ctx.fields[i].type == ConvertFieldToType(m_ctx.fields[i].id), erpt::ResultFieldTypeMismatch());
R_UNLESS(m_ctx.category == ConvertFieldToCategory(m_ctx.fields[i].id), erpt::ResultFieldCategoryMismatch());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace ams::erpt::srv {
err::GetErrorCodeString(error_code_str, sizeof(error_code_str), err::ConvertResultToErrorCode(err::ResultForcedShutdownDetected()));

/* Add error code to the context. */
R_TRY(record->Add(ERPT_FIELD_ID(ErrorCode), error_code_str, std::strlen(error_code_str)));
R_TRY(record->Add(FieldId_ErrorCode, error_code_str, std::strlen(error_code_str)));

/* Create report. */
R_TRY(Reporter::CreateReport(ReportType_Invisible, ResultSuccess(), std::move(record), nullptr, nullptr, 0, erpt::srv::MakeNoCreateReportOptionFlags()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ namespace ams::erpt::srv {
static Result AddId(Report *report, FieldId field_id) {
static_assert(MaxFieldStringSize < ElementSize_256);

if (hos::GetVersion() >= hos::Version_17_0_0) {
R_TRY(AddStringValue(report, FieldString[field_id], strnlen(FieldString[field_id], MaxFieldStringSize)));
} else {
R_TRY(AddStringValue(report, DeprecatedFieldString[field_id], strnlen(DeprecatedFieldString[field_id], MaxFieldStringSize)));
}
R_TRY(AddStringValue(report, FieldString[field_id], strnlen(FieldString[field_id], MaxFieldStringSize)));

R_SUCCEED();
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace ams::erpt::srv {
auto record = std::make_unique<ContextRecord>(CategoryId_ProductModelInfo);
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());

R_TRY(record->Add(ERPT_FIELD_ID(ProductModel), model, model_len));
R_TRY(record->Add(FieldId_ProductModel, model, model_len));
R_TRY(Context::SubmitContextRecord(std::move(record)));

R_SUCCEED();
Expand All @@ -146,7 +146,7 @@ namespace ams::erpt::srv {
auto record = std::make_unique<ContextRecord>(CategoryId_RegionSettingInfo);
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());

R_TRY(record->Add(ERPT_FIELD_ID(RegionSetting), region, region_len));
R_TRY(record->Add(FieldId_RegionSetting, region, region_len));
R_TRY(Context::SubmitContextRecord(std::move(record)));

R_SUCCEED();
Expand Down
56 changes: 28 additions & 28 deletions libraries/libstratosphere/source/erpt/srv/erpt_srv_reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ namespace ams::erpt::srv {
if (error_context_total_size == 0) {
return;
}
record->Add(ERPT_FIELD_ID(ErrorContextTotalSize), error_context_total_size);
record->Add(FieldId_ErrorContextTotalSize, error_context_total_size);

/* Set the context. */
if (error_context_size == 0) {
return;
}
record->Add(ERPT_FIELD_ID(ErrorContextSize), error_context_size);
record->Add(ERPT_FIELD_ID(ErrorContext), error_context, error_context_size);
record->Add(FieldId_ErrorContextSize, error_context_size);
record->Add(FieldId_ErrorContext, error_context, error_context_size);
}

constinit os::SdkMutex g_limit_mutex;
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace ams::erpt::srv {
if (R_FAILED(svc::GetResourceLimitLimitValue(std::addressof(limit_value), handle, svc::LimitableResource_##__RESOURCE__##Max))) { \
return; \
} \
if (R_FAILED(record->Add(ERPT_FIELD_ID(System##__RESOURCE__##Limit), limit_value))) { \
if (R_FAILED(record->Add(FieldId_System##__RESOURCE__##Limit, limit_value))) { \
return; \
} \
} while (0)
Expand Down Expand Up @@ -203,7 +203,7 @@ namespace ams::erpt::srv {
if (R_FAILED(svc::GetResourceLimitPeakValue(std::addressof(peak_value), handle, svc::LimitableResource_##__RESOURCE__##Max))) { \
return; \
} \
if (R_FAILED(record->Add(ERPT_FIELD_ID(System##__RESOURCE__##Peak), peak_value))) { \
if (R_FAILED(record->Add(FieldId_System##__RESOURCE__##Peak, peak_value))) { \
return; \
} \
} while (0)
Expand Down Expand Up @@ -234,7 +234,7 @@ namespace ams::erpt::srv {
R_UNLESS(ctx->field_count <= FieldsPerContext, erpt::ResultInvalidArgument());

const bool found_error_code = util::range::any_of(MakeSpan(ctx->fields, ctx->field_count), [] (const FieldEntry &entry) {
return entry.id == ERPT_FIELD_ID(ErrorCode);
return entry.id == FieldId_ErrorCode;
});
R_UNLESS(found_error_code, erpt::ResultRequiredFieldMissing());

Expand All @@ -249,10 +249,10 @@ namespace ams::erpt::srv {

bool found_abort_flag = false, found_syslog_flag = false;
for (u32 i = 0; i < ctx->field_count; i++) {
if (ctx->fields[i].id == ERPT_FIELD_ID(AbortFlag)) {
if (ctx->fields[i].id == FieldId_AbortFlag) {
found_abort_flag = true;
}
if (ctx->fields[i].id == ERPT_FIELD_ID(HasSyslogFlag)) {
if (ctx->fields[i].id == FieldId_HasSyslogFlag) {
found_syslog_flag = true;
}
if (found_abort_flag && found_syslog_flag) {
Expand All @@ -261,11 +261,11 @@ namespace ams::erpt::srv {
}

if (!found_abort_flag) {
record->Add(ERPT_FIELD_ID(AbortFlag), false);
record->Add(FieldId_AbortFlag, false);
}

if (!found_syslog_flag) {
record->Add(ERPT_FIELD_ID(HasSyslogFlag), true);
record->Add(FieldId_HasSyslogFlag, true);
}

R_TRY(Context::SubmitContextRecord(std::move(record)));
Expand All @@ -277,7 +277,7 @@ namespace ams::erpt::srv {
bool needs_save_syslog = true;
for (u32 i = 0; i < ctx->field_count; i++) {
static_assert(FieldToTypeMap[FieldId_HasSyslogFlag] == FieldType_Bool);
if (ctx->fields[i].id == ERPT_FIELD_ID(HasSyslogFlag) && !ctx->fields[i].value_bool) {
if (ctx->fields[i].id == FieldId_HasSyslogFlag && !ctx->fields[i].value_bool) {
needs_save_syslog = false;
break;
}
Expand All @@ -299,13 +299,13 @@ namespace ams::erpt::srv {

/* Find the program id entry. */
const auto fields_span = MakeSpan(error_info_ctx->fields, error_info_ctx->field_count);
const auto program_id_entry = util::range::find_if(fields_span, [](const FieldEntry &entry) { return entry.id == ERPT_FIELD_ID(ProgramId); });
const auto program_id_entry = util::range::find_if(fields_span, [](const FieldEntry &entry) { return entry.id == FieldId_ProgramId; });
if (program_id_entry == fields_span.end()) {
return;
}

/* Check that the report has abort flag set. */
AMS_ASSERT(util::range::any_of(fields_span, [](const FieldEntry &entry) { return entry.id == ERPT_FIELD_ID(AbortFlag) && entry.value_bool; }));
AMS_ASSERT(util::range::any_of(fields_span, [](const FieldEntry &entry) { return entry.id == FieldId_AbortFlag && entry.value_bool; }));

/* Check that the program id's value is a string. */
AMS_ASSERT(program_id_entry->type == FieldType_String);
Expand Down Expand Up @@ -334,7 +334,7 @@ namespace ams::erpt::srv {
}

/* Add the active applet time. */
const auto result = error_info_auto_record->Add(ERPT_FIELD_ID(AppletTotalActiveTime), (*active_duration).GetSeconds());
const auto result = error_info_auto_record->Add(FieldId_AppletTotalActiveTime, (*active_duration).GetSeconds());
R_ASSERT(result);
}

Expand Down Expand Up @@ -489,28 +489,28 @@ namespace ams::erpt::srv {
R_ABORT_UNLESS(time::GetStandardSteadyClockCurrentTimePoint(std::addressof(steady_clock_current_timepoint)));

/* Add automatic fields. */
auto_record->Add(ERPT_FIELD_ID(OsVersion), s_os_version, util::Strnlen(s_os_version, sizeof(s_os_version)));
auto_record->Add(ERPT_FIELD_ID(PrivateOsVersion), s_private_os_version, util::Strnlen(s_private_os_version, sizeof(s_private_os_version)));
auto_record->Add(ERPT_FIELD_ID(SerialNumber), s_serial_number, util::Strnlen(s_serial_number, sizeof(s_serial_number)));
auto_record->Add(ERPT_FIELD_ID(ReportIdentifier), identifier_str, util::Strnlen(identifier_str, sizeof(identifier_str)));
auto_record->Add(ERPT_FIELD_ID(OccurrenceTimestamp), timestamp_user.value);
auto_record->Add(ERPT_FIELD_ID(OccurrenceTimestampNet), timestamp_network.value);
auto_record->Add(ERPT_FIELD_ID(ReportVisibilityFlag), type == ReportType_Visible);
auto_record->Add(ERPT_FIELD_ID(OccurrenceTick), occurrence_tick.GetInt64Value());
auto_record->Add(ERPT_FIELD_ID(SteadyClockInternalOffset), steady_clock_internal_offset_seconds);
auto_record->Add(ERPT_FIELD_ID(SteadyClockCurrentTimePointValue), steady_clock_current_timepoint.value);
auto_record->Add(ERPT_FIELD_ID(ElapsedTimeSincePowerOn), (occurrence_tick - *s_power_on_time).ToTimeSpan().GetSeconds());
auto_record->Add(ERPT_FIELD_ID(ElapsedTimeSinceLastAwake), (occurrence_tick - *s_awake_time).ToTimeSpan().GetSeconds());
auto_record->Add(FieldId_OsVersion, s_os_version, util::Strnlen(s_os_version, sizeof(s_os_version)));
auto_record->Add(FieldId_PrivateOsVersion, s_private_os_version, util::Strnlen(s_private_os_version, sizeof(s_private_os_version)));
auto_record->Add(FieldId_SerialNumber, s_serial_number, util::Strnlen(s_serial_number, sizeof(s_serial_number)));
auto_record->Add(FieldId_ReportIdentifier, identifier_str, util::Strnlen(identifier_str, sizeof(identifier_str)));
auto_record->Add(FieldId_OccurrenceTimestamp, timestamp_user.value);
auto_record->Add(FieldId_OccurrenceTimestampNet, timestamp_network.value);
auto_record->Add(FieldId_ReportVisibilityFlag, type == ReportType_Visible);
auto_record->Add(FieldId_OccurrenceTick, occurrence_tick.GetInt64Value());
auto_record->Add(FieldId_SteadyClockInternalOffset, steady_clock_internal_offset_seconds);
auto_record->Add(FieldId_SteadyClockCurrentTimePointValue, steady_clock_current_timepoint.value);
auto_record->Add(FieldId_ElapsedTimeSincePowerOn, (occurrence_tick - *s_power_on_time).ToTimeSpan().GetSeconds());
auto_record->Add(FieldId_ElapsedTimeSinceLastAwake, (occurrence_tick - *s_awake_time).ToTimeSpan().GetSeconds());

if (s_initial_launch_settings_completion_time) {
s64 elapsed_seconds;
if (R_SUCCEEDED(time::GetElapsedSecondsBetween(std::addressof(elapsed_seconds), *s_initial_launch_settings_completion_time, steady_clock_current_timepoint))) {
auto_record->Add(ERPT_FIELD_ID(ElapsedTimeSinceInitialLaunch), elapsed_seconds);
auto_record->Add(FieldId_ElapsedTimeSinceInitialLaunch, elapsed_seconds);
}
}

if (s_application_launch_time) {
auto_record->Add(ERPT_FIELD_ID(ApplicationAliveTime), (occurrence_tick - *s_application_launch_time).ToTimeSpan().GetSeconds());
auto_record->Add(FieldId_ApplicationAliveTime, (occurrence_tick - *s_application_launch_time).ToTimeSpan().GetSeconds());
}

/* Submit applet active duration information. */
Expand Down

0 comments on commit 71d0274

Please sign in to comment.