libc separate stdlib functions to libc_stdlib

This commit is contained in:
georgemoralis 2023-10-31 18:12:05 +02:00
parent f5526977d3
commit fd535bae6b
6 changed files with 45 additions and 33 deletions

View File

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

View File

@ -9,6 +9,7 @@
#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"
@ -66,8 +67,8 @@ void LibC_Register(SymbolsResolver* sym) {
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::exit);
LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::atexit);
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);
@ -76,8 +77,8 @@ void LibC_Register(SymbolsResolver* sym) {
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::malloc);
LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::free);
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);

View File

@ -2,33 +2,8 @@
#include <debug.h>
#include <cstdlib>
namespace Core::Libraries::LibC {
void PS4_SYSV_ABI exit(int code) { std::exit(code); }
int PS4_SYSV_ABI atexit(void (*func)()) {
int rt = std::atexit(func);
if (rt != 0) {
BREAKPOINT();
}
return rt;
}
void* PS4_SYSV_ABI malloc(size_t size) { return std::malloc(size); }
void PS4_SYSV_ABI free(void* ptr) { std::free(ptr); }
// math
}; // namespace Core::Libraries::LibC

View File

@ -7,11 +7,7 @@ namespace Core::Libraries::LibC {
// HLE functions
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);

View File

@ -0,0 +1,26 @@
#include "libc_stdlib.h"
#include <Util/log.h>
#include <debug.h>
#include <cstdlib>
namespace Core::Libraries::LibC::stdlib {
constexpr bool log_file_libc = true; // disable it to disable logging
void PS4_SYSV_ABI exit(int code) { std::exit(code); }
int PS4_SYSV_ABI atexit(void (*func)()) {
int rt = std::atexit(func);
if (rt != 0) {
LOG_ERROR_IF(log_file_libc, "atexit returned {}\n", rt);
BREAKPOINT();
}
return rt;
}
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

View File

@ -0,0 +1,12 @@
#pragma once
#include <types.h>
#include <cstddef>
namespace Core::Libraries::LibC::stdlib {
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