mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:37:35 +00:00
Kernel: Combine validate and copy of user mode pointers (#1069)
Right now there is a significant amount of boiler plate code required to validate user mode parameters in syscalls. In an attempt to reduce this a bit, introduce validate_read_and_copy_typed which combines the usermode address check and does the copy internally if the validation passes. This cleans up a little bit of code from a significant amount of syscalls.
This commit is contained in:
parent
9cac205d67
commit
4cee441279
2 changed files with 55 additions and 66 deletions
|
@ -285,6 +285,15 @@ public:
|
|||
template<typename T>
|
||||
bool validate_read_typed(T* value, size_t count = 1) { return validate_read(value, sizeof(T) * count); }
|
||||
template<typename T>
|
||||
bool validate_read_and_copy_typed(T* dest, const T* src)
|
||||
{
|
||||
bool validated = validate_read_typed(src);
|
||||
if (validated) {
|
||||
copy_from_user(dest, src);
|
||||
}
|
||||
return validated;
|
||||
}
|
||||
template<typename T>
|
||||
bool validate_write_typed(T* value, size_t count = 1) { return validate_write(value, sizeof(T) * count); }
|
||||
template<typename DataType, typename SizeType>
|
||||
bool validate(const Syscall::MutableBufferArgument<DataType, SizeType>&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue