From cd2819d1a9c1248e1be57ba344102eb91695d266 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Fri, 7 Jul 2023 14:07:22 +0300 Subject: [PATCH 01/20] ci: Add linux.yml --- .github/workflows/linux.yml | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/linux.yml diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 00000000..06132775 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,46 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Linux + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.2 + with: + name: shadps4-ubuntu64 + # A file, directory or wildcard pattern that describes what to upload + path: | + ${{github.workspace}}/build/shadps4 + ${{github.workspace}}/build/libSDL3.so.0.0.0 From bed5edadaeafa514729fd2ace156301add2cb869 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Fri, 7 Jul 2023 14:07:34 +0300 Subject: [PATCH 02/20] Add clang-format --- .clang-format | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..9f2c6426 --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +BasedOnStyle: Google +IndentWidth: 4 +ColumnLimit: 150 +AccessModifierOffset: -2 +TabWidth: 4 +AllowShortEnumsOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true From c7e73c896001315d8b6ff141757661c50fac211a Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Fri, 7 Jul 2023 14:12:24 +0300 Subject: [PATCH 03/20] git: Enable shallow checkout for submodules --- .gitmodules | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitmodules b/.gitmodules index c7d75fb4..6d4a8197 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,18 +1,24 @@ [submodule "third-party/imgui"] path = third-party/imgui url = https://github.com/ocornut/imgui + shallow = true [submodule "third-party/SDL"] path = third-party/SDL url = https://github.com/libsdl-org/SDL + shallow = true [submodule "third-party/fmt"] path = third-party/fmt url = https://github.com/fmtlib/fmt.git + shallow = true [submodule "third-party/spdlog"] path = third-party/spdlog url = https://github.com/gabime/spdlog + shallow = true [submodule "third-party/magic_enum"] path = third-party/magic_enum url = https://github.com/Neargye/magic_enum.git + shallow = true [submodule "third-party/zydis"] path = third-party/zydis url = https://github.com/zyantific/zydis.git + shallow = true From a353da81b7b007e28e947a98b33ebd5301905992 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Fri, 7 Jul 2023 14:14:52 +0300 Subject: [PATCH 04/20] ci: install some packages for linux --- .github/workflows/linux.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 06132775..f4dda539 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -23,6 +23,10 @@ jobs: runs-on: ubuntu-latest steps: + - name: Install dev packages + run: | + sudo apt install libxext-dev doxygen libgl-dev + - uses: actions/checkout@v3 with: submodules: recursive From 266111dcf8b91bdb5ee5801e0b9efb6ef8b26ff1 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Fri, 7 Jul 2023 14:23:00 +0300 Subject: [PATCH 05/20] ci: Use all available cores for linux --- .github/workflows/linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f4dda539..258c5740 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -38,7 +38,7 @@ jobs: - name: Build # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel `nproc` - name: Upload a Build Artifact uses: actions/upload-artifact@v3.1.2 From cb117e996bb98c337093be0e7d9bf36687fad9ea Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 7 Jul 2023 14:47:34 +0300 Subject: [PATCH 06/20] Update README.md Added linux build status --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 582fbd25..1d8258cd 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ make -j$(nproc) |Platform|Build status| |--------|------------| |Windows build|[![Windows](https://github.com/georgemoralis/shadPS4/actions/workflows/windows.yml/badge.svg)](https://github.com/georgemoralis/shadPS4/actions/workflows/windows.yml) -|Linux build| TODO +|Linux build|[![Linux](https://github.com/georgemoralis/shadPS4/actions/workflows/linux.yml/badge.svg)](https://github.com/georgemoralis/shadPS4/actions/workflows/linux.yml) To discuss this emulator please join our Discord server: [![Discord](https://img.shields.io/discord/1080089157554155590)](https://discord.gg/MyZRaBngxA) From 8f36540386f18a0177af70e4d5427adc2c467356 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Sat, 8 Jul 2023 21:06:10 +0300 Subject: [PATCH 07/20] kalitero usage minima sto main.cpp . Ola einai modules alla den tha katalaboun --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c61de612..e4d8e493 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +34,7 @@ int main(int argc, char* argv[]) { if (argc == 1) { - printf("Usage: %s \n", argv[0]); + printf("Usage: %s \n", argv[0]); return -1; } From 42dc5356388ad4c5a92c5a9cb36ab083ca8f63e6 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 10 Jul 2023 14:52:14 +0300 Subject: [PATCH 08/20] some more work on linker and added some more needed (but not currently used) memory functions --- src/Core/Memory.cpp | 52 +++++++++++++++++++++++++++++++++++++++++ src/Core/Memory.h | 3 +++ src/Core/PS4/Linker.cpp | 13 ++++++----- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/Core/Memory.cpp b/src/Core/Memory.cpp index 39449176..0855df7f 100644 --- a/src/Core/Memory.cpp +++ b/src/Core/Memory.cpp @@ -42,6 +42,17 @@ namespace Memory return PAGE_NOACCESS; } } + static MemoryMode convertMemoryMode(u32 mode) { + switch (mode) { + case PAGE_NOACCESS: return MemoryMode::NoAccess; + case PAGE_READONLY: return MemoryMode::Read; + case PAGE_READWRITE: return MemoryMode::ReadWrite; + case PAGE_EXECUTE: return MemoryMode::Execute; + case PAGE_EXECUTE_READ: return MemoryMode::ExecuteRead; + case PAGE_EXECUTE_READWRITE: return MemoryMode::ExecuteReadWrite; + default: return MemoryMode::NoAccess; + } + } u64 memory_alloc(u64 address, u64 size, MemoryMode mode) { @@ -71,5 +82,46 @@ namespace Memory #endif return ptr; } + bool memory_protect(u64 address, u64 size, MemoryMode mode, MemoryMode* old_mode) { + DWORD old_protect = 0; + if (VirtualProtect(reinterpret_cast(static_cast(address)), size, convertMemoryMode(mode), &old_protect) == 0) { + auto err = static_cast(GetLastError()); + LOG_ERROR_IF(true, "VirtualProtect() failed: 0x{:X}\n", err); + return false; + } + if (old_mode != nullptr) { + *old_mode = convertMemoryMode(old_protect); + } + return true; + } + + bool memory_flush(u64 address, u64 size) { + if (::FlushInstructionCache(GetCurrentProcess(), reinterpret_cast(static_cast(address)), size) == 0) { + auto err = static_cast(GetLastError()); + LOG_ERROR_IF(true, "FlushInstructionCache() failed: 0x{:X}\n", err); + return false; + } + return true; + } + bool memory_patch(u64 vaddr, u64 value) { + MemoryMode old_mode{}; + memory_protect(vaddr, 8, MemoryMode::ReadWrite, &old_mode); + + auto* ptr = reinterpret_cast(vaddr); + + bool ret = (*ptr != value); + + *ptr = value; + + memory_protect(vaddr, 8, old_mode, nullptr); + + //if mode is executable flush it so insure that cpu finds it + if ((old_mode == MemoryMode::Execute || old_mode == MemoryMode::ExecuteRead || old_mode == MemoryMode::ExecuteWrite || + old_mode == MemoryMode::ExecuteReadWrite)) { + memory_flush(vaddr, 8); + } + + return ret; + } } } diff --git a/src/Core/Memory.h b/src/Core/Memory.h index 7bc5ba0f..00b9d2ba 100644 --- a/src/Core/Memory.h +++ b/src/Core/Memory.h @@ -20,5 +20,8 @@ namespace Memory namespace VirtualMemory { u64 memory_alloc(u64 address, u64 size, MemoryMode mode); + bool memory_protect(u64 address, u64 size, MemoryMode mode, MemoryMode* old_mode); + bool memory_flush(u64 address, u64 size); + bool memory_patch(u64 vaddr, u64 value); } } \ No newline at end of file diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp index efa3bc15..d1922c52 100644 --- a/src/Core/PS4/Linker.cpp +++ b/src/Core/PS4/Linker.cpp @@ -511,6 +511,7 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) bool rel_isResolved = false; u08 rel_sym_type = 0; std::string rel_name; + u08 rel_bind_type = -1;//-1 means it didn't resolve switch (type) { @@ -544,12 +545,12 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) switch (sym_bind) { case STB_GLOBAL: - if (type == R_X86_64_64) { - LOG_INFO_IF(debug_loader, "R_X86_64_64 sym_type {} bind STB_GLOBAL symbol : {:#010x}\n", sym_type,symbol); - } - if (type == R_X86_64_JUMP_SLOT) { - LOG_INFO_IF(debug_loader, "R_X86_64_JUMP_SLOT sym_type {} bind STB_GLOBAL symbol : {:#010x}\n", sym_type,symbol); - } + rel_bind_type = STB_GLOBAL; + rel_name = namesTlb + sym.st_name; + if (type == R_X86_64_JUMP_SLOT) { + addend = 0; + } + LOG_INFO_IF(debug_loader, "R_X86_64_64-R_X86_64_JUMP_SLOT sym_type {} bind STB_GLOBAL symbol : {:#010x}\n", sym_type, symbol); break; default: LOG_INFO_IF(debug_loader, "UNK bind {}\n", sym_bind); From 81906c271aa38bcfce59589e3b8a7cf3e3b205a6 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 11 Jul 2023 18:50:29 +0300 Subject: [PATCH 09/20] resolving relocate function and patching them (successfully done one :D) --- src/Core/PS4/Linker.cpp | 166 ++++++++++++++++-------- src/Core/PS4/Linker.h | 4 + src/Core/PS4/Loader/SymbolsResolver.cpp | 23 +++- src/Core/PS4/Loader/SymbolsResolver.h | 3 + 4 files changed, 137 insertions(+), 59 deletions(-) diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp index d1922c52..aed80637 100644 --- a/src/Core/PS4/Linker.cpp +++ b/src/Core/PS4/Linker.cpp @@ -70,6 +70,7 @@ static std::string encodeId(u64 nVal) Module* Linker::LoadModule(const std::string& elf_name) { auto* m = new Module; + m->linker = this; m->elf = new Elf; m->elf->Open(elf_name);//load elf @@ -497,68 +498,78 @@ void Linker::LoadSymbols(Module* m) } } } -static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) -{ - auto type = rel->GetType(); - auto symbol = rel->GetSymbol(); - auto addend = rel->rel_addend; - auto* symbolsTlb = m->dynamic_info->symbol_table; - auto* namesTlb = m->dynamic_info->str_table; +static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) { + auto type = rel->GetType(); + auto symbol = rel->GetSymbol(); + auto addend = rel->rel_addend; + auto* symbolsTlb = m->dynamic_info->symbol_table; + auto* namesTlb = m->dynamic_info->str_table; - u64 rel_value = 0; - u64 rel_base_virtual_addr = m->base_virtual_addr; - u64 rel_virtual_addr = m->base_virtual_addr + rel->rel_offset; - bool rel_isResolved = false; - u08 rel_sym_type = 0; - std::string rel_name; - u08 rel_bind_type = -1;//-1 means it didn't resolve + u64 rel_value = 0; + u64 rel_base_virtual_addr = m->base_virtual_addr; + u64 rel_virtual_addr = m->base_virtual_addr + rel->rel_offset; + bool rel_isResolved = false; + u08 rel_sym_type = 0; + std::string rel_name; + u08 rel_bind_type = -1; //-1 means it didn't resolve - switch (type) - { - case R_X86_64_RELATIVE: - if (symbol != 0)//should be always zero - { - LOG_INFO_IF(debug_loader, "R_X86_64_RELATIVE symbol not zero = {:#010x}\n", type, symbol); - } - rel_value = rel_base_virtual_addr + addend; - rel_isResolved = true; - break; - case R_X86_64_64: - case R_X86_64_JUMP_SLOT://similar but addend is not take into account - { - auto sym = symbolsTlb[symbol]; - auto sym_bind = sym.GetBind(); - auto sym_type = sym.GetType(); - auto sym_visibility = sym.GetVisibility(); - u64 symbol_vitrual_addr = 0; - switch (sym_type) - { - case STT_FUN: rel_sym_type = 2; break; - case STT_OBJECT: rel_sym_type = 1; break; - default: - LOG_INFO_IF(debug_loader, "unknown symbol type {}\n",sym_type); - } - if (sym_visibility != 0)//should be zero log if else - { - LOG_INFO_IF(debug_loader, "symbol visilibity !=0"); - } - switch (sym_bind) - { - case STB_GLOBAL: + switch (type) { + case R_X86_64_RELATIVE: + if (symbol != 0) // should be always zero + { + LOG_INFO_IF(debug_loader, "R_X86_64_RELATIVE symbol not zero = {:#010x}\n", type, symbol); + } + rel_value = rel_base_virtual_addr + addend; + rel_isResolved = true; + break; + case R_X86_64_64: + case R_X86_64_JUMP_SLOT: // similar but addend is not take into account + { + auto sym = symbolsTlb[symbol]; + auto sym_bind = sym.GetBind(); + auto sym_type = sym.GetType(); + auto sym_visibility = sym.GetVisibility(); + u64 symbol_vitrual_addr = 0; + SymbolRecord symrec{}; + switch (sym_type) { + case STT_FUN: rel_sym_type = 2; break; + case STT_OBJECT: rel_sym_type = 1; break; + default: LOG_INFO_IF(debug_loader, "unknown symbol type {}\n", sym_type); + } + if (sym_visibility != 0) // should be zero log if else + { + LOG_INFO_IF(debug_loader, "symbol visilibity !=0\n"); + } + switch (sym_bind) { + case STB_GLOBAL: rel_bind_type = STB_GLOBAL; rel_name = namesTlb + sym.st_name; + m->linker->Resolve(rel_name, rel_sym_type, m, &symrec); + symbol_vitrual_addr = symrec.virtual_address; + rel_isResolved = (symbol_vitrual_addr != 0); + + rel_name = symrec.name; if (type == R_X86_64_JUMP_SLOT) { - addend = 0; + addend = 0; } - LOG_INFO_IF(debug_loader, "R_X86_64_64-R_X86_64_JUMP_SLOT sym_type {} bind STB_GLOBAL symbol : {:#010x}\n", sym_type, symbol); - break; - default: - LOG_INFO_IF(debug_loader, "UNK bind {}\n", sym_bind); - } - } - break; - default: - LOG_INFO_IF(debug_loader, "UNK type {:#010x} rel symbol : {:#010x}\n", type, symbol); + rel_value = (rel_isResolved ? symbol_vitrual_addr + addend : 0); + if (!rel_isResolved) { + LOG_INFO_IF(debug_loader, "R_X86_64_64-R_X86_64_JUMP_SLOT sym_type {} bind STB_GLOBAL symbol : {:#010x}\n", sym_type, symbol); + } + break; + default: LOG_INFO_IF(debug_loader, "UNK bind {}\n", sym_bind); + } + + } break; + default: LOG_INFO_IF(debug_loader, "UNK type {:#010x} rel symbol : {:#010x}\n", type, symbol); + } + + if (rel_isResolved) { + Memory::VirtualMemory::memory_patch(rel_virtual_addr, rel_value); + } + else + { + LOG_INFO_IF(debug_loader, "function not patched!\n"); } } @@ -574,4 +585,47 @@ void Linker::Relocate(Module* m) { relocate(idx, rel, m, true); } +} + + +void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info) { + auto ids = StringUtil::split(name, '#'); + + if (ids.size() == 3) // symbols are 3 parts name , library , module + { + const auto* library = FindLibrary(*m, ids.at(1)); + const auto* module = FindModule(*m, ids.at(2)); + + if (library != nullptr && module != nullptr) { + SymbolRes sr{}; + sr.name = ids.at(0); + sr.library = library->name; + sr.library_version = library->version; + sr.module = module->name; + sr.module_version_major = module->version_major; + sr.module_version_minor = module->version_minor; + sr.type = Symtype; + + const SymbolRecord* rec = nullptr; + + if (m_HLEsymbols != nullptr) { + rec = m_HLEsymbols->FindSymbol(sr); + } + if (rec != nullptr) { + *return_info = *rec; + } else { + return_info->virtual_address = 0; + return_info->name = "Unresolved!!!"; + } + } + else + { + __debugbreak();//den tha prepei na ftasoume edo + } + } + else + { + __debugbreak();//oute edo mallon + } + } \ No newline at end of file diff --git a/src/Core/PS4/Linker.h b/src/Core/PS4/Linker.h index 4763bdf6..e2e33019 100644 --- a/src/Core/PS4/Linker.h +++ b/src/Core/PS4/Linker.h @@ -5,6 +5,7 @@ #include "Loader/SymbolsResolver.h" struct DynamicModuleInfo; +class Linker; /*this struct keeps neccesary info about loaded modules.Main executeable is included too as well*/ struct Module @@ -13,6 +14,8 @@ struct Module u64 aligned_base_size = 0; u64 base_virtual_addr = 0; //base virtual address + Linker* linker = nullptr; + void* m_dynamic = nullptr; void* m_dynamic_data = nullptr; DynamicModuleInfo* dynamic_info = nullptr; @@ -111,6 +114,7 @@ public: void LoadSymbols(Module* m); SymbolsResolver* getHLESymbols() { return m_HLEsymbols; } void Relocate(Module* m); + void Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info); private: const ModuleInfo* FindModule(const Module& m, const std::string& id); diff --git a/src/Core/PS4/Loader/SymbolsResolver.cpp b/src/Core/PS4/Loader/SymbolsResolver.cpp index 3dc4e1c3..de28a99a 100644 --- a/src/Core/PS4/Loader/SymbolsResolver.cpp +++ b/src/Core/PS4/Loader/SymbolsResolver.cpp @@ -5,9 +5,26 @@ void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) { SymbolRecord r{}; - char str[256]; - sprintf(str, "%s (%s)[%s_v%d][%s_v%d.%d]", s.name.c_str(),s.nidName.c_str(), s.library.c_str(), s.library_version, s.module.c_str(),s.module_version_major, s.module_version_minor); - r.name = std::string(str); + r.name = GenerateName(s); r.virtual_address = virtual_addr; m_symbols.push_back(r); +} + +std::string SymbolsResolver::GenerateName(const SymbolRes& s) { + char str[256]; + sprintf(str, "%s lib[%s_v%d]mod[%s_v%d.%d]", s.name.c_str(),s.library.c_str(), s.library_version, s.module.c_str(), + s.module_version_major, s.module_version_minor); + return std::string(str); +} + +const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const { + std::string name = GenerateName(s); + int index = 0; + for (auto symbol : m_symbols) { + if (symbol.name.compare(name) == 0) { + return &m_symbols.at(index); + } + index++; + } + return nullptr; } \ No newline at end of file diff --git a/src/Core/PS4/Loader/SymbolsResolver.h b/src/Core/PS4/Loader/SymbolsResolver.h index 4abdd5b5..9932e050 100644 --- a/src/Core/PS4/Loader/SymbolsResolver.h +++ b/src/Core/PS4/Loader/SymbolsResolver.h @@ -31,6 +31,9 @@ public: virtual ~SymbolsResolver() = default; void AddSymbol(const SymbolRes& s, u64 virtual_addr); + const SymbolRecord* FindSymbol(const SymbolRes& s) const; + + static std::string GenerateName(const SymbolRes& s); private: std::vector m_symbols; From 0ac4032d00f87fa64247d1ed876aee23cda13675 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 12 Jul 2023 14:44:37 +0300 Subject: [PATCH 10/20] some missing nid names from videoout_basic demo --- src/Core/PS4/Util/aerolib.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Core/PS4/Util/aerolib.h b/src/Core/PS4/Util/aerolib.h index e51aa49b..9c210888 100644 --- a/src/Core/PS4/Util/aerolib.h +++ b/src/Core/PS4/Util/aerolib.h @@ -11207,7 +11207,20 @@ namespace aerolib { {"TLar1HULv1Q","sceZlibInflate"}, {"m1YErdIXCp4","sceZlibInitialize"}, {"uB8VlDD4e0s","sceZlibWaitForDone"}, - {"b-Qiqugeo5U","sce_libc_tls_heap"} - + {"b-Qiqugeo5U","sce_libc_tls_heap"}, + + //libc + {"P330P3dFF68", "Need_sceLibc"}, + {"bzQExy189ZI", "_init_env"}, + {"8G2LB+A3rzg", "atexit"}, + {"XKRegsFpEpk", "catchReturnFromMain"}, + {"uMei1W9uyNo", "exit"}, + {"3GPpjQdAMTw", "__cxa_guard_acquire"}, + {"9rAeANT2tyE", "__cxa_guard_release"}, + {"DfivPArhucg", "memcmp"}, + {"Q3VBxCXhUHs", "memcpy"}, + //libkernel + {"Ou3iL1abvng", "__stack_chk_fail"}, + {"f7uOxY9mM1U", "__stack_chk_guard"} }; }; \ No newline at end of file From 063a68981221e32edfd792da42f622a1d3409b30 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 13 Jul 2023 12:56:36 +0300 Subject: [PATCH 11/20] patching more dummy functions --- CMakeLists.txt | 2 +- src/Core/PS4/HLE/LibC.cpp | 15 +++---------- src/Core/PS4/HLE/LibC.h | 2 +- src/Core/PS4/HLE/LibKernel.cpp | 30 +++++++++++++++++++++++++ src/Core/PS4/HLE/LibKernel.h | 13 +++++++++++ src/Core/PS4/HLE/LibSceGnmDriver.cpp | 0 src/Core/PS4/HLE/LibSceGnmDriver.h | 0 src/Core/PS4/HLE/LibSceVideoOut.cpp | 0 src/Core/PS4/HLE/LibSceVideoOut.h | 0 src/Core/PS4/HLE/Libs.cpp | 4 +++- src/Core/PS4/HLE/Libs.h | 15 +++++++++++++ src/Core/PS4/Linker.cpp | 2 +- src/Core/PS4/Loader/SymbolsResolver.cpp | 2 ++ 13 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 src/Core/PS4/HLE/LibKernel.cpp create mode 100644 src/Core/PS4/HLE/LibKernel.h create mode 100644 src/Core/PS4/HLE/LibSceGnmDriver.cpp create mode 100644 src/Core/PS4/HLE/LibSceGnmDriver.h create mode 100644 src/Core/PS4/HLE/LibSceVideoOut.cpp create mode 100644 src/Core/PS4/HLE/LibSceVideoOut.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ee1da38..33ae2b02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ add_executable(shadps4 src/Core/Memory.h src/Core/PS4/Linker.cpp src/Core/PS4/Linker.h - "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h") + "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h") find_package(OpenGL REQUIRED) diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index 1ae10613..2154fd86 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -1,4 +1,5 @@ #include "LibC.h" +#include "Libs.h" #include "../Loader/Elf.h" namespace HLE::Libs::LibC { @@ -11,18 +12,8 @@ namespace HLE::Libs::LibC { //__debugbreak();//if we reach here it will be a great progress :D } - void LibC_RegisterFunc(SymbolsResolver* sym) + void LibC_Register(SymbolsResolver* sym) { - //TODO this will be convert to macro probably once we decide how will it work and what's the best - SymbolRes sr {}; - sr.name = "bzQExy189ZI"; - sr.library = "libc"; - sr.library_version = 1; - sr.module = "libc"; - sr.module_version_major = 1; - sr.module_version_minor = 1; - sr.type = STT_FUN; - auto func = reinterpret_cast(init_env); - sym->AddSymbol(sr, func); + LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); } }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibC.h b/src/Core/PS4/HLE/LibC.h index 0f4f1726..2f0cc2b7 100644 --- a/src/Core/PS4/HLE/LibC.h +++ b/src/Core/PS4/HLE/LibC.h @@ -3,7 +3,7 @@ namespace HLE::Libs::LibC { - void LibC_RegisterFunc(SymbolsResolver* sym); + void LibC_Register(SymbolsResolver* sym); //functions static void init_env(); diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp new file mode 100644 index 00000000..7ec0ec2d --- /dev/null +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -0,0 +1,30 @@ +#include "../Loader/Elf.h" +#include "LibKernel.h" +#include "Libs.h" + +namespace HLE::Libs::LibKernel { + + int sceKernelAllocateDirectMemory(off_t searchStart, off_t searchEnd, size_t len, size_t alignment, int memoryType, off_t* physAddrOut) { return 0;//OK + } + size_t sceKernelGetDirectMemorySize() { return 0; + } + int32_t sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t directMemoryStart, size_t alignment) { return 0; + } + int32_t sceKernelReleaseDirectMemory(off_t start, size_t len) { return 0; + } + + int sceKernelCreateEqueue(/* SceKernelEqueue* eq*/int eq,const char* name) + { return 0; + } + + void LibKernel_Register(SymbolsResolver* sym) { + //memory + LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory); + LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetDirectMemorySize); + LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, sceKernelMapDirectMemory); + LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory); + //equeue + LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue); + } + +}; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.h b/src/Core/PS4/HLE/LibKernel.h new file mode 100644 index 00000000..7361c21a --- /dev/null +++ b/src/Core/PS4/HLE/LibKernel.h @@ -0,0 +1,13 @@ +#include "../Loader/SymbolsResolver.h" + +namespace HLE::Libs::LibKernel { + +void LibKernel_Register(SymbolsResolver* sym); +// functions +int sceKernelAllocateDirectMemory(off_t searchStart, off_t searchEnd, size_t len, size_t alignment, int memoryType, off_t* physAddrOut); +size_t sceKernelGetDirectMemorySize(); +int sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name); +int32_t sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t directMemoryStart, size_t alignment); +int32_t sceKernelReleaseDirectMemory(off_t start, size_t len); + +}; // namespace HLE::Libs::LibKernel \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.cpp b/src/Core/PS4/HLE/LibSceGnmDriver.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.h b/src/Core/PS4/HLE/LibSceGnmDriver.h new file mode 100644 index 00000000..e69de29b diff --git a/src/Core/PS4/HLE/LibSceVideoOut.cpp b/src/Core/PS4/HLE/LibSceVideoOut.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/Core/PS4/HLE/LibSceVideoOut.h b/src/Core/PS4/HLE/LibSceVideoOut.h new file mode 100644 index 00000000..e69de29b diff --git a/src/Core/PS4/HLE/Libs.cpp b/src/Core/PS4/HLE/Libs.cpp index c4dd7f67..66f319f6 100644 --- a/src/Core/PS4/HLE/Libs.cpp +++ b/src/Core/PS4/HLE/Libs.cpp @@ -1,10 +1,12 @@ #include "Libs.h" #include "LibC.h" +#include "LibKernel.h" namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver *sym) { - LibC::LibC_RegisterFunc(sym); + LibC::LibC_Register(sym); + LibKernel::LibKernel_Register(sym); } } \ No newline at end of file diff --git a/src/Core/PS4/HLE/Libs.h b/src/Core/PS4/HLE/Libs.h index 9e1944c6..a7177ca3 100644 --- a/src/Core/PS4/HLE/Libs.h +++ b/src/Core/PS4/HLE/Libs.h @@ -1,6 +1,21 @@ #pragma once #include "../Loader/SymbolsResolver.h" + +#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ + {\ + SymbolRes sr{}; \ + sr.name = nid; \ + sr.library = lib; \ + sr.library_version = libversion;\ + sr.module = mod;\ + sr.module_version_major = moduleVersionMajor;\ + sr.module_version_minor = moduleVersionMinor;\ + sr.type = STT_FUN;\ + auto func = reinterpret_cast(function);\ + sym->AddSymbol(sr, func);\ + } + namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver* sym); } \ No newline at end of file diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp index aed80637..e7461690 100644 --- a/src/Core/PS4/Linker.cpp +++ b/src/Core/PS4/Linker.cpp @@ -569,7 +569,7 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) { } else { - LOG_INFO_IF(debug_loader, "function not patched!\n"); + LOG_INFO_IF(debug_loader, "function not patched! {}\n",rel_name); } } diff --git a/src/Core/PS4/Loader/SymbolsResolver.cpp b/src/Core/PS4/Loader/SymbolsResolver.cpp index de28a99a..babce4f5 100644 --- a/src/Core/PS4/Loader/SymbolsResolver.cpp +++ b/src/Core/PS4/Loader/SymbolsResolver.cpp @@ -1,5 +1,6 @@ #include "../../../types.h" #include "SymbolsResolver.h" +#include "../../../Util/Log.h" void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) @@ -26,5 +27,6 @@ const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const { } index++; } + LOG_INFO_IF(true, "unresolved! {}\n", name); return nullptr; } \ No newline at end of file From 3cbbdd5b2f5a60ff554d225ffef3997288ab9ea9 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 13 Jul 2023 18:36:03 +0300 Subject: [PATCH 12/20] patching sceVideoOut functions --- src/Core/PS4/HLE/LibSceGnmDriver.cpp | 12 +++++++ src/Core/PS4/HLE/LibSceGnmDriver.h | 8 +++++ src/Core/PS4/HLE/LibSceVideoOut.cpp | 49 ++++++++++++++++++++++++++++ src/Core/PS4/HLE/LibSceVideoOut.h | 18 ++++++++++ src/Core/PS4/HLE/Libs.cpp | 4 +++ 5 files changed, 91 insertions(+) diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.cpp b/src/Core/PS4/HLE/LibSceGnmDriver.cpp index e69de29b..36085b79 100644 --- a/src/Core/PS4/HLE/LibSceGnmDriver.cpp +++ b/src/Core/PS4/HLE/LibSceGnmDriver.cpp @@ -0,0 +1,12 @@ +#include "LibSceGnmDriver.h" +#include "Libs.h" +#include "../Loader/Elf.h" + +namespace HLE::Libs::LibSceGnmDriver { + + void LibSceGnmDriver_Register(SymbolsResolver* sym) + { + + } + +}; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.h b/src/Core/PS4/HLE/LibSceGnmDriver.h index e69de29b..ade8683a 100644 --- a/src/Core/PS4/HLE/LibSceGnmDriver.h +++ b/src/Core/PS4/HLE/LibSceGnmDriver.h @@ -0,0 +1,8 @@ +#pragma once +#include "../Loader/SymbolsResolver.h" + +namespace HLE::Libs::LibSceGnmDriver { + +void LibSceGnmDriver_Register(SymbolsResolver* sym); + +}; // namespace HLE::Libs::LibSceGnmDriver \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceVideoOut.cpp b/src/Core/PS4/HLE/LibSceVideoOut.cpp index e69de29b..2d1d0e19 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.cpp +++ b/src/Core/PS4/HLE/LibSceVideoOut.cpp @@ -0,0 +1,49 @@ +#include "LibSceVideoOut.h" +#include "Libs.h" +#include "../Loader/Elf.h" + +namespace HLE::Libs::LibSceVideoOut { + + int32_t sceVideoOutGetFlipStatus(int32_t handle /*, SceVideoOutFlipStatus* status*/){ + return 0; + } + + int32_t sceVideoOutSubmitFlip(int32_t handle, int32_t bufferIndex, int32_t flipMode,int64_t flipArg){ + return 0; + } + int32_t sceVideoOutRegisterBuffers(int32_t handle, int32_t startIndex, void* const* addresses, int32_t bufferNum /*, + const SceVideoOutBufferAttribute* attribute*/) { + return 0; + } + int32_t sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata) { + return 0; + } + int32_t sceVideoOutSetFlipRate(int32_t handle, int32_t rate) { + return 0; + } + void sceVideoOutSetBufferAttribute(/* SceVideoOutBufferAttribute* attribute,*/ uint32_t pixelFormat, uint32_t tilingMode, uint32_t aspectRatio, + uint32_t width, uint32_t height, uint32_t pitchInPixel) + { + + } + int32_t sceVideoOutGetResolutionStatus(int32_t handle /*, SceVideoOutResolutionStatus* status*/) + { return 0; + } + int32_t sceVideoOutOpen(/* SceUserServiceUserId userId,*/ int32_t busType, int32_t index, const void* param) { return 0; + } + int32_t sceVideoOutIsFlipPending(int32_t handle) { return 0; + } + void LibSceVideoOut_Register(SymbolsResolver* sym) + { + LIB_FUNCTION("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetFlipStatus); + LIB_FUNCTION("U46NwOiJpys", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSubmitFlip); + LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutRegisterBuffers); + LIB_FUNCTION("HXzjK9yI30k", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutAddFlipEvent); + LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetFlipRate); + LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetBufferAttribute); + LIB_FUNCTION("6kPnj51T62Y", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetResolutionStatus); + LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutOpen); + LIB_FUNCTION("zgXifHT9ErY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutIsFlipPending); + } + +}; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceVideoOut.h b/src/Core/PS4/HLE/LibSceVideoOut.h index e69de29b..6f54daf9 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.h +++ b/src/Core/PS4/HLE/LibSceVideoOut.h @@ -0,0 +1,18 @@ +#pragma once +#include "../Loader/SymbolsResolver.h" + +namespace HLE::Libs::LibSceVideoOut { + +void LibSceVideoOut_Register(SymbolsResolver* sym); +//functions +int32_t sceVideoOutGetFlipStatus(int32_t handle /*, SceVideoOutFlipStatus* status*/); +int32_t sceVideoOutSubmitFlip(int32_t handle, int32_t bufferIndex, int32_t flipMode, int64_t flipArg); +int32_t sceVideoOutRegisterBuffers(int32_t handle, int32_t startIndex, void* const* addresses, int32_t bufferNum /*,const SceVideoOutBufferAttribute* attribute*/); +int32_t sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata); +int32_t sceVideoOutSetFlipRate(int32_t handle, int32_t rate); +void sceVideoOutSetBufferAttribute(/* SceVideoOutBufferAttribute* attribute,*/ uint32_t pixelFormat, uint32_t tilingMode, uint32_t aspectRatio, + uint32_t width, uint32_t height, uint32_t pitchInPixel); +int32_t sceVideoOutGetResolutionStatus(int32_t handle /*, SceVideoOutResolutionStatus* status*/); +int32_t sceVideoOutOpen(/* SceUserServiceUserId userId,*/ int32_t busType, int32_t index, const void* param); +int32_t sceVideoOutIsFlipPending(int32_t handle); +}; // namespace HLE::Libs::LibSceVideoOut \ No newline at end of file diff --git a/src/Core/PS4/HLE/Libs.cpp b/src/Core/PS4/HLE/Libs.cpp index 66f319f6..09f1d85b 100644 --- a/src/Core/PS4/HLE/Libs.cpp +++ b/src/Core/PS4/HLE/Libs.cpp @@ -1,6 +1,8 @@ #include "Libs.h" #include "LibC.h" #include "LibKernel.h" +#include "LibSceVideoOut.h" +#include "LibSceGnmDriver.h" namespace HLE::Libs { @@ -8,5 +10,7 @@ namespace HLE::Libs { { LibC::LibC_Register(sym); LibKernel::LibKernel_Register(sym); + LibSceVideoOut::LibSceVideoOut_Register(sym); + LibSceGnmDriver::LibSceGnmDriver_Register(sym); } } \ No newline at end of file From d9da9ade78f6aaf37afcf0f55b9bd25690372fdd Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 14 Jul 2023 14:29:13 +0300 Subject: [PATCH 13/20] more dummy patching functions --- src/Core/PS4/HLE/LibC.cpp | 38 ++++++++++- src/Core/PS4/HLE/LibC.h | 6 +- src/Core/PS4/HLE/LibKernel.cpp | 14 ++++- src/Core/PS4/HLE/LibKernel.h | 3 +- src/Core/PS4/HLE/LibSceGnmDriver.cpp | 94 +++++++++++++++++++++++++++- src/Core/PS4/HLE/LibSceGnmDriver.h | 14 +++++ 6 files changed, 164 insertions(+), 5 deletions(-) diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index 2154fd86..aec94d3d 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -12,8 +12,44 @@ namespace HLE::Libs::LibC { //__debugbreak();//if we reach here it will be a great progress :D } + int __cxa_guard_acquire(u64* guard_object) + { return 0; + } + + int __cxa_guard_release(u64* guard_object) + { return 0; + } + + int memcmp(const void* s1, const void* s2, size_t n) { + return ::memcmp(s1, s2, n); + } + + void* memcpy(void* dest, const void* src, size_t n) { + return ::memcpy(dest, src, n); + } + + static void catchReturnFromMain(int status) + { + + } + static void exit(int code) + { + + } + static int atexit(void (*func)()) + { return 0; + } + void LibC_Register(SymbolsResolver* sym) { LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); - } + LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire); + LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, __cxa_guard_release); + LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1, memcmp); + LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1, memcpy); + LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, catchReturnFromMain); + LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1, exit); + LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, atexit); + } + }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibC.h b/src/Core/PS4/HLE/LibC.h index 2f0cc2b7..241a785c 100644 --- a/src/Core/PS4/HLE/LibC.h +++ b/src/Core/PS4/HLE/LibC.h @@ -6,5 +6,9 @@ namespace HLE::Libs::LibC { void LibC_Register(SymbolsResolver* sym); //functions static void init_env(); - + static void exit(int code); + static void catchReturnFromMain(int status); + int __cxa_guard_acquire(u64* guard_object); + int memcmp(const void* s1, const void* s2, size_t n); + void* memcpy(void* dest, const void* src, size_t n); }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 7ec0ec2d..231213c8 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -16,7 +16,15 @@ namespace HLE::Libs::LibKernel { int sceKernelCreateEqueue(/* SceKernelEqueue* eq*/int eq,const char* name) { return 0; } - + int sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/) { return 0; + } + int sceKernelIsNeoMode() + { return 0; + } + + static void stack_chk_fail() { + + } void LibKernel_Register(SymbolsResolver* sym) { //memory LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory); @@ -25,6 +33,10 @@ namespace HLE::Libs::LibKernel { LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory); //equeue LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue); + LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, sceKernelWaitEqueue); + //misc + LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, sceKernelIsNeoMode); + LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); } }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.h b/src/Core/PS4/HLE/LibKernel.h index 7361c21a..fa6efff9 100644 --- a/src/Core/PS4/HLE/LibKernel.h +++ b/src/Core/PS4/HLE/LibKernel.h @@ -9,5 +9,6 @@ size_t sceKernelGetDirectMemorySize(); int sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name); int32_t sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t directMemoryStart, size_t alignment); int32_t sceKernelReleaseDirectMemory(off_t start, size_t len); - +int sceKernelIsNeoMode(); +int sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/); }; // namespace HLE::Libs::LibKernel \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.cpp b/src/Core/PS4/HLE/LibSceGnmDriver.cpp index 36085b79..542ec76e 100644 --- a/src/Core/PS4/HLE/LibSceGnmDriver.cpp +++ b/src/Core/PS4/HLE/LibSceGnmDriver.cpp @@ -4,9 +4,101 @@ namespace HLE::Libs::LibSceGnmDriver { - void LibSceGnmDriver_Register(SymbolsResolver* sym) + int sceGnmAddEqEvent(/* SceKernelEqueue eq, EqEventType id,*/ void* udata) + { return 0; + } + bool sceGnmAreSubmitsAllowed() + { + return true; + } + + int /* WorkloadStatus*/ sceGnmBeginWorkload(uint64_t* workload /*, WorkloadStream stream*/) + { + return 0; + } + + int /* WorkloadStatus*/ sceGnmCreateWorkloadStream(/* WorkloadStream* workloadStream,*/ const char* name) + { + return 0; + } + void sceGnmDebugHardwareStatus(/* HardwareStatus flag*/) { + + } + void sceGnmSetGsRingSizes(/* GsRingSizeSetup esgsRingSize, GsRingSizeSetup gsvsRingSize*/) { } + int32_t sceGnmSetWaveLimitMultipliers(uint16_t targetPipeMask, uint8_t gfxRatio, const uint8_t (*pipeRatios)[7]) + { return 0; + } + int /*MipStatsError*/ sceGnmSetupMipStatsReport(void* outputBuffer, uint32_t sizeInBytes, uint8_t intervalsBetweenReports, + uint8_t numReportsBeforeReset /*, MipStatsResetForce mipStatsResetForce*/) + { + return 0; + } + + int sceGnmSubmitCommandBuffers(uint32_t count, void* dcb_gpu_addrs[], const uint32_t* dcb_sizes_in_bytes, void* ccb_gpu_addrs[], + const uint32_t* ccb_sizes_in_bytes) + { + return 0; + } + + int sceGnmSubmitAndFlipCommandBuffers(uint32_t count, void* dcb_gpu_addrs[], const uint32_t* dcb_sizes_in_bytes, + void* ccb_gpu_addrs[], const uint32_t* ccb_sizes_in_bytes, int handle, int index, + int flip_mode, int64_t flip_arg) + { + return 0; + } + void LibSceGnmDriver_Register(SymbolsResolver* sym) + { + LIB_FUNCTION("b0xyllnVY-I", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmAddEqEvent); + LIB_FUNCTION("b08AgtPlHPg", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmAreSubmitsAllowed); + LIB_FUNCTION("ihxrbsoSKWc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmBeginWorkload); + LIB_FUNCTION("5udAm+6boVg", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmCreateWorkloadStream); + LIB_FUNCTION("qpGITzPE+Zc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDebugHardwareStatus); + LIB_FUNCTION("jtkqXpAOY6w", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSetGsRingSizes); + LIB_FUNCTION("XiyzNZ9J4nQ", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSetWaveLimitMultipliers); + LIB_FUNCTION("+xuDhxlWRPg", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSetupMipStatsReport); + LIB_FUNCTION("zwY0YV91TTI", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitCommandBuffers); + LIB_FUNCTION("xbxNatawohc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitAndFlipCommandBuffers); + + /*LIB_FUNCTION("Ga6r7H6Y0RI", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitAndFlipCommandBuffersForWorkload); + LIB_FUNCTION("f33OrruQYbM", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceRazorIsLoaded); + LIB_FUNCTION("jRcI8VcgTz4", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitCommandBuffersForWorkload); + LIB_FUNCTION("PVT+fuoS9gU", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDeleteEqEvent); + LIB_FUNCTION("yvZ73uQUqrk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitDone); + LIB_FUNCTION("UtObDRQiGbs", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDestroyWorkloadStream); + LIB_FUNCTION("bX5IbRvECXk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDingDong); + LIB_FUNCTION("byXlqupd8cE", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDingDongForWorkload); + LIB_FUNCTION("HHo1BAljZO8", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDisableMipStatsReport); + LIB_FUNCTION("TLV4mswiZ4A", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDriverCaptureInProgress); + LIB_FUNCTION("ArSg-TGinhk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmUnmapComputeQueue); + LIB_FUNCTION("R6z1xM3pW-w", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDriverTraceInProgress); + LIB_FUNCTION("d88anrgNoKY", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDriverTriggerCapture); + LIB_FUNCTION("Fa3x75OOLRA", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmEndWorkload); + LIB_FUNCTION("iBt3Oe00Kvc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmFlushGarlic); + LIB_FUNCTION("UoYY0DWMC0U", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetEqEventType); + LIB_FUNCTION("H7-fgvEutM0", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetEqTimeStamp); + LIB_FUNCTION("oL4hGI1PMpw", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetGpuBlockStatus); + LIB_FUNCTION("tZCSL5ulnB4", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetGpuInfoStatus); + LIB_FUNCTION("iFirFzgYsvw", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetLastWaitedAddress); + LIB_FUNCTION("KnldROUkWJY", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetNumTcaUnits); + LIB_FUNCTION("FFVZcCu3zWU", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetOffChipTessellationBufferSize); + LIB_FUNCTION("dewXw5roLs0", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetPhysicalCounterFromVirtualized); + LIB_FUNCTION("fzJdEihTFV4", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetProtectionFaultTimeStamp); + LIB_FUNCTION("nEyFbYUloIM", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetShaderProgramBaseAddress); + LIB_FUNCTION("k7iGTvDQPLQ", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetShaderStatus); + LIB_FUNCTION("ln33zjBrfjk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmGetTheTessellationFactorRingBufferBaseAddress); + LIB_FUNCTION("jg33rEKLfVs", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmIsUserPaEnabled); + LIB_FUNCTION("26PM5Mzl8zc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmLogicalCuIndexToPhysicalCuIndex); + LIB_FUNCTION("RU74kek-N0c", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmLogicalCuMaskToPhysicalCuMask); + LIB_FUNCTION("29oKvKXzEZo", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmMapComputeQueue); + LIB_FUNCTION("A+uGq+3KFtQ", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmMapComputeQueueWithPriority); + LIB_FUNCTION("u9YKpRRHe-M", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceRazorCaptureImmediate); + LIB_FUNCTION("gObODli-OH8", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmRequestFlipAndSubmitDone); + LIB_FUNCTION("6YRHhh5mHCs", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmRequestFlipAndSubmitDoneForWorkload); + LIB_FUNCTION("f85orjx7qts", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmRequestMipStatsReportAndReset);*/ + } + }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.h b/src/Core/PS4/HLE/LibSceGnmDriver.h index ade8683a..cd0a7d35 100644 --- a/src/Core/PS4/HLE/LibSceGnmDriver.h +++ b/src/Core/PS4/HLE/LibSceGnmDriver.h @@ -5,4 +5,18 @@ namespace HLE::Libs::LibSceGnmDriver { void LibSceGnmDriver_Register(SymbolsResolver* sym); +//functions +int sceGnmAddEqEvent(/* SceKernelEqueue eq, EqEventType id,*/ void* udata); +bool sceGnmAreSubmitsAllowed(); +int /* WorkloadStatus*/ sceGnmBeginWorkload(uint64_t* workload /*, WorkloadStream stream*/); +int /* WorkloadStatus*/ sceGnmCreateWorkloadStream(/* WorkloadStream* workloadStream,*/ const char* name); +void sceGnmDebugHardwareStatus(/* HardwareStatus flag*/); +void sceGnmSetGsRingSizes(/* GsRingSizeSetup esgsRingSize, GsRingSizeSetup gsvsRingSize*/); +int32_t sceGnmSetWaveLimitMultipliers(uint16_t targetPipeMask, uint8_t gfxRatio, const uint8_t (*pipeRatios)[7]); +int /*MipStatsError*/ sceGnmSetupMipStatsReport(void* outputBuffer, uint32_t sizeInBytes, uint8_t intervalsBetweenReports, + uint8_t numReportsBeforeReset /*, MipStatsResetForce mipStatsResetForce*/); +int sceGnmSubmitCommandBuffers(uint32_t count, void* dcb_gpu_addrs[], const uint32_t* dcb_sizes_in_bytes, void* ccb_gpu_addrs[], + const uint32_t* ccb_sizes_in_bytes); +int sceGnmSubmitAndFlipCommandBuffers(uint32_t count, void* dcb_gpu_addrs[], const uint32_t* dcb_sizes_in_bytes, void* ccb_gpu_addrs[], + const uint32_t* ccb_sizes_in_bytes, int handle, int index, int flip_mode, int64_t flip_arg); }; // namespace HLE::Libs::LibSceGnmDriver \ No newline at end of file From 35e21f9a8c581aa162865edd4a7b320b6e885ee2 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jul 2023 13:39:00 +0300 Subject: [PATCH 14/20] more dummy GnmDriver function calls --- src/Core/PS4/HLE/LibSceGnmDriver.cpp | 62 ++++++++++++++++++++++++++-- src/Core/PS4/HLE/LibSceGnmDriver.h | 36 ++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.cpp b/src/Core/PS4/HLE/LibSceGnmDriver.cpp index 542ec76e..e8be26a9 100644 --- a/src/Core/PS4/HLE/LibSceGnmDriver.cpp +++ b/src/Core/PS4/HLE/LibSceGnmDriver.cpp @@ -50,6 +50,63 @@ namespace HLE::Libs::LibSceGnmDriver { { return 0; } + void sceGnmDingDong(u32 ring_id, u32 offset_dw) + { + + } + bool sceRazorIsLoaded() + { return true;// hmm??? + } + int sceGnmDeleteEqEvent(/* SceKernelEqueue eq, EqEventType id*/) + { return 0; + } + int32_t sceGnmSubmitDone() + { return 0; + } + int /* MipStatsError*/ sceGnmDisableMipStatsReport() + { return 0; + } + int sceGnmSubmitAndFlipCommandBuffersForWorkload() + { return 0; + } + int sceGnmSubmitCommandBuffersForWorkload() + { return 0; + } + int /* WorkloadStatus*/ sceGnmDestroyWorkloadStream(/*WorkloadStream workloadStream*/) + { return 0; + } + void sceGnmDingDongForWorkload() + { + + } + void sceGnmDriverCaptureInProgress() {} + void sceGnmUnmapComputeQueue(){} + void sceGnmDriverTraceInProgress(){} + void sceGnmDriverTriggerCapture(){} + void sceGnmEndWorkload(){} + void sceGnmFlushGarlic(){} + void sceGnmGetEqEventType(){} + void sceGnmGetEqTimeStamp(){} + void sceGnmGetGpuBlockStatus(){} + void sceGnmGetGpuInfoStatus(){} + void sceGnmGetLastWaitedAddress(){} + void sceGnmGetNumTcaUnits(){} + void sceGnmGetOffChipTessellationBufferSize(){} + void sceGnmGetPhysicalCounterFromVirtualized(){} + void sceGnmGetProtectionFaultTimeStamp(){} + void sceGnmGetShaderProgramBaseAddress(){} + void sceGnmGetShaderStatus(){} + void sceGnmGetTheTessellationFactorRingBufferBaseAddress(){} + void sceGnmIsUserPaEnabled(){} + void sceGnmLogicalCuIndexToPhysicalCuIndex(){} + void sceGnmLogicalCuMaskToPhysicalCuMask(){} + void sceGnmMapComputeQueue(){} + void sceGnmMapComputeQueueWithPriority(){} + void sceRazorCaptureImmediate(){} + void sceGnmRequestFlipAndSubmitDone(){} + void sceGnmRequestFlipAndSubmitDoneForWorkload(){} + void sceGnmRequestMipStatsReportAndReset(){} + void LibSceGnmDriver_Register(SymbolsResolver* sym) { LIB_FUNCTION("b0xyllnVY-I", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmAddEqEvent); @@ -62,8 +119,7 @@ namespace HLE::Libs::LibSceGnmDriver { LIB_FUNCTION("+xuDhxlWRPg", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSetupMipStatsReport); LIB_FUNCTION("zwY0YV91TTI", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitCommandBuffers); LIB_FUNCTION("xbxNatawohc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitAndFlipCommandBuffers); - - /*LIB_FUNCTION("Ga6r7H6Y0RI", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitAndFlipCommandBuffersForWorkload); + LIB_FUNCTION("Ga6r7H6Y0RI", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitAndFlipCommandBuffersForWorkload); LIB_FUNCTION("f33OrruQYbM", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceRazorIsLoaded); LIB_FUNCTION("jRcI8VcgTz4", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitCommandBuffersForWorkload); LIB_FUNCTION("PVT+fuoS9gU", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmDeleteEqEvent); @@ -98,7 +154,7 @@ namespace HLE::Libs::LibSceGnmDriver { LIB_FUNCTION("u9YKpRRHe-M", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceRazorCaptureImmediate); LIB_FUNCTION("gObODli-OH8", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmRequestFlipAndSubmitDone); LIB_FUNCTION("6YRHhh5mHCs", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmRequestFlipAndSubmitDoneForWorkload); - LIB_FUNCTION("f85orjx7qts", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmRequestMipStatsReportAndReset);*/ + LIB_FUNCTION("f85orjx7qts", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmRequestMipStatsReportAndReset); } }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.h b/src/Core/PS4/HLE/LibSceGnmDriver.h index cd0a7d35..b4a640d1 100644 --- a/src/Core/PS4/HLE/LibSceGnmDriver.h +++ b/src/Core/PS4/HLE/LibSceGnmDriver.h @@ -19,4 +19,40 @@ int sceGnmSubmitCommandBuffers(uint32_t count, void* dcb_gpu_addrs[], const uint const uint32_t* ccb_sizes_in_bytes); int sceGnmSubmitAndFlipCommandBuffers(uint32_t count, void* dcb_gpu_addrs[], const uint32_t* dcb_sizes_in_bytes, void* ccb_gpu_addrs[], const uint32_t* ccb_sizes_in_bytes, int handle, int index, int flip_mode, int64_t flip_arg); +void sceGnmDingDong(u32 ring_id, u32 offset_dw); +bool sceRazorIsLoaded(); +int sceGnmDeleteEqEvent(/* SceKernelEqueue eq, EqEventType id*/); +int32_t sceGnmSubmitDone(); +int /* MipStatsError*/ sceGnmDisableMipStatsReport(); +int sceGnmSubmitAndFlipCommandBuffersForWorkload(); +int sceGnmSubmitCommandBuffersForWorkload(); +int /* WorkloadStatus*/ sceGnmDestroyWorkloadStream(/*WorkloadStream workloadStream*/); +void sceGnmDingDongForWorkload(); +void sceGnmDriverCaptureInProgress(); +void sceGnmUnmapComputeQueue(); +void sceGnmDriverTraceInProgress(); +void sceGnmDriverTriggerCapture(); +void sceGnmEndWorkload(); +void sceGnmFlushGarlic(); +void sceGnmGetEqEventType(); +void sceGnmGetEqTimeStamp(); +void sceGnmGetGpuBlockStatus(); +void sceGnmGetGpuInfoStatus(); +void sceGnmGetLastWaitedAddress(); +void sceGnmGetNumTcaUnits(); +void sceGnmGetOffChipTessellationBufferSize(); +void sceGnmGetPhysicalCounterFromVirtualized(); +void sceGnmGetProtectionFaultTimeStamp(); +void sceGnmGetShaderProgramBaseAddress(); +void sceGnmGetShaderStatus(); +void sceGnmGetTheTessellationFactorRingBufferBaseAddress(); +void sceGnmIsUserPaEnabled(); +void sceGnmLogicalCuIndexToPhysicalCuIndex(); +void sceGnmLogicalCuMaskToPhysicalCuMask(); +void sceGnmMapComputeQueue(); +void sceGnmMapComputeQueueWithPriority(); +void sceRazorCaptureImmediate(); +void sceGnmRequestFlipAndSubmitDone(); +void sceGnmRequestFlipAndSubmitDoneForWorkload(); +void sceGnmRequestMipStatsReportAndReset(); }; // namespace HLE::Libs::LibSceGnmDriver \ No newline at end of file From ecccead408e1151a06dee24ae43e89ad98a7d909 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jul 2023 13:53:27 +0300 Subject: [PATCH 15/20] all function for video out demo should resolve now --- src/Core/PS4/HLE/LibC.cpp | 4 ++++ src/Core/PS4/HLE/LibKernel.cpp | 4 ++++ src/Core/PS4/HLE/Libs.h | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index aec94d3d..db58b9df 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -4,6 +4,8 @@ namespace HLE::Libs::LibC { + static u32 g_need_sceLibc = 1; + static void init_env() //every game/demo should probably { for(;;) { @@ -50,6 +52,8 @@ namespace HLE::Libs::LibC { LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, catchReturnFromMain); LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1, exit); LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, atexit); + + LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &HLE::Libs::LibC::g_need_sceLibc); } }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 231213c8..0bb77997 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -4,6 +4,8 @@ namespace HLE::Libs::LibKernel { + static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; //dummy return + int sceKernelAllocateDirectMemory(off_t searchStart, off_t searchEnd, size_t len, size_t alignment, int memoryType, off_t* physAddrOut) { return 0;//OK } size_t sceKernelGetDirectMemorySize() { return 0; @@ -26,6 +28,8 @@ namespace HLE::Libs::LibKernel { } void LibKernel_Register(SymbolsResolver* sym) { + //obj + LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &HLE::Libs::LibKernel::g_stack_chk_guard); //memory LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory); LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetDirectMemorySize); diff --git a/src/Core/PS4/HLE/Libs.h b/src/Core/PS4/HLE/Libs.h index a7177ca3..5f94e81c 100644 --- a/src/Core/PS4/HLE/Libs.h +++ b/src/Core/PS4/HLE/Libs.h @@ -16,6 +16,19 @@ sym->AddSymbol(sr, func);\ } +#define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ + { \ + SymbolRes sr{}; \ + sr.name = nid; \ + sr.library = lib; \ + sr.library_version = libversion; \ + sr.module = mod; \ + sr.module_version_major = moduleVersionMajor; \ + sr.module_version_minor = moduleVersionMinor; \ + sr.type = STT_OBJECT; \ + auto func = reinterpret_cast(function); \ + sym->AddSymbol(sr, func); \ + } namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver* sym); } \ No newline at end of file From 3d073e2ed4f56d18d7ba57343a59fc60a846187a Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jul 2023 22:43:30 +0300 Subject: [PATCH 16/20] added winpthread library --- .gitmodules | 4 ++++ third-party/winpthread | 1 + 2 files changed, 5 insertions(+) create mode 160000 third-party/winpthread diff --git a/.gitmodules b/.gitmodules index 6d4a8197..532659db 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,7 @@ path = third-party/zydis url = https://github.com/zyantific/zydis.git shallow = true +[submodule "third-party/winpthread"] + path = third-party/winpthread + url = https://github.com/shadps4/winpthread.git + branch = main diff --git a/third-party/winpthread b/third-party/winpthread new file mode 160000 index 00000000..e6a93f20 --- /dev/null +++ b/third-party/winpthread @@ -0,0 +1 @@ +Subproject commit e6a93f2050226b33347ca753fa94f6b1a6c34f39 From 5180a282ede612669beb043cbd5c2f2bb5a605e7 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jul 2023 23:19:33 +0300 Subject: [PATCH 17/20] updates submodules to latest --- CMakeLists.txt | 6 ++++-- third-party/SDL | 2 +- third-party/fmt | 2 +- third-party/imgui | 2 +- third-party/magic_enum | 2 +- third-party/spdlog | 2 +- third-party/winpthread | 2 +- third-party/zydis | 2 +- 8 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33ae2b02..382a505f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,8 +15,8 @@ include_directories(third-party/sdl/) include_directories(third-party/fmt/include) include_directories(third-party/magic_enum/include) include_directories(third-party/zydis/include/Zydis) +include_directories(third-party/winpthread/include) add_subdirectory("third-party") - #=================== EXAMPLE =================== add_executable(shadps4 @@ -37,10 +37,12 @@ add_executable(shadps4 "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h") find_package(OpenGL REQUIRED) - target_link_libraries(shadps4 PUBLIC fmt spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY}) add_custom_command(TARGET shadps4 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $) +add_custom_command(TARGET shadps4 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${PROJECT_SOURCE_DIR}/third-party/winpthread/bin/libwinpthread-1.dll" $) diff --git a/third-party/SDL b/third-party/SDL index 125e7420..27556e09 160000 --- a/third-party/SDL +++ b/third-party/SDL @@ -1 +1 @@ -Subproject commit 125e7420ecd2b0d1847aef804f53e614fbc68253 +Subproject commit 27556e098ecce54014ed1fc11c1e974ffdf4bc93 diff --git a/third-party/fmt b/third-party/fmt index de0757b5..661b23ed 160000 --- a/third-party/fmt +++ b/third-party/fmt @@ -1 +1 @@ -Subproject commit de0757b578244e0bf7ac50007fb5e25fcc899c7c +Subproject commit 661b23edeb52d400cf5812e7330f14f05c072fab diff --git a/third-party/imgui b/third-party/imgui index 4fab72b4..52125a54 160000 --- a/third-party/imgui +++ b/third-party/imgui @@ -1 +1 @@ -Subproject commit 4fab72b40e2972f5d56fc884ed5797446238844e +Subproject commit 52125a54a57a458e89bc61502010e964add3cdd5 diff --git a/third-party/magic_enum b/third-party/magic_enum index 5018ef96..4904822d 160000 --- a/third-party/magic_enum +++ b/third-party/magic_enum @@ -1 +1 @@ -Subproject commit 5018ef9677521983bfedb127901284432d1a05a2 +Subproject commit 4904822db8770d04444add00a9e155568d3e8bd1 diff --git a/third-party/spdlog b/third-party/spdlog index 5a6b6caf..76dfc7e7 160000 --- a/third-party/spdlog +++ b/third-party/spdlog @@ -1 +1 @@ -Subproject commit 5a6b6cafa8d4aee3e6d0dd16a2cae9169141c831 +Subproject commit 76dfc7e7c0d3c69d3cdaa3399b63545235ccbb02 diff --git a/third-party/winpthread b/third-party/winpthread index e6a93f20..918de958 160000 --- a/third-party/winpthread +++ b/third-party/winpthread @@ -1 +1 @@ -Subproject commit e6a93f2050226b33347ca753fa94f6b1a6c34f39 +Subproject commit 918de958b720c3ba7bc47f4988609c0109a0f75b diff --git a/third-party/zydis b/third-party/zydis index d4c37ae7..a6d0c713 160000 --- a/third-party/zydis +++ b/third-party/zydis @@ -1 +1 @@ -Subproject commit d4c37ae7a9db989495eb66636a65d8d4ff69eb35 +Subproject commit a6d0c713b71b5009634868389f0ff551871273d6 From c3eb515895aa7fd635e5bf87932d010019db0b6e Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jul 2023 23:20:17 +0300 Subject: [PATCH 18/20] fixed winpthread linking --- third-party/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 7272a238..048fae86 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -27,6 +27,8 @@ option(ZYDIS_BUILD_EXAMPLES "" OFF) set(zydis_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zydis) add_subdirectory(${zydis_DIR}) +#========== winpthreads ====================== +add_subdirectory(winpthread) #=================== IMGUI =================== set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui) @@ -56,6 +58,6 @@ find_package(OpenGL REQUIRED) target_link_libraries(IMGUI PUBLIC ${OPENGL_LIBRARIES}) -target_link_libraries(IMGUI PUBLIC SDL3-shared ${CMAKE_DL_LIBS} Zydis) +target_link_libraries(IMGUI PUBLIC SDL3-shared ${CMAKE_DL_LIBS} Zydis winpthread) From f03c1a5fb4df1a602dc46b5c9f0510ec526c5071 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 17 Jul 2023 23:46:25 +0300 Subject: [PATCH 19/20] initial thread management files --- CMakeLists.txt | 2 +- src/Core/PS4/HLE/Kernel/ThreadManagement.cpp | 4 ++++ src/Core/PS4/HLE/Kernel/ThreadManagement.h | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/Core/PS4/HLE/Kernel/ThreadManagement.cpp create mode 100644 src/Core/PS4/HLE/Kernel/ThreadManagement.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 382a505f..95d7b1d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ add_executable(shadps4 src/Core/Memory.h src/Core/PS4/Linker.cpp src/Core/PS4/Linker.h - "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h") + "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h") find_package(OpenGL REQUIRED) target_link_libraries(shadps4 PUBLIC fmt spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY}) diff --git a/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp b/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp new file mode 100644 index 00000000..646d14a6 --- /dev/null +++ b/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp @@ -0,0 +1,4 @@ +namespace HLE::Libs::LibKernel::ThreadManagement +{ + +}; \ No newline at end of file diff --git a/src/Core/PS4/HLE/Kernel/ThreadManagement.h b/src/Core/PS4/HLE/Kernel/ThreadManagement.h new file mode 100644 index 00000000..975aee2f --- /dev/null +++ b/src/Core/PS4/HLE/Kernel/ThreadManagement.h @@ -0,0 +1,5 @@ +#pragma once + +namespace HLE::Libs::LibKernel::ThreadManagement { + +}; \ No newline at end of file From ce95520f38bb3ebeb03416a3bc9b25ffaff00560 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 18 Jul 2023 18:54:46 +0300 Subject: [PATCH 20/20] some pthread work nothing exciting --- CMakeLists.txt | 2 +- src/Core/PS4/HLE/ErrorCodes.h | 5 + src/Core/PS4/HLE/Kernel/ThreadManagement.cpp | 121 +++++++++++++++++++ src/Core/PS4/HLE/Kernel/ThreadManagement.h | 34 +++++- 4 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/Core/PS4/HLE/ErrorCodes.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 95d7b1d7..d6acb9db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ add_executable(shadps4 src/Core/Memory.h src/Core/PS4/Linker.cpp src/Core/PS4/Linker.h - "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h") + "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h") find_package(OpenGL REQUIRED) target_link_libraries(shadps4 PUBLIC fmt spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY}) diff --git a/src/Core/PS4/HLE/ErrorCodes.h b/src/Core/PS4/HLE/ErrorCodes.h new file mode 100644 index 00000000..5ff20660 --- /dev/null +++ b/src/Core/PS4/HLE/ErrorCodes.h @@ -0,0 +1,5 @@ +#pragma once +constexpr int SCE_OK = 0; + +constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c;//Insufficient memory +constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016;//null or invalid states diff --git a/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp b/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp index 646d14a6..e6cb0fba 100644 --- a/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp +++ b/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp @@ -1,4 +1,125 @@ +#include "ThreadManagement.h" +#include "../ErrorCodes.h" + namespace HLE::Libs::LibKernel::ThreadManagement { +thread_local PthreadInternal* g_pthread_self = nullptr; +PThreadCxt* g_pthread_cxt = nullptr; + + + +int scePthreadAttrInit(ScePthreadAttr* attr) { + + *attr = new PthreadAttrInternal{}; + + int result = pthread_attr_init(&(*attr)->p); + + (*attr)->affinity = 0x7f; + (*attr)->guard_size = 0x1000; + + SceKernelSchedParam param{}; + param.sched_priority = 700; + + result = (result == 0 ? scePthreadAttrSetinheritsched(attr, PTHREAD_INHERIT_SCHED) : result); + result = (result == 0 ? scePthreadAttrSetschedparam(attr, ¶m) : result); + result = (result == 0 ? scePthreadAttrSetschedpolicy(attr, SCHED_OTHER) : result); + result = (result == 0 ? scePthreadAttrSetdetachstate(attr, PTHREAD_CREATE_JOINABLE) : result); + + switch (result) { + case 0: return SCE_OK; + case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM; + default: return SCE_KERNEL_ERROR_EINVAL; + } +} + +int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) { + + if (attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int pstate = PTHREAD_CREATE_JOINABLE; + switch (detachstate) { + case 0: pstate = PTHREAD_CREATE_JOINABLE; break; + case 1: pstate = PTHREAD_CREATE_DETACHED; break; + default: + __debugbreak(); //unknown state + } + + int result = pthread_attr_setdetachstate(&(*attr)->p, pstate); + + (*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED); + + if (result == 0) { + return SCE_OK; + } + return SCE_KERNEL_ERROR_EINVAL; +} + +int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) { + + if (attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + int pinherit_sched = PTHREAD_INHERIT_SCHED; + switch (inheritSched) { + case 0: pinherit_sched = PTHREAD_EXPLICIT_SCHED; break; + case 4: pinherit_sched = PTHREAD_INHERIT_SCHED; break; + default: __debugbreak(); // unknown inheritSched + } + + int result = pthread_attr_setinheritsched(&(*attr)->p, pinherit_sched); + + if (result == 0) { + return SCE_OK; + } + return SCE_KERNEL_ERROR_EINVAL; +} + +int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) { + + if (param == nullptr || attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + SceKernelSchedParam pparam{}; + if (param->sched_priority <= 478) { + pparam.sched_priority = +2; + } else if (param->sched_priority >= 733) { + pparam.sched_priority = -2; + } else { + pparam.sched_priority = 0; + } + + int result = pthread_attr_setschedparam(&(*attr)->p, &pparam); + + if (result == 0) { + return SCE_OK; + } + return SCE_KERNEL_ERROR_EINVAL; +} + +int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) { + + if (attr == nullptr || *attr == nullptr) { + return SCE_KERNEL_ERROR_EINVAL; + } + + if (policy!= SCHED_OTHER) + { + __debugbreak();//invest if policy is other and if winpthreadlibrary support it + } + + (*attr)->policy = policy; + + int result = pthread_attr_setschedpolicy(&(*attr)->p, policy); + + if (result == 0) { + return SCE_OK; + } + return SCE_KERNEL_ERROR_EINVAL; +} + }; \ No newline at end of file diff --git a/src/Core/PS4/HLE/Kernel/ThreadManagement.h b/src/Core/PS4/HLE/Kernel/ThreadManagement.h index 975aee2f..7685045e 100644 --- a/src/Core/PS4/HLE/Kernel/ThreadManagement.h +++ b/src/Core/PS4/HLE/Kernel/ThreadManagement.h @@ -1,5 +1,37 @@ #pragma once +#include +#include +#include "../../../../types.h" + +extern "C" { +struct sched_param; +} namespace HLE::Libs::LibKernel::ThreadManagement { -}; \ No newline at end of file +struct PthreadAttrInternal; + +using SceKernelSchedParam = struct sched_param; +using ScePthreadAttr = PthreadAttrInternal*; + +struct PthreadInternal { + pthread_t p; +}; +struct PthreadAttrInternal { + u64 affinity; + size_t guard_size; + int policy; + bool detached; + pthread_attr_t p; +}; + +class PThreadCxt {}; + +//HLE FUNCTIONS +int scePthreadAttrInit(ScePthreadAttr* attr); +int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate); +int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched); +int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param); +int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy); + +} // namespace HLE::Libs::LibKernel::ThreadManagement \ No newline at end of file