Move IoDevice to orbis

This commit is contained in:
DH 2025-10-11 14:49:51 +03:00
parent 63e9a3f597
commit 05dee2c8e3
71 changed files with 368 additions and 299 deletions

View File

@ -0,0 +1,54 @@
#pragma once
#include "error/ErrorCode.hpp"
#include "rx/Rc.hpp"
namespace orbis {
enum OpenFlags {
kOpenFlagReadOnly = 0x0,
kOpenFlagWriteOnly = 0x1,
kOpenFlagReadWrite = 0x2,
kOpenFlagNonBlock = 0x4,
kOpenFlagAppend = 0x8,
kOpenFlagShLock = 0x10,
kOpenFlagExLock = 0x20,
kOpenFlagAsync = 0x40,
kOpenFlagFsync = 0x80,
kOpenFlagCreat = 0x200,
kOpenFlagTrunc = 0x400,
kOpenFlagExcl = 0x800,
kOpenFlagDSync = 0x1000,
kOpenFlagDirect = 0x10000,
kOpenFlagDirectory = 0x20000,
};
struct File;
struct Thread;
struct IoDevice : rx::RcBase {
virtual ErrorCode open(rx::Ref<File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
Thread *thread) = 0;
virtual ErrorCode unlink(const char *path, bool recursive, Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode createSymlink(const char *target, const char *linkPath,
Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode mkdir(const char *path, int mode, Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode rmdir(const char *path, Thread *thread) {
return ErrorCode::NOTSUP;
}
virtual ErrorCode rename(const char *from, const char *to, Thread *thread) {
return ErrorCode::NOTSUP;
}
};
} // namespace orbis

View File

@ -1,6 +1,7 @@
#pragma once
#include "AppInfo.hpp"
#include "Budget.hpp"
#include "IoDevice.hpp"
#include "KernelObject.hpp"
#include "evf.hpp"
#include "ipmi.hpp"
@ -136,11 +137,11 @@ public:
}
rx::Ref<EventEmitter> deviceEventEmitter;
rx::Ref<rx::RcBase> shmDevice;
rx::Ref<rx::RcBase> dmemDevice;
rx::Ref<rx::RcBase> blockpoolDevice;
rx::Ref<IoDevice> shmDevice;
rx::Ref<IoDevice> dmemDevice;
rx::Ref<IoDevice> blockpoolDevice;
rx::Ref<rx::RcBase> gpuDevice;
rx::Ref<rx::RcBase> dceDevice;
rx::Ref<IoDevice> dceDevice;
rx::shared_mutex gpuDeviceMtx;
uint sdkVersion{};
uint fwSdkVersion{};

View File

@ -5,6 +5,7 @@
#include "note.hpp"
#include "rx/Rc.hpp"
#include "rx/SharedMutex.hpp"
#include "IoDevice.hpp"
#include "stat.hpp"
#include <cstdint>
@ -77,7 +78,7 @@ struct File : rx::RcBase {
rx::shared_mutex mtx;
rx::Ref<EventEmitter> event;
const FileOps *ops = nullptr;
rx::Ref<RcBase> device;
rx::Ref<IoDevice> device;
std::uint64_t nextOff = 0;
int flags = 0;
int mode = 0;

View File

@ -339,9 +339,8 @@ static orbis::ErrorCode host_mmap(orbis::File *file, void **address,
if (!hostFile->dirEntries.empty())
return orbis::ErrorCode::ISDIR;
auto result =
vm::map(*address, size, prot, flags, vm::kMapInternalReserveOnly,
hostFile->device.cast<IoDevice>().get(), offset);
auto result = vm::map(*address, size, prot, flags,
vm::kMapInternalReserveOnly, hostFile->device.get(), offset);
if (result == (void *)-1) {
return orbis::ErrorCode::NOMEM;
@ -695,8 +694,8 @@ static const orbis::FileOps socketOps = {
.getsockopt = socket_getsockopt,
};
IoDevice *createHostIoDevice(orbis::kstring hostPath,
orbis::kstring virtualPath) {
orbis::IoDevice *createHostIoDevice(orbis::kstring hostPath,
orbis::kstring virtualPath) {
while (hostPath.size() > 0 && hostPath.ends_with("/")) {
hostPath.resize(hostPath.size() - 1);
}
@ -778,44 +777,44 @@ orbis::ErrorCode HostFsDevice::open(rx::Ref<orbis::File> *file,
int realFlags = flags & O_ACCMODE;
flags &= ~O_ACCMODE;
if ((flags & kOpenFlagAppend) != 0) {
if ((flags & orbis::kOpenFlagAppend) != 0) {
realFlags |= O_APPEND;
flags &= ~kOpenFlagAppend;
flags &= ~orbis::kOpenFlagAppend;
}
if ((flags & kOpenFlagNonBlock) != 0) {
if ((flags & orbis::kOpenFlagNonBlock) != 0) {
realFlags |= O_NONBLOCK;
flags &= ~kOpenFlagNonBlock;
flags &= ~orbis::kOpenFlagNonBlock;
}
if ((flags & kOpenFlagFsync) != 0) {
if ((flags & orbis::kOpenFlagFsync) != 0) {
realFlags |= O_FSYNC;
flags &= ~kOpenFlagFsync;
flags &= ~orbis::kOpenFlagFsync;
}
if ((flags & kOpenFlagAsync) != 0) {
if ((flags & orbis::kOpenFlagAsync) != 0) {
realFlags |= O_ASYNC;
flags &= ~kOpenFlagAsync;
flags &= ~orbis::kOpenFlagAsync;
}
if ((flags & kOpenFlagTrunc) != 0) {
if ((flags & orbis::kOpenFlagTrunc) != 0) {
realFlags |= O_TRUNC;
flags &= ~kOpenFlagTrunc;
flags &= ~orbis::kOpenFlagTrunc;
}
if ((flags & kOpenFlagCreat) != 0) {
if ((flags & orbis::kOpenFlagCreat) != 0) {
realFlags |= O_CREAT;
flags &= ~kOpenFlagCreat;
flags &= ~orbis::kOpenFlagCreat;
}
if ((flags & kOpenFlagExcl) != 0) {
if ((flags & orbis::kOpenFlagExcl) != 0) {
realFlags |= O_EXCL;
flags &= ~kOpenFlagExcl;
flags &= ~orbis::kOpenFlagExcl;
}
if ((flags & kOpenFlagDirectory) != 0) {
if ((flags & orbis::kOpenFlagDirectory) != 0) {
realFlags |= O_DIRECTORY;
flags &= ~kOpenFlagDirectory;
flags &= ~orbis::kOpenFlagDirectory;
}
if (flags != 0) {
@ -937,7 +936,7 @@ orbis::ErrorCode HostFsDevice::rename(const char *from, const char *to,
return convertErrorCode(ec);
}
orbis::File *createHostFile(int hostFd, rx::Ref<IoDevice> device,
orbis::File *createHostFile(int hostFd, rx::Ref<orbis::IoDevice> device,
bool alignTruncate) {
auto newFile = orbis::knew<HostFile>();
newFile->hostFd = hostFd;
@ -947,7 +946,7 @@ orbis::File *createHostFile(int hostFd, rx::Ref<IoDevice> device,
return newFile;
}
struct FdWrapDevice : public IoDevice {
struct FdWrapDevice : public orbis::IoDevice {
int fd;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
@ -959,7 +958,7 @@ struct FdWrapDevice : public IoDevice {
}
};
IoDevice *createFdWrapDevice(int fd) {
orbis::IoDevice *createFdWrapDevice(int fd) {
auto result = orbis::knew<FdWrapDevice>();
result->fd = fd;
return result;

View File

@ -1,56 +1,13 @@
#pragma once
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "rx/Rc.hpp"
#include <cstdint>
#include <system_error>
enum OpenFlags {
kOpenFlagReadOnly = 0x0,
kOpenFlagWriteOnly = 0x1,
kOpenFlagReadWrite = 0x2,
kOpenFlagNonBlock = 0x4,
kOpenFlagAppend = 0x8,
kOpenFlagShLock = 0x10,
kOpenFlagExLock = 0x20,
kOpenFlagAsync = 0x40,
kOpenFlagFsync = 0x80,
kOpenFlagCreat = 0x200,
kOpenFlagTrunc = 0x400,
kOpenFlagExcl = 0x800,
kOpenFlagDSync = 0x1000,
kOpenFlagDirect = 0x10000,
kOpenFlagDirectory = 0x20000,
};
struct IoDevice : rx::RcBase {
virtual orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) = 0;
virtual orbis::ErrorCode unlink(const char *path, bool recursive,
orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
virtual orbis::ErrorCode createSymlink(const char *target,
const char *linkPath,
orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
virtual orbis::ErrorCode mkdir(const char *path, int mode,
orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
virtual orbis::ErrorCode rmdir(const char *path, orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
virtual orbis::ErrorCode rename(const char *from, const char *to,
orbis::Thread *thread) {
return orbis::ErrorCode::NOTSUP;
}
};
struct HostFsDevice : IoDevice {
struct HostFsDevice : orbis::IoDevice {
orbis::kstring hostPath;
orbis::kstring virtualPath;
@ -72,12 +29,12 @@ struct HostFsDevice : IoDevice {
orbis::ErrorCode convertErrorCode(const std::error_code &code);
orbis::ErrorCode convertErrno();
IoDevice *createHostIoDevice(orbis::kstring hostPath,
orbis::kstring virtualPath);
orbis::IoDevice *createHostIoDevice(orbis::kstring hostPath,
orbis::kstring virtualPath);
rx::Ref<orbis::File> wrapSocket(int hostFd, orbis::kstring name, int dom,
int type, int prot);
orbis::ErrorCode createSocket(rx::Ref<orbis::File> *file, orbis::kstring name,
int dom, int type, int prot);
orbis::File *createHostFile(int hostFd, rx::Ref<IoDevice> device,
orbis::File *createHostFile(int hostFd, rx::Ref<orbis::IoDevice> device,
bool alignTruncate = false);
IoDevice *createFdWrapDevice(int fd);
orbis::IoDevice *createFdWrapDevice(int fd);

View File

@ -3,57 +3,59 @@
#include "audio/AudioDevice.hpp"
#include <cstdint>
namespace orbis {
struct IoDevice;
}
IoDevice *createDceCharacterDevice();
IoDevice *createDipswCharacterDevice();
IoDevice *createDmemCharacterDevice(int index);
IoDevice *createGcCharacterDevice();
IoDevice *createHidCharacterDevice();
IoDevice *createHmd3daCharacterDevice();
IoDevice *createHmdCmdCharacterDevice();
IoDevice *createHmdMmapCharacterDevice();
IoDevice *createHmdSnsrCharacterDevice();
IoDevice *createNullCharacterDevice();
IoDevice *createZeroCharacterDevice();
IoDevice *createRngCharacterDevice();
IoDevice *createAjmCharacterDevice();
IoDevice *createIccConfigurationCharacterDevice();
IoDevice *createNpdrmCharacterDevice();
IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd);
IoDevice *createSblSrvCharacterDevice();
IoDevice *createShmDevice();
IoDevice *createBlockPoolDevice();
IoDevice *createUrandomCharacterDevice();
IoDevice *createCameraCharacterDevice();
IoDevice *createNotificationCharacterDevice(int index);
IoDevice *createMBusCharacterDevice();
IoDevice *createBtCharacterDevice();
IoDevice *createXptCharacterDevice();
IoDevice *createCdCharacterDevice();
IoDevice *createMetaDbgCharacterDevice();
IoDevice *createHddCharacterDevice(std::uint64_t size);
IoDevice *createAoutCharacterDevice(std::int8_t id, AudioDevice *device);
IoDevice *createAVControlCharacterDevice();
IoDevice *createHDMICharacterDevice();
IoDevice *createMBusAVCharacterDevice();
IoDevice *createScaninCharacterDevice();
IoDevice *createS3DACharacterDevice();
IoDevice *createGbaseCharacterDevice();
IoDevice *createDevStatCharacterDevice();
IoDevice *createDevCtlCharacterDevice();
IoDevice *createDevActCharacterDevice();
IoDevice *createUVDCharacterDevice();
IoDevice *createVCECharacterDevice();
IoDevice *createEvlgCharacterDevice(int outputFd);
IoDevice *createSrtcCharacterDevice();
IoDevice *createScreenShotCharacterDevice();
IoDevice *createLvdCtlCharacterDevice();
IoDevice *createIccPowerCharacterDevice();
IoDevice *createCaymanRegCharacterDevice();
IoDevice *createA53IoCharacterDevice();
IoDevice *createNsidCtlCharacterDevice();
IoDevice *createHmd2CmdCharacterDevice();
IoDevice *createHmd2ImuCharacterDevice();
IoDevice *createHmd2GazeCharacterDevice();
IoDevice *createHmd2GenDataCharacterDevice();
orbis::IoDevice *createDceCharacterDevice();
orbis::IoDevice *createDipswCharacterDevice();
orbis::IoDevice *createDmemCharacterDevice(int index);
orbis::IoDevice *createGcCharacterDevice();
orbis::IoDevice *createHidCharacterDevice();
orbis::IoDevice *createHmd3daCharacterDevice();
orbis::IoDevice *createHmdCmdCharacterDevice();
orbis::IoDevice *createHmdMmapCharacterDevice();
orbis::IoDevice *createHmdSnsrCharacterDevice();
orbis::IoDevice *createNullCharacterDevice();
orbis::IoDevice *createZeroCharacterDevice();
orbis::IoDevice *createRngCharacterDevice();
orbis::IoDevice *createAjmCharacterDevice();
orbis::IoDevice *createIccConfigurationCharacterDevice();
orbis::IoDevice *createNpdrmCharacterDevice();
orbis::IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd);
orbis::IoDevice *createSblSrvCharacterDevice();
orbis::IoDevice *createShmDevice();
orbis::IoDevice *createBlockPoolDevice();
orbis::IoDevice *createUrandomCharacterDevice();
orbis::IoDevice *createCameraCharacterDevice();
orbis::IoDevice *createNotificationCharacterDevice(int index);
orbis::IoDevice *createMBusCharacterDevice();
orbis::IoDevice *createBtCharacterDevice();
orbis::IoDevice *createXptCharacterDevice();
orbis::IoDevice *createCdCharacterDevice();
orbis::IoDevice *createMetaDbgCharacterDevice();
orbis::IoDevice *createHddCharacterDevice(std::uint64_t size);
orbis::IoDevice *createAoutCharacterDevice(std::int8_t id, AudioDevice *device);
orbis::IoDevice *createAVControlCharacterDevice();
orbis::IoDevice *createHDMICharacterDevice();
orbis::IoDevice *createMBusAVCharacterDevice();
orbis::IoDevice *createScaninCharacterDevice();
orbis::IoDevice *createS3DACharacterDevice();
orbis::IoDevice *createGbaseCharacterDevice();
orbis::IoDevice *createDevStatCharacterDevice();
orbis::IoDevice *createDevCtlCharacterDevice();
orbis::IoDevice *createDevActCharacterDevice();
orbis::IoDevice *createUVDCharacterDevice();
orbis::IoDevice *createVCECharacterDevice();
orbis::IoDevice *createEvlgCharacterDevice(int outputFd);
orbis::IoDevice *createSrtcCharacterDevice();
orbis::IoDevice *createScreenShotCharacterDevice();
orbis::IoDevice *createLvdCtlCharacterDevice();
orbis::IoDevice *createIccPowerCharacterDevice();
orbis::IoDevice *createCaymanRegCharacterDevice();
orbis::IoDevice *createA53IoCharacterDevice();
orbis::IoDevice *createNsidCtlCharacterDevice();
orbis::IoDevice *createHmd2CmdCharacterDevice();
orbis::IoDevice *createHmd2ImuCharacterDevice();
orbis::IoDevice *createHmd2GazeCharacterDevice();
orbis::IoDevice *createHmd2GenDataCharacterDevice();

View File

@ -1,8 +1,8 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include <chrono>
#include <thread>
struct A53IoFile : orbis::File {};
@ -26,7 +26,7 @@ static const orbis::FileOps fileOps = {
.read = a53io_read,
};
struct A53IoDevice : IoDevice {
struct A53IoDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -39,4 +39,6 @@ struct A53IoDevice : IoDevice {
}
};
IoDevice *createA53IoCharacterDevice() { return orbis::knew<A53IoDevice>(); }
orbis::IoDevice *createA53IoCharacterDevice() {
return orbis::knew<A53IoDevice>();
}

View File

@ -40,7 +40,7 @@ enum {
AJM_RESULT_CODEC_ERROR = 0x40000000,
};
struct AjmDevice : IoDevice {
struct AjmDevice : orbis::IoDevice {
rx::shared_mutex mtx;
orbis::uint32_t batchId = 1; // temp
@ -789,4 +789,4 @@ orbis::ErrorCode AjmDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createAjmCharacterDevice() { return orbis::knew<AjmDevice>(); }
orbis::IoDevice *createAjmCharacterDevice() { return orbis::knew<AjmDevice>(); }

View File

@ -27,7 +27,7 @@
struct AoutFile : orbis::File {};
struct AoutDevice : public IoDevice {
struct AoutDevice : public orbis::IoDevice {
std::int8_t id;
rx::Ref<AudioDevice> audioDevice;
@ -205,6 +205,7 @@ orbis::ErrorCode AoutDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createAoutCharacterDevice(std::int8_t id, AudioDevice *device) {
orbis::IoDevice *createAoutCharacterDevice(std::int8_t id,
AudioDevice *device) {
return orbis::knew<AoutDevice>(id, device);
}

View File

@ -34,7 +34,7 @@ static const orbis::FileOps fileOps = {
.ioctl = av_control_ioctl,
};
struct AVControlDevice : IoDevice {
struct AVControlDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -47,6 +47,6 @@ struct AVControlDevice : IoDevice {
}
};
IoDevice *createAVControlCharacterDevice() {
orbis::IoDevice *createAVControlCharacterDevice() {
return orbis::knew<AVControlDevice>();
}

View File

@ -1,6 +1,6 @@
#include "blockpool.hpp"
#include "dmem.hpp"
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/KernelContext.hpp"
#include "orbis/file.hpp"
@ -139,4 +139,6 @@ orbis::ErrorCode BlockPoolDevice::unmap(void *address, std::uint64_t len,
}
return orbis::ErrorCode::INVAL;
}
IoDevice *createBlockPoolDevice() { return orbis::knew<BlockPoolDevice>(); }
orbis::IoDevice *createBlockPoolDevice() {
return orbis::knew<BlockPoolDevice>();
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
#include "rx/MemoryTable.hpp"
@ -8,7 +8,7 @@
#include "rx/SharedMutex.hpp"
#include <cstdint>
struct BlockPoolDevice : public IoDevice {
struct BlockPoolDevice : public orbis::IoDevice {
rx::shared_mutex mtx;
rx::MemoryAreaTable<> pool;

View File

@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = bt_ioctl,
};
struct BtDevice : IoDevice {
struct BtDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,4 +29,4 @@ struct BtDevice : IoDevice {
}
};
IoDevice *createBtCharacterDevice() { return orbis::knew<BtDevice>(); }
orbis::IoDevice *createBtCharacterDevice() { return orbis::knew<BtDevice>(); }

View File

@ -49,7 +49,7 @@ static const orbis::FileOps fileOps = {
.write = camera_write,
};
struct CameraDevice : IoDevice {
struct CameraDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -62,4 +62,6 @@ struct CameraDevice : IoDevice {
}
};
IoDevice *createCameraCharacterDevice() { return orbis::knew<CameraDevice>(); }
orbis::IoDevice *createCameraCharacterDevice() {
return orbis::knew<CameraDevice>();
}

View File

@ -4,7 +4,7 @@
#include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp"
struct CaymanRegDevice : IoDevice {
struct CaymanRegDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -34,6 +34,6 @@ orbis::ErrorCode CaymanRegDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createCaymanRegCharacterDevice() {
orbis::IoDevice *createCaymanRegCharacterDevice() {
return orbis::knew<CaymanRegDevice>();
}

View File

@ -23,7 +23,7 @@ static const orbis::FileOps fileOps = {
.ioctl = cd_ioctl,
};
struct CdDevice : IoDevice {
struct CdDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -36,4 +36,4 @@ struct CdDevice : IoDevice {
}
};
IoDevice *createCdCharacterDevice() { return orbis::knew<CdDevice>(); }
orbis::IoDevice *createCdCharacterDevice() { return orbis::knew<CdDevice>(); }

View File

@ -9,7 +9,7 @@
#include <unistd.h>
struct ConsoleFile : orbis::File {};
struct ConsoleDevice : IoDevice {
struct ConsoleDevice : orbis::IoDevice {
int inputFd;
int outputFd;
@ -76,6 +76,6 @@ orbis::ErrorCode ConsoleDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd) {
orbis::IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd) {
return orbis::knew<ConsoleDevice>(inputFd, outputFd);
}

View File

@ -653,4 +653,4 @@ void DceDevice::initializeProcess(orbis::Process *process) {
}
}
IoDevice *createDceCharacterDevice() { return orbis::knew<DceDevice>(); }
orbis::IoDevice *createDceCharacterDevice() { return orbis::knew<DceDevice>(); }

View File

@ -10,7 +10,7 @@
static constexpr auto kVmIdCount = 6;
struct DceDevice : IoDevice {
struct DceDevice : orbis::IoDevice {
rx::shared_mutex mtx;
std::uint32_t eopCount = 0;
std::uint32_t freeVmIds = (1 << (kVmIdCount + 1)) - 1;

View File

@ -48,7 +48,7 @@ static const orbis::FileOps fileOps = {
.ioctl = devact_ioctl,
};
struct DevActDevice : IoDevice {
struct DevActDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -61,4 +61,6 @@ struct DevActDevice : IoDevice {
}
};
IoDevice *createDevActCharacterDevice() { return orbis::knew<DevActDevice>(); }
orbis::IoDevice *createDevActCharacterDevice() {
return orbis::knew<DevActDevice>();
}

View File

@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = devctl_ioctl,
};
struct DevCtlDevice : IoDevice {
struct DevCtlDevice : orbis::IoDevice {
orbis::kstring data;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
@ -30,4 +30,6 @@ struct DevCtlDevice : IoDevice {
}
};
IoDevice *createDevCtlCharacterDevice() { return orbis::knew<DevCtlDevice>(); }
orbis::IoDevice *createDevCtlCharacterDevice() {
return orbis::knew<DevCtlDevice>();
}

View File

@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = devstat_ioctl,
};
struct DevStatDevice : IoDevice {
struct DevStatDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,6 +29,6 @@ struct DevStatDevice : IoDevice {
}
};
IoDevice *createDevStatCharacterDevice() {
orbis::IoDevice *createDevStatCharacterDevice() {
return orbis::knew<DevStatDevice>();
}

View File

@ -60,7 +60,7 @@ static const orbis::FileOps ops = {
.ioctl = dipsw_ioctl,
};
struct DipswDevice : public IoDevice {
struct DipswDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -72,4 +72,6 @@ struct DipswDevice : public IoDevice {
}
};
IoDevice *createDipswCharacterDevice() { return orbis::knew<DipswDevice>(); }
orbis::IoDevice *createDipswCharacterDevice() {
return orbis::knew<DipswDevice>();
}

View File

@ -86,7 +86,7 @@ orbis::ErrorCode DmemDevice::mmap(void **address, std::uint64_t len,
static orbis::ErrorCode dmem_ioctl(orbis::File *file, std::uint64_t request,
void *argp, orbis::Thread *thread) {
auto device = static_cast<DmemDevice *>(file->device.get());
auto device = file->device.rawStaticCast<DmemDevice>();
std::lock_guard lock(device->mtx);
switch (request) {
@ -250,7 +250,7 @@ static orbis::ErrorCode dmem_mmap(orbis::File *file, void **address,
std::uint64_t size, std::int32_t prot,
std::int32_t flags, std::int64_t offset,
orbis::Thread *thread) {
auto device = static_cast<DmemDevice *>(file->device.get());
auto device = file->device.rawStaticCast<DmemDevice>();
return device->mmap(address, size, prot, flags, offset);
}
@ -395,7 +395,7 @@ orbis::ErrorCode DmemDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createDmemCharacterDevice(int index) {
orbis::IoDevice *createDmemCharacterDevice(int index) {
auto *newDevice = orbis::knew<DmemDevice>();
newDevice->index = index;
newDevice->dmemTotalSize = dmemSize;

View File

@ -1,6 +1,6 @@
#pragma once
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -10,7 +10,7 @@
#include <rx/MemoryTable.hpp>
#include <unistd.h>
struct DmemDevice : public IoDevice {
struct DmemDevice : public orbis::IoDevice {
rx::shared_mutex mtx;
int index;
int shmFd = -1;

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -8,7 +8,7 @@
#include <unistd.h>
struct EvlgFile : orbis::File {};
struct EvlgDevice : IoDevice {
struct EvlgDevice : orbis::IoDevice {
int outputFd;
EvlgDevice(int outputFd) : outputFd(outputFd) {}
@ -53,6 +53,6 @@ orbis::ErrorCode EvlgDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createEvlgCharacterDevice(int outputFd) {
orbis::IoDevice *createEvlgCharacterDevice(int outputFd) {
return orbis::knew<EvlgDevice>(outputFd);
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -36,7 +36,7 @@ static const orbis::FileOps fileOps = {
.ioctl = gbase_ioctl,
};
struct GbaseDevice : IoDevice {
struct GbaseDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -49,4 +49,6 @@ struct GbaseDevice : IoDevice {
}
};
IoDevice *createGbaseCharacterDevice() { return orbis::knew<GbaseDevice>(); }
orbis::IoDevice *createGbaseCharacterDevice() {
return orbis::knew<GbaseDevice>();
}

View File

@ -1,7 +1,7 @@
#include "gpu/DeviceCtl.hpp"
#include "io-device.hpp"
#include "iodev/dce.hpp"
#include "iodev/dmem.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/KernelContext.hpp"
#include "orbis/file.hpp"
@ -24,7 +24,7 @@ struct ComputeQueue {
std::uint64_t len{};
};
struct GcDevice : public IoDevice {
struct GcDevice : public orbis::IoDevice {
rx::shared_mutex mtx;
orbis::kmap<orbis::pid_t, int> clients;
orbis::kmap<std::uint64_t, ComputeQueue> computeQueues;
@ -490,4 +490,4 @@ void GcDevice::removeClient(orbis::Process *process) {
}
}
IoDevice *createGcCharacterDevice() { return orbis::knew<GcDevice>(); }
orbis::IoDevice *createGcCharacterDevice() { return orbis::knew<GcDevice>(); }

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -9,7 +9,7 @@
struct HddFile : orbis::File {};
struct HddDevice : IoDevice {
struct HddDevice : orbis::IoDevice {
std::uint64_t size;
HddDevice(std::uint64_t size) : size(size) {}
@ -146,6 +146,6 @@ orbis::ErrorCode HddDevice::open(rx::Ref<orbis::File> *fs, const char *path,
return {};
}
IoDevice *createHddCharacterDevice(std::uint64_t size) {
orbis::IoDevice *createHddCharacterDevice(std::uint64_t size) {
return orbis::knew<HddDevice>(size);
}

View File

@ -1,5 +1,5 @@
#include "io-device.hpp"
#include "orbis-config.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -75,7 +75,7 @@ static const orbis::FileOps fileOps = {
.ioctl = hdmi_ioctl,
};
struct HDMIDevice : IoDevice {
struct HDMIDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -88,4 +88,6 @@ struct HDMIDevice : IoDevice {
}
};
IoDevice *createHDMICharacterDevice() { return orbis::knew<HDMIDevice>(); }
orbis::IoDevice *createHDMICharacterDevice() {
return orbis::knew<HDMIDevice>();
}

View File

@ -1,13 +1,12 @@
#include "gpu/DeviceCtl.hpp"
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/KernelContext.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp"
#include <chrono>
struct HidDevice : public IoDevice {
struct HidDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -165,4 +164,4 @@ orbis::ErrorCode HidDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createHidCharacterDevice() { return orbis::knew<HidDevice>(); }
orbis::IoDevice *createHidCharacterDevice() { return orbis::knew<HidDevice>(); }

View File

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd2CmdDevice : public IoDevice {
struct Hmd2CmdDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -30,6 +31,6 @@ orbis::ErrorCode Hmd2CmdDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd2CmdCharacterDevice() {
orbis::IoDevice *createHmd2CmdCharacterDevice() {
return orbis::knew<Hmd2CmdDevice>();
}

View File

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd2GazeDevice : public IoDevice {
struct Hmd2GazeDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -31,6 +32,6 @@ orbis::ErrorCode Hmd2GazeDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd2GazeCharacterDevice() {
orbis::IoDevice *createHmd2GazeCharacterDevice() {
return orbis::knew<Hmd2GazeDevice>();
}

View File

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd2GenDataDevice : public IoDevice {
struct Hmd2GenDataDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -31,6 +32,6 @@ orbis::ErrorCode Hmd2GenDataDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd2GenDataCharacterDevice() {
orbis::IoDevice *createHmd2GenDataCharacterDevice() {
return orbis::knew<Hmd2GenDataDevice>();
}

View File

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd2ImuDevice : public IoDevice {
struct Hmd2ImuDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -30,6 +31,6 @@ orbis::ErrorCode Hmd2ImuDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd2ImuCharacterDevice() {
orbis::IoDevice *createHmd2ImuCharacterDevice() {
return orbis::knew<Hmd2ImuDevice>();
}

View File

@ -1,9 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct Hmd3daDevice : public IoDevice {
struct Hmd3daDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -32,4 +32,6 @@ orbis::ErrorCode Hmd3daDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmd3daCharacterDevice() { return orbis::knew<Hmd3daDevice>(); }
orbis::IoDevice *createHmd3daCharacterDevice() {
return orbis::knew<Hmd3daDevice>();
}

View File

@ -1,8 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct HmdCmdDevice : public IoDevice {
struct HmdCmdDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -31,4 +32,6 @@ orbis::ErrorCode HmdCmdDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmdCmdCharacterDevice() { return orbis::knew<HmdCmdDevice>(); }
orbis::IoDevice *createHmdCmdCharacterDevice() {
return orbis::knew<HmdCmdDevice>();
}

View File

@ -1,9 +1,10 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include "vm.hpp"
struct HmdMmapDevice : public IoDevice {
struct HmdMmapDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -49,6 +50,6 @@ orbis::ErrorCode HmdMmapDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmdMmapCharacterDevice() {
orbis::IoDevice *createHmdMmapCharacterDevice() {
return orbis::knew<HmdMmapDevice>();
}

View File

@ -1,9 +1,9 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
struct HmdSnsrDevice : public IoDevice {
struct HmdSnsrDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -33,6 +33,6 @@ orbis::ErrorCode HmdSnsrDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createHmdSnsrCharacterDevice() {
orbis::IoDevice *createHmdSnsrCharacterDevice() {
return orbis::knew<HmdSnsrDevice>();
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
@ -18,7 +18,7 @@ static const orbis::FileOps fileOps = {
.ioctl = icc_configuration_ioctl,
};
struct IccConfigurationDevice : IoDevice {
struct IccConfigurationDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -31,6 +31,6 @@ struct IccConfigurationDevice : IoDevice {
}
};
IoDevice *createIccConfigurationCharacterDevice() {
orbis::IoDevice *createIccConfigurationCharacterDevice() {
return orbis::knew<IccConfigurationDevice>();
}

View File

@ -1,10 +1,10 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
#include "orbis/utils/Logs.hpp"
struct IccPowerDevice : IoDevice {
struct IccPowerDevice : orbis::IoDevice {
std::uint8_t bootphase = 0;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
@ -69,6 +69,6 @@ orbis::ErrorCode IccPowerDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createIccPowerCharacterDevice() {
orbis::IoDevice *createIccPowerCharacterDevice() {
return orbis::knew<IccPowerDevice>();
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -17,7 +17,7 @@ static const orbis::FileOps fileOps = {
.ioctl = lvdctl_ioctl,
};
struct LvdCtlDevice : IoDevice {
struct LvdCtlDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -30,4 +30,6 @@ struct LvdCtlDevice : IoDevice {
}
};
IoDevice *createLvdCtlCharacterDevice() { return orbis::knew<LvdCtlDevice>(); }
orbis::IoDevice *createLvdCtlCharacterDevice() {
return orbis::knew<LvdCtlDevice>();
}

View File

@ -1,5 +1,4 @@
#include "mbus.hpp"
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
@ -65,4 +64,6 @@ orbis::ErrorCode MBusDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createMBusCharacterDevice() { return orbis::knew<MBusDevice>(); }
orbis::IoDevice *createMBusCharacterDevice() {
return orbis::knew<MBusDevice>();
}

View File

@ -1,11 +1,13 @@
#pragma once
#include "io-device.hpp"
#include "iodev/MBusEvent.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/note.hpp"
#include "rx/SharedCV.hpp"
#include "rx/SharedMutex.hpp"
struct MBusDevice : IoDevice {
struct MBusDevice : orbis::IoDevice {
rx::shared_mutex mtx;
rx::shared_cv cv;
orbis::kdeque<MBusEvent> events;

View File

@ -1,5 +1,4 @@
#include "mbus_av.hpp"
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/note.hpp"
@ -65,4 +64,6 @@ void MBusAVDevice::emitEvent(const MBusEvent &event) {
eventEmitter->emit(orbis::kEvFiltRead);
}
IoDevice *createMBusAVCharacterDevice() { return orbis::knew<MBusAVDevice>(); }
orbis::IoDevice *createMBusAVCharacterDevice() {
return orbis::knew<MBusAVDevice>();
}

View File

@ -1,11 +1,13 @@
#pragma once
#include "io-device.hpp"
#include "iodev/MBusEvent.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/note.hpp"
#include "rx/SharedCV.hpp"
#include "rx/SharedMutex.hpp"
struct MBusAVDevice : IoDevice {
struct MBusAVDevice : orbis::IoDevice {
rx::shared_mutex mtx;
rx::shared_cv cv;
orbis::kdeque<MBusEvent> events;

View File

@ -1,8 +1,7 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include <chrono>
#include <thread>
struct MetaDbgFile : orbis::File {};
@ -26,7 +25,7 @@ static const orbis::FileOps fileOps = {
.read = metadbg_read,
};
struct MetaDbgDevice : IoDevice {
struct MetaDbgDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -39,6 +38,6 @@ struct MetaDbgDevice : IoDevice {
}
};
IoDevice *createMetaDbgCharacterDevice() {
orbis::IoDevice *createMetaDbgCharacterDevice() {
return orbis::knew<MetaDbgDevice>();
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -12,7 +12,7 @@
#include <thread>
struct NotificationFile : orbis::File {};
struct NotificationDevice : IoDevice {
struct NotificationDevice : orbis::IoDevice {
int index;
rx::shared_mutex mutex;
orbis::kvector<std::byte> data;
@ -104,6 +104,6 @@ orbis::ErrorCode NotificationDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createNotificationCharacterDevice(int index) {
orbis::IoDevice *createNotificationCharacterDevice(int index) {
return orbis::knew<NotificationDevice>(index);
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = npdrm_ioctl,
};
struct NpdrmDevice : IoDevice {
struct NpdrmDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,4 +29,6 @@ struct NpdrmDevice : IoDevice {
}
};
IoDevice *createNpdrmCharacterDevice() { return orbis::knew<NpdrmDevice>(); }
orbis::IoDevice *createNpdrmCharacterDevice() {
return orbis::knew<NpdrmDevice>();
}

View File

@ -1,10 +1,9 @@
#include "../io-devices.hpp"
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include "vfs.hpp"
#include <chrono>
#include <thread>
struct NsidCtlFile : orbis::File {};
@ -34,7 +33,7 @@ static const orbis::FileOps fileOps = {
.read = nsid_ctl_read,
};
struct NsidCtlDevice : IoDevice {
struct NsidCtlDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -47,6 +46,6 @@ struct NsidCtlDevice : IoDevice {
}
};
IoDevice *createNsidCtlCharacterDevice() {
orbis::IoDevice *createNsidCtlCharacterDevice() {
return orbis::knew<NsidCtlDevice>();
}

View File

@ -1,9 +1,10 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
#include <span>
struct NullDevice : public IoDevice {
struct NullDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -32,4 +33,6 @@ orbis::ErrorCode NullDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createNullCharacterDevice() { return orbis::knew<NullDevice>(); }
orbis::IoDevice *createNullCharacterDevice() {
return orbis::knew<NullDevice>();
}

View File

@ -1,9 +1,10 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
#include "vm.hpp"
struct RngDevice : public IoDevice {
struct RngDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -48,4 +49,4 @@ orbis::ErrorCode RngDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createRngCharacterDevice() { return orbis::knew<RngDevice>(); }
orbis::IoDevice *createRngCharacterDevice() { return orbis::knew<RngDevice>(); }

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = s3da_ioctl,
};
struct S3DADevice : IoDevice {
struct S3DADevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,4 +29,6 @@ struct S3DADevice : IoDevice {
}
};
IoDevice *createS3DACharacterDevice() { return orbis::knew<S3DADevice>(); }
orbis::IoDevice *createS3DACharacterDevice() {
return orbis::knew<S3DADevice>();
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -9,7 +9,7 @@
struct SblSrvFile : public orbis::File {};
struct SblSrvDevice : IoDevice {
struct SblSrvDevice : orbis::IoDevice {
rx::shared_mutex mtx;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
@ -53,4 +53,6 @@ orbis::ErrorCode SblSrvDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createSblSrvCharacterDevice() { return orbis::knew<SblSrvDevice>(); }
orbis::IoDevice *createSblSrvCharacterDevice() {
return orbis::knew<SblSrvDevice>();
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -18,7 +18,7 @@ static const orbis::FileOps fileOps = {
.ioctl = scanin_ioctl,
};
struct ScaninDevice : IoDevice {
struct ScaninDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -31,4 +31,6 @@ struct ScaninDevice : IoDevice {
}
};
IoDevice *createScaninCharacterDevice() { return orbis::knew<ScaninDevice>(); }
orbis::IoDevice *createScaninCharacterDevice() {
return orbis::knew<ScaninDevice>();
}

View File

@ -1,4 +1,5 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/error/ErrorCode.hpp"
#include "orbis/file.hpp"
@ -9,7 +10,7 @@
#include <filesystem>
#include <sys/mman.h>
struct ShmDevice : IoDevice {
struct ShmDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -56,4 +57,4 @@ orbis::ErrorCode ShmDevice::unlink(const char *path, bool recursive,
return convertErrorCode(ec);
}
IoDevice *createShmDevice() { return orbis::knew<ShmDevice>(); }
orbis::IoDevice *createShmDevice() { return orbis::knew<ShmDevice>(); }

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -17,7 +17,7 @@ static const orbis::FileOps fileOps = {
.ioctl = srtc_ioctl,
};
struct SrtcDevice : IoDevice {
struct SrtcDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -30,4 +30,6 @@ struct SrtcDevice : IoDevice {
}
};
IoDevice *createSrtcCharacterDevice() { return orbis::knew<SrtcDevice>(); }
orbis::IoDevice *createSrtcCharacterDevice() {
return orbis::knew<SrtcDevice>();
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -18,7 +18,7 @@ static const orbis::FileOps fileOps = {
.ioctl = sshot_ioctl,
};
struct ScreenShotDevice : IoDevice {
struct ScreenShotDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -31,6 +31,6 @@ struct ScreenShotDevice : IoDevice {
}
};
IoDevice *createScreenShotCharacterDevice() {
orbis::IoDevice *createScreenShotCharacterDevice() {
return orbis::knew<ScreenShotDevice>();
}

View File

@ -1,10 +1,11 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
#include <cstring>
#include <span>
struct UrandomDevice : public IoDevice {
struct UrandomDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -36,6 +37,6 @@ orbis::ErrorCode UrandomDevice::open(rx::Ref<orbis::File> *file,
return {};
}
IoDevice *createUrandomCharacterDevice() {
orbis::IoDevice *createUrandomCharacterDevice() {
return orbis::knew<UrandomDevice>();
}

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/utils/Logs.hpp"
@ -16,7 +16,7 @@ static const orbis::FileOps fileOps = {
.ioctl = uvd_ioctl,
};
struct UVDDevice : IoDevice {
struct UVDDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -29,4 +29,4 @@ struct UVDDevice : IoDevice {
}
};
IoDevice *createUVDCharacterDevice() { return orbis::knew<UVDDevice>(); }
orbis::IoDevice *createUVDCharacterDevice() { return orbis::knew<UVDDevice>(); }

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -29,7 +29,7 @@ static const orbis::FileOps fileOps = {
.ioctl = vce_ioctl,
};
struct VCEDevice : IoDevice {
struct VCEDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -42,4 +42,4 @@ struct VCEDevice : IoDevice {
}
};
IoDevice *createVCECharacterDevice() { return orbis::knew<VCEDevice>(); }
orbis::IoDevice *createVCECharacterDevice() { return orbis::knew<VCEDevice>(); }

View File

@ -1,4 +1,4 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/thread/Thread.hpp"
@ -22,7 +22,7 @@ static const orbis::FileOps fileOps = {
.ioctl = xpt_ioctl,
};
struct XptDevice : IoDevice {
struct XptDevice : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -35,4 +35,4 @@ struct XptDevice : IoDevice {
}
};
IoDevice *createXptCharacterDevice() { return orbis::knew<XptDevice>(); }
orbis::IoDevice *createXptCharacterDevice() { return orbis::knew<XptDevice>(); }

View File

@ -1,10 +1,11 @@
#include "io-device.hpp"
#include "orbis/IoDevice.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
#include <cstring>
#include <span>
struct ZeroDevice : public IoDevice {
struct ZeroDevice : public orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
@ -35,4 +36,6 @@ orbis::ErrorCode ZeroDevice::open(rx::Ref<orbis::File> *file, const char *path,
return {};
}
IoDevice *createZeroCharacterDevice() { return orbis::knew<ZeroDevice>(); }
orbis::IoDevice *createZeroCharacterDevice() {
return orbis::knew<ZeroDevice>();
}

View File

@ -179,7 +179,7 @@ orbis::EventFlag *ipmi::createEventFlag(std::string_view name, uint32_t attrs,
void ipmi::createShm(const char *name, uint32_t flags, uint32_t mode,
uint64_t size) {
rx::Ref<orbis::File> shm;
auto shmDevice = orbis::g_context->shmDevice.staticCast<IoDevice>();
auto shmDevice = orbis::g_context->shmDevice.staticCast<orbis::IoDevice>();
shmDevice->open(&shm, name, flags, mode, nullptr);
shm->ops->truncate(shm.get(), size, nullptr);
}

View File

@ -974,7 +974,8 @@ rx::Ref<orbis::Module> rx::linker::loadModule(std::span<std::byte> image,
static rx::Ref<orbis::Module> loadModuleFileImpl(std::string_view path,
orbis::Thread *thread) {
rx::Ref<orbis::File> instance;
if (vfs::open(path, kOpenFlagReadOnly, 0, &instance, thread).isError()) {
if (vfs::open(path, orbis::kOpenFlagReadOnly, 0, &instance, thread)
.isError()) {
return {};
}

View File

@ -869,7 +869,7 @@ static orbis::SysResult launchDaemon(orbis::Thread *thread, std::string path,
{
rx::Ref<orbis::File> file;
auto result = vfs::open(path, kOpenFlagReadOnly, 0, &file, thread);
auto result = vfs::open(path, orbis::kOpenFlagReadOnly, 0, &file, thread);
if (result.isError()) {
return result;
}

View File

@ -303,7 +303,7 @@ orbis::SysResult open(orbis::Thread *thread, orbis::ptr<const char> path,
orbis::SysResult shm_open(orbis::Thread *thread, const char *path,
orbis::sint flags, orbis::sint mode,
rx::Ref<orbis::File> *file) {
auto dev = static_cast<IoDevice *>(orbis::g_context->shmDevice.get());
auto dev = orbis::g_context->shmDevice;
return dev->open(file, path, flags, mode, thread);
}
orbis::SysResult unlink(orbis::Thread *thread, orbis::ptr<const char> path) {

View File

@ -18,7 +18,7 @@ static orbis::FileOps devfs_ops = {
.stat = devfs_stat,
};
struct DevFs : IoDevice {
struct DevFs : orbis::IoDevice {
std::map<std::string, rx::Ref<IoDevice>, std::less<>> devices;
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
@ -50,7 +50,7 @@ struct DevFs : IoDevice {
}
};
struct ProcFs : IoDevice {
struct ProcFs : orbis::IoDevice {
orbis::ErrorCode open(rx::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override {
@ -60,7 +60,8 @@ struct ProcFs : IoDevice {
};
static rx::shared_mutex gMountMtx;
static std::map<std::string, rx::Ref<IoDevice>, std::greater<>> gMountsMap;
static std::map<std::string, rx::Ref<orbis::IoDevice>, std::greater<>>
gMountsMap;
static rx::Ref<DevFs> gDevFs;
void vfs::fork() {
@ -93,16 +94,16 @@ void vfs::deinitialize() {
gMountsMap.clear();
}
void vfs::addDevice(std::string name, IoDevice *device) {
void vfs::addDevice(std::string name, orbis::IoDevice *device) {
std::lock_guard lock(gMountMtx);
gDevFs->devices[std::move(name)] = device;
}
std::pair<rx::Ref<IoDevice>, std::string>
std::pair<rx::Ref<orbis::IoDevice>, std::string>
vfs::get(const std::filesystem::path &guestPath) {
std::string normalPath = std::filesystem::path(guestPath).lexically_normal();
std::string_view path = normalPath;
rx::Ref<IoDevice> device;
rx::Ref<orbis::IoDevice> device;
std::lock_guard lock(gMountMtx);
@ -141,7 +142,7 @@ vfs::get(const std::filesystem::path &guestPath) {
}
orbis::SysResult vfs::mount(const std::filesystem::path &guestPath,
IoDevice *dev) {
orbis::IoDevice *dev) {
auto mp = guestPath.lexically_normal().string();
if (!mp.ends_with("/")) {
mp += "/";

View File

@ -5,16 +5,19 @@
#include "rx/Rc.hpp"
#include <filesystem>
namespace orbis {
struct IoDevice;
}
namespace vfs {
void fork();
void initialize();
void deinitialize();
void addDevice(std::string name, IoDevice *device);
std::pair<rx::Ref<IoDevice>, std::string>
void addDevice(std::string name, orbis::IoDevice *device);
std::pair<rx::Ref<orbis::IoDevice>, std::string>
get(const std::filesystem::path &guestPath);
orbis::SysResult mount(const std::filesystem::path &guestPath, IoDevice *dev);
orbis::SysResult mount(const std::filesystem::path &guestPath,
orbis::IoDevice *dev);
orbis::SysResult open(std::string_view path, int flags, int mode,
rx::Ref<orbis::File> *file, orbis::Thread *thread);
bool exists(std::string_view path, orbis::Thread *thread);

View File

@ -649,7 +649,7 @@ struct Block {
static Block gBlocks[kBlockCount];
struct MapInfo {
rx::Ref<IoDevice> device;
rx::Ref<orbis::IoDevice> device;
std::uint64_t offset;
std::uint32_t flags;
char name[32];
@ -776,7 +776,7 @@ constexpr auto kMainDirectMemorySize =
kPhysicalMemorySize - kFlexibleMemorySize;
void *vm::map(void *addr, std::uint64_t len, std::int32_t prot,
std::int32_t flags, std::int32_t internalFlags, IoDevice *device,
std::int32_t flags, std::int32_t internalFlags, orbis::IoDevice *device,
std::uint64_t offset) {
std::println(stderr, "vm::map(addr = {}, len = {}, prot = {}, flags = {})",
addr, len, mapProtToString(prot), mapFlagsToString(flags));

View File

@ -1,6 +1,5 @@
#pragma once
#include "io-device.hpp"
#include <cstddef>
#include "orbis/IoDevice.hpp"
#include <cstdint>
#include <string>
@ -72,7 +71,7 @@ void reset();
void initialize(std::uint64_t pid);
void deinitialize();
void *map(void *addr, std::uint64_t len, std::int32_t prot, std::int32_t flags,
std::int32_t internalFlags = 0, IoDevice *device = nullptr,
std::int32_t internalFlags = 0, orbis::IoDevice *device = nullptr,
std::uint64_t offset = 0);
bool unmap(void *addr, std::uint64_t size);
bool protect(void *addr, std::uint64_t size, std::int32_t prot);