mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-20 22:05:12 +00:00
orbis: remove process list from context & initial serialization support
modernize kenv add LockableKernelObject utility
This commit is contained in:
parent
f71e3410c1
commit
014012c219
22 changed files with 372 additions and 215 deletions
|
|
@ -78,7 +78,7 @@ orbis::SysResult orbis::sys_cpuset_getaffinity(Thread *thread, cpulevel_t level,
|
|||
case CpuLevel::Which:
|
||||
switch (CpuWhich(which)) {
|
||||
case CpuWhich::Tid: {
|
||||
Thread *whichThread = nullptr;
|
||||
rx::Ref<Thread> whichThread = nullptr;
|
||||
if (id == ~id_t(0) || thread->tid == id) {
|
||||
whichThread = thread;
|
||||
} else {
|
||||
|
|
@ -97,7 +97,7 @@ orbis::SysResult orbis::sys_cpuset_getaffinity(Thread *thread, cpulevel_t level,
|
|||
if (id == ~id_t(0) || id == thread->tproc->pid) {
|
||||
whichProcess = thread->tproc;
|
||||
} else {
|
||||
whichProcess = g_context->findProcessById(id);
|
||||
whichProcess = findProcessById(id);
|
||||
|
||||
if (whichProcess == nullptr) {
|
||||
return ErrorCode::SRCH;
|
||||
|
|
@ -132,7 +132,7 @@ orbis::SysResult orbis::sys_cpuset_setaffinity(Thread *thread, cpulevel_t level,
|
|||
case CpuLevel::Which:
|
||||
switch (CpuWhich(which)) {
|
||||
case CpuWhich::Tid: {
|
||||
Thread *whichThread = nullptr;
|
||||
rx::Ref<Thread> whichThread = nullptr;
|
||||
if (id == ~id_t(0) || thread->tid == id) {
|
||||
whichThread = thread;
|
||||
} else {
|
||||
|
|
@ -163,7 +163,7 @@ orbis::SysResult orbis::sys_cpuset_setaffinity(Thread *thread, cpulevel_t level,
|
|||
} else {
|
||||
ORBIS_LOG_ERROR(__FUNCTION__, "process not found", level, which, id,
|
||||
cpusetsize);
|
||||
whichProcess = g_context->findProcessById(id);
|
||||
whichProcess = findProcessById(id);
|
||||
|
||||
if (whichProcess == nullptr) {
|
||||
return ErrorCode::SRCH;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ orbis::SysResult orbis::sys_kenv(Thread *thread, sint what,
|
|||
size_t entry = 0;
|
||||
// Entry: size of both full buffers, the '=' and the '\0' at the end
|
||||
if (value == nullptr || len == 0) {
|
||||
entry = key.size() + 1 + strnlen(env_value, 128) + 1;
|
||||
entry = key.size() + 1 + env_value.size() + 1;
|
||||
} else {
|
||||
char buf[128 * 2 + 2];
|
||||
|
||||
|
|
@ -28,9 +28,8 @@ orbis::SysResult orbis::sys_kenv(Thread *thread, sint what,
|
|||
|
||||
*_buf++ = '=';
|
||||
|
||||
const size_t value_size = strnlen(env_value, 128);
|
||||
std::strncpy(_buf, env_value, value_size);
|
||||
_buf += value_size;
|
||||
std::strncpy(_buf, env_value.data(), env_value.size());
|
||||
_buf += env_value.size();
|
||||
|
||||
*_buf++ = '\0';
|
||||
|
||||
|
|
@ -58,16 +57,16 @@ orbis::SysResult orbis::sys_kenv(Thread *thread, sint what,
|
|||
if (it == kenv.end()) {
|
||||
return ErrorCode::NOENT;
|
||||
}
|
||||
const char *buf = it->second;
|
||||
ORBIS_RET_ON_ERROR(uwriteRaw(value, buf, std::min(len, 128)));
|
||||
ORBIS_RET_ON_ERROR(uwriteRaw(value, it->second.data(), it->second.size()));
|
||||
break;
|
||||
}
|
||||
case kenv_set: {
|
||||
if (len < 1) {
|
||||
return ErrorCode::INVAL;
|
||||
}
|
||||
char *_value_buf = kenv[kstring(_name)];
|
||||
ORBIS_RET_ON_ERROR(ureadString(_value_buf, 128, value));
|
||||
auto &_value_buf = kenv[kstring(_name)];
|
||||
ORBIS_RET_ON_ERROR(
|
||||
ureadString(_value_buf.data(), _value_buf.max_size() + 1, value));
|
||||
break;
|
||||
}
|
||||
case kenv_unset: {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ static SysResult keventChange(KQueue *kq, KEvent &change, Thread *thread) {
|
|||
nodeIt = kq->notes.begin();
|
||||
|
||||
if (change.filter == kEvFiltProc) {
|
||||
auto process = g_context->findProcessById(change.ident);
|
||||
auto process = findProcessById(change.ident);
|
||||
if (process == nullptr) {
|
||||
return ErrorCode::SRCH;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ orbis::SysResult orbis::sys_wait4(Thread *thread, sint pid, ptr<sint> status,
|
|||
|
||||
int hostPid = pid;
|
||||
if (pid > 0) {
|
||||
auto process = g_context->findProcessById(pid);
|
||||
auto process = findProcessById(pid);
|
||||
if (process == nullptr) {
|
||||
return ErrorCode::SRCH;
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ orbis::SysResult orbis::sys_wait4(Thread *thread, sint pid, ptr<sint> status,
|
|||
|
||||
ORBIS_LOG_ERROR(__FUNCTION__, pid, status, options, rusage, result, stat);
|
||||
|
||||
auto process = g_context->findProcessByHostId(result);
|
||||
auto process = findProcessByHostId(result);
|
||||
if (process == nullptr) {
|
||||
ORBIS_LOG_ERROR("host process not found", result);
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ orbis::SysResult orbis::sys_rtprio_thread(Thread *thread, sint function,
|
|||
ORBIS_LOG_ERROR(__FUNCTION__, function, lwpid, rtp->prio, rtp->type);
|
||||
thread->where();
|
||||
|
||||
Thread *targetThread;
|
||||
rx::Ref<Thread> targetThread;
|
||||
if (lwpid == thread->tid || lwpid == -1) {
|
||||
targetThread = thread;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -940,7 +940,7 @@ orbis::SysResult orbis::sys_dmem_container(Thread *thread, uint id) {
|
|||
orbis::SysResult orbis::sys_get_authinfo(Thread *thread, pid_t pid,
|
||||
ptr<AuthInfo> info) {
|
||||
|
||||
auto process = pid > 0 ? g_context->findProcessById(pid) : thread->tproc;
|
||||
auto process = pid > 0 ? findProcessById(pid) : thread->tproc;
|
||||
if (process == nullptr) {
|
||||
return ErrorCode::SRCH;
|
||||
}
|
||||
|
|
@ -1188,21 +1188,20 @@ orbis::SysResult orbis::sys_randomized_path(Thread *thread, sint type,
|
|||
}
|
||||
orbis::SysResult orbis::sys_rdup(Thread *thread, sint pid, sint fd) {
|
||||
ORBIS_LOG_TODO(__FUNCTION__, pid, fd);
|
||||
for (auto it = g_context->getProcessList(); it != nullptr; it = it->next) {
|
||||
auto &p = it->object;
|
||||
if (p.pid != pid) {
|
||||
continue;
|
||||
}
|
||||
auto process = pid == -1 || pid == thread->tproc->pid ? thread->tproc
|
||||
: findProcessById(pid);
|
||||
|
||||
auto file = p.fileDescriptors.get(fd);
|
||||
if (file == nullptr) {
|
||||
return ErrorCode::BADF;
|
||||
}
|
||||
|
||||
thread->retval[0] = thread->tproc->fileDescriptors.insert(std::move(file));
|
||||
return {};
|
||||
if (!process) {
|
||||
return ErrorCode::SRCH;
|
||||
}
|
||||
return ErrorCode::SRCH;
|
||||
|
||||
auto file = process->fileDescriptors.get(fd);
|
||||
if (file == nullptr) {
|
||||
return ErrorCode::BADF;
|
||||
}
|
||||
|
||||
thread->retval[0] = thread->tproc->fileDescriptors.insert(std::move(file));
|
||||
return {};
|
||||
}
|
||||
orbis::SysResult orbis::sys_dl_get_metadata(Thread *thread /* TODO */) {
|
||||
return ErrorCode::NOSYS;
|
||||
|
|
@ -1297,7 +1296,7 @@ orbis::SysResult orbis::sys_budget_get_ptype(Thread *thread, sint pid) {
|
|||
if (pid < 0 || pid == thread->tproc->pid) {
|
||||
process = thread->tproc;
|
||||
} else {
|
||||
process = g_context->findProcessById(pid);
|
||||
process = findProcessById(pid);
|
||||
|
||||
if (!process) {
|
||||
return ErrorCode::SRCH;
|
||||
|
|
@ -1337,14 +1336,14 @@ orbis::SysResult orbis::sys_get_resident_fmem_count(Thread *thread, pid_t pid) {
|
|||
}
|
||||
orbis::SysResult orbis::sys_thr_get_name(Thread *thread, lwpid_t lwpid,
|
||||
char *buf, size_t buflen) {
|
||||
Thread *searchThread;
|
||||
rx::Ref<Thread> searchThread;
|
||||
if (thread->tid == lwpid || lwpid == -1) {
|
||||
searchThread = thread;
|
||||
} else {
|
||||
searchThread = thread->tproc->threadsMap.get(lwpid - thread->tproc->pid);
|
||||
|
||||
if (searchThread == nullptr) {
|
||||
if (auto process = g_context->findProcessById(lwpid)) {
|
||||
if (auto process = findProcessById(lwpid)) {
|
||||
searchThread = process->threadsMap.get(lwpid - process->pid);
|
||||
}
|
||||
}
|
||||
|
|
@ -1354,11 +1353,11 @@ orbis::SysResult orbis::sys_thr_get_name(Thread *thread, lwpid_t lwpid,
|
|||
}
|
||||
}
|
||||
|
||||
auto namelen = std::strlen(searchThread->name);
|
||||
auto namelen = searchThread->name.length();
|
||||
|
||||
auto writeLen = std::min(namelen + 1, buflen);
|
||||
if (writeLen > 0) {
|
||||
ORBIS_RET_ON_ERROR(uwriteRaw(buf, searchThread->name, writeLen - 1));
|
||||
ORBIS_RET_ON_ERROR(uwriteRaw(buf, searchThread->name.data(), writeLen - 1));
|
||||
buf[writeLen] = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ orbis::SysResult orbis::sys_kill(Thread *thread, sint pid, sint signum) {
|
|||
|
||||
int hostPid = pid;
|
||||
if (pid > 0) {
|
||||
auto process = g_context->findProcessById(pid);
|
||||
auto process = findProcessById(pid);
|
||||
if (process == nullptr) {
|
||||
return ErrorCode::SRCH;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ SysResult kern_sysctl(Thread *thread, ptr<sint> name, uint namelen,
|
|||
ORBIS_LOG_ERROR("KERN_PROC_PROC 2");
|
||||
|
||||
if (namelen >= 4) {
|
||||
auto process = g_context->findProcessById(name[3]);
|
||||
auto process = findProcessById(name[3]);
|
||||
if (process == nullptr || process->exitStatus.has_value()) {
|
||||
return ErrorCode::SRCH;
|
||||
}
|
||||
|
|
@ -259,7 +259,7 @@ SysResult kern_sysctl(Thread *thread, ptr<sint> name, uint namelen,
|
|||
if (name[0] == kern && name[1] == proc && name[2] == 36) {
|
||||
Process *process = thread->tproc;
|
||||
if (process->pid != name[3]) {
|
||||
process = g_context->findProcessById(name[3]);
|
||||
process = findProcessById(name[3]);
|
||||
if (process == nullptr) {
|
||||
ORBIS_LOG_ERROR("get sdk version by pid: process not found", name[3],
|
||||
thread->tproc->pid);
|
||||
|
|
@ -290,7 +290,7 @@ SysResult kern_sysctl(Thread *thread, ptr<sint> name, uint namelen,
|
|||
// 1 - 14 - 35 - pid
|
||||
Process *process = thread->tproc;
|
||||
if (process->pid != name[3] && name[3] != -1) {
|
||||
process = g_context->findProcessById(name[3]);
|
||||
process = findProcessById(name[3]);
|
||||
if (process == nullptr) {
|
||||
ORBIS_LOG_ERROR("appinfo process not found", name[3],
|
||||
thread->tproc->pid);
|
||||
|
|
@ -461,7 +461,7 @@ SysResult kern_sysctl(Thread *thread, ptr<sint> name, uint namelen,
|
|||
if (name[0] == kern && name[1] == proc && name[2] == 68) {
|
||||
Process *process = thread->tproc;
|
||||
if (process->pid != name[3]) {
|
||||
process = g_context->findProcessById(name[3]);
|
||||
process = findProcessById(name[3]);
|
||||
if (process == nullptr) {
|
||||
ORBIS_LOG_ERROR("get ps5 sdk version by pid: process not found",
|
||||
name[3], thread->tproc->pid);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue