From 9f685ac30a4bc2ec55e581b5779e4a9c7172f1d1 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Fri, 7 Aug 2020 00:38:36 -0700 Subject: [PATCH] AK: Add static_ptr_cast support for the Userspace pointer type When using Userspace there are certain syscalls where being able to cast between types is needed. You should be able to easily cast away the Userspace wrapper, but it's perfectly safe to be able to cast the internal type that is being wrapped. --- AK/Userspace.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 +inline Userspace static_ptr_cast(const Userspace& ptr) +{ +#ifdef KERNEL + auto casted_ptr = static_cast(ptr.unsafe_userspace_ptr()); +#else + auto casted_ptr = static_cast(ptr.ptr()); +#endif + return Userspace((FlatPtr)casted_ptr); +} + } using AK::Userspace; +using AK::static_ptr_cast;