1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

Kernel+AK: Add and use Userspace<T>::unsafe_userspace_ptr()

Since we already have the type information in the Userspace template,
it was a bit silly to cast manually everywhere. Just add a sufficiently
scary-sounding getter for a typed pointer.

Thanks @alimpfard for pointing out that I was being silly with tossing
out the type.

In the future we may want to make this API non-public as well.
This commit is contained in:
Andreas Kling 2020-07-31 18:46:55 +02:00
parent 5cd7159629
commit 628b3badfb
4 changed files with 13 additions and 12 deletions

View file

@ -75,23 +75,23 @@ inline void copy_to_user(T* dest, const T* src)
template<typename T>
inline void copy_from_user(T* dest, Userspace<const T*> src)
{
copy_from_user(dest, (const T*)src.ptr(), sizeof(T));
copy_from_user(dest, src.unsafe_userspace_ptr(), sizeof(T));
}
template<typename T>
inline void copy_to_user(Userspace<T*> dest, const T* src)
{
copy_to_user((T*)dest.ptr(), src, sizeof(T));
copy_to_user(dest.unsafe_userspace_ptr(), src, sizeof(T));
}
template<typename T>
inline void copy_to_user(Userspace<T*> dest, const void* src, size_t size)
{
copy_to_user((void*)dest.ptr(), src, size);
copy_to_user(dest.unsafe_userspace_ptr(), src, size);
}
template<typename T>
inline void copy_from_user(void* dest, Userspace<const T*> src, size_t size)
{
copy_from_user(dest, (const void*)src.ptr(), size);
copy_from_user(dest, src.unsafe_userspace_ptr(), size);
}