[rpcsx-os] stub /dev/urandom

This commit is contained in:
DH 2023-10-18 01:11:01 +03:00
parent ef4f11f2ad
commit 4f3495117c
4 changed files with 41 additions and 0 deletions

View file

@ -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

View file

@ -21,3 +21,4 @@ IoDevice *createConsoleCharacterDevice();
IoDevice *createSblSrvCharacterDevice();
IoDevice *createShmDevice();
IoDevice *createBlockPoolDevice();
IoDevice *createUrandomCharacterDevice();

View file

@ -0,0 +1,38 @@
#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/uio.hpp"
#include <cstring>
#include <span>
struct UrandomDevice : public IoDevice {
orbis::ErrorCode open(orbis::Ref<orbis::File> *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<orbis::File> *file,
const char *path, std::uint32_t flags,
std::uint32_t mode, orbis::Thread *thread) {
auto newFile = orbis::knew<UrandomFile>();
newFile->device = this;
newFile->ops = &ops;
*file = newFile;
return {};
}
IoDevice *createUrandomCharacterDevice() { return orbis::knew<UrandomDevice>(); }

View file

@ -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<orbis::File> stdinFile;
orbis::Ref<orbis::File> stdoutFile;