mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
sysmodule: track shared module load references and unloaded status
This commit is contained in:
@@ -45,6 +45,7 @@ void InitLibKernel_1_Apr(Loader::SymbolDatabase *symbols);
|
||||
|
||||
namespace Libs {
|
||||
void InitLibKernel_1(Loader::SymbolDatabase *symbols);
|
||||
void InitSysmodule_1(Loader::SymbolDatabase *symbols);
|
||||
}
|
||||
|
||||
namespace Libs::LibAmpr {
|
||||
@@ -164,6 +165,45 @@ void TestFileDescriptorFlags() {
|
||||
}
|
||||
}
|
||||
|
||||
void TestSysmoduleReferences() {
|
||||
Loader::SymbolDatabase symbols;
|
||||
Libs::InitSysmodule_1(&symbols);
|
||||
using ModuleCall = int (KYTY_SYSV_ABI *)(uint16_t);
|
||||
const auto resolve = [&](const char* nid) {
|
||||
const auto* symbol = symbols.Find(
|
||||
{nid, "Sysmodule", 1, "Sysmodule", 1, 1, Loader::SymbolType::Func});
|
||||
Check(symbol != nullptr, "Sysmodule export resolves");
|
||||
return reinterpret_cast<ModuleCall>(symbol->vaddr);
|
||||
};
|
||||
const auto load = resolve("g8cM39EUZ6o");
|
||||
const auto unload = resolve("eR2bZFAAU0Q");
|
||||
const auto is_loaded = resolve("fMP5NHUOaMk");
|
||||
constexpr int unloaded = static_cast<int>(0x805a1001u);
|
||||
Check(load(0x113) == OK && is_loaded(0xb4) == unloaded,
|
||||
"loading entitlement access does not mark AppContent loaded");
|
||||
Check(unload(0x113) == OK, "release independent module reference");
|
||||
for (const uint16_t id : {0x113, 0xb4}) {
|
||||
Check(is_loaded(id) == unloaded, "unloaded module allows guest initialization");
|
||||
Check(unload(id) == unloaded, "unloading an absent module reports UNLOADED");
|
||||
Check(load(id) == OK && load(id) == OK && is_loaded(id) == OK,
|
||||
"repeated loads retain references");
|
||||
Check(unload(id) == OK && is_loaded(id) == OK,
|
||||
"one unload preserves the remaining reference");
|
||||
Check(unload(id) == OK && is_loaded(id) == unloaded,
|
||||
"last unload restores unloaded status");
|
||||
}
|
||||
const auto* internal_symbol = symbols.Find(
|
||||
{"hHrGoGoNf+s", "Sysmodule", 1, "Sysmodule", 1, 1, Loader::SymbolType::Func});
|
||||
Check(internal_symbol != nullptr, "internal Sysmodule load export resolves");
|
||||
const auto internal_load =
|
||||
reinterpret_cast<int (KYTY_SYSV_ABI *)(uint16_t, int, int, int, int*)>(
|
||||
internal_symbol->vaddr);
|
||||
int result = -1;
|
||||
Check(internal_load(0xb4, 0, 0, 0, &result) == OK && result == OK &&
|
||||
is_loaded(0xb4) == OK && unload(0xb4) == OK && is_loaded(0xb4) == unloaded,
|
||||
"internal and public module operations share load state");
|
||||
}
|
||||
|
||||
void TestSaveOpenVisibility() {
|
||||
constexpr char Path[] = "/savedata0/visible-save.dat";
|
||||
constexpr char Payload[] = "saved progress";
|
||||
@@ -1532,6 +1572,7 @@ int main(int, char**) {
|
||||
|
||||
TempDirectory temporary;
|
||||
FileSystem::Initialize();
|
||||
TestSysmoduleReferences();
|
||||
TestRandomDevices();
|
||||
TestFileDescriptorFlags();
|
||||
CheckMountRoot(temporary.Path());
|
||||
|
||||
Reference in New Issue
Block a user