commit
dde91c1c4d
|
@ -119,8 +119,8 @@ add_executable(shadps4
|
|||
src/core/hle/libraries/libkernel/libkernel.h
|
||||
src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp
|
||||
src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h
|
||||
src/core/hle/kernel/thread_management.cpp
|
||||
src/core/hle/kernel/thread_management.h
|
||||
src/core/hle/libraries/libkernel/thread_management.cpp
|
||||
src/core/hle/libraries/libkernel/thread_management.h
|
||||
src/core/hle/kernel/memory_management.cpp
|
||||
src/core/hle/kernel/memory_management.h
|
||||
src/core/hle/error_codes.h
|
||||
|
|
|
@ -1,13 +1,234 @@
|
|||
#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_ENOMEM = 0x8002000c; // Insufficient memory
|
||||
constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address pointer
|
||||
constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; // null or invalid states
|
||||
constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023; // Memory cannot be allocated
|
||||
constexpr int SCE_KERNEL_ERROR_ENAMETOOLONG = 0x8002003f; // character strings exceeds valid size
|
||||
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
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
#include "common/debug.h"
|
||||
#include "core/hle/kernel/thread_management.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
thread_local PthreadInternal g_pthread_self{};
|
||||
PThreadCxt* g_pthread_cxt = nullptr;
|
||||
|
||||
void Pthread_Init_Self_MainThread() {
|
||||
scePthreadAttrInit(&g_pthread_self.attr);
|
||||
g_pthread_self.pth = pthread_self();
|
||||
g_pthread_self.name = "Main_Thread";
|
||||
}
|
||||
|
||||
int 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 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: BREAKPOINT(); // unknown state
|
||||
}
|
||||
|
||||
int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate);
|
||||
|
||||
(*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED);
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int 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: BREAKPOINT(); // unknown inheritSched
|
||||
}
|
||||
|
||||
int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched);
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int 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);
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
|
||||
if (attr == nullptr || *attr == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
if (policy != SCHED_OTHER) {
|
||||
BREAKPOINT(); // invest if policy is other and if winpthreadlibrary support it
|
||||
}
|
||||
|
||||
(*attr)->policy = policy;
|
||||
|
||||
int result = pthread_attr_setschedpolicy(&(*attr)->pth_attr, policy);
|
||||
|
||||
if (result == 0) {
|
||||
return SCE_OK;
|
||||
}
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
} // namespace Core::Kernel
|
|
@ -1,42 +0,0 @@
|
|||
#pragma once
|
||||
#define _TIMESPEC_DEFINED
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include "common/types.h"
|
||||
#include <string>
|
||||
|
||||
namespace Core::Kernel {
|
||||
|
||||
struct PthreadAttrInternal;
|
||||
|
||||
using SceKernelSchedParam = ::sched_param;
|
||||
using ScePthreadAttr = PthreadAttrInternal*;
|
||||
|
||||
struct PthreadInternal {
|
||||
u08 reserved[4096];
|
||||
std::string name;
|
||||
pthread_t pth;
|
||||
ScePthreadAttr attr;
|
||||
};
|
||||
|
||||
struct PthreadAttrInternal {
|
||||
u08 reserved[64];
|
||||
u64 affinity;
|
||||
size_t guard_size;
|
||||
int policy;
|
||||
bool detached;
|
||||
pthread_attr_t pth_attr;
|
||||
};
|
||||
|
||||
class PThreadCxt {};
|
||||
|
||||
void Pthread_Init_Self_MainThread();
|
||||
|
||||
int scePthreadAttrInit(ScePthreadAttr* attr);
|
||||
int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate);
|
||||
int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched);
|
||||
int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param);
|
||||
int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy);
|
||||
|
||||
} // namespace Core::Kernel
|
|
@ -1,19 +1,21 @@
|
|||
#include "common/log.h"
|
||||
#include "core/hle/libraries/libkernel/libkernel.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "core/loader/elf.h"
|
||||
#include "core/hle/kernel/Objects/physical_memory.h"
|
||||
#include "core/hle/kernel/cpu_management.h"
|
||||
#include "core/hle/kernel/event_queues.h"
|
||||
#include "core/hle/kernel/memory_management.h"
|
||||
#include "core/hle/libraries/libkernel/libkernel.h"
|
||||
#include "core/hle/libraries/libkernel/file_system.h"
|
||||
#include "core/hle/libraries/libkernel/time_management.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/loader/elf.h"
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "thread_management.h"
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
|
@ -24,13 +26,12 @@ int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static PS4_SYSV_ABI void stack_chk_fail() {
|
||||
BREAKPOINT();
|
||||
}
|
||||
static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); }
|
||||
|
||||
int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
|
||||
BREAKPOINT();
|
||||
}
|
||||
int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { BREAKPOINT(); }
|
||||
|
||||
static thread_local int libc_error;
|
||||
int* PS4_SYSV_ABI __Error() { return &libc_error; }
|
||||
|
||||
void LibKernel_Register(Loader::SymbolsResolver* sym) {
|
||||
// obj
|
||||
|
@ -47,9 +48,11 @@ void LibKernel_Register(Loader::SymbolsResolver* sym) {
|
|||
// misc
|
||||
LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelIsNeoMode);
|
||||
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);
|
||||
|
||||
LIB_FUNCTION("9BcDykPmo1I", "libkernel", 1, "libkernel", 1, 1, __Error);
|
||||
|
||||
Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym);
|
||||
Core::Libraries::LibKernel::timeSymbolsRegister(sym);
|
||||
Core::Libraries::LibKernel::pthreadSymbolsRegister(sym);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
|
@ -10,7 +11,8 @@ class SymbolsResolver;
|
|||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len);
|
||||
int* PS4_SYSV_ABI __Error();
|
||||
|
||||
void LibKernel_Register(Loader::SymbolsResolver* sym);
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
} // namespace Core::Libraries::LibKernel
|
||||
|
|
|
@ -0,0 +1,300 @@
|
|||
#include "core/hle/libraries/libkernel/thread_management.h"
|
||||
|
||||
#include <core/hle/libraries/libs.h>
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
thread_local PthreadInternal g_pthread_self{};
|
||||
PThreadCxt* g_pthread_cxt = nullptr;
|
||||
|
||||
constexpr bool log_pthread_file = true; // disable it to disable logging
|
||||
|
||||
void init_pthreads() {
|
||||
g_pthread_cxt = new PThreadCxt{};
|
||||
ScePthreadMutexattr default_mutexattr = nullptr;
|
||||
scePthreadMutexattrInit(&default_mutexattr);
|
||||
g_pthread_cxt->setDefaultMutexattr(default_mutexattr);
|
||||
}
|
||||
|
||||
void pthreadInitSelfMainThread() {
|
||||
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 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: LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetdetachstate invalid detachstate: {}\n", detachstate); std::exit(0);
|
||||
}
|
||||
|
||||
int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate);
|
||||
|
||||
(*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: LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetinheritsched invalid inheritSched: {}\n", inheritSched); std::exit(0);
|
||||
}
|
||||
|
||||
int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched);
|
||||
|
||||
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 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_TRACE_IF(log_pthread_file, "scePthreadAttrSetschedpolicy 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;
|
||||
}
|
||||
|
||||
/****
|
||||
* Mutex calls
|
||||
*/
|
||||
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) {
|
||||
PRINT_FUNCTION_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 = "noname";
|
||||
}
|
||||
|
||||
int result = pthread_mutex_init(&(*mutex)->pth_mutex, &(*attr)->pth_mutex_attr);
|
||||
|
||||
if (name != nullptr) {
|
||||
LOG_INFO_IF(log_pthread_file, "mutex_init name={},result={}\n", 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 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: LOG_TRACE_IF(log_pthread_file, "scePthreadMutexattrSettype invalid type: {}\n", type); std::exit(0);
|
||||
}
|
||||
|
||||
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: LOG_TRACE_IF(log_pthread_file, "scePthreadMutexattrSetprotocol invalid protocol: {}\n", protocol); std::exit(0);
|
||||
}
|
||||
|
||||
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) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
mutex = static_cast<ScePthreadMutex*>(createMutex(mutex));
|
||||
|
||||
if (mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_mutex_lock(&(*mutex)->pth_mutex);
|
||||
LOG_INFO_IF(log_pthread_file, "scePthreadMutexLock name={} result={}\n", (*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) {
|
||||
PRINT_FUNCTION_NAME();
|
||||
mutex = static_cast<ScePthreadMutex*>(createMutex(mutex));
|
||||
if (mutex == nullptr) {
|
||||
return SCE_KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
|
||||
int result = pthread_mutex_unlock(&(*mutex)->pth_mutex);
|
||||
LOG_INFO_IF(log_pthread_file, "scePthreadMutexUnlock name={} result={}\n", (*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 posix_pthread_mutex_init(ScePthreadMutex* mutex, const ScePthreadMutexattr* attr) {
|
||||
LOG_INFO_IF(log_pthread_file, "posix pthread_mutex_init redirect to scePthreadMutexInit\n");
|
||||
int result = scePthreadMutexInit(mutex, attr, nullptr);
|
||||
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_IF(log_pthread_file, "posix pthread_mutex_lock redirect to scePthreadMutexLock\n");
|
||||
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_IF(log_pthread_file, "posix pthread_mutex_unlock redirect to scePthreadMutexUnlock\n");
|
||||
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;
|
||||
}
|
||||
|
||||
void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("cmo1RIYva9o", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexInit);
|
||||
LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrInit);
|
||||
LIB_FUNCTION("iMp8QpE+XO4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSettype);
|
||||
LIB_FUNCTION("1FGvU0i9saQ", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSetprotocol);
|
||||
LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy);
|
||||
LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate);
|
||||
LIB_FUNCTION("eXbUSpEaTsA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetinheritsched);
|
||||
LIB_FUNCTION("DzES9hQF4f4", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedparam);
|
||||
LIB_FUNCTION("nsYoNRywwNg", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrInit);
|
||||
LIB_FUNCTION("9UK1vLZQft4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexLock);
|
||||
LIB_FUNCTION("tn3VlD0hG60", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexUnlock);
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
} // namespace Core::Libraries::LibKernel
|
|
@ -0,0 +1,89 @@
|
|||
#pragma once
|
||||
#define _TIMESPEC_DEFINED
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Core::Libraries::LibKernel {
|
||||
|
||||
struct PthreadAttrInternal;
|
||||
struct PthreadMutexInternal;
|
||||
struct PthreadMutexattrInternal;
|
||||
|
||||
using SceKernelSchedParam = ::sched_param;
|
||||
using ScePthreadAttr = PthreadAttrInternal*;
|
||||
using ScePthreadMutex = PthreadMutexInternal*;
|
||||
using ScePthreadMutexattr = PthreadMutexattrInternal*;
|
||||
|
||||
struct PthreadInternal {
|
||||
u08 reserved[4096];
|
||||
std::string name;
|
||||
pthread_t pth;
|
||||
ScePthreadAttr attr;
|
||||
};
|
||||
|
||||
struct PthreadAttrInternal {
|
||||
u08 reserved[64];
|
||||
u64 affinity;
|
||||
size_t guard_size;
|
||||
int policy;
|
||||
bool detached;
|
||||
pthread_attr_t pth_attr;
|
||||
};
|
||||
|
||||
struct PthreadMutexInternal {
|
||||
u08 reserved[256];
|
||||
std::string name;
|
||||
pthread_mutex_t pth_mutex;
|
||||
};
|
||||
|
||||
struct PthreadMutexattrInternal {
|
||||
u08 reserved[64];
|
||||
pthread_mutexattr_t pth_mutex_attr;
|
||||
int pprotocol;
|
||||
};
|
||||
|
||||
class PThreadCxt {
|
||||
public:
|
||||
ScePthreadMutexattr* getDefaultMutexattr() { return &m_default_mutexattr; }
|
||||
void setDefaultMutexattr(ScePthreadMutexattr attr) { m_default_mutexattr = attr; }
|
||||
|
||||
private:
|
||||
ScePthreadMutexattr m_default_mutexattr = 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);
|
||||
|
||||
/***
|
||||
* 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);
|
||||
/****
|
||||
* 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);
|
||||
|
||||
void pthreadSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
} // namespace Core::Libraries::LibKernel
|
|
@ -1,7 +1,8 @@
|
|||
#include "core/hle/libraries/libsystemservice/system_service.h"
|
||||
|
||||
#include "common/log.h"
|
||||
#include "core/hle/error_codes.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/hle/libraries/libsystemservice/system_service.h"
|
||||
|
||||
namespace Core::Libraries::LibSystemService {
|
||||
|
||||
|
@ -10,9 +11,21 @@ s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen() {
|
|||
return SCE_OK;
|
||||
}
|
||||
|
||||
void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1,
|
||||
sceSystemServiceHideSplashScreen);
|
||||
s32 PS4_SYSV_ABI sceSystemServiceGetStatus(SceSystemServiceStatus* status) {
|
||||
SceSystemServiceStatus st = {};
|
||||
st.eventNum = 0;
|
||||
st.isSystemUiOverlaid = false;
|
||||
st.isInBackgroundExecution = false;
|
||||
st.isCpuMode7CpuNormal = true;
|
||||
st.isGameLiveStreamingOnAir = false;
|
||||
st.isOutOfVrPlayArea = false;
|
||||
*status = st;
|
||||
return SCE_OK;
|
||||
}
|
||||
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1, sceSystemServiceHideSplashScreen);
|
||||
LIB_FUNCTION("rPo6tV8D9bM", "libSceSystemService", 1, "libSceSystemService", 1, 1, sceSystemServiceGetStatus);
|
||||
}
|
||||
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
|
|
|
@ -8,8 +8,19 @@ class SymbolsResolver;
|
|||
|
||||
namespace Core::Libraries::LibSystemService {
|
||||
|
||||
struct SceSystemServiceStatus {
|
||||
s32 eventNum;
|
||||
bool isSystemUiOverlaid;
|
||||
bool isInBackgroundExecution;
|
||||
bool isCpuMode7CpuNormal;
|
||||
bool isGameLiveStreamingOnAir;
|
||||
bool isOutOfVrPlayArea;
|
||||
u08 reserved[];
|
||||
};
|
||||
|
||||
s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen();
|
||||
s32 PS4_SYSV_ABI sceSystemServiceGetStatus(SceSystemServiceStatus* status);
|
||||
|
||||
void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym);
|
||||
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
}; // namespace Core::Libraries::LibSystemService
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "common/string_util.h"
|
||||
#include "core/aerolib/aerolib.h"
|
||||
#include "core/aerolib/stubs.h"
|
||||
#include "core/hle/kernel/thread_management.h"
|
||||
#include "core/hle/libraries/libkernel/thread_management.h"
|
||||
#include "core/linker.h"
|
||||
#include "core/virtual_memory.h"
|
||||
|
||||
|
@ -654,7 +654,7 @@ static void run_main_entry(u64 addr, EntryParams* params, exit_func_t exit_func)
|
|||
}
|
||||
|
||||
void Linker::Execute() {
|
||||
Core::Kernel::Pthread_Init_Self_MainThread();
|
||||
Core::Libraries::LibKernel::pthreadInitSelfMainThread();
|
||||
EntryParams p{};
|
||||
p.argc = 1;
|
||||
p.argv[0] = "eboot.bin"; //hmm should be ok?
|
||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -1,19 +1,22 @@
|
|||
#include <cstdio>
|
||||
#include <cinttypes>
|
||||
#include <thread>
|
||||
#include <fmt/core.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <Zydis/Zydis.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
|
||||
#include "Util/config.h"
|
||||
#include "common/discord.h"
|
||||
#include "common/types.h"
|
||||
#include "common/log.h"
|
||||
#include "common/singleton.h"
|
||||
#include "common/types.h"
|
||||
#include "core/PS4/HLE/Graphics/video_out.h"
|
||||
#include "Util/config.h"
|
||||
#include "emulator.h"
|
||||
#include "core/hle/libraries/libs.h"
|
||||
#include "core/linker.h"
|
||||
#include "emuTimer.h"
|
||||
#include "emulator.h"
|
||||
#include <core/hle/libraries/libkernel/thread_management.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc == 1) {
|
||||
|
@ -22,6 +25,7 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
Config::load("config.toml");
|
||||
Common::Log::Init(true);
|
||||
Core::Libraries::LibKernel::init_pthreads();
|
||||
auto width = Config::getScreenWidth();
|
||||
auto height = Config::getScreenHeight();
|
||||
Emu::emuInit(width, height);
|
||||
|
@ -34,11 +38,7 @@ int main(int argc, char* argv[]) {
|
|||
auto linker = Common::Singleton<Core::Linker>::Instance();
|
||||
Core::Libraries::InitHLELibs(&linker->getHLESymbols());
|
||||
linker->LoadModule(path);
|
||||
std::jthread mainthread(
|
||||
[linker](std::stop_token stop_token, void*) {
|
||||
linker->Execute();
|
||||
},
|
||||
nullptr);
|
||||
std::jthread mainthread([linker](std::stop_token stop_token, void*) { linker->Execute(); }, nullptr);
|
||||
Discord::RPC discordRPC;
|
||||
discordRPC.init();
|
||||
discordRPC.update(Discord::RPCStatus::Idling, "");
|
||||
|
|
Loading…
Reference in New Issue