rpcsx/rpcsx-os/iodev/zero.cpp

39 lines
1.1 KiB
C++
Raw Normal View History

2023-06-23 02:28:14 +02:00
#include "io-device.hpp"
2023-07-04 18:19:17 +02:00
#include "orbis/KernelAllocator.hpp"
#include "orbis/uio.hpp"
2023-06-23 02:28:14 +02:00
#include <cstring>
#include <span>
2023-06-23 02:28:14 +02:00
struct ZeroDevice : public IoDevice {
orbis::ErrorCode open(orbis::Ref<orbis::File> *file, const char *path,
2023-07-29 21:46:28 +02:00
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) override;
};
struct ZeroFile : public orbis::File {};
2023-06-23 02:28:14 +02:00
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 {};
2023-06-23 02:28:14 +02:00
}
static const orbis::FileOps ops = {
.read = zero_read,
};
2023-06-23 02:28:14 +02:00
orbis::ErrorCode ZeroDevice::open(orbis::Ref<orbis::File> *file,
const char *path, std::uint32_t flags,
2023-07-29 21:46:28 +02:00
std::uint32_t mode, orbis::Thread *thread) {
auto newFile = orbis::knew<ZeroFile>();
newFile->device = this;
newFile->ops = &ops;
*file = newFile;
return {};
2023-06-23 02:28:14 +02:00
}
IoDevice *createZeroCharacterDevice() { return orbis::knew<ZeroDevice>(); }