mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-31 07:43:16 +00:00
src: Reorganize and cleanup libraries
This commit is contained in:
parent
e99129d72f
commit
5e2ac6c72b
84 changed files with 806 additions and 8664 deletions
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libsceaudioin.h"
|
||||
#include "core/libraries/audio/audioin.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
|
||||
namespace Libraries::AudioIn {
|
||||
|
||||
|
@ -277,4 +277,4 @@ void RegisterlibSceAudioIn(Core::Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("4kHw99LUG3A", "libSceAudioIn", 1, "libSceAudioIn", 1, 1, sceAudioInVmicWrite);
|
||||
};
|
||||
|
||||
} // namespace Libraries::AudioIn
|
||||
} // namespace Libraries::AudioIn
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::AudioIn {
|
||||
|
||||
|
@ -51,4 +55,4 @@ int PS4_SYSV_ABI sceAudioInVmicDestroy();
|
|||
int PS4_SYSV_ABI sceAudioInVmicWrite();
|
||||
|
||||
void RegisterlibSceAudioIn(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::AudioIn
|
||||
} // namespace Libraries::AudioIn
|
|
@ -1,13 +1,13 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include <common/singleton.h>
|
||||
#include <memory>
|
||||
#include <magic_enum.hpp>
|
||||
#include "audio_core/sdl_audio.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libsceaudioout.h"
|
||||
#include "src/audio_core/sdl_audio.h"
|
||||
#include "core/libraries/audio/audioout.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
|
||||
namespace Libraries::AudioOut {
|
||||
|
||||
|
@ -575,4 +575,4 @@ void RegisterlibSceAudioOut(Core::Loader::SymbolsResolver* sym) {
|
|||
sceAudioOutSetSystemDebugState);
|
||||
};
|
||||
|
||||
} // namespace Libraries::AudioOut
|
||||
} // namespace Libraries::AudioOut
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "libsceuserservice.h"
|
||||
#include "core/libraries/system/userservice.h"
|
||||
|
||||
namespace Libraries::AudioOut {
|
||||
|
||||
|
@ -110,4 +109,4 @@ int PS4_SYSV_ABI sceAudioOutSparkControlSetEqCoef();
|
|||
int PS4_SYSV_ABI sceAudioOutSetSystemDebugState();
|
||||
|
||||
void RegisterlibSceAudioOut(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::AudioOut
|
||||
} // namespace Libraries::AudioOut
|
|
@ -3,6 +3,249 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// posix error codes
|
||||
constexpr int POSIX_EPERM = 1;
|
||||
constexpr int POSIX_ENOENT = 2;
|
||||
constexpr int POSIX_ESRCH = 3;
|
||||
constexpr int POSIX_EINTR = 4;
|
||||
constexpr int POSIX_EIO = 5;
|
||||
constexpr int POSIX_ENXIO = 6;
|
||||
constexpr int POSIX_E2BIG = 7;
|
||||
constexpr int POSIX_ENOEXEC = 8;
|
||||
constexpr int POSIX_EBADF = 9;
|
||||
constexpr int POSIX_ECHILD = 10;
|
||||
constexpr int POSIX_EDEADLK = 11;
|
||||
constexpr int POSIX_ENOMEM = 12;
|
||||
constexpr int POSIX_EACCES = 13;
|
||||
constexpr int POSIX_EFAULT = 14;
|
||||
constexpr int POSIX_ENOTBLK = 15;
|
||||
constexpr int POSIX_EBUSY = 16;
|
||||
constexpr int POSIX_EEXIST = 17;
|
||||
constexpr int POSIX_EXDEV = 18;
|
||||
constexpr int POSIX_ENODEV = 19;
|
||||
constexpr int POSIX_ENOTDIR = 20;
|
||||
constexpr int POSIX_EISDIR = 21;
|
||||
constexpr int POSIX_EINVAL = 22;
|
||||
constexpr int POSIX_ENFILE = 23;
|
||||
constexpr int POSIX_EMFILE = 24;
|
||||
constexpr int POSIX_ENOTTY = 25;
|
||||
constexpr int POSIX_ETXTBSY = 26;
|
||||
constexpr int POSIX_EFBIG = 27;
|
||||
constexpr int POSIX_ENOSPC = 28;
|
||||
constexpr int POSIX_ESPIPE = 29;
|
||||
constexpr int POSIX_EROFS = 30;
|
||||
constexpr int POSIX_EMLINK = 31;
|
||||
constexpr int POSIX_EPIPE = 32;
|
||||
constexpr int POSIX_EDOM = 33;
|
||||
constexpr int POSIX_ERANGE = 34;
|
||||
constexpr int POSIX_EAGAIN = 35;
|
||||
constexpr int POSIX_EWOULDBLOCK = 35;
|
||||
constexpr int POSIX_EINPROGRESS = 36;
|
||||
constexpr int POSIX_EALREADY = 37;
|
||||
constexpr int POSIX_ENOTSOCK = 38;
|
||||
constexpr int POSIX_EDESTADDRREQ = 39;
|
||||
constexpr int POSIX_EMSGSIZE = 40;
|
||||
constexpr int POSIX_EPROTOTYPE = 41;
|
||||
constexpr int POSIX_ENOPROTOOPT = 42;
|
||||
constexpr int POSIX_EPROTONOSUPPORT = 43;
|
||||
constexpr int POSIX_ESOCKTNOSUPPORT = 44;
|
||||
constexpr int POSIX_EOPNOTSUPP = 45;
|
||||
constexpr int POSIX_ENOTSUP = 45;
|
||||
constexpr int POSIX_EPFNOSUPPORT = 46;
|
||||
constexpr int POSIX_EAFNOSUPPORT = 47;
|
||||
constexpr int POSIX_EADDRINUSE = 48;
|
||||
constexpr int POSIX_EADDRNOTAVAIL = 49;
|
||||
constexpr int POSIX_ENETDOWN = 50;
|
||||
constexpr int POSIX_ENETUNREACH = 51;
|
||||
constexpr int POSIX_ENETRESET = 52;
|
||||
constexpr int POSIX_ECONNABORTED = 53;
|
||||
constexpr int POSIX_ECONNRESET = 54;
|
||||
constexpr int POSIX_ENOBUFS = 55;
|
||||
constexpr int POSIX_EISCONN = 56;
|
||||
constexpr int POSIX_ENOTCONN = 57;
|
||||
constexpr int POSIX_ESHUTDOWN = 58;
|
||||
constexpr int POSIX_ETOOMANYREFS = 59;
|
||||
constexpr int POSIX_ETIMEDOUT = 60;
|
||||
constexpr int POSIX_ECONNREFUSED = 61;
|
||||
constexpr int POSIX_ELOOP = 62;
|
||||
constexpr int POSIX_ENAMETOOLONG = 63;
|
||||
constexpr int POSIX_EHOSTDOWN = 64;
|
||||
constexpr int POSIX_EHOSTUNREACH = 65;
|
||||
constexpr int POSIX_ENOTEMPTY = 66;
|
||||
constexpr int POSIX_EPROCLIM = 67;
|
||||
constexpr int POSIX_EUSERS = 68;
|
||||
constexpr int POSIX_EDQUOT = 69;
|
||||
constexpr int POSIX_ESTALE = 70;
|
||||
constexpr int POSIX_EREMOTE = 71;
|
||||
constexpr int POSIX_EBADRPC = 72;
|
||||
constexpr int POSIX_ERPCMISMATCH = 73;
|
||||
constexpr int POSIX_EPROGUNAVAIL = 74;
|
||||
constexpr int POSIX_EPROGMISMATCH = 75;
|
||||
constexpr int POSIX_EPROCUNAVAIL = 76;
|
||||
constexpr int POSIX_ENOLCK = 77;
|
||||
constexpr int POSIX_ENOSYS = 78;
|
||||
constexpr int POSIX_EFTYPE = 79;
|
||||
constexpr int POSIX_EAUTH = 80;
|
||||
constexpr int POSIX_ENEEDAUTH = 81;
|
||||
constexpr int POSIX_EIDRM = 82;
|
||||
constexpr int POSIX_ENOMSG = 83;
|
||||
constexpr int POSIX_EOVERFLOW = 84;
|
||||
constexpr int POSIX_ECANCELED = 85;
|
||||
constexpr int POSIX_EILSEQ = 86;
|
||||
constexpr int POSIX_ENOATTR = 87;
|
||||
constexpr int POSIX_EDOOFUS = 88;
|
||||
constexpr int POSIX_EBADMSG = 89;
|
||||
constexpr int POSIX_EMULTIHOP = 90;
|
||||
constexpr int POSIX_ENOLINK = 91;
|
||||
constexpr int POSIX_EPROTO = 92;
|
||||
constexpr int POSIX_ENOTCAPABLE = 93;
|
||||
constexpr int POSIX_ECAPMODE = 94;
|
||||
constexpr int POSIX_ENOBLK = 95;
|
||||
constexpr int POSIX_EICV = 96;
|
||||
constexpr int POSIX_ENOPLAYGOENT = 97;
|
||||
constexpr int POSIX_EREVOKE = 98;
|
||||
constexpr int POSIX_ESDKVERSION = 99;
|
||||
constexpr int POSIX_ESTART = 100;
|
||||
constexpr int POSIX_ESTOP = 101;
|
||||
constexpr int POSIX_EINVALID2MB = 102;
|
||||
constexpr int POSIX_ELAST = 102;
|
||||
constexpr int POSIX_EADHOC = 160;
|
||||
constexpr int POSIX_EINACTIVEDISABLED = 163;
|
||||
constexpr int POSIX_ENETNODATA = 164;
|
||||
constexpr int POSIX_ENETDESC = 165;
|
||||
constexpr int POSIX_ENETDESCTIMEDOUT = 166;
|
||||
constexpr int POSIX_ENETINTR = 167;
|
||||
constexpr int POSIX_ERETURN = 205;
|
||||
constexpr int POSIX_EFPOS = 152;
|
||||
constexpr int POSIX_ENODATA = 1040;
|
||||
constexpr int POSIX_ENOSR = 1050;
|
||||
constexpr int POSIX_ENOSTR = 1051;
|
||||
constexpr int POSIX_ENOTRECOVERABLE = 1056;
|
||||
constexpr int POSIX_EOTHER = 1062;
|
||||
constexpr int POSIX_EOWNERDEAD = 1064;
|
||||
constexpr int POSIX_ETIME = 1074;
|
||||
|
||||
constexpr int SCE_OK = 0;
|
||||
|
||||
// kernel error codes
|
||||
constexpr int SCE_KERNEL_ERROR_UNKNOWN = 0x80020000;
|
||||
constexpr int SCE_KERNEL_ERROR_EPERM = 0x80020001;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOENT = 0x80020002;
|
||||
constexpr int SCE_KERNEL_ERROR_ESRCH = 0x80020003;
|
||||
constexpr int SCE_KERNEL_ERROR_EINTR = 0x80020004;
|
||||
constexpr int SCE_KERNEL_ERROR_EIO = 0x80020005;
|
||||
constexpr int SCE_KERNEL_ERROR_ENXIO = 0x80020006;
|
||||
constexpr int SCE_KERNEL_ERROR_E2BIG = 0x80020007;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOEXEC = 0x80020008;
|
||||
constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009;
|
||||
constexpr int SCE_KERNEL_ERROR_ECHILD = 0x8002000A;
|
||||
constexpr int SCE_KERNEL_ERROR_EDEADLK = 0x8002000B;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000C;
|
||||
constexpr int SCE_KERNEL_ERROR_EACCES = 0x8002000D;
|
||||
constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000E;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTBLK = 0x8002000F;
|
||||
constexpr int SCE_KERNEL_ERROR_EBUSY = 0x80020010;
|
||||
constexpr int SCE_KERNEL_ERROR_EEXIST = 0x80020011;
|
||||
constexpr int SCE_KERNEL_ERROR_EXDEV = 0x80020012;
|
||||
constexpr int SCE_KERNEL_ERROR_ENODEV = 0x80020013;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTDIR = 0x80020014;
|
||||
constexpr int SCE_KERNEL_ERROR_EISDIR = 0x80020015;
|
||||
constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016;
|
||||
constexpr int SCE_KERNEL_ERROR_ENFILE = 0x80020017;
|
||||
constexpr int SCE_KERNEL_ERROR_EMFILE = 0x80020018;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTTY = 0x80020019;
|
||||
constexpr int SCE_KERNEL_ERROR_ETXTBSY = 0x8002001A;
|
||||
constexpr int SCE_KERNEL_ERROR_EFBIG = 0x8002001B;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOSPC = 0x8002001C;
|
||||
constexpr int SCE_KERNEL_ERROR_ESPIPE = 0x8002001D;
|
||||
constexpr int SCE_KERNEL_ERROR_EROFS = 0x8002001E;
|
||||
constexpr int SCE_KERNEL_ERROR_EMLINK = 0x8002001F;
|
||||
constexpr int SCE_KERNEL_ERROR_EPIPE = 0x80020020;
|
||||
constexpr int SCE_KERNEL_ERROR_EDOM = 0x80020021;
|
||||
constexpr int SCE_KERNEL_ERROR_ERANGE = 0x80020022;
|
||||
constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023;
|
||||
constexpr int SCE_KERNEL_ERROR_EWOULDBLOCK = 0x80020023;
|
||||
constexpr int SCE_KERNEL_ERROR_EINPROGRESS = 0x80020024;
|
||||
constexpr int SCE_KERNEL_ERROR_EALREADY = 0x80020025;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTSOCK = 0x80020026;
|
||||
constexpr int SCE_KERNEL_ERROR_EDESTADDRREQ = 0x80020027;
|
||||
constexpr int SCE_KERNEL_ERROR_EMSGSIZE = 0x80020028;
|
||||
constexpr int SCE_KERNEL_ERROR_EPROTOTYPE = 0x80020029;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOPROTOOPT = 0x8002002A;
|
||||
constexpr int SCE_KERNEL_ERROR_EPROTONOSUPPORT = 0x8002002B;
|
||||
constexpr int SCE_KERNEL_ERROR_ESOCKTNOSUPPORT = 0x8002002C;
|
||||
constexpr int SCE_KERNEL_ERROR_EOPNOTSUPP = 0x8002002D;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTSUP = 0x8002002D;
|
||||
constexpr int SCE_KERNEL_ERROR_EPFNOSUPPORT = 0x8002002E;
|
||||
constexpr int SCE_KERNEL_ERROR_EAFNOSUPPORT = 0x8002002F;
|
||||
constexpr int SCE_KERNEL_ERROR_EADDRINUSE = 0x80020030;
|
||||
constexpr int SCE_KERNEL_ERROR_EADDRNOTAVAIL = 0x80020031;
|
||||
constexpr int SCE_KERNEL_ERROR_ENETDOWN = 0x80020032;
|
||||
constexpr int SCE_KERNEL_ERROR_ENETUNREACH = 0x80020033;
|
||||
constexpr int SCE_KERNEL_ERROR_ENETRESET = 0x80020034;
|
||||
constexpr int SCE_KERNEL_ERROR_ECONNABORTED = 0x80020035;
|
||||
constexpr int SCE_KERNEL_ERROR_ECONNRESET = 0x80020036;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOBUFS = 0x80020037;
|
||||
constexpr int SCE_KERNEL_ERROR_EISCONN = 0x80020038;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTCONN = 0x80020039;
|
||||
constexpr int SCE_KERNEL_ERROR_ESHUTDOWN = 0x8002003A;
|
||||
constexpr int SCE_KERNEL_ERROR_ETOOMANYREFS = 0x8002003B;
|
||||
constexpr int SCE_KERNEL_ERROR_ETIMEDOUT = 0x8002003C;
|
||||
constexpr int SCE_KERNEL_ERROR_ECONNREFUSED = 0x8002003D;
|
||||
constexpr int SCE_KERNEL_ERROR_ELOOP = 0x8002003E;
|
||||
constexpr int SCE_KERNEL_ERROR_ENAMETOOLONG = 0x8002003F;
|
||||
constexpr int SCE_KERNEL_ERROR_EHOSTDOWN = 0x80020040;
|
||||
constexpr int SCE_KERNEL_ERROR_EHOSTUNREACH = 0x80020041;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTEMPTY = 0x80020042;
|
||||
constexpr int SCE_KERNEL_ERROR_EPROCLIM = 0x80020043;
|
||||
constexpr int SCE_KERNEL_ERROR_EUSERS = 0x80020044;
|
||||
constexpr int SCE_KERNEL_ERROR_EDQUOT = 0x80020045;
|
||||
constexpr int SCE_KERNEL_ERROR_ESTALE = 0x80020046;
|
||||
constexpr int SCE_KERNEL_ERROR_EREMOTE = 0x80020047;
|
||||
constexpr int SCE_KERNEL_ERROR_EBADRPC = 0x80020048;
|
||||
constexpr int SCE_KERNEL_ERROR_ERPCMISMATCH = 0x80020049;
|
||||
constexpr int SCE_KERNEL_ERROR_EPROGUNAVAIL = 0x8002004A;
|
||||
constexpr int SCE_KERNEL_ERROR_EPROGMISMATCH = 0x8002004B;
|
||||
constexpr int SCE_KERNEL_ERROR_EPROCUNAVAIL = 0x8002004C;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOLCK = 0x8002004D;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOSYS = 0x8002004E;
|
||||
constexpr int SCE_KERNEL_ERROR_EFTYPE = 0x8002004F;
|
||||
constexpr int SCE_KERNEL_ERROR_EAUTH = 0x80020050;
|
||||
constexpr int SCE_KERNEL_ERROR_ENEEDAUTH = 0x80020051;
|
||||
constexpr int SCE_KERNEL_ERROR_EIDRM = 0x80020052;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOMSG = 0x80020053;
|
||||
constexpr int SCE_KERNEL_ERROR_EOVERFLOW = 0x80020054;
|
||||
constexpr int SCE_KERNEL_ERROR_ECANCELED = 0x80020055;
|
||||
constexpr int SCE_KERNEL_ERROR_EILSEQ = 0x80020056;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOATTR = 0x80020057;
|
||||
constexpr int SCE_KERNEL_ERROR_EDOOFUS = 0x80020058;
|
||||
constexpr int SCE_KERNEL_ERROR_EBADMSG = 0x80020059;
|
||||
constexpr int SCE_KERNEL_ERROR_EMULTIHOP = 0x8002005A;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOLINK = 0x8002005B;
|
||||
constexpr int SCE_KERNEL_ERROR_EPROTO = 0x8002005C;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTCAPABLE = 0x8002005D;
|
||||
constexpr int SCE_KERNEL_ERROR_ECAPMODE = 0x8002005E;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOBLK = 0x8002005F;
|
||||
constexpr int SCE_KERNEL_ERROR_EICV = 0x80020060;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOPLAYGOENT = 0x80020061;
|
||||
constexpr int SCE_KERNEL_ERROR_EREVOKE = 0x80020062;
|
||||
constexpr int SCE_KERNEL_ERROR_ESDKVERSION = 0x80020063;
|
||||
constexpr int SCE_KERNEL_ERROR_ESTART = 0x80020064;
|
||||
constexpr int SCE_KERNEL_ERROR_ESTOP = 0x80020065;
|
||||
|
||||
// videoOut
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; // invalid addresses
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_TILING_MODE = 0x80290007; // invalid tiling mode
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ASPECT_RATIO = 0x80290008; // invalid aspect ration
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009; // already opened
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_INDEX = 0x8029000A; // invalid buffer index
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_HANDLE = 0x8029000B; // invalid handle
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE = 0x8029000C; // Invalid event queue
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; // slot already used
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; // flip queue is full
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; // Invalid buffer attribute option
|
||||
|
||||
// Generic
|
||||
constexpr int ORBIS_OK = 0x00000000;
|
||||
constexpr int ORBIS_FAIL = 0xFFFFFFFF;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscegnmdriver.h"
|
||||
#include "core/PS4/GPU/gpu_memory.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/gnmdriver/gnmdriver.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "emulator.h"
|
||||
|
||||
namespace Libraries::GnmDriver {
|
||||
|
||||
|
@ -133,9 +135,14 @@ int PS4_SYSV_ABI sceGnmDispatchInitDefaultHardwareState() {
|
|||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmDrawIndex() {
|
||||
LOG_ERROR(Lib_GnmDriver, "(STUBBED) called");
|
||||
return ORBIS_OK;
|
||||
s32 PS4_SYSV_ABI sceGnmDrawIndex(u32* cmd, u64 size, u32 index_count, const void* index_addr,
|
||||
u32 flags, u32 type) {
|
||||
LOG_INFO(Lib_GnmDriver,
|
||||
"(STUBBED) called cmd_buffer = 0x{:x} size = {} index_count = {} index_addr = 0x{:x} "
|
||||
"flags = 0x{:x} type = {}",
|
||||
reinterpret_cast<uint64_t>(cmd), size, index_count,
|
||||
reinterpret_cast<uint64_t>(index_addr), flags, type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmDrawIndexAuto() {
|
||||
|
@ -198,9 +205,10 @@ int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState200() {
|
|||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350() {
|
||||
LOG_ERROR(Lib_GnmDriver, "(STUBBED) called");
|
||||
return ORBIS_OK;
|
||||
int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350(u32* cmd, u64 size) {
|
||||
LOG_INFO(Lib_GnmDriver, "(STUBBED) called cmd_buffer = 0x{:x} size = {}",
|
||||
reinterpret_cast<uint64_t>(cmd), size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextState() {
|
||||
|
@ -283,9 +291,9 @@ int PS4_SYSV_ABI sceGnmFindResourcesPublic() {
|
|||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmFlushGarlic() {
|
||||
LOG_ERROR(Lib_GnmDriver, "(STUBBED) called");
|
||||
return ORBIS_OK;
|
||||
void PS4_SYSV_ABI sceGnmFlushGarlic() {
|
||||
LOG_WARNING(Lib_GnmDriver, "(STUBBED) called");
|
||||
GPU::flushGarlic(Emu::getGraphicCtx());
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmGetCoredumpAddress() {
|
||||
|
@ -683,9 +691,14 @@ int PS4_SYSV_ABI sceGnmSetVgtControl() {
|
|||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmSetVsShader() {
|
||||
LOG_ERROR(Lib_GnmDriver, "(STUBBED) called");
|
||||
return ORBIS_OK;
|
||||
int PS4_SYSV_ABI sceGnmSetVsShader(u32* cmd, u64 size, const u32* vs_regs, u32 shader_modifier) {
|
||||
LOG_INFO(Lib_GnmDriver,
|
||||
"(STUBBED) called cmd_buffer = 0x{:x} size = {} shader_modifier = {} vs_reg0 = "
|
||||
"0x{:x} vs_reg1 = 0x{:x} vs_reg2 = 0x{:x} vs_reg3 = 0x{:x} vs_reg4 = 0x{:x} vs_reg5 = "
|
||||
"0x{:x} vs_reg6 = 0x{:x}",
|
||||
reinterpret_cast<uint64_t>(cmd), size, shader_modifier, vs_regs[0], vs_regs[1],
|
||||
vs_regs[2], vs_regs[3], vs_regs[4], vs_regs[5], vs_regs[6]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmSetWaveLimitMultiplier() {
|
||||
|
@ -948,8 +961,13 @@ int PS4_SYSV_ABI sceGnmUpdatePsShader350() {
|
|||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceGnmUpdateVsShader() {
|
||||
LOG_ERROR(Lib_GnmDriver, "(STUBBED) called");
|
||||
int PS4_SYSV_ABI sceGnmUpdateVsShader(u32* cmd, u64 size, const u32* vs_regs, u32 shader_modifier) {
|
||||
LOG_INFO(Lib_GnmDriver,
|
||||
"(STUBBED) called cmd_buffer = 0x{:x} size = {} shader_modifier = {} vs_reg0 = "
|
||||
"0x{:x} vs_reg1 = 0x{:x} vs_reg2 = 0x{:x} vs_reg3 = 0x{:x} vs_reg4 = 0x{:x} vs_reg5 = "
|
||||
"0x{:x} vs_reg6 = 0x{:x}",
|
||||
reinterpret_cast<uint64_t>(cmd), size, shader_modifier, vs_regs[0], vs_regs[1],
|
||||
vs_regs[2], vs_regs[3], vs_regs[4], vs_regs[5], vs_regs[6]);
|
||||
return ORBIS_OK;
|
||||
}
|
||||
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::GnmDriver {
|
||||
|
||||
|
@ -32,7 +36,8 @@ int PS4_SYSV_ABI sceGnmDispatchDirect();
|
|||
int PS4_SYSV_ABI sceGnmDispatchIndirect();
|
||||
int PS4_SYSV_ABI sceGnmDispatchIndirectOnMec();
|
||||
int PS4_SYSV_ABI sceGnmDispatchInitDefaultHardwareState();
|
||||
int PS4_SYSV_ABI sceGnmDrawIndex();
|
||||
s32 PS4_SYSV_ABI sceGnmDrawIndex(u32* cmd, u64 size, u32 index_count, const void* index_addr,
|
||||
u32 flags, u32 type);
|
||||
int PS4_SYSV_ABI sceGnmDrawIndexAuto();
|
||||
int PS4_SYSV_ABI sceGnmDrawIndexIndirect();
|
||||
int PS4_SYSV_ABI sceGnmDrawIndexIndirectCountMulti();
|
||||
|
@ -45,7 +50,7 @@ int PS4_SYSV_ABI sceGnmDrawIndirectMulti();
|
|||
int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState();
|
||||
int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState175();
|
||||
int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState200();
|
||||
int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350();
|
||||
int PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350(u32* cmd, u64 size);
|
||||
int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextState();
|
||||
int PS4_SYSV_ABI sceGnmDrawInitToDefaultContextState400();
|
||||
int PS4_SYSV_ABI sceGnmDrawOpaqueAuto();
|
||||
|
@ -62,7 +67,7 @@ int PS4_SYSV_ABI sceGnmDriverTraceInProgress();
|
|||
int PS4_SYSV_ABI sceGnmDriverTriggerCapture();
|
||||
int PS4_SYSV_ABI sceGnmEndWorkload();
|
||||
int PS4_SYSV_ABI sceGnmFindResourcesPublic();
|
||||
int PS4_SYSV_ABI sceGnmFlushGarlic();
|
||||
void PS4_SYSV_ABI sceGnmFlushGarlic();
|
||||
int PS4_SYSV_ABI sceGnmGetCoredumpAddress();
|
||||
int PS4_SYSV_ABI sceGnmGetCoredumpMode();
|
||||
int PS4_SYSV_ABI sceGnmGetCoredumpProtectionFaultTimestamp();
|
||||
|
@ -142,7 +147,7 @@ int PS4_SYSV_ABI sceGnmSetSpiEnableSqCounters();
|
|||
int PS4_SYSV_ABI sceGnmSetSpiEnableSqCountersForUnitInstance();
|
||||
int PS4_SYSV_ABI sceGnmSetupMipStatsReport();
|
||||
int PS4_SYSV_ABI sceGnmSetVgtControl();
|
||||
int PS4_SYSV_ABI sceGnmSetVsShader();
|
||||
int PS4_SYSV_ABI sceGnmSetVsShader(u32* cmd, u64 size, const u32* vs_regs, u32 shader_modifier);
|
||||
int PS4_SYSV_ABI sceGnmSetWaveLimitMultiplier();
|
||||
int PS4_SYSV_ABI sceGnmSetWaveLimitMultipliers();
|
||||
int PS4_SYSV_ABI sceGnmSpmEndSpm();
|
||||
|
@ -195,7 +200,7 @@ int PS4_SYSV_ABI sceGnmUpdateGsShader();
|
|||
int PS4_SYSV_ABI sceGnmUpdateHsShader();
|
||||
int PS4_SYSV_ABI sceGnmUpdatePsShader();
|
||||
int PS4_SYSV_ABI sceGnmUpdatePsShader350();
|
||||
int PS4_SYSV_ABI sceGnmUpdateVsShader();
|
||||
int PS4_SYSV_ABI sceGnmUpdateVsShader(u32* cmd, u64 size, const u32* vs_regs, u32 shader_modifier);
|
||||
int PS4_SYSV_ABI sceGnmValidateCommandBuffers();
|
||||
int PS4_SYSV_ABI sceGnmValidateDisableDiagnostics();
|
||||
int PS4_SYSV_ABI sceGnmValidateDisableDiagnostics2();
|
||||
|
@ -260,4 +265,4 @@ int PS4_SYSV_ABI Func_E51D44DB8151238C();
|
|||
int PS4_SYSV_ABI Func_F916890425496553();
|
||||
|
||||
void RegisterlibSceGnmDriver(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::GnmDriver
|
||||
} // namespace Libraries::GnmDriver
|
15
src/core/libraries/kernel/cpu_management.cpp
Normal file
15
src/core/libraries/kernel/cpu_management.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/config.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/libraries/kernel/cpu_management.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
int PS4_SYSV_ABI sceKernelIsNeoMode() {
|
||||
LOG_INFO(Kernel_Sce, "called");
|
||||
return Config::isNeoMode();
|
||||
}
|
||||
|
||||
} // namespace Libraries::Kernel
|
12
src/core/libraries/kernel/cpu_management.h
Normal file
12
src/core/libraries/kernel/cpu_management.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
int PS4_SYSV_ABI sceKernelIsNeoMode();
|
||||
|
||||
} // namespace Libraries::Kernel
|
82
src/core/libraries/kernel/event_queue.cpp
Normal file
82
src/core/libraries/kernel/event_queue.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "core/libraries/kernel/event_queue.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
EqueueInternal::~EqueueInternal() = default;
|
||||
|
||||
int EqueueInternal::addEvent(const EqueueEvent& event) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
if (m_events.size() > 0) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
// TODO check if event is already exists and return it. Currently we just add in m_events array
|
||||
m_events.push_back(event);
|
||||
|
||||
if (event.isTriggered) {
|
||||
BREAKPOINT(); // we don't support that either yet
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EqueueInternal::waitForEvents(SceKernelEvent* ev, int num, u32 micros) {
|
||||
std::unique_lock lock{m_mutex};
|
||||
int ret = 0;
|
||||
|
||||
const auto predicate = [&] {
|
||||
ret = getTriggeredEvents(ev, num);
|
||||
return ret > 0;
|
||||
};
|
||||
|
||||
if (micros == 0) {
|
||||
m_cond.wait(lock, predicate);
|
||||
} else {
|
||||
m_cond.wait_for(lock, std::chrono::microseconds(micros), predicate);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool EqueueInternal::triggerEvent(u64 ident, s16 filter, void* trigger_data) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
if (m_events.size() > 1) {
|
||||
BREAKPOINT(); // we currently support one event
|
||||
}
|
||||
auto& event = m_events[0];
|
||||
|
||||
if (event.filter.trigger_event_func != nullptr) {
|
||||
event.filter.trigger_event_func(&event, trigger_data);
|
||||
} else {
|
||||
event.isTriggered = true;
|
||||
}
|
||||
|
||||
m_cond.notify_one();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) {
|
||||
int ret = 0;
|
||||
|
||||
if (m_events.size() > 1) {
|
||||
BREAKPOINT(); // we currently support one event
|
||||
}
|
||||
auto& event = m_events[0];
|
||||
|
||||
if (event.isTriggered) {
|
||||
ev[ret++] = event.event;
|
||||
|
||||
if (event.filter.reset_event_func != nullptr) {
|
||||
event.filter.reset_event_func(&event);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Libraries::Kernel
|
85
src/core/libraries/kernel/event_queue.h
Normal file
85
src/core/libraries/kernel/event_queue.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
constexpr s16 EVFILT_READ = -1;
|
||||
constexpr s16 EVFILT_WRITE = -2;
|
||||
constexpr s16 EVFILT_AIO = -3; // attached to aio requests
|
||||
constexpr s16 EVFILT_VNODE = -4; // attached to vnodes
|
||||
constexpr s16 EVFILT_PROC = -5; // attached to struct proc
|
||||
constexpr s16 EVFILT_SIGNAL = -6; // attached to struct proc
|
||||
constexpr s16 EVFILT_TIMER = -7; // timers
|
||||
constexpr s16 EVFILT_FS = -9; // filesystem events
|
||||
constexpr s16 EVFILT_LIO = -10; // attached to lio requests
|
||||
constexpr s16 EVFILT_USER = -11; // User events
|
||||
constexpr s16 EVFILT_POLLING = -12;
|
||||
constexpr s16 EVFILT_VIDEO_OUT = -13;
|
||||
constexpr s16 EVFILT_GRAPHICS_CORE = -14;
|
||||
constexpr s16 EVFILT_HRTIMER = -15;
|
||||
constexpr s16 EVFILT_UVD_TRAP = -16;
|
||||
constexpr s16 EVFILT_VCE_TRAP = -17;
|
||||
constexpr s16 EVFILT_SDMA_TRAP = -18;
|
||||
constexpr s16 EVFILT_REG_EV = -19;
|
||||
constexpr s16 EVFILT_GPU_EXCEPTION = -20;
|
||||
constexpr s16 EVFILT_GPU_SYSTEM_EXCEPTION = -21;
|
||||
constexpr s16 EVFILT_GPU_DBGGC_EV = -22;
|
||||
constexpr s16 EVFILT_SYSCOUNT = 22;
|
||||
|
||||
class EqueueInternal;
|
||||
struct EqueueEvent;
|
||||
|
||||
using TriggerFunc = void (*)(EqueueEvent* event, void* trigger_data);
|
||||
using ResetFunc = void (*)(EqueueEvent* event);
|
||||
using DeleteFunc = void (*)(EqueueInternal* eq, EqueueEvent* event);
|
||||
|
||||
struct SceKernelEvent {
|
||||
u64 ident = 0; /* identifier for this event */
|
||||
s16 filter = 0; /* filter for event */
|
||||
u16 flags = 0;
|
||||
u32 fflags = 0;
|
||||
s64 data = 0;
|
||||
void* udata = nullptr; /* opaque user data identifier */
|
||||
};
|
||||
|
||||
struct Filter {
|
||||
void* data = nullptr;
|
||||
TriggerFunc trigger_event_func = nullptr;
|
||||
ResetFunc reset_event_func = nullptr;
|
||||
DeleteFunc delete_event_func = nullptr;
|
||||
};
|
||||
|
||||
struct EqueueEvent {
|
||||
bool isTriggered = false;
|
||||
SceKernelEvent event;
|
||||
Filter filter;
|
||||
};
|
||||
|
||||
class EqueueInternal {
|
||||
public:
|
||||
EqueueInternal() = default;
|
||||
virtual ~EqueueInternal();
|
||||
void setName(const std::string& m_name) {
|
||||
this->m_name = m_name;
|
||||
}
|
||||
int addEvent(const EqueueEvent& event);
|
||||
int waitForEvents(SceKernelEvent* ev, int num, u32 micros);
|
||||
bool triggerEvent(u64 ident, s16 filter, void* trigger_data);
|
||||
int getTriggeredEvents(SceKernelEvent* ev, int num);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::mutex m_mutex;
|
||||
std::vector<EqueueEvent> m_events;
|
||||
std::condition_variable m_cond;
|
||||
};
|
||||
|
||||
} // namespace Libraries::Kernel
|
72
src/core/libraries/kernel/event_queues.cpp
Normal file
72
src/core/libraries/kernel/event_queues.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/kernel/event_queues.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) {
|
||||
if (eq == nullptr) {
|
||||
LOG_ERROR(Kernel_Event, "Event queue is null!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (name == nullptr) {
|
||||
LOG_ERROR(Kernel_Event, "Event queue name is invalid!");
|
||||
return SCE_KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
if (name == NULL) {
|
||||
LOG_ERROR(Kernel_Event, "Event queue name is null!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
// Maximum is 32 including null terminator
|
||||
static constexpr size_t MaxEventQueueNameSize = 32;
|
||||
if (std::strlen(name) > MaxEventQueueNameSize) {
|
||||
LOG_ERROR(Kernel_Event, "Event queue name exceeds 32 bytes!");
|
||||
return SCE_KERNEL_ERROR_ENAMETOOLONG;
|
||||
}
|
||||
|
||||
LOG_INFO(Kernel_Event, "name = {}", name);
|
||||
|
||||
*eq = new EqueueInternal;
|
||||
(*eq)->setName(std::string(name));
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int num, int* out,
|
||||
SceKernelUseconds* timo) {
|
||||
LOG_INFO(Kernel_Event, "num = {}", num);
|
||||
|
||||
if (eq == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
if (ev == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
|
||||
if (num < 1) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
if (timo == nullptr) { // wait until an event arrives without timing out
|
||||
*out = eq->waitForEvents(ev, num, 0);
|
||||
}
|
||||
|
||||
if (timo != nullptr) {
|
||||
// Only events that have already arrived at the time of this function call can be received
|
||||
if (*timo == 0) {
|
||||
UNREACHABLE();
|
||||
} else {
|
||||
// Wait until an event arrives with timing out
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
} // namespace Libraries::Kernel
|
17
src/core/libraries/kernel/event_queues.h
Normal file
17
src/core/libraries/kernel/event_queues.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/libraries/kernel/event_queue.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
using SceKernelUseconds = u32;
|
||||
using SceKernelEqueue = EqueueInternal*;
|
||||
|
||||
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name);
|
||||
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int num, int* out,
|
||||
SceKernelUseconds* timo);
|
||||
|
||||
} // namespace Libraries::Kernel
|
129
src/core/libraries/kernel/file_system.cpp
Normal file
129
src/core/libraries/kernel/file_system.cpp
Normal file
|
@ -0,0 +1,129 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/file_sys/fs.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/kernel/file_system.h"
|
||||
#include "core/libraries/libs.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
|
||||
LOG_INFO(Kernel_Fs, "path = {} flags = {:#x} mode = {:#x}", path, flags, mode);
|
||||
ASSERT_MSG(flags == 0, "flags!=0 not supported yet");
|
||||
ASSERT_MSG(mode == 0, "mode!=0 not supported yet");
|
||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
|
||||
|
||||
// only open files support!
|
||||
u32 handle = h->CreateHandle();
|
||||
auto* file = h->GetFile(handle);
|
||||
file->m_guest_name = path;
|
||||
file->m_host_name = mnt->GetHostFile(file->m_guest_name);
|
||||
|
||||
file->f.Open(file->m_host_name, Common::FS::FileAccessMode::Read);
|
||||
if (!file->f.IsOpen()) {
|
||||
h->DeleteHandle(handle);
|
||||
return SCE_KERNEL_ERROR_EACCES;
|
||||
}
|
||||
file->is_opened = true;
|
||||
return handle;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16 mode) {
|
||||
LOG_INFO(Kernel_Fs, "posix open redirect to sceKernelOpen\n");
|
||||
int result = sceKernelOpen(path, flags, mode);
|
||||
// Posix calls different only for their return values
|
||||
ASSERT(result >= 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelClose(int d) {
|
||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||
auto* file = h->GetFile(d);
|
||||
if (file == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EBADF;
|
||||
}
|
||||
if (!file->is_directory) {
|
||||
file->f.Close();
|
||||
}
|
||||
file->is_opened = false;
|
||||
LOG_INFO(Kernel_Fs, "Closing {}", file->m_guest_name);
|
||||
h->DeleteHandle(d);
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
size_t PS4_SYSV_ABI _readv(int d, const SceKernelIovec* iov, int iovcnt) {
|
||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||
auto* file = h->GetFile(d);
|
||||
size_t total_read = 0;
|
||||
file->m_mutex.lock();
|
||||
for (int i = 0; i < iovcnt; i++) {
|
||||
total_read += file->f.ReadRaw<u8>(iov[i].iov_base, iov[i].iov_len);
|
||||
}
|
||||
file->m_mutex.unlock();
|
||||
return total_read;
|
||||
}
|
||||
|
||||
s64 PS4_SYSV_ABI sceKernelLseek(int d, s64 offset, int whence) {
|
||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||
auto* file = h->GetFile(d);
|
||||
|
||||
file->m_mutex.lock();
|
||||
|
||||
if (whence == 1) {
|
||||
offset = static_cast<int64_t>(file->f.Tell()) + offset;
|
||||
whence = 0;
|
||||
}
|
||||
|
||||
if (whence == 2) {
|
||||
offset = static_cast<int64_t>(file->f.GetSize()) + offset;
|
||||
whence = 0;
|
||||
}
|
||||
|
||||
file->f.Seek(offset);
|
||||
auto pos = static_cast<int64_t>(file->f.Tell());
|
||||
|
||||
file->m_mutex.unlock();
|
||||
return pos;
|
||||
}
|
||||
|
||||
s64 PS4_SYSV_ABI lseek(int d, s64 offset, int whence) {
|
||||
return sceKernelLseek(d, offset, whence);
|
||||
}
|
||||
|
||||
s64 PS4_SYSV_ABI sceKernelRead(int d, void* buf, size_t nbytes) {
|
||||
if (buf == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
|
||||
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
|
||||
auto* file = h->GetFile(d);
|
||||
if (file == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EBADF;
|
||||
}
|
||||
file->m_mutex.lock();
|
||||
u32 bytes_read = file->f.ReadRaw<u8>(buf, static_cast<u32>(nbytes));
|
||||
file->m_mutex.unlock();
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
void fileSystemSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, sceKernelOpen);
|
||||
LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, posix_open);
|
||||
LIB_FUNCTION("UK2Tl2DWUns", "libkernel", 1, "libkernel", 1, 1, sceKernelClose);
|
||||
|
||||
LIB_FUNCTION("+WRlkKjZvag", "libkernel", 1, "libkernel", 1, 1, _readv);
|
||||
LIB_FUNCTION("Oy6IpwgtYOk", "libkernel", 1, "libkernel", 1, 1, lseek);
|
||||
LIB_FUNCTION("oib76F-12fk", "libkernel", 1, "libkernel", 1, 1, sceKernelLseek);
|
||||
LIB_FUNCTION("Cg4srZ6TKbU", "libkernel", 1, "libkernel", 1, 1, sceKernelRead);
|
||||
|
||||
// openOrbis (to check if it is valid out of OpenOrbis
|
||||
LIB_FUNCTION("6c3rCVE-fTU", "libkernel", 1, "libkernel", 1, 1,
|
||||
posix_open); // _open shoudld be equal to open function
|
||||
}
|
||||
|
||||
} // namespace Libraries::Kernel
|
26
src/core/libraries/kernel/file_system.h
Normal file
26
src/core/libraries/kernel/file_system.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
struct SceKernelIovec {
|
||||
void* iov_base;
|
||||
std::size_t iov_len;
|
||||
};
|
||||
|
||||
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
|
||||
int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
s64 PS4_SYSV_ABI lseek(int d, s64 offset, int whence);
|
||||
|
||||
void fileSystemSymbolsRegister(Core::Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Libraries::Kernel
|
189
src/core/libraries/kernel/libkernel.cpp
Normal file
189
src/core/libraries/kernel/libkernel.cpp
Normal file
|
@ -0,0 +1,189 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/kernel/cpu_management.h"
|
||||
#include "core/libraries/kernel/event_queues.h"
|
||||
#include "core/libraries/kernel/file_system.h"
|
||||
#include "core/libraries/kernel/libkernel.h"
|
||||
#include "core/libraries/kernel/memory_management.h"
|
||||
#include "core/libraries/kernel/thread_management.h"
|
||||
#include "core/libraries/kernel/time_management.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/linker.h"
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return
|
||||
|
||||
static void* PS4_SYSV_ABI sceKernelGetProcParam() {
|
||||
auto* linker = Common::Singleton<Core::Linker>::Instance();
|
||||
return reinterpret_cast<void*>(linker->GetProcParam());
|
||||
}
|
||||
|
||||
int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) {
|
||||
UNREACHABLE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PS4_SYSV_ABI void stack_chk_fail() {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI sceKernelUsleep(unsigned int microseconds) {
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
|
||||
}
|
||||
|
||||
struct iovec {
|
||||
void* iov_base; /* Base address. */
|
||||
size_t iov_len; /* Length. */
|
||||
};
|
||||
|
||||
size_t PS4_SYSV_ABI _writev(int fd, const struct iovec* iov, int iovcn) {
|
||||
// weird it gives fd ==0 and writes to stdout , i am not sure if it that is valid (found in
|
||||
// openorbis)
|
||||
size_t total_written = 0;
|
||||
for (int i = 0; i < iovcn; i++) {
|
||||
total_written += ::fwrite(iov[i].iov_base, 1, iov[i].iov_len, stdout);
|
||||
}
|
||||
return total_written;
|
||||
}
|
||||
|
||||
static thread_local int libc_error;
|
||||
int* PS4_SYSV_ABI __Error() {
|
||||
return &libc_error;
|
||||
}
|
||||
|
||||
#define PROT_READ 0x1
|
||||
#define PROT_WRITE 0x2
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMmap(void* addr, u64 len, int prot, int flags, int fd, off_t offset,
|
||||
void** res) {
|
||||
#ifdef _WIN64
|
||||
LOG_INFO(Kernel_Vmm, "called");
|
||||
if (prot > 3) {
|
||||
LOG_ERROR(Kernel_Vmm, "prot = {} not supported", prot);
|
||||
}
|
||||
DWORD flProtect;
|
||||
if (prot & PROT_WRITE) {
|
||||
flProtect = PAGE_READWRITE;
|
||||
}
|
||||
off_t end = len + offset;
|
||||
HANDLE mmap_fd, h;
|
||||
if (fd == -1)
|
||||
mmap_fd = INVALID_HANDLE_VALUE;
|
||||
else
|
||||
mmap_fd = (HANDLE)_get_osfhandle(fd);
|
||||
h = CreateFileMapping(mmap_fd, NULL, flProtect, 0, end, NULL);
|
||||
int k = GetLastError();
|
||||
if (NULL == h)
|
||||
return -1;
|
||||
DWORD dwDesiredAccess;
|
||||
if (prot & PROT_WRITE)
|
||||
dwDesiredAccess = FILE_MAP_WRITE;
|
||||
else
|
||||
dwDesiredAccess = FILE_MAP_READ;
|
||||
void* ret = MapViewOfFile(h, dwDesiredAccess, 0, offset, len);
|
||||
if (ret == NULL) {
|
||||
CloseHandle(h);
|
||||
ret = nullptr;
|
||||
}
|
||||
*res = ret;
|
||||
return 0;
|
||||
#else
|
||||
void* result = mmap(addr, len, prot, flags, fd, offset);
|
||||
if (result != MAP_FAILED) {
|
||||
*res = result;
|
||||
return 0;
|
||||
}
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
PS4_SYSV_ABI void* posix_mmap(void* addr, u64 len, int prot, int flags, int fd, u64 offset) {
|
||||
void* ptr;
|
||||
LOG_INFO(Kernel_Vmm, "posix mmap redirect to sceKernelMmap\n");
|
||||
// posix call the difference is that there is a different behaviour when it doesn't return 0 or
|
||||
// SCE_OK
|
||||
int result = sceKernelMmap(addr, len, prot, flags, fd, offset, &ptr);
|
||||
ASSERT(result == 0);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static uint64_t g_mspace_atomic_id_mask = 0;
|
||||
static uint64_t g_mstate_table[64] = {0};
|
||||
|
||||
struct HeapInfoInfo {
|
||||
uint64_t size = sizeof(HeapInfoInfo);
|
||||
uint32_t flag;
|
||||
uint32_t getSegmentInfo;
|
||||
uint64_t* mspace_atomic_id_mask;
|
||||
uint64_t* mstate_table;
|
||||
};
|
||||
|
||||
void PS4_SYSV_ABI sceLibcHeapGetTraceInfo(HeapInfoInfo* info) {
|
||||
info->mspace_atomic_id_mask = &g_mspace_atomic_id_mask;
|
||||
info->mstate_table = g_mstate_table;
|
||||
info->getSegmentInfo = 0;
|
||||
}
|
||||
|
||||
s64 PS4_SYSV_ABI ps4__write(int d, const void* buf, std::size_t nbytes) {
|
||||
if (d <= 2) { // stdin,stdout,stderr
|
||||
char* str = strdup((const char*)buf);
|
||||
if (str[nbytes - 1] == '\n')
|
||||
str[nbytes - 1] = 0;
|
||||
LOG_INFO(Tty, "{}", str);
|
||||
free(str);
|
||||
return nbytes;
|
||||
}
|
||||
LOG_ERROR(Kernel, "(STUBBED) called d = {} nbytes = {} ", d, nbytes);
|
||||
UNREACHABLE(); // normal write , is it a posix call??
|
||||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
void LibKernel_Register(Core::Loader::SymbolsResolver* sym) {
|
||||
// obj
|
||||
LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &g_stack_chk_guard);
|
||||
// memory
|
||||
LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory);
|
||||
LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetDirectMemorySize);
|
||||
LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, sceKernelMapDirectMemory);
|
||||
LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory);
|
||||
LIB_FUNCTION("cQke9UuBQOk", "libkernel", 1, "libkernel", 1, 1, sceKernelMunmap);
|
||||
// equeue
|
||||
LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue);
|
||||
LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, sceKernelWaitEqueue);
|
||||
// misc
|
||||
LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, sceKernelIsNeoMode);
|
||||
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);
|
||||
LIB_FUNCTION("9BcDykPmo1I", "libkernel", 1, "libkernel", 1, 1, __Error);
|
||||
LIB_FUNCTION("BPE9s9vQQXo", "libkernel", 1, "libkernel", 1, 1, posix_mmap);
|
||||
LIB_FUNCTION("1jfXLRVzisc", "libkernel", 1, "libkernel", 1, 1, sceKernelUsleep);
|
||||
LIB_FUNCTION("YSHRBRLn2pI", "libkernel", 1, "libkernel", 1, 1, _writev);
|
||||
LIB_FUNCTION("959qrazPIrg", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcParam);
|
||||
|
||||
Libraries::Kernel::fileSystemSymbolsRegister(sym);
|
||||
Libraries::Kernel::timeSymbolsRegister(sym);
|
||||
Libraries::Kernel::pthreadSymbolsRegister(sym);
|
||||
|
||||
// temp
|
||||
LIB_FUNCTION("NWtTN10cJzE", "libSceLibcInternalExt", 1, "libSceLibcInternal", 1, 1,
|
||||
sceLibcHeapGetTraceInfo);
|
||||
LIB_FUNCTION("FxVZqBAA7ks", "libkernel", 1, "libkernel", 1, 1, ps4__write);
|
||||
}
|
||||
|
||||
} // namespace Libraries::Kernel
|
20
src/core/libraries/kernel/libkernel.h
Normal file
20
src/core/libraries/kernel/libkernel.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len);
|
||||
int* PS4_SYSV_ABI __Error();
|
||||
|
||||
void LibKernel_Register(Core::Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Libraries::Kernel
|
125
src/core/libraries/kernel/memory_management.cpp
Normal file
125
src/core/libraries/kernel/memory_management.cpp
Normal file
|
@ -0,0 +1,125 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <bit>
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/PS4/GPU/gpu_memory.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/kernel/memory_management.h"
|
||||
#include "core/libraries/kernel/physical_memory.h"
|
||||
#include "core/virtual_memory.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
bool is16KBAligned(u64 n) {
|
||||
return ((n % (16ull * 1024) == 0));
|
||||
}
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
|
||||
LOG_WARNING(Kernel_Vmm, "called");
|
||||
return SCE_KERNEL_MAIN_DMEM_SIZE;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len,
|
||||
u64 alignment, int memoryType, s64* physAddrOut) {
|
||||
LOG_INFO(Kernel_Vmm,
|
||||
"searchStart = {:#x}, searchEnd = {:#x}, len = {:#x}, alignment = {:#x}, memoryType = "
|
||||
"{:#x}",
|
||||
searchStart, searchEnd, len, alignment, memoryType);
|
||||
|
||||
if (searchStart < 0 || searchEnd <= searchStart) {
|
||||
LOG_ERROR(Kernel_Vmm, "Provided address range is invalid!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
const bool is_in_range = (searchStart < len && searchEnd > len);
|
||||
if (len <= 0 || !is16KBAligned(len) || !is_in_range) {
|
||||
LOG_ERROR(Kernel_Vmm, "Provided address range is invalid!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if ((alignment != 0 || is16KBAligned(alignment)) && !std::has_single_bit(alignment)) {
|
||||
LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (physAddrOut == nullptr) {
|
||||
LOG_ERROR(Kernel_Vmm, "Result physical address pointer is null!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
u64 physical_addr = 0;
|
||||
auto* physical_memory = Common::Singleton<PhysicalMemory>::Instance();
|
||||
if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr,
|
||||
memoryType)) {
|
||||
LOG_CRITICAL(Kernel_Vmm, "Unable to allocate physical memory");
|
||||
return SCE_KERNEL_ERROR_EAGAIN;
|
||||
}
|
||||
*physAddrOut = static_cast<s64>(physical_addr);
|
||||
LOG_INFO(Kernel_Vmm, "physAddrOut = {:#x}", physical_addr);
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags,
|
||||
s64 directMemoryStart, u64 alignment) {
|
||||
LOG_INFO(
|
||||
Kernel_Vmm,
|
||||
"len = {:#x}, prot = {:#x}, flags = {:#x}, directMemoryStart = {:#x}, alignment = {:#x}",
|
||||
len, prot, flags, directMemoryStart, alignment);
|
||||
|
||||
if (len == 0 || !is16KBAligned(len)) {
|
||||
LOG_ERROR(Kernel_Vmm, "Map size is either zero or not 16KB aligned!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (!is16KBAligned(directMemoryStart)) {
|
||||
LOG_ERROR(Kernel_Vmm, "Start address is not 16KB aligned!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (alignment != 0) {
|
||||
if ((!std::has_single_bit(alignment) && !is16KBAligned(alignment))) {
|
||||
LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!");
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
VirtualMemory::MemoryMode cpu_mode = VirtualMemory::MemoryMode::NoAccess;
|
||||
GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess;
|
||||
|
||||
switch (prot) {
|
||||
case 0x03:
|
||||
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
|
||||
break;
|
||||
case 0x32:
|
||||
case 0x33: // SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL
|
||||
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
|
||||
gpu_mode = GPU::MemoryMode::ReadWrite;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
auto in_addr = reinterpret_cast<u64>(*addr);
|
||||
u64 out_addr = 0;
|
||||
|
||||
if (flags == 0) {
|
||||
out_addr = VirtualMemory::memory_alloc_aligned(in_addr, len, cpu_mode, alignment);
|
||||
}
|
||||
LOG_INFO(Kernel_Vmm, "in_addr = {:#x}, out_addr = {:#x}", in_addr, out_addr);
|
||||
|
||||
*addr = reinterpret_cast<void*>(out_addr); // return out_addr to first functions parameter
|
||||
|
||||
if (out_addr == 0) {
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
}
|
||||
|
||||
auto* physical_memory = Common::Singleton<PhysicalMemory>::Instance();
|
||||
if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
if (gpu_mode != GPU::MemoryMode::NoAccess) {
|
||||
GPU::memorySetAllocArea(out_addr, len);
|
||||
}
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
} // namespace Libraries::Kernel
|
39
src/core/libraries/kernel/memory_management.h
Normal file
39
src/core/libraries/kernel/memory_management.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB; // ~ 6GB
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
enum MemoryTypes : u32 {
|
||||
SCE_KERNEL_WB_ONION = 0, // write - back mode (Onion bus)
|
||||
SCE_KERNEL_WC_GARLIC = 3, // write - combining mode (Garlic bus)
|
||||
SCE_KERNEL_WB_GARLIC = 10 // write - back mode (Garlic bus)
|
||||
};
|
||||
|
||||
enum MemoryFlags : u32 {
|
||||
SCE_KERNEL_MAP_FIXED = 0x0010, // Fixed
|
||||
SCE_KERNEL_MAP_NO_OVERWRITE = 0x0080,
|
||||
SCE_KERNEL_MAP_NO_COALESCE = 0x400000
|
||||
};
|
||||
|
||||
enum MemoryProtection : u32 {
|
||||
SCE_KERNEL_PROT_CPU_READ = 0x01, // Permit reads from the CPU
|
||||
SCE_KERNEL_PROT_CPU_RW = 0x02, // Permit reads/writes from the CPU
|
||||
SCE_KERNEL_PROT_CPU_WRITE = 0x02, // Permit reads/writes from the CPU (same)
|
||||
SCE_KERNEL_PROT_GPU_READ = 0x10, // Permit reads from the GPU
|
||||
SCE_KERNEL_PROT_GPU_WRITE = 0x20, // Permit writes from the GPU
|
||||
SCE_KERNEL_PROT_GPU_RW = 0x30 // Permit reads/writes from the GPU
|
||||
};
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize();
|
||||
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len,
|
||||
u64 alignment, int memoryType, s64* physAddrOut);
|
||||
int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags,
|
||||
s64 directMemoryStart, u64 alignment);
|
||||
|
||||
} // namespace Libraries::Kernel
|
71
src/core/libraries/kernel/physical_memory.cpp
Normal file
71
src/core/libraries/kernel/physical_memory.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/libraries/kernel/physical_memory.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
static u64 AlignUp(u64 pos, u64 align) {
|
||||
return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos);
|
||||
}
|
||||
|
||||
bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut,
|
||||
int memoryType) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
u64 find_free_pos = 0;
|
||||
|
||||
// iterate through allocated blocked and find the next free position
|
||||
for (const auto& block : m_allocatedBlocks) {
|
||||
u64 n = block.start_addr + block.size;
|
||||
if (n > find_free_pos) {
|
||||
find_free_pos = n;
|
||||
}
|
||||
}
|
||||
|
||||
// align free position
|
||||
find_free_pos = AlignUp(find_free_pos, alignment);
|
||||
|
||||
// if the new position is between searchStart - searchEnd , allocate a new block
|
||||
if (find_free_pos >= searchStart && find_free_pos + len <= searchEnd) {
|
||||
AllocatedBlock block{};
|
||||
block.size = len;
|
||||
block.start_addr = find_free_pos;
|
||||
block.memoryType = memoryType;
|
||||
block.gpu_mode = GPU::MemoryMode::NoAccess;
|
||||
block.map_size = 0;
|
||||
block.map_virtual_addr = 0;
|
||||
block.prot = 0;
|
||||
block.cpu_mode = VirtualMemory::MemoryMode::NoAccess;
|
||||
|
||||
m_allocatedBlocks.push_back(block);
|
||||
|
||||
*physAddrOut = find_free_pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot,
|
||||
VirtualMemory::MemoryMode cpu_mode, GPU::MemoryMode gpu_mode) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
for (auto& b : m_allocatedBlocks) {
|
||||
if (phys_addr >= b.start_addr && phys_addr < b.start_addr + b.size) {
|
||||
if (b.map_virtual_addr != 0 || b.map_size != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
b.map_virtual_addr = virtual_addr;
|
||||
b.map_size = len;
|
||||
b.prot = prot;
|
||||
b.cpu_mode = cpu_mode;
|
||||
b.gpu_mode = gpu_mode;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Libraries::Kernel
|
40
src/core/libraries/kernel/physical_memory.h
Normal file
40
src/core/libraries/kernel/physical_memory.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include "common/types.h"
|
||||
#include "core/PS4/GPU/gpu_memory.h"
|
||||
#include "core/virtual_memory.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
class PhysicalMemory {
|
||||
public:
|
||||
struct AllocatedBlock {
|
||||
u64 start_addr;
|
||||
u64 size;
|
||||
int memoryType;
|
||||
u64 map_virtual_addr;
|
||||
u64 map_size;
|
||||
int prot;
|
||||
VirtualMemory::MemoryMode cpu_mode;
|
||||
GPU::MemoryMode gpu_mode;
|
||||
};
|
||||
PhysicalMemory() {}
|
||||
virtual ~PhysicalMemory() {}
|
||||
|
||||
public:
|
||||
bool Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut,
|
||||
int memoryType);
|
||||
bool Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, VirtualMemory::MemoryMode cpu_mode,
|
||||
GPU::MemoryMode gpu_mode);
|
||||
|
||||
private:
|
||||
std::vector<AllocatedBlock> m_allocatedBlocks;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
} // namespace Libraries::Kernel
|
935
src/core/libraries/kernel/thread_management.cpp
Normal file
935
src/core/libraries/kernel/thread_management.cpp
Normal file
|
@ -0,0 +1,935 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/kernel/thread_management.h"
|
||||
#include "core/libraries/libs.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
thread_local ScePthread g_pthread_self{};
|
||||
PThreadCxt* g_pthread_cxt = nullptr;
|
||||
|
||||
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);
|
||||
// default attr init
|
||||
ScePthreadAttr default_attr = nullptr;
|
||||
scePthreadAttrInit(&default_attr);
|
||||
g_pthread_cxt->SetDefaultAttr(default_attr);
|
||||
|
||||
g_pthread_cxt->SetPthreadPool(new PThreadPool);
|
||||
}
|
||||
|
||||
void pthreadInitSelfMainThread() {
|
||||
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) {
|
||||
*attr = new PthreadAttrInternal{};
|
||||
|
||||
int result = pthread_attr_init(&(*attr)->pth_attr);
|
||||
|
||||
(*attr)->affinity = 0x7f;
|
||||
(*attr)->guard_size = 0x1000;
|
||||
|
||||
SceKernelSchedParam param{};
|
||||
param.sched_priority = 700;
|
||||
|
||||
result = (result == 0 ? scePthreadAttrSetinheritsched(attr, 4) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetschedparam(attr, ¶m) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetschedpolicy(attr, SCHED_OTHER) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetdetachstate(attr, PTHREAD_CREATE_JOINABLE) : result);
|
||||
|
||||
switch (result) {
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrDestroy(ScePthreadAttr* attr) {
|
||||
|
||||
int result = pthread_attr_destroy(&(*attr)->pth_attr);
|
||||
|
||||
delete *attr;
|
||||
*attr = nullptr;
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetguardsize(ScePthreadAttr* attr, size_t guard_size) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
(*attr)->guard_size = guard_size;
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGetguardsize(const ScePthreadAttr* attr, size_t* guard_size) {
|
||||
if (guard_size == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
*guard_size = (*attr)->guard_size;
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGetinheritsched(const ScePthreadAttr* attr, int* inherit_sched) {
|
||||
|
||||
if (inherit_sched == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_attr_getinheritsched(&(*attr)->pth_attr, inherit_sched);
|
||||
|
||||
switch (*inherit_sched) {
|
||||
case PTHREAD_EXPLICIT_SCHED:
|
||||
*inherit_sched = 0;
|
||||
break;
|
||||
case PTHREAD_INHERIT_SCHED:
|
||||
*inherit_sched = 4;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGetdetachstate(const ScePthreadAttr* attr, int* state) {
|
||||
if (state == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
// int result = pthread_attr_getdetachstate(&(*attr)->p, state);
|
||||
int result = 0;
|
||||
|
||||
*state = ((*attr)->detached ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
switch (*state) {
|
||||
case PTHREAD_CREATE_JOINABLE:
|
||||
*state = 0;
|
||||
break;
|
||||
case PTHREAD_CREATE_DETACHED:
|
||||
*state = 1;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int pstate = PTHREAD_CREATE_JOINABLE;
|
||||
switch (detachstate) {
|
||||
case 0:
|
||||
pstate = PTHREAD_CREATE_JOINABLE;
|
||||
break;
|
||||
case 1:
|
||||
pstate = PTHREAD_CREATE_DETACHED;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE_MSG("Invalid detachstate: {}", detachstate);
|
||||
}
|
||||
|
||||
// int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); doesn't seem to work
|
||||
// correctly
|
||||
int result = 0;
|
||||
|
||||
(*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED);
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int pinherit_sched = PTHREAD_INHERIT_SCHED;
|
||||
switch (inheritSched) {
|
||||
case 0:
|
||||
pinherit_sched = PTHREAD_EXPLICIT_SCHED;
|
||||
break;
|
||||
case 4:
|
||||
pinherit_sched = PTHREAD_INHERIT_SCHED;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE_MSG("Invalid inheritSched: {}", inheritSched);
|
||||
}
|
||||
|
||||
int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched);
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGetschedparam(const ScePthreadAttr* attr,
|
||||
SceKernelSchedParam* param) {
|
||||
|
||||
if (param == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_attr_getschedparam(&(*attr)->pth_attr, param);
|
||||
|
||||
if (param->sched_priority <= -2) {
|
||||
param->sched_priority = 767;
|
||||
} else if (param->sched_priority >= +2) {
|
||||
param->sched_priority = 256;
|
||||
} else {
|
||||
param->sched_priority = 700;
|
||||
}
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr,
|
||||
const SceKernelSchedParam* param) {
|
||||
if (param == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
SceKernelSchedParam pparam{};
|
||||
if (param->sched_priority <= 478) {
|
||||
pparam.sched_priority = +2;
|
||||
} else if (param->sched_priority >= 733) {
|
||||
pparam.sched_priority = -2;
|
||||
} else {
|
||||
pparam.sched_priority = 0;
|
||||
}
|
||||
|
||||
int result = pthread_attr_setschedparam(&(*attr)->pth_attr, &pparam);
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGetschedpolicy(const ScePthreadAttr* attr, int* policy) {
|
||||
|
||||
if (policy == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_attr_getschedpolicy(&(*attr)->pth_attr, policy);
|
||||
|
||||
switch (*policy) {
|
||||
case SCHED_OTHER:
|
||||
*policy = (*attr)->policy;
|
||||
break;
|
||||
case SCHED_FIFO:
|
||||
*policy = 1;
|
||||
break;
|
||||
case SCHED_RR:
|
||||
*policy = 3;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int ppolicy = SCHED_OTHER; // winpthreads only supports SCHED_OTHER
|
||||
if (policy != SCHED_OTHER) {
|
||||
LOG_ERROR(Kernel_Pthread, "policy={} not supported by winpthreads\n", policy);
|
||||
}
|
||||
(*attr)->policy = policy;
|
||||
|
||||
int result = pthread_attr_setschedpolicy(&(*attr)->pth_attr, ppolicy);
|
||||
|
||||
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) {
|
||||
LOG_INFO(Kernel_Pthread, "called");
|
||||
|
||||
if (pattr == nullptr || *pattr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
(*pattr)->affinity = mask;
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGetaffinity(const ScePthreadAttr* pattr,
|
||||
/* SceKernelCpumask*/ u64* mask) {
|
||||
if (pattr == nullptr || *pattr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
*mask = (*pattr)->affinity;
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGetstackaddr(const ScePthreadAttr* attr, void** stack_addr) {
|
||||
|
||||
if (stack_addr == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_attr_getstackaddr(&(*attr)->pth_attr, stack_addr);
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGetstacksize(const ScePthreadAttr* attr, size_t* stack_size) {
|
||||
|
||||
if (stack_size == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_attr_getstacksize(&(*attr)->pth_attr, stack_size);
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetstackaddr(ScePthreadAttr* attr, void* addr) {
|
||||
|
||||
if (addr == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_attr_setstackaddr(&(*attr)->pth_attr, addr);
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrSetstacksize(ScePthreadAttr* attr, size_t stack_size) {
|
||||
|
||||
if (stack_size == 0 || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_attr_setstacksize(&(*attr)->pth_attr, stack_size);
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadSetaffinity(ScePthread thread, const /*SceKernelCpumask*/ u64 mask) {
|
||||
LOG_INFO(Kernel_Pthread, "called");
|
||||
|
||||
if (thread == nullptr) {
|
||||
return SCE_KERNEL_ERROR_ESRCH;
|
||||
}
|
||||
|
||||
auto result = scePthreadAttrSetaffinity(&thread->attr, mask);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void* createMutex(void* addr) {
|
||||
if (addr == nullptr || *static_cast<ScePthreadMutex*>(addr) != nullptr) {
|
||||
return addr;
|
||||
}
|
||||
auto vaddr = reinterpret_cast<u64>(addr);
|
||||
|
||||
std::string name = fmt::format("mutex{:#x}", vaddr);
|
||||
scePthreadMutexInit(static_cast<ScePthreadMutex*>(addr), nullptr, name.c_str());
|
||||
return addr;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr,
|
||||
const char* name) {
|
||||
if (mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
if (attr == nullptr) {
|
||||
attr = g_pthread_cxt->getDefaultMutexattr();
|
||||
}
|
||||
|
||||
*mutex = new PthreadMutexInternal{};
|
||||
if (name != nullptr) {
|
||||
(*mutex)->name = name;
|
||||
} else {
|
||||
(*mutex)->name = "nonameMutex";
|
||||
}
|
||||
|
||||
int result = pthread_mutex_init(&(*mutex)->pth_mutex, &(*attr)->pth_mutex_attr);
|
||||
|
||||
if (name != nullptr) {
|
||||
LOG_INFO(Kernel_Pthread, "name={}, result={}", 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 scePthreadMutexDestroy(ScePthreadMutex* mutex) {
|
||||
|
||||
if (mutex == nullptr || *mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_mutex_destroy(&(*mutex)->pth_mutex);
|
||||
|
||||
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result);
|
||||
|
||||
delete *mutex;
|
||||
*mutex = nullptr;
|
||||
|
||||
switch (result) {
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case EBUSY:
|
||||
return SCE_KERNEL_ERROR_EBUSY;
|
||||
case EINVAL:
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr) {
|
||||
*attr = new PthreadMutexattrInternal{};
|
||||
|
||||
int result = pthread_mutexattr_init(&(*attr)->pth_mutex_attr);
|
||||
|
||||
result = (result == 0 ? scePthreadMutexattrSettype(attr, 1) : result);
|
||||
result = (result == 0 ? scePthreadMutexattrSetprotocol(attr, 0) : result);
|
||||
|
||||
switch (result) {
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type) {
|
||||
int ptype = PTHREAD_MUTEX_DEFAULT;
|
||||
switch (type) {
|
||||
case 1:
|
||||
ptype = PTHREAD_MUTEX_ERRORCHECK;
|
||||
break;
|
||||
case 2:
|
||||
ptype = PTHREAD_MUTEX_RECURSIVE;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
ptype = PTHREAD_MUTEX_NORMAL;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE_MSG("Invalid type: {}", type);
|
||||
}
|
||||
|
||||
int result = pthread_mutexattr_settype(&(*attr)->pth_mutex_attr, ptype);
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int protocol) {
|
||||
int pprotocol = PTHREAD_PRIO_NONE;
|
||||
switch (protocol) {
|
||||
case 0:
|
||||
pprotocol = PTHREAD_PRIO_NONE;
|
||||
break;
|
||||
case 1:
|
||||
pprotocol = PTHREAD_PRIO_INHERIT;
|
||||
break;
|
||||
case 2:
|
||||
pprotocol = PTHREAD_PRIO_PROTECT;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE_MSG("Invalid protocol: {}", protocol);
|
||||
}
|
||||
|
||||
int result = 0; // pthread_mutexattr_setprotocol(&(*attr)->p, pprotocol); //it appears that
|
||||
// pprotocol has issues in winpthreads
|
||||
(*attr)->pprotocol = pprotocol;
|
||||
|
||||
return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
int PS4_SYSV_ABI scePthreadMutexLock(ScePthreadMutex* mutex) {
|
||||
mutex = static_cast<ScePthreadMutex*>(createMutex(mutex));
|
||||
|
||||
if (mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_mutex_lock(&(*mutex)->pth_mutex);
|
||||
if (result != 0) {
|
||||
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result);
|
||||
}
|
||||
switch (result) {
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case EAGAIN:
|
||||
return SCE_KERNEL_ERROR_EAGAIN;
|
||||
case EINVAL:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
case EDEADLK:
|
||||
return SCE_KERNEL_ERROR_EDEADLK;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
int PS4_SYSV_ABI scePthreadMutexUnlock(ScePthreadMutex* mutex) {
|
||||
mutex = static_cast<ScePthreadMutex*>(createMutex(mutex));
|
||||
if (mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_mutex_unlock(&(*mutex)->pth_mutex);
|
||||
if (result != 0) {
|
||||
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result);
|
||||
}
|
||||
switch (result) {
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
|
||||
case EINVAL:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
case EPERM:
|
||||
return SCE_KERNEL_ERROR_EPERM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadMutexattrDestroy(ScePthreadMutexattr* attr) {
|
||||
|
||||
int result = pthread_mutexattr_destroy(&(*attr)->pth_mutex_attr);
|
||||
|
||||
delete *attr;
|
||||
*attr = nullptr;
|
||||
|
||||
switch (result) {
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
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(Kernel_Pthread, "name={}, result={}", (*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) {
|
||||
LOG_INFO(Kernel_Pthread, "called");
|
||||
cond = static_cast<ScePthreadCond*>(createCond(cond));
|
||||
|
||||
if (cond == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_cond_broadcast(&(*cond)->cond);
|
||||
|
||||
LOG_INFO(Kernel_Pthread, "name={}, result={}", (*cond)->name, result);
|
||||
|
||||
return (result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL);
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr) {
|
||||
// LOG_INFO(Kernel_Pthread, "posix pthread_mutex_init redirect to scePthreadMutexInit");
|
||||
int result = scePthreadMutexInit(mutex, attr, nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI posix_pthread_mutex_lock(ScePthreadMutex* mutex) {
|
||||
// LOG_INFO(Kernel_Pthread, "posix pthread_mutex_lock redirect to scePthreadMutexLock");
|
||||
int result = scePthreadMutexLock(mutex);
|
||||
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;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI posix_pthread_mutex_unlock(ScePthreadMutex* mutex) {
|
||||
// LOG_INFO(Kernel_Pthread, "posix pthread_mutex_unlock redirect to scePthreadMutexUnlock");
|
||||
int result = scePthreadMutexUnlock(mutex);
|
||||
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;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI posix_pthread_cond_broadcast(ScePthreadCond* cond) {
|
||||
LOG_INFO(Kernel_Pthread,
|
||||
"posix posix_pthread_cond_broadcast redirect to scePthreadCondBroadcast");
|
||||
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;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, SceKernelTimespec* tp) {
|
||||
if (tp == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
clockid_t pclock_id = CLOCK_REALTIME;
|
||||
switch (clock_id) {
|
||||
case 0:
|
||||
pclock_id = CLOCK_REALTIME;
|
||||
break;
|
||||
case 13:
|
||||
case 4:
|
||||
pclock_id = CLOCK_MONOTONIC;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
timespec t{};
|
||||
int result = clock_gettime(pclock_id, &t);
|
||||
tp->tv_sec = t.tv_sec;
|
||||
tp->tv_nsec = t.tv_nsec;
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI clock_gettime(s32 clock_id, SceKernelTimespec* time) {
|
||||
int result = sceKernelClockGettime(clock_id, time);
|
||||
if (result < 0) {
|
||||
UNREACHABLE(); // TODO return posix error code
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceKernelNanosleep(const SceKernelTimespec* rqtp, SceKernelTimespec* rmtp) {
|
||||
|
||||
if (rqtp == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EFAULT;
|
||||
}
|
||||
|
||||
if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
u64 nanos = rqtp->tv_sec * 1000000000 + rqtp->tv_nsec;
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(nanos));
|
||||
if (rmtp != nullptr) {
|
||||
UNREACHABLE(); // not supported yet
|
||||
}
|
||||
return SCE_OK;
|
||||
}
|
||||
int PS4_SYSV_ABI nanosleep(const SceKernelTimespec* rqtp, SceKernelTimespec* rmtp) {
|
||||
int result = sceKernelNanosleep(rqtp, rmtp);
|
||||
if (result < 0) {
|
||||
UNREACHABLE(); // TODO return posix error code
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static int pthread_copy_attributes(ScePthreadAttr* dst, const ScePthreadAttr* src) {
|
||||
if (dst == nullptr || *dst == nullptr || src == nullptr || *src == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
u64 mask = 0;
|
||||
int state = 0;
|
||||
size_t guard_size = 0;
|
||||
int inherit_sched = 0;
|
||||
SceKernelSchedParam param = {};
|
||||
int policy = 0;
|
||||
void* stack_addr = nullptr;
|
||||
size_t stack_size = 0;
|
||||
|
||||
int result = 0;
|
||||
|
||||
result = (result == 0 ? scePthreadAttrGetaffinity(src, &mask) : result);
|
||||
result = (result == 0 ? scePthreadAttrGetdetachstate(src, &state) : result);
|
||||
result = (result == 0 ? scePthreadAttrGetguardsize(src, &guard_size) : result);
|
||||
result = (result == 0 ? scePthreadAttrGetinheritsched(src, &inherit_sched) : result);
|
||||
result = (result == 0 ? scePthreadAttrGetschedparam(src, ¶m) : result);
|
||||
result = (result == 0 ? scePthreadAttrGetschedpolicy(src, &policy) : result);
|
||||
result = (result == 0 ? scePthreadAttrGetstackaddr(src, &stack_addr) : result);
|
||||
result = (result == 0 ? scePthreadAttrGetstacksize(src, &stack_size) : result);
|
||||
|
||||
result = (result == 0 ? scePthreadAttrSetaffinity(dst, mask) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetdetachstate(dst, state) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetguardsize(dst, guard_size) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetinheritsched(dst, inherit_sched) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetschedparam(dst, ¶m) : result);
|
||||
result = (result == 0 ? scePthreadAttrSetschedpolicy(dst, policy) : result);
|
||||
if (stack_addr != nullptr) {
|
||||
result = (result == 0 ? scePthreadAttrSetstackaddr(dst, stack_addr) : result);
|
||||
}
|
||||
if (stack_size != 0) {
|
||||
result = (result == 0 ? scePthreadAttrSetstacksize(dst, stack_size) : result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrGet(ScePthread thread, ScePthreadAttr* attr) {
|
||||
if (thread == nullptr || attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
return pthread_copy_attributes(attr, &thread->attr);
|
||||
}
|
||||
|
||||
static void cleanup_thread(void* arg) {
|
||||
auto* thread = static_cast<ScePthread>(arg);
|
||||
thread->is_almost_done = true;
|
||||
}
|
||||
|
||||
static void* run_thread(void* arg) {
|
||||
auto* thread = static_cast<ScePthread>(arg);
|
||||
void* ret = nullptr;
|
||||
g_pthread_self = thread;
|
||||
pthread_cleanup_push(cleanup_thread, thread);
|
||||
thread->is_started = true;
|
||||
ret = thread->entry(thread->arg);
|
||||
pthread_cleanup_pop(1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePthreadCreate(ScePthread* thread, const ScePthreadAttr* attr,
|
||||
pthreadEntryFunc start_routine, void* arg, const char* name) {
|
||||
if (thread == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
auto* pthread_pool = g_pthread_cxt->GetPthreadPool();
|
||||
|
||||
if (attr == nullptr) {
|
||||
attr = g_pthread_cxt->GetDefaultAttr();
|
||||
}
|
||||
|
||||
*thread = pthread_pool->Create();
|
||||
|
||||
if ((*thread)->attr != nullptr) {
|
||||
scePthreadAttrDestroy(&(*thread)->attr);
|
||||
}
|
||||
|
||||
scePthreadAttrInit(&(*thread)->attr);
|
||||
|
||||
int result = pthread_copy_attributes(&(*thread)->attr, attr);
|
||||
|
||||
if (result == 0) {
|
||||
(*thread)->name = name;
|
||||
(*thread)->entry = start_routine;
|
||||
(*thread)->arg = arg;
|
||||
(*thread)->is_almost_done = false;
|
||||
(*thread)->is_detached = (*attr)->detached;
|
||||
(*thread)->is_started = false;
|
||||
|
||||
result = pthread_create(&(*thread)->pth, &(*attr)->pth_attr, run_thread, *thread);
|
||||
}
|
||||
|
||||
if (result == 0) {
|
||||
while (!(*thread)->is_started) {
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(1000));
|
||||
}
|
||||
}
|
||||
LOG_INFO(Kernel_Pthread, "thread create name = {}", (*thread)->name);
|
||||
|
||||
switch (result) {
|
||||
case 0:
|
||||
return SCE_OK;
|
||||
case ENOMEM:
|
||||
return SCE_KERNEL_ERROR_ENOMEM;
|
||||
case EAGAIN:
|
||||
return SCE_KERNEL_ERROR_EAGAIN;
|
||||
case EDEADLK:
|
||||
return SCE_KERNEL_ERROR_EDEADLK;
|
||||
case EPERM:
|
||||
return SCE_KERNEL_ERROR_EPERM;
|
||||
default:
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
ScePthread PThreadPool::Create() {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
for (auto* p : m_threads) {
|
||||
if (p->is_free) {
|
||||
p->is_free = false;
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
auto* ret = new PthreadInternal{};
|
||||
|
||||
ret->is_free = false;
|
||||
ret->is_detached = false;
|
||||
ret->is_almost_done = false;
|
||||
ret->attr = nullptr;
|
||||
|
||||
m_threads.push_back(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void PS4_SYSV_ABI scePthreadYield() {
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
void pthreadSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
|
||||
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("62KCwEMmzcM", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrDestroy);
|
||||
|
||||
LIB_FUNCTION("aI+OeCz8xrQ", "libkernel", 1, "libkernel", 1, 1, scePthreadSelf);
|
||||
LIB_FUNCTION("3qxgM4ezETA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetaffinity);
|
||||
LIB_FUNCTION("8+s5BzZjxSg", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGetaffinity);
|
||||
LIB_FUNCTION("x1X76arYMxU", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrGet);
|
||||
|
||||
LIB_FUNCTION("bt3CTBKmGyI", "libkernel", 1, "libkernel", 1, 1, scePthreadSetaffinity);
|
||||
LIB_FUNCTION("6UgtwV+0zb4", "libkernel", 1, "libkernel", 1, 1, scePthreadCreate);
|
||||
LIB_FUNCTION("T72hz6ffq08", "libkernel", 1, "libkernel", 1, 1, scePthreadYield);
|
||||
|
||||
// mutex calls
|
||||
LIB_FUNCTION("cmo1RIYva9o", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexInit);
|
||||
LIB_FUNCTION("2Of0f+3mhhE", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexDestroy);
|
||||
LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrInit);
|
||||
LIB_FUNCTION("smWEktiyyG0", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrDestroy);
|
||||
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);
|
||||
|
||||
LIB_FUNCTION("QBi7HCK03hw", "libkernel", 1, "libkernel", 1, 1, sceKernelClockGettime);
|
||||
LIB_FUNCTION("lLMT9vJAck0", "libkernel", 1, "libkernel", 1, 1, clock_gettime);
|
||||
LIB_FUNCTION("yS8U2TGCe1A", "libScePosix", 1, "libkernel", 1, 1, nanosleep);
|
||||
|
||||
// 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 Libraries::Kernel
|
172
src/core/libraries/kernel/thread_management.h
Normal file
172
src/core/libraries/kernel/thread_management.h
Normal file
|
@ -0,0 +1,172 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
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 SceKernelTimespec {
|
||||
int64_t tv_sec;
|
||||
int64_t tv_nsec;
|
||||
};
|
||||
|
||||
struct PthreadInternal {
|
||||
u8 reserved[4096];
|
||||
std::string name;
|
||||
pthread_t pth;
|
||||
ScePthreadAttr attr;
|
||||
pthreadEntryFunc entry;
|
||||
void* arg;
|
||||
std::atomic_bool is_started;
|
||||
std::atomic_bool is_detached;
|
||||
std::atomic_bool is_almost_done;
|
||||
std::atomic_bool is_free;
|
||||
};
|
||||
|
||||
struct PthreadAttrInternal {
|
||||
u8 reserved[64];
|
||||
u64 affinity;
|
||||
size_t guard_size;
|
||||
int policy;
|
||||
bool detached;
|
||||
pthread_attr_t pth_attr;
|
||||
};
|
||||
|
||||
struct PthreadMutexInternal {
|
||||
u8 reserved[256];
|
||||
std::string name;
|
||||
pthread_mutex_t pth_mutex;
|
||||
};
|
||||
|
||||
struct PthreadMutexattrInternal {
|
||||
u8 reserved[64];
|
||||
pthread_mutexattr_t pth_mutex_attr;
|
||||
int pprotocol;
|
||||
};
|
||||
|
||||
struct PthreadCondInternal {
|
||||
u8 reserved[256];
|
||||
std::string name;
|
||||
pthread_cond_t cond;
|
||||
};
|
||||
|
||||
struct PthreadCondAttrInternal {
|
||||
u8 reserved[64];
|
||||
pthread_condattr_t cond_attr;
|
||||
};
|
||||
|
||||
class PThreadPool {
|
||||
public:
|
||||
ScePthread Create();
|
||||
|
||||
private:
|
||||
std::vector<ScePthread> m_threads;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
ScePthreadAttr* GetDefaultAttr() {
|
||||
return &m_default_attr;
|
||||
}
|
||||
void SetDefaultAttr(ScePthreadAttr attr) {
|
||||
m_default_attr = attr;
|
||||
}
|
||||
PThreadPool* GetPthreadPool() {
|
||||
return m_pthread_pool;
|
||||
}
|
||||
void SetPthreadPool(PThreadPool* pool) {
|
||||
m_pthread_pool = pool;
|
||||
}
|
||||
|
||||
private:
|
||||
ScePthreadMutexattr m_default_mutexattr = nullptr;
|
||||
ScePthreadCondattr m_default_condattr = nullptr;
|
||||
ScePthreadAttr m_default_attr = nullptr;
|
||||
PThreadPool* m_pthread_pool = nullptr;
|
||||
};
|
||||
|
||||
void init_pthreads();
|
||||
void pthreadInitSelfMainThread();
|
||||
|
||||
int PS4_SYSV_ABI scePthreadAttrInit(ScePthreadAttr* attr);
|
||||
int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate);
|
||||
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
|
||||
*/
|
||||
int PS4_SYSV_ABI scePthreadMutexInit(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr,
|
||||
const char* name);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type);
|
||||
int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int protocol);
|
||||
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(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::Kernel
|
39
src/core/libraries/kernel/time_management.cpp
Normal file
39
src/core/libraries/kernel/time_management.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/native_clock.h"
|
||||
#include "core/libraries/kernel/time_management.h"
|
||||
#include "core/libraries/libs.h"
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
static u64 initial_ptc;
|
||||
static std::unique_ptr<Common::NativeClock> clock;
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTime() {
|
||||
return clock->GetProcessTimeUS();
|
||||
}
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter() {
|
||||
return clock->GetUptime() - initial_ptc;
|
||||
}
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency() {
|
||||
return clock->GetTscFrequency();
|
||||
}
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelReadTsc() {
|
||||
return clock->GetUptime();
|
||||
}
|
||||
|
||||
void timeSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
|
||||
clock = std::make_unique<Common::NativeClock>();
|
||||
initial_ptc = clock->GetUptime();
|
||||
LIB_FUNCTION("4J2sUJmuHZQ", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTime);
|
||||
LIB_FUNCTION("fgxnMeTNUtY", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounter);
|
||||
LIB_FUNCTION("BNowx2l588E", "libkernel", 1, "libkernel", 1, 1,
|
||||
sceKernelGetProcessTimeCounterFrequency);
|
||||
LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc);
|
||||
}
|
||||
|
||||
} // namespace Libraries::Kernel
|
21
src/core/libraries/kernel/time_management.h
Normal file
21
src/core/libraries/kernel/time_management.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Kernel {
|
||||
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTime();
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter();
|
||||
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency();
|
||||
u64 PS4_SYSV_ABI sceKernelReadTsc();
|
||||
|
||||
void timeSymbolsRegister(Core::Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Libraries::Kernel
|
493
src/core/libraries/libc/libc.cpp
Normal file
493
src/core/libraries/libc/libc.cpp
Normal file
|
@ -0,0 +1,493 @@
|
|||
// 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 Core::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(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);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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 Core::Libraries::LibC
|
14
src/core/libraries/libc/libc.h
Normal file
14
src/core/libraries/libc/libc.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
void libcSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
161
src/core/libraries/libc/libc_cxa.cpp
Normal file
161
src/core/libraries/libc/libc_cxa.cpp
Normal file
|
@ -0,0 +1,161 @@
|
|||
// 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 Core::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 Core::Libraries::LibC
|
15
src/core/libraries/libc/libc_cxa.h
Normal file
15
src/core/libraries/libc/libc_cxa.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
// 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 Core::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 Core::Libraries::LibC
|
41
src/core/libraries/libc/libc_math.cpp
Normal file
41
src/core/libraries/libc/libc_math.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cmath>
|
||||
#include "core/libraries/libc/libc_math.h"
|
||||
|
||||
namespace Core::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);
|
||||
}
|
||||
|
||||
double PS4_SYSV_ABI ps4__Sin(double x) {
|
||||
return sin(x);
|
||||
}
|
||||
|
||||
float PS4_SYSV_ABI ps4__Fsin(float arg) {
|
||||
return sinf(arg);
|
||||
}
|
||||
|
||||
double PS4_SYSV_ABI ps4_exp2(double arg) {
|
||||
return exp2(arg);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
19
src/core/libraries/libc/libc_math.h
Normal file
19
src/core/libraries/libc/libc_math.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::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);
|
||||
double PS4_SYSV_ABI ps4_exp2(double arg);
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
73
src/core/libraries/libc/libc_stdio.cpp
Normal file
73
src/core/libraries/libc/libc_stdio.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/file_sys/fs.h"
|
||||
#include "core/libraries/libc/libc_stdio.h"
|
||||
|
||||
namespace Core::Libraries::LibC {
|
||||
|
||||
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode) {
|
||||
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
|
||||
FILE* f = std::fopen(mnt->GetHostFile(filename).c_str(), mode);
|
||||
if (f != nullptr) {
|
||||
LOG_INFO(Lib_LibC, "fopen = {}", mnt->GetHostFile(filename).c_str());
|
||||
} else {
|
||||
LOG_INFO(Lib_LibC, "fopen can't open = {}", mnt->GetHostFile(filename).c_str());
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
22
src/core/libraries/libc/libc_stdio.h
Normal file
22
src/core/libraries/libc/libc_stdio.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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 Core::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);
|
||||
|
||||
} // namespace Core::Libraries::LibC
|
45
src/core/libraries/libc/libc_stdlib.cpp
Normal file
45
src/core/libraries/libc/libc_stdlib.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
// 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 Core::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 Core::Libraries::LibC
|
19
src/core/libraries/libc/libc_stdlib.h
Normal file
19
src/core/libraries/libc/libc_stdlib.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::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 Core::Libraries::LibC
|
61
src/core/libraries/libc/libc_string.cpp
Normal file
61
src/core/libraries/libc/libc_string.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
// 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 Core::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 Core::Libraries::LibC
|
24
src/core/libraries/libc/libc_string.h
Normal file
24
src/core/libraries/libc/libc_string.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::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 Core::Libraries::LibC
|
753
src/core/libraries/libc/printf.h
Normal file
753
src/core/libraries/libc/printf.h
Normal file
|
@ -0,0 +1,753 @@
|
|||
// 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 Core::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 Core::Libraries::LibC
|
110
src/core/libraries/libc/va_ctx.h
Normal file
110
src/core/libraries/libc/va_ctx.h
Normal file
|
@ -0,0 +1,110 @@
|
|||
// 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 Core::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 Core::Libraries::LibC
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,6 +0,0 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
// TODO placeholder until port finishes
|
||||
#include "core/hle/libraries/libs.h"
|
54
src/core/libraries/libs.cpp
Normal file
54
src/core/libraries/libs.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/config.h"
|
||||
#include "core/PS4/HLE/Graphics/video_out.h"
|
||||
#include "core/libraries/audio/audioin.h"
|
||||
#include "core/libraries/audio/audioout.h"
|
||||
#include "core/libraries/gnmdriver/gnmdriver.h"
|
||||
#include "core/libraries/kernel/libkernel.h"
|
||||
#include "core/libraries/libc/libc.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/network/http.h"
|
||||
#include "core/libraries/network/net.h"
|
||||
#include "core/libraries/network/netctl.h"
|
||||
#include "core/libraries/network/ssl.h"
|
||||
#include "core/libraries/pad/pad.h"
|
||||
#include "core/libraries/system/commondialog.h"
|
||||
#include "core/libraries/system/msgdialog.h"
|
||||
#include "core/libraries/system/posix.h"
|
||||
#include "core/libraries/system/savedata.h"
|
||||
#include "core/libraries/system/savedatadialog.h"
|
||||
#include "core/libraries/system/sysmodule.h"
|
||||
#include "core/libraries/system/systemservice.h"
|
||||
#include "core/libraries/system/userservice.h"
|
||||
|
||||
namespace Libraries {
|
||||
|
||||
void InitHLELibs(Core::Loader::SymbolsResolver* sym) {
|
||||
Libraries::Kernel::LibKernel_Register(sym);
|
||||
HLE::Libs::Graphics::VideoOut::videoOutRegisterLib(sym);
|
||||
Libraries::GnmDriver::RegisterlibSceGnmDriver(sym);
|
||||
Libraries::LibPad::padSymbolsRegister(sym);
|
||||
if (!Config::isLleLibc()) {
|
||||
Core::Libraries::LibC::libcSymbolsRegister(sym);
|
||||
}
|
||||
|
||||
// New libraries folder from autogen
|
||||
Libraries::UserService::RegisterlibSceUserService(sym);
|
||||
Libraries::SystemService::RegisterlibSceSystemService(sym);
|
||||
Libraries::CommonDialog::RegisterlibSceCommonDialog(sym);
|
||||
Libraries::MsgDialog::RegisterlibSceMsgDialog(sym);
|
||||
Libraries::AudioOut::RegisterlibSceAudioOut(sym);
|
||||
Libraries::Http::RegisterlibSceHttp(sym);
|
||||
Libraries::Net::RegisterlibSceNet(sym);
|
||||
Libraries::NetCtl::RegisterlibSceNetCtl(sym);
|
||||
Libraries::SaveData::RegisterlibSceSaveData(sym);
|
||||
Libraries::Ssl::RegisterlibSceSsl(sym);
|
||||
Libraries::SysModule::RegisterlibSceSysmodule(sym);
|
||||
Libraries::Posix::Registerlibsceposix(sym);
|
||||
Libraries::AudioIn::RegisterlibSceAudioIn(sym);
|
||||
Libraries::SaveDataDialog::RegisterlibSceSaveDataDialog(sym);
|
||||
}
|
||||
|
||||
} // namespace Libraries
|
41
src/core/libraries/libs.h
Normal file
41
src/core/libraries/libs.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/loader/elf.h"
|
||||
#include "core/loader/symbols_resolver.h"
|
||||
|
||||
#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
|
||||
{ \
|
||||
Core::Loader::SymbolResolver sr{}; \
|
||||
sr.name = nid; \
|
||||
sr.library = lib; \
|
||||
sr.library_version = libversion; \
|
||||
sr.module = mod; \
|
||||
sr.module_version_major = moduleVersionMajor; \
|
||||
sr.module_version_minor = moduleVersionMinor; \
|
||||
sr.type = Core::Loader::SymbolType::Function; \
|
||||
auto func = reinterpret_cast<u64>(function); \
|
||||
sym->AddSymbol(sr, func); \
|
||||
}
|
||||
|
||||
#define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
|
||||
{ \
|
||||
Core::Loader::SymbolResolver sr{}; \
|
||||
sr.name = nid; \
|
||||
sr.library = lib; \
|
||||
sr.library_version = libversion; \
|
||||
sr.module = mod; \
|
||||
sr.module_version_major = moduleVersionMajor; \
|
||||
sr.module_version_minor = moduleVersionMinor; \
|
||||
sr.type = Core::Loader::SymbolType::Object; \
|
||||
auto func = reinterpret_cast<u64>(function); \
|
||||
sym->AddSymbol(sr, func); \
|
||||
}
|
||||
|
||||
namespace Libraries {
|
||||
|
||||
void InitHLELibs(Core::Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Libraries
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscehttp.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/network/http.h"
|
||||
|
||||
namespace Libraries::Http {
|
||||
|
||||
|
@ -717,4 +717,4 @@ void RegisterlibSceHttp(Core::Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("qISjDHrxONc", "libSceHttp", 1, "libSceHttp", 1, 1, sceHttpWaitRequest);
|
||||
};
|
||||
|
||||
} // namespace Libraries::Http
|
||||
} // namespace Libraries::Http
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Http {
|
||||
|
||||
|
@ -124,4 +128,4 @@ int PS4_SYSV_ABI sceHttpUriUnescape();
|
|||
int PS4_SYSV_ABI sceHttpWaitRequest();
|
||||
|
||||
void RegisterlibSceHttp(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::Http
|
||||
} // namespace Libraries::Http
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscenet.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/network/net.h"
|
||||
|
||||
namespace Libraries::Net {
|
||||
|
||||
|
@ -1353,4 +1353,4 @@ void RegisterlibSceNet(Core::Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("pfn3Fha1ydc", "libSceNetDebug", 1, "libSceNet", 1, 1, sceNetEmulationSet);
|
||||
};
|
||||
|
||||
} // namespace Libraries::Net
|
||||
} // namespace Libraries::Net
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Net {
|
||||
|
||||
|
@ -228,4 +232,4 @@ int PS4_SYSV_ABI sceNetEmulationGet();
|
|||
int PS4_SYSV_ABI sceNetEmulationSet();
|
||||
|
||||
void RegisterlibSceNet(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::Net
|
||||
} // namespace Libraries::Net
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscenetctl.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/network/netctl.h"
|
||||
|
||||
namespace Libraries::NetCtl {
|
||||
|
||||
|
@ -633,4 +633,4 @@ void RegisterlibSceNetCtl(Core::Loader::SymbolsResolver* sym) {
|
|||
sceNetCtlApRpUnregisterCallback);
|
||||
};
|
||||
|
||||
} // namespace Libraries::NetCtl
|
||||
} // namespace Libraries::NetCtl
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::NetCtl {
|
||||
|
||||
|
@ -102,4 +106,4 @@ int PS4_SYSV_ABI sceNetCtlApRpStop();
|
|||
int PS4_SYSV_ABI sceNetCtlApRpUnregisterCallback();
|
||||
|
||||
void RegisterlibSceNetCtl(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::NetCtl
|
||||
} // namespace Libraries::NetCtl
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscessl.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/network/ssl.h"
|
||||
|
||||
namespace Libraries::Ssl {
|
||||
|
||||
|
@ -1283,4 +1283,4 @@ void RegisterlibSceSsl(Core::Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("KPh5GncdOcc", "libSceSsl", 1, "libSceSsl", 1, 1, Func_28F8791A771D39C7);
|
||||
};
|
||||
|
||||
} // namespace Libraries::Ssl
|
||||
} // namespace Libraries::Ssl
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Ssl {
|
||||
|
||||
|
@ -217,4 +221,4 @@ int PS4_SYSV_ABI Func_22E76E60BC0587D7();
|
|||
int PS4_SYSV_ABI Func_28F8791A771D39C7();
|
||||
|
||||
void RegisterlibSceSsl(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::Ssl
|
||||
} // namespace Libraries::Ssl
|
126
src/core/libraries/pad/pad.cpp
Normal file
126
src/core/libraries/pad/pad.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "Emulator/Host/controller.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/pad/pad.h"
|
||||
|
||||
namespace Libraries::LibPad {
|
||||
|
||||
int PS4_SYSV_ABI scePadInit() {
|
||||
LOG_WARNING(Lib_Pad, "(DUMMY) called");
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePadOpen(Libraries::UserService::OrbisUserServiceUserId user_id, s32 type,
|
||||
s32 index, const ScePadOpenParam* pParam) {
|
||||
LOG_INFO(Lib_Pad, "(DUMMY) called user_id = {} type = {} index = {}", user_id, type, index);
|
||||
return 1; // dummy
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) {
|
||||
auto* controller = Common::Singleton<Emulator::Host::Controller::GameController>::Instance();
|
||||
|
||||
int connectedCount = 0;
|
||||
bool isConnected = false;
|
||||
Emulator::Host::Controller::State state;
|
||||
|
||||
controller->readState(&state, &isConnected, &connectedCount);
|
||||
pData->buttons = state.buttonsState;
|
||||
pData->leftStick.x = 128; // dummy
|
||||
pData->leftStick.y = 128; // dummy
|
||||
pData->rightStick.x = 0; // dummy
|
||||
pData->rightStick.y = 0; // dummy
|
||||
pData->analogButtons.r2 = 0; // dummy
|
||||
pData->analogButtons.l2 = 0; // dummy
|
||||
pData->orientation.x = 0;
|
||||
pData->orientation.y = 0;
|
||||
pData->orientation.z = 0;
|
||||
pData->orientation.w = 0;
|
||||
pData->timestamp = state.time;
|
||||
pData->connected = true; // isConnected; //TODO fix me proper
|
||||
pData->connectedCount = 1; // connectedCount;
|
||||
pData->deviceUniqueDataLen = 0;
|
||||
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI scePadRead(int handle, ScePadData* pData, int num) {
|
||||
int connected_count = 0;
|
||||
bool connected = false;
|
||||
Emulator::Host::Controller::State states[64];
|
||||
auto* controller = Common::Singleton<Emulator::Host::Controller::GameController>::Instance();
|
||||
int ret_num = controller->ReadStates(states, num, &connected, &connected_count);
|
||||
|
||||
if (!connected) {
|
||||
ret_num = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ret_num; i++) {
|
||||
pData[i].buttons = states[i].buttonsState;
|
||||
pData[i].leftStick.x = 128; // dummy
|
||||
pData[i].leftStick.y = 128; // dummy
|
||||
pData[i].rightStick.x = 0; // dummy
|
||||
pData[i].rightStick.y = 0; // dummy
|
||||
pData[i].analogButtons.l2 = 0; // dummy
|
||||
pData[i].analogButtons.r2 = 0; // dummy
|
||||
pData[i].orientation.x = 0.0f;
|
||||
pData[i].orientation.y = 0.0f;
|
||||
pData[i].orientation.z = 0.0f;
|
||||
pData[i].orientation.w = 1.0f;
|
||||
pData[i].acceleration.x = 0.0f;
|
||||
pData[i].acceleration.y = 0.0f;
|
||||
pData[i].acceleration.z = 0.0f;
|
||||
pData[i].angularVelocity.x = 0.0f;
|
||||
pData[i].angularVelocity.y = 0.0f;
|
||||
pData[i].angularVelocity.z = 0.0f;
|
||||
pData[i].touchData.touchNum = 0;
|
||||
pData[i].touchData.touch[0].x = 0;
|
||||
pData[i].touchData.touch[0].y = 0;
|
||||
pData[i].touchData.touch[0].id = 1;
|
||||
pData[i].touchData.touch[1].x = 0;
|
||||
pData[i].touchData.touch[1].y = 0;
|
||||
pData[i].touchData.touch[1].id = 2;
|
||||
pData[i].connected = connected;
|
||||
pData[i].timestamp = states[i].time;
|
||||
pData[i].connectedCount = connected_count;
|
||||
pData[i].deviceUniqueDataLen = 0;
|
||||
}
|
||||
|
||||
return ret_num;
|
||||
}
|
||||
|
||||
s32 PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadInformation* info) {
|
||||
LOG_INFO(Lib_Pad, "called handle = {}", handle);
|
||||
info->touchpadDensity = 1;
|
||||
info->touchResolutionX = 1920;
|
||||
info->touchResolutionY = 950;
|
||||
info->stickDeadzoneL = 2;
|
||||
info->stickDeadzoneR = 2;
|
||||
info->connectionType = ORBIS_PAD_CONNECTION_TYPE_STANDARD;
|
||||
info->count = 1;
|
||||
info->connected = 1;
|
||||
info->deviceClass = ORBIS_PAD_PORT_TYPE_STANDARD;
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
s32 PS4_SYSV_ABI scePadSetMotionSensorState(s32 handle, bool enable) {
|
||||
LOG_INFO(Lib_Pad, "(DUMMY) called handle = {} enabled = {}", handle,
|
||||
(enable ? "true" : "false"));
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
void padSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit);
|
||||
LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen);
|
||||
LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState);
|
||||
LIB_FUNCTION("q1cHNfGycLI", "libScePad", 1, "libScePad", 1, 1, scePadRead);
|
||||
|
||||
LIB_FUNCTION("gjP9-KQzoUk", "libScePad", 1, "libScePad", 1, 1, scePadGetControllerInformation);
|
||||
LIB_FUNCTION("clVvL4ZDntw", "libScePad", 1, "libScePad", 1, 1, scePadSetMotionSensorState);
|
||||
}
|
||||
|
||||
} // namespace Libraries::LibPad
|
128
src/core/libraries/pad/pad.h
Normal file
128
src/core/libraries/pad/pad.h
Normal file
|
@ -0,0 +1,128 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/types.h"
|
||||
#include "src/core/libraries/system/userservice.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::LibPad {
|
||||
|
||||
constexpr s8 ORBIS_PAD_PORT_TYPE_STANDARD = 0;
|
||||
constexpr s8 ORBIS_PAD_PORT_TYPE_SPECIAL = 2;
|
||||
|
||||
constexpr s8 ORBIS_PAD_DEVICE_CLASS_PAD = 0;
|
||||
constexpr s8 ORBIS_PAD_DEVICE_CLASS_GUITAR = 1;
|
||||
constexpr s8 ORBIS_PAD_DEVICE_CLASS_DRUMS = 2;
|
||||
|
||||
constexpr s8 ORBIS_PAD_CONNECTION_TYPE_STANDARD = 0;
|
||||
constexpr s8 ORBIS_PAD_CONNECTION_TYPE_REMOTE = 2;
|
||||
|
||||
enum ScePadButton : u32 {
|
||||
L3 = 0x00000002,
|
||||
R3 = 0x00000004,
|
||||
OPTIONS = 0x00000008,
|
||||
UP = 0x00000010,
|
||||
RIGHT = 0x00000020,
|
||||
DOWN = 0x00000040,
|
||||
LEFT = 0x00000080,
|
||||
L2 = 0x00000100,
|
||||
R2 = 0x00000200,
|
||||
L1 = 0x00000400,
|
||||
R1 = 0x00000800,
|
||||
TRIANGLE = 0x00001000,
|
||||
CIRCLE = 0x00002000,
|
||||
CROSS = 0x00004000,
|
||||
SQUARE = 0x00008000,
|
||||
TOUCH_PAD = 0x00100000,
|
||||
INTERCEPTED = 0x80000000,
|
||||
};
|
||||
|
||||
struct ScePadOpenParam {
|
||||
u8 reserve[8];
|
||||
};
|
||||
|
||||
struct ScePadAnalogStick {
|
||||
u8 x;
|
||||
u8 y;
|
||||
};
|
||||
struct ScePadAnalogButtons {
|
||||
u8 l2;
|
||||
u8 r2;
|
||||
u8 padding[2];
|
||||
};
|
||||
|
||||
struct SceFQuaternion {
|
||||
float x, y, z, w;
|
||||
};
|
||||
|
||||
struct SceFVector3 {
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
struct ScePadTouch {
|
||||
u16 x;
|
||||
u16 y;
|
||||
u8 id;
|
||||
u8 reserve[3];
|
||||
};
|
||||
|
||||
constexpr int SCE_PAD_MAX_TOUCH_NUM = 2;
|
||||
|
||||
typedef struct ScePadTouchData {
|
||||
u8 touchNum;
|
||||
u8 reserve[3];
|
||||
u32 reserve1;
|
||||
ScePadTouch touch[SCE_PAD_MAX_TOUCH_NUM];
|
||||
} ScePadTouchData;
|
||||
|
||||
struct ScePadExtensionUnitData {
|
||||
u32 extensionUnitId;
|
||||
u8 reserve[1];
|
||||
u8 dataLength;
|
||||
u8 data[10];
|
||||
};
|
||||
|
||||
struct ScePadData {
|
||||
u32 buttons;
|
||||
ScePadAnalogStick leftStick;
|
||||
ScePadAnalogStick rightStick;
|
||||
ScePadAnalogButtons analogButtons;
|
||||
SceFQuaternion orientation;
|
||||
SceFVector3 acceleration;
|
||||
SceFVector3 angularVelocity;
|
||||
ScePadTouchData touchData;
|
||||
bool connected;
|
||||
u64 timestamp;
|
||||
ScePadExtensionUnitData extensionUnitData;
|
||||
uint8_t connectedCount;
|
||||
uint8_t reserve[2];
|
||||
uint8_t deviceUniqueDataLen;
|
||||
uint8_t deviceUniqueData[12];
|
||||
};
|
||||
|
||||
struct OrbisPadInformation {
|
||||
float touchpadDensity;
|
||||
u16 touchResolutionX;
|
||||
u16 touchResolutionY;
|
||||
u8 stickDeadzoneL;
|
||||
u8 stickDeadzoneR;
|
||||
u8 connectionType;
|
||||
u8 count;
|
||||
s8 connected;
|
||||
s8 deviceClass;
|
||||
u8 unknown[8];
|
||||
};
|
||||
|
||||
int PS4_SYSV_ABI scePadInit();
|
||||
int PS4_SYSV_ABI scePadOpen(Libraries::UserService::OrbisUserServiceUserId userId, s32 type,
|
||||
s32 index, const ScePadOpenParam* pParam);
|
||||
int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData);
|
||||
|
||||
void padSymbolsRegister(Core::Loader::SymbolsResolver* sym);
|
||||
|
||||
}; // namespace Libraries::LibPad
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscecommondialog.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/system/commondialog.h"
|
||||
|
||||
namespace Libraries::CommonDialog {
|
||||
|
||||
|
@ -207,4 +207,4 @@ void RegisterlibSceCommonDialog(Core::Loader::SymbolsResolver* sym) {
|
|||
Func_F2AEE270605622B0);
|
||||
};
|
||||
|
||||
} // namespace Libraries::CommonDialog
|
||||
} // namespace Libraries::CommonDialog
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::CommonDialog {
|
||||
|
||||
|
@ -43,4 +47,4 @@ int PS4_SYSV_ABI Func_CB18E00EFA946C64();
|
|||
int PS4_SYSV_ABI Func_F2AEE270605622B0();
|
||||
|
||||
void RegisterlibSceCommonDialog(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::CommonDialog
|
||||
} // namespace Libraries::CommonDialog
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscemsgdialog.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/system/msgdialog.h"
|
||||
|
||||
namespace Libraries::MsgDialog {
|
||||
|
||||
|
@ -82,4 +82,4 @@ void RegisterlibSceMsgDialog(Core::Loader::SymbolsResolver* sym) {
|
|||
sceMsgDialogUpdateStatus);
|
||||
};
|
||||
|
||||
} // namespace Libraries::MsgDialog
|
||||
} // namespace Libraries::MsgDialog
|
|
@ -3,8 +3,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "libscecommondialog.h"
|
||||
#include "common/types.h"
|
||||
#include "core/libraries/system/commondialog.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::MsgDialog {
|
||||
|
||||
|
@ -92,4 +96,4 @@ int PS4_SYSV_ABI sceMsgDialogTerminate();
|
|||
int PS4_SYSV_ABI sceMsgDialogUpdateStatus();
|
||||
|
||||
void RegisterlibSceMsgDialog(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::MsgDialog
|
||||
} // namespace Libraries::MsgDialog
|
|
@ -1,13 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libsceposix.h"
|
||||
#include "core/libraries/system/posix.h"
|
||||
|
||||
namespace Libraries::Posix {
|
||||
|
||||
void Registerlibsceposix(Core::Loader::SymbolsResolver* sym) {}
|
||||
|
||||
} // namespace Libraries::Posix
|
||||
} // namespace Libraries::Posix
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Posix {
|
||||
void Registerlibsceposix(Core::Loader::SymbolsResolver* sym);
|
|
@ -1,11 +1,11 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include <common/assert.h>
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscesavedata.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/system/savedata.h"
|
||||
|
||||
namespace Libraries::SaveData {
|
||||
|
||||
|
@ -657,4 +657,4 @@ void RegisterlibSceSaveData(Core::Loader::SymbolsResolver* sym) {
|
|||
LIB_FUNCTION("AuTE0gFxZCI", "libSceSaveData", 1, "libSceSaveData", 1, 1, Func_02E4C4D201716422);
|
||||
};
|
||||
|
||||
} // namespace Libraries::SaveData
|
||||
} // namespace Libraries::SaveData
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::SaveData {
|
||||
|
||||
|
@ -136,4 +140,4 @@ int PS4_SYSV_ABI sceSaveDataUpload();
|
|||
int PS4_SYSV_ABI Func_02E4C4D201716422();
|
||||
|
||||
void RegisterlibSceSaveData(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::SaveData
|
||||
} // namespace Libraries::SaveData
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscesavedatadialog.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/system/savedatadialog.h"
|
||||
|
||||
namespace Libraries::SaveDataDialog {
|
||||
|
||||
|
@ -81,4 +81,4 @@ void RegisterlibSceSaveDataDialog(Core::Loader::SymbolsResolver* sym) {
|
|||
sceSaveDataDialogUpdateStatus);
|
||||
};
|
||||
|
||||
} // namespace Libraries::SaveDataDialog
|
||||
} // namespace Libraries::SaveDataDialog
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::SaveDataDialog {
|
||||
|
||||
|
@ -19,4 +23,4 @@ int PS4_SYSV_ABI sceSaveDataDialogTerminate();
|
|||
int PS4_SYSV_ABI sceSaveDataDialogUpdateStatus();
|
||||
|
||||
void RegisterlibSceSaveDataDialog(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::SaveDataDialog
|
||||
} // namespace Libraries::SaveDataDialog
|
|
@ -1,13 +1,14 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#define MAGIC_ENUM_RANGE_MIN 0
|
||||
#define MAGIC_ENUM_RANGE_MAX 300
|
||||
#include <magic_enum.hpp>
|
||||
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscesysmodule.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/system/sysmodule.h"
|
||||
|
||||
namespace Libraries::SysModule {
|
||||
|
||||
|
@ -127,4 +128,4 @@ void RegisterlibSceSysmodule(Core::Loader::SymbolsResolver* sym) {
|
|||
sceSysmoduleUnloadModuleInternalWithArg);
|
||||
};
|
||||
|
||||
} // namespace Libraries::SysModule
|
||||
} // namespace Libraries::SysModule
|
|
@ -3,7 +3,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::SysModule {
|
||||
|
||||
|
@ -161,4 +165,4 @@ int PS4_SYSV_ABI sceSysmoduleUnloadModuleInternal();
|
|||
int PS4_SYSV_ABI sceSysmoduleUnloadModuleInternalWithArg();
|
||||
|
||||
void RegisterlibSceSysmodule(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::SysModule
|
||||
} // namespace Libraries::SysModule
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libscesystemservice.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/system/systemservice.h"
|
||||
|
||||
namespace Libraries::SystemService {
|
||||
|
||||
|
@ -3358,4 +3358,4 @@ void RegisterlibSceSystemService(Core::Loader::SymbolsResolver* sym) {
|
|||
"libSceSystemService", 1, 1, Func_CB5E885E225F69F0);
|
||||
};
|
||||
|
||||
} // namespace Libraries::SystemService
|
||||
} // namespace Libraries::SystemService
|
|
@ -4,7 +4,11 @@
|
|||
// https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/blob/master/include/orbis/_types/sys_service.h
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::SystemService {
|
||||
|
||||
|
@ -570,4 +574,4 @@ int PS4_SYSV_ABI Func_6B1CDB955F0EBD65();
|
|||
int PS4_SYSV_ABI Func_CB5E885E225F69F0();
|
||||
|
||||
void RegisterlibSceSystemService(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::SystemService
|
||||
} // namespace Libraries::SystemService
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Generated By moduleGenerator
|
||||
#include "common/logging/log.h"
|
||||
#include "error_codes.h"
|
||||
#include "libsceuserservice.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "core/libraries/system/userservice.h"
|
||||
|
||||
namespace Libraries::UserService {
|
||||
|
||||
|
@ -3010,4 +3010,4 @@ void RegisterlibSceUserService(Core::Loader::SymbolsResolver* sym) {
|
|||
1, sceUserServiceGetRegisteredUserIdList);
|
||||
};
|
||||
|
||||
} // namespace Libraries::UserService
|
||||
} // namespace Libraries::UserService
|
|
@ -4,7 +4,11 @@
|
|||
// https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/blob/master/include/orbis/_types/user.h
|
||||
#pragma once
|
||||
|
||||
#include "library_common.h"
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::UserService {
|
||||
|
||||
|
@ -478,4 +482,4 @@ int PS4_SYSV_ABI Func_BB9491DFE6B4953C();
|
|||
int PS4_SYSV_ABI Func_D2B814603E7B4477();
|
||||
|
||||
void RegisterlibSceUserService(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::UserService
|
||||
} // namespace Libraries::UserService
|
Loading…
Add table
Add a link
Reference in a new issue