mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-01-08 17:50:31 +01:00
[rpcsx-os] Enable thr_new
Fix uwrite
This commit is contained in:
parent
855b7ab75c
commit
030327cd1d
|
|
@ -20,8 +20,7 @@ orbis::SysResult orbis::sys_thr_new(Thread *thread, ptr<struct thr_param> param,
|
|||
}
|
||||
|
||||
orbis::SysResult orbis::sys_thr_self(Thread *thread, ptr<slong> id) {
|
||||
uwrite(id, (slong)thread->tid);
|
||||
return {};
|
||||
return uwrite(id, (slong)thread->tid);
|
||||
}
|
||||
|
||||
orbis::SysResult orbis::sys_thr_exit(Thread *thread, ptr<slong> state) {
|
||||
|
|
|
|||
|
|
@ -43,11 +43,11 @@ void orbis::syscall_entry(Thread *thread) {
|
|||
std::abort();
|
||||
}
|
||||
|
||||
error =
|
||||
int(uread(args + regcnt,
|
||||
ptr<void>(readRegister(thread->context, RegisterId::rsp) +
|
||||
sizeof(uint64_t)),
|
||||
(sysent.narg - regcnt) * sizeof(uint64_t)));
|
||||
error = int(
|
||||
ureadRaw(args + regcnt,
|
||||
ptr<void>(readRegister(thread->context, RegisterId::rsp) +
|
||||
sizeof(uint64_t)),
|
||||
(sysent.narg - regcnt) * sizeof(uint64_t)));
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
|
|
|
|||
|
|
@ -433,8 +433,11 @@ SysResult thr_create(orbis::Thread *thread, orbis::ptr<struct ucontext> ctxt,
|
|||
}
|
||||
SysResult thr_new(orbis::Thread *thread, orbis::ptr<thr_param> param,
|
||||
orbis::sint param_size) {
|
||||
return {}; // FIXME: remove when we ready for MT
|
||||
auto _param = uread(param);
|
||||
thr_param _param;
|
||||
auto result = uread(_param, param);
|
||||
if (result != ErrorCode{}) {
|
||||
return result;
|
||||
}
|
||||
|
||||
auto proc = thread->tproc;
|
||||
auto [baseId, childThread] = proc->threadsMap.emplace();
|
||||
|
|
@ -445,14 +448,19 @@ SysResult thr_new(orbis::Thread *thread, orbis::ptr<thr_param> param,
|
|||
childThread->stackEnd = _param.stack_base + _param.stack_size;
|
||||
childThread->fsBase = reinterpret_cast<std::uintptr_t>(_param.tls_base);
|
||||
|
||||
uwrite(_param.parent_tid, slong(childThread->tid));
|
||||
result = uwrite(_param.parent_tid, slong(childThread->tid));
|
||||
|
||||
if (result != ErrorCode{}) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// FIXME: implement scheduler
|
||||
|
||||
std::printf("Starting child thread %lu\n", (long)(proc->pid + baseId));
|
||||
|
||||
std::thread{[=, childThread = Ref<Thread>(childThread)] {
|
||||
uwrite(_param.child_tid, slong(childThread->tid));
|
||||
static_cast<void>(
|
||||
uwrite(_param.child_tid, slong(childThread->tid))); // TODO: verify
|
||||
auto context = new ucontext_t{};
|
||||
|
||||
context->uc_mcontext.gregs[REG_RDI] =
|
||||
|
|
|
|||
|
|
@ -40,14 +40,14 @@ template <typename T> using cptr = T *const;
|
|||
|
||||
using caddr_t = ptr<char>;
|
||||
|
||||
[[nodiscard]] inline ErrorCode uread(void *kernelAddress,
|
||||
ptr<const void> userAddress, size_t size) {
|
||||
[[nodiscard]] inline ErrorCode
|
||||
ureadRaw(void *kernelAddress, ptr<const void> userAddress, size_t size) {
|
||||
std::memcpy(kernelAddress, userAddress, size);
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline ErrorCode uwrite(ptr<void> userAddress,
|
||||
const void *kernelAddress, size_t size) {
|
||||
[[nodiscard]] inline ErrorCode
|
||||
uwriteRaw(ptr<void> userAddress, const void *kernelAddress, size_t size) {
|
||||
std::memcpy(userAddress, kernelAddress, size);
|
||||
return {};
|
||||
}
|
||||
|
|
@ -64,28 +64,28 @@ using caddr_t = ptr<char>;
|
|||
return {};
|
||||
}
|
||||
|
||||
template <typename T> [[deprecated]] T uread(ptr<T> pointer) {
|
||||
T result;
|
||||
uread(&result, pointer, sizeof(T));
|
||||
template <typename T> [[deprecated]] T uread(ptr<const T> pointer) {
|
||||
T result{};
|
||||
ureadRaw(&result, pointer, sizeof(T));
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> [[nodiscard]] ErrorCode uread(T &result, ptr<T> pointer) {
|
||||
return uread(&result, pointer, sizeof(T));
|
||||
return ureadRaw(&result, pointer, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T> [[nodiscard]] ErrorCode uwrite(ptr<T> pointer, T data) {
|
||||
return uwrite(pointer, &data, sizeof(T));
|
||||
return uwriteRaw(pointer, &data, sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] ErrorCode uread(T *result, ptr<T> pointer, std::size_t count) {
|
||||
return uread(&result, pointer, sizeof(T) * count);
|
||||
return ureadRaw(&result, pointer, sizeof(T) * count);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] ErrorCode uwrite(ptr<T> pointer, T *data, std::size_t count) {
|
||||
return uwrite(pointer, &data, sizeof(T) * count);
|
||||
return uwriteRaw(pointer, &data, sizeof(T) * count);
|
||||
}
|
||||
|
||||
inline uint64_t readRegister(void *context, RegisterId id) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue