Merge pull request #75 from georgemoralis/threads_and_openorbis_stuff_part1

Threads and openorbis stuff part1
This commit is contained in:
georgemoralis 2023-11-18 10:51:36 +02:00 committed by GitHub
commit 103de64bba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 292 additions and 128 deletions

View File

@ -27,7 +27,7 @@ struct CContext {
std::vector<CxaDestructor> cxa;
};
static PS4_SYSV_ABI int __cxa_atexit(void (*func)(void*), void* arg, void* dso_handle) {
static PS4_SYSV_ABI int ps4___cxa_atexit(void (*func)(void*), void* arg, void* dso_handle) {
auto* cc = Common::Singleton<CContext>::Instance();
CxaDestructor c{};
c.destructor_func = func;
@ -37,42 +37,42 @@ static PS4_SYSV_ABI int __cxa_atexit(void (*func)(void*), void* arg, void* dso_h
return 0;
}
void PS4_SYSV_ABI __cxa_finalize(void* d) {
void PS4_SYSV_ABI ps4___cxa_finalize(void* d) {
BREAKPOINT();
}
void PS4_SYSV_ABI __cxa_pure_virtual() {
void PS4_SYSV_ABI ps4___cxa_pure_virtual() {
BREAKPOINT();
}
static PS4_SYSV_ABI void init_env() {
static PS4_SYSV_ABI void ps4_init_env() {
PRINT_DUMMY_FUNCTION_NAME();
}
static PS4_SYSV_ABI void catchReturnFromMain(int status) {
static PS4_SYSV_ABI void ps4_catchReturnFromMain(int status) {
LOG_INFO_IF(log_file_libc, "catchReturnFromMain returned ={}\n", status);
}
static PS4_SYSV_ABI void _Assert() {
static PS4_SYSV_ABI void ps4__Assert() {
PRINT_DUMMY_FUNCTION_NAME();
BREAKPOINT();
}
PS4_SYSV_ABI void _ZdlPv(void* ptr) {
PS4_SYSV_ABI void ps4__ZdlPv(void* ptr) {
std::free(ptr);
}
PS4_SYSV_ABI void _ZSt11_Xbad_allocv() {
PS4_SYSV_ABI void ps4__ZSt11_Xbad_allocv() {
PRINT_DUMMY_FUNCTION_NAME();
BREAKPOINT();
}
PS4_SYSV_ABI void _ZSt14_Xlength_errorPKc() {
PS4_SYSV_ABI void ps4__ZSt14_Xlength_errorPKc() {
PRINT_DUMMY_FUNCTION_NAME();
BREAKPOINT();
}
PS4_SYSV_ABI void* _Znwm(u64 count) {
PS4_SYSV_ABI void* ps4__Znwm(u64 count) {
if (count == 0) {
LOG_ERROR_IF(log_file_libc, "_Znwm count ={}\n", count);
BREAKPOINT();
@ -99,7 +99,7 @@ static constexpr u16 lowercaseTable[256] = {
0x00FC, 0x00FD, 0x00FE, 0x00FF,
};
const PS4_SYSV_ABI u16* _Getptolower() { return &lowercaseTable[0]; }
const PS4_SYSV_ABI u16* ps4__Getptolower() { return &lowercaseTable[0]; }
static constexpr u16 uppercaseTable[256] = {
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011,
@ -119,7 +119,7 @@ static constexpr u16 uppercaseTable[256] = {
0x00FC, 0x00FD, 0x00FE, 0x00FF,
};
const PS4_SYSV_ABI u16* _Getptoupper() { return &uppercaseTable[0]; }
const PS4_SYSV_ABI u16* ps4__Getptoupper() { return &uppercaseTable[0]; }
namespace CharacterType {
enum : u16 {
@ -396,66 +396,66 @@ static constexpr u16 characterTypeTable[256] = {
0,
};
const PS4_SYSV_ABI u16* _Getpctype() { return &characterTypeTable[0]; }
const PS4_SYSV_ABI u16* ps4__Getpctype() { return &characterTypeTable[0]; }
void libcSymbolsRegister(Loader::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);
LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, ps4___cxa_guard_acquire);
LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, ps4___cxa_guard_release);
LIB_FUNCTION("2emaaluWzUw", "libc", 1, "libc", 1, 1, ps4___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);
LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1, ps4_exit);
LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, ps4_atexit);
LIB_FUNCTION("gQX+4GDQjpM", "libc", 1, "libc", 1, 1, ps4_malloc);
LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1, ps4_free);
LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, ps4_rand);
LIB_FUNCTION("AEJdIVZTEmo", "libc", 1, "libc", 1, 1, ps4_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);
LIB_FUNCTION("dnaeGXbjP6E", "libc", 1, "libc", 1, 1, exp2);
LIB_FUNCTION("EH-x713A99c", "libc", 1, "libc", 1, 1, ps4_atan2f);
LIB_FUNCTION("QI-x0SL8jhw", "libc", 1, "libc", 1, 1, ps4_acosf);
LIB_FUNCTION("ZE6RNL+eLbk", "libc", 1, "libc", 1, 1, ps4_tanf);
LIB_FUNCTION("GZWjF-YIFFk", "libc", 1, "libc", 1, 1, ps4_asinf);
LIB_FUNCTION("9LCjpWyQ5Zc", "libc", 1, "libc", 1, 1, ps4_pow);
LIB_FUNCTION("cCXjU72Z0Ow", "libc", 1, "libc", 1, 1, ps4__Sin);
LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, ps4__Fsin);
LIB_FUNCTION("dnaeGXbjP6E", "libc", 1, "libc", 1, 1, ps4_exp2);
// 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);
LIB_FUNCTION("Ovb2dSJOAuE", "libc", 1, "libc", 1, 1, ps4_strcmp);
LIB_FUNCTION("j4ViWNHEgww", "libc", 1, "libc", 1, 1, ps4_strlen);
LIB_FUNCTION("6sJWiWSRuqk", "libc", 1, "libc", 1, 1, ps4_strncpy);
LIB_FUNCTION("+P6FRGH4LfA", "libc", 1, "libc", 1, 1, ps4_memmove);
LIB_FUNCTION("kiZSXIWd9vg", "libc", 1, "libc", 1, 1, ps4_strcpy);
LIB_FUNCTION("Ls4tzzhimqQ", "libc", 1, "libc", 1, 1, ps4_strcat);
LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1, ps4_memcmp);
LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1, ps4_memcpy);
LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1, ps4_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);
LIB_FUNCTION("fffwELXNVFA", "libc", 1, "libc", 1, 1, fprintf);
LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, ps4_printf);
LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, ps4_vsnprintf);
LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, ps4_puts);
LIB_FUNCTION("fffwELXNVFA", "libc", 1, "libc", 1, 1, ps4_fprintf);
// misc
LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc);
LIB_OBJ("2sWzhYqFH4E","libc", 1, "libc", 1, 1,stdout);
LIB_OBJ("H8AprKeZtNg", "libc", 1, "libc", 1, 1, stderr);
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);
LIB_FUNCTION("tsvEmnenz48", "libc", 1, "libc", 1, 1, __cxa_atexit);
LIB_FUNCTION("H2e8t5ScQGc", "libc", 1, "libc", 1, 1, __cxa_finalize);
LIB_FUNCTION("zr094EQ39Ww", "libc", 1, "libc", 1, 1, __cxa_pure_virtual);
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("bzQExy189ZI", "libc", 1, "libc", 1, 1, ps4_init_env);
LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, ps4_catchReturnFromMain);
LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, ps4__Assert);
LIB_FUNCTION("z+P+xCnWLBk", "libc", 1, "libc", 1, 1, ps4__ZdlPv);
LIB_FUNCTION("eT2UsmTewbU", "libc", 1, "libc", 1, 1, ps4__ZSt11_Xbad_allocv);
LIB_FUNCTION("tQIo+GIPklo", "libc", 1, "libc", 1, 1, ps4__ZSt14_Xlength_errorPKc);
LIB_FUNCTION("fJnpuVVBbKk", "libc", 1, "libc", 1, 1, ps4__Znwm);
LIB_FUNCTION("tsvEmnenz48", "libc", 1, "libc", 1, 1, ps4___cxa_atexit);
LIB_FUNCTION("H2e8t5ScQGc", "libc", 1, "libc", 1, 1, ps4___cxa_finalize);
LIB_FUNCTION("zr094EQ39Ww", "libc", 1, "libc", 1, 1, ps4___cxa_pure_virtual);
LIB_FUNCTION("1uJgoVq3bQU", "libc", 1, "libc", 1, 1, ps4__Getptolower);
LIB_FUNCTION("rcQCUr0EaRU", "libc", 1, "libc", 1, 1, ps4__Getptoupper);
LIB_FUNCTION("sUP1hBaouOw", "libc", 1, "libc", 1, 1, ps4__Getpctype);
}
}; // namespace Core::Libraries::LibC

View File

@ -73,7 +73,7 @@ static void setNotInUse(u64* guard_object) { ((u08*)guard_object)[1] = 0; }
// aborts if called again on the same guard object without an intervening
// call to __cxa_guard_release() or __cxa_guard_abort().
//
int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object) {
int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
// Double check that the initializer has not already been run
if (initializerHasRun(guard_object)) return 0;
@ -121,7 +121,7 @@ int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object) {
// Sets the first byte of the guard_object to a non-zero value.
// Releases any locks acquired by __cxa_guard_acquire().
//
void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object) {
void PS4_SYSV_ABI ps4___cxa_guard_release(u64* guard_object) {
// first mark initalizer as having been run, so
// other threads won't try to re-run it.
setInitializerHasRun(guard_object);
@ -136,7 +136,7 @@ void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object) {
//
// Releases any locks acquired by __cxa_guard_acquire().
//
void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object) {
void PS4_SYSV_ABI ps4___cxa_guard_abort(u64* guard_object) {
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_TRACE_IF(log_file_cxa, "__cxa_guard_abort(): pthread_mutex_unlock failed with {}\n", result);

View File

@ -6,8 +6,8 @@
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);
int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object);
void PS4_SYSV_ABI ps4___cxa_guard_release(u64* guard_object);
void PS4_SYSV_ABI ps4___cxa_guard_abort(u64* guard_object);
} // namespace Core::Libraries::LibC

View File

@ -3,35 +3,35 @@
namespace Core::Libraries::LibC {
float PS4_SYSV_ABI atan2f(float y, float x) {
float PS4_SYSV_ABI ps4_atan2f(float y, float x) {
return std::atan2f(y, x);
}
float PS4_SYSV_ABI acosf(float num) {
float PS4_SYSV_ABI ps4_acosf(float num) {
return std::acosf(num);
}
float PS4_SYSV_ABI tanf(float num) {
float PS4_SYSV_ABI ps4_tanf(float num) {
return std::tanf(num);
}
float PS4_SYSV_ABI asinf(float num) {
float PS4_SYSV_ABI ps4_asinf(float num) {
return std::asinf(num);
}
double PS4_SYSV_ABI pow(double base, double exponent) {
double PS4_SYSV_ABI ps4_pow(double base, double exponent) {
return std::pow(base, exponent);
}
double PS4_SYSV_ABI _Sin(double x) {
double PS4_SYSV_ABI ps4__Sin(double x) {
return std::sin(x);
}
float PS4_SYSV_ABI _Fsin(float arg) {
float PS4_SYSV_ABI ps4__Fsin(float arg) {
return std::sinf(arg);
}
double PS4_SYSV_ABI exp2(double arg) {
double PS4_SYSV_ABI ps4_exp2(double arg) {
return std::exp2(arg);
}

View File

@ -4,13 +4,13 @@
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);
float PS4_SYSV_ABI _Fsin(float arg);
double PS4_SYSV_ABI exp2(double arg);
float PS4_SYSV_ABI ps4_atan2f(float y, float x);
float PS4_SYSV_ABI ps4_acosf(float num);
float PS4_SYSV_ABI ps4_tanf(float num);
float PS4_SYSV_ABI ps4_asinf(float num);
double PS4_SYSV_ABI ps4_pow(double base, double exponent);
double PS4_SYSV_ABI ps4__Sin(double x);
float PS4_SYSV_ABI ps4__Fsin(float arg);
double PS4_SYSV_ABI ps4_exp2(double arg);
} // namespace Core::Libraries::LibC

View File

@ -6,12 +6,12 @@ namespace Core::Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging
int PS4_SYSV_ABI printf(VA_ARGS) {
int PS4_SYSV_ABI ps4_printf(VA_ARGS) {
VA_CTX(ctx);
return printf_ctx(&ctx);
}
int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) {
int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS) {
int fd = _fileno(file);
if (fd == 1 || fd == 2) { // output stdout and stderr to console
VA_CTX(ctx);
@ -22,11 +22,11 @@ int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) {
return 0;
}
int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) {
int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg) {
return vsnprintf_ctx(s, n, format, arg);
}
int PS4_SYSV_ABI puts(const char* s) {
int PS4_SYSV_ABI ps4_puts(const char* s) {
return std::puts(s);
}

View File

@ -5,9 +5,9 @@
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);
int PS4_SYSV_ABI puts(const char* s);
int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS);
int PS4_SYSV_ABI ps4_printf(VA_ARGS);
int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg);
int PS4_SYSV_ABI ps4_puts(const char* s);
int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS);
} // namespace Core::Libraries::LibC

View File

@ -7,11 +7,11 @@ namespace Core::Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging
void PS4_SYSV_ABI exit(int code) {
void PS4_SYSV_ABI ps4_exit(int code) {
std::exit(code);
}
int PS4_SYSV_ABI atexit(void (*func)()) {
int PS4_SYSV_ABI ps4_atexit(void (*func)()) {
int rt = std::atexit(func);
if (rt != 0) {
LOG_ERROR_IF(log_file_libc, "atexit returned {}\n", rt);
@ -20,11 +20,11 @@ int PS4_SYSV_ABI atexit(void (*func)()) {
return rt;
}
void* PS4_SYSV_ABI malloc(size_t size) {
void* PS4_SYSV_ABI ps4_malloc(size_t size) {
return std::malloc(size);
}
void PS4_SYSV_ABI free(void* ptr) {
void PS4_SYSV_ABI ps4_free(void* ptr) {
std::free(ptr);
}
@ -35,12 +35,12 @@ 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*)) {
void PS4_SYSV_ABI ps4_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() {
int PS4_SYSV_ABI ps4_rand() {
return std::rand();
}

View File

@ -5,11 +5,11 @@
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);
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();
void PS4_SYSV_ABI ps4_exit(int code);
int PS4_SYSV_ABI ps4_atexit(void (*func)());
void* PS4_SYSV_ABI ps4_malloc(size_t size);
void PS4_SYSV_ABI ps4_free(void* ptr);
void PS4_SYSV_ABI ps4_qsort(void* ptr, size_t count, size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*));
int PS4_SYSV_ABI ps4_rand();
} // namespace Core::Libraries::LibC

View File

@ -3,39 +3,39 @@
namespace Core::Libraries::LibC {
int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n) {
int PS4_SYSV_ABI ps4_memcmp(const void* s1, const void* s2, size_t n) {
return std::memcmp(s1, s2, n);
}
void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n) {
void* PS4_SYSV_ABI ps4_memcpy(void* dest, const void* src, size_t n) {
return std::memcpy(dest, src, n);
}
void* PS4_SYSV_ABI memset(void* s, int c, size_t n) {
void* PS4_SYSV_ABI ps4_memset(void* s, int c, size_t n) {
return std::memset(s, c, n);
}
int PS4_SYSV_ABI strcmp(const char* str1, const char* str2) {
int PS4_SYSV_ABI ps4_strcmp(const char* str1, const char* str2) {
return std::strcmp(str1, str2);
}
char* PS4_SYSV_ABI strncpy(char* dest, const char* src, size_t count) {
char* PS4_SYSV_ABI ps4_strncpy(char* dest, const char* src, size_t count) {
return std::strncpy(dest, src, count);
}
void* PS4_SYSV_ABI memmove(void* dest, const void* src, std::size_t count) {
void* PS4_SYSV_ABI ps4_memmove(void* dest, const void* src, std::size_t count) {
return std::memmove(dest, src, count);
}
char* PS4_SYSV_ABI strcpy(char* dest, const char* src) {
char* PS4_SYSV_ABI ps4_strcpy(char* dest, const char* src) {
return std::strcpy(dest, src);
}
char* PS4_SYSV_ABI strcat(char* dest, const char* src) {
char* PS4_SYSV_ABI ps4_strcat(char* dest, const char* src) {
return std::strcat(dest, src);
}
size_t PS4_SYSV_ABI strlen(const char* str) {
size_t PS4_SYSV_ABI ps4_strlen(const char* str) {
return std::strlen(str);
}

View File

@ -5,14 +5,14 @@
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);
int PS4_SYSV_ABI strcmp(const char* str1, const char* str2);
char* PS4_SYSV_ABI strncpy(char* dest, const char* src, size_t count);
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);
int PS4_SYSV_ABI ps4_memcmp(const void* s1, const void* s2, size_t n);
void* PS4_SYSV_ABI ps4_memcpy(void* dest, const void* src, size_t n);
void* PS4_SYSV_ABI ps4_memset(void* s, int c, size_t n);
int PS4_SYSV_ABI ps4_strcmp(const char* str1, const char* str2);
char* PS4_SYSV_ABI ps4_strncpy(char* dest, const char* src, size_t count);
void* PS4_SYSV_ABI ps4_memmove(void* dest, const void* src, std::size_t count);
char* PS4_SYSV_ABI ps4_strcpy(char* destination, const char* source);
char* PS4_SYSV_ABI ps4_strcat(char* dest, const char* src);
size_t PS4_SYSV_ABI ps4_strlen(const char* str);
} // namespace Core::Libraries::LibC

View File

@ -8,22 +8,28 @@
namespace Core::Libraries::LibKernel {
thread_local PthreadInternal g_pthread_self{};
thread_local ScePthread g_pthread_self{};
PThreadCxt* g_pthread_cxt = nullptr;
constexpr bool log_pthread_file = true; // disable it to disable logging
void init_pthreads() {
g_pthread_cxt = new PThreadCxt{};
// default mutex init
ScePthreadMutexattr default_mutexattr = nullptr;
scePthreadMutexattrInit(&default_mutexattr);
g_pthread_cxt->setDefaultMutexattr(default_mutexattr);
// default cond init
ScePthreadCondattr default_condattr = nullptr;
scePthreadCondattrInit(&default_condattr);
g_pthread_cxt->setDefaultCondattr(default_condattr);
}
void pthreadInitSelfMainThread() {
scePthreadAttrInit(&g_pthread_self.attr);
g_pthread_self.pth = pthread_self();
g_pthread_self.name = "Main_Thread";
g_pthread_self = new PthreadInternal{};
scePthreadAttrInit(&g_pthread_self->attr);
g_pthread_self->pth = pthread_self();
g_pthread_self->name = "Main_Thread";
}
int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr) {
@ -61,7 +67,8 @@ int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachst
default: LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetdetachstate invalid detachstate: {}\n", detachstate); std::exit(0);
}
int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate);
// int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); doesn't seem to work correctly
int result = 0;
(*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED);
@ -119,7 +126,35 @@ int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy)
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
}
ScePthread PS4_SYSV_ABI scePthreadSelf() { return g_pthread_self; }
int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr, const /*SceKernelCpumask*/ u64 mask) {
PRINT_FUNCTION_NAME();
if (pattr == nullptr || *pattr == nullptr) {
return SCE_KERNEL_ERROR_EINVAL;
}
(*pattr)->affinity = mask;
return SCE_OK;
}
int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpumask*/ u64 mask) {
PRINT_FUNCTION_NAME();
if (thread == nullptr) {
return SCE_KERNEL_ERROR_ESRCH;
}
auto result = scePthreadAttrSetaffinity(&thread->attr, mask);
return result;
}
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr, pthreadEntryFunc start_routine, void* arg, const char* name) {
PRINT_DUMMY_FUNCTION_NAME();
return 0;
}
/****
* Mutex calls
*/
@ -147,7 +182,7 @@ int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMut
if (name != nullptr) {
(*mutex)->name = name;
} else {
(*mutex)->name = "noname";
(*mutex)->name = "nonameMutex";
}
int result = pthread_mutex_init(&(*mutex)->pth_mutex, &(*attr)->pth_mutex_attr);
@ -245,6 +280,81 @@ int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) {
}
}
/****
* Cond calls
*/
void* createCond(void* addr) {
if (addr == nullptr || *static_cast<ScePthreadCond*>(addr) != nullptr) {
return addr;
}
auto vaddr = reinterpret_cast<u64>(addr);
std::string name = fmt::format("cond{:#x}", vaddr);
scePthreadCondInit(static_cast<ScePthreadCond*>(addr), nullptr, name.c_str());
return addr;
}
int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondattr* attr, const char* name) {
if (cond == nullptr) {
return SCE_KERNEL_ERROR_EINVAL;
}
if (attr == nullptr) {
attr = g_pthread_cxt->getDefaultCondattr();
}
*cond = new PthreadCondInternal{};
if (name != nullptr) {
(*cond)->name = name;
} else {
(*cond)->name = "nonameCond";
}
int result = pthread_cond_init(&(*cond)->cond, &(*attr)->cond_attr);
if (name != nullptr) {
LOG_INFO_IF(log_pthread_file, "cond init name={},result={}\n", (*cond)->name, result);
}
switch (result) {
case 0: return SCE_OK;
case EAGAIN: return SCE_KERNEL_ERROR_EAGAIN;
case EINVAL: return SCE_KERNEL_ERROR_EINVAL;
case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
default: return SCE_KERNEL_ERROR_EINVAL;
}
}
int PS4_SYSV_ABI scePthreadCondattrInit(ScePthreadCondattr* attr) {
*attr = new PthreadCondAttrInternal{};
int result = pthread_condattr_init(&(*attr)->cond_attr);
switch (result) {
case 0: return SCE_OK;
case ENOMEM: return SCE_KERNEL_ERROR_ENOMEM;
default: return SCE_KERNEL_ERROR_EINVAL;
}
}
int PS4_SYSV_ABI scePthreadCondBroadcast(ScePthreadCond* cond) {
PRINT_FUNCTION_NAME();
cond = static_cast<ScePthreadCond*>(createCond(cond));
if (cond == nullptr) {
return SCE_KERNEL_ERROR_EINVAL;
}
int result = pthread_cond_broadcast(&(*cond)->cond);
LOG_INFO_IF(log_pthread_file, "cond broadcast name={},result={}\n", (*cond)->name, result);
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
}
/****
* Posix calls
*/
int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr) {
LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_init redirect to scePthreadMutexInit\n");
int result = scePthreadMutexInit(mutex, attr, nullptr);
@ -275,26 +385,47 @@ int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex) {
return result;
}
int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond) {
LOG_INFO_IF(log_pthread_file, "posix posix_pthread_cond_broadcast redirect to scePthreadCondBroadcast\n");
int result = scePthreadCondBroadcast(cond);
if (result != 0) {
int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP ? result + -SCE_KERNEL_ERROR_UNKNOWN : POSIX_EOTHER;
return rt;
}
return result;
}
void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("cmo1RIYva9o", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexInit);
LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrInit);
LIB_FUNCTION("iMp8QpE+XO4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSettype);
LIB_FUNCTION("1FGvU0i9saQ", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSetprotocol);
LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy);
LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate);
LIB_FUNCTION("eXbUSpEaTsA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetinheritsched);
LIB_FUNCTION("DzES9hQF4f4", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedparam);
LIB_FUNCTION("nsYoNRywwNg", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrInit);
LIB_FUNCTION("aI+OeCz8xrQ", "libkernel", 1, "libkernel", 1, 1, scePthreadSelf);
LIB_FUNCTION("3qxgM4ezETA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetaffinity);
LIB_FUNCTION("bt3CTBKmGyI", "libkernel", 1, "libkernel", 1, 1, scePthreadSetaffinity);
LIB_FUNCTION("6UgtwV+0zb4", "libkernel", 1, "libkernel", 1, 1, scePthreadCreate);
// mutex calls
LIB_FUNCTION("cmo1RIYva9o", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexInit);
LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrInit);
LIB_FUNCTION("iMp8QpE+XO4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSettype);
LIB_FUNCTION("1FGvU0i9saQ", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSetprotocol);
LIB_FUNCTION("9UK1vLZQft4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexLock);
LIB_FUNCTION("tn3VlD0hG60", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexUnlock);
//cond calls
LIB_FUNCTION("2Tb92quprl0", "libkernel", 1, "libkernel", 1, 1, scePthreadCondInit);
LIB_FUNCTION("m5-2bsNfv7s", "libkernel", 1, "libkernel", 1, 1, scePthreadCondattrInit);
LIB_FUNCTION("JGgj7Uvrl+A", "libkernel", 1, "libkernel", 1, 1, scePthreadCondBroadcast);
// posix calls
LIB_FUNCTION("ttHNfU+qDBU", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_init);
LIB_FUNCTION("7H0iTOciTLo", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_lock);
LIB_FUNCTION("2Z+PpY6CaJg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_unlock);
LIB_FUNCTION("mkx2fVhNMsg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cond_broadcast);
// openorbis weird functions
LIB_FUNCTION("7H0iTOciTLo", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_lock);
LIB_FUNCTION("2Z+PpY6CaJg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_mutex_unlock);
LIB_FUNCTION("mkx2fVhNMsg", "libkernel", 1, "libkernel", 1, 1, posix_pthread_cond_broadcast);
}
} // namespace Core::Libraries::LibKernel

View File

@ -14,14 +14,22 @@ class SymbolsResolver;
namespace Core::Libraries::LibKernel {
struct PthreadInternal;
struct PthreadAttrInternal;
struct PthreadMutexInternal;
struct PthreadMutexattrInternal;
struct PthreadCondInternal;
struct PthreadCondAttrInternal;
using SceKernelSchedParam = ::sched_param;
using ScePthread = PthreadInternal*;
using ScePthreadAttr = PthreadAttrInternal*;
using ScePthreadMutex = PthreadMutexInternal*;
using ScePthreadMutexattr = PthreadMutexattrInternal*;
using ScePthreadCond = PthreadCondInternal*;
using ScePthreadCondattr = PthreadCondAttrInternal*;
using pthreadEntryFunc = PS4_SYSV_ABI void* (*)(void*);
struct PthreadInternal {
u08 reserved[4096];
@ -51,13 +59,27 @@ struct PthreadMutexattrInternal {
int pprotocol;
};
struct PthreadCondInternal {
u08 reserved[256];
std::string name;
pthread_cond_t cond;
};
struct PthreadCondAttrInternal {
u08 reserved[64];
pthread_condattr_t cond_attr;
};
class PThreadCxt {
public:
ScePthreadMutexattr* getDefaultMutexattr() { return &m_default_mutexattr; }
void setDefaultMutexattr(ScePthreadMutexattr attr) { m_default_mutexattr = attr; }
ScePthreadCondattr* getDefaultCondattr() { return &m_default_condattr; }
void setDefaultCondattr(ScePthreadCondattr attr) { m_default_condattr = attr; }
private:
ScePthreadMutexattr m_default_mutexattr = nullptr;
ScePthreadCondattr m_default_condattr = nullptr;
};
void init_pthreads();
@ -68,6 +90,10 @@ int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachst
int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched);
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param);
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy);
ScePthread PS4_SYSV_ABI scePthreadSelf();
int PS4_SYSV_ABI scePthreadAttrSetaffinity(ScePthreadAttr* pattr, const /*SceKernelCpumask*/ u64 mask);
int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpumask*/ u64 mask);
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr, pthreadEntryFunc start_routine, void* arg, const char* name);
/***
* Mutex calls
@ -79,11 +105,18 @@ int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int p
int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex);
int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex);
/****
* Cond calls
*/
int PS4_SYSV_ABI scePthreadCondInit(ScePthreadCond* cond, const ScePthreadCondattr* attr, const char* name);
int PS4_SYSV_ABI scePthreadCondattrInit(ScePthreadCondattr* attr);
int PS4_SYSV_ABI scePthreadCondBroadcast(ScePthreadCond* cond);
/****
* Posix calls
*/
int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr);
int PS4_SYSV_ABI posix_pthread_mutex_lock(ScePthreadMutex* mutex);
int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex);
int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond);
void pthreadSymbolsRegister(Loader::SymbolsResolver* sym);
} // namespace Core::Libraries::LibKernel