orbis: improve fd tracing
Some checks are pending
Formatting check / formatting-check (push) Waiting to run
Build RPCSX / build-linux (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8.1-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8.2-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8.4-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv8.5-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv9-a) (push) Waiting to run
Build RPCSX / build-android (arm64-v8a, armv9.1-a) (push) Waiting to run
Build RPCSX / build-android (x86_64, x86-64) (push) Waiting to run

This commit is contained in:
DH 2025-12-03 21:06:11 +03:00
parent 7c3ee53d6e
commit 566ad3edd8
10 changed files with 100 additions and 34 deletions

View file

@ -76,6 +76,8 @@ struct IoDevice : rx::RcBase {
virtual ErrorCode map(rx::AddressRange range, std::int64_t offset, virtual ErrorCode map(rx::AddressRange range, std::int64_t offset,
rx::EnumBitSet<vmem::Protection> protection, File *file, rx::EnumBitSet<vmem::Protection> protection, File *file,
Process *process); Process *process);
[[nodiscard]] virtual std::string toString() const;
}; };
namespace ioctl { namespace ioctl {
@ -95,6 +97,8 @@ constexpr std::uint32_t paramSize(std::uint32_t cmd) {
} }
constexpr std::uint32_t group(std::uint32_t cmd) { return (cmd >> 8) & 0xff; } constexpr std::uint32_t group(std::uint32_t cmd) { return (cmd >> 8) & 0xff; }
constexpr std::uint32_t id(std::uint32_t cmd) { return cmd & 0xff; } constexpr std::uint32_t id(std::uint32_t cmd) { return cmd & 0xff; }
std::string groupToString(unsigned iocGroup);
} // namespace ioctl } // namespace ioctl
struct IoctlHandlerEntry; struct IoctlHandlerEntry;
@ -201,5 +205,9 @@ template <int Group> struct IoDeviceWithIoctl : IoDevice {
return ioctlTable[id].handler(thread, argp, this, ioctlTable[id].impl); return ioctlTable[id].handler(thread, argp, this, ioctlTable[id].impl);
} }
[[nodiscard]] std::string toString() const override {
return ioctl::groupToString(Group) + " " + IoDevice::toString();
}
}; };
} // namespace orbis } // namespace orbis

View file

@ -43,32 +43,32 @@ struct FileOps {
// TODO: chown // TODO: chown
// TODO: chmod // TODO: chmod
ErrorCode (*bind)(orbis::File *file, SocketAddress *address, ErrorCode (*bind)(File *file, SocketAddress *address, std::size_t addressLen,
std::size_t addressLen, Thread *thread) = nullptr; Thread *thread) = nullptr;
ErrorCode (*listen)(orbis::File *file, int backlog, Thread *thread) = nullptr; ErrorCode (*listen)(File *file, int backlog, Thread *thread) = nullptr;
ErrorCode (*accept)(orbis::File *file, SocketAddress *address, ErrorCode (*accept)(File *file, SocketAddress *address,
std::uint32_t *addressLen, Thread *thread) = nullptr; std::uint32_t *addressLen, Thread *thread) = nullptr;
ErrorCode (*connect)(orbis::File *file, SocketAddress *address, ErrorCode (*connect)(File *file, SocketAddress *address,
std::uint32_t addressLen, Thread *thread) = nullptr; std::uint32_t addressLen, Thread *thread) = nullptr;
ErrorCode (*sendto)(orbis::File *file, const void *buf, size_t len, ErrorCode (*sendto)(File *file, const void *buf, size_t len, sint flags,
sint flags, caddr_t to, sint tolen, caddr_t to, sint tolen, Thread *thread) = nullptr;
ErrorCode (*sendmsg)(File *file, msghdr *msg, sint flags,
Thread *thread) = nullptr; Thread *thread) = nullptr;
ErrorCode (*sendmsg)(orbis::File *file, msghdr *msg, sint flags, ErrorCode (*recvfrom)(File *file, void *buf, size_t len, sint flags,
Thread *thread) = nullptr;
ErrorCode (*recvfrom)(orbis::File *file, void *buf, size_t len, sint flags,
SocketAddress *from, uint32_t *fromlenaddr, SocketAddress *from, uint32_t *fromlenaddr,
Thread *thread) = nullptr; Thread *thread) = nullptr;
ErrorCode (*recvmsg)(orbis::File *file, msghdr *msg, sint flags, ErrorCode (*recvmsg)(File *file, msghdr *msg, sint flags,
Thread *thread) = nullptr; Thread *thread) = nullptr;
ErrorCode (*shutdown)(orbis::File *file, sint how, Thread *thread) = nullptr; ErrorCode (*shutdown)(File *file, sint how, Thread *thread) = nullptr;
ErrorCode (*setsockopt)(orbis::File *file, sint level, sint name, ErrorCode (*setsockopt)(File *file, sint level, sint name, const void *val,
const void *val, sint valsize, sint valsize, Thread *thread) = nullptr;
Thread *thread) = nullptr; ErrorCode (*getsockopt)(File *file, sint level, sint name, void *val,
ErrorCode (*getsockopt)(orbis::File *file, sint level, sint name, void *val,
sint *avalsize, Thread *thread) = nullptr; sint *avalsize, Thread *thread) = nullptr;
ErrorCode (*sendfile)(orbis::File *file, sint fd, off_t offset, size_t nbytes, ErrorCode (*sendfile)(File *file, sint fd, off_t offset, size_t nbytes,
ptr<struct sf_hdtr> hdtr, ptr<off_t> sbytes, sint flags, ptr<struct sf_hdtr> hdtr, ptr<off_t> sbytes, sint flags,
Thread *thread) = nullptr; Thread *thread) = nullptr;
std::string (*toString)(File *file, Thread *thread);
}; };
struct File : rx::RcBase { struct File : rx::RcBase {

View file

@ -10,7 +10,7 @@ using sy_call_t = SysResult(Thread *, uint64_t *);
struct sysent { struct sysent {
sint narg; sint narg;
sy_call_t *call; sy_call_t *call;
std::string (*format)(uint64_t *); std::string (*format)(Thread *, uint64_t *);
}; };
struct sysentvec { struct sysentvec {

View file

@ -1,11 +1,12 @@
#include "IoDevice.hpp" #include "IoDevice.hpp"
#include "file.hpp" #include "file.hpp"
#include "rx/Mappable.hpp" #include "rx/Mappable.hpp"
#include "rx/format-base.hpp"
#include "thread/Thread.hpp" #include "thread/Thread.hpp"
#include "utils/Logs.hpp" #include "utils/Logs.hpp"
#include "vmem.hpp" #include "vmem.hpp"
static std::string iocGroupToString(unsigned iocGroup) { std::string orbis::ioctl::groupToString(unsigned iocGroup) {
if (iocGroup >= 128) { if (iocGroup >= 128) {
const char *sceGroups[] = { const char *sceGroups[] = {
"DEV", "DEV",
@ -86,10 +87,14 @@ orbis::IoDevice::map(rx::AddressRange range, std::int64_t offset,
orbis::ErrorCode orbis::IoDevice::ioctl(std::uint64_t request, orbis::ErrorCode orbis::IoDevice::ioctl(std::uint64_t request,
orbis::ptr<void> argp, Thread *thread) { orbis::ptr<void> argp, Thread *thread) {
auto group = iocGroupToString(ioctl::group(request)); auto group = ioctl::groupToString(ioctl::group(request));
auto paramSize = ioctl::paramSize(request); auto paramSize = ioctl::paramSize(request);
ORBIS_LOG_ERROR("unhandled ioctl", request, group, paramSize, argp, ORBIS_LOG_ERROR("unhandled ioctl", request, group, paramSize, argp,
thread->tid); thread->tid);
thread->where(); thread->where();
return ErrorCode::NOTSUP; return ErrorCode::NOTSUP;
} }
std::string orbis::IoDevice::toString() const {
return rx::format("{}", static_cast<const void *>(this));
}

View file

@ -106,7 +106,7 @@ struct WrapImpl<Fn> {
sysent result; sysent result;
result.narg = sizeof...(Args); result.narg = sizeof...(Args);
result.call = &WrapImpl::call; result.call = &WrapImpl::call;
result.format = [](uint64_t *values) -> std::string { result.format = [](Thread *thread, uint64_t *values) -> std::string {
std::string result = getSysentName(&WrapImpl::call); std::string result = getSysentName(&WrapImpl::call);
result += "("; result += "(";
@ -134,7 +134,9 @@ struct WrapImpl<Fn> {
} else if constexpr (std::is_pointer_v<type>) { } else if constexpr (std::is_pointer_v<type>) {
result += rx::format("{}", (void *)value); result += rx::format("{}", (void *)value);
// using pointee = std::remove_cvref_t<std::remove_pointer_t<type>>; // using pointee =
// std::remove_cvref_t<std::remove_pointer_t<type>>;
//
// if constexpr (requires(rx::format_parse_context &ctx) { // if constexpr (requires(rx::format_parse_context &ctx) {
// rx::formatter<pointee>().parse(ctx); // rx::formatter<pointee>().parse(ctx);
// }) { // }) {
@ -149,6 +151,27 @@ struct WrapImpl<Fn> {
// } // }
// } // }
// } // }
} else if constexpr (std::is_same_v<type, FileDescriptor>) {
result += rx::format("{}", std::to_underlying(value));
if (std::to_underlying(value) >= 0) {
auto file = thread->tproc->fileDescriptors.get(value);
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 += "<null device>";
}
} else {
result += "<invalid fd>";
}
result += ")";
}
} else if constexpr (requires(rx::format_parse_context &ctx) { } else if constexpr (requires(rx::format_parse_context &ctx) {
rx::formatter<type>().parse(ctx); rx::formatter<type>().parse(ctx);
}) { }) {

View file

@ -10,6 +10,7 @@
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "orbis/vmem.hpp" #include "orbis/vmem.hpp"
#include "rx/Mappable.hpp" #include "rx/Mappable.hpp"
#include "rx/format-base.hpp"
#include "vfs.hpp" #include "vfs.hpp"
#include <cerrno> #include <cerrno>
#include <dirent.h> #include <dirent.h>
@ -33,6 +34,7 @@
struct HostFile : orbis::File { struct HostFile : orbis::File {
bool closeOnExit = true; bool closeOnExit = true;
bool alignTruncate = false; bool alignTruncate = false;
orbis::kstring path;
~HostFile() { ~HostFile() {
if (!closeOnExit && hostFd) { if (!closeOnExit && hostFd) {
@ -611,11 +613,26 @@ orbis::ErrorCode socket_recvfrom(orbis::File *file, void *buf,
return orbis::ErrorCode::NOTSUP; return orbis::ErrorCode::NOTSUP;
} }
static std::string host_toString(orbis::File *file, orbis::Thread *thread) {
auto hostFile = static_cast<HostFile *>(file);
if (!hostFile->path.empty()) {
std::string result;
result += '"';
result += hostFile->path;
result += '"';
return result;
}
return rx::format("host fd {}", hostFile->hostFd.native_handle());
}
static const orbis::FileOps hostOps = { static const orbis::FileOps hostOps = {
.read = host_read, .read = host_read,
.write = host_write, .write = host_write,
.truncate = host_truncate, .truncate = host_truncate,
.stat = host_stat, .stat = host_stat,
.toString = host_toString,
}; };
static const orbis::FileOps socketOps = { static const orbis::FileOps socketOps = {
@ -828,6 +845,7 @@ orbis::ErrorCode HostFsDevice::open(rx::Ref<orbis::File> *file,
newFile->dirEntries = std::move(dirEntries); newFile->dirEntries = std::move(dirEntries);
newFile->ops = &hostOps; newFile->ops = &hostOps;
newFile->device = this; newFile->device = this;
newFile->path = path;
*file = newFile; *file = newFile;
return {}; return {};
} }

View file

@ -9,6 +9,7 @@
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "rx/Rc.hpp" #include "rx/Rc.hpp"
#include <bits/types/struct_iovec.h> #include <bits/types/struct_iovec.h>
#include <string>
// #include <rx/hexdump.hpp> // #include <rx/hexdump.hpp>
#define SNDCTL_DSP_RESET 0x20005000 #define SNDCTL_DSP_RESET 0x20005000
@ -37,6 +38,10 @@ struct AoutDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path, orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode, std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override; orbis::Thread *thread) override;
[[nodiscard]] std::string toString() const override {
return "aout" + std::to_string(id);
}
}; };
static orbis::ErrorCode aout_ioctl(orbis::File *file, std::uint64_t request, static orbis::ErrorCode aout_ioctl(orbis::File *file, std::uint64_t request,

View file

@ -51,6 +51,8 @@ struct BlockPoolDevice
orbis::ErrorCode map(rx::AddressRange range, std::int64_t offset, orbis::ErrorCode map(rx::AddressRange range, std::int64_t offset,
rx::EnumBitSet<orbis::vmem::Protection> protection, rx::EnumBitSet<orbis::vmem::Protection> protection,
orbis::File *file, orbis::Process *process) override; orbis::File *file, orbis::Process *process) override;
[[nodiscard]] std::string toString() const override { return "blockpool"; }
}; };
#pragma pack(push, 1) #pragma pack(push, 1)

View file

@ -9,9 +9,10 @@
#include "orbis/thread/Thread.hpp" #include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "orbis/vmem.hpp" #include "orbis/vmem.hpp"
#include "rx/format.hpp"
#include "rx/AddressRange.hpp" #include "rx/AddressRange.hpp"
#include "rx/EnumBitSet.hpp" #include "rx/EnumBitSet.hpp"
#include "rx/format.hpp"
#include <string>
enum { enum {
DMEM_IOCTL_ALLOCATE = 0xc0288001, DMEM_IOCTL_ALLOCATE = 0xc0288001,
@ -42,6 +43,10 @@ struct DmemDevice
orbis::ErrorCode map(rx::AddressRange range, std::int64_t offset, orbis::ErrorCode map(rx::AddressRange range, std::int64_t offset,
rx::EnumBitSet<orbis::vmem::Protection> protection, rx::EnumBitSet<orbis::vmem::Protection> protection,
orbis::File *file, orbis::Process *process) override; orbis::File *file, orbis::Process *process) override;
[[nodiscard]] std::string toString() const override {
return "dmem" + std::to_string(index);
}
}; };
struct DmemFile : public orbis::File {}; struct DmemFile : public orbis::File {};

View file

@ -15,6 +15,7 @@
#include "orbis/utils/Logs.hpp" #include "orbis/utils/Logs.hpp"
#include "orbis/vmem.hpp" #include "orbis/vmem.hpp"
#include "rx/Config.hpp" #include "rx/Config.hpp"
#include "rx/FileLock.hpp"
#include "rx/die.hpp" #include "rx/die.hpp"
#include "rx/format.hpp" #include "rx/format.hpp"
#include "rx/mem.hpp" #include "rx/mem.hpp"
@ -299,26 +300,26 @@ static void onSysEnter(orbis::Thread *thread, int id, uint64_t *args,
if (!g_traceSyscalls) { if (!g_traceSyscalls) {
return; return;
} }
flockfile(stderr);
std::fprintf(stderr, " [%u] ", thread->tid); rx::ScopedFileLock lock(stderr);
rx::print(stderr, " [{}] ", thread->tid);
if (auto ent = getSyscallEnt(thread, id)) { if (auto ent = getSyscallEnt(thread, id)) {
std::fprintf(stderr, "%s\n", ent->format(args).c_str()); rx::println(stderr, "{}", ent->format(thread, args).c_str());
return; return;
} }
std::fprintf(stderr, "sys_%u(", id); rx::print(stderr, "sys_{}(", id);
for (int i = 0; i < argsCount; ++i) { for (int i = 0; i < argsCount; ++i) {
if (i != 0) { if (i != 0) {
std::fprintf(stderr, ", "); rx::print(stderr, ", ");
} }
std::fprintf(stderr, "%#lx", args[i]); rx::print(stderr, "{:#x}", args[i]);
} }
std::fprintf(stderr, ")\n"); rx::println(stderr, ")");
funlockfile(stderr);
} }
static void onSysExit(orbis::Thread *thread, int id, uint64_t *args, static void onSysExit(orbis::Thread *thread, int id, uint64_t *args,
@ -327,11 +328,11 @@ static void onSysExit(orbis::Thread *thread, int id, uint64_t *args,
return; return;
} }
flockfile(stderr); rx::ScopedFileLock lock(stderr);
rx::print(stderr, "{}: [{}] ", result.isError() ? 'E' : 'S', thread->tid); rx::print(stderr, "{}: [{}] ", result.isError() ? 'E' : 'S', thread->tid);
if (auto ent = getSyscallEnt(thread, id)) { if (auto ent = getSyscallEnt(thread, id)) {
rx::print(stderr, "{}", ent->format(args)); rx::print(stderr, "{}", ent->format(thread, args));
} else { } else {
rx::print(stderr, "sys_{}(", id); rx::print(stderr, "sys_{}(", id);
@ -352,7 +353,6 @@ static void onSysExit(orbis::Thread *thread, int id, uint64_t *args,
if (result.isError()) { if (result.isError()) {
thread->where(); thread->where();
} }
funlockfile(stderr);
} }
static void guestInitDev(orbis::Thread *thread, int stdinFd, int stdoutFd, static void guestInitDev(orbis::Thread *thread, int stdinFd, int stdoutFd,