mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 01:32:14 -05: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
Notes:
sideshowbarker
2024-07-19 04:09:54 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/9f685ac30a4 Pull-request: https://github.com/SerenityOS/serenity/pull/3039
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…
Reference in a new issue