diff options
author | Brian Gianforcaro <b.gianfo@gmail.com> | 2020-08-07 00:38:36 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-07 16:18:36 +0200 |
commit | 9f685ac30a4bc2ec55e581b5779e4a9c7172f1d1 (patch) | |
tree | 5aea114d7c4035929497ebaeee1a6d5f4771a6ae | |
parent | 8fa46bcb7dfea4a758e534baebd5c7399871f343 (diff) | |
download | serenity-9f685ac30a4bc2ec55e581b5779e4a9c7172f1d1.zip |
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.
-rw-r--r-- | AK/Userspace.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/AK/Userspace.h b/AK/Userspace.h index 4ac2ef07ed..8c8b778c13 100644 --- a/AK/Userspace.h +++ b/AK/Userspace.h @@ -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; |