Merge pull request #525 from shadps4-emu/libc_removal

HLE libc removal
This commit is contained in:
georgemoralis 2024-08-22 11:59:56 +03:00 committed by GitHub
commit 746559658c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 7 additions and 1924 deletions

View File

@ -223,21 +223,7 @@ set(VIDEOOUT_LIB src/core/libraries/videoout/buffer.h
src/core/libraries/videoout/video_out.h
)
set(LIBC_SOURCES src/core/libraries/libc/libc.cpp
src/core/libraries/libc/libc.h
src/core/libraries/libc/printf.h
src/core/libraries/libc/va_ctx.h
src/core/libraries/libc/libc_cxa.cpp
src/core/libraries/libc/libc_cxa.h
src/core/libraries/libc/libc_stdio.cpp
src/core/libraries/libc/libc_stdio.h
src/core/libraries/libc/libc_math.cpp
src/core/libraries/libc/libc_math.h
src/core/libraries/libc/libc_string.cpp
src/core/libraries/libc/libc_string.h
src/core/libraries/libc/libc_stdlib.cpp
src/core/libraries/libc/libc_stdlib.h
src/core/libraries/libc_internal/libc_internal.cpp
set(LIBC_SOURCES src/core/libraries/libc_internal/libc_internal.cpp
src/core/libraries/libc_internal/libc_internal.h
)

View File

@ -18,7 +18,6 @@ static std::string logFilter;
static std::string logType = "async";
static std::string userName = "shadPS4";
static bool isDebugDump = false;
static bool isLibc = true;
static bool isShowSplash = false;
static bool isNullGpu = false;
static bool shouldDumpShaders = false;
@ -49,10 +48,6 @@ std::vector<std::string> m_recent_files;
// Settings
u32 m_language = 1; // english
bool isLleLibc() {
return isLibc;
}
bool isNeoMode() {
return isNeo;
}
@ -354,12 +349,6 @@ void load(const std::filesystem::path& path) {
isDebugDump = toml::find_or<bool>(debug, "DebugDump", false);
}
if (data.contains("LLE")) {
const toml::value& lle = data.at("LLE");
isLibc = toml::find_or<bool>(lle, "libc", true);
}
if (data.contains("GUI")) {
const toml::value& gui = data.at("GUI");
@ -425,7 +414,6 @@ void save(const std::filesystem::path& path) {
data["Vulkan"]["rdocEnable"] = rdocEnable;
data["Vulkan"]["rdocMarkersEnable"] = rdocMarkersEnable;
data["Debug"]["DebugDump"] = isDebugDump;
data["LLE"]["libc"] = isLibc;
data["GUI"]["theme"] = mw_themes;
data["GUI"]["iconSize"] = m_icon_size;
data["GUI"]["sliderPos"] = m_slider_pos;

View File

@ -22,7 +22,6 @@ u32 getScreenHeight();
s32 getGpuId();
bool debugDump();
bool isLleLibc();
bool showSplash();
bool nullGpu();
bool dumpShaders();

View File

@ -1,496 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdlib>
#include "common/debug.h"
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/libraries/libc/libc.h"
#include "core/libraries/libc/libc_cxa.h"
#include "core/libraries/libc/libc_math.h"
#include "core/libraries/libc/libc_stdio.h"
#include "core/libraries/libc/libc_stdlib.h"
#include "core/libraries/libc/libc_string.h"
#include "core/libraries/libs.h"
namespace Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging
static u32 g_need_sceLibc = 1;
using cxa_destructor_func_t = void (*)(void*);
struct CxaDestructor {
cxa_destructor_func_t destructor_func;
void* destructor_object;
void* module_id;
};
struct CContext {
std::vector<CxaDestructor> cxa;
};
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;
c.destructor_object = arg;
c.module_id = dso_handle;
cc->cxa.push_back(c);
return 0;
}
void PS4_SYSV_ABI ps4___cxa_finalize(void* d) {
BREAKPOINT();
}
void PS4_SYSV_ABI ps4___cxa_pure_virtual() {
BREAKPOINT();
}
static PS4_SYSV_ABI void ps4_init_env() {
LOG_INFO(Lib_LibC, "called");
}
static PS4_SYSV_ABI void ps4_catchReturnFromMain(int status) {
LOG_INFO(Lib_LibC, "returned = {}", status);
}
static PS4_SYSV_ABI void ps4__Assert() {
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
PS4_SYSV_ABI void ps4__ZdlPv(void* ptr) {
std::free(ptr);
}
PS4_SYSV_ABI void ps4__ZSt11_Xbad_allocv() {
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
PS4_SYSV_ABI void ps4__ZSt14_Xlength_errorPKc() {
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
PS4_SYSV_ABI void* ps4__Znwm(u64 count) {
if (count == 0) {
LOG_INFO(Lib_LibC, "_Znwm count ={}", count);
BREAKPOINT();
}
void* ptr = std::malloc(count);
return ptr;
}
static constexpr u16 lowercaseTable[256] = {
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B,
0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B,
0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073,
0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B,
0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083,
0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB,
0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3,
0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB,
0x00FC, 0x00FD, 0x00FE, 0x00FF,
};
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, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B,
0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053,
0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
0x0060, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B,
0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083,
0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB,
0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3,
0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB,
0x00FC, 0x00FD, 0x00FE, 0x00FF,
};
const PS4_SYSV_ABI u16* ps4__Getptoupper() {
return &uppercaseTable[0];
}
namespace CharacterType {
enum : u16 {
HexDigit = 0x1, // '0'-'9', 'A'-'F', 'a'-'f'
Uppercase = 0x2, // 'A'-'Z'
Space = 0x4,
Punctuation = 0x08,
Lowercase = 0x10, // 'a'-'z'
DecimalDigit = 0x20, // '0'-'9'
Control = 0x40, // CR, FF, HT, NL, VT
Control2 = 0x80, // BEL, BS, etc
ExtraSpace = 0x100,
ExtraAlphabetic = 0x200,
ExtraBlank = 0x400
};
}
static constexpr u16 characterTypeTable[256] = {
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control | CharacterType::Control2 | CharacterType::ExtraBlank,
CharacterType::Control | CharacterType::Control2,
CharacterType::Control | CharacterType::Control2,
CharacterType::Control | CharacterType::Control2,
CharacterType::Control | CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Space, //
CharacterType::Punctuation, // !
CharacterType::Punctuation, // "
CharacterType::Punctuation, // #
CharacterType::Punctuation, // $
CharacterType::Punctuation, // %
CharacterType::Punctuation, // &
CharacterType::Punctuation, // '
CharacterType::Punctuation, // (
CharacterType::Punctuation, // )
CharacterType::Punctuation, // *
CharacterType::Punctuation, // +
CharacterType::Punctuation, // ,
CharacterType::Punctuation, // -
CharacterType::Punctuation, // .
CharacterType::Punctuation, // /
CharacterType::HexDigit | CharacterType::DecimalDigit, // 0
CharacterType::HexDigit | CharacterType::DecimalDigit, // 1
CharacterType::HexDigit | CharacterType::DecimalDigit, // 2
CharacterType::HexDigit | CharacterType::DecimalDigit, // 3
CharacterType::HexDigit | CharacterType::DecimalDigit, // 4
CharacterType::HexDigit | CharacterType::DecimalDigit, // 5
CharacterType::HexDigit | CharacterType::DecimalDigit, // 6
CharacterType::HexDigit | CharacterType::DecimalDigit, // 7
CharacterType::HexDigit | CharacterType::DecimalDigit, // 8
CharacterType::HexDigit | CharacterType::DecimalDigit, // 9
CharacterType::Punctuation, // :
CharacterType::Punctuation, // ;
CharacterType::Punctuation, // <
CharacterType::Punctuation, // =
CharacterType::Punctuation, // >
CharacterType::Punctuation, // ?
CharacterType::Punctuation, // @
CharacterType::HexDigit | CharacterType::Uppercase, // A
CharacterType::HexDigit | CharacterType::Uppercase, // B
CharacterType::HexDigit | CharacterType::Uppercase, // C
CharacterType::HexDigit | CharacterType::Uppercase, // D
CharacterType::HexDigit | CharacterType::Uppercase, // E
CharacterType::HexDigit | CharacterType::Uppercase, // F
CharacterType::Uppercase, // G
CharacterType::Uppercase, // H
CharacterType::Uppercase, // I
CharacterType::Uppercase, // J
CharacterType::Uppercase, // K
CharacterType::Uppercase, // L
CharacterType::Uppercase, // M
CharacterType::Uppercase, // N
CharacterType::Uppercase, // O
CharacterType::Uppercase, // P
CharacterType::Uppercase, // Q
CharacterType::Uppercase, // R
CharacterType::Uppercase, // S
CharacterType::Uppercase, // T
CharacterType::Uppercase, // U
CharacterType::Uppercase, // V
CharacterType::Uppercase, // W
CharacterType::Uppercase, // X
CharacterType::Uppercase, // Y
CharacterType::Uppercase, // Z
CharacterType::Punctuation, // [
CharacterType::Punctuation, //
CharacterType::Punctuation, // ]
CharacterType::Punctuation, // ^
CharacterType::Punctuation, // _
CharacterType::Punctuation, // `
CharacterType::HexDigit | CharacterType::Lowercase, // a
CharacterType::HexDigit | CharacterType::Lowercase, // b
CharacterType::HexDigit | CharacterType::Lowercase, // c
CharacterType::HexDigit | CharacterType::Lowercase, // d
CharacterType::HexDigit | CharacterType::Lowercase, // e
CharacterType::HexDigit | CharacterType::Lowercase, // f
CharacterType::Lowercase, // g
CharacterType::Lowercase, // h
CharacterType::Lowercase, // i
CharacterType::Lowercase, // j
CharacterType::Lowercase, // k
CharacterType::Lowercase, // l
CharacterType::Lowercase, // m
CharacterType::Lowercase, // n
CharacterType::Lowercase, // o
CharacterType::Lowercase, // p
CharacterType::Lowercase, // q
CharacterType::Lowercase, // r
CharacterType::Lowercase, // s
CharacterType::Lowercase, // t
CharacterType::Lowercase, // u
CharacterType::Lowercase, // v
CharacterType::Lowercase, // w
CharacterType::Lowercase, // x
CharacterType::Lowercase, // y
CharacterType::Lowercase, // z
CharacterType::Punctuation, // {
CharacterType::Punctuation, // |
CharacterType::Punctuation, // }
CharacterType::Punctuation, // ~
CharacterType::Control2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
};
const PS4_SYSV_ABI u16* ps4__Getpctype() {
return &characterTypeTable[0];
}
void libcSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
// cxa functions
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, 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, 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);
LIB_FUNCTION("1D0H2KNjshE", "libc", 1, "libc", 1, 1, ps4_powf);
LIB_FUNCTION("DDHG1a6+3q0", "libc", 1, "libc", 1, 1, ps4_roundf);
// string functions
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);
LIB_FUNCTION("9yDWMxEFdJU", "libc", 1, "libc", 1, 1, ps4_strrchr);
LIB_FUNCTION("aesyjrHVWy4", "libc", 1, "libc", 1, 1, ps4_strncmp);
LIB_FUNCTION("g7zzzLDYGw0", "libc", 1, "libc", 1, 1, ps4_strdup);
// stdio functions
LIB_FUNCTION("xeYO4u7uyJ0", "libc", 1, "libc", 1, 1, ps4_fopen);
// 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);
LIB_FUNCTION("QMFyLoqNxIg", "libc", 1, "libc", 1, 1, ps4_setvbuf);
LIB_FUNCTION("uodLYyUip20", "libc", 1, "libc", 1, 1, ps4_fclose);
LIB_FUNCTION("rQFVBXp-Cxg", "libc", 1, "libc", 1, 1, ps4_fseek);
LIB_FUNCTION("SHlt7EhOtqA", "libc", 1, "libc", 1, 1, ps4_fgetpos);
LIB_FUNCTION("lbB+UlZqVG0", "libc", 1, "libc", 1, 1, ps4_fread);
LIB_FUNCTION("Qazy8LmXTvw", "libc", 1, "libc", 1, 1, ps4_ftell);
// 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, 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 Libraries::LibC

View File

@ -1,14 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
namespace Core::Loader {
class SymbolsResolver;
}
namespace Libraries::LibC {
void libcSymbolsRegister(Core::Loader::SymbolsResolver* sym);
} // namespace Libraries::LibC

View File

@ -1,161 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include "core/libraries/libc/libc_cxa.h"
// adapted from
// https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html
namespace Libraries::LibC {
// This file implements the __cxa_guard_* functions as defined at:
// http://www.codesourcery.com/public/cxx-abi/abi.html
//
// The goal of these functions is to support thread-safe, one-time
// initialization of function scope variables. The compiler will generate
// code like the following:
//
// if ( obj_guard.first_byte == 0 ) {
// if ( __cxa_guard_acquire(&obj_guard) ) {
// try {
// ... initialize the object ...;
// }
// catch (...) {
// __cxa_guard_abort(&obj_guard);
// throw;
// }
// ... queue object destructor with __cxa_atexit() ...;
// __cxa_guard_release(&obj_guard);
// }
// }
//
// Notes:
// ojb_guard is a 64-bytes in size and statically initialized to zero.
//
// Section 6.7 of the C++ Spec says "If control re-enters the declaration
// recursively while the object is being initialized, the behavior is
// undefined". This implementation calls abort().
//
// Note don't use function local statics to avoid use of cxa functions...
static pthread_mutex_t __guard_mutex;
static pthread_once_t __once_control = PTHREAD_ONCE_INIT;
static void makeRecusiveMutex() {
pthread_mutexattr_t recursiveMutexAttr;
pthread_mutexattr_init(&recursiveMutexAttr);
pthread_mutexattr_settype(&recursiveMutexAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&__guard_mutex, &recursiveMutexAttr);
}
__attribute__((noinline)) static pthread_mutex_t* guard_mutex() {
pthread_once(&__once_control, &makeRecusiveMutex);
return &__guard_mutex;
}
// helper functions for getting/setting flags in guard_object
static bool initializerHasRun(u64* guard_object) {
return (*((u8*)guard_object) != 0);
}
static void setInitializerHasRun(u64* guard_object) {
*((u8*)guard_object) = 1;
}
static bool inUse(u64* guard_object) {
return (((u8*)guard_object)[1] != 0);
}
static void setInUse(u64* guard_object) {
((u8*)guard_object)[1] = 1;
}
static void setNotInUse(u64* guard_object) {
((u8*)guard_object)[1] = 0;
}
//
// Returns 1 if the caller needs to run the initializer and then either
// call __cxa_guard_release() or __cxa_guard_abort(). If zero is returned,
// then the initializer has already been run. This function blocks
// if another thread is currently running the initializer. This function
// 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 ps4___cxa_guard_acquire(u64* guard_object) {
// Double check that the initializer has not already been run
if (initializerHasRun(guard_object))
return 0;
// We now need to acquire a lock that allows only one thread
// to run the initializer. If a different thread calls
// __cxa_guard_acquire() with the same guard object, we want
// that thread to block until this thread is done running the
// initializer and calls __cxa_guard_release(). But if the same
// thread calls __cxa_guard_acquire() with the same guard object,
// we want to abort.
// To implement this we have one global pthread recursive mutex
// shared by all guard objects, but only one at a time.
int result = ::pthread_mutex_lock(guard_mutex());
if (result != 0) {
LOG_ERROR(Lib_LibC, "pthread_mutex_lock failed with {}", result);
}
// At this point all other threads will block in __cxa_guard_acquire()
// Check if another thread has completed initializer run
if (initializerHasRun(guard_object)) {
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_ERROR(Lib_LibC, "pthread_mutex_lock failed with {}", result);
}
return 0;
}
// The pthread mutex is recursive to allow other lazy initialized
// function locals to be evaluated during evaluation of this one.
// But if the same thread can call __cxa_guard_acquire() on the
// *same* guard object again, we call abort();
if (inUse(guard_object)) {
LOG_ERROR(Lib_LibC,
"initializer for function local static variable called enclosing function");
}
// mark this guard object as being in use
setInUse(guard_object);
// return non-zero to tell caller to run initializer
return 1;
}
//
// 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 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);
// release global mutex
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_ERROR(Lib_LibC, "pthread_mutex_unlock failed with {}", result);
}
}
//
// Releases any locks acquired by __cxa_guard_acquire().
//
void PS4_SYSV_ABI ps4___cxa_guard_abort(u64* guard_object) {
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_ERROR(Lib_LibC, "pthread_mutex_unlock failed with {}", result);
}
// now reset state, so possible to try to initialize again
setNotInUse(guard_object);
}
} // namespace Libraries::LibC

View File

@ -1,15 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <pthread.h>
#include "common/types.h"
namespace Libraries::LibC {
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 Libraries::LibC

View File

@ -1,55 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cmath>
#include "common/assert.h"
#include "core/libraries/libc/libc_math.h"
namespace Libraries::LibC {
float PS4_SYSV_ABI ps4_atan2f(float y, float x) {
return atan2f(y, x);
}
float PS4_SYSV_ABI ps4_acosf(float num) {
return acosf(num);
}
float PS4_SYSV_ABI ps4_tanf(float num) {
return tanf(num);
}
float PS4_SYSV_ABI ps4_asinf(float num) {
return asinf(num);
}
double PS4_SYSV_ABI ps4_pow(double base, double exponent) {
return pow(base, exponent);
}
float PS4_SYSV_ABI ps4_powf(float x, float y) {
return powf(x, y);
}
float PS4_SYSV_ABI ps4_roundf(float arg) {
return roundf(arg);
}
double PS4_SYSV_ABI ps4__Sin(double x) {
return sin(x);
}
float PS4_SYSV_ABI ps4__Fsin(float arg, unsigned int m, int n) {
ASSERT(n == 0);
if (m != 0) {
return cosf(arg);
} else {
return sinf(arg);
}
}
double PS4_SYSV_ABI ps4_exp2(double arg) {
return exp2(arg);
}
} // namespace Libraries::LibC

View File

@ -1,21 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/types.h"
namespace Libraries::LibC {
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, unsigned int, int);
double PS4_SYSV_ABI ps4_exp2(double arg);
float PS4_SYSV_ABI ps4_powf(float x, float y);
float PS4_SYSV_ABI ps4_roundf(float arg);
} // namespace Libraries::LibC

View File

@ -1,78 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/file_sys/fs.h"
#include "core/libraries/libc/libc_stdio.h"
namespace Libraries::LibC {
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
const auto host_path = mnt->GetHostPath(filename).string();
FILE* f = std::fopen(host_path.c_str(), mode);
if (f != nullptr) {
LOG_INFO(Lib_LibC, "fopen = {}", host_path);
} else {
LOG_INFO(Lib_LibC, "fopen can't open = {}", host_path);
}
return f;
}
int PS4_SYSV_ABI ps4_fclose(FILE* stream) {
LOG_INFO(Lib_LibC, "callled");
int ret = 0;
if (stream != nullptr) {
ret = fclose(stream);
}
return ret;
}
int PS4_SYSV_ABI ps4_setvbuf(FILE* stream, char* buf, int mode, size_t size) {
return setvbuf(stream, buf, mode, size);
}
int PS4_SYSV_ABI ps4_fseek(FILE* stream, long offset, int whence) {
return fseek(stream, offset, whence);
}
int PS4_SYSV_ABI ps4_fgetpos(FILE* stream, fpos_t* pos) {
return fgetpos(stream, pos);
}
std::size_t PS4_SYSV_ABI ps4_fread(void* ptr, size_t size, size_t nmemb, FILE* stream) {
return fread(ptr, size, nmemb, stream);
}
int PS4_SYSV_ABI ps4_printf(VA_ARGS) {
VA_CTX(ctx);
return printf_ctx(&ctx);
}
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);
return printf_ctx(&ctx);
} else {
VA_CTX(ctx);
char buf[256];
fprintf_ctx(&ctx, buf);
return fprintf(file, "%s", buf);
}
}
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 ps4_puts(const char* s) {
return std::puts(s);
}
long PS4_SYSV_ABI ps4_ftell(FILE* stream) {
return ftell(stream);
}
} // namespace Libraries::LibC

View File

@ -1,23 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/types.h"
#include "core/libraries/libc/printf.h"
namespace Libraries::LibC {
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode);
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);
int PS4_SYSV_ABI ps4_setvbuf(FILE* stream, char* buf, int mode, size_t size);
int PS4_SYSV_ABI ps4_fclose(FILE* stream);
int PS4_SYSV_ABI ps4_fseek(FILE* stream, long offset, int whence);
int PS4_SYSV_ABI ps4_fgetpos(FILE* stream, fpos_t* pos);
std::size_t PS4_SYSV_ABI ps4_fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
long PS4_SYSV_ABI ps4_ftell(FILE* stream);
} // namespace Libraries::LibC

View File

@ -1,45 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdlib>
#include "common/assert.h"
#include "core/libraries/libc/libc_stdlib.h"
namespace Libraries::LibC {
void PS4_SYSV_ABI ps4_exit(int code) {
std::exit(code);
}
int PS4_SYSV_ABI ps4_atexit(void (*func)()) {
int rt = std::atexit(func);
ASSERT_MSG(rt == 0, "atexit returned {}", rt);
return rt;
}
void* PS4_SYSV_ABI ps4_malloc(size_t size) {
return std::malloc(size);
}
void PS4_SYSV_ABI ps4_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);
}
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 ps4_rand() {
return std::rand();
}
} // namespace Libraries::LibC

View File

@ -1,19 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <cstddef>
#include "common/types.h"
namespace Libraries::LibC {
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 Libraries::LibC

View File

@ -1,61 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdlib>
#include <cstring>
#include "core/libraries/libc/libc_string.h"
namespace Libraries::LibC {
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 ps4_memcpy(void* dest, const void* src, size_t n) {
return std::memcpy(dest, src, n);
}
void* PS4_SYSV_ABI ps4_memset(void* s, int c, size_t n) {
return std::memset(s, c, n);
}
int PS4_SYSV_ABI ps4_strcmp(const char* str1, const char* str2) {
return std::strcmp(str1, str2);
}
char* PS4_SYSV_ABI ps4_strncpy(char* dest, const char* src, size_t count) {
return std::strncpy(dest, src, 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 ps4_strcpy(char* dest, const char* src) {
return std::strcpy(dest, src);
}
char* PS4_SYSV_ABI ps4_strcat(char* dest, const char* src) {
return std::strcat(dest, src);
}
size_t PS4_SYSV_ABI ps4_strlen(const char* str) {
return std::strlen(str);
}
char* PS4_SYSV_ABI ps4_strrchr(const char* s, int c) {
return (char*)strrchr(s, c);
}
int PS4_SYSV_ABI ps4_strncmp(const char* s1, const char* s2, size_t n) {
return strncmp(s1, s2, n);
}
char* PS4_SYSV_ABI ps4_strdup(const char* str1) {
char* dup = (char*)std::malloc(std::strlen(str1) + 1);
if (dup != NULL)
strcpy(dup, str1);
return dup;
}
} // namespace Libraries::LibC

View File

@ -1,24 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <cstddef>
#include "common/types.h"
namespace Libraries::LibC {
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);
char* PS4_SYSV_ABI ps4_strrchr(const char* s, int c);
int PS4_SYSV_ABI ps4_strncmp(const char* s1, const char* s2, size_t n);
char* PS4_SYSV_ABI ps4_strdup(const char* str1);
} // namespace Libraries::LibC

View File

@ -1,753 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2014-2018 Marco Paland (info@paland.com)
// SPDX-License-Identifier: MIT
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland (info@paland.com)
// 2014-2018, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
// embedded systems with a very limited resources.
// Use this instead of bloated standard/newlib printf.
// These routines are thread safe and reentrant!
//
///////////////////////////////////////////////////////////////////////////////
// Vita3K emulator project
// Copyright (C) 2023 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// copied from Vita3k project at 6/10/2023 (latest update 30/06/2023)
// modifications for adapting va_args parameters
#pragma once
#include <stdio.h>
#include <cstdarg>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>
#include "va_ctx.h"
namespace Libraries::LibC {
// ntoa conversion buffer size, this must be big enough to hold
// one converted numeric number including padded zeros (dynamically created on stack)
// 32 byte is a good default
#define PRINTF_NTOA_BUFFER_SIZE 32U
// ftoa conversion buffer size, this must be big enough to hold
// one converted float number including padded zeros (dynamically created on stack)
// 32 byte is a good default
#define PRINTF_FTOA_BUFFER_SIZE 32U
// define this to support floating point (%f)
#define PRINTF_SUPPORT_FLOAT
// define this to support long long types (%llu or %p)
#define PRINTF_SUPPORT_LONG_LONG
// define this to support the ptrdiff_t type (%t)
// ptrdiff_t is normally defined in <stddef.h> as long or long long type
#define PRINTF_SUPPORT_PTRDIFF_T
///////////////////////////////////////////////////////////////////////////////
// internal flag definitions
#define FLAGS_ZEROPAD (1U << 0U)
#define FLAGS_LEFT (1U << 1U)
#define FLAGS_PLUS (1U << 2U)
#define FLAGS_SPACE (1U << 3U)
#define FLAGS_HASH (1U << 4U)
#define FLAGS_UPPERCASE (1U << 5U)
#define FLAGS_CHAR (1U << 6U)
#define FLAGS_SHORT (1U << 7U)
#define FLAGS_LONG (1U << 8U)
#define FLAGS_LONG_LONG (1U << 9U)
#define FLAGS_PRECISION (1U << 10U)
#define FLAGS_WIDTH (1U << 11U)
// output function type
typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen);
// wrapper (used as buffer) for output function type
typedef struct {
void (*fct)(char character, void* arg);
void* arg;
} out_fct_wrap_type;
// internal buffer output
static inline void _out_buffer(char character, void* buffer, size_t idx, size_t maxlen) {
if (idx < maxlen) {
((char*)buffer)[idx] = character;
}
}
// internal null output
static inline void _out_null(char character, void* buffer, size_t idx, size_t maxlen) {
(void)character;
(void)buffer;
(void)idx;
(void)maxlen;
}
// internal output function wrapper
static inline void _out_fct(char character, void* buffer, size_t idx, size_t maxlen) {
(void)idx;
(void)maxlen;
// buffer is the output fct pointer
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
}
// internal strlen
// \return The length of the string (excluding the terminating 0)
static inline unsigned int _strlen(const char* str) {
const char* s;
for (s = str; *s; ++s)
;
return (unsigned int)(s - str);
}
// internal test if char is a digit (0-9)
// \return true if char is a digit
static inline bool _is_digit(char ch) {
return (ch >= '0') && (ch <= '9');
}
// internal ASCII string to unsigned int conversion
static inline unsigned int _atoi(const char** str) {
unsigned int i = 0U;
while (_is_digit(**str)) {
i = i * 10U + (unsigned int)(*((*str)++) - '0');
}
return i;
}
// internal itoa format
static inline size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
char* buf, size_t len, bool negative, unsigned int base,
unsigned int prec, unsigned int width, unsigned int flags) {
const size_t start_idx = idx;
// pad leading zeros
while (!(flags & FLAGS_LEFT) && (len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = '0';
}
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) &&
(len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = '0';
}
// handle hash
if (flags & FLAGS_HASH) {
if (((len == prec) || (len == width)) && (len > 0U)) {
len--;
if ((base == 16U) && (len > 0U)) {
len--;
}
}
if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = 'x';
}
if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = 'X';
}
if (len < PRINTF_NTOA_BUFFER_SIZE) {
buf[len++] = '0';
}
}
// handle sign
if ((len == width) && (negative || (flags & FLAGS_PLUS) || (flags & FLAGS_SPACE))) {
len--;
}
if (len < PRINTF_NTOA_BUFFER_SIZE) {
if (negative) {
buf[len++] = '-';
} else if (flags & FLAGS_PLUS) {
buf[len++] = '+'; // ignore the space if the '+' exists
} else if (flags & FLAGS_SPACE) {
buf[len++] = ' ';
}
}
// pad spaces up to given width
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
for (size_t i = len; i < width; i++) {
out(' ', buffer, idx++, maxlen);
}
}
// reverse string
for (size_t i = 0U; i < len; i++) {
out(buf[len - i - 1U], buffer, idx++, maxlen);
}
// append pad spaces up to given width
if (flags & FLAGS_LEFT) {
while (idx - start_idx < width) {
out(' ', buffer, idx++, maxlen);
}
}
return idx;
}
// internal itoa for 'long' type
static inline size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
unsigned long value, bool negative, unsigned long base,
unsigned int prec, unsigned int width, unsigned int flags) {
char buf[PRINTF_NTOA_BUFFER_SIZE];
size_t len = 0U;
// write if precision != 0 and value is != 0
if (!(flags & FLAGS_PRECISION) || value) {
do {
const char digit = (char)(value % base);
buf[len++] =
digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
value /= base;
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
}
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec,
width, flags);
}
// internal itoa for 'long long' type
#if defined(PRINTF_SUPPORT_LONG_LONG)
static inline size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
unsigned long long value, bool negative,
unsigned long long base, unsigned int prec, unsigned int width,
unsigned int flags) {
char buf[PRINTF_NTOA_BUFFER_SIZE];
size_t len = 0U;
// write if precision != 0 and value is != 0
if (!(flags & FLAGS_PRECISION) || value) {
do {
const char digit = (char)(value % base);
buf[len++] =
digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
value /= base;
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
}
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec,
width, flags);
}
#endif // PRINTF_SUPPORT_LONG_LONG
#if defined(PRINTF_SUPPORT_FLOAT)
static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value,
unsigned int prec, unsigned int width, unsigned int flags) {
char buf[PRINTF_FTOA_BUFFER_SIZE];
size_t len = 0U;
double diff = 0.0;
// if input is larger than thres_max, revert to exponential
const double thres_max = (double)0x7FFFFFFF;
// powers of 10
static const double pow10[] = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
// test for negative
bool negative = false;
if (value < 0) {
negative = true;
value = 0 - value;
}
// set default precision to 6, if not set explicitly
if (!(flags & FLAGS_PRECISION)) {
prec = 6U;
}
// limit precision to 9, cause a prec >= 10 can lead to overflow errors
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) {
buf[len++] = '0';
prec--;
}
int whole = (int)value;
double tmp = (value - whole) * pow10[prec];
unsigned long frac = (unsigned long)tmp;
diff = tmp - frac;
if (diff > 0.5) {
++frac;
// handle rollover, e.g. case 0.99 with prec 1 is 1.0
if (frac >= pow10[prec]) {
frac = 0;
++whole;
}
} else if ((diff == 0.5) && ((frac == 0U) || (frac & 1U))) {
// if halfway, round up if odd, OR if last digit is 0
++frac;
}
// TBD: for very large numbers switch back to native sprintf for exponentials. Anyone want to
// write code to replace this? Normal printf behavior is to print EVERY whole number digit which
// can be 100s of characters overflowing your buffers == bad
if (value > thres_max) {
return 0U;
}
if (prec == 0U) {
diff = value - (double)whole;
if (diff > 0.5) {
// greater than 0.5, round up, e.g. 1.6 -> 2
++whole;
} else if ((diff == 0.5) && (whole & 1)) {
// exactly 0.5 and ODD, then round up
// 1.5 -> 2, but 2.5 -> 2
++whole;
}
} else {
unsigned int count = prec;
// now do fractional part, as an unsigned number
while (len < PRINTF_FTOA_BUFFER_SIZE) {
--count;
buf[len++] = (char)(48U + (frac % 10U));
if (!(frac /= 10U)) {
break;
}
}
// add extra 0s
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) {
buf[len++] = '0';
}
if (len < PRINTF_FTOA_BUFFER_SIZE) {
// add decimal
buf[len++] = '.';
}
}
// do whole part, number is reversed
while (len < PRINTF_FTOA_BUFFER_SIZE) {
buf[len++] = (char)(48 + (whole % 10));
if (!(whole /= 10)) {
break;
}
}
// pad leading zeros
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) &&
(len < PRINTF_FTOA_BUFFER_SIZE)) {
buf[len++] = '0';
}
// handle sign
if ((len == width) && (negative || (flags & FLAGS_PLUS) || (flags & FLAGS_SPACE))) {
len--;
}
if (len < PRINTF_FTOA_BUFFER_SIZE) {
if (negative) {
buf[len++] = '-';
} else if (flags & FLAGS_PLUS) {
buf[len++] = '+'; // ignore the space if the '+' exists
} else if (flags & FLAGS_SPACE) {
buf[len++] = ' ';
}
}
// pad spaces up to given width
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
for (size_t i = len; i < width; i++) {
out(' ', buffer, idx++, maxlen);
}
}
// reverse string
for (size_t i = 0U; i < len; i++) {
out(buf[len - i - 1U], buffer, idx++, maxlen);
}
// append pad spaces up to given width
if (flags & FLAGS_LEFT) {
while (idx < width) {
out(' ', buffer, idx++, maxlen);
}
}
return idx;
}
#endif // PRINTF_SUPPORT_FLOAT
// internal vsnprintf
static inline int _vsnprintf(out_fct_type out, char* buffer, const char* format, VaList* va_list) {
unsigned int flags, width, precision, n;
size_t idx = 0U;
auto maxlen = static_cast<size_t>(-1);
if (!buffer) {
// use null output function
out = _out_null;
}
while (*format) {
// format specifier? %[flags][width][.precision][length]
if (*format != '%') {
// no
out(*format, buffer, idx++, maxlen);
format++;
continue;
} else {
// yes, evaluate it
format++;
}
// evaluate flags
flags = 0U;
do {
switch (*format) {
case '0':
flags |= FLAGS_ZEROPAD;
format++;
n = 1U;
break;
case '-':
flags |= FLAGS_LEFT;
format++;
n = 1U;
break;
case '+':
flags |= FLAGS_PLUS;
format++;
n = 1U;
break;
case ' ':
flags |= FLAGS_SPACE;
format++;
n = 1U;
break;
case '#':
flags |= FLAGS_HASH;
format++;
n = 1U;
break;
default:
n = 0U;
break;
}
} while (n);
// evaluate width field
width = 0U;
if (_is_digit(*format)) {
width = _atoi(&format);
} else if (*format == '*') {
const int w = vaArgInteger(va_list); // const int w = va.next<int>(cpu, mem);
if (w < 0) {
flags |= FLAGS_LEFT; // reverse padding
width = (unsigned int)-w;
} else {
width = (unsigned int)w;
}
format++;
}
// evaluate precision field
precision = 0U;
if (*format == '.') {
flags |= FLAGS_PRECISION;
format++;
if (_is_digit(*format)) {
precision = _atoi(&format);
} else if (*format == '*') {
precision =
vaArgInteger(va_list); // precision = (unsigned int)va.next<int>(cpu, mem);
format++;
}
}
// evaluate length field
switch (*format) {
case 'l':
flags |= FLAGS_LONG;
format++;
if (*format == 'l') {
flags |= FLAGS_LONG_LONG;
format++;
}
break;
case 'h':
flags |= FLAGS_SHORT;
format++;
if (*format == 'h') {
flags |= FLAGS_CHAR;
format++;
}
break;
#if defined(PRINTF_SUPPORT_PTRDIFF_T)
case 't':
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
format++;
break;
#endif
case 'j':
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
format++;
break;
case 'z':
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
format++;
break;
default:
break;
}
// evaluate specifier
switch (*format) {
case 'd':
case 'i':
case 'u':
case 'x':
case 'X':
case 'o':
case 'b': {
// set the base
unsigned int base;
if (*format == 'x' || *format == 'X') {
base = 16U;
} else if (*format == 'o') {
base = 8U;
} else if (*format == 'b') {
base = 2U;
flags &= ~FLAGS_HASH; // no hash for bin format
} else {
base = 10U;
flags &= ~FLAGS_HASH; // no hash for dec format
}
// uppercase
if (*format == 'X') {
flags |= FLAGS_UPPERCASE;
}
// no plus or space flag for u, x, X, o, b
if ((*format != 'i') && (*format != 'd')) {
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
}
// convert the integer
if ((*format == 'i') || (*format == 'd')) {
// signed
if (flags & FLAGS_LONG_LONG) {
#if defined(PRINTF_SUPPORT_LONG_LONG)
auto value = vaArgLongLong(
va_list); // const long long value = va.next<long long>(cpu, mem);
idx = _ntoa_long_long(out, buffer, idx, maxlen,
(unsigned long long)(value > 0 ? value : 0 - value),
value < 0, base, precision, width, flags);
#endif
} else if (flags & FLAGS_LONG) {
auto value = vaArgLong(va_list); // const long value = va.next<long>(cpu, mem);
idx = _ntoa_long(out, buffer, idx, maxlen,
(unsigned long)(value > 0 ? value : 0 - value), value < 0,
base, precision, width, flags);
} else {
// const int value = (flags & FLAGS_CHAR) ? (char)va.next<int>(cpu, mem) :
// (flags & FLAGS_SHORT) ? (short int)va.next<int>(cpu, mem): va.next<int>(cpu,
// mem);
const int value =
(flags & FLAGS_CHAR) ? static_cast<char>(vaArgInteger(va_list))
: (flags & FLAGS_SHORT) ? static_cast<int16_t>(vaArgInteger(va_list))
: vaArgInteger(va_list);
idx = _ntoa_long(out, buffer, idx, maxlen,
(unsigned int)(value > 0 ? value : 0 - value), value < 0, base,
precision, width, flags);
}
} else {
// unsigned
if (flags & FLAGS_LONG_LONG) {
#if defined(PRINTF_SUPPORT_LONG_LONG)
// idx = _ntoa_long_long(out, buffer, idx, maxlen, va.next<unsigned long
// long>(cpu, mem), false, base, precision, width, flags);
idx = _ntoa_long_long(out, buffer, idx, maxlen,
static_cast<u64>(vaArgLongLong(va_list)), false, base,
precision, width, flags);
#endif
} else if (flags & FLAGS_LONG) {
// idx = _ntoa_long(out, buffer, idx, maxlen, va.next<unsigned long>(cpu, mem),
// false, base, precision, width, flags);
idx = _ntoa_long(out, buffer, idx, maxlen, static_cast<u32>(vaArgLong(va_list)),
false, base, precision, width, flags);
} else {
// const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned
// char)va.next<unsigned int>(cpu, mem) : (flags & FLAGS_SHORT) ?
// (unsigned short int)va.next<unsigned int>(cpu, mem) : va.next<unsigned
// int>(cpu, mem);
const unsigned int value =
(flags & FLAGS_CHAR) ? static_cast<u8>(vaArgInteger(va_list))
: (flags & FLAGS_SHORT) ? static_cast<u16>(vaArgInteger(va_list))
: static_cast<u32>(vaArgInteger(va_list));
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width,
flags);
}
}
format++;
break;
}
#if defined(PRINTF_SUPPORT_FLOAT)
case 'f':
case 'F':
// idx = _ftoa(out, buffer, idx, maxlen, va.next<double>(cpu, mem), precision, width,
// flags);
idx = _ftoa(out, buffer, idx, maxlen, vaArgDouble(va_list), precision, width, flags);
format++;
break;
#endif // PRINTF_SUPPORT_FLOAT
case 'c': {
unsigned int l = 1U;
// pre padding
if (!(flags & FLAGS_LEFT)) {
while (l++ < width) {
out(' ', buffer, idx++, maxlen);
}
}
// char output
// out((char)va.next<int>(cpu, mem), buffer, idx++, maxlen);
out(static_cast<char>(vaArgInteger(va_list)), buffer, idx++, maxlen);
// post padding
if (flags & FLAGS_LEFT) {
while (l++ < width) {
out(' ', buffer, idx++, maxlen);
}
}
format++;
break;
}
case 's': {
const char* p = vaArgPtr<const char>(
va_list); // const char *p = va.next<Ptr<char>>(cpu, mem).get(mem);
p = p != nullptr ? p : "(null)";
unsigned int l = _strlen(p);
// pre padding
if (flags & FLAGS_PRECISION) {
l = (l < precision ? l : precision);
}
if (!(flags & FLAGS_LEFT)) {
while (l++ < width) {
out(' ', buffer, idx++, maxlen);
}
}
// string output
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
out(*(p++), buffer, idx++, maxlen);
}
// post padding
if (flags & FLAGS_LEFT) {
while (l++ < width) {
out(' ', buffer, idx++, maxlen);
}
}
format++;
break;
}
case 'p': {
width = sizeof(void*) * 2U;
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
#if defined(PRINTF_SUPPORT_LONG_LONG)
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
if (is_ll) {
// idx = _ntoa_long_long(out, buffer, idx, maxlen,
// (uintptr_t)va.next<Ptr<void>>(cpu, mem).address(), false, 16U, precision, width,
// flags);
idx = _ntoa_long_long(out, buffer, idx, maxlen,
reinterpret_cast<uintptr_t>(vaArgPtr<void>(va_list)), false,
16U, precision, width, flags);
} else {
#endif
// idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned
// long)((uintptr_t)va.next<Ptr<void>>(cpu, mem).address()), false, 16U, precision,
// width, flags);
idx = _ntoa_long(
out, buffer, idx, maxlen,
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(vaArgPtr<void>(va_list))),
false, 16U, precision, width, flags);
#if defined(PRINTF_SUPPORT_LONG_LONG)
}
#endif
format++;
break;
}
case '%':
out('%', buffer, idx++, maxlen);
format++;
break;
default:
out(*format, buffer, idx++, maxlen);
format++;
break;
}
}
// termination
out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen);
// return written chars without terminating \0
return (int)idx;
}
static int printf_ctx(VaCtx* ctx) {
const char* format = vaArgPtr<const char>(&ctx->va_list);
char buffer[256];
int result = _vsnprintf(_out_buffer, buffer, format, &ctx->va_list);
printf("%s", buffer);
return result;
}
static int fprintf_ctx(VaCtx* ctx, char* buf) {
const char* format = vaArgPtr<const char>(&ctx->va_list);
char buffer[256];
int result = _vsnprintf(_out_buffer, buffer, format, &ctx->va_list);
std::strcpy(buf, buffer);
return result;
}
static int vsnprintf_ctx(char* s, size_t n, const char* format, VaList* arg) {
char buffer[n];
int result = _vsnprintf(_out_buffer, buffer, format, arg);
std::strcpy(s, buffer);
return result;
}
} // namespace Libraries::LibC

View File

@ -1,110 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <xmmintrin.h>
#include "common/types.h"
#define VA_ARGS \
uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9, \
uint64_t overflow_arg_area, __m128 xmm0, __m128 xmm1, __m128 xmm2, __m128 xmm3, \
__m128 xmm4, __m128 xmm5, __m128 xmm6, __m128 xmm7, ...
#define VA_CTX(ctx) \
alignas(16) VaCtx ctx; \
(ctx).reg_save_area.gp[0] = rdi; \
(ctx).reg_save_area.gp[1] = rsi; \
(ctx).reg_save_area.gp[2] = rdx; \
(ctx).reg_save_area.gp[3] = rcx; \
(ctx).reg_save_area.gp[4] = r8; \
(ctx).reg_save_area.gp[5] = r9; \
(ctx).reg_save_area.fp[0] = xmm0; \
(ctx).reg_save_area.fp[1] = xmm1; \
(ctx).reg_save_area.fp[2] = xmm2; \
(ctx).reg_save_area.fp[3] = xmm3; \
(ctx).reg_save_area.fp[4] = xmm4; \
(ctx).reg_save_area.fp[5] = xmm5; \
(ctx).reg_save_area.fp[6] = xmm6; \
(ctx).reg_save_area.fp[7] = xmm7; \
(ctx).va_list.reg_save_area = &(ctx).reg_save_area; \
(ctx).va_list.gp_offset = offsetof(VaRegSave, gp); \
(ctx).va_list.fp_offset = offsetof(VaRegSave, fp); \
(ctx).va_list.overflow_arg_area = &overflow_arg_area;
namespace Libraries::LibC {
// https://stackoverflow.com/questions/4958384/what-is-the-format-of-the-x86-64-va-list-structure
struct VaList {
u32 gp_offset;
u32 fp_offset;
void* overflow_arg_area;
void* reg_save_area;
};
struct VaRegSave {
u64 gp[6];
__m128 fp[8];
};
struct VaCtx {
VaRegSave reg_save_area;
VaList va_list;
};
template <class T, uint32_t Size>
T vaArgRegSaveAreaGp(VaList* l) {
auto* addr = reinterpret_cast<T*>(static_cast<u8*>(l->reg_save_area) + l->gp_offset);
l->gp_offset += Size;
return *addr;
}
template <class T, u64 Align, u64 Size>
T vaArgOverflowArgArea(VaList* l) {
auto ptr = ((reinterpret_cast<u64>(l->overflow_arg_area) + (Align - 1)) & ~(Align - 1));
auto* addr = reinterpret_cast<T*>(ptr);
l->overflow_arg_area = reinterpret_cast<void*>(ptr + Size);
return *addr;
}
template <class T, uint32_t Size>
T vaArgRegSaveAreaFp(VaList* l) {
auto* addr = reinterpret_cast<T*>(static_cast<u8*>(l->reg_save_area) + l->fp_offset);
l->fp_offset += Size;
return *addr;
}
inline int vaArgInteger(VaList* l) {
if (l->gp_offset <= 40) {
return vaArgRegSaveAreaGp<int, 8>(l);
}
return vaArgOverflowArgArea<int, 1, 8>(l);
}
inline long long vaArgLongLong(VaList* l) {
if (l->gp_offset <= 40) {
return vaArgRegSaveAreaGp<long long, 8>(l);
}
return vaArgOverflowArgArea<long long, 1, 8>(l);
}
inline long vaArgLong(VaList* l) {
if (l->gp_offset <= 40) {
return vaArgRegSaveAreaGp<long, 8>(l);
}
return vaArgOverflowArgArea<long, 1, 8>(l);
}
inline double vaArgDouble(VaList* l) {
if (l->fp_offset <= 160) {
return vaArgRegSaveAreaFp<double, 16>(l);
}
return vaArgOverflowArgArea<double, 1, 8>(l);
}
template <class T>
T* vaArgPtr(VaList* l) {
if (l->gp_offset <= 40) {
return vaArgRegSaveAreaGp<T*, 8>(l);
}
return vaArgOverflowArgArea<T*, 1, 8>(l);
}
} // namespace Libraries::LibC

View File

@ -8,7 +8,6 @@
#include "core/libraries/disc_map/disc_map.h"
#include "core/libraries/gnmdriver/gnmdriver.h"
#include "core/libraries/kernel/libkernel.h"
#include "core/libraries/libc/libc.h"
#include "core/libraries/libc_internal/libc_internal.h"
#include "core/libraries/libs.h"
#include "core/libraries/network/http.h"
@ -46,9 +45,6 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) {
Libraries::Kernel::LibKernel_Register(sym);
Libraries::GnmDriver::RegisterlibSceGnmDriver(sym);
Libraries::VideoOut::RegisterLib(sym);
if (!Config::isLleLibc()) {
Libraries::LibC::libcSymbolsRegister(sym);
}
// New libraries folder from autogen
Libraries::UserService::RegisterlibSceUserService(sym);

View File

@ -19,7 +19,6 @@
#include "core/file_sys/fs.h"
#include "core/libraries/disc_map/disc_map.h"
#include "core/libraries/kernel/thread_management.h"
#include "core/libraries/libc/libc.h"
#include "core/libraries/libc_internal/libc_internal.h"
#include "core/libraries/libs.h"
#include "core/libraries/ngs2/ngs2.h"
@ -63,7 +62,6 @@ Emulator::Emulator() {
LOG_INFO(Config, "Vulkan vkValidationGpu: {}", Config::vkValidationGpuEnabled());
LOG_INFO(Config, "Vulkan rdocEnable: {}", Config::isRdocEnabled());
LOG_INFO(Config, "Vulkan rdocMarkersEnable: {}", Config::isMarkersEnabled());
LOG_INFO(Config, "LLE isLibc: {}", Config::isLleLibc());
// Defer until after logging is initialized.
memory = Core::Memory::Instance();
@ -167,23 +165,14 @@ void Emulator::Run(const std::filesystem::path& file) {
// check if we have system modules to load
LoadSystemModules(file);
// Check if there is a libc.prx in sce_module folder
bool found = false;
if (Config::isLleLibc()) {
std::filesystem::path sce_module_folder = file.parent_path() / "sce_module";
if (std::filesystem::is_directory(sce_module_folder)) {
for (const auto& entry : std::filesystem::directory_iterator(sce_module_folder)) {
if (entry.path().filename() == "libc.prx") {
found = true;
}
LOG_INFO(Loader, "Loading {}", entry.path().string().c_str());
linker->LoadModule(entry.path());
}
// Load all prx from game's sce_module folder
std::filesystem::path sce_module_folder = file.parent_path() / "sce_module";
if (std::filesystem::is_directory(sce_module_folder)) {
for (const auto& entry : std::filesystem::directory_iterator(sce_module_folder)) {
LOG_INFO(Loader, "Loading {}", entry.path().string().c_str());
linker->LoadModule(entry.path());
}
}
if (!found) {
Libraries::LibC::libcSymbolsRegister(&linker->GetHLESymbols());
}
// start execution
std::jthread mainthread =