mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-29 12:54:16 +01:00
Fix .hook
section being allocated without any hooked symbols
Due to the trampoline and save/load context functions, `GetHookSectionSize` returned a non-zero size for when there were no hooked symbols supplied to it. This is problematic as it isn't required and hooking is currently not stable so it can lead to crashes or freezes in certain titles.
This commit is contained in:
parent
3fa314f6cb
commit
f882b613bc
@ -34,6 +34,7 @@ namespace skyline::loader {
|
||||
std::vector<nce::NCE::HookedSymbolEntry> executableSymbols;
|
||||
size_t hookSize{};
|
||||
if (dynamicallyLinked) {
|
||||
if constexpr (!hle::HookedSymbols.empty()) {
|
||||
for (auto &symbol : dynsym) {
|
||||
if (symbol.st_name == 0 || symbol.st_value == 0)
|
||||
continue;
|
||||
@ -66,6 +67,24 @@ namespace skyline::loader {
|
||||
}, &symbol.st_value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PRINT_HOOK_ALL
|
||||
for (auto &symbol : dynsym) {
|
||||
if (symbolName == "memcpy" || symbolName == "memcmp" || symbolName == "memset" || symbolName == "strcmp" || symbolName == "strlen")
|
||||
// If symbol is from libc (such as memcpy, strcmp, strlen, etc), we don't need to hook it
|
||||
continue;
|
||||
|
||||
executableSymbols.emplace_back(std::string{symbolName}, hle::EntryExitHook{
|
||||
.entry = [](const DeviceState &, const hle::HookedSymbol &symbol) {
|
||||
Logger::Error("Entering \"{}\" ({})", symbol.prettyName, symbol.name);
|
||||
},
|
||||
.exit = [](const DeviceState &, const hle::HookedSymbol &symbol) {
|
||||
Logger::Error("Exiting \"{}\"", symbol.prettyName);
|
||||
},
|
||||
}, &symbol.st_value);
|
||||
}
|
||||
#endif
|
||||
|
||||
hookSize = util::AlignUp(state.nce->GetHookSectionSize(executableSymbols), PAGE_SIZE);
|
||||
}
|
||||
|
@ -515,6 +515,9 @@ namespace skyline::nce {
|
||||
}
|
||||
|
||||
size_t NCE::GetHookSectionSize(span<HookedSymbolEntry> entries) {
|
||||
if (entries.empty())
|
||||
return 0;
|
||||
|
||||
size_t size{guest::SaveCtxSize + guest::LoadCtxSize + TrampolineSize};
|
||||
for (const auto &entry : entries) {
|
||||
constexpr size_t EmitTrampolineSize{10};
|
||||
|
Loading…
Reference in New Issue
Block a user