Skip to content

Commit

Permalink
Kernel: UsermodePointer bool cast
Browse files Browse the repository at this point in the history
This allows UsermodePointer to be checked in if statements without an explicit cast/access
  • Loading branch information
fido2020 committed Oct 29, 2021
1 parent d01e737 commit 2493e20
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Kernel/include/UserPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ template <typename T> class UserPointer {

ALWAYS_INLINE T* Pointer() { return m_ptr; }

ALWAYS_INLINE operator bool() const { return m_ptr != nullptr; }

private:
T* m_ptr;
};
Expand All @@ -44,6 +46,9 @@ template <typename T> class UserBuffer {
public:
UserBuffer(uintptr_t ptr) : m_ptr(reinterpret_cast<T*>(ptr)) {}

ALWAYS_INLINE int GetValue(unsigned index, T& kernelValue) const { return UserMemcpy(&kernelValue, &m_ptr[index], sizeof(T)); }
ALWAYS_INLINE int StoreValue(unsigned index, const T& kernelValue) { return UserMemcpy(&m_ptr[index], &kernelValue, sizeof(T)); }

ALWAYS_INLINE int Read(T* data, size_t offset, size_t count) const {
if (!IsUsermodePointer(m_ptr, offset, count)) { // Don't allow kernel memory access
return 0;
Expand Down

0 comments on commit 2493e20

Please sign in to comment.