Skip to content

Commit

Permalink
Merge branch 'RPCSX:master' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
qurious-pixel authored Oct 30, 2023
2 parents 098694b + 95f1a6f commit bfdfe82
Show file tree
Hide file tree
Showing 17 changed files with 802 additions and 110 deletions.
4 changes: 2 additions & 2 deletions orbis-kernel/include/orbis/sys/sysproto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ SysResult sys_socketex(Thread *thread, ptr<const char> name, sint domain,
sint type, sint protocol);
SysResult sys_socketclose(Thread *thread, sint fd);
SysResult sys_netgetiflist(Thread *thread /* TODO */);
SysResult sys_kqueueex(Thread *thread /* TODO */);
SysResult sys_kqueueex(Thread *thread, ptr<char> name, sint flags);
SysResult sys_mtypeprotect(Thread *thread /* TODO */);
SysResult sys_regmgr_call(Thread *thread, uint32_t op, uint32_t id,
ptr<void> result, ptr<void> value, uint64_t type);
Expand Down Expand Up @@ -728,7 +728,7 @@ SysResult sys_get_gpo(Thread *thread /* TODO */);
SysResult sys_get_vm_map_timestamp(Thread *thread /* TODO */);
SysResult sys_opmc_set_hw(Thread *thread /* TODO */);
SysResult sys_opmc_get_hw(Thread *thread /* TODO */);
SysResult sys_get_cpu_usage_all(Thread *thread /* TODO */);
SysResult sys_get_cpu_usage_all(Thread *thread, uint32_t unk, ptr<uint32_t> result);
SysResult sys_mmap_dmem(Thread *thread, caddr_t addr, size_t len,
sint memoryType, sint prot, sint flags,
off_t directMemoryStart);
Expand Down
1 change: 1 addition & 0 deletions orbis-kernel/include/orbis/thread/Process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct Process final {

std::uint64_t nextTlsSlot = 1;
std::uint64_t lastTlsOffset = 0;
bool isSystem = false;

utils::RcIdMap<EventFlag, sint, 4097, 1> evfMap;
utils::RcIdMap<Semaphore, sint, 4097, 1> semMap;
Expand Down
10 changes: 4 additions & 6 deletions orbis-kernel/include/orbis/umtx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ ErrorCode umtx_cv_wait(Thread *thread, ptr<ucond> cv, ptr<umutex> m,
std::uint64_t ut, ulong wflags);
ErrorCode umtx_cv_signal(Thread *thread, ptr<ucond> cv);
ErrorCode umtx_cv_broadcast(Thread *thread, ptr<ucond> cv);
ErrorCode umtx_rw_rdlock(Thread *thread, ptr<void> obj, std::int64_t val,
ptr<void> uaddr1, ptr<void> uaddr2);
ErrorCode umtx_rw_wrlock(Thread *thread, ptr<void> obj, std::int64_t val,
ptr<void> uaddr1, ptr<void> uaddr2);
ErrorCode umtx_rw_unlock(Thread *thread, ptr<void> obj, std::int64_t val,
ptr<void> uaddr1, ptr<void> uaddr2);
ErrorCode umtx_rw_rdlock(Thread *thread, ptr<urwlock> rwlock, slong fflag,
ulong ut);
ErrorCode umtx_rw_wrlock(Thread *thread, ptr<urwlock> rwlock, ulong ut);
ErrorCode umtx_rw_unlock(Thread *thread, ptr<urwlock> rwlock);
ErrorCode umtx_wake_private(Thread *thread, ptr<void> uaddr, sint n_wake);
ErrorCode umtx_wait_umutex(Thread *thread, ptr<umutex> m, std::uint64_t ut);
ErrorCode umtx_wake_umutex(Thread *thread, ptr<umutex> m);
Expand Down
12 changes: 6 additions & 6 deletions orbis-kernel/src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ static orbis::SysResult doRelocation(orbis::Process *process,

auto &defModule = module->importedModules.at(symbol.moduleIndex);
if (!defModule) {
std::printf("'%s' ('%s') uses undefined symbol '%llx' in unloaded module "
"'%s', rel %u\n",
module->moduleName, module->soName,
(unsigned long long)symbol.id,
module->neededModules.at(symbol.moduleIndex).name.c_str(),
rel.relType);
// std::printf("'%s' ('%s') uses undefined symbol '%llx' in unloaded module "
// "'%s', rel %u\n",
// module->moduleName, module->soName,
// (unsigned long long)symbol.id,
// module->neededModules.at(symbol.moduleIndex).name.c_str(),
// rel.relType);

return {};
}
Expand Down
140 changes: 135 additions & 5 deletions orbis-kernel/src/sys/sys_event.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,156 @@
#include "KernelAllocator.hpp"
#include "sys/sysproto.hpp"

#include "thread/Process.hpp"
#include "utils/Logs.hpp"
#include "utils/SharedMutex.hpp"
#include <list>
#include <span>

struct KQueue : orbis::File {};
namespace orbis {
struct KEvent {
uintptr_t ident;
sshort filter;
ushort flags;
uint fflags;
intptr_t data;
ptr<void> udata;
};

struct KNote {
KEvent event;
bool enabled;
};

struct KQueue : orbis::File {
std::list<KNote, kallocator<KNote>> notes;
};

static constexpr auto kEvFiltRead = -1;
static constexpr auto kEvFiltWrite = -2;
static constexpr auto kEvFiltAio = -3;
static constexpr auto kEvFiltVnode = -4;
static constexpr auto kEvFiltProc = -5;
static constexpr auto kEvFiltSignal = -6;
static constexpr auto kEvFiltTimer = -7;
static constexpr auto kEvFiltFs = -9;
static constexpr auto kEvFiltLio = -10;
static constexpr auto kEvFiltUser = -11;
static constexpr auto kEvFiltPolling = -12;
static constexpr auto kEvFiltDisplay = -13;
static constexpr auto kEvFiltGraphicsCore = -14;
static constexpr auto kEvFiltHrTimer = -15;
static constexpr auto kEvFiltUvdTrap = -16;
static constexpr auto kEvFiltVceTrap = -17;
static constexpr auto kEvFiltSdmaTrap = -18;
static constexpr auto kEvFiltRegEv = -19;
static constexpr auto kEvFiltGpuException = -20;
static constexpr auto kEvFiltGpuSystemException = -21;
static constexpr auto kEvFiltGpuDbgGcEv = -22;
static constexpr auto kEvFiltSysCount = 22;

// actions
static constexpr auto kEvAdd = 0x0001;
static constexpr auto kEvDelete = 0x0002;
static constexpr auto kEvEnable = 0x0004;
static constexpr auto kEvDisable = 0x0008;

// flags
static constexpr auto kEvOneshot = 0x0010;
static constexpr auto kEvClear = 0x0020;
static constexpr auto kEvReceipt = 0x0040;
static constexpr auto kEvDispatch = 0x0080;
static constexpr auto kEvSysFlags = 0xf000;
static constexpr auto kEvFlag1 = 0x2000;

static constexpr auto kEvEof = 0x8000;
static constexpr auto kEvError = 0x4000;
} // namespace orbis

orbis::SysResult orbis::sys_kqueue(Thread *thread) {
ORBIS_LOG_TODO(__FUNCTION__);
auto queue = knew<KQueue>();
if (queue == nullptr) {
return ErrorCode::NOMEM;
}

thread->retval[0] = thread->tproc->fileDescriptors.insert(queue);
auto fd = thread->tproc->fileDescriptors.insert(queue);
ORBIS_LOG_TODO(__FUNCTION__, fd);
thread->retval[0] = fd;
return {};
}

orbis::SysResult orbis::sys_kqueueex(Thread *thread, ptr<char> name, sint flags) {
auto queue = knew<KQueue>();
if (queue == nullptr) {
return ErrorCode::NOMEM;
}

auto fd = thread->tproc->fileDescriptors.insert(queue);
ORBIS_LOG_TODO(__FUNCTION__, name, flags, fd);
thread->retval[0] = fd;
return {};
}

orbis::SysResult orbis::sys_kevent(Thread *thread, sint fd,
ptr<KEvent> changelist, sint nchanges,
ptr<KEvent> eventlist, sint nevents,
ptr<const timespec> timeout) {
// ORBIS_LOG_TODO(__FUNCTION__, fd);
thread->retval[0] = 1;
// ORBIS_LOG_TODO(__FUNCTION__, fd, changelist, nchanges, eventlist, nevents,
// timeout);
Ref<File> kqf = thread->tproc->fileDescriptors.get(fd);
if (kqf == nullptr) {
return orbis::ErrorCode::BADF;
}

std::lock_guard lock(kqf->mtx);

auto kq = dynamic_cast<KQueue *>(kqf.get());

if (kq == nullptr) {
return orbis::ErrorCode::BADF;
}


if (nchanges != 0) {
for (auto change : std::span(changelist, nchanges)) {
ORBIS_LOG_TODO(__FUNCTION__, change.ident, change.filter, change.flags,
change.fflags, change.data, change.udata);

if (change.flags & kEvAdd) {
if (change.filter != kEvFiltDisplay && change.filter != kEvFiltGraphicsCore) {
std::abort();
}

kq->notes.push_back({
.event = change,
.enabled = (change.flags & kEvDisable) == 0
});

kq->notes.back().event.flags &= ~(kEvAdd | kEvClear | kEvDelete | kEvDisable);
}

// TODO
}
}

std::vector<KEvent> result;
result.reserve(nevents);

for (auto &note : kq->notes) {
if (result.size() >= nevents) {
break;
}

if (!note.enabled) {
continue;
}

if (note.event.filter == kEvFiltDisplay || note.event.filter == kEvFiltGraphicsCore) {
result.push_back(note.event);
}
}

std::memcpy(eventlist, result.data(), result.size() * sizeof(KEvent));
thread->retval[0] = result.size();
return {};
}
2 changes: 1 addition & 1 deletion orbis-kernel/src/sys/sys_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ static std::string ioctlToString(unsigned long arg) {
orbis::SysResult orbis::sys_ioctl(Thread *thread, sint fd, ulong com,
caddr_t data) {
auto str = ioctlToString(com);
ORBIS_LOG_WARNING(__FUNCTION__, fd, com, str);
// ORBIS_LOG_WARNING(__FUNCTION__, fd, com, str);
Ref<File> file = thread->tproc->fileDescriptors.get(fd);
if (file == nullptr) {
return ErrorCode::BADF;
Expand Down
Loading

0 comments on commit bfdfe82

Please sign in to comment.