1
0
Fork 0

service/ldr: Migrate logging macros (#3867)

* service/ldr: Migrate logging macros

* service/ldr: Fix clang format

* service/ldr: Addressed comment about .c_str() equivalent .data()

* service/ldr: Fix clang format
This commit is contained in:
NarcolepticK 2018-06-23 05:24:05 -04:00 committed by Weiyi Wang
parent f50e505a5a
commit c2efd49997
2 changed files with 148 additions and 149 deletions

View File

@ -131,7 +131,7 @@ ResultCode CROHelper::ApplyRelocationBatch(VAddr batch, u32 symbol_address, bool
ResultCode result = ApplyRelocation(relocation_target, relocation.type, relocation.addend, ResultCode result = ApplyRelocation(relocation_target, relocation.type, relocation.addend,
symbol_address, relocation_target); symbol_address, relocation_target);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation {:08X}", result.raw);
return result; return result;
} }
@ -493,7 +493,7 @@ ResultCode CROHelper::ResetExternalRelocations() {
ResultCode result = ApplyRelocation(relocation_target, relocation.type, relocation.addend, ResultCode result = ApplyRelocation(relocation_target, relocation.type, relocation.addend,
unresolved_symbol, relocation_target); unresolved_symbol, relocation_target);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation {:08X}", result.raw);
return result; return result;
} }
@ -525,7 +525,7 @@ ResultCode CROHelper::ClearExternalRelocations() {
ResultCode result = ClearRelocation(relocation_target, relocation.type); ResultCode result = ClearRelocation(relocation_target, relocation.type);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error clearing relocation %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error clearing relocation {:08X}", result.raw);
return result; return result;
} }
@ -550,7 +550,7 @@ ResultCode CROHelper::ApplyStaticAnonymousSymbolToCRS(VAddr crs_address) {
CROHelper crs(crs_address); CROHelper crs(crs_address);
u32 offset_export_num = GetField(StaticAnonymousSymbolNum); u32 offset_export_num = GetField(StaticAnonymousSymbolNum);
LOG_INFO(Service_LDR, "CRO \"%s\" exports %d static anonymous symbols", ModuleName().data(), NGLOG_INFO(Service_LDR, "CRO \"{}\" exports {} static anonymous symbols", ModuleName(),
offset_export_num); offset_export_num);
for (u32 i = 0; i < offset_export_num; ++i) { for (u32 i = 0; i < offset_export_num; ++i) {
StaticAnonymousSymbolEntry entry; StaticAnonymousSymbolEntry entry;
@ -563,11 +563,11 @@ ResultCode CROHelper::ApplyStaticAnonymousSymbolToCRS(VAddr crs_address) {
} }
u32 symbol_address = SegmentTagToAddress(entry.symbol_position); u32 symbol_address = SegmentTagToAddress(entry.symbol_position);
LOG_TRACE(Service_LDR, "CRO \"%s\" exports 0x%08X to the static module", NGLOG_TRACE(Service_LDR, "CRO \"{}\" exports 0x{:08X} to the static module", ModuleName(),
ModuleName().data(), symbol_address); symbol_address);
ResultCode result = crs.ApplyRelocationBatch(batch_address, symbol_address); ResultCode result = crs.ApplyRelocationBatch(batch_address, symbol_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
@ -603,12 +603,12 @@ ResultCode CROHelper::ApplyInternalRelocations(u32 old_data_segment_address) {
SegmentEntry symbol_segment; SegmentEntry symbol_segment;
GetEntry(relocation.symbol_segment, symbol_segment); GetEntry(relocation.symbol_segment, symbol_segment);
LOG_TRACE(Service_LDR, "Internally relocates 0x%08X with 0x%08X", target_address, NGLOG_TRACE(Service_LDR, "Internally relocates 0x{:08X} with 0x{:08X}", target_address,
symbol_segment.offset); symbol_segment.offset);
ResultCode result = ApplyRelocation(target_address, relocation.type, relocation.addend, ResultCode result = ApplyRelocation(target_address, relocation.type, relocation.addend,
symbol_segment.offset, target_addressB); symbol_segment.offset, target_addressB);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation {:08X}", result.raw);
return result; return result;
} }
} }
@ -628,7 +628,7 @@ ResultCode CROHelper::ClearInternalRelocations() {
ResultCode result = ClearRelocation(target_address, relocation.type); ResultCode result = ClearRelocation(target_address, relocation.type);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error clearing relocation %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error clearing relocation {:08X}", result.raw);
return result; return result;
} }
} }
@ -764,13 +764,12 @@ ResultCode CROHelper::ApplyImportNamedSymbol(VAddr crs_address) {
u32 symbol_address = source.FindExportNamedSymbol(symbol_name); u32 symbol_address = source.FindExportNamedSymbol(symbol_name);
if (symbol_address != 0) { if (symbol_address != 0) {
LOG_TRACE(Service_LDR, "CRO \"%s\" imports \"%s\" from \"%s\"", NGLOG_TRACE(Service_LDR, "CRO \"{}\" imports \"{}\" from \"{}\"",
ModuleName().data(), symbol_name.data(), ModuleName(), symbol_name, source.ModuleName());
source.ModuleName().data());
ResultCode result = ApplyRelocationBatch(relocation_addr, symbol_address); ResultCode result = ApplyRelocationBatch(relocation_addr, symbol_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}",
result.raw); result.raw);
return result; return result;
} }
@ -801,7 +800,7 @@ ResultCode CROHelper::ResetImportNamedSymbol() {
ResultCode result = ApplyRelocationBatch(relocation_addr, unresolved_symbol, true); ResultCode result = ApplyRelocationBatch(relocation_addr, unresolved_symbol, true);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error reseting relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error reseting relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
@ -821,7 +820,7 @@ ResultCode CROHelper::ResetImportIndexedSymbol() {
ResultCode result = ApplyRelocationBatch(relocation_addr, unresolved_symbol, true); ResultCode result = ApplyRelocationBatch(relocation_addr, unresolved_symbol, true);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error reseting relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error reseting relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
@ -841,7 +840,7 @@ ResultCode CROHelper::ResetImportAnonymousSymbol() {
ResultCode result = ApplyRelocationBatch(relocation_addr, unresolved_symbol, true); ResultCode result = ApplyRelocationBatch(relocation_addr, unresolved_symbol, true);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error reseting relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error reseting relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
@ -860,36 +859,35 @@ ResultCode CROHelper::ApplyModuleImport(VAddr crs_address) {
ResultCode result = ResultCode result =
ForEachAutoLinkCRO(crs_address, [&](CROHelper source) -> ResultVal<bool> { ForEachAutoLinkCRO(crs_address, [&](CROHelper source) -> ResultVal<bool> {
if (want_cro_name == source.ModuleName()) { if (want_cro_name == source.ModuleName()) {
LOG_INFO(Service_LDR, "CRO \"%s\" imports %d indexed symbols from \"%s\"", NGLOG_INFO(Service_LDR, "CRO \"{}\" imports {} indexed symbols from \"{}\"",
ModuleName().data(), entry.import_indexed_symbol_num, ModuleName(), entry.import_indexed_symbol_num, source.ModuleName());
source.ModuleName().data());
for (u32 j = 0; j < entry.import_indexed_symbol_num; ++j) { for (u32 j = 0; j < entry.import_indexed_symbol_num; ++j) {
ImportIndexedSymbolEntry im; ImportIndexedSymbolEntry im;
entry.GetImportIndexedSymbolEntry(j, im); entry.GetImportIndexedSymbolEntry(j, im);
ExportIndexedSymbolEntry ex; ExportIndexedSymbolEntry ex;
source.GetEntry(im.index, ex); source.GetEntry(im.index, ex);
u32 symbol_address = source.SegmentTagToAddress(ex.symbol_position); u32 symbol_address = source.SegmentTagToAddress(ex.symbol_position);
LOG_TRACE(Service_LDR, " Imports 0x%08X", symbol_address); NGLOG_TRACE(Service_LDR, " Imports 0x{:08X}", symbol_address);
ResultCode result = ResultCode result =
ApplyRelocationBatch(im.relocation_batch_offset, symbol_address); ApplyRelocationBatch(im.relocation_batch_offset, symbol_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}",
result.raw); result.raw);
return result; return result;
} }
} }
LOG_INFO(Service_LDR, "CRO \"%s\" imports %d anonymous symbols from \"%s\"", NGLOG_INFO(Service_LDR, "CRO \"{}\" imports {} anonymous symbols from \"{}\"",
ModuleName().data(), entry.import_anonymous_symbol_num, ModuleName(), entry.import_anonymous_symbol_num,
source.ModuleName().data()); source.ModuleName());
for (u32 j = 0; j < entry.import_anonymous_symbol_num; ++j) { for (u32 j = 0; j < entry.import_anonymous_symbol_num; ++j) {
ImportAnonymousSymbolEntry im; ImportAnonymousSymbolEntry im;
entry.GetImportAnonymousSymbolEntry(j, im); entry.GetImportAnonymousSymbolEntry(j, im);
u32 symbol_address = source.SegmentTagToAddress(im.symbol_position); u32 symbol_address = source.SegmentTagToAddress(im.symbol_position);
LOG_TRACE(Service_LDR, " Imports 0x%08X", symbol_address); NGLOG_TRACE(Service_LDR, " Imports 0x{:08X}", symbol_address);
ResultCode result = ResultCode result =
ApplyRelocationBatch(im.relocation_batch_offset, symbol_address); ApplyRelocationBatch(im.relocation_batch_offset, symbol_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}",
result.raw); result.raw);
return result; return result;
} }
@ -906,8 +904,8 @@ ResultCode CROHelper::ApplyModuleImport(VAddr crs_address) {
} }
ResultCode CROHelper::ApplyExportNamedSymbol(CROHelper target) { ResultCode CROHelper::ApplyExportNamedSymbol(CROHelper target) {
LOG_DEBUG(Service_LDR, "CRO \"%s\" exports named symbols to \"%s\"", ModuleName().data(), NGLOG_DEBUG(Service_LDR, "CRO \"{}\" exports named symbols to \"{}\"", ModuleName(),
target.ModuleName().data()); target.ModuleName());
u32 target_import_strings_size = target.GetField(ImportStringsSize); u32 target_import_strings_size = target.GetField(ImportStringsSize);
u32 target_symbol_import_num = target.GetField(ImportNamedSymbolNum); u32 target_symbol_import_num = target.GetField(ImportNamedSymbolNum);
for (u32 i = 0; i < target_symbol_import_num; ++i) { for (u32 i = 0; i < target_symbol_import_num; ++i) {
@ -922,10 +920,10 @@ ResultCode CROHelper::ApplyExportNamedSymbol(CROHelper target) {
Memory::ReadCString(entry.name_offset, target_import_strings_size); Memory::ReadCString(entry.name_offset, target_import_strings_size);
u32 symbol_address = FindExportNamedSymbol(symbol_name); u32 symbol_address = FindExportNamedSymbol(symbol_name);
if (symbol_address != 0) { if (symbol_address != 0) {
LOG_TRACE(Service_LDR, " exports symbol \"%s\"", symbol_name.data()); NGLOG_TRACE(Service_LDR, " exports symbol \"{}\"", symbol_name);
ResultCode result = target.ApplyRelocationBatch(relocation_addr, symbol_address); ResultCode result = target.ApplyRelocationBatch(relocation_addr, symbol_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
@ -935,8 +933,8 @@ ResultCode CROHelper::ApplyExportNamedSymbol(CROHelper target) {
} }
ResultCode CROHelper::ResetExportNamedSymbol(CROHelper target) { ResultCode CROHelper::ResetExportNamedSymbol(CROHelper target) {
LOG_DEBUG(Service_LDR, "CRO \"%s\" unexports named symbols to \"%s\"", ModuleName().data(), NGLOG_DEBUG(Service_LDR, "CRO \"{}\" unexports named symbols to \"{}\"", ModuleName(),
target.ModuleName().data()); target.ModuleName());
u32 unresolved_symbol = target.GetOnUnresolvedAddress(); u32 unresolved_symbol = target.GetOnUnresolvedAddress();
u32 target_import_strings_size = target.GetField(ImportStringsSize); u32 target_import_strings_size = target.GetField(ImportStringsSize);
u32 target_symbol_import_num = target.GetField(ImportNamedSymbolNum); u32 target_symbol_import_num = target.GetField(ImportNamedSymbolNum);
@ -952,11 +950,11 @@ ResultCode CROHelper::ResetExportNamedSymbol(CROHelper target) {
Memory::ReadCString(entry.name_offset, target_import_strings_size); Memory::ReadCString(entry.name_offset, target_import_strings_size);
u32 symbol_address = FindExportNamedSymbol(symbol_name); u32 symbol_address = FindExportNamedSymbol(symbol_name);
if (symbol_address != 0) { if (symbol_address != 0) {
LOG_TRACE(Service_LDR, " unexports symbol \"%s\"", symbol_name.data()); NGLOG_TRACE(Service_LDR, " unexports symbol \"{}\"", symbol_name);
ResultCode result = ResultCode result =
target.ApplyRelocationBatch(relocation_addr, unresolved_symbol, true); target.ApplyRelocationBatch(relocation_addr, unresolved_symbol, true);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
@ -976,34 +974,34 @@ ResultCode CROHelper::ApplyModuleExport(CROHelper target) {
if (Memory::ReadCString(entry.name_offset, target_import_string_size) != module_name) if (Memory::ReadCString(entry.name_offset, target_import_string_size) != module_name)
continue; continue;
LOG_INFO(Service_LDR, "CRO \"%s\" exports %d indexed symbols to \"%s\"", module_name.data(), NGLOG_INFO(Service_LDR, "CRO \"{}\" exports {} indexed symbols to \"{}\"", module_name,
entry.import_indexed_symbol_num, target.ModuleName().data()); entry.import_indexed_symbol_num, target.ModuleName());
for (u32 j = 0; j < entry.import_indexed_symbol_num; ++j) { for (u32 j = 0; j < entry.import_indexed_symbol_num; ++j) {
ImportIndexedSymbolEntry im; ImportIndexedSymbolEntry im;
entry.GetImportIndexedSymbolEntry(j, im); entry.GetImportIndexedSymbolEntry(j, im);
ExportIndexedSymbolEntry ex; ExportIndexedSymbolEntry ex;
GetEntry(im.index, ex); GetEntry(im.index, ex);
u32 symbol_address = SegmentTagToAddress(ex.symbol_position); u32 symbol_address = SegmentTagToAddress(ex.symbol_position);
LOG_TRACE(Service_LDR, " exports symbol 0x%08X", symbol_address); NGLOG_TRACE(Service_LDR, " exports symbol 0x{:08X}", symbol_address);
ResultCode result = ResultCode result =
target.ApplyRelocationBatch(im.relocation_batch_offset, symbol_address); target.ApplyRelocationBatch(im.relocation_batch_offset, symbol_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
LOG_INFO(Service_LDR, "CRO \"%s\" exports %d anonymous symbols to \"%s\"", NGLOG_INFO(Service_LDR, "CRO \"{}\" exports {} anonymous symbols to \"{}\"", module_name,
module_name.data(), entry.import_anonymous_symbol_num, target.ModuleName().data()); entry.import_anonymous_symbol_num, target.ModuleName());
for (u32 j = 0; j < entry.import_anonymous_symbol_num; ++j) { for (u32 j = 0; j < entry.import_anonymous_symbol_num; ++j) {
ImportAnonymousSymbolEntry im; ImportAnonymousSymbolEntry im;
entry.GetImportAnonymousSymbolEntry(j, im); entry.GetImportAnonymousSymbolEntry(j, im);
u32 symbol_address = SegmentTagToAddress(im.symbol_position); u32 symbol_address = SegmentTagToAddress(im.symbol_position);
LOG_TRACE(Service_LDR, " exports symbol 0x%08X", symbol_address); NGLOG_TRACE(Service_LDR, " exports symbol 0x{:08X}", symbol_address);
ResultCode result = ResultCode result =
target.ApplyRelocationBatch(im.relocation_batch_offset, symbol_address); target.ApplyRelocationBatch(im.relocation_batch_offset, symbol_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
@ -1025,28 +1023,28 @@ ResultCode CROHelper::ResetModuleExport(CROHelper target) {
if (Memory::ReadCString(entry.name_offset, target_import_string_size) != module_name) if (Memory::ReadCString(entry.name_offset, target_import_string_size) != module_name)
continue; continue;
LOG_DEBUG(Service_LDR, "CRO \"%s\" unexports indexed symbols to \"%s\"", module_name.data(), NGLOG_DEBUG(Service_LDR, "CRO \"{}\" unexports indexed symbols to \"{}\"", module_name,
target.ModuleName().data()); target.ModuleName());
for (u32 j = 0; j < entry.import_indexed_symbol_num; ++j) { for (u32 j = 0; j < entry.import_indexed_symbol_num; ++j) {
ImportIndexedSymbolEntry im; ImportIndexedSymbolEntry im;
entry.GetImportIndexedSymbolEntry(j, im); entry.GetImportIndexedSymbolEntry(j, im);
ResultCode result = ResultCode result =
target.ApplyRelocationBatch(im.relocation_batch_offset, unresolved_symbol, true); target.ApplyRelocationBatch(im.relocation_batch_offset, unresolved_symbol, true);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
LOG_DEBUG(Service_LDR, "CRO \"%s\" unexports anonymous symbols to \"%s\"", NGLOG_DEBUG(Service_LDR, "CRO \"{}\" unexports anonymous symbols to \"{}\"", module_name,
module_name.data(), target.ModuleName().data()); target.ModuleName());
for (u32 j = 0; j < entry.import_anonymous_symbol_num; ++j) { for (u32 j = 0; j < entry.import_anonymous_symbol_num; ++j) {
ImportAnonymousSymbolEntry im; ImportAnonymousSymbolEntry im;
entry.GetImportAnonymousSymbolEntry(j, im); entry.GetImportAnonymousSymbolEntry(j, im);
ResultCode result = ResultCode result =
target.ApplyRelocationBatch(im.relocation_batch_offset, unresolved_symbol, true); target.ApplyRelocationBatch(im.relocation_batch_offset, unresolved_symbol, true);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}", result.raw);
return result; return result;
} }
} }
@ -1071,12 +1069,12 @@ ResultCode CROHelper::ApplyExitRelocations(VAddr crs_address) {
u32 symbol_address = source.FindExportNamedSymbol("nnroAeabiAtexit_"); u32 symbol_address = source.FindExportNamedSymbol("nnroAeabiAtexit_");
if (symbol_address != 0) { if (symbol_address != 0) {
LOG_DEBUG(Service_LDR, "CRO \"%s\" import exit function from \"%s\"", NGLOG_DEBUG(Service_LDR, "CRO \"{}\" import exit function from \"{}\"",
ModuleName().data(), source.ModuleName().data()); ModuleName(), source.ModuleName());
ResultCode result = ApplyRelocationBatch(relocation_addr, symbol_address); ResultCode result = ApplyRelocationBatch(relocation_addr, symbol_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying relocation batch %08X", NGLOG_ERROR(Service_LDR, "Error applying relocation batch {:08X}",
result.raw); result.raw);
return result; return result;
} }
@ -1087,7 +1085,7 @@ ResultCode CROHelper::ApplyExitRelocations(VAddr crs_address) {
return MakeResult<bool>(true); return MakeResult<bool>(true);
}); });
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying exit relocation %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying exit relocation {:08X}", result.raw);
return result; return result;
} }
} }
@ -1118,13 +1116,13 @@ ResultCode CROHelper::Rebase(VAddr crs_address, u32 cro_size, VAddr data_segment
ResultCode result = RebaseHeader(cro_size); ResultCode result = RebaseHeader(cro_size);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error rebasing header %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error rebasing header {:08X}", result.raw);
return result; return result;
} }
result = VerifyStringTableLength(GetField(ModuleNameOffset), GetField(ModuleNameSize)); result = VerifyStringTableLength(GetField(ModuleNameOffset), GetField(ModuleNameSize));
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error verifying module name %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error verifying module name {:08X}", result.raw);
return result; return result;
} }
@ -1133,7 +1131,7 @@ ResultCode CROHelper::Rebase(VAddr crs_address, u32 cro_size, VAddr data_segment
auto result_val = RebaseSegmentTable(cro_size, data_segment_addresss, data_segment_size, auto result_val = RebaseSegmentTable(cro_size, data_segment_addresss, data_segment_size,
bss_segment_address, bss_segment_size); bss_segment_address, bss_segment_size);
if (result_val.Failed()) { if (result_val.Failed()) {
LOG_ERROR(Service_LDR, "Error rebasing segment table %08X", result_val.Code().raw); NGLOG_ERROR(Service_LDR, "Error rebasing segment table {:08X}", result_val.Code().raw);
return result_val.Code(); return result_val.Code();
} }
prev_data_segment_address = *result_val; prev_data_segment_address = *result_val;
@ -1141,76 +1139,76 @@ ResultCode CROHelper::Rebase(VAddr crs_address, u32 cro_size, VAddr data_segment
result = RebaseExportNamedSymbolTable(); result = RebaseExportNamedSymbolTable();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error rebasing symbol export table %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error rebasing symbol export table {:08X}", result.raw);
return result; return result;
} }
result = VerifyExportTreeTable(); result = VerifyExportTreeTable();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error verifying export tree %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error verifying export tree {:08X}", result.raw);
return result; return result;
} }
result = VerifyStringTableLength(GetField(ExportStringsOffset), GetField(ExportStringsSize)); result = VerifyStringTableLength(GetField(ExportStringsOffset), GetField(ExportStringsSize));
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error verifying export strings %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error verifying export strings {:08X}", result.raw);
return result; return result;
} }
result = RebaseImportModuleTable(); result = RebaseImportModuleTable();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error rebasing object table %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error rebasing object table {:08X}", result.raw);
return result; return result;
} }
result = ResetExternalRelocations(); result = ResetExternalRelocations();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error resetting all external relocations %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error resetting all external relocations {:08X}", result.raw);
return result; return result;
} }
result = RebaseImportNamedSymbolTable(); result = RebaseImportNamedSymbolTable();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error rebasing symbol import table %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error rebasing symbol import table {:08X}", result.raw);
return result; return result;
} }
result = RebaseImportIndexedSymbolTable(); result = RebaseImportIndexedSymbolTable();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error rebasing index import table %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error rebasing index import table {:08X}", result.raw);
return result; return result;
} }
result = RebaseImportAnonymousSymbolTable(); result = RebaseImportAnonymousSymbolTable();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error rebasing offset import table %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error rebasing offset import table {:08X}", result.raw);
return result; return result;
} }
result = VerifyStringTableLength(GetField(ImportStringsOffset), GetField(ImportStringsSize)); result = VerifyStringTableLength(GetField(ImportStringsOffset), GetField(ImportStringsSize));
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error verifying import strings %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error verifying import strings {:08X}", result.raw);
return result; return result;
} }
if (!is_crs) { if (!is_crs) {
result = ApplyStaticAnonymousSymbolToCRS(crs_address); result = ApplyStaticAnonymousSymbolToCRS(crs_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying offset export to CRS %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying offset export to CRS {:08X}", result.raw);
return result; return result;
} }
} }
result = ApplyInternalRelocations(prev_data_segment_address); result = ApplyInternalRelocations(prev_data_segment_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying internal relocations %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying internal relocations {:08X}", result.raw);
return result; return result;
} }
if (!is_crs) { if (!is_crs) {
result = ApplyExitRelocations(crs_address); result = ApplyExitRelocations(crs_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying exit relocations %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying exit relocations {:08X}", result.raw);
return result; return result;
} }
} }
@ -1282,14 +1280,14 @@ ResultCode CROHelper::Link(VAddr crs_address, bool link_on_load_bug_fix) {
// Imports named symbols from other modules // Imports named symbols from other modules
result = ApplyImportNamedSymbol(crs_address); result = ApplyImportNamedSymbol(crs_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying symbol import %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying symbol import {:08X}", result.raw);
return result; return result;
} }
// Imports indexed and anonymous symbols from other modules // Imports indexed and anonymous symbols from other modules
result = ApplyModuleImport(crs_address); result = ApplyModuleImport(crs_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying module import %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying module import {:08X}", result.raw);
return result; return result;
} }
} }
@ -1307,7 +1305,7 @@ ResultCode CROHelper::Link(VAddr crs_address, bool link_on_load_bug_fix) {
return MakeResult<bool>(true); return MakeResult<bool>(true);
}); });
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying export %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error applying export {:08X}", result.raw);
return result; return result;
} }
@ -1319,21 +1317,21 @@ ResultCode CROHelper::Unlink(VAddr crs_address) {
// Resets all imported named symbols // Resets all imported named symbols
ResultCode result = ResetImportNamedSymbol(); ResultCode result = ResetImportNamedSymbol();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error resetting symbol import %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error resetting symbol import {:08X}", result.raw);
return result; return result;
} }
// Resets all imported indexed symbols // Resets all imported indexed symbols
result = ResetImportIndexedSymbol(); result = ResetImportIndexedSymbol();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error resetting indexed import %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error resetting indexed import {:08X}", result.raw);
return result; return result;
} }
// Resets all imported anonymous symbols // Resets all imported anonymous symbols
result = ResetImportAnonymousSymbol(); result = ResetImportAnonymousSymbol();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error resetting anonymous import %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error resetting anonymous import {:08X}", result.raw);
return result; return result;
} }
@ -1351,7 +1349,7 @@ ResultCode CROHelper::Unlink(VAddr crs_address) {
return MakeResult<bool>(true); return MakeResult<bool>(true);
}); });
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error resetting export %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error resetting export {:08X}", result.raw);
return result; return result;
} }
@ -1361,13 +1359,13 @@ ResultCode CROHelper::Unlink(VAddr crs_address) {
ResultCode CROHelper::ClearRelocations() { ResultCode CROHelper::ClearRelocations() {
ResultCode result = ClearExternalRelocations(); ResultCode result = ClearExternalRelocations();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error clearing external relocations %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error clearing external relocations {:08X}", result.raw);
return result; return result;
} }
result = ClearInternalRelocations(); result = ClearInternalRelocations();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error clearing internal relocations %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error clearing internal relocations {:08X}", result.raw);
return result; return result;
} }
return RESULT_SUCCESS; return RESULT_SUCCESS;

View File

@ -58,51 +58,52 @@ void RO::Initialize(Kernel::HLERequestContext& ctx) {
// All other service functions below have the same issue. // All other service functions below have the same issue.
auto process = rp.PopObject<Kernel::Process>(); auto process = rp.PopObject<Kernel::Process>();
LOG_DEBUG(Service_LDR, "called, crs_buffer_ptr=0x%08X, crs_address=0x%08X, crs_size=0x%X", NGLOG_DEBUG(Service_LDR,
"called, crs_buffer_ptr=0x{:08X}, crs_address=0x{:08X}, crs_size=0x{:X}",
crs_buffer_ptr, crs_address, crs_size); crs_buffer_ptr, crs_address, crs_size);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
ClientSlot* slot = GetSessionData(ctx.Session()); ClientSlot* slot = GetSessionData(ctx.Session());
if (slot->loaded_crs != 0) { if (slot->loaded_crs != 0) {
LOG_ERROR(Service_LDR, "Already initialized"); NGLOG_ERROR(Service_LDR, "Already initialized");
rb.Push(ERROR_ALREADY_INITIALIZED); rb.Push(ERROR_ALREADY_INITIALIZED);
return; return;
} }
if (crs_size < CRO_HEADER_SIZE) { if (crs_size < CRO_HEADER_SIZE) {
LOG_ERROR(Service_LDR, "CRS is too small"); NGLOG_ERROR(Service_LDR, "CRS is too small");
rb.Push(ERROR_BUFFER_TOO_SMALL); rb.Push(ERROR_BUFFER_TOO_SMALL);
return; return;
} }
if (crs_buffer_ptr & Memory::PAGE_MASK) { if (crs_buffer_ptr & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRS original address is not aligned"); NGLOG_ERROR(Service_LDR, "CRS original address is not aligned");
rb.Push(ERROR_MISALIGNED_ADDRESS); rb.Push(ERROR_MISALIGNED_ADDRESS);
return; return;
} }
if (crs_address & Memory::PAGE_MASK) { if (crs_address & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRS mapping address is not aligned"); NGLOG_ERROR(Service_LDR, "CRS mapping address is not aligned");
rb.Push(ERROR_MISALIGNED_ADDRESS); rb.Push(ERROR_MISALIGNED_ADDRESS);
return; return;
} }
if (crs_size & Memory::PAGE_MASK) { if (crs_size & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRS size is not aligned"); NGLOG_ERROR(Service_LDR, "CRS size is not aligned");
rb.Push(ERROR_MISALIGNED_SIZE); rb.Push(ERROR_MISALIGNED_SIZE);
return; return;
} }
if (!VerifyBufferState(*process, crs_buffer_ptr, crs_size)) { if (!VerifyBufferState(*process, crs_buffer_ptr, crs_size)) {
LOG_ERROR(Service_LDR, "CRS original buffer is in invalid state"); NGLOG_ERROR(Service_LDR, "CRS original buffer is in invalid state");
rb.Push(ERROR_INVALID_MEMORY_STATE); rb.Push(ERROR_INVALID_MEMORY_STATE);
return; return;
} }
if (crs_address < Memory::PROCESS_IMAGE_VADDR || if (crs_address < Memory::PROCESS_IMAGE_VADDR ||
crs_address + crs_size > Memory::PROCESS_IMAGE_VADDR_END) { crs_address + crs_size > Memory::PROCESS_IMAGE_VADDR_END) {
LOG_ERROR(Service_LDR, "CRS mapping address is not in the process image region"); NGLOG_ERROR(Service_LDR, "CRS mapping address is not in the process image region");
rb.Push(ERROR_ILLEGAL_ADDRESS); rb.Push(ERROR_ILLEGAL_ADDRESS);
return; return;
} }
@ -117,7 +118,7 @@ void RO::Initialize(Kernel::HLERequestContext& ctx) {
.MapMemoryBlock(crs_address, crs_mem, 0, crs_size, Kernel::MemoryState::Code) .MapMemoryBlock(crs_address, crs_mem, 0, crs_size, Kernel::MemoryState::Code)
.Code(); .Code();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error mapping memory block %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error mapping memory block {:08X}", result.raw);
rb.Push(result); rb.Push(result);
return; return;
} }
@ -125,7 +126,7 @@ void RO::Initialize(Kernel::HLERequestContext& ctx) {
result = result =
process->vm_manager.ReprotectRange(crs_address, crs_size, Kernel::VMAPermission::Read); process->vm_manager.ReprotectRange(crs_address, crs_size, Kernel::VMAPermission::Read);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error reprotecting memory block %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error reprotecting memory block {:08X}", result.raw);
rb.Push(result); rb.Push(result);
return; return;
} }
@ -136,7 +137,7 @@ void RO::Initialize(Kernel::HLERequestContext& ctx) {
// TODO(wwylele): verify this behaviour. This is only seen in the web browser app, // TODO(wwylele): verify this behaviour. This is only seen in the web browser app,
// and the actual behaviour is unclear. "Do nothing" is probably an incorrect implement. // and the actual behaviour is unclear. "Do nothing" is probably an incorrect implement.
// There is also a chance that another issue causes the app passing wrong arguments. // There is also a chance that another issue causes the app passing wrong arguments.
LOG_WARNING(Service_LDR, "crs_buffer_ptr == crs_address (0x%08X)", crs_address); NGLOG_WARNING(Service_LDR, "crs_buffer_ptr == crs_address (0x{:08X})", crs_address);
} }
CROHelper crs(crs_address); CROHelper crs(crs_address);
@ -144,7 +145,7 @@ void RO::Initialize(Kernel::HLERequestContext& ctx) {
result = crs.Rebase(0, crs_size, 0, 0, 0, 0, true); result = crs.Rebase(0, crs_size, 0, 0, 0, 0, true);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error rebasing CRS 0x%08X", result.raw); NGLOG_ERROR(Service_LDR, "Error rebasing CRS 0x{:08X}", result.raw);
rb.Push(result); rb.Push(result);
return; return;
} }
@ -165,7 +166,7 @@ void RO::LoadCRR(Kernel::HLERequestContext& ctx) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_LDR, "(STUBBED) called, crr_buffer_ptr=0x%08X, crr_size=0x%08X", NGLOG_WARNING(Service_LDR, "(STUBBED) called, crr_buffer_ptr=0x{:08X}, crr_size=0x{:08X}",
crr_buffer_ptr, crr_size); crr_buffer_ptr, crr_size);
} }
@ -177,7 +178,7 @@ void RO::UnloadCRR(Kernel::HLERequestContext& ctx) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
LOG_WARNING(Service_LDR, "(STUBBED) called, crr_buffer_ptr=0x%08X", crr_buffer_ptr); NGLOG_WARNING(Service_LDR, "(STUBBED) called, crr_buffer_ptr=0x{:08X}", crr_buffer_ptr);
} }
void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) { void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
@ -195,55 +196,55 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
VAddr crr_address = rp.Pop<u32>(); VAddr crr_address = rp.Pop<u32>();
auto process = rp.PopObject<Kernel::Process>(); auto process = rp.PopObject<Kernel::Process>();
LOG_DEBUG(Service_LDR, NGLOG_DEBUG(Service_LDR,
"called (%s), cro_buffer_ptr=0x%08X, cro_address=0x%08X, cro_size=0x%X, " "called ({}), cro_buffer_ptr=0x{:08X}, cro_address=0x{:08X}, cro_size=0x{:X}, "
"data_segment_address=0x%08X, zero=%d, data_segment_size=0x%X, " "data_segment_address=0x{:08X}, zero={}, data_segment_size=0x{:X}, "
"bss_segment_address=0x%08X, bss_segment_size=0x%X, auto_link=%s, " "bss_segment_address=0x{:08X}, bss_segment_size=0x{:X}, auto_link={}, "
"fix_level=%d, crr_address=0x%08X", "fix_level={}, crr_address=0x{:08X}",
link_on_load_bug_fix ? "new" : "old", cro_buffer_ptr, cro_address, cro_size, link_on_load_bug_fix ? "new" : "old", cro_buffer_ptr, cro_address, cro_size,
data_segment_address, zero, data_segment_size, bss_segment_address, bss_segment_size, data_segment_address, zero, data_segment_size, bss_segment_address,
auto_link ? "true" : "false", fix_level, crr_address); bss_segment_size, auto_link ? "true" : "false", fix_level, crr_address);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
ClientSlot* slot = GetSessionData(ctx.Session()); ClientSlot* slot = GetSessionData(ctx.Session());
if (slot->loaded_crs == 0) { if (slot->loaded_crs == 0) {
LOG_ERROR(Service_LDR, "Not initialized"); NGLOG_ERROR(Service_LDR, "Not initialized");
rb.Push(ERROR_NOT_INITIALIZED); rb.Push(ERROR_NOT_INITIALIZED);
rb.Push<u32>(0); rb.Push<u32>(0);
return; return;
} }
if (cro_size < CRO_HEADER_SIZE) { if (cro_size < CRO_HEADER_SIZE) {
LOG_ERROR(Service_LDR, "CRO too small"); NGLOG_ERROR(Service_LDR, "CRO too small");
rb.Push(ERROR_BUFFER_TOO_SMALL); rb.Push(ERROR_BUFFER_TOO_SMALL);
rb.Push<u32>(0); rb.Push<u32>(0);
return; return;
} }
if (cro_buffer_ptr & Memory::PAGE_MASK) { if (cro_buffer_ptr & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRO original address is not aligned"); NGLOG_ERROR(Service_LDR, "CRO original address is not aligned");
rb.Push(ERROR_MISALIGNED_ADDRESS); rb.Push(ERROR_MISALIGNED_ADDRESS);
rb.Push<u32>(0); rb.Push<u32>(0);
return; return;
} }
if (cro_address & Memory::PAGE_MASK) { if (cro_address & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRO mapping address is not aligned"); NGLOG_ERROR(Service_LDR, "CRO mapping address is not aligned");
rb.Push(ERROR_MISALIGNED_ADDRESS); rb.Push(ERROR_MISALIGNED_ADDRESS);
rb.Push<u32>(0); rb.Push<u32>(0);
return; return;
} }
if (cro_size & Memory::PAGE_MASK) { if (cro_size & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRO size is not aligned"); NGLOG_ERROR(Service_LDR, "CRO size is not aligned");
rb.Push(ERROR_MISALIGNED_SIZE); rb.Push(ERROR_MISALIGNED_SIZE);
rb.Push<u32>(0); rb.Push<u32>(0);
return; return;
} }
if (!VerifyBufferState(*process, cro_buffer_ptr, cro_size)) { if (!VerifyBufferState(*process, cro_buffer_ptr, cro_size)) {
LOG_ERROR(Service_LDR, "CRO original buffer is in invalid state"); NGLOG_ERROR(Service_LDR, "CRO original buffer is in invalid state");
rb.Push(ERROR_INVALID_MEMORY_STATE); rb.Push(ERROR_INVALID_MEMORY_STATE);
rb.Push<u32>(0); rb.Push<u32>(0);
return; return;
@ -251,14 +252,14 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
if (cro_address < Memory::PROCESS_IMAGE_VADDR || if (cro_address < Memory::PROCESS_IMAGE_VADDR ||
cro_address + cro_size > Memory::PROCESS_IMAGE_VADDR_END) { cro_address + cro_size > Memory::PROCESS_IMAGE_VADDR_END) {
LOG_ERROR(Service_LDR, "CRO mapping address is not in the process image region"); NGLOG_ERROR(Service_LDR, "CRO mapping address is not in the process image region");
rb.Push(ERROR_ILLEGAL_ADDRESS); rb.Push(ERROR_ILLEGAL_ADDRESS);
rb.Push<u32>(0); rb.Push<u32>(0);
return; return;
} }
if (zero) { if (zero) {
LOG_ERROR(Service_LDR, "Zero is not zero %d", zero); NGLOG_ERROR(Service_LDR, "Zero is not zero {}", zero);
rb.Push(ResultCode(static_cast<ErrorDescription>(29), ErrorModule::RO, rb.Push(ResultCode(static_cast<ErrorDescription>(29), ErrorModule::RO,
ErrorSummary::Internal, ErrorLevel::Usage)); ErrorSummary::Internal, ErrorLevel::Usage));
rb.Push<u32>(0); rb.Push<u32>(0);
@ -275,7 +276,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
.MapMemoryBlock(cro_address, cro_mem, 0, cro_size, Kernel::MemoryState::Code) .MapMemoryBlock(cro_address, cro_mem, 0, cro_size, Kernel::MemoryState::Code)
.Code(); .Code();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error mapping memory block %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error mapping memory block {:08X}", result.raw);
rb.Push(result); rb.Push(result);
rb.Push<u32>(0); rb.Push<u32>(0);
return; return;
@ -284,7 +285,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
result = result =
process->vm_manager.ReprotectRange(cro_address, cro_size, Kernel::VMAPermission::Read); process->vm_manager.ReprotectRange(cro_address, cro_size, Kernel::VMAPermission::Read);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error reprotecting memory block %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error reprotecting memory block {:08X}", result.raw);
process->vm_manager.UnmapRange(cro_address, cro_size); process->vm_manager.UnmapRange(cro_address, cro_size);
rb.Push(result); rb.Push(result);
rb.Push<u32>(0); rb.Push<u32>(0);
@ -298,14 +299,14 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
// This is derived from the case of LoadCRS with buffer_ptr==address, // This is derived from the case of LoadCRS with buffer_ptr==address,
// and is never seen in any game. "Do nothing" is probably an incorrect implement. // and is never seen in any game. "Do nothing" is probably an incorrect implement.
// There is also a chance that this case is just prohibited. // There is also a chance that this case is just prohibited.
LOG_WARNING(Service_LDR, "cro_buffer_ptr == cro_address (0x%08X)", cro_address); NGLOG_WARNING(Service_LDR, "cro_buffer_ptr == cro_address (0x{:08X})", cro_address);
} }
CROHelper cro(cro_address); CROHelper cro(cro_address);
result = cro.VerifyHash(cro_size, crr_address); result = cro.VerifyHash(cro_size, crr_address);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error verifying CRO in CRR %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error verifying CRO in CRR {:08X}", result.raw);
process->vm_manager.UnmapRange(cro_address, cro_size); process->vm_manager.UnmapRange(cro_address, cro_size);
rb.Push(result); rb.Push(result);
rb.Push<u32>(0); rb.Push<u32>(0);
@ -315,7 +316,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
result = cro.Rebase(slot->loaded_crs, cro_size, data_segment_address, data_segment_size, result = cro.Rebase(slot->loaded_crs, cro_size, data_segment_address, data_segment_size,
bss_segment_address, bss_segment_size, false); bss_segment_address, bss_segment_size, false);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error rebasing CRO %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error rebasing CRO {:08X}", result.raw);
process->vm_manager.UnmapRange(cro_address, cro_size); process->vm_manager.UnmapRange(cro_address, cro_size);
rb.Push(result); rb.Push(result);
rb.Push<u32>(0); rb.Push<u32>(0);
@ -324,7 +325,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
result = cro.Link(slot->loaded_crs, link_on_load_bug_fix); result = cro.Link(slot->loaded_crs, link_on_load_bug_fix);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error linking CRO %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error linking CRO {:08X}", result.raw);
process->vm_manager.UnmapRange(cro_address, cro_size); process->vm_manager.UnmapRange(cro_address, cro_size);
rb.Push(result); rb.Push(result);
rb.Push<u32>(0); rb.Push<u32>(0);
@ -342,7 +343,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
if (fix_size != cro_size) { if (fix_size != cro_size) {
result = process->vm_manager.UnmapRange(cro_address + fix_size, cro_size - fix_size); result = process->vm_manager.UnmapRange(cro_address + fix_size, cro_size - fix_size);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error unmapping memory block %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error unmapping memory block {:08X}", result.raw);
process->vm_manager.UnmapRange(cro_address, cro_size); process->vm_manager.UnmapRange(cro_address, cro_size);
rb.Push(result); rb.Push(result);
rb.Push<u32>(0); rb.Push<u32>(0);
@ -361,7 +362,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
result = process->vm_manager.ReprotectRange(exe_begin, exe_size, result = process->vm_manager.ReprotectRange(exe_begin, exe_size,
Kernel::VMAPermission::ReadExecute); Kernel::VMAPermission::ReadExecute);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error reprotecting memory block %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error reprotecting memory block {:08X}", result.raw);
process->vm_manager.UnmapRange(cro_address, fix_size); process->vm_manager.UnmapRange(cro_address, fix_size);
rb.Push(result); rb.Push(result);
rb.Push<u32>(0); rb.Push<u32>(0);
@ -371,7 +372,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
Core::CPU().InvalidateCacheRange(cro_address, cro_size); Core::CPU().InvalidateCacheRange(cro_address, cro_size);
LOG_INFO(Service_LDR, "CRO \"%s\" loaded at 0x%08X, fixed_end=0x%08X", cro.ModuleName().data(), NGLOG_INFO(Service_LDR, "CRO \"{}\" loaded at 0x{:08X}, fixed_end=0x{:08X}", cro.ModuleName(),
cro_address, cro_address + fix_size); cro_address, cro_address + fix_size);
rb.Push(RESULT_SUCCESS, fix_size); rb.Push(RESULT_SUCCESS, fix_size);
@ -384,7 +385,7 @@ void RO::UnloadCRO(Kernel::HLERequestContext& ctx) {
VAddr cro_buffer_ptr = rp.Pop<u32>(); VAddr cro_buffer_ptr = rp.Pop<u32>();
auto process = rp.PopObject<Kernel::Process>(); auto process = rp.PopObject<Kernel::Process>();
LOG_DEBUG(Service_LDR, "called, cro_address=0x%08X, zero=%d, cro_buffer_ptr=0x%08X", NGLOG_DEBUG(Service_LDR, "called, cro_address=0x{:08X}, zero={}, cro_buffer_ptr=0x{:08X}",
cro_address, zero, cro_buffer_ptr); cro_address, zero, cro_buffer_ptr);
CROHelper cro(cro_address); CROHelper cro(cro_address);
@ -393,24 +394,24 @@ void RO::UnloadCRO(Kernel::HLERequestContext& ctx) {
ClientSlot* slot = GetSessionData(ctx.Session()); ClientSlot* slot = GetSessionData(ctx.Session());
if (slot->loaded_crs == 0) { if (slot->loaded_crs == 0) {
LOG_ERROR(Service_LDR, "Not initialized"); NGLOG_ERROR(Service_LDR, "Not initialized");
rb.Push(ERROR_NOT_INITIALIZED); rb.Push(ERROR_NOT_INITIALIZED);
return; return;
} }
if (cro_address & Memory::PAGE_MASK) { if (cro_address & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRO address is not aligned"); NGLOG_ERROR(Service_LDR, "CRO address is not aligned");
rb.Push(ERROR_MISALIGNED_ADDRESS); rb.Push(ERROR_MISALIGNED_ADDRESS);
return; return;
} }
if (!cro.IsLoaded()) { if (!cro.IsLoaded()) {
LOG_ERROR(Service_LDR, "Invalid or not loaded CRO"); NGLOG_ERROR(Service_LDR, "Invalid or not loaded CRO");
rb.Push(ERROR_NOT_LOADED); rb.Push(ERROR_NOT_LOADED);
return; return;
} }
LOG_INFO(Service_LDR, "Unloading CRO \"%s\"", cro.ModuleName().data()); NGLOG_INFO(Service_LDR, "Unloading CRO \"{}\"", cro.ModuleName());
u32 fixed_size = cro.GetFixedSize(); u32 fixed_size = cro.GetFixedSize();
@ -418,7 +419,7 @@ void RO::UnloadCRO(Kernel::HLERequestContext& ctx) {
ResultCode result = cro.Unlink(slot->loaded_crs); ResultCode result = cro.Unlink(slot->loaded_crs);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error unlinking CRO %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error unlinking CRO {:08X}", result.raw);
rb.Push(result); rb.Push(result);
return; return;
} }
@ -428,7 +429,7 @@ void RO::UnloadCRO(Kernel::HLERequestContext& ctx) {
if (!cro.IsFixed()) { if (!cro.IsFixed()) {
result = cro.ClearRelocations(); result = cro.ClearRelocations();
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error clearing relocations %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error clearing relocations {:08X}", result.raw);
rb.Push(result); rb.Push(result);
return; return;
} }
@ -442,7 +443,7 @@ void RO::UnloadCRO(Kernel::HLERequestContext& ctx) {
if (cro_address != cro_buffer_ptr) { if (cro_address != cro_buffer_ptr) {
result = process->vm_manager.UnmapRange(cro_address, fixed_size); result = process->vm_manager.UnmapRange(cro_address, fixed_size);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error unmapping CRO %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error unmapping CRO {:08X}", result.raw);
} }
slot->memory_synchronizer.RemoveMemoryBlock(cro_address, cro_buffer_ptr); slot->memory_synchronizer.RemoveMemoryBlock(cro_address, cro_buffer_ptr);
} }
@ -457,7 +458,7 @@ void RO::LinkCRO(Kernel::HLERequestContext& ctx) {
VAddr cro_address = rp.Pop<u32>(); VAddr cro_address = rp.Pop<u32>();
auto process = rp.PopObject<Kernel::Process>(); auto process = rp.PopObject<Kernel::Process>();
LOG_DEBUG(Service_LDR, "called, cro_address=0x%08X", cro_address); NGLOG_DEBUG(Service_LDR, "called, cro_address=0x{:08X}", cro_address);
CROHelper cro(cro_address); CROHelper cro(cro_address);
@ -465,28 +466,28 @@ void RO::LinkCRO(Kernel::HLERequestContext& ctx) {
ClientSlot* slot = GetSessionData(ctx.Session()); ClientSlot* slot = GetSessionData(ctx.Session());
if (slot->loaded_crs == 0) { if (slot->loaded_crs == 0) {
LOG_ERROR(Service_LDR, "Not initialized"); NGLOG_ERROR(Service_LDR, "Not initialized");
rb.Push(ERROR_NOT_INITIALIZED); rb.Push(ERROR_NOT_INITIALIZED);
return; return;
} }
if (cro_address & Memory::PAGE_MASK) { if (cro_address & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRO address is not aligned"); NGLOG_ERROR(Service_LDR, "CRO address is not aligned");
rb.Push(ERROR_MISALIGNED_ADDRESS); rb.Push(ERROR_MISALIGNED_ADDRESS);
return; return;
} }
if (!cro.IsLoaded()) { if (!cro.IsLoaded()) {
LOG_ERROR(Service_LDR, "Invalid or not loaded CRO"); NGLOG_ERROR(Service_LDR, "Invalid or not loaded CRO");
rb.Push(ERROR_NOT_LOADED); rb.Push(ERROR_NOT_LOADED);
return; return;
} }
LOG_INFO(Service_LDR, "Linking CRO \"%s\"", cro.ModuleName().data()); NGLOG_INFO(Service_LDR, "Linking CRO \"{}\"", cro.ModuleName());
ResultCode result = cro.Link(slot->loaded_crs, false); ResultCode result = cro.Link(slot->loaded_crs, false);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error linking CRO %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error linking CRO {:08X}", result.raw);
} }
slot->memory_synchronizer.SynchronizeOriginalMemory(*process); slot->memory_synchronizer.SynchronizeOriginalMemory(*process);
@ -499,7 +500,7 @@ void RO::UnlinkCRO(Kernel::HLERequestContext& ctx) {
VAddr cro_address = rp.Pop<u32>(); VAddr cro_address = rp.Pop<u32>();
auto process = rp.PopObject<Kernel::Process>(); auto process = rp.PopObject<Kernel::Process>();
LOG_DEBUG(Service_LDR, "called, cro_address=0x%08X", cro_address); NGLOG_DEBUG(Service_LDR, "called, cro_address=0x{:08X}", cro_address);
CROHelper cro(cro_address); CROHelper cro(cro_address);
@ -507,28 +508,28 @@ void RO::UnlinkCRO(Kernel::HLERequestContext& ctx) {
ClientSlot* slot = GetSessionData(ctx.Session()); ClientSlot* slot = GetSessionData(ctx.Session());
if (slot->loaded_crs == 0) { if (slot->loaded_crs == 0) {
LOG_ERROR(Service_LDR, "Not initialized"); NGLOG_ERROR(Service_LDR, "Not initialized");
rb.Push(ERROR_NOT_INITIALIZED); rb.Push(ERROR_NOT_INITIALIZED);
return; return;
} }
if (cro_address & Memory::PAGE_MASK) { if (cro_address & Memory::PAGE_MASK) {
LOG_ERROR(Service_LDR, "CRO address is not aligned"); NGLOG_ERROR(Service_LDR, "CRO address is not aligned");
rb.Push(ERROR_MISALIGNED_ADDRESS); rb.Push(ERROR_MISALIGNED_ADDRESS);
return; return;
} }
if (!cro.IsLoaded()) { if (!cro.IsLoaded()) {
LOG_ERROR(Service_LDR, "Invalid or not loaded CRO"); NGLOG_ERROR(Service_LDR, "Invalid or not loaded CRO");
rb.Push(ERROR_NOT_LOADED); rb.Push(ERROR_NOT_LOADED);
return; return;
} }
LOG_INFO(Service_LDR, "Unlinking CRO \"%s\"", cro.ModuleName().data()); NGLOG_INFO(Service_LDR, "Unlinking CRO \"{}\"", cro.ModuleName());
ResultCode result = cro.Unlink(slot->loaded_crs); ResultCode result = cro.Unlink(slot->loaded_crs);
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error unlinking CRO %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error unlinking CRO {:08X}", result.raw);
} }
slot->memory_synchronizer.SynchronizeOriginalMemory(*process); slot->memory_synchronizer.SynchronizeOriginalMemory(*process);
@ -541,13 +542,13 @@ void RO::Shutdown(Kernel::HLERequestContext& ctx) {
VAddr crs_buffer_ptr = rp.Pop<u32>(); VAddr crs_buffer_ptr = rp.Pop<u32>();
auto process = rp.PopObject<Kernel::Process>(); auto process = rp.PopObject<Kernel::Process>();
LOG_DEBUG(Service_LDR, "called, crs_buffer_ptr=0x%08X", crs_buffer_ptr); NGLOG_DEBUG(Service_LDR, "called, crs_buffer_ptr=0x{:08X}", crs_buffer_ptr);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
ClientSlot* slot = GetSessionData(ctx.Session()); ClientSlot* slot = GetSessionData(ctx.Session());
if (slot->loaded_crs == 0) { if (slot->loaded_crs == 0) {
LOG_ERROR(Service_LDR, "Not initialized"); NGLOG_ERROR(Service_LDR, "Not initialized");
rb.Push(ERROR_NOT_INITIALIZED); rb.Push(ERROR_NOT_INITIALIZED);
return; return;
} }
@ -563,7 +564,7 @@ void RO::Shutdown(Kernel::HLERequestContext& ctx) {
if (slot->loaded_crs != crs_buffer_ptr) { if (slot->loaded_crs != crs_buffer_ptr) {
result = process->vm_manager.UnmapRange(slot->loaded_crs, crs.GetFileSize()); result = process->vm_manager.UnmapRange(slot->loaded_crs, crs.GetFileSize());
if (result.IsError()) { if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error unmapping CRS %08X", result.raw); NGLOG_ERROR(Service_LDR, "Error unmapping CRS {:08X}", result.raw);
} }
slot->memory_synchronizer.RemoveMemoryBlock(slot->loaded_crs, crs_buffer_ptr); slot->memory_synchronizer.RemoveMemoryBlock(slot->loaded_crs, crs_buffer_ptr);
} }