AK: Add static_ptr_cast support for the Userspace<T> pointer type

When using Userspace<T> there are certain syscalls where being able
to cast between types is needed. You should be able to easily cast
away the Userspace<T> wrapper, but it's perfectly safe to be able to
cast the internal type that is being wrapped.
This commit is contained in:
Brian Gianforcaro 2020-08-07 00:38:36 -07:00 committed by Andreas Kling
parent 8fa46bcb7d
commit 9f685ac30a

View file

@ -73,6 +73,18 @@ private:
#endif
};
template<typename T, typename U>
inline Userspace<T> static_ptr_cast(const Userspace<U>& ptr)
{
#ifdef KERNEL
auto casted_ptr = static_cast<T>(ptr.unsafe_userspace_ptr());
#else
auto casted_ptr = static_cast<T>(ptr.ptr());
#endif
return Userspace<T>((FlatPtr)casted_ptr);
}
}
using AK::Userspace;
using AK::static_ptr_cast;