mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:07:35 +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
1 changed files with 12 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue