[orbis-kernel] Added uread/uwrite of arrays

Deprecate uread without error code
This commit is contained in:
DH 2023-07-11 23:13:09 +03:00
parent 764994f94c
commit 679bf94b5c

View file

@ -23,31 +23,38 @@ using size_t = uint64_t;
using ssize_t = int64_t;
using off_t = int64_t;
using sshort = int16_t;
using ushort = uint16_t;
using uint = uint32_t;
using sint = int32_t;
using slong = int64_t;
using ulong = uint64_t;
using uintptr_t = uint64_t;
using intptr_t = int64_t;
template <typename T> using ptr = T *;
template <typename T> using cptr = T *const;
using caddr_t = ptr<char>;
inline ErrorCode uread(void *kernelAddress, ptr<const void> userAddress,
size_t size) {
[[nodiscard]] inline ErrorCode uread(void *kernelAddress,
ptr<const void> userAddress, size_t size) {
std::memcpy(kernelAddress, userAddress, size);
return {};
}
inline ErrorCode uwrite(ptr<void> userAddress, const void *kernelAddress,
size_t size) {
[[nodiscard]] inline ErrorCode uwrite(ptr<void> userAddress,
const void *kernelAddress, size_t size) {
std::memcpy(userAddress, kernelAddress, size);
return {};
}
inline ErrorCode ureadString(char *kernelAddress, size_t kernelSize,
ptr<const char> userAddress) {
[[nodiscard]] inline ErrorCode ureadString(char *kernelAddress,
size_t kernelSize,
ptr<const char> userAddress) {
std::strncpy(kernelAddress, userAddress, kernelSize);
if (kernelAddress[kernelSize - 1] != '\0') {
kernelAddress[kernelSize - 1] = '\0';
@ -57,14 +64,28 @@ inline ErrorCode ureadString(char *kernelAddress, size_t kernelSize,
return {};
}
template <typename T> T uread(ptr<T> pointer) {
template <typename T> [[deprecated]] T uread(ptr<T> pointer) {
T result;
uread(&result, pointer, sizeof(T));
return result;
}
template <typename T> void uwrite(ptr<T> pointer, T data) {
uwrite(pointer, &data, sizeof(T));
template <typename T> [[nodiscard]] ErrorCode uread(T &result, ptr<T> pointer) {
return uread(&result, pointer, sizeof(T));
}
template <typename T> [[nodiscard]] ErrorCode uwrite(ptr<T> pointer, T data) {
return uwrite(pointer, &data, sizeof(T));
}
template <typename T>
[[nodiscard]] ErrorCode uread(T *result, ptr<T> pointer, std::size_t count) {
return uread(&result, pointer, sizeof(T) * count);
}
template <typename T>
[[nodiscard]] ErrorCode uwrite(ptr<T> pointer, T *data, std::size_t count) {
return uwrite(pointer, &data, sizeof(T) * count);
}
inline uint64_t readRegister(void *context, RegisterId id) {