diff options
author | dzwdz | 2022-07-17 20:28:53 +0200 |
---|---|---|
committer | dzwdz | 2022-07-17 20:28:53 +0200 |
commit | c6bbf615e5c77ec273b954c11cef95df3d6f7286 (patch) | |
tree | 7b4539c9c5089a8b563d90444c388169fd093cf0 /src/kernel/mem/virt.h | |
parent | 51cbabd0f40b041fa00203266afa046d14e88b22 (diff) |
kernel/virt_cpy: error struct, better error handling
Diffstat (limited to 'src/kernel/mem/virt.h')
-rw-r--r-- | src/kernel/mem/virt.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/kernel/mem/virt.h b/src/kernel/mem/virt.h index 7d95b3b..cf22a75 100644 --- a/src/kernel/mem/virt.h +++ b/src/kernel/mem/virt.h @@ -18,6 +18,10 @@ struct virt_iter { bool _writeable; }; +struct virt_cpy_error { + bool read_fail, write_fail; +}; + /* if pages == NULL, create an iterator over physical memory. */ void virt_iter_new( struct virt_iter *iter, void __user *virt, size_t length, @@ -25,17 +29,20 @@ void virt_iter_new( bool virt_iter_next(struct virt_iter *); -bool virt_cpy( +size_t virt_cpy( struct pagedir *dest_pages, void __user *dest, - struct pagedir *src_pages, const void __user *src, size_t length); + struct pagedir *src_pages, const void __user *src, + size_t length, struct virt_cpy_error *err); -static inline bool virt_cpy_to(struct pagedir *dest_pages, // physical -> virtual +/* copies to virtual memory, returns true on success */ +static inline bool virt_cpy_to(struct pagedir *dest_pages, void __user *dest, const void *src, size_t length) { - return virt_cpy(dest_pages, dest, NULL, (userptr_t)src, length); + return length == virt_cpy(dest_pages, dest, NULL, (userptr_t)src, length, NULL); } -static inline bool virt_cpy_from(struct pagedir *src_pages, // virtual -> physical +/* copies from virtual memory, returns true on success */ +static inline bool virt_cpy_from(struct pagedir *src_pages, void *dest, const void __user *src, size_t length) { - return virt_cpy(NULL, (userptr_t)dest, src_pages, src, length); + return length == virt_cpy(NULL, (userptr_t)dest, src_pages, src, length, NULL); } |