summaryrefslogtreecommitdiff
path: root/src/kernel/mem
diff options
context:
space:
mode:
authordzwdz2021-11-04 07:35:23 +0000
committerdzwdz2021-11-04 07:35:23 +0000
commitd9b7a1a5d222a618b7530ecfa42b1ccb4f9a5f4c (patch)
tree99732f38912a7db5bf8fabc610a03a9ca366a4be /src/kernel/mem
parent0c24ed6eb939bd68c9a882d21fd45e2079e1bb66 (diff)
parente0ddaaa6290f74fcce6e067c1e5f1c9c87974f4c (diff)
Merge branch 'main' into fork2
Diffstat (limited to 'src/kernel/mem')
-rw-r--r--src/kernel/mem/virt.h13
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;
+ }
+}