From 6fba3a438002c39c0446fd2b3583f0d9f01684bc Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 31 Oct 2023 19:08:33 +0200 Subject: [PATCH] finished libc refactoring --- CMakeLists.txt | 4 +- src/core/PS4/HLE/LibC.cpp | 102 -------------------- src/core/PS4/HLE/LibC.h | 13 --- src/core/PS4/HLE/Libs.cpp | 5 +- src/core/hle/libraries/libc/libc.cpp | 87 +++++++++++++++++ src/core/hle/libraries/libc/libc.h | 9 +- src/core/hle/libraries/libc/libc_cxa.cpp | 4 +- src/core/hle/libraries/libc/libc_cxa.h | 4 +- src/core/hle/libraries/libc/libc_math.cpp | 7 +- src/core/hle/libraries/libc/libc_math.h | 5 +- src/core/hle/libraries/libc/libc_stdio.cpp | 7 +- src/core/hle/libraries/libc/libc_stdio.h | 7 +- src/core/hle/libraries/libc/libc_stdlib.cpp | 15 ++- src/core/hle/libraries/libc/libc_stdlib.h | 6 +- src/core/hle/libraries/libc/libc_string.cpp | 4 +- src/core/hle/libraries/libc/libc_string.h | 5 +- 16 files changed, 137 insertions(+), 147 deletions(-) delete mode 100644 src/core/PS4/HLE/LibC.cpp delete mode 100644 src/core/PS4/HLE/LibC.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cb066ac..1c27e640 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,8 +105,8 @@ add_executable(shadps4 src/core/PS4/HLE/Kernel/event_queues.h src/core/PS4/HLE/Kernel/cpu_management.cpp src/core/PS4/HLE/Kernel/cpu_management.h - src/core/PS4/HLE/LibC.cpp - src/core/PS4/HLE/LibC.h + + "src/Util/Disassembler.cpp" "src/Util/Disassembler.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/LibKernel.cpp" "src/core/PS4/HLE/LibKernel.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" "src/debug.h" "src/core/PS4/HLE/Kernel/memory_management.cpp" "src/core/PS4/HLE/Kernel/memory_management.h" "src/core/PS4/GPU/gpu_memory.cpp" "src/core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/core/PS4/HLE/Kernel/Objects/event_queue.h" "src/core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/core/PS4/GPU/video_out_buffer.cpp" "src/core/PS4/GPU/video_out_buffer.h" "src/core/PS4/HLE/Graphics/graphics_render.cpp" "src/core/PS4/HLE/Graphics/graphics_render.h" "src/core/PS4/GPU/tile_manager.cpp" "src/core/PS4/GPU/tile_manager.h" "src/version.h" "src/emuTimer.cpp" "src/emuTimer.h" "src/core/hle/libraries/libkernel/time_management.cpp" "src/core/hle/libraries/libkernel/time_management.h") diff --git a/src/core/PS4/HLE/LibC.cpp b/src/core/PS4/HLE/LibC.cpp deleted file mode 100644 index 8f67e5d7..00000000 --- a/src/core/PS4/HLE/LibC.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "LibC.h" - -#include -#include - -#include "../Loader/Elf.h" -#include "core/hle/libraries/libc/libc.h" -#include "core/hle/libraries/libc/libc_cxa.h" -#include "core/hle/libraries/libc/libc_math.h" -#include "core/hle/libraries/libc/libc_stdio.h" -#include "core/hle/libraries/libc/libc_string.h" -#include "core/hle/libraries/libc/libc_stdlib.h" -#include "ErrorCodes.h" -#include "Libs.h" - -namespace HLE::Libs::LibC { - -static u32 g_need_sceLibc = 1; - -static PS4_SYSV_ABI void init_env() // every game/demo should probably -{ - // dummy no need atm -} - -static PS4_SYSV_ABI void catchReturnFromMain(int status) { - // dummy -} - -static PS4_SYSV_ABI void _Assert() { BREAKPOINT(); } - -PS4_SYSV_ABI int puts(const char* s) { - std::puts(s); - return SCE_OK; -} - -PS4_SYSV_ABI int rand() { return std::rand(); } - -PS4_SYSV_ABI void _ZdlPv(void* ptr) { std::free(ptr); } -PS4_SYSV_ABI void _ZSt11_Xbad_allocv() { BREAKPOINT(); } -PS4_SYSV_ABI void _ZSt14_Xlength_errorPKc() { BREAKPOINT(); } -PS4_SYSV_ABI void* _Znwm(u64 count) { - if (count == 0) { - BREAKPOINT(); - } - void* ptr = std::malloc(count); - return ptr; -} - -float PS4_SYSV_ABI _Fsin(float arg) { return std::sinf(arg); } - -typedef int(PS4_SYSV_ABI* pfunc_QsortCmp)(const void*, const void*); -thread_local static pfunc_QsortCmp compair_ps4; - -int qsort_compair(const void* arg1, const void* arg2) { return compair_ps4(arg1, arg2); } - -void PS4_SYSV_ABI qsort(void* ptr, size_t count,size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*)) { - compair_ps4 = comp; - std::qsort(ptr, count, size, qsort_compair); -} - -void LibC_Register(SymbolsResolver* sym) { - LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); - LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::cxa::__cxa_guard_acquire); - LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::cxa::__cxa_guard_release); - LIB_FUNCTION("2emaaluWzUw", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::cxa::__cxa_guard_abort); - LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::string::memcmp); - LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::string::memcpy); - LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::memset); - LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, catchReturnFromMain); - LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::stdlib::exit); - LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::stdlib::atexit); - LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, _Assert); - LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::stdio::printf); - LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::stdio::vsnprintf); - LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, puts); - LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, rand); - LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, _Fsin); - LIB_FUNCTION("AEJdIVZTEmo", "libc", 1, "libc", 1, 1, qsort); - LIB_FUNCTION("Ovb2dSJOAuE", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::strcmp); - LIB_FUNCTION("gQX+4GDQjpM", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::stdlib::malloc); - LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::stdlib::free); - LIB_FUNCTION("j4ViWNHEgww", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::strlen); - LIB_FUNCTION("6sJWiWSRuqk", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::strncpy); - LIB_FUNCTION("+P6FRGH4LfA", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::memmove); - LIB_FUNCTION("kiZSXIWd9vg", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::strcpy); - LIB_FUNCTION("Ls4tzzhimqQ", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::strcat); - LIB_FUNCTION("EH-x713A99c", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::math::atan2f); - LIB_FUNCTION("QI-x0SL8jhw", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::math::acosf); - LIB_FUNCTION("ZE6RNL+eLbk", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::math::tanf); - LIB_FUNCTION("GZWjF-YIFFk", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::math::asinf); - LIB_FUNCTION("9LCjpWyQ5Zc", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::math::pow); - LIB_FUNCTION("cCXjU72Z0Ow", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::math::_Sin); - - LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &HLE::Libs::LibC::g_need_sceLibc); - - LIB_FUNCTION("z+P+xCnWLBk", "libc", 1, "libc", 1, 1, _ZdlPv); - LIB_FUNCTION("eT2UsmTewbU", "libc", 1, "libc", 1, 1, _ZSt11_Xbad_allocv); - LIB_FUNCTION("tQIo+GIPklo", "libc", 1, "libc", 1, 1, _ZSt14_Xlength_errorPKc); - LIB_FUNCTION("fJnpuVVBbKk", "libc", 1, "libc", 1, 1, _Znwm); -} - -}; // namespace HLE::Libs::LibC \ No newline at end of file diff --git a/src/core/PS4/HLE/LibC.h b/src/core/PS4/HLE/LibC.h deleted file mode 100644 index c9887c4b..00000000 --- a/src/core/PS4/HLE/LibC.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "../Loader/SymbolsResolver.h" - -namespace HLE::Libs::LibC { - - void LibC_Register(SymbolsResolver* sym); - - //functions - static PS4_SYSV_ABI void init_env(); - static PS4_SYSV_ABI void _Assert(); - static PS4_SYSV_ABI void catchReturnFromMain(int status); - -}; \ No newline at end of file diff --git a/src/core/PS4/HLE/Libs.cpp b/src/core/PS4/HLE/Libs.cpp index 18bc52ec..ae8431f8 100644 --- a/src/core/PS4/HLE/Libs.cpp +++ b/src/core/PS4/HLE/Libs.cpp @@ -1,22 +1,23 @@ #include "Libs.h" -#include "LibC.h" #include "LibKernel.h" #include "LibSceGnmDriver.h" #include #include "core/hle/libraries/libuserservice/user_service.h" #include "core/hle/libraries/libpad/pad.h" #include +#include "core/hle/libraries/libc/libc.h" namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver *sym) { - LibC::LibC_Register(sym); + LibKernel::LibKernel_Register(sym); Graphics::VideoOut::videoOutRegisterLib(sym); LibSceGnmDriver::LibSceGnmDriver_Register(sym); Core::Libraries::LibUserService::userServiceSymbolsRegister(sym); Core::Libraries::LibPad::padSymbolsRegister(sym); Core::Libraries::LibSystemService::systemServiceSymbolsRegister(sym); + Core::Libraries::LibC::libcSymbolsRegister(sym); } } // namespace HLE::Libs \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index 6ffac8af..e8e30d4c 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -1,9 +1,96 @@ #include "libc.h" #include +#include +#include "Util/log.h" +#include "core/PS4/HLE/Libs.h" +#include "core/hle/libraries/libc/libc.h" +#include "core/hle/libraries/libc/libc_cxa.h" +#include "core/hle/libraries/libc/libc_math.h" +#include "core/hle/libraries/libc/libc_stdio.h" +#include "core/hle/libraries/libc/libc_stdlib.h" +#include "core/hle/libraries/libc/libc_string.h" namespace Core::Libraries::LibC { +constexpr bool log_file_libc = true; // disable it to disable logging +static u32 g_need_sceLibc = 1; +static PS4_SYSV_ABI void init_env() { PRINT_DUMMY_FUNCTION_NAME(); } + +static PS4_SYSV_ABI void catchReturnFromMain(int status) { LOG_INFO_IF(log_file_libc, "catchReturnFromMain returned ={}\n", status); } + +static PS4_SYSV_ABI void _Assert() { + PRINT_DUMMY_FUNCTION_NAME(); + BREAKPOINT(); +} + +PS4_SYSV_ABI void _ZdlPv(void* ptr) { std::free(ptr); } +PS4_SYSV_ABI void _ZSt11_Xbad_allocv() { + PRINT_DUMMY_FUNCTION_NAME(); + BREAKPOINT(); +} +PS4_SYSV_ABI void _ZSt14_Xlength_errorPKc() { + PRINT_DUMMY_FUNCTION_NAME(); + BREAKPOINT(); +} +PS4_SYSV_ABI void* _Znwm(u64 count) { + if (count == 0) { + LOG_ERROR_IF(log_file_libc, "_Znwm count ={}\n", count); + BREAKPOINT(); + } + void* ptr = std::malloc(count); + return ptr; +} + +void libcSymbolsRegister(SymbolsResolver* sym) { + // cxa functions + LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire); + LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, __cxa_guard_release); + LIB_FUNCTION("2emaaluWzUw", "libc", 1, "libc", 1, 1, __cxa_guard_abort); + + // stdlib functions + LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1, exit); + LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, atexit); + LIB_FUNCTION("gQX+4GDQjpM", "libc", 1, "libc", 1, 1, malloc); + LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1, free); + LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, rand); + LIB_FUNCTION("AEJdIVZTEmo", "libc", 1, "libc", 1, 1, qsort); + + // math functions + LIB_FUNCTION("EH-x713A99c", "libc", 1, "libc", 1, 1, atan2f); + LIB_FUNCTION("QI-x0SL8jhw", "libc", 1, "libc", 1, 1, acosf); + LIB_FUNCTION("ZE6RNL+eLbk", "libc", 1, "libc", 1, 1, tanf); + LIB_FUNCTION("GZWjF-YIFFk", "libc", 1, "libc", 1, 1, asinf); + LIB_FUNCTION("9LCjpWyQ5Zc", "libc", 1, "libc", 1, 1, pow); + LIB_FUNCTION("cCXjU72Z0Ow", "libc", 1, "libc", 1, 1, _Sin); + LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, _Fsin); + + // string functions + LIB_FUNCTION("Ovb2dSJOAuE", "libc", 1, "libc", 1, 1, strcmp); + LIB_FUNCTION("j4ViWNHEgww", "libc", 1, "libc", 1, 1, strlen); + LIB_FUNCTION("6sJWiWSRuqk", "libc", 1, "libc", 1, 1, strncpy); + LIB_FUNCTION("+P6FRGH4LfA", "libc", 1, "libc", 1, 1, memmove); + LIB_FUNCTION("kiZSXIWd9vg", "libc", 1, "libc", 1, 1, strcpy); + LIB_FUNCTION("Ls4tzzhimqQ", "libc", 1, "libc", 1, 1, strcat); + LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1, memcmp); + LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1, memcpy); + LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1, memset); + + // stdio functions + LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, printf); + LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, vsnprintf); + LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, puts); + + // misc + LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc); + LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); + LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, catchReturnFromMain); + LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, _Assert); + LIB_FUNCTION("z+P+xCnWLBk", "libc", 1, "libc", 1, 1, _ZdlPv); + LIB_FUNCTION("eT2UsmTewbU", "libc", 1, "libc", 1, 1, _ZSt11_Xbad_allocv); + LIB_FUNCTION("tQIo+GIPklo", "libc", 1, "libc", 1, 1, _ZSt14_Xlength_errorPKc); + LIB_FUNCTION("fJnpuVVBbKk", "libc", 1, "libc", 1, 1, _Znwm); +} }; // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc.h b/src/core/hle/libraries/libc/libc.h index 14eb0d26..e3824ead 100644 --- a/src/core/hle/libraries/libc/libc.h +++ b/src/core/hle/libraries/libc/libc.h @@ -1,15 +1,10 @@ #pragma once #include -#include +#include "core/PS4/Loader/SymbolsResolver.h" namespace Core::Libraries::LibC { -// HLE functions - - - - - +void libcSymbolsRegister(SymbolsResolver* sym); } // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc_cxa.cpp b/src/core/hle/libraries/libc/libc_cxa.cpp index d8d4c337..50ac9add 100644 --- a/src/core/hle/libraries/libc/libc_cxa.cpp +++ b/src/core/hle/libraries/libc/libc_cxa.cpp @@ -5,7 +5,7 @@ // adapted from https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html -namespace Core::Libraries::LibC::cxa { +namespace Core::Libraries::LibC { constexpr bool log_file_cxa = true; // disable it to disable logging // This file implements the __cxa_guard_* functions as defined at: @@ -145,4 +145,4 @@ void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object) { setNotInUse(guard_object); } -} // namespace Core::Libraries::LibC::Cxa \ No newline at end of file +} // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc_cxa.h b/src/core/hle/libraries/libc/libc_cxa.h index 6353d73c..170e48f8 100644 --- a/src/core/hle/libraries/libc/libc_cxa.h +++ b/src/core/hle/libraries/libc/libc_cxa.h @@ -4,8 +4,8 @@ #include #include -namespace Core::Libraries::LibC::cxa { +namespace Core::Libraries::LibC { int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object); void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object); void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object); -} // namespace Core::Libraries::LibC::Cxa \ No newline at end of file +} // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc_math.cpp b/src/core/hle/libraries/libc/libc_math.cpp index c65cadcc..5e373d05 100644 --- a/src/core/hle/libraries/libc/libc_math.cpp +++ b/src/core/hle/libraries/libc/libc_math.cpp @@ -2,7 +2,7 @@ #include -namespace Core::Libraries::LibC::math { +namespace Core::Libraries::LibC { float PS4_SYSV_ABI atan2f(float y, float x) { return std::atan2f(y, x); } @@ -15,4 +15,7 @@ float PS4_SYSV_ABI asinf(float num) { return std::asinf(num); } double PS4_SYSV_ABI pow(double base, double exponent) { return std::pow(base, exponent); } double PS4_SYSV_ABI _Sin(double x) { return std::sin(x); } -} // namespace Core::Libraries::LibC::math \ No newline at end of file + +float PS4_SYSV_ABI _Fsin(float arg) { return std::sinf(arg); } + +} // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc_math.h b/src/core/hle/libraries/libc/libc_math.h index 0880e5cb..2927c09e 100644 --- a/src/core/hle/libraries/libc/libc_math.h +++ b/src/core/hle/libraries/libc/libc_math.h @@ -2,11 +2,12 @@ #include -namespace Core::Libraries::LibC::math { +namespace Core::Libraries::LibC { float PS4_SYSV_ABI atan2f(float y, float x); float PS4_SYSV_ABI acosf(float num); float PS4_SYSV_ABI tanf(float num); float PS4_SYSV_ABI asinf(float num); double PS4_SYSV_ABI pow(double base, double exponent); double PS4_SYSV_ABI _Sin(double x); -} // namespace Core::Libraries::LibC::math \ No newline at end of file +float PS4_SYSV_ABI _Fsin(float arg); +} // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc_stdio.cpp b/src/core/hle/libraries/libc/libc_stdio.cpp index 9a57d3cc..f4039574 100644 --- a/src/core/hle/libraries/libc/libc_stdio.cpp +++ b/src/core/hle/libraries/libc/libc_stdio.cpp @@ -1,10 +1,13 @@ #include "libc_stdio.h" -namespace Core::Libraries::LibC::stdio { +namespace Core::Libraries::LibC { int PS4_SYSV_ABI printf(VA_ARGS) { VA_CTX(ctx); return printf_ctx(&ctx); } int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) { return vsnprintf_ctx(s, n, format, arg); } -} // namespace Core::Libraries::LibC::stdio \ No newline at end of file + +int PS4_SYSV_ABI puts(const char* s) { return std::puts(s); } + +} // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc_stdio.h b/src/core/hle/libraries/libc/libc_stdio.h index d2d27954..36d1991d 100644 --- a/src/core/hle/libraries/libc/libc_stdio.h +++ b/src/core/hle/libraries/libc/libc_stdio.h @@ -1,10 +1,11 @@ #pragma once #include + #include "printf.h" -namespace Core::Libraries::LibC::stdio { +namespace Core::Libraries::LibC { int PS4_SYSV_ABI printf(VA_ARGS); int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg); - -} \ No newline at end of file +int PS4_SYSV_ABI puts(const char* s); +} // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/core/hle/libraries/libc/libc_stdlib.cpp b/src/core/hle/libraries/libc/libc_stdlib.cpp index e5a90d0d..83b4506d 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.cpp +++ b/src/core/hle/libraries/libc/libc_stdlib.cpp @@ -5,7 +5,7 @@ #include -namespace Core::Libraries::LibC::stdlib { +namespace Core::Libraries::LibC { constexpr bool log_file_libc = true; // disable it to disable logging void PS4_SYSV_ABI exit(int code) { std::exit(code); } @@ -23,4 +23,15 @@ void* PS4_SYSV_ABI malloc(size_t size) { return std::malloc(size); } void PS4_SYSV_ABI free(void* ptr) { std::free(ptr); } -} // namespace Core::Libraries::LibC::stdlib +typedef int(PS4_SYSV_ABI* pfunc_QsortCmp)(const void*, const void*); +thread_local static pfunc_QsortCmp compair_ps4; + +int qsort_compair(const void* arg1, const void* arg2) { return compair_ps4(arg1, arg2); } + +void PS4_SYSV_ABI qsort(void* ptr, size_t count, size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*)) { + compair_ps4 = comp; + std::qsort(ptr, count, size, qsort_compair); +} +int PS4_SYSV_ABI rand() { return std::rand(); } + +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdlib.h b/src/core/hle/libraries/libc/libc_stdlib.h index b21f69be..d8d465ef 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.h +++ b/src/core/hle/libraries/libc/libc_stdlib.h @@ -4,9 +4,11 @@ #include -namespace Core::Libraries::LibC::stdlib { +namespace Core::Libraries::LibC { void PS4_SYSV_ABI exit(int code); int PS4_SYSV_ABI atexit(void (*func)()); void* PS4_SYSV_ABI malloc(size_t size); void PS4_SYSV_ABI free(void* ptr); -} // namespace Core::Libraries::LibC::stdlib +void PS4_SYSV_ABI qsort(void* ptr, size_t count, size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*)); +int PS4_SYSV_ABI rand(); +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_string.cpp b/src/core/hle/libraries/libc/libc_string.cpp index b9c16695..8cfffd1d 100644 --- a/src/core/hle/libraries/libc/libc_string.cpp +++ b/src/core/hle/libraries/libc/libc_string.cpp @@ -2,7 +2,7 @@ #include -namespace Core::Libraries::LibC::string { +namespace Core::Libraries::LibC { int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n) { return std::memcmp(s1, s2, n); } @@ -22,4 +22,4 @@ char* PS4_SYSV_ABI strcat(char* dest, const char* src) { return std::strcat(dest size_t PS4_SYSV_ABI strlen(const char* str) { return std::strlen(str); } -} // namespace Core::Libraries::LibC::string +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_string.h b/src/core/hle/libraries/libc/libc_string.h index 4ed676d0..0396ddd2 100644 --- a/src/core/hle/libraries/libc/libc_string.h +++ b/src/core/hle/libraries/libc/libc_string.h @@ -1,9 +1,10 @@ #pragma once #include + #include -namespace Core::Libraries::LibC::string { +namespace Core::Libraries::LibC { int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n); void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n); void* PS4_SYSV_ABI memset(void* s, int c, size_t n); @@ -13,4 +14,4 @@ void* PS4_SYSV_ABI memmove(void* dest, const void* src, std::size_t count); char* PS4_SYSV_ABI strcpy(char* destination, const char* source); char* PS4_SYSV_ABI strcat(char* dest, const char* src); size_t PS4_SYSV_ABI strlen(const char* str); -} // namespace Core::Libraries::LibC::string \ No newline at end of file +} // namespace Core::Libraries::LibC \ No newline at end of file