diff options
author | dzwdz | 2021-11-03 07:38:30 +0000 |
---|---|---|
committer | dzwdz | 2021-11-03 07:38:30 +0000 |
commit | d7225aa75814788828387ad5871b6aa1dddf2cec (patch) | |
tree | 137851b58c1fe771363901e205f3a82029e649c1 /src/kernel/mem/virt.h | |
parent | 6d3960c8fdd361af32f88e4fb1e2deb892166932 (diff) |
kernel: implement virt_cpy2kmalloc
Diffstat (limited to 'src/kernel/mem/virt.h')
-rw-r--r-- | src/kernel/mem/virt.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/kernel/mem/virt.h b/src/kernel/mem/virt.h index 3a42e9e..b858bdd 100644 --- a/src/kernel/mem/virt.h +++ b/src/kernel/mem/virt.h @@ -1,5 +1,6 @@ /* contains utilities for interacting with virtual memory */ #pragma once +#include <kernel/mem/alloc.h> #include <shared/types.h> #include <stdbool.h> #include <stddef.h> @@ -38,3 +39,15 @@ static inline bool virt_cpy_from(struct pagedir *src_pages, // virtual -> physic void *dest, const void __user *src, size_t length) { return virt_cpy(NULL, (userptr_t)dest, src_pages, src, length); } + +/** Copies a chunk of virtual memory to a newly kmalloc'd buffer. */ +static inline void *virt_cpy2kmalloc(struct pagedir *src_pages, + const void __user *src, size_t length) { + void *buf = kmalloc(length); + if (virt_cpy_from(src_pages, buf, src, length)) { + return buf; + } else { + kfree(buf); + return NULL; + } +} |