diff --git a/kernel/orbis/CMakeLists.txt b/kernel/orbis/CMakeLists.txt index e7981e1e6..22a44f62a 100644 --- a/kernel/orbis/CMakeLists.txt +++ b/kernel/orbis/CMakeLists.txt @@ -5,6 +5,7 @@ add_library(obj.orbis-kernel OBJECT src/dmem.cpp src/event.cpp src/evf.cpp + src/file.cpp src/fmem.cpp src/IoDevice.cpp src/ipmi.cpp diff --git a/kernel/orbis/include/orbis/file.hpp b/kernel/orbis/include/orbis/file.hpp index 75953a8e7..b597e5f27 100644 --- a/kernel/orbis/include/orbis/file.hpp +++ b/kernel/orbis/include/orbis/file.hpp @@ -68,7 +68,7 @@ struct FileOps { ptr hdtr, ptr sbytes, sint flags, Thread *thread) = nullptr; - std::string (*toString)(File *file, Thread *thread); + std::string (*toString)(File *file); }; struct File : rx::RcBase { @@ -83,5 +83,6 @@ struct File : rx::RcBase { kvector dirEntries; bool noBlock() const { return (flags & 4) != 0; } + std::string toString(); }; } // namespace orbis diff --git a/kernel/orbis/include/orbis/thread/Process.hpp b/kernel/orbis/include/orbis/thread/Process.hpp index b368ec31c..20bbedcc1 100644 --- a/kernel/orbis/include/orbis/thread/Process.hpp +++ b/kernel/orbis/include/orbis/thread/Process.hpp @@ -8,6 +8,7 @@ #include "../ipmi.hpp" #include "../osem.hpp" #include "Thread.hpp" +#include "rx/StaticString.hpp" #include "types.hpp" #include "ProcessState.hpp" #include "cpuset.hpp" @@ -108,7 +109,7 @@ struct Process final { // Named objects for debugging rx::shared_mutex namedObjMutex; - kmap namedObjNames; + kmap> namedObjNames; rx::OwningIdMap namedObjIds; kmap sigActions; @@ -127,6 +128,7 @@ struct Process final { return ref.get(storage); } + rx::StaticString<32> getNameOfObject(ptr addr); Budget *getBudget() const; template diff --git a/kernel/orbis/src/file.cpp b/kernel/orbis/src/file.cpp new file mode 100644 index 000000000..b46ca1fa7 --- /dev/null +++ b/kernel/orbis/src/file.cpp @@ -0,0 +1,13 @@ +#include "file.hpp" + +std::string orbis::File::toString() { + if (ops && ops->toString) { + return ops->toString(this); + } + + if (device) { + return device->toString(); + } + + return ""; +} diff --git a/kernel/orbis/src/sys/sys_event.cpp b/kernel/orbis/src/sys/sys_event.cpp index 3f42edf91..ae26fb4d4 100644 --- a/kernel/orbis/src/sys/sys_event.cpp +++ b/kernel/orbis/src/sys/sys_event.cpp @@ -1,5 +1,6 @@ #include "KernelAllocator.hpp" #include "KernelContext.hpp" +#include "rx/format-base.hpp" #include "sys/sysproto.hpp" #include "thread/Process.hpp" @@ -13,11 +14,98 @@ #include #endif +static std::string filterToString(orbis::sshort filter) { + switch (filter) { + case orbis::kEvFiltRead: + return "Read"; + case orbis::kEvFiltWrite: + return "Write"; + case orbis::kEvFiltAio: + return "Aio"; + case orbis::kEvFiltVnode: + return "Vnode"; + case orbis::kEvFiltProc: + return "Proc"; + case orbis::kEvFiltSignal: + return "Signal"; + case orbis::kEvFiltTimer: + return "Timer"; + case orbis::kEvFiltFs: + return "Fs"; + case orbis::kEvFiltLio: + return "Lio"; + case orbis::kEvFiltUser: + return "User"; + case orbis::kEvFiltPolling: + return "Polling"; + case orbis::kEvFiltDisplay: + return "Display"; + case orbis::kEvFiltGraphicsCore: + return "GraphicsCore"; + case orbis::kEvFiltHrTimer: + return "HrTimer"; + case orbis::kEvFiltUvdTrap: + return "UvdTrap"; + case orbis::kEvFiltVceTrap: + return "VceTrap"; + case orbis::kEvFiltSdmaTrap: + return "SdmaTrap"; + case orbis::kEvFiltRegEv: + return "RegEv"; + case orbis::kEvFiltGpuException: + return "GpuException"; + case orbis::kEvFiltGpuSystemException: + return "GpuSystemException"; + case orbis::kEvFiltGpuDbgGcEv: + return "GpuDbgGcEv"; + } + + return ""; +} + +static std::string kqueue_toString(orbis::File *file) { + auto queue = static_cast(file); + + std::string result = "kqueue"; + + if (!queue->name.empty()) { + result += " \""; + result += queue->name; + result += "\""; + } + + result += " {"; + + for (auto ¬e : queue->notes) { + result += " knote {"; + result += filterToString(note.event.filter); + + if (auto file = note.file) { + result += " "; + result += file->toString(); + } + + result += rx::format( + " ident {:#x}, flags {:#x} fflags {:#x}, data {:#x}, udata {}", + note.event.ident, note.event.flags, note.event.fflags, note.event.data, + note.event.udata); + result += "}"; + } + result += " }"; + + return result; +} + +static orbis::FileOps kqueueOps = { + .toString = kqueue_toString, +}; + orbis::SysResult orbis::sys_kqueue(Thread *thread) { auto queue = knew(); if (queue == nullptr) { return ErrorCode::NOMEM; } + queue->ops = &kqueueOps; auto fd = thread->tproc->fileDescriptors.insert(queue); ORBIS_LOG_TODO(__FUNCTION__, (int)fd); @@ -36,6 +124,7 @@ orbis::SysResult orbis::sys_kqueueex(Thread *thread, ptr name, if (name != nullptr) { queue->name = name; } + queue->ops = &kqueueOps; ORBIS_LOG_TODO(__FUNCTION__, name, flags, (int)fd); thread->retval[0] = std::to_underlying(fd); return {}; diff --git a/kernel/orbis/src/sysvec.cpp b/kernel/orbis/src/sysvec.cpp index aae20789d..2ca2cb292 100644 --- a/kernel/orbis/src/sysvec.cpp +++ b/kernel/orbis/src/sysvec.cpp @@ -158,14 +158,7 @@ struct WrapImpl { result += " ("; if (file) { - if (file->ops && file->ops->toString) { - result += file->ops->toString(file.get(), thread); - } else if (file->device) { - result += file->device->toString(); - } else { - result += ""; - } - + result += file->toString(); } else { result += ""; } diff --git a/kernel/orbis/src/thread/Process.cpp b/kernel/orbis/src/thread/Process.cpp index 1a83e0c43..b5412cf34 100644 --- a/kernel/orbis/src/thread/Process.cpp +++ b/kernel/orbis/src/thread/Process.cpp @@ -326,6 +326,15 @@ orbis::Process *orbis::createProcess(Process *parentProcess, pid_t pid) { return &result->object; } +rx::StaticString<32> +orbis::Process::getNameOfObject(ptr addr) { + std::lock_guard lock(namedObjMutex); + if (auto it = namedObjNames.find(addr); it != namedObjNames.end()) { + return it->second; + } + return {}; +} + orbis::Budget *orbis::Process::getBudget() const { auto result = g_context->budgets.get(budgetId); diff --git a/rpcsx/io-device.cpp b/rpcsx/io-device.cpp index 655381947..e0ec81aef 100644 --- a/rpcsx/io-device.cpp +++ b/rpcsx/io-device.cpp @@ -613,7 +613,7 @@ orbis::ErrorCode socket_recvfrom(orbis::File *file, void *buf, return orbis::ErrorCode::NOTSUP; } -static std::string host_toString(orbis::File *file, orbis::Thread *thread) { +static std::string host_toString(orbis::File *file) { auto hostFile = static_cast(file); if (!hostFile->path.empty()) {