Stubs: Auto add aerolib, add __error to libc, libkernel

This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2023-10-02 22:26:10 +03:00
parent 5094d3044c
commit 00fa98a225
8 changed files with 11316 additions and 11229 deletions

View File

@ -40,6 +40,7 @@ add_executable(shadps4
src/Core/virtual_memory.h src/Core/virtual_memory.h
src/Core/PS4/Linker.cpp src/Core/PS4/Linker.cpp
src/Core/PS4/Linker.h src/Core/PS4/Linker.h
src/Core/PS4/Util/aerolib.cpp
src/Lib/Threads.cpp src/Lib/Threads.cpp
src/Lib/Threads.h src/Lib/Threads.h
src/Core/PS4/HLE/Kernel/Objects/physical_memory.h src/Core/PS4/HLE/Kernel/Objects/physical_memory.h

View File

@ -91,7 +91,8 @@ namespace HLE::Libs::LibC {
return rt; return rt;
} }
static PS4_SYSV_ABI void _Assert() { BREAKPOINT(); } static PS4_SYSV_ABI void _Assert() { BREAKPOINT(); }
static PS4_SYSV_ABI int* _Error() { return _errno(); }
void LibC_Register(SymbolsResolver* sym) void LibC_Register(SymbolsResolver* sym)
{ {
LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env);
@ -103,6 +104,8 @@ namespace HLE::Libs::LibC {
LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1, exit); LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1, exit);
LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, atexit); LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, atexit);
LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, _Assert); LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, _Assert);
LIB_FUNCTION("9BcDykPmo1I", "libc", 1, "libc", 1, 1, _Error);
LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &HLE::Libs::LibC::g_need_sceLibc); LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &HLE::Libs::LibC::g_need_sceLibc);
} }

View File

@ -26,6 +26,9 @@ namespace HLE::Libs::LibKernel {
QueryPerformanceCounter(&c); QueryPerformanceCounter(&c);
return c.QuadPart; return c.QuadPart;
} }
static PS4_SYSV_ABI int* _Error() { return _errno(); }
void LibKernel_Register(SymbolsResolver* sym) { void LibKernel_Register(SymbolsResolver* sym) {
//obj //obj
LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &HLE::Libs::LibKernel::g_stack_chk_guard); LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &HLE::Libs::LibKernel::g_stack_chk_guard);
@ -42,6 +45,8 @@ namespace HLE::Libs::LibKernel {
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);
//time //time
LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc); LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc);
LIB_FUNCTION("9BcDykPmo1I", "libkernel", 1, "libkernel", 1, 1, _Error);
} }
}; };

View File

@ -590,6 +590,25 @@ void Linker::Relocate(Module* m)
} }
std::vector<std::string> unresolved_ids;
template<int idx>
static u64 unresolved_i() {
LOG_CRITICAL_IF(true, "{} unresolved STUB called!!!\n", unresolved_ids[idx]);
return 0;
}
u64 unresolved_handlers[] = {(u64)&unresolved_i<0>, (u64)&unresolved_i<1>, (u64)&unresolved_i<2>,
(u64)&unresolved_i<3>, (u64)&unresolved_i<4>, (u64)&unresolved_i<5>,
(u64)&unresolved_i<6>, (u64)&unresolved_i<7>, 0};
static u64 unresolved() {
LOG_CRITICAL_IF(true, "unknown unresolved STUB called!!!\n");
return 0;
}
void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info) { void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info) {
auto ids = StringUtil::split_string(name, '#'); auto ids = StringUtil::split_string(name, '#');
@ -616,8 +635,20 @@ void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolReco
if (rec != nullptr) { if (rec != nullptr) {
*return_info = *rec; *return_info = *rec;
} else { } else {
return_info->virtual_address = 0; auto it = aerolib::symbolsStubsMap.find(sr.name);
return_info->name = "Unresolved!!!";
if (it != aerolib::symbolsStubsMap.end()) {
return_info->virtual_address = it->second;
return_info->name = aerolib::symbolsMap[sr.name];
} else {
if (unresolved_handlers[unresolved_ids.size()] == 0) {
return_info->virtual_address = (u64)&unresolved;
} else {
return_info->virtual_address = unresolved_handlers[unresolved_ids.size()];
unresolved_ids.push_back(sr.name);
}
return_info->name = "Unresolved!!!";
}
} }
} }
else else

View File

@ -2,6 +2,8 @@
#include "SymbolsResolver.h" #include "SymbolsResolver.h"
#include <Util/log.h> #include <Util/log.h>
#include "../Util/aerolib.h"
void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr)
{ {
@ -27,6 +29,16 @@ const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
} }
index++; index++;
} }
LOG_INFO_IF(true, "unresolved! {}\n", name);
std::string UnhashedName = "Unknown Unhashed Name";
auto guess = aerolib::symbolsMap.find(s.name);
if (guess != aerolib::symbolsMap.end()) {
UnhashedName = guess->second;
LOG_INFO_IF(true, "unresolved! {} {}\n", name, UnhashedName);
} else {
LOG_ERROR_IF(true, "unresolved! {} {}\n", name, UnhashedName);
}
return nullptr; return nullptr;
} }

View File

@ -0,0 +1,29 @@
#include <map>
#include <string>
#include "types.h"
#include <Util/log.h>
namespace aerolib {
#define STUB(a, b) { a, #b },
std::map<std::string, std::string> symbolsMap = {
#include "stubs.h"
};
#undef STUB
#define STUB(a, b) \
uint64_t PS4_SYSV_ABI stub_##b() { \
LOG_ERROR_IF(true, #b " STUB!\n"); \
\
return 0; \
}
#include "stubs.h"
#undef STUB
#define STUB(a, b) {a, (uint64_t) & stub_##b},
std::map<std::string, uint64_t> symbolsStubsMap = {
#include "stubs.h"
};
#undef STUB
};

File diff suppressed because it is too large Load Diff

11226
src/Core/PS4/Util/stubs.h Normal file

File diff suppressed because it is too large Load Diff