diff --git a/rpcsx-os/CMakeLists.txt b/rpcsx-os/CMakeLists.txt index e7ce4b45c..8572e8ef1 100644 --- a/rpcsx-os/CMakeLists.txt +++ b/rpcsx-os/CMakeLists.txt @@ -21,6 +21,7 @@ add_executable(rpcsx-os iodev/rng.cpp iodev/sbl_srv.cpp iodev/shm.cpp + iodev/urandom.cpp iodev/zero.cpp main.cpp diff --git a/rpcsx-os/io-devices.hpp b/rpcsx-os/io-devices.hpp index 79e3f5d40..71defd2b7 100644 --- a/rpcsx-os/io-devices.hpp +++ b/rpcsx-os/io-devices.hpp @@ -21,3 +21,4 @@ IoDevice *createConsoleCharacterDevice(); IoDevice *createSblSrvCharacterDevice(); IoDevice *createShmDevice(); IoDevice *createBlockPoolDevice(); +IoDevice *createUrandomCharacterDevice(); diff --git a/rpcsx-os/iodev/urandom.cpp b/rpcsx-os/iodev/urandom.cpp new file mode 100644 index 000000000..01239e342 --- /dev/null +++ b/rpcsx-os/iodev/urandom.cpp @@ -0,0 +1,38 @@ +#include "io-device.hpp" +#include "orbis/KernelAllocator.hpp" +#include "orbis/uio.hpp" +#include +#include + +struct UrandomDevice : public IoDevice { + orbis::ErrorCode open(orbis::Ref *file, const char *path, + std::uint32_t flags, std::uint32_t mode, + orbis::Thread *thread) override; +}; +struct UrandomFile : public orbis::File {}; + +static orbis::ErrorCode zero_read(orbis::File *file, orbis::Uio *uio, + orbis::Thread *) { + for (auto entry : std::span(uio->iov, uio->iovcnt)) { + std::memset(entry.base, 0, entry.len); + uio->offset += entry.len; + } + uio->resid = 0; + return {}; +} + +static const orbis::FileOps ops = { + .read = zero_read, +}; + +orbis::ErrorCode UrandomDevice::open(orbis::Ref *file, + const char *path, std::uint32_t flags, + std::uint32_t mode, orbis::Thread *thread) { + auto newFile = orbis::knew(); + newFile->device = this; + newFile->ops = &ops; + *file = newFile; + return {}; +} + +IoDevice *createUrandomCharacterDevice() { return orbis::knew(); } diff --git a/rpcsx-os/main.cpp b/rpcsx-os/main.cpp index 2ded78261..28ddca4ca 100644 --- a/rpcsx-os/main.cpp +++ b/rpcsx-os/main.cpp @@ -344,6 +344,7 @@ static int ps4Exec(orbis::Thread *mainThread, rx::vfs::mount("/dev/rng", createRngCharacterDevice()); rx::vfs::mount("/dev/sbl_srv", createSblSrvCharacterDevice()); rx::vfs::mount("/dev/ajm", createAjmCharacterDevice()); + rx::vfs::mount("/dev/urandom", createUrandomCharacterDevice()); orbis::Ref stdinFile; orbis::Ref stdoutFile;