diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index 4ca01e434..6e5ac14e8 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -9,6 +9,7 @@ #include "core/hle/libraries/libc/libc_stdlib.h" #include "core/hle/libraries/libc/libc_string.h" #include "core/hle/libraries/libs.h" +#include namespace Core::Libraries::LibC { @@ -398,6 +399,8 @@ static constexpr u16 characterTypeTable[256] = { const PS4_SYSV_ABI u16* _Getpctype() { return &characterTypeTable[0]; } +int PS4_SYSV_ABI ps4_setjmp(jmp_buf env) { return std::setjmp(env); } + void libcSymbolsRegister(Loader::SymbolsResolver* sym) { // cxa functions LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire); @@ -411,6 +414,8 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) { 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); + LIB_FUNCTION("zlfEH8FmyUA", "libc", 1, "libc", 1, 1, _Stoul); + LIB_FUNCTION("VPbJwTCgME0", "libc", 1, "libc", 1, 1, srand); // math functions LIB_FUNCTION("EH-x713A99c", "libc", 1, "libc", 1, 1, atan2f); @@ -434,7 +439,7 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1, memset); LIB_FUNCTION("aesyjrHVWy4", "libc", 1, "libc", 1, 1, strncmp); LIB_FUNCTION("9yDWMxEFdJU", "libc", 1, "libc", 1, 1, strrchr); - + LIB_FUNCTION("g7zzzLDYGw0", "libc", 1, "libc", 1, 1, strdup); // stdio functions LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, printf); LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, vsnprintf); @@ -448,6 +453,8 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("rQFVBXp-Cxg", "libc", 1, "libc", 1, 1, fseek); LIB_FUNCTION("SHlt7EhOtqA", "libc", 1, "libc", 1, 1, fgetpos); LIB_FUNCTION("lbB+UlZqVG0", "libc", 1, "libc", 1, 1, fread); + LIB_FUNCTION("aZK8lNei-Qw", "libc", 1, "libc", 1, 1, fputc); + // misc LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc); LIB_OBJ("2sWzhYqFH4E","libc", 1, "libc", 1, 1,stdout); @@ -465,6 +472,7 @@ void libcSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("1uJgoVq3bQU", "libc", 1, "libc", 1, 1, _Getptolower); LIB_FUNCTION("rcQCUr0EaRU", "libc", 1, "libc", 1, 1, _Getptoupper); LIB_FUNCTION("sUP1hBaouOw", "libc", 1, "libc", 1, 1, _Getpctype); + LIB_FUNCTION("gNQ1V2vfXDE", "libc", 1, "libc", 1, 1, ps4_setjmp); } }; // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdio.cpp b/src/core/hle/libraries/libc/libc_stdio.cpp index 89275020a..58f5019e6 100644 --- a/src/core/hle/libraries/libc/libc_stdio.cpp +++ b/src/core/hle/libraries/libc/libc_stdio.cpp @@ -65,4 +65,5 @@ int PS4_SYSV_ABI setvbuf(FILE* stream, char* buffer, int mode, size_t size) { re int PS4_SYSV_ABI fseek(FILE* stream, long int offset, int origin) { return std::fseek(stream, offset, origin); } int PS4_SYSV_ABI fgetpos(FILE* stream, fpos_t* pos) { return std::fgetpos(stream, pos); } size_t PS4_SYSV_ABI fread(void* ptr, size_t size, size_t count, FILE* stream) { return std::fread(ptr, size, count, stream); } +int PS4_SYSV_ABI fputc(int character, FILE* stream) { return std::fputc(character, stream); } } // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdio.h b/src/core/hle/libraries/libc/libc_stdio.h index 55522687e..476ad100a 100644 --- a/src/core/hle/libraries/libc/libc_stdio.h +++ b/src/core/hle/libraries/libc/libc_stdio.h @@ -17,4 +17,5 @@ int PS4_SYSV_ABI setvbuf(FILE* stream, char* buffer, int mode, size_t size); int PS4_SYSV_ABI fseek(FILE* stream, long int offset, int origin); int PS4_SYSV_ABI fgetpos(FILE* stream, fpos_t* pos); size_t PS4_SYSV_ABI fread(void* ptr, size_t size, size_t count, FILE* stream); +int PS4_SYSV_ABI fputc(int character, FILE* stream); } // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdlib.cpp b/src/core/hle/libraries/libc/libc_stdlib.cpp index d5c32d566..21d9b36fc 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.cpp +++ b/src/core/hle/libraries/libc/libc_stdlib.cpp @@ -1,15 +1,15 @@ -#include -#include "common/log.h" -#include "common/debug.h" #include "core/hle/libraries/libc/libc_stdlib.h" +#include + +#include "common/debug.h" +#include "common/log.h" + 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); -} +void PS4_SYSV_ABI exit(int code) { std::exit(code); } int PS4_SYSV_ABI atexit(void (*func)()) { int rt = std::atexit(func); @@ -20,28 +20,24 @@ int PS4_SYSV_ABI atexit(void (*func)()) { return rt; } -void* PS4_SYSV_ABI malloc(size_t size) { - return std::malloc(size); -} +void* PS4_SYSV_ABI malloc(size_t size) { return std::malloc(size); } -void PS4_SYSV_ABI free(void* ptr) { - std::free(ptr); -} +void PS4_SYSV_ABI free(void* ptr) { std::free(ptr); } 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); -} +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(); -} +int PS4_SYSV_ABI rand() { return std::rand(); } -} // namespace Core::Libraries::LibC +unsigned long int PS4_SYSV_ABI _Stoul(const char* str, char** endptr, int base) { return std::strtoul(str, endptr, base); } + +void PS4_SYSV_ABI srand(unsigned int seed) { return std::srand(seed); } + +} // 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 5704d6481..a6928910f 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.h +++ b/src/core/hle/libraries/libc/libc_stdlib.h @@ -11,5 +11,6 @@ void* PS4_SYSV_ABI malloc(size_t size); void PS4_SYSV_ABI free(void* ptr); 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(); - +unsigned long int PS4_SYSV_ABI _Stoul(const char* str, char** endptr, int base); +void PS4_SYSV_ABI srand(unsigned int seed); } // 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 2700cc751..6ca6348a9 100644 --- a/src/core/hle/libraries/libc/libc_string.cpp +++ b/src/core/hle/libraries/libc/libc_string.cpp @@ -1,5 +1,6 @@ #include "core/hle/libraries/libc/libc_string.h" +#include #include namespace Core::Libraries::LibC { @@ -26,4 +27,10 @@ int PS4_SYSV_ABI strncmp(const char* str1, const char* str2, size_t num) { retur char* PS4_SYSV_ABI strrchr(char* str, int character) { return (char*)std::strrchr(str, character); } +char* PS4_SYSV_ABI strdup(const char* str1) { + char* dup = (char*)std::malloc(std::strlen(str1) + 1); + if (dup != NULL) strcpy(dup, str1); + return dup; +} + } // 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 c6e86c722..a57183f00 100644 --- a/src/core/hle/libraries/libc/libc_string.h +++ b/src/core/hle/libraries/libc/libc_string.h @@ -17,5 +17,6 @@ char* PS4_SYSV_ABI strcat(char* dest, const char* src); size_t PS4_SYSV_ABI strlen(const char* str); int PS4_SYSV_ABI strncmp(const char* str1, const char* str2, size_t num); char* PS4_SYSV_ABI strrchr(char* str, int character); +char* PS4_SYSV_ABI strdup(const char* str1); } // namespace Core::Libraries::LibC