mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 02:26:11 +00:00
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:
parent
8fa46bcb7d
commit
9f685ac30a
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue