From d7e5768763ff39201761e7c4dfb07cd18c724344 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 5 Sep 2021 17:50:34 +0200 Subject: [PATCH] Kernel: Add copy_typed_from_userspace(Userspace) This allows easy retrieval of typed POD values from userspace with implicit error propagation. --- Kernel/StdLib.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Kernel/StdLib.h b/Kernel/StdLib.h index 37eb932394..0b9c3f9158 100644 --- a/Kernel/StdLib.h +++ b/Kernel/StdLib.h @@ -167,3 +167,11 @@ template return EOVERFLOW; return copy_to_user(dest.unsafe_userspace_ptr(), src, size.value()); } + +template +inline KResultOr copy_typed_from_user(Userspace user_data) +{ + T data {}; + TRY(copy_from_user(&data, user_data)); + return data; +}