diff --git a/orbis-kernel/include/orbis/sys/sysproto.hpp b/orbis-kernel/include/orbis/sys/sysproto.hpp index 66bacced2..7b9075677 100644 --- a/orbis-kernel/include/orbis/sys/sysproto.hpp +++ b/orbis-kernel/include/orbis/sys/sysproto.hpp @@ -607,7 +607,7 @@ SysResult sys_netabort(Thread *thread /* TODO */); SysResult sys_netgetsockinfo(Thread *thread /* TODO */); SysResult sys_socketex(Thread *thread, ptr name, sint domain, sint type, sint protocol); -SysResult sys_socketclose(Thread *thread /* TODO */); +SysResult sys_socketclose(Thread *thread, sint fd); SysResult sys_netgetiflist(Thread *thread /* TODO */); SysResult sys_kqueueex(Thread *thread /* TODO */); SysResult sys_mtypeprotect(Thread *thread /* TODO */); diff --git a/orbis-kernel/include/orbis/thread/ProcessOps.hpp b/orbis-kernel/include/orbis/thread/ProcessOps.hpp index 964b6eef2..32330fe63 100644 --- a/orbis-kernel/include/orbis/thread/ProcessOps.hpp +++ b/orbis-kernel/include/orbis/thread/ProcessOps.hpp @@ -30,6 +30,8 @@ struct ProcessOps { SysResult (*open)(Thread *thread, ptr path, sint flags, sint mode); + SysResult (*socket)(Thread *thread, ptr name, sint domain, + sint type, sint protocol); SysResult (*close)(Thread *thread, sint fd); SysResult (*ioctl)(Thread *thread, sint fd, ulong com, caddr_t argp); SysResult (*write)(Thread *thread, sint fd, ptr data, ulong size); diff --git a/orbis-kernel/src/sys/sys_descrip.cpp b/orbis-kernel/src/sys/sys_descrip.cpp index 6a1952667..5899aef54 100644 --- a/orbis-kernel/src/sys/sys_descrip.cpp +++ b/orbis-kernel/src/sys/sys_descrip.cpp @@ -16,6 +16,7 @@ orbis::SysResult orbis::sys_fcntl(Thread *thread, sint fd, sint cmd, return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_close(Thread *thread, sint fd) { + ORBIS_LOG_NOTICE(__FUNCTION__, fd); if (auto close = thread->tproc->ops->close) { return close(thread, fd); } diff --git a/orbis-kernel/src/sys/sys_generic.cpp b/orbis-kernel/src/sys/sys_generic.cpp index 7bbf5ec10..923a7664d 100644 --- a/orbis-kernel/src/sys/sys_generic.cpp +++ b/orbis-kernel/src/sys/sys_generic.cpp @@ -75,6 +75,7 @@ orbis::SysResult orbis::sys_freebsd6_ftruncate(Thread *thread, sint fd, sint, } orbis::SysResult orbis::sys_ioctl(Thread *thread, sint fd, ulong com, caddr_t data) { + ORBIS_LOG_WARNING(__FUNCTION__, fd, com); if (auto ioctl = thread->tproc->ops->ioctl) { return ioctl(thread, fd, com, data); } diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp index 3be7aad18..75deaa4bb 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -22,10 +22,20 @@ orbis::SysResult orbis::sys_netgetsockinfo(Thread *thread /* TODO */) { } orbis::SysResult orbis::sys_socketex(Thread *thread, ptr name, sint domain, sint type, sint protocol) { - return {}; + ORBIS_LOG_TODO(__FUNCTION__, name, domain, type, protocol); + if (auto socket = thread->tproc->ops->socket) { + return socket(thread, name, domain, type, protocol); + } + return ErrorCode::NOSYS; } -orbis::SysResult orbis::sys_socketclose(Thread *thread /* TODO */) { - return {}; +orbis::SysResult orbis::sys_socketclose(Thread *thread, sint fd) { + // This syscall is identical to sys_close + ORBIS_LOG_NOTICE(__FUNCTION__, fd); + if (auto close = thread->tproc->ops->close) { + return close(thread, fd); + } + + return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_netgetiflist(Thread *thread /* TODO */) { return ErrorCode::NOSYS; diff --git a/rpcsx-os/io-device.cpp b/rpcsx-os/io-device.cpp index 1b306fb35..8ec2ec995 100644 --- a/rpcsx-os/io-device.cpp +++ b/rpcsx-os/io-device.cpp @@ -1,7 +1,9 @@ #include "io-device.hpp" #include "orbis/KernelAllocator.hpp" +#include "orbis/utils/Logs.hpp" #include #include +#include #include std::int64_t io_device_instance_close(IoDeviceInstance *instance) { return 0; } @@ -24,6 +26,11 @@ struct HostIoDeviceInstance : IoDeviceInstance { int hostFd; }; +struct SocketDeviceInstance : IoDeviceInstance { + orbis::utils::kstring name; + int hostFd; +}; + static std::int64_t host_io_device_instance_read(IoDeviceInstance *instance, void *data, std::uint64_t size) { @@ -130,3 +137,25 @@ IoDevice *createHostIoDevice(const char *hostPath) { result->hostPath = hostPath; return result; } + +static std::int64_t socket_instance_ioctl(IoDeviceInstance *instance, + std::uint64_t request, void *argp) { + + ORBIS_LOG_FATAL("Unhandled socket ioctl", request); + return 0; +} + +static std::int64_t socket_instance_close(IoDeviceInstance *instance) { + return 0; +} + +orbis::ErrorCode createSocket(const char *name, int dom, int type, int prot, + orbis::Ref *instance) { + auto s = orbis::knew(); + s->ioctl = socket_instance_ioctl; + s->close = socket_instance_close; + s->name = name; + s->hostFd = ::socket(dom, type, prot); + *instance = s; + return {}; +} diff --git a/rpcsx-os/io-device.hpp b/rpcsx-os/io-device.hpp index fccdc4a77..e69c4a742 100644 --- a/rpcsx-os/io-device.hpp +++ b/rpcsx-os/io-device.hpp @@ -4,6 +4,9 @@ #include struct IoDevice; +namespace orbis { +enum class ErrorCode : int; +} enum OpenFlags { kOpenFlagReadOnly = 0x0, @@ -53,3 +56,5 @@ std::int64_t io_device_instance_close(IoDeviceInstance *instance); void io_device_instance_init(IoDevice *device, IoDeviceInstance *instance); IoDevice *createHostIoDevice(const char *hostPath); +orbis::ErrorCode createSocket(const char *name, int dom, int type, int prot, + orbis::Ref *instance); diff --git a/rpcsx-os/ops.cpp b/rpcsx-os/ops.cpp index d12fd4796..0a34eee01 100644 --- a/rpcsx-os/ops.cpp +++ b/rpcsx-os/ops.cpp @@ -130,7 +130,8 @@ orbis::SysResult mmap(orbis::Thread *thread, orbis::caddr_t addr, if (handle->mmap != nullptr) { result = handle->mmap(handle.get(), addr, len, prot, flags, pos); } else { - std::printf("unimplemented mmap for fd %d\n", static_cast(fd)); + ORBIS_LOG_FATAL("unimplemented mmap", fd, (void *)addr, len, prot, flags, + pos); result = rx::vm::map(addr, len, prot, flags); } } @@ -207,13 +208,29 @@ orbis::SysResult open(orbis::Thread *thread, orbis::ptr path, orbis::Ref instance; auto result = rx::vfs::open(path, flags, mode, &instance); if (result.isError()) { - ORBIS_LOG_WARNING("sys_open: failed to open", path, result.value()); + ORBIS_LOG_WARNING("Failed to open file", path, result.value()); return result; } auto fd = thread->tproc->fileDescriptors.insert(instance); thread->retval[0] = fd; - ORBIS_LOG_WARNING("sys_open", path, fd); + ORBIS_LOG_WARNING("File opened", path, fd); + return {}; +} + +orbis::SysResult socket(orbis::Thread *thread, orbis::ptr name, + orbis::sint domain, orbis::sint type, + orbis::sint protocol) { + orbis::Ref instance; + auto error = createSocket(name, domain, type, protocol, &instance); + if (error != ErrorCode{}) { + ORBIS_LOG_WARNING("Failed to open socket", name, int(error)); + return error; + } + + auto fd = thread->tproc->fileDescriptors.insert(instance); + thread->retval[0] = fd; + ORBIS_LOG_WARNING("Socket opened", name, fd); return {}; } @@ -225,7 +242,7 @@ orbis::SysResult close(orbis::Thread *thread, orbis::sint fd) { return ErrorCode::BADF; } - ORBIS_LOG_WARNING("sys_close", fd); + ORBIS_LOG_WARNING("fd closed", fd); return {}; } @@ -748,6 +765,7 @@ ProcessOps rx::procOpsTable = { .munlock = munlock, .virtual_query = virtual_query, .open = open, + .socket = socket, .close = close, .ioctl = ioctl, .write = write,