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,
rx::EnumBitSet<vmem::Protection> protection, File *file,
Process *process);
[[nodiscard]] virtual std::string toString() const;
};
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 id(std::uint32_t cmd) { return cmd & 0xff; }
std::string groupToString(unsigned iocGroup);
} // namespace ioctl
struct IoctlHandlerEntry;
@ -201,5 +205,9 @@ template <int Group> struct IoDeviceWithIoctl : IoDevice {
return ioctlTable[id].handler(thread, argp, this, ioctlTable[id].impl);
}
[[nodiscard]] std::string toString() const override {
return ioctl::groupToString(Group) + " " + IoDevice::toString();
}
};
} // namespace orbis

View file

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

View file

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

View file

@ -1,11 +1,12 @@
#include "IoDevice.hpp"
#include "file.hpp"
#include "rx/Mappable.hpp"
#include "rx/format-base.hpp"
#include "thread/Thread.hpp"
#include "utils/Logs.hpp"
#include "vmem.hpp"
static std::string iocGroupToString(unsigned iocGroup) {
std::string orbis::ioctl::groupToString(unsigned iocGroup) {
if (iocGroup >= 128) {
const char *sceGroups[] = {
"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::ptr<void> argp, Thread *thread) {
auto group = iocGroupToString(ioctl::group(request));
auto group = ioctl::groupToString(ioctl::group(request));
auto paramSize = ioctl::paramSize(request);
ORBIS_LOG_ERROR("unhandled ioctl", request, group, paramSize, argp,
thread->tid);
thread->where();
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;
result.narg = sizeof...(Args);
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);
result += "(";
@ -134,7 +134,9 @@ struct WrapImpl<Fn> {
} else if constexpr (std::is_pointer_v<type>) {
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) {
// 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) {
rx::formatter<type>().parse(ctx);
}) {