mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-01-20 07:30:24 +01:00
[orbis-kernel] Implement basic sys_socketex
Implement sys_socketclose
This commit is contained in:
parent
cea6052e54
commit
76db5849a0
|
|
@ -607,7 +607,7 @@ SysResult sys_netabort(Thread *thread /* TODO */);
|
|||
SysResult sys_netgetsockinfo(Thread *thread /* TODO */);
|
||||
SysResult sys_socketex(Thread *thread, ptr<const char> 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 */);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ struct ProcessOps {
|
|||
|
||||
SysResult (*open)(Thread *thread, ptr<const char> path, sint flags,
|
||||
sint mode);
|
||||
SysResult (*socket)(Thread *thread, ptr<const char> 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<const void> data, ulong size);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,20 @@ orbis::SysResult orbis::sys_netgetsockinfo(Thread *thread /* TODO */) {
|
|||
}
|
||||
orbis::SysResult orbis::sys_socketex(Thread *thread, ptr<const char> 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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#include "io-device.hpp"
|
||||
#include "orbis/KernelAllocator.hpp"
|
||||
#include "orbis/utils/Logs.hpp"
|
||||
#include <fcntl.h>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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<IoDeviceInstance> *instance) {
|
||||
auto s = orbis::knew<SocketDeviceInstance>();
|
||||
s->ioctl = socket_instance_ioctl;
|
||||
s->close = socket_instance_close;
|
||||
s->name = name;
|
||||
s->hostFd = ::socket(dom, type, prot);
|
||||
*instance = s;
|
||||
return {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
#include <cstdint>
|
||||
|
||||
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<IoDeviceInstance> *instance);
|
||||
|
|
|
|||
|
|
@ -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<int>(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<const char> path,
|
|||
orbis::Ref<IoDeviceInstance> 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<const char> name,
|
||||
orbis::sint domain, orbis::sint type,
|
||||
orbis::sint protocol) {
|
||||
orbis::Ref<IoDeviceInstance> 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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue