Skip to content

Commit 872d9d8

Browse files
committed
Revert "The way to Unity, pt.3 (shadps4-emu#1681)"
This reverts commit fea2593.
1 parent 6f82b09 commit 872d9d8

File tree

17 files changed

+50
-256
lines changed

17 files changed

+50
-256
lines changed

src/common/ntapi.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ NtClose_t NtClose = nullptr;
99
NtSetInformationFile_t NtSetInformationFile = nullptr;
1010
NtCreateThread_t NtCreateThread = nullptr;
1111
NtTerminateThread_t NtTerminateThread = nullptr;
12-
NtQueueApcThreadEx_t NtQueueApcThreadEx = nullptr;
1312

1413
namespace Common::NtApi {
1514

@@ -22,7 +21,6 @@ void Initialize() {
2221
(NtSetInformationFile_t)GetProcAddress(nt_handle, "NtSetInformationFile");
2322
NtCreateThread = (NtCreateThread_t)GetProcAddress(nt_handle, "NtCreateThread");
2423
NtTerminateThread = (NtTerminateThread_t)GetProcAddress(nt_handle, "NtTerminateThread");
25-
NtQueueApcThreadEx = (NtQueueApcThreadEx_t)GetProcAddress(nt_handle, "NtQueueApcThreadEx");
2624
}
2725

2826
} // namespace Common::NtApi

src/common/ntapi.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -509,20 +509,6 @@ typedef struct _TEB { /* win32/win64 */
509509
static_assert(offsetof(TEB, DeallocationStack) ==
510510
0x1478); /* The only member we care about at the moment */
511511

512-
typedef enum _QUEUE_USER_APC_FLAGS {
513-
QueueUserApcFlagsNone,
514-
QueueUserApcFlagsSpecialUserApc,
515-
QueueUserApcFlagsMaxValue
516-
} QUEUE_USER_APC_FLAGS;
517-
518-
typedef union _USER_APC_OPTION {
519-
ULONG_PTR UserApcFlags;
520-
HANDLE MemoryReserveHandle;
521-
} USER_APC_OPTION, *PUSER_APC_OPTION;
522-
523-
using PPS_APC_ROUTINE = void (*)(PVOID ApcArgument1, PVOID ApcArgument2, PVOID ApcArgument3,
524-
PCONTEXT Context);
525-
526512
typedef u64(__stdcall* NtClose_t)(HANDLE Handle);
527513

528514
typedef u64(__stdcall* NtSetInformationFile_t)(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock,
@@ -536,16 +522,10 @@ typedef u64(__stdcall* NtCreateThread_t)(PHANDLE ThreadHandle, ACCESS_MASK Desir
536522

537523
typedef u64(__stdcall* NtTerminateThread_t)(HANDLE ThreadHandle, u64 ExitStatus);
538524

539-
typedef u64(__stdcall* NtQueueApcThreadEx_t)(HANDLE ThreadHandle,
540-
USER_APC_OPTION UserApcReserveHandle,
541-
PPS_APC_ROUTINE ApcRoutine, PVOID ApcArgument1,
542-
PVOID ApcArgument2, PVOID ApcArgument3);
543-
544525
extern NtClose_t NtClose;
545526
extern NtSetInformationFile_t NtSetInformationFile;
546527
extern NtCreateThread_t NtCreateThread;
547528
extern NtTerminateThread_t NtTerminateThread;
548-
extern NtQueueApcThreadEx_t NtQueueApcThreadEx;
549529

550530
namespace Common::NtApi {
551531
void Initialize();

src/core/libraries/ajm/ajm_context.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "common/assert.h"
55
#include "common/logging/log.h"
6-
#include "common/thread.h"
76
#include "core/libraries/ajm/ajm.h"
87
#include "core/libraries/ajm/ajm_at9.h"
98
#include "core/libraries/ajm/ajm_context.h"
@@ -54,7 +53,6 @@ s32 AjmContext::ModuleRegister(AjmCodecType type) {
5453
}
5554

5655
void AjmContext::WorkerThread(std::stop_token stop) {
57-
Common::SetCurrentThreadName("shadPS4:AjmWorker");
5856
while (!stop.stop_requested()) {
5957
auto batch = batch_queue.PopWait(stop);
6058
if (batch != nullptr) {

src/core/libraries/kernel/kernel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void KernelSignalRequest() {
4646
}
4747

4848
static void KernelServiceThread(std::stop_token stoken) {
49-
Common::SetCurrentThreadName("shadPS4:KernelServiceThread");
49+
Common::SetCurrentThreadName("shadPS4:Kernel_ServiceThread");
5050

5151
while (!stoken.stop_requested()) {
5252
HLE_TRACE;
@@ -255,7 +255,6 @@ void RegisterKernel(Core::Loader::SymbolsResolver* sym) {
255255
LIB_FUNCTION("NWtTN10cJzE", "libSceLibcInternalExt", 1, "libSceLibcInternal", 1, 1,
256256
sceLibcHeapGetTraceInfo);
257257
LIB_FUNCTION("FxVZqBAA7ks", "libkernel", 1, "libkernel", 1, 1, ps4__write);
258-
LIB_FUNCTION("FN4gaPmuFV8", "libScePosix", 1, "libkernel", 1, 1, ps4__write);
259258
}
260259

261260
} // namespace Libraries::Kernel

src/core/libraries/kernel/memory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
492492
return ORBIS_OK;
493493
}
494494
auto* memory = Core::Memory::Instance();
495-
return memory->UnmapMemory(std::bit_cast<VAddr>(addr), len);
495+
memory->UnmapMemory(std::bit_cast<VAddr>(addr), len);
496+
return ORBIS_OK;
496497
}
497498

498499
int PS4_SYSV_ABI posix_munmap(void* addr, size_t len) {

src/core/libraries/kernel/process.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ s32 PS4_SYSV_ABI sceKernelLoadStartModule(const char* moduleFileName, size_t arg
4545

4646
// Load PRX module and relocate any modules that import it.
4747
auto* linker = Common::Singleton<Core::Linker>::Instance();
48-
u32 handle = linker->FindByName(path);
49-
if (handle != -1) {
50-
return handle;
48+
u32 handle = linker->LoadModule(path, true);
49+
if (handle == -1) {
50+
return ORBIS_KERNEL_ERROR_EINVAL;
5151
}
52-
handle = linker->LoadModule(path, true);
5352
auto* module = linker->GetModule(handle);
5453
linker->RelocateAnyImports(module);
5554

@@ -61,10 +60,7 @@ s32 PS4_SYSV_ABI sceKernelLoadStartModule(const char* moduleFileName, size_t arg
6160
// Retrieve and verify proc param according to libkernel.
6261
u64* param = module->GetProcParam<u64*>();
6362
ASSERT_MSG(!param || param[0] >= 0x18, "Invalid module param size: {}", param[0]);
64-
s32 ret = module->Start(args, argp, param);
65-
if (pRes) {
66-
*pRes = ret;
67-
}
63+
module->Start(args, argp, param);
6864

6965
return handle;
7066
}
@@ -108,9 +104,6 @@ s32 PS4_SYSV_ABI sceKernelGetModuleInfoForUnwind(VAddr addr, int flags,
108104
LOG_INFO(Lib_Kernel, "called addr = {:#x}, flags = {:#x}", addr, flags);
109105
auto* linker = Common::Singleton<Core::Linker>::Instance();
110106
auto* module = linker->FindByAddress(addr);
111-
if (!module) {
112-
return ORBIS_KERNEL_ERROR_EFAULT;
113-
}
114107
const auto mod_info = module->GetModuleInfoEx();
115108

116109
// Fill in module info.

src/core/libraries/kernel/sync/semaphore.h

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,14 @@ class Semaphore {
8787
template <class Rep, class Period>
8888
bool try_acquire_for(const std::chrono::duration<Rep, Period>& rel_time) {
8989
#ifdef _WIN64
90-
const auto start_time = std::chrono::high_resolution_clock::now();
91-
auto rel_time_ms = std::chrono::ceil<std::chrono::milliseconds>(rel_time);
90+
const auto rel_time_ms = std::chrono::ceil<std::chrono::milliseconds>(rel_time);
91+
const u64 timeout_ms = static_cast<u64>(rel_time_ms.count());
9292

93-
while (rel_time_ms.count() > 0) {
94-
u64 timeout_ms = static_cast<u64>(rel_time_ms.count());
95-
u64 res = WaitForSingleObjectEx(sem, timeout_ms, true);
96-
if (res == WAIT_OBJECT_0) {
97-
return true;
98-
} else if (res == WAIT_IO_COMPLETION) {
99-
auto elapsed_time = std::chrono::high_resolution_clock::now() - start_time;
100-
rel_time_ms -= std::chrono::duration_cast<std::chrono::milliseconds>(elapsed_time);
101-
} else {
102-
return false;
103-
}
93+
if (timeout_ms == 0) {
94+
return false;
10495
}
10596

106-
return false;
97+
return WaitForSingleObjectEx(sem, timeout_ms, true) == WAIT_OBJECT_0;
10798
#elif defined(__APPLE__)
10899
const auto rel_time_ns = std::chrono::ceil<std::chrono::nanoseconds>(rel_time).count();
109100
const auto timeout = dispatch_time(DISPATCH_TIME_NOW, rel_time_ns);
@@ -116,26 +107,19 @@ class Semaphore {
116107
template <class Clock, class Duration>
117108
bool try_acquire_until(const std::chrono::time_point<Clock, Duration>& abs_time) {
118109
#ifdef _WIN64
119-
const auto start_time = Clock::now();
120-
if (start_time >= abs_time) {
110+
const auto now = Clock::now();
111+
if (now >= abs_time) {
121112
return false;
122113
}
123114

124-
auto rel_time = std::chrono::ceil<std::chrono::milliseconds>(abs_time - start_time);
125-
while (rel_time.count() > 0) {
126-
u64 timeout_ms = static_cast<u64>(rel_time.count());
127-
u64 res = WaitForSingleObjectEx(sem, timeout_ms, true);
128-
if (res == WAIT_OBJECT_0) {
129-
return true;
130-
} else if (res == WAIT_IO_COMPLETION) {
131-
auto elapsed_time = Clock::now() - start_time;
132-
rel_time -= std::chrono::duration_cast<std::chrono::milliseconds>(elapsed_time);
133-
} else {
134-
return false;
135-
}
115+
const auto rel_time = std::chrono::ceil<std::chrono::milliseconds>(abs_time - now);
116+
const u64 timeout_ms = static_cast<u64>(rel_time.count());
117+
if (timeout_ms == 0) {
118+
return false;
136119
}
137120

138-
return false;
121+
u64 res = WaitForSingleObjectEx(sem, static_cast<u64>(timeout_ms), true);
122+
return res == WAIT_OBJECT_0;
139123
#elif defined(__APPLE__)
140124
auto abs_s = std::chrono::time_point_cast<std::chrono::seconds>(abs_time);
141125
auto abs_ns = std::chrono::time_point_cast<std::chrono::nanoseconds>(abs_time) -

src/core/libraries/kernel/threads/event_flag.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -132,33 +132,6 @@ class EventFlagInternal {
132132
m_bits &= bits;
133133
}
134134

135-
void Cancel(u64 setPattern, int* numWaitThreads) {
136-
std::unique_lock lock{m_mutex};
137-
138-
while (m_status != Status::Set) {
139-
m_mutex.unlock();
140-
std::this_thread::sleep_for(std::chrono::microseconds(10));
141-
m_mutex.lock();
142-
}
143-
144-
if (numWaitThreads) {
145-
*numWaitThreads = m_waiting_threads;
146-
}
147-
148-
m_status = Status::Canceled;
149-
m_bits = setPattern;
150-
151-
m_cond_var.notify_all();
152-
153-
while (m_waiting_threads > 0) {
154-
m_mutex.unlock();
155-
std::this_thread::sleep_for(std::chrono::microseconds(10));
156-
m_mutex.lock();
157-
}
158-
159-
m_status = Status::Set;
160-
}
161-
162135
private:
163136
enum class Status { Set, Canceled, Deleted };
164137

@@ -259,8 +232,7 @@ int PS4_SYSV_ABI sceKernelClearEventFlag(OrbisKernelEventFlag ef, u64 bitPattern
259232

260233
int PS4_SYSV_ABI sceKernelCancelEventFlag(OrbisKernelEventFlag ef, u64 setPattern,
261234
int* pNumWaitThreads) {
262-
LOG_DEBUG(Kernel_Event, "called");
263-
ef->Cancel(setPattern, pNumWaitThreads);
235+
LOG_ERROR(Kernel_Event, "(STUBBED) called");
264236
return ORBIS_OK;
265237
}
266238

src/core/libraries/kernel/threads/exception.cpp

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "core/libraries/libs.h"
88

99
#ifdef _WIN64
10-
#include "common/ntapi.h"
1110
#else
1211
#include <signal.h>
1312
#endif
@@ -65,34 +64,6 @@ void SigactionHandler(int signum, siginfo_t* inf, ucontext_t* raw_context) {
6564
handler(POSIX_SIGUSR1, &ctx);
6665
}
6766
}
68-
#else
69-
void ExceptionHandler(void* arg1, void* arg2, void* arg3, PCONTEXT context) {
70-
const char* thrName = (char*)arg1;
71-
LOG_INFO(Lib_Kernel, "Exception raised successfully on thread '{}'", thrName);
72-
const auto handler = Handlers[POSIX_SIGUSR1];
73-
if (handler) {
74-
auto ctx = Ucontext{};
75-
ctx.uc_mcontext.mc_r8 = context->R8;
76-
ctx.uc_mcontext.mc_r9 = context->R9;
77-
ctx.uc_mcontext.mc_r10 = context->R10;
78-
ctx.uc_mcontext.mc_r11 = context->R11;
79-
ctx.uc_mcontext.mc_r12 = context->R12;
80-
ctx.uc_mcontext.mc_r13 = context->R13;
81-
ctx.uc_mcontext.mc_r14 = context->R14;
82-
ctx.uc_mcontext.mc_r15 = context->R15;
83-
ctx.uc_mcontext.mc_rdi = context->Rdi;
84-
ctx.uc_mcontext.mc_rsi = context->Rsi;
85-
ctx.uc_mcontext.mc_rbp = context->Rbp;
86-
ctx.uc_mcontext.mc_rbx = context->Rbx;
87-
ctx.uc_mcontext.mc_rdx = context->Rdx;
88-
ctx.uc_mcontext.mc_rax = context->Rax;
89-
ctx.uc_mcontext.mc_rcx = context->Rcx;
90-
ctx.uc_mcontext.mc_rsp = context->Rsp;
91-
ctx.uc_mcontext.mc_fs = context->SegFs;
92-
ctx.uc_mcontext.mc_gs = context->SegGs;
93-
handler(POSIX_SIGUSR1, &ctx);
94-
}
95-
}
9667
#endif
9768

9869
int PS4_SYSV_ABI sceKernelInstallExceptionHandler(s32 signum, SceKernelExceptionHandler handler) {
@@ -102,7 +73,9 @@ int PS4_SYSV_ABI sceKernelInstallExceptionHandler(s32 signum, SceKernelException
10273
}
10374
ASSERT_MSG(!Handlers[POSIX_SIGUSR1], "Invalid parameters");
10475
Handlers[POSIX_SIGUSR1] = handler;
105-
#ifndef _WIN64
76+
#ifdef _WIN64
77+
UNREACHABLE_MSG("Missing exception implementation");
78+
#else
10679
struct sigaction act = {};
10780
act.sa_flags = SA_SIGINFO | SA_RESTART;
10881
act.sa_sigaction = reinterpret_cast<decltype(act.sa_sigaction)>(SigactionHandler);
@@ -118,7 +91,9 @@ int PS4_SYSV_ABI sceKernelRemoveExceptionHandler(s32 signum) {
11891
}
11992
ASSERT_MSG(Handlers[POSIX_SIGUSR1], "Invalid parameters");
12093
Handlers[POSIX_SIGUSR1] = nullptr;
121-
#ifndef _WIN64
94+
#ifdef _WIN64
95+
UNREACHABLE_MSG("Missing exception implementation");
96+
#else
12297
struct sigaction act = {};
12398
act.sa_flags = SA_SIGINFO | SA_RESTART;
12499
act.sa_sigaction = nullptr;
@@ -128,18 +103,13 @@ int PS4_SYSV_ABI sceKernelRemoveExceptionHandler(s32 signum) {
128103
}
129104

130105
int PS4_SYSV_ABI sceKernelRaiseException(PthreadT thread, int signum) {
131-
LOG_WARNING(Lib_Kernel, "Raising exception on thread '{}'", thread->name);
106+
LOG_ERROR(Lib_Kernel, "Raising exception");
132107
ASSERT_MSG(signum == POSIX_SIGUSR1, "Attempting to raise non user defined signal!");
133-
#ifndef _WIN64
108+
#ifdef _WIN64
109+
UNREACHABLE_MSG("Missing exception implementation");
110+
#else
134111
pthread_t pthr = *reinterpret_cast<pthread_t*>(thread->native_thr.GetHandle());
135112
pthread_kill(pthr, SIGUSR2);
136-
#else
137-
USER_APC_OPTION option;
138-
option.UserApcFlags = QueueUserApcFlagsSpecialUserApc;
139-
140-
u64 res = NtQueueApcThreadEx(reinterpret_cast<HANDLE>(thread->native_thr.GetHandle()), option,
141-
ExceptionHandler, (void*)thread->name.c_str(), nullptr, nullptr);
142-
ASSERT(res == 0);
143113
#endif
144114
return 0;
145115
}

src/core/libraries/kernel/threads/pthread.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,6 @@ void RegisterThread(Core::Loader::SymbolsResolver* sym) {
540540
LIB_FUNCTION("onNY9Byn-W8", "libkernel", 1, "libkernel", 1, 1, ORBIS(posix_pthread_join));
541541
LIB_FUNCTION("P41kTWUS3EI", "libkernel", 1, "libkernel", 1, 1,
542542
ORBIS(posix_pthread_getschedparam));
543-
LIB_FUNCTION("oIRFTjoILbg", "libkernel", 1, "libkernel", 1, 1,
544-
ORBIS(posix_pthread_setschedparam));
545543
LIB_FUNCTION("How7B8Oet6k", "libkernel", 1, "libkernel", 1, 1, ORBIS(posix_pthread_getname_np));
546544
LIB_FUNCTION("3kg7rT0NQIs", "libkernel", 1, "libkernel", 1, 1, posix_pthread_exit);
547545
LIB_FUNCTION("aI+OeCz8xrQ", "libkernel", 1, "libkernel", 1, 1, posix_pthread_self);

0 commit comments

Comments
 (0)