mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-28 10:02:31 -06:00
ldr_ro: replace usage of Core::CPU()
This commit is contained in:
parent
de1128c60d
commit
b9f6bd9278
3 changed files with 34 additions and 29 deletions
|
@ -72,11 +72,11 @@ ResultCode CROHelper::ApplyRelocation(VAddr target_address, RelocationType reloc
|
||||||
case RelocationType::AbsoluteAddress:
|
case RelocationType::AbsoluteAddress:
|
||||||
case RelocationType::AbsoluteAddress2:
|
case RelocationType::AbsoluteAddress2:
|
||||||
memory.Write32(target_address, symbol_address + addend);
|
memory.Write32(target_address, symbol_address + addend);
|
||||||
Core::CPU().InvalidateCacheRange(target_address, sizeof(u32));
|
cpu.InvalidateCacheRange(target_address, sizeof(u32));
|
||||||
break;
|
break;
|
||||||
case RelocationType::RelativeAddress:
|
case RelocationType::RelativeAddress:
|
||||||
memory.Write32(target_address, symbol_address + addend - target_future_address);
|
memory.Write32(target_address, symbol_address + addend - target_future_address);
|
||||||
Core::CPU().InvalidateCacheRange(target_address, sizeof(u32));
|
cpu.InvalidateCacheRange(target_address, sizeof(u32));
|
||||||
break;
|
break;
|
||||||
case RelocationType::ThumbBranch:
|
case RelocationType::ThumbBranch:
|
||||||
case RelocationType::ArmBranch:
|
case RelocationType::ArmBranch:
|
||||||
|
@ -99,7 +99,7 @@ ResultCode CROHelper::ClearRelocation(VAddr target_address, RelocationType reloc
|
||||||
case RelocationType::AbsoluteAddress2:
|
case RelocationType::AbsoluteAddress2:
|
||||||
case RelocationType::RelativeAddress:
|
case RelocationType::RelativeAddress:
|
||||||
memory.Write32(target_address, 0);
|
memory.Write32(target_address, 0);
|
||||||
Core::CPU().InvalidateCacheRange(target_address, sizeof(u32));
|
cpu.InvalidateCacheRange(target_address, sizeof(u32));
|
||||||
break;
|
break;
|
||||||
case RelocationType::ThumbBranch:
|
case RelocationType::ThumbBranch:
|
||||||
case RelocationType::ArmBranch:
|
case RelocationType::ArmBranch:
|
||||||
|
@ -548,7 +548,7 @@ ResultCode CROHelper::ApplyStaticAnonymousSymbolToCRS(VAddr crs_address) {
|
||||||
static_relocation_table_offset +
|
static_relocation_table_offset +
|
||||||
GetField(StaticRelocationNum) * sizeof(StaticRelocationEntry);
|
GetField(StaticRelocationNum) * sizeof(StaticRelocationEntry);
|
||||||
|
|
||||||
CROHelper crs(crs_address, process, memory);
|
CROHelper crs(crs_address, process, memory, cpu);
|
||||||
u32 offset_export_num = GetField(StaticAnonymousSymbolNum);
|
u32 offset_export_num = GetField(StaticAnonymousSymbolNum);
|
||||||
LOG_INFO(Service_LDR, "CRO \"{}\" exports {} static anonymous symbols", ModuleName(),
|
LOG_INFO(Service_LDR, "CRO \"{}\" exports {} static anonymous symbols", ModuleName(),
|
||||||
offset_export_num);
|
offset_export_num);
|
||||||
|
@ -759,7 +759,7 @@ ResultCode CROHelper::ApplyImportNamedSymbol(VAddr crs_address) {
|
||||||
|
|
||||||
if (!relocation_entry.is_batch_resolved) {
|
if (!relocation_entry.is_batch_resolved) {
|
||||||
ResultCode result = ForEachAutoLinkCRO(
|
ResultCode result = ForEachAutoLinkCRO(
|
||||||
process, memory, crs_address, [&](CROHelper source) -> ResultVal<bool> {
|
process, memory, cpu, crs_address, [&](CROHelper source) -> ResultVal<bool> {
|
||||||
std::string symbol_name =
|
std::string symbol_name =
|
||||||
memory.ReadCString(entry.name_offset, import_strings_size);
|
memory.ReadCString(entry.name_offset, import_strings_size);
|
||||||
u32 symbol_address = source.FindExportNamedSymbol(symbol_name);
|
u32 symbol_address = source.FindExportNamedSymbol(symbol_name);
|
||||||
|
@ -861,7 +861,7 @@ ResultCode CROHelper::ApplyModuleImport(VAddr crs_address) {
|
||||||
std::string want_cro_name = memory.ReadCString(entry.name_offset, import_strings_size);
|
std::string want_cro_name = memory.ReadCString(entry.name_offset, import_strings_size);
|
||||||
|
|
||||||
ResultCode result = ForEachAutoLinkCRO(
|
ResultCode result = ForEachAutoLinkCRO(
|
||||||
process, memory, crs_address, [&](CROHelper source) -> ResultVal<bool> {
|
process, memory, cpu, crs_address, [&](CROHelper source) -> ResultVal<bool> {
|
||||||
if (want_cro_name == source.ModuleName()) {
|
if (want_cro_name == source.ModuleName()) {
|
||||||
LOG_INFO(Service_LDR, "CRO \"{}\" imports {} indexed symbols from \"{}\"",
|
LOG_INFO(Service_LDR, "CRO \"{}\" imports {} indexed symbols from \"{}\"",
|
||||||
ModuleName(), entry.import_indexed_symbol_num, source.ModuleName());
|
ModuleName(), entry.import_indexed_symbol_num, source.ModuleName());
|
||||||
|
@ -1071,7 +1071,7 @@ ResultCode CROHelper::ApplyExitRelocations(VAddr crs_address) {
|
||||||
|
|
||||||
if (memory.ReadCString(entry.name_offset, import_strings_size) == "__aeabi_atexit") {
|
if (memory.ReadCString(entry.name_offset, import_strings_size) == "__aeabi_atexit") {
|
||||||
ResultCode result = ForEachAutoLinkCRO(
|
ResultCode result = ForEachAutoLinkCRO(
|
||||||
process, memory, crs_address, [&](CROHelper source) -> ResultVal<bool> {
|
process, memory, cpu, crs_address, [&](CROHelper source) -> ResultVal<bool> {
|
||||||
u32 symbol_address = source.FindExportNamedSymbol("nnroAeabiAtexit_");
|
u32 symbol_address = source.FindExportNamedSymbol("nnroAeabiAtexit_");
|
||||||
|
|
||||||
if (symbol_address != 0) {
|
if (symbol_address != 0) {
|
||||||
|
@ -1301,7 +1301,7 @@ ResultCode CROHelper::Link(VAddr crs_address, bool link_on_load_bug_fix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exports symbols to other modules
|
// Exports symbols to other modules
|
||||||
result = ForEachAutoLinkCRO(process, memory, crs_address,
|
result = ForEachAutoLinkCRO(process, memory, cpu, crs_address,
|
||||||
[this](CROHelper target) -> ResultVal<bool> {
|
[this](CROHelper target) -> ResultVal<bool> {
|
||||||
ResultCode result = ApplyExportNamedSymbol(target);
|
ResultCode result = ApplyExportNamedSymbol(target);
|
||||||
if (result.IsError())
|
if (result.IsError())
|
||||||
|
@ -1346,7 +1346,7 @@ ResultCode CROHelper::Unlink(VAddr crs_address) {
|
||||||
|
|
||||||
// Resets all symbols in other modules imported from this module
|
// Resets all symbols in other modules imported from this module
|
||||||
// Note: the RO service seems only searching in auto-link modules
|
// Note: the RO service seems only searching in auto-link modules
|
||||||
result = ForEachAutoLinkCRO(process, memory, crs_address,
|
result = ForEachAutoLinkCRO(process, memory, cpu, crs_address,
|
||||||
[this](CROHelper target) -> ResultVal<bool> {
|
[this](CROHelper target) -> ResultVal<bool> {
|
||||||
ResultCode result = ResetExportNamedSymbol(target);
|
ResultCode result = ResetExportNamedSymbol(target);
|
||||||
if (result.IsError())
|
if (result.IsError())
|
||||||
|
@ -1387,13 +1387,13 @@ void CROHelper::InitCRS() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CROHelper::Register(VAddr crs_address, bool auto_link) {
|
void CROHelper::Register(VAddr crs_address, bool auto_link) {
|
||||||
CROHelper crs(crs_address, process, memory);
|
CROHelper crs(crs_address, process, memory, cpu);
|
||||||
CROHelper head(auto_link ? crs.NextModule() : crs.PreviousModule(), process, memory);
|
CROHelper head(auto_link ? crs.NextModule() : crs.PreviousModule(), process, memory, cpu);
|
||||||
|
|
||||||
if (head.module_address) {
|
if (head.module_address) {
|
||||||
// there are already CROs registered
|
// there are already CROs registered
|
||||||
// register as the new tail
|
// register as the new tail
|
||||||
CROHelper tail(head.PreviousModule(), process, memory);
|
CROHelper tail(head.PreviousModule(), process, memory, cpu);
|
||||||
|
|
||||||
// link with the old tail
|
// link with the old tail
|
||||||
ASSERT(tail.NextModule() == 0);
|
ASSERT(tail.NextModule() == 0);
|
||||||
|
@ -1419,11 +1419,11 @@ void CROHelper::Register(VAddr crs_address, bool auto_link) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CROHelper::Unregister(VAddr crs_address) {
|
void CROHelper::Unregister(VAddr crs_address) {
|
||||||
CROHelper crs(crs_address, process, memory);
|
CROHelper crs(crs_address, process, memory, cpu);
|
||||||
CROHelper next_head(crs.NextModule(), process, memory);
|
CROHelper next_head(crs.NextModule(), process, memory, cpu);
|
||||||
CROHelper previous_head(crs.PreviousModule(), process, memory);
|
CROHelper previous_head(crs.PreviousModule(), process, memory, cpu);
|
||||||
CROHelper next(NextModule(), process, memory);
|
CROHelper next(NextModule(), process, memory, cpu);
|
||||||
CROHelper previous(PreviousModule(), process, memory);
|
CROHelper previous(PreviousModule(), process, memory, cpu);
|
||||||
|
|
||||||
if (module_address == next_head.module_address ||
|
if (module_address == next_head.module_address ||
|
||||||
module_address == previous_head.module_address) {
|
module_address == previous_head.module_address) {
|
||||||
|
|
|
@ -15,6 +15,8 @@ namespace Kernel {
|
||||||
class Process;
|
class Process;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ARM_Interface;
|
||||||
|
|
||||||
namespace Service::LDR {
|
namespace Service::LDR {
|
||||||
|
|
||||||
// GCC versions < 5.0 do not implement std::is_trivially_copyable.
|
// GCC versions < 5.0 do not implement std::is_trivially_copyable.
|
||||||
|
@ -40,8 +42,9 @@ static constexpr u32 CRO_HASH_SIZE = 0x80;
|
||||||
class CROHelper final {
|
class CROHelper final {
|
||||||
public:
|
public:
|
||||||
// TODO (wwylele): pass in the process handle for memory access
|
// TODO (wwylele): pass in the process handle for memory access
|
||||||
explicit CROHelper(VAddr cro_address, Kernel::Process& process, Memory::MemorySystem& memory)
|
explicit CROHelper(VAddr cro_address, Kernel::Process& process, Memory::MemorySystem& memory,
|
||||||
: module_address(cro_address), process(process), memory(memory) {}
|
ARM_Interface& cpu)
|
||||||
|
: module_address(cro_address), process(process), memory(memory), cpu(cpu) {}
|
||||||
|
|
||||||
std::string ModuleName() const {
|
std::string ModuleName() const {
|
||||||
return memory.ReadCString(GetField(ModuleNameOffset), GetField(ModuleNameSize));
|
return memory.ReadCString(GetField(ModuleNameOffset), GetField(ModuleNameSize));
|
||||||
|
@ -151,6 +154,7 @@ private:
|
||||||
const VAddr module_address; ///< the virtual address of this module
|
const VAddr module_address; ///< the virtual address of this module
|
||||||
Kernel::Process& process; ///< the owner process of this module
|
Kernel::Process& process; ///< the owner process of this module
|
||||||
Memory::MemorySystem& memory;
|
Memory::MemorySystem& memory;
|
||||||
|
ARM_Interface& cpu;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Each item in this enum represents a u32 field in the header begin from address+0x80,
|
* Each item in this enum represents a u32 field in the header begin from address+0x80,
|
||||||
|
@ -480,10 +484,11 @@ private:
|
||||||
*/
|
*/
|
||||||
template <typename FunctionObject>
|
template <typename FunctionObject>
|
||||||
static ResultCode ForEachAutoLinkCRO(Kernel::Process& process, Memory::MemorySystem& memory,
|
static ResultCode ForEachAutoLinkCRO(Kernel::Process& process, Memory::MemorySystem& memory,
|
||||||
VAddr crs_address, FunctionObject func) {
|
ARM_Interface& cpu, VAddr crs_address,
|
||||||
|
FunctionObject func) {
|
||||||
VAddr current = crs_address;
|
VAddr current = crs_address;
|
||||||
while (current != 0) {
|
while (current != 0) {
|
||||||
CROHelper cro(current, process, memory);
|
CROHelper cro(current, process, memory, cpu);
|
||||||
CASCADE_RESULT(bool next, func(cro));
|
CASCADE_RESULT(bool next, func(cro));
|
||||||
if (!next)
|
if (!next)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -115,7 +115,7 @@ void RO::Initialize(Kernel::HLERequestContext& ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CROHelper crs(crs_address, *process, system.Memory());
|
CROHelper crs(crs_address, *process, system.Memory(), system.CPU());
|
||||||
crs.InitCRS();
|
crs.InitCRS();
|
||||||
|
|
||||||
result = crs.Rebase(0, crs_size, 0, 0, 0, 0, true);
|
result = crs.Rebase(0, crs_size, 0, 0, 0, 0, true);
|
||||||
|
@ -249,7 +249,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CROHelper cro(cro_address, *process, system.Memory());
|
CROHelper cro(cro_address, *process, system.Memory(), system.CPU());
|
||||||
|
|
||||||
result = cro.VerifyHash(cro_size, crr_address);
|
result = cro.VerifyHash(cro_size, crr_address);
|
||||||
if (result.IsError()) {
|
if (result.IsError()) {
|
||||||
|
@ -313,7 +313,7 @@ void RO::LoadCRO(Kernel::HLERequestContext& ctx, bool link_on_load_bug_fix) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::CPU().InvalidateCacheRange(cro_address, cro_size);
|
system.CPU().InvalidateCacheRange(cro_address, cro_size);
|
||||||
|
|
||||||
LOG_INFO(Service_LDR, "CRO \"{}\" loaded at 0x{:08X}, fixed_end=0x{:08X}", cro.ModuleName(),
|
LOG_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);
|
||||||
|
@ -331,7 +331,7 @@ void RO::UnloadCRO(Kernel::HLERequestContext& ctx) {
|
||||||
LOG_DEBUG(Service_LDR, "called, cro_address=0x{:08X}, zero={}, cro_buffer_ptr=0x{:08X}",
|
LOG_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, *process, system.Memory());
|
CROHelper cro(cro_address, *process, system.Memory(), system.CPU());
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ void RO::UnloadCRO(Kernel::HLERequestContext& ctx) {
|
||||||
LOG_ERROR(Service_LDR, "Error unmapping CRO {:08X}", result.raw);
|
LOG_ERROR(Service_LDR, "Error unmapping CRO {:08X}", result.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::CPU().InvalidateCacheRange(cro_address, fixed_size);
|
system.CPU().InvalidateCacheRange(cro_address, fixed_size);
|
||||||
|
|
||||||
rb.Push(result);
|
rb.Push(result);
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,7 @@ void RO::LinkCRO(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
LOG_DEBUG(Service_LDR, "called, cro_address=0x{:08X}", cro_address);
|
LOG_DEBUG(Service_LDR, "called, cro_address=0x{:08X}", cro_address);
|
||||||
|
|
||||||
CROHelper cro(cro_address, *process, system.Memory());
|
CROHelper cro(cro_address, *process, system.Memory(), system.CPU());
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
|
|
||||||
|
@ -438,7 +438,7 @@ void RO::UnlinkCRO(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
LOG_DEBUG(Service_LDR, "called, cro_address=0x{:08X}", cro_address);
|
LOG_DEBUG(Service_LDR, "called, cro_address=0x{:08X}", cro_address);
|
||||||
|
|
||||||
CROHelper cro(cro_address, *process, system.Memory());
|
CROHelper cro(cro_address, *process, system.Memory(), system.CPU());
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
|
|
||||||
|
@ -487,7 +487,7 @@ void RO::Shutdown(Kernel::HLERequestContext& ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CROHelper crs(slot->loaded_crs, *process, system.Memory());
|
CROHelper crs(slot->loaded_crs, *process, system.Memory(), system.CPU());
|
||||||
crs.Unrebase(true);
|
crs.Unrebase(true);
|
||||||
|
|
||||||
ResultCode result = RESULT_SUCCESS;
|
ResultCode result = RESULT_SUCCESS;
|
||||||
|
|
Loading…
Reference in a new issue