libc separated string functions to libc_string

This commit is contained in:
georgemoralis 2023-10-31 17:32:56 +02:00
parent bb578ae377
commit f5526977d3
8 changed files with 63 additions and 34 deletions

View File

@ -34,6 +34,8 @@ set(LIBC_SOURCES src/core/hle/libraries/Libc/Libc.cpp
src/core/hle/libraries/libc/libc_stdio.h src/core/hle/libraries/libc/libc_stdio.h
src/core/hle/libraries/libc/libc_math.cpp src/core/hle/libraries/libc/libc_math.cpp
src/core/hle/libraries/libc/libc_math.h src/core/hle/libraries/libc/libc_math.h
src/core/hle/libraries/libc/libc_string.cpp
src/core/hle/libraries/libc/libc_string.h
) )
set(USERSERVICE_SOURCES src/core/hle/libraries/libuserservice/user_service.cpp set(USERSERVICE_SOURCES src/core/hle/libraries/libuserservice/user_service.cpp
src/core/hle/libraries/libuserservice/user_service.h src/core/hle/libraries/libuserservice/user_service.h

View File

@ -8,6 +8,7 @@
#include "core/hle/libraries/libc/libc_cxa.h" #include "core/hle/libraries/libc/libc_cxa.h"
#include "core/hle/libraries/libc/libc_math.h" #include "core/hle/libraries/libc/libc_math.h"
#include "core/hle/libraries/libc/libc_stdio.h" #include "core/hle/libraries/libc/libc_stdio.h"
#include "core/hle/libraries/libc/libc_string.h"
#include "ErrorCodes.h" #include "ErrorCodes.h"
#include "Libs.h" #include "Libs.h"
@ -58,12 +59,12 @@ void PS4_SYSV_ABI qsort(void* ptr, size_t count,size_t size, int(PS4_SYSV_ABI* c
void LibC_Register(SymbolsResolver* sym) { void LibC_Register(SymbolsResolver* sym) {
LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env);
LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::Cxa::__cxa_guard_acquire); 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("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("2emaaluWzUw", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::cxa::__cxa_guard_abort);
LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::memcmp); LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::string::memcmp);
LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::memcpy); LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::string::memcpy);
LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::memset); LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::memset);
LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, catchReturnFromMain); LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, catchReturnFromMain);
LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::exit); LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::exit);
LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::atexit); LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::atexit);
@ -74,14 +75,14 @@ void LibC_Register(SymbolsResolver* sym) {
LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, rand); LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, rand);
LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, _Fsin); LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, _Fsin);
LIB_FUNCTION("AEJdIVZTEmo", "libc", 1, "libc", 1, 1, qsort); LIB_FUNCTION("AEJdIVZTEmo", "libc", 1, "libc", 1, 1, qsort);
LIB_FUNCTION("Ovb2dSJOAuE", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strcmp); 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::malloc); LIB_FUNCTION("gQX+4GDQjpM", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::malloc);
LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::free); LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::free);
LIB_FUNCTION("j4ViWNHEgww", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strlen); LIB_FUNCTION("j4ViWNHEgww", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::strlen);
LIB_FUNCTION("6sJWiWSRuqk", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strncpy); LIB_FUNCTION("6sJWiWSRuqk", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::strncpy);
LIB_FUNCTION("+P6FRGH4LfA", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::memmove); LIB_FUNCTION("+P6FRGH4LfA", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::memmove);
LIB_FUNCTION("kiZSXIWd9vg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strcpy); LIB_FUNCTION("kiZSXIWd9vg", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::string::strcpy);
LIB_FUNCTION("Ls4tzzhimqQ", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strcat); 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("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("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("ZE6RNL+eLbk", "libc", 1, "libc", 1, 1, Core::Libraries::LibC::math::tanf);

View File

@ -3,7 +3,7 @@
#include <debug.h> #include <debug.h>
#include <cstdlib> #include <cstdlib>
#include <cstring>
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
@ -17,27 +17,17 @@ int PS4_SYSV_ABI atexit(void (*func)()) {
return rt; return rt;
} }
int PS4_SYSV_ABI 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) { return std::memcpy(dest, src, n); }
void* PS4_SYSV_ABI memset(void* s, int c, size_t n) { return std::memset(s, c, n); }
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); }
int PS4_SYSV_ABI strcmp(const char* str1, const char* str2) { return std::strcmp(str1, str2); }
size_t PS4_SYSV_ABI strlen(const char* str) { return std::strlen(str); }
char* PS4_SYSV_ABI 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) { return std::memmove(dest, src, count); }
char* PS4_SYSV_ABI strcpy(char* dest, const char* src) { return std::strcpy(dest, src); }
char* PS4_SYSV_ABI strcat(char* dest, const char* src) { return std::strcat(dest, src); }
// math // math

View File

@ -9,16 +9,11 @@ namespace Core::Libraries::LibC {
void PS4_SYSV_ABI exit(int code); void PS4_SYSV_ABI exit(int code);
int PS4_SYSV_ABI atexit(void (*func)()); int PS4_SYSV_ABI atexit(void (*func)());
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);
void* PS4_SYSV_ABI malloc(size_t size); void* PS4_SYSV_ABI malloc(size_t size);
void PS4_SYSV_ABI free(void* ptr); void PS4_SYSV_ABI free(void* ptr);
int PS4_SYSV_ABI strcmp(const char* str1, const char* str2);
size_t PS4_SYSV_ABI strlen(const char* str);
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);
} // namespace Core::Libraries::LibC } // namespace Core::Libraries::LibC

View File

@ -5,7 +5,7 @@
// adapted from https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html // 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::cxa {
constexpr bool log_file_cxa = true; // disable it to disable logging constexpr bool log_file_cxa = true; // disable it to disable logging
// This file implements the __cxa_guard_* functions as defined at: // This file implements the __cxa_guard_* functions as defined at:

View File

@ -4,7 +4,7 @@
#include <pthread.h> #include <pthread.h>
#include <types.h> #include <types.h>
namespace Core::Libraries::LibC::Cxa { namespace Core::Libraries::LibC::cxa {
int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object); 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_release(u64* guard_object);
void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object); void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object);

View File

@ -0,0 +1,25 @@
#include "libc_string.h"
#include <cstring>
namespace Core::Libraries::LibC::string {
int PS4_SYSV_ABI 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) { return std::memcpy(dest, src, n); }
void* PS4_SYSV_ABI 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) { return std::strcmp(str1, str2); }
char* PS4_SYSV_ABI 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) { return std::memmove(dest, src, count); }
char* PS4_SYSV_ABI strcpy(char* dest, const char* src) { return std::strcpy(dest, src); }
char* PS4_SYSV_ABI strcat(char* dest, const char* src) { return std::strcat(dest, src); }
size_t PS4_SYSV_ABI strlen(const char* str) { return std::strlen(str); }
} // namespace Core::Libraries::LibC::string

View File

@ -0,0 +1,16 @@
#pragma once
#include <types.h>
#include <cstddef>
namespace Core::Libraries::LibC::string {
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);
} // namespace Core::Libraries::LibC::string